Skip to content

Instantly share code, notes, and snippets.

Avatar

Chintan Soni iChintanSoni

View GitHub Profile
View AnimationExtension.kt
class AnimatorExtension {
// Skipping the initialization
private val animator: Animator? = null
// Normal Usage
fun normalAnimationListener() {
animator?.addListener(
onStart = {
View HomeActivity.kt
class HomeActivity : DaggerAppCompatActivity() {
@Inject
lateinit var apiService: ApiService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// init UI
// Your apiService instance is ready to use.
View ActivityModule.kt
@Module
abstract class ActivityModule {
@ContributesAndroidInjector
internal abstract fun contributeHomeActivity(): HomeActivity
}
View MyApplication.kt
class MyApplication : DaggerApplication() {
override fun onCreate() {
super.onCreate()
initializeTimber()
}
private fun initializeTimber() {
if (BuildConfig.DEBUG) {
View AppComponent.kt
@Component(modules = [AndroidSupportInjectionModule::class, AppModule::class, ActivityModule::class])
interface AppComponent : AndroidInjector<DaggerApplication> {
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application): Builder
fun build(): AppComponent
}
@iChintanSoni
iChintanSoni / ApiService.kt
Last active Jan 23, 2020
Daggering kotlin-android: AppModule.kt
View ApiService.kt
interface ApiService {
@GET("api")
fun getUsers(@Query("result") result: Int): Observable<RandomUserResponse>
}
@iChintanSoni
iChintanSoni / build.gradle
Created Apr 17, 2018
Daggering Kotlin-anroid: build.gradle
View build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.simform.android.dagger2advanced"
minSdkVersion 16
@iChintanSoni
iChintanSoni / BaseRecyclerAdapter.java
Created Jul 24, 2017
BaseRecyclerAdapter, a generic Recycler adapter, is an extended version from https://gist.github.com/chintansoni202/3c61aea787ae4bd49f26adee9dd40a08 This version should be used along with Data-binding. You can even pass empty view layout, if there is no list item.
View BaseRecyclerAdapter.java
public class BaseRecyclerAdapter<T, MVH extends BaseViewHolder<T>, EVH extends BaseViewHolder<T>> extends RecyclerView.Adapter<BaseViewHolder<T>> {
private static final int VIEW_TYPE_EMPTY = 0;
private static final int VIEW_TYPE_DATA = 1;
private List<T> list = new ArrayList<>();
@LayoutRes
private int emptyViewLayoutResource;
private Class<EVH> emptyViewHolder;
@LayoutRes
private int dataLayoutResource;
@iChintanSoni
iChintanSoni / BaseRecyclerAdapter.java
Created Jul 24, 2017
BaseRecyclerAdapter, a generic Recycler adapter, is an extended version from https://gist.github.com/chintansoni202/3c61aea787ae4bd49f26adee9dd40a08
View BaseRecyclerAdapter.java
public class BaseRecyclerAdapter<T, MVH extends BaseViewHolder<T>, EVH extends BaseViewHolder<T>> extends RecyclerView.Adapter<BaseViewHolder<T>> {
private static final int VIEW_TYPE_EMPTY = 0;
private static final int VIEW_TYPE_DATA = 1;
private List<T> list = new ArrayList<>();
@LayoutRes
private int emptyViewLayoutResource;
private Class<EVH> emptyViewHolder;
@LayoutRes
private int dataLayoutResource;
@iChintanSoni
iChintanSoni / ScrollingActivity.java
Last active Oct 3, 2018
CollapsingToolbarLayout with TabLayout
View ScrollingActivity.java
public class ScrollingActivity extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);