0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-27 05:23:00 +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) {
private val fragmentItems = 3
override fun getItemCount(): Int {
return fragmentItems
}
override fun getItemCount(): Int = 3
override fun createFragment(position: Int): Fragment {
var fragment: Fragment? = null
when (position) {
0 -> fragment = VancedChangelogFragment()
1 -> fragment = MicrogChangelogFragment()
2 -> fragment = ManagerChangelogFragment()
return when (position) {
0 -> VancedChangelogFragment()
1 -> MicrogChangelogFragment()
2 -> 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) {
private val fragmentItems = 2
override fun getItemCount(): Int {
return fragmentItems
}
override fun getItemCount(): Int = 2
override fun createFragment(position: Int): Fragment {
var fragment: Fragment? = null
when (position) {
0 -> fragment = VancedChangelogFragment()
1 -> fragment = ManagerChangelogFragment()
return when (position) {
0 -> VancedChangelogFragment()
1 -> 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.data.remote.NetworkType
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
class App: Application() {
@ -21,9 +19,6 @@ class App: Application() {
.withDistributionHash("36c51aed3180a4f43073d28j4s6")
.withNetworkType(NetworkType.WIFI)
.build())
if (!isPermissionGranted(this))
requestPermission()
}
/*

View file

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

View file

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

View file

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

View file

@ -1,19 +1,16 @@
package com.vanced.manager.core.installer
import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInstaller
import android.os.Build
import android.os.IBinder
import android.util.Log
import android.widget.Toast
import androidx.annotation.Nullable
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.R
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
class SplitInstallerService: Service() {
@ -22,11 +19,9 @@ class SplitInstallerService: Service() {
val notifId = 666
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this)
Log.d(TAG, "Requesting user confirmation for installation")
val confirmationIntent =
intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
startActivity(confirmationIntent)
@ -36,10 +31,7 @@ class SplitInstallerService: Service() {
PackageInstaller.STATUS_SUCCESS -> {
Log.d(TAG, "Installation succeed")
getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply()
val mIntent = Intent(MainActivity.INSTALL_COMPLETED)
mIntent.action = MainActivity.INSTALL_COMPLETED
mIntent.putExtra("package", "split")
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
sendRefreshHome(this)
createBasicNotif(
getString(R.string.successfully_installed, "Vanced"),
notifId,
@ -49,7 +41,7 @@ class SplitInstallerService: Service() {
else -> {
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
createBasicNotif(
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)),
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this),
notifId,
this
)
@ -62,44 +54,10 @@ class SplitInstallerService: Service() {
private fun sendFailure(status: Int) {
val mIntent = Intent(MainActivity.INSTALL_FAILED)
mIntent.action = MainActivity.INSTALL_FAILED
mIntent.putExtra("errorMsg", getErrorMessage(status))
mIntent.putExtra("errorMsg", getErrorMessage(status, this))
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? {
return null
}

View file

@ -43,8 +43,6 @@ class MainActivity : AppCompatActivity() {
DialogContainer.regularPackageInstalled(getString(R.string.successfully_installed, "MicroG"), 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() {
super.onPause()
with(getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit()) {
putBoolean("isInstalling", false).apply()
putBoolean("isVancedDownloading", false).apply()
putBoolean("isMicrogDownloading", false).apply()
}
localBroadcastManager.unregisterReceiver(broadcastReceiver)
Crowdin.unregisterDataLoadingObserver(loadingObserver)
}
@ -134,10 +127,8 @@ class MainActivity : AppCompatActivity() {
private fun registerReceivers() {
val intentFilter = IntentFilter()
intentFilter.addAction(INSTALL_COMPLETED)
//intentFilter.addAction(INSTALL_COMPLETED)
intentFilter.addAction(INSTALL_FAILED)
intentFilter.addAction(APP_UNINSTALLED)
intentFilter.addAction(APP_NOT_UNINSTALLED)
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
}
@ -189,7 +180,5 @@ class MainActivity : AppCompatActivity() {
companion object {
const val INSTALL_COMPLETED = "install_completed"
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
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.core.content.FileProvider
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.vanced.manager.R
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() {
private var downloadId: Long = 0
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.dev_settings, rootKey)
activity?.registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
val ftSwitch: Preference? = findPreference("firststart_switch")
@ -45,5 +59,39 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
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
import android.content.*
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator
@ -26,8 +24,8 @@ class HomeFragment : Home() {
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
requireActivity().title = getString(R.string.title_home)
setHasOptionsMenu(true)
@ -42,15 +40,15 @@ class HomeFragment : Home() {
val variantPref = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
registerReceivers()
if (variantPref == "root")
attachRootChangelog()
else {
attachNonrootChangelog()
/*
if (variantPref == "nonroot") {
if (!viewModel.microgInstalled.get()!!) {
disableVancedButton()
}
}
*/
binding.includeChangelogsLayout.changelogButton.setOnClickListener {
cardExpandCollapse()
}
@ -68,6 +66,25 @@ class HomeFragment : Home() {
versionToast("MicroG")
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) {
@ -76,8 +93,7 @@ class HomeFragment : Home() {
private fun cardExpandCollapse() {
with(binding.includeChangelogsLayout) {
viewpager.visibility = if (isExpanded) View.GONE else View.VISIBLE
tablayout.visibility = if (isExpanded) View.GONE else View.VISIBLE
viewModel.expanded.set(!isExpanded)
changelogButton.animate().apply {
rotation(if (isExpanded) 0F else 180F)
interpolator = AccelerateDecelerateInterpolator()
@ -96,6 +112,7 @@ class HomeFragment : Home() {
when (intent.action) {
MICROG_DOWNLOADED -> binding.includeMicrogLayout.microgInstalling.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()
intentFilter.addAction(VANCED_DOWNLOADED)
intentFilter.addAction(MICROG_DOWNLOADED)
intentFilter.addAction(REFRESH_HOME)
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) {
inflater.inflate(R.menu.toolbar_menu, menu)
super.onCreateOptionsMenu(menu, inflater)
}
/*
private fun disableVancedButton() {
binding.includeVancedLayout.vancedInstallbtn.apply {
icon = null
@ -147,10 +139,12 @@ class HomeFragment : Home() {
setTextColor(ColorStateList.valueOf(Color.GRAY))
}
}
*/
companion object {
const val VANCED_DOWNLOADED = "vanced_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 com.crowdin.platform.Crowdin
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.getJsonString
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
@ -57,14 +55,19 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
val nonrootModeSelected: Boolean = variant == "nonroot"
val expanded = ObservableField<Boolean>()
val fetching = ObservableField<Boolean>()
val shouldBeDisabled = ObservableField<Boolean>()
//this too
fun fetchData() {
runBlocking {
launch {
fetching.set(true)
Crowdin.forceUpdate(getApplication())
shouldBeDisabled.set(nonrootModeSelected && !microgInstalled.get()!!)
vancedVersion.set(getJsonString("vanced.json", "version", getApplication()))
microgVersion.set(getJsonString("microg.json", "version", getApplication()))
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()))
microgInstallButtonIcon.set(compareIntDrawable(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))
vancedInstallButtonIcon.set(
if (variant == "nonroot") {
if (microgInstalled.get()!!)
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
else
null
if (shouldBeDisabled.get()!!) {
null
} else
compareIntDrawable(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
)
vancedInstallButtonTxt.set(
if (variant == "nonroot") {
if (microgInstalled.get()!!) {
compareInt(vancedVersionCode.get()!!, vancedInstalledVersionCode.get()!!, getApplication())
} else {
getApplication<Application>().getString(R.string.no_microg)
}
if (shouldBeDisabled.get()!!) {
getApplication<Application>().getString(R.string.no_microg)
} else
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 {
return if (toCheck) {
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 {
return when {
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)
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? {
return when {
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)
else -> application.getDrawable(R.drawable.ic_download)
}

View file

@ -1,19 +1,35 @@
package com.vanced.manager.utils
import android.content.Context
import android.content.pm.PackageManager
import androidx.core.content.ContextCompat.checkSelfPermission
import android.content.Intent
import android.content.pm.PackageInstaller
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.R
import com.vanced.manager.ui.fragments.HomeFragment
object AppUtils {
fun requestPermission(context: Context) {
val requestPermissionLauncher = registerForActivityResult()
fun sendRefreshHome(context: Context) {
val mIntent = Intent()
mIntent.action = HomeFragment.REFRESH_HOME
mIntent.putExtra("package", "normal")
LocalBroadcastManager.getInstance(context).sendBroadcast(mIntent)
}
fun isPermissionGranted(context: Context): Boolean {
//Check Storage Permissions
return checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
fun getErrorMessage(status: Int, context: Context): String {
return when (status) {
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:layout_alignParentTop="true">
<com.google.android.material.appbar.MaterialToolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"

View file

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

View file

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

View file

@ -1,5 +1,6 @@
<?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:tools="http://schemas.android.com/tools">
@ -48,7 +49,10 @@
android:id="@+id/vanced_installbtn"
style="@style/ButtonStyle"
android:text="@{viewModel.vancedInstallButtonTxt}"
android:textColor="@{viewModel.shouldBeDisabled ? @color/LightGray : @color/White}"
android:backgroundTint="@{viewModel.shouldBeDisabled ? @color/Gray : ?colorPrimary}"
app:icon="@{viewModel.vancedInstallButtonIcon}"
android:clickable="@{!viewModel.shouldBeDisabled}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View file

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

View file

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