From d3caeb755409fbff4f08fc9e4ccbbfd626af9958 Mon Sep 17 00:00:00 2001 From: X1nto Date: Mon, 6 Jul 2020 18:29:27 +0400 Subject: [PATCH] all main activity code now belongs to MainActivity.kt --- .../main/java/com/vanced/manager/core/Main.kt | 61 ------------------- .../com/vanced/manager/ui/MainActivity.kt | 49 ++++++++++++++- 2 files changed, 47 insertions(+), 63 deletions(-) delete mode 100644 app/src/main/java/com/vanced/manager/core/Main.kt diff --git a/app/src/main/java/com/vanced/manager/core/Main.kt b/app/src/main/java/com/vanced/manager/core/Main.kt deleted file mode 100644 index ebb7a731..00000000 --- a/app/src/main/java/com/vanced/manager/core/Main.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.vanced.manager.core - -import android.annotation.SuppressLint -import android.content.Context -import android.os.Bundle -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import androidx.preference.PreferenceManager -import com.dezlum.codelabs.getjson.GetJson -import com.vanced.manager.R -import com.vanced.manager.ui.dialogs.DialogContainer.basicDialog -import com.vanced.manager.ui.dialogs.DialogContainer.showRootDialog -import com.vanced.manager.ui.dialogs.DialogContainer.showSecurityDialog -import com.vanced.manager.ui.dialogs.DialogContainer.statementFalse -import com.vanced.manager.ui.fragments.UpdateCheckFragment -import com.vanced.manager.utils.InternetTools.isUpdateAvailable -import com.vanced.manager.utils.PackageHelper.getPackageVersionName - -// This activity will NOT be used in manifest -// since MainActivity will extend it -@SuppressLint("Registered") -open class Main: AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - val prefs = PreferenceManager.getDefaultSharedPreferences(this) - val variant = prefs.getString("vanced_variant", "nonroot") - val showRootDialog = prefs.getBoolean("show_root_dialog", true) - - when { - prefs.getBoolean("firstStart", true) -> showSecurityDialog(this) - !prefs.getBoolean("statement", true) -> statementFalse(this) - variant == "root" -> { - if (showRootDialog) - showRootDialog(this) - - if (getPackageVersionName("com.google.android.youtube", packageManager) == "14.21.54") - basicDialog(getString(R.string.hold_on), getString(R.string.magisk_vanced), this) - } - } - - checkUpdates() - - } - - override fun onPause() { - getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply() - getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isVancedDownloading", false).apply() - getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isMicrogDownloading", false).apply() - super.onPause() - } - - private fun checkUpdates() { - if (GetJson().isConnected(this) && isUpdateAvailable()) { - val fm = supportFragmentManager - UpdateCheckFragment().show(fm, "UpdateCheck") - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt index be030341..897f4bfc 100644 --- a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt @@ -7,23 +7,29 @@ import android.content.IntentFilter import android.os.Bundle import android.util.Log import android.view.MenuItem +import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.navigation.NavDestination import androidx.navigation.findNavController import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.setupWithNavController +import androidx.preference.PreferenceManager import com.crowdin.platform.Crowdin import com.crowdin.platform.LoadingStateListener +import com.dezlum.codelabs.getjson.GetJson import com.vanced.manager.R -import com.vanced.manager.core.Main import com.vanced.manager.databinding.ActivityMainBinding +import com.vanced.manager.ui.dialogs.DialogContainer import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder import com.vanced.manager.ui.dialogs.DialogContainer.launchVanced import com.vanced.manager.ui.dialogs.DialogContainer.regularPackageInstalled +import com.vanced.manager.ui.fragments.UpdateCheckFragment +import com.vanced.manager.utils.InternetTools +import com.vanced.manager.utils.PackageHelper import com.vanced.manager.utils.ThemeHelper.setFinalTheme -class MainActivity : Main() { +class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private val navHost by lazy { findNavController(R.id.bottom_nav_host) } @@ -75,10 +81,15 @@ class MainActivity : Main() { Crowdin.registerDataLoadingObserver(loadingObserver) + initDialogs() + } override fun onPause() { super.onPause() + getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply() + getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isVancedDownloading", false).apply() + getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isMicrogDownloading", false).apply() localBroadcastManager.unregisterReceiver(broadcastReceiver) Crowdin.unregisterDataLoadingObserver(loadingObserver) } @@ -137,6 +148,40 @@ class MainActivity : Main() { finish() } + private fun initDialogs() { + val prefs = PreferenceManager.getDefaultSharedPreferences(this) + val variant = prefs.getString("vanced_variant", "nonroot") + val showRootDialog = prefs.getBoolean("show_root_dialog", true) + + when { + prefs.getBoolean("firstStart", true) -> DialogContainer.showSecurityDialog(this) + !prefs.getBoolean("statement", true) -> DialogContainer.statementFalse(this) + variant == "root" -> { + if (showRootDialog) + DialogContainer.showRootDialog(this) + + if (PackageHelper.getPackageVersionName( + "com.google.android.youtube", + packageManager + ) == "14.21.54") + DialogContainer.basicDialog( + getString(R.string.hold_on), + getString(R.string.magisk_vanced), + this + ) + } + } + + checkUpdates() + } + + private fun checkUpdates() { + if (GetJson().isConnected(this) && InternetTools.isUpdateAvailable()) { + val fm = supportFragmentManager + UpdateCheckFragment().show(fm, "UpdateCheck") + } + } + companion object { const val INSTALL_COMPLETED = "install_completed" const val INSTALL_FAILED = "install_failed"