2020-04-03 16:40:54 +00:00
|
|
|
package com.vanced.manager.ui
|
2020-03-16 15:41:57 +00:00
|
|
|
|
2020-07-02 10:23:12 +00:00
|
|
|
import android.content.Context
|
2020-03-16 15:41:57 +00:00
|
|
|
import android.os.Bundle
|
2020-06-22 17:28:45 +00:00
|
|
|
import android.util.Log
|
2020-04-05 18:07:26 +00:00
|
|
|
import android.view.MenuItem
|
2020-07-06 14:29:27 +00:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-06-04 07:35:26 +00:00
|
|
|
import androidx.databinding.DataBindingUtil
|
2020-04-19 17:21:40 +00:00
|
|
|
import androidx.navigation.NavDestination
|
2020-04-14 20:54:42 +00:00
|
|
|
import androidx.navigation.findNavController
|
2020-04-22 09:41:18 +00:00
|
|
|
import androidx.navigation.ui.AppBarConfiguration
|
2020-04-14 20:54:42 +00:00
|
|
|
import androidx.navigation.ui.setupWithNavController
|
2020-07-06 14:29:27 +00:00
|
|
|
import androidx.preference.PreferenceManager
|
2020-07-06 11:38:00 +00:00
|
|
|
import com.crowdin.platform.Crowdin
|
|
|
|
import com.crowdin.platform.LoadingStateListener
|
2020-08-26 11:09:34 +00:00
|
|
|
import com.google.android.material.tabs.TabLayoutMediator
|
|
|
|
import com.google.android.material.tabs.TabLayout
|
2020-08-06 07:46:07 +00:00
|
|
|
import com.google.firebase.messaging.FirebaseMessaging
|
2020-04-03 16:40:54 +00:00
|
|
|
import com.vanced.manager.R
|
2020-06-04 07:35:26 +00:00
|
|
|
import com.vanced.manager.databinding.ActivityMainBinding
|
2020-07-06 14:29:27 +00:00
|
|
|
import com.vanced.manager.ui.dialogs.DialogContainer
|
|
|
|
import com.vanced.manager.ui.fragments.UpdateCheckFragment
|
2020-08-08 20:21:08 +00:00
|
|
|
import com.vanced.manager.utils.AppUtils.installing
|
2020-07-06 14:29:27 +00:00
|
|
|
import com.vanced.manager.utils.InternetTools
|
|
|
|
import com.vanced.manager.utils.PackageHelper
|
2020-06-19 15:48:14 +00:00
|
|
|
import com.vanced.manager.utils.ThemeHelper.setFinalTheme
|
2020-08-26 11:09:34 +00:00
|
|
|
import com.vanced.manager.adapter.SectionVariantAdapter
|
2020-08-07 19:24:35 +00:00
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
2020-07-11 21:43:43 +00:00
|
|
|
import kotlinx.coroutines.launch
|
2020-03-16 15:41:57 +00:00
|
|
|
|
2020-07-06 14:29:27 +00:00
|
|
|
class MainActivity : AppCompatActivity() {
|
2020-03-16 15:41:57 +00:00
|
|
|
|
2020-06-04 07:35:26 +00:00
|
|
|
private lateinit var binding: ActivityMainBinding
|
2020-07-04 13:44:28 +00:00
|
|
|
private val navHost by lazy { findNavController(R.id.bottom_nav_host) }
|
2020-05-27 16:37:03 +00:00
|
|
|
|
2020-07-06 11:38:00 +00:00
|
|
|
private val loadingObserver = object : LoadingStateListener {
|
|
|
|
val tag = "VMLocalisation"
|
|
|
|
override fun onDataChanged() {
|
|
|
|
Log.d(tag, "Loaded data")
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onFailure(throwable: Throwable) {
|
|
|
|
Log.d(tag, "Failed to load data")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
setFinalTheme(this)
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
|
|
|
|
|
|
|
|
with(binding) {
|
|
|
|
lifecycleOwner = this@MainActivity
|
|
|
|
setSupportActionBar(homeToolbar)
|
|
|
|
val appBarConfiguration = AppBarConfiguration(navHost.graph)
|
|
|
|
homeToolbar.setupWithNavController(navHost, appBarConfiguration)
|
2020-08-26 11:09:34 +00:00
|
|
|
mainViewpager.adapter = SectionVariantAdapter()
|
|
|
|
TabLayoutMediator(mainTablayout, mainViewpager) { tab, position ->
|
|
|
|
when (position) {
|
|
|
|
0 -> tab.text = "nonroot"
|
|
|
|
1 -> tab.text = "Music"
|
|
|
|
2 -> tab.text = "root"
|
|
|
|
}
|
|
|
|
}.attach()
|
|
|
|
|
|
|
|
when (variant) {
|
|
|
|
"nonroot" -> mainTablayout.getTabAt(0).select()
|
|
|
|
"music" -> mainTablayout.getTabAt(1).select()
|
|
|
|
"nonroot" -> mainTablayout.getTabAt(2).select()
|
|
|
|
}
|
|
|
|
|
|
|
|
mainTablayout.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
|
|
|
|
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) {
|
|
|
|
getDefaultSharedPreferences(requireActivity()).edit().apply {
|
|
|
|
when (tab.position) {
|
|
|
|
0 -> putString("vanced_variant", "nonroot")
|
|
|
|
0 -> putString("vanced_variant", "music")
|
|
|
|
0 -> putString("vanced_variant", "root")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) {}
|
|
|
|
|
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) {
|
|
|
|
getDefaultSharedPreferences(requireActivity()).edit().apply {
|
|
|
|
when (tab.position) {
|
|
|
|
0 -> putString("vanced_variant", "nonroot")
|
|
|
|
0 -> putString("vanced_variant", "music")
|
|
|
|
0 -> putString("vanced_variant", "root")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
navHost.addOnDestinationChangedListener { _, currFrag: NavDestination, _ ->
|
2020-07-04 15:35:23 +00:00
|
|
|
setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment)
|
2020-08-26 11:09:34 +00:00
|
|
|
val tabHide = AnimationUtils.loadAnimation(this, R.anim.tablayout_exit)
|
|
|
|
val tabShow = AnimationUtils.loadAnimation(this, R.anim.tablayout_enter)
|
|
|
|
if (currFrag.id != R.id.home_fragment) {
|
|
|
|
binding.variantTabContainer.startAnimation(tabHide)
|
|
|
|
binding.variantTabContainer.visibility = View.GONE
|
|
|
|
} else {
|
|
|
|
binding.variantTabContainer.visibility = View.VISIBLE
|
|
|
|
binding.variantTabContainer.startAnimation(tabShow)
|
|
|
|
}
|
2020-07-04 13:44:28 +00:00
|
|
|
}
|
2020-07-06 11:38:00 +00:00
|
|
|
|
2020-07-06 14:29:27 +00:00
|
|
|
initDialogs()
|
|
|
|
|
2020-07-04 13:44:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 16:37:03 +00:00
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
2020-07-06 11:38:00 +00:00
|
|
|
Crowdin.unregisterDataLoadingObserver(loadingObserver)
|
2020-05-27 16:37:03 +00:00
|
|
|
}
|
2020-04-19 17:21:40 +00:00
|
|
|
|
2020-05-27 16:37:03 +00:00
|
|
|
override fun onResume() {
|
2020-06-19 15:48:14 +00:00
|
|
|
setFinalTheme(this)
|
2020-05-27 16:37:03 +00:00
|
|
|
super.onResume()
|
2020-08-06 07:46:07 +00:00
|
|
|
Crowdin.registerDataLoadingObserver(loadingObserver)
|
2020-04-05 18:07:26 +00:00
|
|
|
}
|
|
|
|
|
2020-04-19 17:21:40 +00:00
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
2020-08-08 20:21:08 +00:00
|
|
|
if (installing) {
|
2020-08-06 07:46:07 +00:00
|
|
|
return false
|
2020-08-06 17:17:40 +00:00
|
|
|
}
|
2020-08-06 07:46:07 +00:00
|
|
|
when (item.itemId) {
|
|
|
|
android.R.id.home -> {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
2020-04-19 17:21:40 +00:00
|
|
|
}
|
2020-08-06 07:46:07 +00:00
|
|
|
R.id.toolbar_about -> {
|
|
|
|
navHost.navigate(R.id.toAboutFragment)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
R.id.toolbar_settings -> {
|
|
|
|
navHost.navigate(R.id.action_settingsFragment)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
R.id.dev_settings -> {
|
|
|
|
navHost.navigate(R.id.toDevSettingsFragment)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
2020-04-05 18:07:26 +00:00
|
|
|
}
|
2020-08-06 07:46:07 +00:00
|
|
|
|
2020-04-24 16:10:29 +00:00
|
|
|
return false
|
2020-04-19 17:21:40 +00:00
|
|
|
}
|
2020-05-14 06:27:07 +00:00
|
|
|
|
2020-04-19 17:21:40 +00:00
|
|
|
private fun setDisplayHomeAsUpEnabled(isNeeded: Boolean) {
|
2020-07-04 13:44:28 +00:00
|
|
|
binding.homeToolbar.navigationIcon = if (isNeeded) getDrawable(R.drawable.ic_keyboard_backspace_black_24dp) else null
|
2020-07-06 11:38:00 +00:00
|
|
|
}
|
2020-07-04 13:44:28 +00:00
|
|
|
|
2020-07-06 11:38:00 +00:00
|
|
|
override fun attachBaseContext(newBase: Context) {
|
|
|
|
super.attachBaseContext(Crowdin.wrapContext(newBase))
|
2020-04-05 18:07:26 +00:00
|
|
|
}
|
2020-05-27 16:37:03 +00:00
|
|
|
|
2020-07-06 14:29:27 +00:00
|
|
|
private fun initDialogs() {
|
|
|
|
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
val variant = prefs.getString("vanced_variant", "nonroot")
|
|
|
|
val showRootDialog = prefs.getBoolean("show_root_dialog", true)
|
|
|
|
|
|
|
|
when {
|
2020-08-06 07:46:07 +00:00
|
|
|
prefs.getBoolean("firstStart", true) -> {
|
|
|
|
DialogContainer.showSecurityDialog(this)
|
|
|
|
with(FirebaseMessaging.getInstance()) {
|
|
|
|
subscribeToTopic("Vanced-Update")
|
|
|
|
subscribeToTopic("MicroG-Update")
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 14:29:27 +00:00
|
|
|
!prefs.getBoolean("statement", true) -> DialogContainer.statementFalse(this)
|
|
|
|
variant == "root" -> {
|
|
|
|
|
|
|
|
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() {
|
2020-08-08 20:21:08 +00:00
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
2020-08-07 19:24:35 +00:00
|
|
|
if (InternetTools.isUpdateAvailable()) {
|
2020-08-08 20:21:08 +00:00
|
|
|
UpdateCheckFragment().show(supportFragmentManager, "UpdateCheck")
|
2020-07-11 21:43:43 +00:00
|
|
|
}
|
2020-07-06 14:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 15:41:57 +00:00
|
|
|
}
|