From dba75b8a41391f86a71ff971a5a9d57820781022 Mon Sep 17 00:00:00 2001 From: Bande Rajkiran Date: Sat, 28 Mar 2020 15:05:14 +0530 Subject: [PATCH] Removed some unwanted files --- android-commons.gradle | 2 + app/src/main/res/menu/menu_bottom_nav.xml | 14 --- buildSrc/src/main/kotlin/Deps.kt | 6 + .../com/skeleton/network/NetworkManager.kt | 6 +- .../src/main/res/drawable/ic_add.xml | 9 -- .../src/main/res/drawable/ic_arrow_right.xml | 9 -- .../src/main/res/drawable/ic_consent.xml | 14 --- .../src/main/res/drawable/ic_deny.xml | 11 -- .../src/main/res/drawable/ic_grant.xml | 9 -- .../src/main/res/drawable/ic_home.xml | 17 --- .../res/drawable/ic_purpose_of_request.xml | 14 --- .../main/res/drawable/ic_requests_info.xml | 14 --- .../src/main/res/values/colors.xml | 30 +---- .../src/main/res/values/styles.xml | 118 ------------------ commons/utils/build.gradle | 1 - .../com/skeleton/util/extension/Extensions.kt | 26 ++-- .../sharedPref/NetworkSharedPrefsManager.kt | 60 ++++----- .../util/sharedPref/SharedPrefsManager.kt | 84 +++++++++++++ .../skeleton/util/extension/ExtensionsTest.kt | 15 --- 19 files changed, 143 insertions(+), 316 deletions(-) delete mode 100644 app/src/main/res/menu/menu_bottom_nav.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_add.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_arrow_right.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_consent.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_deny.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_grant.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_home.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_purpose_of_request.xml delete mode 100644 commons/presentation/src/main/res/drawable/ic_requests_info.xml create mode 100644 commons/utils/src/main/java/com/skeleton/util/sharedPref/SharedPrefsManager.kt diff --git a/android-commons.gradle b/android-commons.gradle index bc4d05a..1a01a43 100644 --- a/android-commons.gradle +++ b/android-commons.gradle @@ -11,6 +11,8 @@ dependencies { api Deps.Koin.main api Deps.Koin.androidXScope api Deps.Koin.androidXViewModel + api Deps.Rx.Kotlin + api Deps.Rx.Android api Deps.Koin.test api Deps.AndroidX.coreKtx api Deps.AndroidX.coreTesting diff --git a/app/src/main/res/menu/menu_bottom_nav.xml b/app/src/main/res/menu/menu_bottom_nav.xml deleted file mode 100644 index 7508582..0000000 --- a/app/src/main/res/menu/menu_bottom_nav.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index dbced88..dd18686 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -38,6 +38,7 @@ object LibVersions { const val jacocoPalantir = "0.4.0" const val eventBus = "3.1.1" const val kappuccino = "1.2.1" + const val rxAndroid = "3.0.0" } object Modules { @@ -112,6 +113,11 @@ object Deps { const val eventBus = "org.greenrobot:eventbus:${LibVersions.eventBus}" } + object Rx { + const val Kotlin = "io.reactivex.rxjava3:rxkotlin:${LibVersions.rxAndroid}" + const val Android = "io.reactivex.rxjava3:rxandroid:${LibVersions.rxAndroid}" + } + object Tools { const val gradleVersions = "com.github.ben-manes:gradle-versions-plugin:${LibVersions.gradle}" const val androidStudio = "com.android.tools.build:gradle:${LibVersions.androidStudio}" diff --git a/commons/network/src/main/java/com/skeleton/network/NetworkManager.kt b/commons/network/src/main/java/com/skeleton/network/NetworkManager.kt index f914360..0dc4313 100644 --- a/commons/network/src/main/java/com/skeleton/network/NetworkManager.kt +++ b/commons/network/src/main/java/com/skeleton/network/NetworkManager.kt @@ -1,7 +1,6 @@ package com.skeleton.network import com.skeleton.util.constant.NetworkConstants.Companion.MOCK_WEB_SERVER_TEST_URL -import com.skeleton.util.sharedPref.NetworkSharedPrefsManager import android.app.Application import android.content.Context import com.skeleton.network.interceptor.HostSelectionInterceptor @@ -9,6 +8,7 @@ import com.skeleton.network.interceptor.RequestInterceptor import com.skeleton.util.constant.NetworkConstants.Companion.CONNECT_TIMEOUT import com.skeleton.util.constant.NetworkConstants.Companion.READ_TIMEOUT import com.skeleton.util.constant.NetworkConstants.Companion.WRITE_TIMEOUT +import com.skeleton.util.sharedPref.getAuthToken import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit @@ -17,10 +17,10 @@ import retrofit2.converter.gson.GsonConverterFactory import java.util.concurrent.TimeUnit fun createNetworkClient(context: Application, debug: Boolean = false) = - retrofitClient(getBaseUrl(context), httpClient(debug, context, NetworkSharedPrefsManager.getAuthToken(context = context))) + retrofitClient(getBaseUrl(context), httpClient(debug, context, context.getAuthToken())) fun getBaseUrl(context: Application): String { - return if (isTestingMode(context)) MOCK_WEB_SERVER_TEST_URL else NetworkSharedPrefsManager.getBaseUrl(context)!! + return if (isTestingMode(context)) MOCK_WEB_SERVER_TEST_URL else getBaseUrl(context) } private fun httpClient(debug: Boolean, context: Context, authToken: String?): OkHttpClient { diff --git a/commons/presentation/src/main/res/drawable/ic_add.xml b/commons/presentation/src/main/res/drawable/ic_add.xml deleted file mode 100644 index 0bc2c2c..0000000 --- a/commons/presentation/src/main/res/drawable/ic_add.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/commons/presentation/src/main/res/drawable/ic_arrow_right.xml b/commons/presentation/src/main/res/drawable/ic_arrow_right.xml deleted file mode 100644 index 83f5068..0000000 --- a/commons/presentation/src/main/res/drawable/ic_arrow_right.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/commons/presentation/src/main/res/drawable/ic_consent.xml b/commons/presentation/src/main/res/drawable/ic_consent.xml deleted file mode 100644 index e59aac9..0000000 --- a/commons/presentation/src/main/res/drawable/ic_consent.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - diff --git a/commons/presentation/src/main/res/drawable/ic_deny.xml b/commons/presentation/src/main/res/drawable/ic_deny.xml deleted file mode 100644 index bfd7fea..0000000 --- a/commons/presentation/src/main/res/drawable/ic_deny.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - diff --git a/commons/presentation/src/main/res/drawable/ic_grant.xml b/commons/presentation/src/main/res/drawable/ic_grant.xml deleted file mode 100644 index 1eb5993..0000000 --- a/commons/presentation/src/main/res/drawable/ic_grant.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/commons/presentation/src/main/res/drawable/ic_home.xml b/commons/presentation/src/main/res/drawable/ic_home.xml deleted file mode 100644 index 42bffff..0000000 --- a/commons/presentation/src/main/res/drawable/ic_home.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - diff --git a/commons/presentation/src/main/res/drawable/ic_purpose_of_request.xml b/commons/presentation/src/main/res/drawable/ic_purpose_of_request.xml deleted file mode 100644 index 971e296..0000000 --- a/commons/presentation/src/main/res/drawable/ic_purpose_of_request.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - diff --git a/commons/presentation/src/main/res/drawable/ic_requests_info.xml b/commons/presentation/src/main/res/drawable/ic_requests_info.xml deleted file mode 100644 index 8ea9534..0000000 --- a/commons/presentation/src/main/res/drawable/ic_requests_info.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - diff --git a/commons/presentation/src/main/res/values/colors.xml b/commons/presentation/src/main/res/values/colors.xml index 734042d..3c090ab 100644 --- a/commons/presentation/src/main/res/values/colors.xml +++ b/commons/presentation/src/main/res/values/colors.xml @@ -1,30 +1,12 @@ - - #006353 - #00463A - #006353 - #fff - #666666 + + #0088ff + #005ccb + #ffc107 + #000000 + #000000 - @color/colorPrimary - @color/textColorSecondary - - #F1F1F1 #FFF #000 #00000000 - - @color/colorPrimary - @color/white - #E8EDE8 - - #FAFAFA - #EDEDED - #F6F6F6 - #C4C4C4 - @color/colorPrimary - @color/red - - #C81800 - #CC333333 \ No newline at end of file diff --git a/commons/presentation/src/main/res/values/styles.xml b/commons/presentation/src/main/res/values/styles.xml index a5b7ac0..c145ef7 100644 --- a/commons/presentation/src/main/res/values/styles.xml +++ b/commons/presentation/src/main/res/values/styles.xml @@ -2,149 +2,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/commons/utils/build.gradle b/commons/utils/build.gradle index aac86e9..654ef5c 100644 --- a/commons/utils/build.gradle +++ b/commons/utils/build.gradle @@ -7,7 +7,6 @@ dependencies { api Deps.AndroidX.lifecyleViewModel api Deps.AndroidX.appcompat api Deps.Testing.Helpers.gson - api Deps.Testing.mockito testImplementation Deps.Testing.Helpers.apacheCommonsIo diff --git a/commons/utils/src/main/java/com/skeleton/util/extension/Extensions.kt b/commons/utils/src/main/java/com/skeleton/util/extension/Extensions.kt index 773f237..acd3972 100644 --- a/commons/utils/src/main/java/com/skeleton/util/extension/Extensions.kt +++ b/commons/utils/src/main/java/com/skeleton/util/extension/Extensions.kt @@ -9,6 +9,12 @@ import androidx.annotation.StringRes import androidx.fragment.app.Fragment import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers +import io.reactivex.rxjava3.core.Observable +import io.reactivex.rxjava3.schedulers.Schedulers +import org.koin.core.context.loadKoinModules +import org.koin.core.context.unloadKoinModules +import org.koin.core.module.Module fun Context.startActivity(clazz: Class) { startActivity(Intent(this, clazz)) @@ -22,7 +28,6 @@ fun Fragment.setTitle(@StringRes resourceId: Int) { activity?.setTitle(resourceId) } - inline fun Activity.findView(id: Int): T = findViewById(id) inline fun View.findView(id: Int): T = findViewById(id) @@ -31,15 +36,6 @@ fun View.getString(id: Int): String = context.getString(id) val String.Companion.EMPTY: String get() = "" -public fun String.mask(): String? { - if (this.length > 4) { - return this.substring(0, 2) + this.substring(2, length - 2).replace( - Regex("[0-9]"), - "X" - ) + this.substring(length - 2) - } else return this -} - fun Context.showLongToast(text: CharSequence) = Toast.makeText(this, text, Toast.LENGTH_LONG).show() fun Fragment.showLongToast(text: CharSequence) = context?.showLongToast(text) fun Context.showShortToast(text: CharSequence) = @@ -48,3 +44,13 @@ fun Context.showShortToast(text: CharSequence) = fun Fragment.showShortToast(text: CharSequence) = context?.showShortToast(text) public inline fun Gson.fromJson(json: String) = this.fromJson(json, object: TypeToken() {}.type) + +fun Observable.getIo(): Observable { + return this.subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) +} + +fun reloadModules(vararg modules: Module) { + unloadKoinModules(modules.toList()) + loadKoinModules(modules.toList()) +} \ No newline at end of file diff --git a/commons/utils/src/main/java/com/skeleton/util/sharedPref/NetworkSharedPrefsManager.kt b/commons/utils/src/main/java/com/skeleton/util/sharedPref/NetworkSharedPrefsManager.kt index 6acc221..74ce0c9 100644 --- a/commons/utils/src/main/java/com/skeleton/util/sharedPref/NetworkSharedPrefsManager.kt +++ b/commons/utils/src/main/java/com/skeleton/util/sharedPref/NetworkSharedPrefsManager.kt @@ -4,42 +4,34 @@ import com.skeleton.util.constant.NetworkConstants.Companion.PROD_URL import android.content.Context import androidx.core.content.edit -class NetworkSharedPrefsManager { - - companion object { - private const val NETWORK_PREF = "NETWORK_PREF_FILE" - private const val ENVIRONMENT = "ENVIRONMENT" - private const val NETWORK_HOST = "NETWORK_PREF_HOST" - private const val AUTH_TOKEN = "AUTH_TOKEN" - - fun setNetworkPref(context: Context, environmentIndex: Int, endpoint: String) { - val sharedPreferences = context.getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) - sharedPreferences.edit { - putInt(ENVIRONMENT, environmentIndex) - putString(NETWORK_HOST, endpoint) - } - } - - fun setAuthToken(context: Context, authToken: String) { - val sharedPreferences = context.getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) - sharedPreferences.edit { putString(AUTH_TOKEN, authToken) } - } - - fun getBaseUrl(context: Context): String? { - return context.getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) - .getString(NETWORK_HOST, PROD_URL) - } +private const val NETWORK_PREF = "NETWORK_PREF_FILE" +private const val ENVIRONMENT = "ENVIRONMENT" +private const val NETWORK_HOST = "NETWORK_PREF_HOST" +private const val AUTH_TOKEN = "AUTH_TOKEN" + +fun Context.setNetworkPref(environmentIndex: Int, endpoint: String) { + val sharedPreferences = getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) + sharedPreferences.edit { + putInt(ENVIRONMENT, environmentIndex) + putString(NETWORK_HOST, endpoint) + } +} - fun getAuthToken(context: Context): String? { - val sharedPreferences = context.getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) - return sharedPreferences.getString(AUTH_TOKEN, "MQ==") - } +fun Context.setAuthToken(authToken: String) { + val sharedPreferences = getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) + sharedPreferences.edit { putString(AUTH_TOKEN, authToken) } +} - fun getEndpointIndex(context: Context): Int { - return context.getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE).getInt( - ENVIRONMENT, 0) - } +fun Context.getAuthToken(): String { + val sharedPreferences = getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) + return sharedPreferences.getString(AUTH_TOKEN, "") ?: "" +} - } +fun Context.getBaseUrl(): String { + return getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE) + .getString(NETWORK_HOST, PROD_URL) ?: PROD_URL +} +fun Context.getEndpointIndex(): Int { + return getSharedPreferences(NETWORK_PREF, Context.MODE_PRIVATE).getInt(ENVIRONMENT, 0) } diff --git a/commons/utils/src/main/java/com/skeleton/util/sharedPref/SharedPrefsManager.kt b/commons/utils/src/main/java/com/skeleton/util/sharedPref/SharedPrefsManager.kt new file mode 100644 index 0000000..2b7fbbd --- /dev/null +++ b/commons/utils/src/main/java/com/skeleton/util/sharedPref/SharedPrefsManager.kt @@ -0,0 +1,84 @@ +package com.skeleton.util.sharedPref + + +import android.content.Context +import android.preference.PreferenceManager +import androidx.fragment.app.Fragment + +fun Context.putInt(key: String, value: Int) { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + val editor = sharedPreferences.edit() + editor.putInt(key, value) + editor.apply() +} + +fun Context.getInt(key: String, defaultValue: Int): Int { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + return sharedPreferences.getInt(key, defaultValue) +} + +fun Context.putLong(key: String, value: Long) { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + val editor = sharedPreferences.edit() + editor.putLong(key, value) + editor.apply() +} + +fun Context.getLong(key: String, defaultValue: Long): Long { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + return sharedPreferences.getLong(key, defaultValue) +} + +fun Context.putBoolean(key: String, value: Boolean) { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + val editor = sharedPreferences.edit() + editor.putBoolean(key, value) + editor.apply() +} + +fun Context.getBoolean(key: String, defaultValue: Boolean): Boolean { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + return sharedPreferences.getBoolean(key, defaultValue) +} + +fun Fragment.putBoolean(key: String, value: Boolean) { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + val editor = sharedPreferences.edit() + editor.putBoolean(key, value) + editor.apply() +} + +fun Fragment.getBoolean(key: String, defaultValue: Boolean): Boolean { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + return sharedPreferences.getBoolean(key, defaultValue) +} + +fun Context.addToStringSet(key: String, value: String) { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + val editor = sharedPreferences.edit() + val set = getStringSet(key) + if (!set.contains(value)) { + set.add(value) + editor.remove(key).apply() + editor.putStringSet(key, set) + editor.commit() + } +} + +fun Context.getStringSet(key: String): HashSet { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + val set = sharedPreferences.getStringSet(key, HashSet()) + return HashSet(set) +} + +fun Context.putString(key: String, value: String) { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + val editor = sharedPreferences.edit() + editor.putString(key, value) + editor.apply() +} + +fun Context.getString(key: String, defaultValue: String): String? { + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) + return sharedPreferences.getString(key, defaultValue) +} \ No newline at end of file diff --git a/commons/utils/src/test/java/com/skeleton/util/extension/ExtensionsTest.kt b/commons/utils/src/test/java/com/skeleton/util/extension/ExtensionsTest.kt index 448b6fb..75cae04 100644 --- a/commons/utils/src/test/java/com/skeleton/util/extension/ExtensionsTest.kt +++ b/commons/utils/src/test/java/com/skeleton/util/extension/ExtensionsTest.kt @@ -28,21 +28,6 @@ class ExtensionsTest { fun setUp() { testActivity = Mockito.mock(TestsOnlyActivity::class.java) } - @Test - fun shouldStartActivityWithJustClassName() { - val clazz = AppCompatActivity::class.java - testActivity.startActivity(clazz) - verify(testActivity).startActivity(clazz) - } - - @Test - fun shouldStartActivityWithJustClassNameFromAFragment() { - val dummyFragment = mock(TestsOnlyFragment::class.java) - `when`(dummyFragment.context).thenReturn(testActivity) - val clazz = AppCompatActivity::class.java - dummyFragment.startActivity(clazz) - verify(testActivity).startActivity(clazz) - }*/ @Test fun shouldFindViewByIdForGivenContext() {