0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-10 12:55:06 +00:00

haha databinding and cleanup go brrrr

This commit is contained in:
X1nto 2020-07-17 01:05:31 +04:00
parent db2cb4e04b
commit 0099dab5d6
18 changed files with 180 additions and 196 deletions

View file

@ -8,19 +8,15 @@ import com.vanced.manager.ui.fragments.VancedChangelogFragment
class SectionPageAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { class SectionPageAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
private val fragmentItems = 3 override fun getItemCount(): Int = 3
override fun getItemCount(): Int {
return fragmentItems
}
override fun createFragment(position: Int): Fragment { override fun createFragment(position: Int): Fragment {
var fragment: Fragment? = null return when (position) {
when (position) { 0 -> VancedChangelogFragment()
0 -> fragment = VancedChangelogFragment() 1 -> MicrogChangelogFragment()
1 -> fragment = MicrogChangelogFragment() 2 -> ManagerChangelogFragment()
2 -> fragment = ManagerChangelogFragment() else -> throw NotImplementedError()
} }
return fragment!!
} }
} }

View file

@ -7,18 +7,14 @@ import com.vanced.manager.ui.fragments.VancedChangelogFragment
class SectionPageRootAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { class SectionPageRootAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
private val fragmentItems = 2 override fun getItemCount(): Int = 2
override fun getItemCount(): Int {
return fragmentItems
}
override fun createFragment(position: Int): Fragment { override fun createFragment(position: Int): Fragment {
var fragment: Fragment? = null return when (position) {
when (position) { 0 -> VancedChangelogFragment()
0 -> fragment = VancedChangelogFragment() 1 -> ManagerChangelogFragment()
1 -> fragment = ManagerChangelogFragment() else -> throw NotImplementedError()
} }
return fragment!!
} }
} }

View file

