diff --git a/corelibrary/build.gradle b/corelibrary/build.gradle index 1c09787..68c3504 100644 --- a/corelibrary/build.gradle +++ b/corelibrary/build.gradle @@ -18,7 +18,7 @@ android { buildTypes { release { - minifyEnabled true + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } diff --git a/corelibrary/src/main/java/com/inyomanw/corelibrary/deps/NetworkModule.kt b/corelibrary/src/main/java/com/inyomanw/corelibrary/deps/NetworkModule.kt index b6df374..336a543 100644 --- a/corelibrary/src/main/java/com/inyomanw/corelibrary/deps/NetworkModule.kt +++ b/corelibrary/src/main/java/com/inyomanw/corelibrary/deps/NetworkModule.kt @@ -1,11 +1,13 @@ package com.inyomanw.corelibrary.deps +import android.content.Context import com.google.gson.FieldNamingPolicy import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.internal.bind.DateTypeAdapter import dagger.Module import dagger.Provides +import okhttp3.Cache import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit @@ -16,7 +18,15 @@ import java.util.concurrent.TimeUnit import javax.inject.Singleton @Module -class NetworkModule(private val baseUrl: String) { +class NetworkModule(private val baseUrl: String, private val context : Context) { + + companion object { + const val REQUEST_TIMEOUT = 20 + const val CACHE_DIR_SIZE_30MB = 30 * 1024 * 1024 + const val KEEP_ALIVE_DURATION = (30 * 1000).toLong() + const val MAX_IDLE_CONNECTIONS = 10 + } + @Provides @Singleton fun providesGson(): Gson { @@ -34,9 +44,17 @@ class NetworkModule(private val baseUrl: String) { @Provides @Singleton - fun providesOkHttpClient(loggingInterceptor: HttpLoggingInterceptor): OkHttpClient { + fun providesCache() : Cache { + return Cache(context.externalCacheDir ?: context.cacheDir, CACHE_DIR_SIZE_30MB.toLong()) + } + + @Provides + @Singleton + fun providesOkHttpClient(loggingInterceptor: HttpLoggingInterceptor, + cache: Cache): OkHttpClient { return OkHttpClient.Builder() .addInterceptor(loggingInterceptor) + .cache(cache) .readTimeout(20, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .connectTimeout(20, TimeUnit.SECONDS) diff --git a/corelibrary/src/main/java/com/inyomanw/corelibrary/utils/Ext.kt b/corelibrary/src/main/java/com/inyomanw/corelibrary/utils/Ext.kt index f4fbbfe..454f705 100644 --- a/corelibrary/src/main/java/com/inyomanw/corelibrary/utils/Ext.kt +++ b/corelibrary/src/main/java/com/inyomanw/corelibrary/utils/Ext.kt @@ -1,6 +1,8 @@ package com.inyomanw.corelibrary.utils +import android.app.Activity import android.content.Context +import android.support.v7.app.AlertDialog import android.view.View import android.widget.EditText import android.widget.ImageView @@ -127,4 +129,21 @@ fun String.changeDateFormatWithoutTimeZone(oldPattern: String, newPattern: Strin e.printStackTrace() } return res +} + +fun Activity.showDialog(message : String, cancelable : Boolean = false, + positiveButton : String, positiveAction: () -> Unit = {}, + negativeButton : String, negativeAction : () -> Unit = {}) { + val dialogBuilder = AlertDialog.Builder(this).apply { + setMessage(message) + setCancelable(cancelable) + setPositiveButton(positiveButton) { dialog, _ -> + positiveAction() + dialog.dismiss() + } + setNegativeButton(negativeButton) { dialog, which -> + negativeAction() + dialog.dismiss() + } + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index b75ae29..85be9ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,8 +12,4 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # Kotlin code style for this project: "official" or "obsolete": -org.gradle.daemon=false -org.gradle.parallel=true -org.gradle.configureondemand=true -android.enableBuildScriptClasspathCheck=false kotlin.code.style=official