Merge pull request #214 from TacoTheDank/dev

Library updates and KTX extensions
This commit is contained in:
Tornike Khintibidze 2020-11-05 21:17:45 +04:00 committed by GitHub
commit 83764ec7fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 99 additions and 79 deletions

View File

@ -23,7 +23,7 @@ android {
versionCode 200
versionName "2.0.0 (.nomagiskui)"
vectorDrawables.useSupportLibrary = true
vectorDrawables.useSupportLibrary true
buildConfigField "String[]", "MANAGER_LANGUAGES", "{" + surroundWithQuotes(langs) + "}"
buildConfigField "Boolean", "ENABLE_CROWDIN_AUTH", "false"
@ -41,7 +41,7 @@ android {
}
applicationVariants.all { variant ->
variant.resValue "string", "versionName", variant.versionName
resValue "string", "versionName", versionName
}
buildTypes {
@ -116,20 +116,34 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0-alpha03'
// Other
// JSON parser
implementation 'com.beust:klaxon:5.4'
// Crowdin
implementation 'com.crowdin.platform:mobile-sdk:1.2.0'
// Tips
implementation 'com.github.florent37:viewtooltip:1.2.2'
// HTTP networking
implementation 'com.github.kittinunf.fuel:fuel:2.3.0'
implementation 'com.github.kittinunf.fuel:fuel-coroutines:2.2.3'
implementation 'com.github.kittinunf.fuel:fuel-json:2.2.3'
implementation 'com.github.topjohnwu.libsu:core:3.0.2'
implementation 'com.github.topjohnwu.libsu:io:3.0.2'
implementation 'com.google.android:flexbox:2.0.1'
implementation 'com.google.firebase:firebase-messaging:21.0.0'
implementation 'com.google.firebase:firebase-perf:19.0.9'
implementation 'com.google.firebase:firebase-analytics-ktx:18.0.0'
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
implementation 'com.mindorks.android:prdownloader:0.6.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
// Root permissions
implementation 'com.github.topjohnwu.libsu:core:3.0.2'
implementation 'com.github.topjohnwu.libsu:io:3.0.2'
// Layout
implementation 'com.google.android:flexbox:2.0.1'
// File downloader
implementation 'com.mindorks.android:prdownloader:0.6.0'
// Firebase
implementation 'com.google.firebase:firebase-analytics-ktx:18.0.0'
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
implementation 'com.google.firebase:firebase-messaging:21.0.0'
implementation 'com.google.firebase:firebase-perf:19.0.9'
}

View File

@ -121,7 +121,7 @@ object VancedDownloader {
"lang" -> {
count++
succesfulLangCount++
if (count < lang?.count()!!)
if (count < lang?.size!!)
downloadSplits(context, "lang")
else
startVancedInstall(context)
@ -133,7 +133,7 @@ object VancedDownloader {
if (type == "lang") {
count++
when {
count < lang?.count()!! -> downloadSplits(context, "lang")
count < lang?.size!! -> downloadSplits(context, "lang")
succesfulLangCount == 0 -> {
lang?.add("en")
downloadSplits(context, "lang")

View File

@ -3,8 +3,9 @@ package com.vanced.manager.ui.core
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.vanced.manager.R
import kotlinx.android.synthetic.main.view_preference.view.*
@ -26,7 +27,7 @@ class EmptyPreference @JvmOverloads constructor(
fun setSummary(newSummary: String) {
preference_summary.text = newSummary
preference_summary.visibility = View.VISIBLE
preference_summary.isVisible = true
preference_title.setPadding(0, 0, 0, 0)
}
@ -38,7 +39,7 @@ class EmptyPreference @JvmOverloads constructor(
if (summary != null) {
preference_summary.text = summary
} else {
preference_summary.visibility = View.GONE
preference_summary.isGone = true
preference_title.setPadding(0, 12, 0, 12)
}
preference_title.text = title

View File

@ -6,6 +6,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.widget.CompoundButton
import android.widget.FrameLayout
import androidx.core.content.edit
import androidx.databinding.BindingAdapter
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.vanced.manager.R
@ -36,7 +37,7 @@ class PreferenceSwitch @JvmOverloads constructor(
Log.d("clickTest", "clicked")
}
preference_switch.setOnCheckedChangeListener { buttonView, isChecked ->
prefs.edit().putBoolean(prefKey, isChecked).apply()
prefs.edit { putBoolean(prefKey, isChecked) }
mListener?.onChecked(buttonView, isChecked)
}
}

View File

@ -5,6 +5,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.vanced.manager.R
@ -34,7 +35,7 @@ object DialogContainer {
show()
}
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit().putBoolean("firstLaunch", false).apply()
prefs.edit { putBoolean("firstLaunch", false) }
}
private fun showMiuiDialog(context: Context) {
@ -65,7 +66,7 @@ object DialogContainer {
}
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit().putBoolean("statement", true).apply()
prefs.edit { putBoolean("statement", true) }
}
fun installAlertBuilder(msg: String, context: Context) {

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@ -33,7 +34,7 @@ class ManagerAccentColorDialog : BottomSheetDialogFragment() {
binding.accentSave.setOnClickListener {
val newPref = binding.accentRadiogroup.getCheckedButtonTag()
if (accent != newPref) {
prefs.edit().putString("manager_accent", newPref).apply()
prefs.edit { putString("manager_accent", newPref) }
dismiss()
requireActivity().recreate()
} else {

View File

@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@ -38,7 +39,7 @@ class ManagerLanguageDialog : BottomSheetDialogFragment() {
binding.languageSave.setOnClickListener {
val newPref = binding.languageRadiogroup.getCheckedButtonTag()
if (language != newPref) {
prefs.edit().putString("manager_lang", newPref).apply()
prefs.edit { putString("manager_lang", newPref) }
dismiss()
requireActivity().recreate()
} else {

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@ -33,7 +34,7 @@ class ManagerThemeDialog : BottomSheetDialogFragment() {
binding.themeSave.setOnClickListener {
val newPref = binding.themeRadiogroup.getCheckedButtonTag()
if (theme != newPref) {
prefs.edit().putString("manager_theme", newPref).apply()
prefs.edit { putString("manager_theme", newPref) }
dismiss()
requireActivity().recreate()
} else {

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import androidx.recyclerview.widget.LinearLayoutManager
@ -41,7 +42,7 @@ class SelectAppsDialog : BottomSheetDialogFragment() {
return@setOnClickListener
}
ad.apps.forEach { app ->
prefs.edit().putBoolean("enable_${app.tag}", app.isChecked).apply()
prefs.edit { putBoolean("enable_${app.tag}", app.isChecked) }
}
dismiss()
}

View File

@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.TextView
import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.button.MaterialButton
@ -45,7 +46,7 @@ class URLChangeDialog : DialogFragment() {
}
private fun saveUrl(url: String) {
getDefaultSharedPreferences(requireActivity()).edit().putString("install_url", url).apply()
getDefaultSharedPreferences(requireActivity()).edit { putString("install_url", url) }
requireActivity().fetchData()
dismiss()
}

View File

@ -10,6 +10,7 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.LinearLayout
import android.widget.Toast
import androidx.core.content.edit
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.button.MaterialButton
@ -54,7 +55,7 @@ class VancedLanguageSelectionDialog : BottomSheetDialogFragment() {
return@setOnClickListener
}
prefs?.edit()?.putString("lang", chosenLangs.joinToString())?.apply()
prefs?.edit { putString("lang", chosenLangs.joinToString()) }
dismiss()
}
}

View File

@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.vanced.manager.R
@ -66,7 +67,7 @@ class VancedPreferencesDialog : BottomSheetDialogFragment() {
binding.themeSpinner.onItemSelectedListener = object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
prefs.edit().putString("theme", adapter[position].value).apply()
prefs.edit { putString("theme", adapter[position].value) }
}
override fun onNothingSelected(parent: AdapterView<*>?) {

View File

@ -7,6 +7,7 @@ import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
@ -54,7 +55,7 @@ class AboutFragment : Fragment() {
val devSettings = prefs.getBoolean("devSettings", false)
if (!devSettings) {
Toast.makeText(requireContext(), "Dev options unlocked!", Toast.LENGTH_SHORT).show()
prefs.edit().putBoolean("devSettings", true).apply()
prefs.edit { putBoolean("devSettings", true) }
} else
Toast.makeText(requireContext(), "Dev options already unlocked", Toast.LENGTH_SHORT).show()

View File

@ -1,12 +1,13 @@
package com.vanced.manager.ui.fragments
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
@ -39,8 +40,10 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
.create()
.show()
prefs.edit().putBoolean("firstLaunch", true).apply()
prefs.edit().putBoolean("show_changelog_tooltip", true).apply()
prefs.edit {
putBoolean("firstLaunch", true)
putBoolean("show_changelog_tooltip", true)
}
true
}
@ -54,7 +57,7 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
if (!Settings.canDrawOverlays(requireActivity())) {
val intent = Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + requireActivity().packageName)
("package:" + requireActivity().packageName).toUri()
)
startActivityForResult(intent, 69)
return@setOnPreferenceClickListener true

View File

@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
@ -36,7 +37,7 @@ class GrantRootFragment : Fragment(), View.OnClickListener {
when (v?.id) {
R.id.grant_root_fab -> {
if (Shell.rootAccess()) {
getDefaultSharedPreferences(requireActivity()).edit().putString("vanced_variant", "root").apply()
getDefaultSharedPreferences(requireActivity()).edit { putString("vanced_variant", "root") }
} else {
Toast.makeText(requireActivity(), R.string.root_not_granted, Toast.LENGTH_SHORT).show()
}

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.view.*
import androidx.core.content.edit
import androidx.core.content.res.ResourcesCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
@ -43,7 +44,7 @@ open class HomeFragment : Fragment() {
// Toast.makeText(requireActivity(), getString(R.string.root_not_granted), Toast.LENGTH_SHORT).show()
// }
// val variant = if (tab.position == 1) "root" else "nonroot"
// getDefaultSharedPreferences(requireActivity()).edit().putString("vanced_variant", variant).apply()
// getDefaultSharedPreferences(requireActivity()).edit { putString("vanced_variant", variant) }
// }
//
// override fun onTabUnselected(tab: TabLayout.Tab) {
@ -86,7 +87,7 @@ open class HomeFragment : Fragment() {
.withShadow(false)
.corner(25)
.onHide {
prefs.edit().putBoolean("show_changelog_tooltip", false).apply()
prefs.edit { putBoolean("show_changelog_tooltip", false) }
}
.text(requireActivity().getString(R.string.app_changelog_tooltip))
@ -159,7 +160,7 @@ open class HomeFragment : Fragment() {
// with(binding) {
// if (mainTablayout.visibility != View.GONE) {
// mainTablayout.startAnimation(tabHide)
// mainTablayout.visibility = View.GONE
// mainTablayout.isVisible = false
// }
// mainViewpager.isUserInputEnabled = false
// }
@ -169,7 +170,7 @@ open class HomeFragment : Fragment() {
// val tabShow = AnimationUtils.loadAnimation(requireActivity(), R.anim.tablayout_enter)
// with(binding) {
// if (mainTablayout.visibility != View.VISIBLE) {
// mainTablayout.visibility = View.VISIBLE
// mainTablayout.isVisible = true
// mainTablayout.startAnimation(tabShow)
// }
// mainViewpager.isUserInputEnabled = true

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
@ -43,7 +44,7 @@ class SelectAppsFragment : Fragment() {
}
selectAdapter.apps.forEach { app ->
prefs.edit().putBoolean("enable_${app.tag}", app.isChecked).apply()
prefs.edit { putBoolean("enable_${app.tag}", app.isChecked) }
}
findNavController().navigate(SelectAppsFragmentDirections.selectAppsToGrantRoot())

View File

@ -3,8 +3,4 @@ package com.vanced.manager.ui.viewmodels
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
class SettingsViewModel(activity: FragmentActivity) : ViewModel() {
}
class SettingsViewModel(activity: FragmentActivity) : ViewModel()

View File

@ -8,6 +8,8 @@ import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.core.content.FileProvider
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.databinding.ObservableField
import com.downloader.OnDownloadListener
import com.downloader.PRDownloader
@ -22,14 +24,14 @@ import java.io.File
object DownloadHelper {
fun download(url: String, dir: String, child: String, context: Context): Long {
val request = DownloadManager.Request(Uri.parse(url)).apply {
val request = DownloadManager.Request(url.toUri()).apply {
setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
setTitle(context.getString(R.string.downloading_file, child))
setDestinationInExternalFilesDir(context, dir, child)
}
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val downloadManager = context.getSystemService<DownloadManager>()!!
return downloadManager.enqueue(request)
}

View File

@ -2,10 +2,10 @@ package com.vanced.manager.utils
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.vanced.manager.BuildConfig
import com.vanced.manager.R
@ -15,16 +15,16 @@ object InternetTools {
private const val TAG = "VMNetTools"
fun openUrl(Url: String, color: Int, context: Context) {
fun openUrl(url: String, color: Int, context: Context) {
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_customtabs", true)
if (customTabPrefs) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(context, color))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(context, Uri.parse(Url))
customTabsIntent.launchUrl(context, url.toUri())
} else
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
context.startActivity(Intent(Intent.ACTION_VIEW, url.toUri()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
}
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)

View File

@ -9,7 +9,7 @@ import com.github.kittinunf.fuel.httpGet
object JsonHelper {
var dataMap: HashMap<String, JsonObject> = HashMap()
private var dataMap: HashMap<String, JsonObject> = HashMap()
suspend fun getJson(url: String): JsonObject? {
return try {

View File

@ -1,13 +1,12 @@
package com.vanced.manager.utils
import android.text.TextUtils
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
object MiuiHelper {
fun isMiui(): Boolean = !TextUtils.isEmpty(getSystemProps("ro.miui.ui.version.name"))
fun isMiui(): Boolean = getSystemProps("ro.miui.ui.version.name")!!.isNotEmpty()
private fun getSystemProps(propname: String): String? {
val line: String

View File

@ -29,7 +29,7 @@ import kotlin.collections.ArrayList
import kotlin.collections.HashMap
object PackageHelper {
private const val apkInstallPath = "/data/adb/Vanced/"
fun isPackageInstalled(packageName: String, packageManager: PackageManager): Boolean {
return try {
@ -116,7 +116,7 @@ object PackageHelper {
e.printStackTrace()
}
}
fun install(path: String, context: Context) {
val callbackIntent = Intent(context, AppInstallerService::class.java)
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
@ -136,7 +136,7 @@ object PackageHelper {
outputStream.close()
session.commit(pendingIntent.intentSender)
}
fun installVanced(context: Context): Int {
val apkFolderPath = context.getExternalFilesDir("vanced/nonroot")?.path.toString() + "/"
val nameSizeMap = HashMap<String, Long>()
@ -238,7 +238,7 @@ object PackageHelper {
session!!.close()
}
}
fun installVancedRoot(context: Context) {
CoroutineScope(Dispatchers.IO).launch {
Shell.enableVerboseLogging = BuildConfig.DEBUG
@ -254,11 +254,8 @@ object PackageHelper {
val apkFilesPath = context.getExternalFilesDir("vanced/root")?.path
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
if (fileInfoList != null) {
var modApk: FileInfo? = null
for (file in fileInfoList) {
if (file.name == "dark.apk" || file.name == "black.apk") {
modApk = file
}
val modApk: FileInfo? = fileInfoList.lastOrNull {
it.name == "dark.apk" || it.name == "black.apk"
}
if (modApk != null) {
if (overwriteBase(modApk, fileInfoList, vancedVersionCode!!, context)) {
@ -281,7 +278,7 @@ object PackageHelper {
}
}
private fun installSplitApkFiles(apkFiles: ArrayList<FileInfo>, context: Context) : Boolean {
var sessionId: Int?
Log.d("AppLog", "installing split apk files:$apkFiles")
@ -315,8 +312,8 @@ object PackageHelper {
val installResult = Shell.su("pm install-commit $sessionId").exec()
if (installResult.isSuccess) {
return true
} else
sendFailure(installResult.out, context)
}
sendFailure(installResult.out, context)
return false
}
@ -333,8 +330,9 @@ object PackageHelper {
if (parentFile.exists() && parentFile.canRead()) {
val listFiles = parentFile.listFiles() ?: return ArrayList()
for (file in listFiles)
result.add(FileInfo(file.name, file.length(), file))
listFiles.mapTo(result) {
FileInfo(it.name, it.length(), it)
}
return result
}
val longLines = Shell.su("ls -l $splitApkPath").exec().out
@ -425,9 +423,7 @@ object PackageHelper {
}
return true
}
else {
return fixNoInstall(baseApkFiles, context)
}
return fixNoInstall(baseApkFiles, context)
}
return fixNoInstall(baseApkFiles, context)
}
@ -508,10 +504,8 @@ object PackageHelper {
return false
}
}
else {
sendFailure(listOf("IFile_Missing").toMutableList(), context)
return false
}
sendFailure(listOf("IFile_Missing").toMutableList(), context)
return false
}
@ -534,14 +528,12 @@ object PackageHelper {
if(execRes.isSuccess) {
val result = execRes.out
var version = 0
for(line in result) {
val versionCode = line.substringAfter("=")
val versionCodeFiltered = versionCode.substringBefore(" ")
if(version < Integer.valueOf(versionCodeFiltered))
{
version = Integer.valueOf(versionCodeFiltered)
}
}
result
.asSequence()
.map { it.substringAfter("=") }
.map { it.substringBefore(" ") }
.filter { version < Integer.valueOf(it) }
.forEach { version = Integer.valueOf(it) }
return version
}
}