0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 11:45:11 +00:00

all main activity code now belongs to MainActivity.kt

This commit is contained in:
X1nto 2020-07-06 18:29:27 +04:00
parent f90101abb7
commit d3caeb7554
2 changed files with 47 additions and 63 deletions

View file

@ -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")
}
}
}

View file

@ -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"