🤵♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.raghu.mvpassignment.util | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.ListUpdateCallback | |
import androidx.recyclerview.widget.RecyclerView | |
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED | |
import kotlinx.coroutines.channels.actor | |
import java.util.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.animation.Animator | |
import android.animation.ObjectAnimator | |
import android.animation.ValueAnimator.AnimatorUpdateListener | |
import android.content.Context | |
import android.content.res.Resources | |
import androidx.core.widget.NestedScrollView | |
import android.util.AttributeSet | |
import android.util.Log | |
import android.view.MotionEvent | |
import android.view.View |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.text.TextUtils; | |
import org.jetbrains.annotations.NotNull; | |
import java.io.IOException; | |
import java.util.concurrent.TimeUnit; | |
import okhttp3.Interceptor; | |
import okhttp3.OkHttpClient; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final OkHttpClient client = new OkHttpClient.Builder() | |
. authenticator(new Authenticator() { | |
@Override public Request authenticate(Route route, Response response) throws IOException { | |
if (response.request().header("Authorization") != null) { | |
return null; // Give up, we've already attempted to authenticate. | |
} | |
String credential = Credentials.basic("jesse", "password1"); | |
return response.request().newBuilder() | |
.header("Authorization", credential) | |
.build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onBackPressed() { | |
if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) { | |
mDrawerLayout.closeDrawers(); | |
} | |
else if (getSupportFragmentManager().getBackStackEntryCount() > 0) { | |
String fragmentTag = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName(); | |
if (fragmentTag.equals("dashboard")) { | |
//Toast.makeText(this.getApplicationContext(),""+fragmentTag,Toast.LENGTH_SHORT).show(); | |
finish(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class class RetrofitDependency : RetrofitInterface { | |
override fun provideRetrofit(): Retrofit { | |
val logging = HttpLoggingInterceptor() | |
logging.level = HttpLoggingInterceptor.Level.BASIC | |
val okHttpClient = OkHttpClient.Builder() | |
.addInterceptor(logging) | |
.connectTimeout(10, TimeUnit.SECONDS) | |
.writeTimeout(10, TimeUnit.SECONDS) | |
.readTimeout(30, TimeUnit.SECONDS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RetrofitInterface { | |
fun provideRetrofit(): Retrofit | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListRepositoryImpl(private val retrofitDependency: RetrofitDependency): ListRepository { | |
var data = MutableLiveData<List<Users>>() | |
override fun getUsers(): MutableLiveData<List<Users>>{ | |
val service = retrofitDependency.provideRetrofit().create(Api::class.java) | |
service.users.enqueue(object : Callback<List<Users>> { | |
override fun onResponse(call: Call<List<Users>>, response: Response<List<Users>>) { | |
if (response.isSuccessful) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListScreenViewModel(private val repo: ListRepositoryImpl) : ViewModel() { | |
fun getUsers() : LiveData<List<Users>> { | |
return repo.getUsers() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val applicationModule = module { | |
single<RetrofitInterface>("Retrofit") { RetrofitDependency() } | |
single<raghu.me.myapplication.di.ListRepository>("ListRepository"){ ListRepositoryImpl(get("Retrofit")) } | |
// ListScreenViewModel | |
viewModel { ListScreenViewModel(get("ListRepository")) } | |
} |