diff --git a/app/build.gradle b/app/build.gradle index a4a687d2..9e4cc0a0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,7 +21,7 @@ android { minSdkVersion 21 targetSdkVersion 30 versionCode 13 - versionName "1.3.0b (Arcturus)" + versionName "1.3.0 (Arcturus)" vectorDrawables.useSupportLibrary = true @@ -88,11 +88,9 @@ def getLanguageNames() { for (int i = 0; i < langs.size(); i++) { if (langs[i].length() > 2) { Locale loc = new Locale(langs[i].substring(0, langs[i].length() - 3), langs[i].substring(langs[i].length() - 2)) - project.logger.lifecycle(loc.getDisplayLanguage(loc).capitalize() + " (" + loc.getDisplayCountry(loc).capitalize() + ")") langnames.add(loc.getDisplayLanguage(loc).capitalize() + " (" + loc.getDisplayCountry(loc).capitalize() + ")") } else { Locale loc = new Locale(langs[i]) - project.logger.lifecycle(loc.getDisplayLanguage(loc).capitalize()) langnames.add(loc.getDisplayLanguage(loc).capitalize()) } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b9fbff4c..4f38c80b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ + @@ -45,6 +46,7 @@ android:name=".ui.MainActivity" android:label="@string/app_name" android:theme="@style/DarkTheme.Blue" + android:configChanges="layoutDirection|locale" android:exported="true"/> () { diff --git a/app/src/main/java/com/vanced/manager/core/App.kt b/app/src/main/java/com/vanced/manager/core/App.kt index d4b8ab3b..79b6b04c 100644 --- a/app/src/main/java/com/vanced/manager/core/App.kt +++ b/app/src/main/java/com/vanced/manager/core/App.kt @@ -2,6 +2,7 @@ package com.vanced.manager.core import android.app.Application import android.content.res.Configuration +import androidx.databinding.ObservableField import androidx.preference.PreferenceManager.getDefaultSharedPreferences import com.beust.klaxon.JsonObject import com.crowdin.platform.Crowdin @@ -10,14 +11,14 @@ import com.crowdin.platform.data.remote.NetworkType import com.downloader.PRDownloader import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.JsonHelper.getJson -import kotlinx.coroutines.* +import kotlinx.coroutines.runBlocking open class App: Application() { - var vanced: JsonObject? = null - var music: JsonObject? = null - var microg: JsonObject? = null - var manager: JsonObject? = null + var vanced = ObservableField() + var music = ObservableField() + var microg = ObservableField() + var manager = ObservableField() override fun onCreate() { loadJsonAsync() @@ -33,12 +34,13 @@ open class App: Application() { } - fun loadJsonAsync() { - val latest = runBlocking { getJson("${getDefaultSharedPreferences(this@App).getString("update_url", baseUrl)}/latest.json") } - vanced = latest.obj("vanced") - music = latest.obj("music") - microg = latest.obj("microg") - manager = latest.obj("manager") + open fun loadJsonAsync() { + val latest = runBlocking { getJson("${getDefaultSharedPreferences(this@App).getString("install_url", baseUrl)}/latest.json") } + + vanced.set(latest?.obj("vanced")) + music.set(latest?.obj("music")) + microg.set(latest?.obj("microg")) + manager.set(latest?.obj("manager")) } override fun onConfigurationChanged(newConfig: Configuration) { @@ -46,4 +48,5 @@ open class App: Application() { Crowdin.onConfigurationChanged() } + } diff --git a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloader.kt b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloader.kt index b48b1c50..28d366d3 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloader.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloader.kt @@ -6,10 +6,10 @@ import com.downloader.Error import com.downloader.OnDownloadListener import com.downloader.PRDownloader import com.vanced.manager.R +import com.vanced.manager.core.App import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.microgProgress import com.vanced.manager.utils.AppUtils.mutableInstall import com.vanced.manager.utils.InternetTools.getFileNameFromUrl -import com.vanced.manager.utils.InternetTools.getJsonString import com.vanced.manager.utils.PackageHelper.install import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -21,14 +21,14 @@ object MicrogDownloader { fun downloadMicrog(context: Context) { CoroutineScope(Dispatchers.IO).launch { - val url = getJsonString("microg.json", "url", context) + val url = (context.applicationContext as App).microg.get()?.string("url") //downloadId = download(url, "apk", "microg.apk", this@MicrogDownloadService) microgProgress.get()?.currentDownload = PRDownloader.download(url, context.getExternalFilesDir("apk")?.path, "microg.apk") .build() .setOnStartOrResumeListener { mutableInstall.value = true - microgProgress.get()?.downloadingFile?.set(context.getString(R.string.downloading_file, getFileNameFromUrl(url))) + microgProgress.get()?.downloadingFile?.set(context.getString(R.string.downloading_file, url?.let { getFileNameFromUrl(it) })) microgProgress.get()?.showDownloadBar?.set(true) } .setOnCancelListener { diff --git a/app/src/main/java/com/vanced/manager/core/downloader/MusicDownloader.kt b/app/src/main/java/com/vanced/manager/core/downloader/MusicDownloader.kt index 6917cafd..3884f734 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/MusicDownloader.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/MusicDownloader.kt @@ -6,10 +6,10 @@ import com.downloader.Error import com.downloader.OnDownloadListener import com.downloader.PRDownloader import com.vanced.manager.R +import com.vanced.manager.core.App import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.musicProgress import com.vanced.manager.utils.AppUtils.mutableInstall import com.vanced.manager.utils.InternetTools.getFileNameFromUrl -import com.vanced.manager.utils.InternetTools.getJsonString import com.vanced.manager.utils.PackageHelper.install import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -21,8 +21,7 @@ object MusicDownloader { fun downloadMusic(context: Context){ CoroutineScope(Dispatchers.IO).launch { - val version = getJsonString("music.json", "version", context) - val url = "https://vanced.app/api/v1/music/v$version.apk" + val url = "https://vanced.app/api/v1/music/v${(context.applicationContext as App).music.get()?.string("version")}.apk" //downloadId = download(url, "apk", "music.apk", this@MusicDownloadService) diff --git a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt index 2a1a8761..75485502 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloader.kt @@ -17,7 +17,6 @@ import com.vanced.manager.utils.AppUtils.mutableInstall import com.vanced.manager.utils.InternetTools import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl -import com.vanced.manager.utils.InternetTools.getObjectFromJson import com.vanced.manager.utils.PackageHelper.getPkgVerCode import com.vanced.manager.utils.PackageHelper.installVanced import com.vanced.manager.utils.PackageHelper.installVancedRoot @@ -50,10 +49,11 @@ object VancedDownloader { private const val yPkg = "com.google.android.youtube" private var vancedVersionCode = 0 - private val vancedVersion by lazy { runBlocking { getObjectFromJson("$installUrl/vanced.json", "version") }} + private var vancedVersion: String? = null fun downloadVanced(context: Context){ - //registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) + //registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))val app = context.applicationContext as App + val app = context.applicationContext as App File(context.getExternalFilesDir("apks")?.path as String).deleteRecursively() defPrefs = getDefaultSharedPreferences(context) installUrl = defPrefs.getString("install_url", baseUrl) @@ -61,6 +61,7 @@ object VancedDownloader { variant = defPrefs.getString("vanced_variant", "nonroot") lang = prefs.getString("lang", "en")?.split(", ")?.toTypedArray() theme = prefs.getString("theme", "dark") + vancedVersion = app.vanced.get()?.string("version") themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme" hashUrl = "apks/v$vancedVersion/$variant/Theme/hash.json" //newInstaller = defPrefs.getBoolean("new_installer", false) @@ -70,8 +71,8 @@ object VancedDownloader { Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a" else -> "armeabi_v7a" } - val app = context.applicationContext as App - vancedVersionCode = app.vanced?.int("versionCode") ?: 0 + + vancedVersionCode = app.vanced.get()?.int("versionCode") ?: 0 downloadSplits(context) } diff --git a/app/src/main/java/com/vanced/manager/model/DataModel.kt b/app/src/main/java/com/vanced/manager/model/DataModel.kt index 79fc50c2..f9a7194a 100644 --- a/app/src/main/java/com/vanced/manager/model/DataModel.kt +++ b/app/src/main/java/com/vanced/manager/model/DataModel.kt @@ -15,18 +15,10 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch open class DataModel( - private val jsonObject: JsonObject?, - app: String, + private val jsonObject: ObservableField, + private val appPkg: String, private val context: Context ) { - - private val appPkg = - when (app) { - "vanced" -> "com.vanced.android.youtube" - "vancedRoot" -> "com.google.android.youtube" - "microg" -> "com.mgoogle.android.gms" - else -> "com.vanced.android.apps.youtube.music" - } private val versionCode = ObservableInt() private val installedVersionCode = ObservableInt() @@ -40,13 +32,13 @@ open class DataModel( fun fetch() = CoroutineScope(Dispatchers.IO).launch { isAppInstalled.set(isPackageInstalled(appPkg, context.packageManager)) - versionName.set(jsonObject?.string("version")?.removeSuffix("-vanced") ?: context.getString(R.string.unavailable)) + versionName.set(jsonObject.get()?.string("version")?.removeSuffix("-vanced") ?: context.getString(R.string.unavailable)) installedVersionName.set(getPkgVersionName(isAppInstalled.get(), appPkg)) - versionCode.set(jsonObject?.int("versionCode") ?: 0) + versionCode.set(jsonObject.get()?.int("versionCode") ?: 0) installedVersionCode.set(getPkgVersionCode(isAppInstalled.get(), appPkg)) buttonTxt.set(compareInt(installedVersionCode.get(), versionCode.get())) buttonIcon.set(compareIntDrawable(installedVersionCode.get(), versionCode.get())) - changelog.set(jsonObject?.string("changelog") ?: context.getString(R.string.unavailable)) + changelog.set(jsonObject.get()?.string("changelog") ?: context.getString(R.string.unavailable)) } init { 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 5381509a..cd8fe2f3 100644 --- a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt @@ -2,6 +2,7 @@ package com.vanced.manager.ui import android.content.Context import android.content.Intent +import android.content.res.Configuration import android.os.Bundle import android.util.Log import android.view.MenuItem @@ -117,6 +118,17 @@ class MainActivity : AppCompatActivity() { super.attachBaseContext(LanguageContextWrapper.wrap(newBase)) } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + recreate() //restarting activity to recreate viewmodels, otherwise some text won't update + } + + override fun recreate() { + //needed for setting language smh + startActivity(Intent(this, this::class.java)) + finish() + } + private fun initDialogs() { val prefs = getDefaultSharedPreferences(this) val variant = prefs.getString("vanced_variant", "nonroot") diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/DevSettingsFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/DevSettingsFragment.kt index 89e0db44..3d90d34f 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/DevSettingsFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/DevSettingsFragment.kt @@ -1,23 +1,15 @@ package com.vanced.manager.ui.fragments import android.content.Intent -import android.net.Uri import android.os.Build import android.os.Bundle -import android.util.Log -import android.widget.Toast import androidx.appcompat.app.AlertDialog -import androidx.core.content.FileProvider import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager -import com.downloader.OnDownloadListener -import com.downloader.PRDownloader import com.vanced.manager.R import com.vanced.manager.ui.MainActivity -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import java.io.File +import com.vanced.manager.utils.DownloadHelper.downloadManager class DevSettingsFragment: PreferenceFragmentCompat() { @@ -45,6 +37,12 @@ class DevSettingsFragment: PreferenceFragmentCompat() { true } + + findPreference("install_url")?.setOnPreferenceClickListener { + URLChangeFragment().show(childFragmentManager.beginTransaction(), "Install URL") + true + } + val supportedAbis: Array = Build.SUPPORTED_ABIS findPreference("device_arch")?.summary = @@ -58,38 +56,7 @@ class DevSettingsFragment: PreferenceFragmentCompat() { val forceUpdate: Preference? = findPreference("force_update") forceUpdate?.setOnPreferenceClickListener { - runBlocking { - launch { - val url = "https://github.com/YTVanced/VancedManager/releases/latest/download/manager.apk" - //downloadId = activity?.let { download(url, "apk", "manager.apk", it) }!! - PRDownloader.download(url, activity?.getExternalFilesDir("apk")?.path, "manager.apk") - .build() - .start(object : OnDownloadListener { - override fun onDownloadComplete() { - activity?.let { - val apk = File("${activity?.getExternalFilesDir("apk")?.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 intent = Intent(Intent.ACTION_VIEW) - intent.setDataAndType(uri, "application/vnd.android.package-archive") - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivity(intent) - } - } - - override fun onError(error: com.downloader.Error?) { - Toast.makeText(activity, error.toString(), Toast.LENGTH_SHORT).show() - Log.e("VMUpgrade", error.toString()) - } - - }) - } - } + downloadManager(true, requireActivity()) true } diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt index 4d121562..60923496 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/HomeFragment.kt @@ -22,12 +22,15 @@ import com.vanced.manager.adapter.VariantAdapter import com.vanced.manager.databinding.FragmentHomeBinding import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder import com.vanced.manager.ui.viewmodels.HomeViewModel +import com.vanced.manager.ui.viewmodels.HomeViewModelFactory import com.vanced.manager.utils.AppUtils open class HomeFragment : Fragment() { private lateinit var binding: FragmentHomeBinding - private val viewModel: HomeViewModel by viewModels() + private val viewModel: HomeViewModel by viewModels { + HomeViewModelFactory(requireActivity()) + } private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) } private val tabListener = object : TabLayout.OnTabSelectedListener { 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 cf07ed0d..95493daa 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 @@ -115,11 +115,6 @@ class SettingsFragment : PreferenceFragmentCompat() { true } - findPreference("install_url")?.setOnPreferenceClickListener { - URLChangeFragment().show(childFragmentManager.beginTransaction(), "Install URL") - true - } - findPreference("clear_files")?.setOnPreferenceClickListener { with(requireActivity()) { listOf("apk", "apks").forEach { dir -> diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/URLChangeFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/URLChangeFragment.kt index cf5d4f5d..bc5e32f9 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/URLChangeFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/URLChangeFragment.kt @@ -1,5 +1,6 @@ package com.vanced.manager.ui.fragments +import android.content.Context import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle @@ -9,9 +10,10 @@ import android.view.ViewGroup import android.widget.EditText import android.widget.TextView import androidx.fragment.app.DialogFragment -import androidx.preference.PreferenceManager +import androidx.preference.PreferenceManager.getDefaultSharedPreferences import com.google.android.material.button.MaterialButton import com.vanced.manager.R +import com.vanced.manager.core.App import com.vanced.manager.utils.InternetTools.baseUrl class URLChangeFragment : DialogFragment() { @@ -29,8 +31,7 @@ class URLChangeFragment : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val urlField = view.findViewById(R.id.url_input) - val prefs = PreferenceManager.getDefaultSharedPreferences(activity) - urlField.setText(prefs.getString("install_url", baseUrl), TextView.BufferType.EDITABLE) + urlField.setText(getDefaultSharedPreferences(requireActivity()).getString("install_url", baseUrl), TextView.BufferType.EDITABLE) view.findViewById(R.id.url_save).setOnClickListener { val finalUrl = if (urlField.text.startsWith("https://") || urlField.text.startsWith("http://")) @@ -38,14 +39,15 @@ class URLChangeFragment : DialogFragment() { else "https://${urlField.text}".removeSuffix("/") + saveUrl(finalUrl, requireActivity()) + } + view.findViewById(R.id.url_reset).setOnClickListener {saveUrl(baseUrl, requireActivity())} + } - prefs.edit().putString("install_url", finalUrl).apply() - dismiss() - } - view.findViewById(R.id.url_reset).setOnClickListener { - prefs.edit().putString("install_url", baseUrl).apply() - dismiss() - } + private fun saveUrl(url: String, context: Context) { + getDefaultSharedPreferences(requireActivity()).edit().putString("install_url", url).apply() + (context.applicationContext as App).loadJsonAsync() + dismiss() } } diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/UpdateCheckFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/UpdateCheckFragment.kt index e899004d..88369802 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/UpdateCheckFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/UpdateCheckFragment.kt @@ -1,29 +1,19 @@ package com.vanced.manager.ui.fragments -import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable -import android.net.Uri -import android.os.Build import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button -import android.widget.ProgressBar import android.widget.TextView -import android.widget.Toast -import androidx.core.content.FileProvider import androidx.fragment.app.DialogFragment -import com.downloader.OnDownloadListener -import com.downloader.PRDownloader import com.google.android.material.button.MaterialButton import com.vanced.manager.R +import com.vanced.manager.utils.DownloadHelper.downloadManager import com.vanced.manager.utils.InternetTools.isUpdateAvailable -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import java.io.File class UpdateCheckFragment : DialogFragment() { @@ -65,57 +55,16 @@ class UpdateCheckFragment : DialogFragment() { view?.findViewById