diff --git a/app/build.gradle b/app/build.gradle index c57dda0..d618664 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -69,6 +69,7 @@ dependencies { implementation "com.google.code.gson:gson:$gson" implementation "com.squareup.okhttp3:logging-interceptor:$interceptor" implementation "com.mocklets:pluto:$pluto" + implementation "com.google.android.gms:play-services-auth:$play_services" // UI implementation "com.google.android.material:material:$material_design" diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 481bb43..d541477 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -18,4 +18,28 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile + +## okhttp +-dontwarn okhttp3.** +-dontwarn okio.** +-dontwarn javax.annotation.** +# A resource is loaded with a relative path so the package of this class must be preserved. +-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase + +## Retrofit +# Platform calls Class.forName on types which do not exist on Android to determine platform. +-dontnote retrofit2.Platform +# Platform used when running on Java 8 VMs. Will not be used at runtime. +-dontwarn retrofit2.Platform$Java8 +# Retain generic type information for use by reflection by converters and adapters. +-keepattributes Signature +# Retain declared checked exceptions for use by a Proxy instance. +-keepattributes Exceptions + +## Bottom Navigation +-keep public class com.google.android.material.bottomnavigation.* { *; } + +# To prevent obfusticating model classes +# TODO : Make sure you do this for each feature module in your app +-keep class com.mina_mikhail.newsapp.features.news.domain.entity.* { *; } \ No newline at end of file diff --git a/app/src/main/java/com/mina_mikhail/newsapp/core/MyApplication.kt b/app/src/main/java/com/mina_mikhail/newsapp/core/MyApplication.kt index 01bb829..f85162b 100644 --- a/app/src/main/java/com/mina_mikhail/newsapp/core/MyApplication.kt +++ b/app/src/main/java/com/mina_mikhail/newsapp/core/MyApplication.kt @@ -1,12 +1,18 @@ package com.mina_mikhail.newsapp.core import android.app.Application +import com.google.android.gms.common.GooglePlayServicesNotAvailableException +import com.google.android.gms.common.GooglePlayServicesRepairableException +import com.google.android.gms.security.ProviderInstaller import com.mina_mikhail.newsapp.BuildConfig import com.mocklets.pluto.Pluto import com.mocklets.pluto.PlutoLog import com.mocklets.pluto.modules.exceptions.ANRException import com.mocklets.pluto.modules.exceptions.ANRListener import dagger.hilt.android.HiltAndroidApp +import java.security.KeyManagementException +import java.security.NoSuchAlgorithmException +import javax.net.ssl.SSLContext @HiltAndroidApp class MyApplication : Application() { @@ -15,11 +21,32 @@ class MyApplication : Application() { fun onCreate() { super.onCreate() + updateAndroidSecurityProvider() + initPlutoNetworkInspection() initPlutoANRInspection() } + private fun updateAndroidSecurityProvider() { + // To fix the following issue, when run app in cellular data, Apis not working + // javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x7edfc49e08: I/O error during system call, Connection reset by peer + try { + ProviderInstaller.installIfNeeded(applicationContext) + val sslContext: SSLContext = SSLContext.getInstance("TLSv1.2") + sslContext.init(null, null, null) + sslContext.createSSLEngine() + } catch (e: GooglePlayServicesRepairableException) { + e.printStackTrace() + } catch (e: GooglePlayServicesNotAvailableException) { + e.printStackTrace() + } catch (e: NoSuchAlgorithmException) { + e.printStackTrace() + } catch (e: KeyManagementException) { + e.printStackTrace() + } + } + private fun initPlutoNetworkInspection() { if (BuildConfig.DEBUG) { Pluto.initialize(this) diff --git a/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseActivity.kt b/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseActivity.kt index b42a7d5..b138197 100644 --- a/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseActivity.kt +++ b/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseActivity.kt @@ -8,7 +8,8 @@ import androidx.viewbinding.ViewBinding abstract class BaseActivity : AppCompatActivity() { - protected lateinit var binding: VB + private var _binding: VB? = null + open val binding get() = _binding!! protected lateinit var navController: LiveData override @@ -32,7 +33,7 @@ abstract class BaseActivity : AppCompatActivity() { } private fun initViewBinding() { - binding = getViewBinding() + _binding = getViewBinding() } abstract fun getViewBinding(): VB @@ -45,4 +46,11 @@ abstract class BaseActivity : AppCompatActivity() { fun onSupportNavigateUp(): Boolean { return navController.value?.navigateUp()!! || super.onSupportNavigateUp() } + + override + fun onDestroy() { + super.onDestroy() + + _binding = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseFragment.kt b/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseFragment.kt index 78ab5d4..4b60e71 100644 --- a/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseFragment.kt +++ b/app/src/main/java/com/mina_mikhail/newsapp/core/view/BaseFragment.kt @@ -12,7 +12,8 @@ import com.mina_mikhail.newsapp.core.utils.showLoadingDialog abstract class BaseFragment : Fragment() { - protected lateinit var binding: VB + private var _binding: VB? = null + open val binding get() = _binding!! private var mRootView: View? = null private var hasInitializedRootView = false private var progressDialog: Dialog? = null @@ -27,7 +28,7 @@ abstract class BaseFragment : Fragment() { } private fun initViewBinding(inflater: LayoutInflater, container: ViewGroup?) { - binding = getViewBinding(inflater, container) + _binding = getViewBinding(inflater, container) mRootView = binding.root } @@ -81,4 +82,11 @@ abstract class BaseFragment : Fragment() { } fun hideLoading() = hideLoadingDialog(progressDialog, requireActivity()) + + override + fun onDestroyView() { + super.onDestroyView() + + _binding = null + } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 21918d1..7dc764a 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ buildscript { gson = '2.8.6' interceptor = '4.8.1' pluto = '1.0.2-beta' + play_services = '19.2.0' // UI material_design = '1.4.0' diff --git a/gradle.properties b/gradle.properties index 98bed16..6ae63f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,5 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +android.enableR8=true \ No newline at end of file