From b5026a775819ed0de4b1edde75a1aca650a0b6d1 Mon Sep 17 00:00:00 2001 From: X1nto Date: Thu, 6 Aug 2020 11:46:07 +0400 Subject: [PATCH] bug fixes and improvements --- .github/workflows/debug.yml | 5 + .../core/downloader/MicrogDownloadService.kt | 2 +- .../core/downloader/VancedDownloadService.kt | 2 +- .../com/vanced/manager/ui/MainActivity.kt | 80 +++++-------- .../manager/ui/dialogs/DialogContainer.kt | 17 ++- .../manager/ui/fragments/SettingsFragment.kt | 105 +++++++++++------- .../VancedLanguageSelectionFragment.kt | 5 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/values-v23/themes.xml | 2 +- app/src/main/res/values/strings.xml | 6 +- app/src/main/res/values/themes.xml | 20 ++-- app/src/main/res/xml/preferences.xml | 10 +- 12 files changed, 137 insertions(+), 119 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 451a1b4b..a643436a 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -18,6 +18,11 @@ jobs: with: java-version: 1.8 + - name: Write firebase config to file + run: echo $FIREBASE_CONFIG > app/google-services.json + env: + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + - name: Grant rights run: chmod +x ./gradlew diff --git a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt index e04dc625..e1b96623 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt @@ -45,7 +45,7 @@ class MicrogDownloadService: Service() { .build() .setOnProgressListener { progress -> val mProgress = progress.currentBytes * 100 / progress.totalBytes - localBroadcastManager.sendBroadcast(Intent(HomeFragment.MICROG_DOWNLOADING).putExtra("progress", mProgress).putExtra("file", getFileNameFromUrl(url))) + localBroadcastManager.sendBroadcast(Intent(HomeFragment.MICROG_DOWNLOADING).putExtra("progress", mProgress.toInt()).putExtra("file", getFileNameFromUrl(url))) } .start(object : OnDownloadListener { override fun onDownloadComplete() { diff --git a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt index c7869c3b..225647e9 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt @@ -71,7 +71,7 @@ class VancedDownloadService: Service() { .build() .setOnProgressListener { progress -> val mProgress = progress.currentBytes * 100 / progress.totalBytes - localBroadcastManager.sendBroadcast(Intent(HomeFragment.VANCED_DOWNLOADING).putExtra("progress", mProgress).putExtra("file", getFileNameFromUrl(url))) + localBroadcastManager.sendBroadcast(Intent(HomeFragment.VANCED_DOWNLOADING).putExtra("progress", mProgress.toInt()).putExtra("file", getFileNameFromUrl(url))) } .start(object : OnDownloadListener { override fun onDownloadComplete() { 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 6cfb3b6c..cb719681 100644 --- a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt @@ -1,15 +1,11 @@ package com.vanced.manager.ui -import android.content.BroadcastReceiver import android.content.Context -import android.content.Intent -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 @@ -17,6 +13,7 @@ import androidx.navigation.ui.setupWithNavController import androidx.preference.PreferenceManager import com.crowdin.platform.Crowdin import com.crowdin.platform.LoadingStateListener +import com.google.firebase.messaging.FirebaseMessaging import com.vanced.manager.R import com.vanced.manager.databinding.ActivityMainBinding import com.vanced.manager.ui.dialogs.DialogContainer @@ -32,14 +29,6 @@ class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private val navHost by lazy { findNavController(R.id.bottom_nav_host) } - private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) } - - private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { - when (intent.action) { - } - } - } private val loadingObserver = object : LoadingStateListener { val tag = "VMLocalisation" @@ -69,46 +58,45 @@ class MainActivity : AppCompatActivity() { setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment) } - Crowdin.registerDataLoadingObserver(loadingObserver) - initDialogs() } override fun onPause() { super.onPause() - localBroadcastManager.unregisterReceiver(broadcastReceiver) Crowdin.unregisterDataLoadingObserver(loadingObserver) } override fun onResume() { setFinalTheme(this) super.onResume() - registerReceivers() + Crowdin.registerDataLoadingObserver(loadingObserver) } override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (!isInstallationRunning(this)) { - when (item.itemId) { - android.R.id.home -> { - onBackPressed() - return true - } - 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) + if (isInstallationRunning(this)) + return false + + when (item.itemId) { + android.R.id.home -> { + onBackPressed() + return true } + 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) } + return false } @@ -120,25 +108,19 @@ class MainActivity : AppCompatActivity() { super.attachBaseContext(Crowdin.wrapContext(newBase)) } - private fun registerReceivers() { - val intentFilter = IntentFilter() - localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter) - - } - - fun restartActivity() { - startActivity(Intent(this@MainActivity, MainActivity::class.java)) - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) - 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("firstStart", true) -> { + DialogContainer.showSecurityDialog(this) + with(FirebaseMessaging.getInstance()) { + subscribeToTopic("Vanced-Update") + subscribeToTopic("MicroG-Update") + } + } !prefs.getBoolean("statement", true) -> DialogContainer.statementFalse(this) variant == "root" -> { if (showRootDialog) @@ -170,6 +152,4 @@ class MainActivity : AppCompatActivity() { } } - companion object { - } } diff --git a/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt b/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt index 29426046..0c57997e 100644 --- a/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt +++ b/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt @@ -17,13 +17,17 @@ object DialogContainer { MaterialAlertDialogBuilder(context) .setTitle(context.resources.getString(R.string.welcome)) .setMessage(context.resources.getString(R.string.security_context)) - .setCancelable(false) .setPositiveButton(context.resources.getString(R.string.close)) { dialog, _ -> - run { - dialog.dismiss() - if (MiuiHelper.isMiui()) { - showMiuiDialog(context) - } + dialog.dismiss() + } + .setOnDismissListener { + if (MiuiHelper.isMiui()) { + showMiuiDialog(context) + } + } + .setOnCancelListener { + if (MiuiHelper.isMiui()) { + showMiuiDialog(context) } } .create() @@ -57,6 +61,7 @@ object DialogContainer { openUrl("https://lmgtfy.com/?q=andnixsh+apk+verification+disable", R.color.Twitter, activity) } .setOnDismissListener { PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean("show_root_dialog", false).apply() } + .setOnCancelListener { PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean("show_root_dialog", false).apply() } .create() .show() } diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt index f83c5022..c1e0819f 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt @@ -3,10 +3,9 @@ package com.vanced.manager.ui.fragments import android.os.Bundle import android.view.Menu import android.view.MenuInflater -import androidx.preference.ListPreference -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat -import androidx.preference.PreferenceManager +import android.widget.Toast +import androidx.preference.* +import com.google.firebase.messaging.FirebaseMessaging import com.vanced.manager.R class SettingsFragment : PreferenceFragmentCompat() { @@ -17,57 +16,79 @@ class SettingsFragment : PreferenceFragmentCompat() { activity?.title = getString(R.string.title_settings) setHasOptionsMenu(true) - val updateCheck: Preference? = findPreference("update_check") - updateCheck?.setOnPreferenceClickListener { - val fm = childFragmentManager.beginTransaction() - val updateDialog = UpdateCheckFragment() - updateDialog.show(fm, "Update Center") - true - } - - val themeSwitch: ListPreference? = findPreference("theme_mode") - val themePref = preferenceScreen.sharedPreferences.getString("theme_mode", "Follow System") - themeSwitch?.summary = - when (themePref) { - "Light" -> getString(R.string.theme_light) - "Dark" -> getString(R.string.theme_dark) - "Follow System" -> getString(R.string.theme_follow) - else -> "" - } - themeSwitch?.setOnPreferenceChangeListener { _, _ -> - activity?.recreate() + findPreference("update_check")?.setOnPreferenceClickListener { + UpdateCheckFragment().show(childFragmentManager.beginTransaction(), "Update Center") true } - val accentSwitch: ListPreference? = findPreference("accent_color") - val accentPref = preferenceScreen.sharedPreferences.getString("accent_color", "Blue") - accentSwitch?.summary = - when (accentPref) { - "Blue" -> getString(R.string.accent_blue) - "Red" -> getString(R.string.accent_red) - "Green" -> getString(R.string.accent_green) - "Yellow" -> getString(R.string.accent_yellow) - "Purple" -> getString(R.string.accent_purple) - else -> "" + findPreference("vanced_notifs")?.apply { + title = getString(R.string.push_notifications, "Vanced") + summary = getString(R.string.push_notifications_summary, "Vanced") + setOnPreferenceChangeListener { _, newValue -> + when (newValue) { + true -> FirebaseMessaging.getInstance().subscribeToTopic("Vanced-Update") + false -> FirebaseMessaging.getInstance().unsubscribeFromTopic("Vanced-Update") + } + true + } + } + + findPreference("microg_notifs")?.apply { + title = getString(R.string.push_notifications, "microG") + summary = getString(R.string.push_notifications_summary, "microG") + setOnPreferenceChangeListener { _, newValue -> + when (newValue) { + true -> FirebaseMessaging.getInstance().subscribeToTopic("MicroG-Update") + false -> FirebaseMessaging.getInstance().unsubscribeFromTopic("MicroG-Update") + } + Toast.makeText(requireActivity(), "Set value to $newValue", Toast.LENGTH_SHORT).show() + true + } + } + + val themePref = preferenceScreen.sharedPreferences.getString("theme_mode", "Follow System") + findPreference("theme_mode")?.apply { + summary = when (themePref) { + "Light" -> getString(R.string.theme_light) + "Dark" -> getString(R.string.theme_dark) + else -> getString(R.string.theme_follow) + } + setOnPreferenceChangeListener { _, newValue -> + if (themePref != newValue) { + requireActivity().recreate() + return@setOnPreferenceChangeListener true + } + false + } + } + + val accentPref = preferenceScreen.sharedPreferences.getString("accent_color", "Blue") + findPreference("accent_color")?.apply { + summary = when (accentPref) { + "Blue" -> getString(R.string.accent_blue) + "Red" -> getString(R.string.accent_red) + "Green" -> getString(R.string.accent_green) + "Yellow" -> getString(R.string.accent_yellow) + else -> getString(R.string.accent_purple) + } + setOnPreferenceChangeListener { _, newValue -> + if (accentPref != newValue) { + requireActivity().recreate() + return@setOnPreferenceChangeListener true + } + false } - accentSwitch?.setOnPreferenceChangeListener { _, _ -> - activity?.recreate() - true } val chosenPrefs: Preference? = findPreference("vanced_chosen_modes") chosenPrefs?.setOnPreferenceClickListener { - val fm = childFragmentManager.beginTransaction() - val chosenPrefsDialog = ChosenPreferenceDialogFragment() - chosenPrefsDialog.show(fm, "Chosen Preferences") + ChosenPreferenceDialogFragment().show(childFragmentManager.beginTransaction(), "Chosen Preferences") true } val installUrl: Preference? = findPreference("install_url") installUrl?.setOnPreferenceClickListener { - val fm = childFragmentManager.beginTransaction() - val chosenPrefsDialog = URLChangeFragment() - chosenPrefsDialog.show(fm, "Install URL") + URLChangeFragment().show(childFragmentManager.beginTransaction(), "Install URL") true } diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt index 1a9943ce..844d7a5b 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt @@ -48,7 +48,10 @@ class VancedLanguageSelectionFragment : Fragment() { chosenLangs.add(lang) } } - activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)?.edit()?.putString("lang", chosenLangs.joinToString())?.apply() + activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)?.edit()?.apply { + putString("lang", chosenLangs.joinToString())?.apply() + putBoolean("valuesModified", true) + } activity?.startService(Intent(activity, VancedDownloadService::class.java)) view.findNavController().navigate(R.id.action_installTo_homeFragment) } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5c6e1d54..704b46cc 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -25,7 +25,7 @@ android:background="?colorSurface" android:layout_alignParentTop="true"> - #1490D7 #2C7EB9 #3E78AF - #803E78AF + ?colorPrimary #ffffff #F3F3F3 ?colorSurface diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f1d7d6f3..4082da47 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,7 +33,7 @@ Latest: Successfully installed %1$s Network connection unavailable - No MicroG! + microG isn\'t installed Root access not granted Unavailable Update @@ -63,8 +63,8 @@ Dark Theme Light Theme Update Channel URL - Push Notifications - Receive push notifications when an update is released + %1$s Push Notifications + Receive push notifications when an update for %1$s is released Re-check Manager Update Center Update found! diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 417cf349..f7a26a1d 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -8,7 +8,7 @@ #1490D7 #2C7EB9 #3E78AF - #803E78AF + ?colorPrimary #ffffff #F3F3F3 ?colorSurface @@ -40,7 +40,7 @@ #D71414 #B92C2C #AF3E3E - #80AF3E3E + ?colorPrimary @@ -49,7 +49,7 @@ #3ED714 #2CB943 #3EAF51 - #803EAF44 + ?colorPrimary @@ -58,7 +58,7 @@ #ffd500 #A6FFD500 #D3B418 - #B7D3B418 + ?colorPrimary @@ -67,7 +67,7 @@ #6D49B7 #563C8D #734BC7 - #9A734BC7 + ?colorPrimary @@ -78,7 +78,7 @@ #1490D7 #2C7EB9 #3E78AF - #803E78AF + ?colorPrimary #000000 #111111 ?colorSurface @@ -111,7 +111,7 @@ #D71414 #B92C2C #AF3E3E - #80AF3E3E + ?colorPrimary @@ -120,7 +120,7 @@ #3ED714 #2CB943 #3EAF51 - #803EAF44 + ?colorPrimary @@ -129,7 +129,7 @@ #ffd500 #A6FFD500 #D3B418 - #B7D3B418 + ?colorPrimary @@ -138,7 +138,7 @@ #6D49B7 #563C8D #734BC7 - #9A734BC7 + ?colorPrimary diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index bd5b84ed..57424920 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -21,9 +21,13 @@ android:summaryOff="@string/link_external_browser" /> + +