Skip to content

Instantly share code, notes, and snippets.

Avatar
🎧
Focusing

Mert Şimşek iammert

🎧
Focusing
View GitHub Profile
View Checkout pr
$ git remote add theirusername git@github.com:theirusername/reponame.git
$ git fetch theirusername
$ git checkout -b mynamefortheirbranch theirusername/theirbranch
@iammert
iammert / AndroidSampleApp.java
Created Dec 18, 2017
AndroidSampleApp.java
View AndroidSampleApp.java
public class AndroidSampleApp extends DaggerApplication {
@Override
protected AndroidInjector<? extends AndroidSampleApp> applicationInjector() {
return DaggerAppComponent.builder().create(this);
}
}
@iammert
iammert / AndroidSampleApp.java
Created Dec 18, 2017
AndroidSampleApp.java
View AndroidSampleApp.java
public class AndroidSampleApp extends Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector;
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent
.builder()
View AppComponent.java
@Component(modules = {
AndroidSupportInjectionModule.class,
AppModule.class,
ActivityBuilder.class})
interface AppComponent extends AndroidInjector<AndroidSampleApp> {
@Component.Builder
abstract class Builder extends AndroidInjector.Builder<AndroidSampleApp> {}
}
View AppComponent.java
@Component(modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuilder.class})
public interface AppComponent {
@Component.Builder
interface Builder {
@BindsInstance Builder application(Application application);
AppComponent build();
View DetailActivity.java
public class DetailActivity extends DaggerAppCompatActivity implements DetailView {
@Inject
DetailPresenter detailPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
}
View DetailActivity.java
public class DetailActivity extends AppCompatActivity implements HasSupportFragmentInjector, DetailView {
@Inject
DispatchingAndroidInjector<Fragment> fragmentDispatchingAndroidInjector;
@Inject
DetailPresenter detailPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@iammert
iammert / DaggerAppCompatActivity.java
Created Dec 18, 2017
DaggerAppCompatActivity.java
View DaggerAppCompatActivity.java
@Beta
public abstract class DaggerAppCompatActivity extends AppCompatActivity
implements HasFragmentInjector, HasSupportFragmentInjector {
@Inject DispatchingAndroidInjector<Fragment> supportFragmentInjector;
@Inject DispatchingAndroidInjector<android.app.Fragment> frameworkFragmentInjector;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
AndroidInjection.inject(this);
View Main.kt
findViewById<View>(R.id.buttonAdd).setOnClickListener { adapter.addUser(DataGenerator.generateNewUser()) }
findViewById<View>(R.id.buttonAddBulk).setOnClickListener { adapter.addUsers(DataGenerator.generateBulkUsers()) }
findViewById<View>(R.id.buttonRemove).setOnClickListener { adapter.removeUser((Math.random() * (adapter.itemCount - 1)).toInt()) }
View adapter.kt
class SortedListSampleAdapter : RecyclerView.Adapter<SortedListSampleAdapter.UserViewHolder>() {
private val userSortedList: SortedList<User>
init {
userSortedList = SortedList(User::class.java, object : SortedListAdapterCallback<User>(this) {
override fun compare(o1: User, o2: User): Int = o1.score - o2.score;
override fun areContentsTheSame(oldItem: User, newItem: User): Boolean = oldItem.id == newItem.id