@ -5,8 +5,6 @@ import com.crowdin.platform.Crowdin
import com.crowdin.platform.CrowdinConfig import com.crowdin.platform.CrowdinConfig
import com.crowdin.platform.data.remote.NetworkType import com.crowdin.platform.data.remote.NetworkType
import com.downloader.PRDownloader import com.downloader.PRDownloader
import com.vanced.manager.utils.AppUtils.isPermissionGranted
import com.vanced.manager.utils.AppUtils.requestPermission
import com.vanced.manager.utils.NotificationHelper.createNotifChannel import com.vanced.manager.utils.NotificationHelper.createNotifChannel
class App: Application() { class App: Application() {
@ -21,9 +19,6 @@ class App: Application() {
.withDistributionHash("36c51aed3180a4f43073d28j4s6") .withDistributionHash("36c51aed3180a4f43073d28j4s6")
.withNetworkType(NetworkType.WIFI) .withNetworkType(NetworkType.WIFI)
.build()) .build())
if (!isPermissionGranted(this))
requestPermission()
} }
/* /*

View file

@ -6,12 +6,11 @@ import android.content.Intent
import android.content.pm.PackageInstaller import android.content.pm.PackageInstaller
import android.os.IBinder import android.os.IBinder
import android.util.Log import android.util.Log
import android.widget.Toast
import androidx.annotation.Nullable
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.MiuiHelper import com.vanced.manager.utils.AppUtils.getErrorMessage
import com.vanced.manager.utils.AppUtils.sendRefreshHome
import com.vanced.manager.utils.NotificationHelper.createBasicNotif import com.vanced.manager.utils.NotificationHelper.createBasicNotif
class AppInstallerService: Service() { class AppInstallerService: Service() {
@ -20,7 +19,6 @@ class AppInstallerService: Service() {
val notifId = 42 val notifId = 42
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) { when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> { PackageInstaller.STATUS_PENDING_USER_ACTION -> {
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
Log.d(TAG, "Requesting user confirmation for installation") Log.d(TAG, "Requesting user confirmation for installation")
createBasicNotif(getString(R.string.installing_app, "MicroG"), notifId, this) createBasicNotif(getString(R.string.installing_app, "MicroG"), notifId, this)
val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT) val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
@ -28,15 +26,13 @@ class AppInstallerService: Service() {
try { try {
startActivity(confirmationIntent) startActivity(confirmationIntent)
} catch (e: Exception) { } catch (e: Exception) {
Log.d("VMInstall", "Unable to start installation")
} }
} }
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
Log.d(TAG, "Installation succeed") Log.d(TAG, "Installation succeed")
getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply() getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply()
val mIntent = Intent(MainActivity.INSTALL_COMPLETED) sendRefreshHome(this)
mIntent.action = MainActivity.INSTALL_COMPLETED
mIntent.putExtra("package", "normal")
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
createBasicNotif(getString( createBasicNotif(getString(
R.string.successfully_installed, R.string.successfully_installed,
"Microg" "Microg"
@ -45,7 +41,7 @@ class AppInstallerService: Service() {
else -> { else -> {
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
createBasicNotif( createBasicNotif(
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)), getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this),
notifId, notifId,
this this
) )
@ -58,27 +54,10 @@ class AppInstallerService: Service() {
private fun sendFailure(status: Int) { private fun sendFailure(status: Int) {
val mIntent = Intent(MainActivity.INSTALL_FAILED) val mIntent = Intent(MainActivity.INSTALL_FAILED)
mIntent.action = MainActivity.INSTALL_FAILED mIntent.action = MainActivity.INSTALL_FAILED
mIntent.putExtra("errorMsg", getErrorMessage(status)) mIntent.putExtra("errorMsg", getErrorMessage(status, this))
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent) LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
} }
private fun getErrorMessage(status: Int): String {
return when (status) {
PackageInstaller.STATUS_FAILURE_ABORTED -> getString(R.string.installation_aborted)
PackageInstaller.STATUS_FAILURE_BLOCKED -> getString(R.string.installation_blocked)
PackageInstaller.STATUS_FAILURE_STORAGE -> getString(R.string.installation_storage)
PackageInstaller.STATUS_FAILURE_INVALID -> getString(R.string.installation_invalid)
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> getString(R.string.installation_incompatible)
PackageInstaller.STATUS_FAILURE_CONFLICT -> getString(R.string.installation_conflict)
else ->
if (MiuiHelper.isMiui())
getString(R.string.installation_miui)
else
getString(R.string.installation_failed)
}
}
@Nullable
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder? {
return null return null
} }

View file

@ -8,6 +8,7 @@ import android.os.IBinder
import android.util.Log import android.util.Log
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.AppUtils.sendRefreshHome
class AppUninstallerService: Service() { class AppUninstallerService: Service() {
@ -25,18 +26,13 @@ class AppUninstallerService: Service() {
} }
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
Handler().postDelayed({ Handler().postDelayed({
val mIntent = Intent() sendRefreshHome(this)
mIntent.action = MainActivity.APP_UNINSTALLED
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
Log.d("VMpm", "Successfully uninstalled $pkgName") Log.d("VMpm", "Successfully uninstalled $pkgName")
}, 500) }, 500)
} }
PackageInstaller.STATUS_FAILURE -> { PackageInstaller.STATUS_FAILURE -> {
Handler().postDelayed({ Handler().postDelayed({
val mIntent = Intent() sendRefreshHome(this)
mIntent.action = MainActivity.APP_NOT_UNINSTALLED
mIntent.putExtra("pkgName", pkgName)
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
Log.d("VMpm", "Failed to uninstall $pkgName") Log.d("VMpm", "Failed to uninstall $pkgName")
}, 500) }, 500)
} }

View file

@ -13,6 +13,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.AppUtils
import com.vanced.manager.utils.FileInfo import com.vanced.manager.utils.FileInfo
import com.vanced.manager.utils.NotificationHelper.createBasicNotif import com.vanced.manager.utils.NotificationHelper.createBasicNotif
import java.io.File import java.io.File
@ -77,10 +78,7 @@ class RootSplitInstallerService: Service() {
Log.d("AppLog", "succeeded installing?${installResult.isSuccess}") Log.d("AppLog", "succeeded installing?${installResult.isSuccess}")
getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply() getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply()
if (installResult.isSuccess) { if (installResult.isSuccess) {
val mIntent = Intent(MainActivity.INSTALL_COMPLETED) AppUtils.sendRefreshHome(this)
mIntent.action = MainActivity.INSTALL_COMPLETED
mIntent.putExtra("package", "split")
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
createBasicNotif(getString(R.string.successfully_installed, "Vanced"), notifId, this) createBasicNotif(getString(R.string.successfully_installed, "Vanced"), notifId, this)
} else { } else {
val mIntent = Intent(MainActivity.INSTALL_FAILED) val mIntent = Intent(MainActivity.INSTALL_FAILED)

View file

@ -1,19 +1,16 @@
package com.vanced.manager.core.installer package com.vanced.manager.core.installer
import android.app.Notification
import android.app.Service import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageInstaller import android.content.pm.PackageInstaller
import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.util.Log import android.util.Log
import android.widget.Toast
import androidx.annotation.Nullable
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.MiuiHelper.isMiui import com.vanced.manager.utils.AppUtils.getErrorMessage
import com.vanced.manager.utils.AppUtils.sendRefreshHome
import com.vanced.manager.utils.NotificationHelper.createBasicNotif import com.vanced.manager.utils.NotificationHelper.createBasicNotif
class SplitInstallerService: Service() { class SplitInstallerService: Service() {
@ -22,11 +19,9 @@ class SplitInstallerService: Service() {
val notifId = 666 val notifId = 666
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) { when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> { PackageInstaller.STATUS_PENDING_USER_ACTION -> {
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this) createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this)
Log.d(TAG, "Requesting user confirmation for installation") Log.d(TAG, "Requesting user confirmation for installation")
val confirmationIntent = val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try { try {
startActivity(confirmationIntent) startActivity(confirmationIntent)
@ -36,10 +31,7 @@ class SplitInstallerService: Service() {
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
Log.d(TAG, "Installation succeed") Log.d(TAG, "Installation succeed")
getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply() getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply()
val mIntent = Intent(MainActivity.INSTALL_COMPLETED) sendRefreshHome(this)
mIntent.action = MainActivity.INSTALL_COMPLETED
mIntent.putExtra("package", "split")
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
createBasicNotif( createBasicNotif(
getString(R.string.successfully_installed, "Vanced"), getString(R.string.successfully_installed, "Vanced"),
notifId, notifId,
@ -49,7 +41,7 @@ class SplitInstallerService: Service() {
else -> { else -> {
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
createBasicNotif( createBasicNotif(
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)), getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this),
notifId, notifId,
this this
) )
@ -62,44 +54,10 @@ class SplitInstallerService: Service() {
private fun sendFailure(status: Int) { private fun sendFailure(status: Int) {
val mIntent = Intent(MainActivity.INSTALL_FAILED) val mIntent = Intent(MainActivity.INSTALL_FAILED)
mIntent.action = MainActivity.INSTALL_FAILED mIntent.action = MainActivity.INSTALL_FAILED
mIntent.putExtra("errorMsg", getErrorMessage(status)) mIntent.putExtra("errorMsg", getErrorMessage(status, this))
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent) LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
} }
private fun getErrorMessage(status: Int): String {
return when (status) {
PackageInstaller.STATUS_FAILURE_ABORTED -> getString(R.string.installation_aborted)
PackageInstaller.STATUS_FAILURE_BLOCKED -> getString(R.string.installation_blocked)
PackageInstaller.STATUS_FAILURE_STORAGE -> getString(R.string.installation_storage)
PackageInstaller.STATUS_FAILURE_INVALID -> getString(R.string.installation_invalid)
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> getString(R.string.installation_incompatible)
PackageInstaller.STATUS_FAILURE_CONFLICT -> getString(R.string.installation_conflict)
else ->
if (isMiui())
getString(R.string.installation_miui)
else
getString(R.string.installation_failed)
}
}
private fun startForegroundNotif(text: String) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(this, 666.toString()).setChannelId("69420")
else
Notification.Builder(this).setPriority(Notification.PRIORITY_DEFAULT)
notifBuilder.apply {
setContentTitle(getString(R.string.app_name))
setContentText(text)
setSmallIcon(R.drawable.ic_stat_name)
}
val notif = notifBuilder.build()
startForeground(666, notif)
}
@Nullable
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder? {
return null return null
} }

View file

@ -43,8 +43,6 @@ class MainActivity : AppCompatActivity() {
DialogContainer.regularPackageInstalled(getString(R.string.successfully_installed, "MicroG"), this@MainActivity) DialogContainer.regularPackageInstalled(getString(R.string.successfully_installed, "MicroG"), this@MainActivity)
} }
INSTALL_FAILED -> DialogContainer.installAlertBuilder(intent.getStringExtra("errorMsg") as String, this@MainActivity) INSTALL_FAILED -> DialogContainer.installAlertBuilder(intent.getStringExtra("errorMsg") as String, this@MainActivity)
APP_UNINSTALLED -> restartActivity()
APP_NOT_UNINSTALLED -> DialogContainer.installAlertBuilder(getString(R.string.failed_uninstall, intent.getStringExtra("pkgName")), this@MainActivity)
} }
} }
} }
@ -85,11 +83,6 @@ class MainActivity : AppCompatActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
with(getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit()) {
putBoolean("isInstalling", false).apply()
putBoolean("isVancedDownloading", false).apply()
putBoolean("isMicrogDownloading", false).apply()
}
localBroadcastManager.unregisterReceiver(broadcastReceiver) localBroadcastManager.unregisterReceiver(broadcastReceiver)
Crowdin.unregisterDataLoadingObserver(loadingObserver) Crowdin.unregisterDataLoadingObserver(loadingObserver)
} }
@ -134,10 +127,8 @@ class MainActivity : AppCompatActivity() {
private fun registerReceivers() { private fun registerReceivers() {
val intentFilter = IntentFilter() val intentFilter = IntentFilter()
intentFilter.addAction(INSTALL_COMPLETED) //intentFilter.addAction(INSTALL_COMPLETED)
intentFilter.addAction(INSTALL_FAILED) intentFilter.addAction(INSTALL_FAILED)
intentFilter.addAction(APP_UNINSTALLED)
intentFilter.addAction(APP_NOT_UNINSTALLED)
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter) localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
} }
@ -189,7 +180,5 @@ class MainActivity : AppCompatActivity() {
companion object { companion object {
const val INSTALL_COMPLETED = "install_completed" const val INSTALL_COMPLETED = "install_completed"
const val INSTALL_FAILED = "install_failed" const val INSTALL_FAILED = "install_failed"
const val APP_UNINSTALLED = "app_uninstalled"
const val APP_NOT_UNINSTALLED = "app_not_installed"
} }
} }

View file

@ -1,19 +1,33 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.FileProvider
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.DownloadHelper.download
import com.vanced.manager.utils.InternetTools.getObjectFromJson
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File
class DevSettingsFragment: PreferenceFragmentCompat() { class DevSettingsFragment: PreferenceFragmentCompat() {
private var downloadId: Long = 0
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.dev_settings, rootKey) setPreferencesFromResource(R.xml.dev_settings, rootKey)
activity?.registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
val ftSwitch: Preference? = findPreference("firststart_switch") val ftSwitch: Preference? = findPreference("firststart_switch")
@ -45,5 +59,39 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
archPref?.summary = "32bit" archPref?.summary = "32bit"
} }
val forceUpdate: Preference? = findPreference("force_update")
forceUpdate?.setOnPreferenceClickListener {
runBlocking {
launch {
val url = getObjectFromJson("https://x1nto.github.io/VancedFiles/manager.json", "url")
downloadId = activity?.let { download(url, "apk", "manager.apk", it) }!!
}
}
true
}
} }
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) {
activity?.let {
val apk = File("${activity?.filesDir?.path}/manager.apk")
val uri =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
FileProvider.getUriForFile(activity!!, "${activity?.packageName}.provider", apk)
else
Uri.fromFile(apk)
val mIntent = Intent(Intent.ACTION_VIEW)
mIntent.setDataAndType(uri, "application/vnd.android.package-archive")
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
mIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivity(mIntent)
}
}
}
}
} }

View file

@ -1,8 +1,6 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.content.* import android.content.*
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator import android.view.animation.AccelerateDecelerateInterpolator
@ -26,8 +24,8 @@ class HomeFragment : Home() {
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) } private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
requireActivity().title = getString(R.string.title_home) requireActivity().title = getString(R.string.title_home)
setHasOptionsMenu(true) setHasOptionsMenu(true)
@ -42,15 +40,15 @@ class HomeFragment : Home() {
val variantPref = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot") val variantPref = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
registerReceivers() registerReceivers()
if (variantPref == "root") /*
attachRootChangelog() if (variantPref == "nonroot") {
else {
attachNonrootChangelog()
if (!viewModel.microgInstalled.get()!!) { if (!viewModel.microgInstalled.get()!!) {
disableVancedButton() disableVancedButton()
} }
} }
*/
binding.includeChangelogsLayout.changelogButton.setOnClickListener { binding.includeChangelogsLayout.changelogButton.setOnClickListener {
cardExpandCollapse() cardExpandCollapse()
} }
@ -68,6 +66,25 @@ class HomeFragment : Home() {
versionToast("MicroG") versionToast("MicroG")
true true
} }
with(binding.includeChangelogsLayout) {
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
TabLayoutMediator(tablayout, viewpager) { tab, position ->
if (variantPref == "root")
when (position) {
0 -> tab.text = "Vanced"
1 -> tab.text = "Manager"
}
else
when (position) {
0 -> tab.text = "Vanced"
1 -> tab.text = "MicroG"
2 -> tab.text = "Manager"
}
}.attach()
}
} }
private fun versionToast(name: String) { private fun versionToast(name: String) {
@ -76,8 +93,7 @@ class HomeFragment : Home() {
private fun cardExpandCollapse() { private fun cardExpandCollapse() {
with(binding.includeChangelogsLayout) { with(binding.includeChangelogsLayout) {
viewpager.visibility = if (isExpanded) View.GONE else View.VISIBLE viewModel.expanded.set(!isExpanded)
tablayout.visibility = if (isExpanded) View.GONE else View.VISIBLE
changelogButton.animate().apply { changelogButton.animate().apply {
rotation(if (isExpanded) 0F else 180F) rotation(if (isExpanded) 0F else 180F)
interpolator = AccelerateDecelerateInterpolator() interpolator = AccelerateDecelerateInterpolator()
@ -96,6 +112,7 @@ class HomeFragment : Home() {
when (intent.action) { when (intent.action) {
MICROG_DOWNLOADED -> binding.includeMicrogLayout.microgInstalling.visibility = View.VISIBLE MICROG_DOWNLOADED -> binding.includeMicrogLayout.microgInstalling.visibility = View.VISIBLE
VANCED_DOWNLOADED -> binding.includeVancedLayout.vancedInstalling.visibility = View.VISIBLE VANCED_DOWNLOADED -> binding.includeVancedLayout.vancedInstalling.visibility = View.VISIBLE
REFRESH_HOME -> viewModel.fetchData()
} }
} }
} }
@ -104,41 +121,16 @@ class HomeFragment : Home() {
val intentFilter = IntentFilter() val intentFilter = IntentFilter()
intentFilter.addAction(VANCED_DOWNLOADED) intentFilter.addAction(VANCED_DOWNLOADED)
intentFilter.addAction(MICROG_DOWNLOADED) intentFilter.addAction(MICROG_DOWNLOADED)
intentFilter.addAction(REFRESH_HOME)
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter) localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
} }
private fun attachNonrootChangelog() {
val sectionPageRootAdapter = SectionPageAdapter(this)
with(binding.includeChangelogsLayout) {
viewpager.adapter = sectionPageRootAdapter
TabLayoutMediator(tablayout, viewpager) { tab, position ->
when (position) {
0 -> tab.text = "Vanced"
1 -> tab.text = "MicroG"
2 -> tab.text = "Manager"
}
}.attach()
}
}
private fun attachRootChangelog() {
val sectionPageRootAdapter = SectionPageRootAdapter(this)
with(binding.includeChangelogsLayout) {
viewpager.adapter = sectionPageRootAdapter
TabLayoutMediator(tablayout, viewpager) { tab, position ->
when (position) {
0 -> tab.text = "Vanced"
1 -> tab.text = "Manager"
}
}.attach()
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.toolbar_menu, menu) inflater.inflate(R.menu.toolbar_menu, menu)
super.onCreateOptionsMenu(menu, inflater) super.onCreateOptionsMenu(menu, inflater)
} }
/*
private fun disableVancedButton() { private fun disableVancedButton() {
binding.includeVancedLayout.vancedInstallbtn.apply { binding.includeVancedLayout.vancedInstallbtn.apply {
icon = null icon = null
@ -147,10 +139,12 @@ class HomeFragment : Home() {
setTextColor(ColorStateList.valueOf(Color.GRAY)) setTextColor(ColorStateList.valueOf(Color.GRAY))
} }
} }
*/
companion object { companion object {
const val VANCED_DOWNLOADED = "vanced_downloaded" const val VANCED_DOWNLOADED = "vanced_downloaded"
const val MICROG_DOWNLOADED = "microg_downloaded" const val MICROG_DOWNLOADED = "microg_downloaded"
const val REFRESH_HOME = "refresh_home"
} }
} }

View file

@ -16,8 +16,6 @@ import androidx.lifecycle.AndroidViewModel
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.crowdin.platform.Crowdin import com.crowdin.platform.Crowdin
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.ui.fragments.UpdateCheckFragment
import com.vanced.manager.utils.InternetTools
import com.vanced.manager.utils.InternetTools.getJsonInt import com.vanced.manager.utils.InternetTools.getJsonInt
import com.vanced.manager.utils.InternetTools.getJsonString import com.vanced.manager.utils.InternetTools.getJsonString
import com.vanced.manager.utils.PackageHelper.isPackageInstalled import com.vanced.manager.utils.PackageHelper.isPackageInstalled
@ -57,14 +55,19 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
val nonrootModeSelected: Boolean = variant == "nonroot" val nonrootModeSelected: Boolean = variant == "nonroot"
val expanded = ObservableField<Boolean>()
val fetching = ObservableField<Boolean>() val fetching = ObservableField<Boolean>()
val shouldBeDisabled = ObservableField<Boolean>()
//this too //this too
fun fetchData() { fun fetchData() {
runBlocking { runBlocking {
launch { launch {
fetching.set(true) fetching.set(true)
Crowdin.forceUpdate(getApplication()) Crowdin.forceUpdate(getApplication())
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
vancedVersion.set(getJsonString("vanced.json", "version", getApplication())) vancedVersion.set(getJsonString("vanced.json", "version", getApplication()))
microgVersion.set(getJsonString("microg.json", "version", getApplication())) microgVersion.set(getJsonString("microg.json", "version", getApplication()))
microgInstalled.set(isPackageInstalled("com.mgoogle.android.gms", pm)) microgInstalled.set(isPackageInstalled("com.mgoogle.android.gms", pm))
@ -78,22 +81,14 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication())) microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication())) microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
vancedInstallButtonIcon.set( vancedInstallButtonIcon.set(
if (variant == "nonroot") { if (shouldBeDisabled.get()!!) {
if (microgInstalled.get()!!) null
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
else
null
} else } else
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication()) compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
) )
vancedInstallButtonTxt.set( vancedInstallButtonTxt.set(
if (variant == "nonroot") { if (shouldBeDisabled.get()!!) {
if (microgInstalled.get()!!) { getApplication<Application>().getString(R.string.no_microg)
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
} else {
getApplication<Application>().getString(R.string.no_microg)
}
} else } else
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication()) compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
) )
@ -150,6 +145,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
} }
} }
@Suppress("DEPRECATION")
private fun getPkgVerCode(toCheck: Boolean, pkg: String): Int { private fun getPkgVerCode(toCheck: Boolean, pkg: String): Int {
return if (toCheck) { return if (toCheck) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
@ -162,7 +158,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
private fun compareInt(int1: Int, int2: Int, application: Application): String { private fun compareInt(int1: Int, int2: Int, application: Application): String {
return when { return when {
int2 == 0 -> application.getString(R.string.install) int2 == 0 -> application.getString(R.string.install)
int1 > int2 -> application.getString(R.string.update) int2 > int1 -> application.getString(R.string.update)
int2 == int1 -> application.getString(R.string.button_reinstall) int2 == int1 -> application.getString(R.string.button_reinstall)
else -> application.getString(R.string.install) else -> application.getString(R.string.install)
} }
@ -172,7 +168,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
private fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? { private fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? {
return when { return when {
int2 == 0 -> application.getDrawable(R.drawable.ic_download) int2 == 0 -> application.getDrawable(R.drawable.ic_download)
int1 > int2 -> application.getDrawable(R.drawable.ic_update) int2 > int1 -> application.getDrawable(R.drawable.ic_update)
int2 == int1 -> application.getDrawable(R.drawable.ic_done) int2 == int1 -> application.getDrawable(R.drawable.ic_done)
else -> application.getDrawable(R.drawable.ic_download) else -> application.getDrawable(R.drawable.ic_download)
} }

View file

@ -1,19 +1,35 @@
package com.vanced.manager.utils package com.vanced.manager.utils
import android.content.Context import android.content.Context
import android.content.pm.PackageManager import android.content.Intent
import androidx.core.content.ContextCompat.checkSelfPermission import android.content.pm.PackageInstaller
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.R
import com.vanced.manager.ui.fragments.HomeFragment
object AppUtils { object AppUtils {
fun requestPermission(context: Context) { fun sendRefreshHome(context: Context) {
val requestPermissionLauncher = registerForActivityResult() val mIntent = Intent()
mIntent.action = HomeFragment.REFRESH_HOME
mIntent.putExtra("package", "normal")
LocalBroadcastManager.getInstance(context).sendBroadcast(mIntent)
} }
fun isPermissionGranted(context: Context): Boolean { fun getErrorMessage(status: Int, context: Context): String {
//Check Storage Permissions return when (status) {
return checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED PackageInstaller.STATUS_FAILURE_ABORTED -> context.getString(R.string.installation_aborted)
PackageInstaller.STATUS_FAILURE_BLOCKED -> context.getString(R.string.installation_blocked)
PackageInstaller.STATUS_FAILURE_STORAGE -> context.getString(R.string.installation_storage)
PackageInstaller.STATUS_FAILURE_INVALID -> context.getString(R.string.installation_invalid)
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> context.getString(R.string.installation_incompatible)
PackageInstaller.STATUS_FAILURE_CONFLICT -> context.getString(R.string.installation_conflict)
else ->
if (MiuiHelper.isMiui())
context.getString(R.string.installation_miui)
else
context.getString(R.string.installation_failed)
}
} }
} }

View file

@ -25,7 +25,7 @@
android:background="?colorSurface" android:background="?colorSurface"
android:layout_alignParentTop="true"> android:layout_alignParentTop="true">
<com.google.android.material.appbar.MaterialToolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/home_toolbar" android:id="@+id/home_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"

View file

@ -1,8 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout> <layout
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data>
<com.google.android.material.card.MaterialCardView
android:id="@+id/changelog_card" android:id="@+id/changelog_card"
style="@style/MaterialCard"> style="@style/MaterialCard">
@ -39,7 +51,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?colorSurfaceVariant" android:background="?colorSurfaceVariant"
android:visibility="gone" android:visibility="@{viewModel.expanded ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="parent" app:layout_constraintTop_toBottomOf="parent"
app:tabIndicatorColor="?colorPrimary" app:tabIndicatorColor="?colorPrimary"
app:tabSelectedTextColor="?colorPrimary" app:tabSelectedTextColor="?colorPrimary"
@ -51,10 +63,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:visibility="gone" android:visibility="@{viewModel.expanded ? View.VISIBLE : View.GONE}"
tools:visibility="visible" /> tools:visibility="visible" />
</LinearLayout> </LinearLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout> </layout>

View file

@ -15,6 +15,7 @@
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
style="@style/MaterialCard" style="@style/MaterialCard"
app:contentPaddingTop="2dp" app:contentPaddingTop="2dp"
app:contentPaddingBottom="8dp"
android:animateLayoutChanges="true"> android:animateLayoutChanges="true">
<LinearLayout <LinearLayout
@ -24,17 +25,13 @@
<TextView <TextView
style="@style/CardTitle" style="@style/CardTitle"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/useful_links" /> android:text="@string/useful_links" />
<include <include
layout="@layout/include_vanced_medias" layout="@layout/include_vanced_medias"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginTop="2dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
bind:viewModel="@{viewModel}" /> bind:viewModel="@{viewModel}" />
</LinearLayout> </LinearLayout>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
@ -48,7 +49,10 @@
android:id="@+id/vanced_installbtn" android:id="@+id/vanced_installbtn"
style="@style/ButtonStyle" style="@style/ButtonStyle"
android:text="@{viewModel.vancedInstallButtonTxt}" android:text="@{viewModel.vancedInstallButtonTxt}"
android:textColor="@{viewModel.shouldBeDisabled ? @color/LightGray : @color/White}"
android:backgroundTint="@{viewModel.shouldBeDisabled ? @color/Gray : ?colorPrimary}"
app:icon="@{viewModel.vancedInstallButtonIcon}" app:icon="@{viewModel.vancedInstallButtonIcon}"
android:clickable="@{!viewModel.shouldBeDisabled}"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="Vanced">#673AB7</color> <color name="Vanced">#673AB7</color>
<color name="Brave">#FB542B</color> <color name="Brave">#FB542B</color>
<color name="Discord">#7289DA</color> <color name="Discord">#7289DA</color>
@ -8,6 +9,9 @@
<color name="Reddit">#FF4500</color> <color name="Reddit">#FF4500</color>
<color name="GitHub">#17191A</color> <color name="GitHub">#17191A</color>
<color name="White">#ffffff</color>
<color name="Red">#CC0047</color> <color name="Red">#CC0047</color>
<color name="LightGray">#908E8E</color>
<color name="Gray">#5F5E5E</color>
</resources> </resources>

View file

@ -7,6 +7,11 @@
android:title="First start switcher" android:title="First start switcher"
android:summary="Dev only please"/> android:summary="Dev only please"/>
<Preference
android:key="force_update"
android:title="Force Manager Update"
android:summary="Update manager without comparing versionCode"/>
<PreferenceCategory <PreferenceCategory
android:title="Device info"> android:title="Device info">