Skip to content

Instantly share code, notes, and snippets.

View iChintanSoni's full-sized avatar

Chintan Soni iChintanSoni

View GitHub Profile
@iChintanSoni
iChintanSoni / SharedPreferenceUtils.java
Last active December 5, 2018 01:52
Utility class for working with SharedPreferences
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferenceUtils {
private static SharedPreferenceUtils mSharedPreferenceUtils;
protected Context mContext;
private SharedPreferences mSharedPreferences;
private SharedPreferences.Editor mSharedPreferencesEditor;
private SharedPreferenceUtils(Context context) {
@iChintanSoni
iChintanSoni / BaseRecyclerAdapter.java
Last active February 1, 2018 14:00
This implementation of generic recycler adapter is truely inspired from Firebase Database UI Adapter.
package com.chintansoni.android.mesamis.base;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@iChintanSoni
iChintanSoni / ScrollingActivity.java
Last active October 3, 2018 09:07
CollapsingToolbarLayout with TabLayout
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);
@iChintanSoni
iChintanSoni / BaseRecyclerAdapter.java
Created July 24, 2017 03:33
BaseRecyclerAdapter, a generic Recycler adapter, is an extended version from https://gist.github.com/chintansoni202/3c61aea787ae4bd49f26adee9dd40a08
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 July 24, 2017 03:44
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.
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 / build.gradle
Created April 17, 2018 09:30
Daggering Kotlin-anroid: 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 / ApiService.kt
Last active January 23, 2020 00:34
Daggering kotlin-android: AppModule.kt
interface ApiService {
@GET("api")
fun getUsers(@Query("result") result: Int): Observable<RandomUserResponse>
}
@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
}
class MyApplication : DaggerApplication() {
override fun onCreate() {
super.onCreate()
initializeTimber()
}
private fun initializeTimber() {
if (BuildConfig.DEBUG) {
@Module
abstract class ActivityModule {
@ContributesAndroidInjector
internal abstract fun contributeHomeActivity(): HomeActivity
}