mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-27 05:23:00 +00:00
Bug fixes
This commit is contained in:
parent
bb18effa8c
commit
30582b8c17
25 changed files with 302 additions and 141 deletions
|
@ -16,7 +16,7 @@ android {
|
|||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 13
|
||||
versionName "1.3.0 (Arcturus)"
|
||||
versionName "1.3.0b (Arcturus)"
|
||||
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@
|
|||
<service android:name=".core.installer.AppInstaller" />
|
||||
<service android:name=".core.downloader.VancedDownloadService" />
|
||||
<service android:name=".core.downloader.MicrogDownloadService" />
|
||||
<service android:name=".core.downloader.MusicDownloadService" />
|
||||
|
||||
</application>
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.vanced.manager.ui.fragments.ManagerChangelogFragment
|
||||
import com.vanced.manager.ui.fragments.MicrogChangelogFragment
|
||||
import com.vanced.manager.ui.fragments.MusicChangelogFragment
|
||||
import com.vanced.manager.ui.fragments.VancedChangelogFragment
|
||||
|
||||
class SectionPageAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
|
@ -13,9 +14,9 @@ class SectionPageAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
|||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> VancedChangelogFragment()
|
||||
1 -> MicrogChangelogFragment()
|
||||
2 -> ManagerChangelogFragment()
|
||||
else -> throw NotImplementedError()
|
||||
1 -> MusicChangelogFragment()
|
||||
2 -> MicrogChangelogFragment()
|
||||
else -> ManagerChangelogFragment()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package com.vanced.manager.adapter
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.vanced.manager.ui.fragments.MicrogChangelogFragment
|
||||
import com.vanced.manager.ui.fragments.MusicChangelogFragment
|
||||
|
||||
class SectionPageMusicAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
|
||||
override fun getItemCount(): Int = 2
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> MusicChangelogFragment()
|
||||
1 -> MicrogChangelogFragment()
|
||||
else -> throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ import com.vanced.manager.ui.fragments.MainFragment
|
|||
|
||||
class SectionVariantAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
|
||||
|
||||
override fun getItemCount(): Int = 3
|
||||
override fun getItemCount(): Int = 2
|
||||
|
||||
override fun createFragment(position: Int): Fragment = MainFragment()
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.vanced.manager.ui.fragments.HomeFragment
|
|||
import com.vanced.manager.utils.AppUtils.installing
|
||||
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.InternetTools.getJsonString
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -34,10 +34,7 @@ class MicrogDownloadService: Service() {
|
|||
|
||||
private fun downloadMicrog() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val url = getObjectFromJson(
|
||||
"${PreferenceManager.getDefaultSharedPreferences(this@MicrogDownloadService)
|
||||
.getString("install_url", baseUrl)}/microg.json", "url"
|
||||
)
|
||||
val url = getJsonString("microg.json", "url", this@MicrogDownloadService)
|
||||
|
||||
//downloadId = download(url, "apk", "microg.apk", this@MicrogDownloadService)
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package com.vanced.manager.core.downloader
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import android.widget.Toast
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.installer.AppInstaller
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
import com.vanced.manager.utils.AppUtils.installing
|
||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||
import com.vanced.manager.utils.InternetTools.getJsonString
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MusicDownloadService: Service() {
|
||||
|
||||
//private var downloadId: Long = 0
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) }
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
//registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
|
||||
downloadMusic()
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
private fun downloadMusic() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val version = getJsonString("music.json", "version", this@MusicDownloadService)
|
||||
val url = "https://vanced.app/api/v1/music/v$version.apk"
|
||||
|
||||
//downloadId = download(url, "apk", "music.apk", this@MusicDownloadService)
|
||||
|
||||
PRDownloader.download(url, getExternalFilesDir("apk")?.path, "music.apk")
|
||||
.build()
|
||||
.setOnStartOrResumeListener { installing = true }
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.MUSIC_DOWNLOADING).putExtra("progress", mProgress.toInt()).putExtra("file", getFileNameFromUrl(url)))
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
val intent = Intent(this@MusicDownloadService, AppInstaller::class.java)
|
||||
intent.putExtra("path", "${getExternalFilesDir("apk")}/music.apk")
|
||||
intent.putExtra("pkg", "com.vanced.android.apps.youtube.music")
|
||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.MUSIC_INSTALLING))
|
||||
startService(intent)
|
||||
}
|
||||
|
||||
override fun onError(error: Error?) {
|
||||
installing = false
|
||||
Toast.makeText(this@MusicDownloadService, getString(R.string.error_downloading, "music"), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) {
|
||||
//prefs?.edit()?.putBoolean("isMusicDownloading", false)?.apply()
|
||||
//cancelNotif(channel, this@MusicDownloadService)
|
||||
val bIntent = Intent(this@MusicDownloadService, AppInstaller::class.java)
|
||||
bIntent.putExtra("path", "${getExternalFilesDir("apk")}/music.apk")
|
||||
bIntent.putExtra("pkg", "com.mgoogle.android.gms")
|
||||
startService(bIntent)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -98,7 +98,7 @@ class VancedDownloadService: Service() {
|
|||
PRDownloader
|
||||
.download(url, getExternalFilesDir("apks")?.path, getFileNameFromUrl(url))
|
||||
.build()
|
||||
.setOnStartOrResumeListener{ installing = true }
|
||||
.setOnStartOrResumeListener { installing = true }
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.VANCED_DOWNLOADING).putExtra("progress", mProgress.toInt()).putExtra("file", getFileNameFromUrl(url)))
|
||||
|
@ -131,8 +131,16 @@ class VancedDownloadService: Service() {
|
|||
}
|
||||
}
|
||||
override fun onError(error: Error?) {
|
||||
installing = false
|
||||
Toast.makeText(this@VancedDownloadService, getString(R.string.error_downloading, "Vanced"), Toast.LENGTH_SHORT).show()
|
||||
if (type == "lang") {
|
||||
count++
|
||||
if (count < lang?.count()!!)
|
||||
downloadSplits("lang")
|
||||
else
|
||||
prepareInstall(variant!!)
|
||||
} else {
|
||||
installing = false
|
||||
Toast.makeText(this@VancedDownloadService, getString(R.string.error_downloading, "Vanced"), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.io.InputStream
|
|||
class AppInstaller: Service() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
val callbackIntent = Intent(applicationContext, AppInstallerService::class.java)
|
||||
val callbackIntent = Intent(applicationContext, AppInstallerService::class.java).putExtra("app", if (intent.getStringExtra("pkg").contains("mgoogle")) "microg" else "music"))
|
||||
val pendingIntent = PendingIntent.getService(applicationContext, 0, callbackIntent, 0)
|
||||
val packageInstaller = packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
|
||||
|
|
|
@ -17,7 +17,7 @@ class AppInstallerService: Service() {
|
|||
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
|
||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
||||
Log.d(TAG, "Requesting user confirmation for installation")
|
||||
localBroadcastManager.sendBroadcast(Intent(HomeFragment.MICROG_INSTALLING))
|
||||
localBroadcastManager.sendBroadcast(Intent(if (intent.getStringExtra("app")) HomeFragment.MICROG_INSTALLING else HomeFragment.MUSIC_INSTALLING))
|
||||
val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
|
||||
confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
try {
|
||||
|
@ -30,7 +30,7 @@ class AppInstallerService: Service() {
|
|||
Log.d(TAG, "Installation succeed")
|
||||
with(localBroadcastManager) {
|
||||
sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
||||
sendBroadcast(Intent(HomeFragment.MICROG_INSTALLED))
|
||||
sendBroadcast(Intent(if (intent.getStringExtra("app")) HomeFragment.MICROG_INSTALLING else HomeFragment.MUSIC_INSTALLING))
|
||||
}
|
||||
}
|
||||
else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this)
|
||||
|
|
|
@ -20,16 +20,15 @@ import kotlinx.coroutines.withContext
|
|||
|
||||
open class DataModel(
|
||||
private val jsonName: String,
|
||||
private val variant: String = "nonroot",
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
private val variant = getDefaultSharedPreferences(context).getString("vanced_variant", "nonroot")
|
||||
|
||||
private val appPkg =
|
||||
when (jsonName) {
|
||||
"vanced" -> if (variant == "root") "com.google.android.youtube" else "com.vanced.android.youtube"
|
||||
"microg" -> "com.mgoogle.android.gms"
|
||||
else -> "com.vanced.android.youtube.music"
|
||||
else -> "com.vanced.android.apps.youtube.music"
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,10 +63,11 @@ open class DataModel(
|
|||
open fun getButtonIcon(): Drawable? = compareIntDrawable(getInstalledVersionCode(), getVersionCode())
|
||||
|
||||
open fun getChangelog(): String = runBlocking(Dispatchers.IO) {
|
||||
if (jsonName == "vanced")
|
||||
getObjectFromJson("$baseUrl/changelog/${getVersionName().replace('.', '_')}.json", "message")
|
||||
else
|
||||
getObjectFromJson("https://ytvanced.github.io/VancedBackend/$jsonName.json", "changelog")
|
||||
when (jsonName) {
|
||||
"vanced" -> getObjectFromJson("$baseUrl/changelog/${getVersionName().replace('.', '_')}.json", "message")
|
||||
"music" -> getJsonString("$jsonName.json", "changelog", context)
|
||||
else -> getObjectFromJson("https://ytvanced.github.io/VancedBackend/$jsonName.json", "changelog")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPkgVersionName(toCheck: Boolean, pkg: String): String {
|
||||
|
|
|
@ -51,7 +51,7 @@ class MainActivity : AppCompatActivity() {
|
|||
2 -> "root"
|
||||
else -> "nonroot"
|
||||
}
|
||||
)
|
||||
).apply()
|
||||
|
||||
}
|
||||
|
||||
|
@ -69,12 +69,6 @@ class MainActivity : AppCompatActivity() {
|
|||
setFinalTheme(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
|
||||
val tabToSelect =
|
||||
when (getDefaultSharedPreferences(this@MainActivity).getString("vanced_variant", "nonroot")) {
|
||||
"music" -> 1
|
||||
"root" -> 2
|
||||
else -> 0
|
||||
}
|
||||
|
||||
with(binding) {
|
||||
lifecycleOwner = this@MainActivity
|
||||
|
@ -82,13 +76,16 @@ class MainActivity : AppCompatActivity() {
|
|||
mainViewpager.adapter = SectionVariantAdapter(this@MainActivity)
|
||||
mainViewpager.setUserInputEnabled(false)
|
||||
TabLayoutMediator(mainTablayout, mainViewpager) { tab, position ->
|
||||
tab.text = when (position) {
|
||||
1 -> "music"
|
||||
2 -> "root"
|
||||
else -> "nonroot"
|
||||
}
|
||||
tab.text = if (position == 1) "root" else "nonroot"
|
||||
}.attach()
|
||||
mainTablayout.getTabAt(tabToSelect)?.select()
|
||||
|
||||
mainTablayout.getTabAt(
|
||||
if (getDefaultSharedPreferences(this@MainActivity).getString("vanced_variant", "nonroot") == "root")
|
||||
1
|
||||
else
|
||||
0
|
||||
)?.select()
|
||||
|
||||
}
|
||||
|
||||
initDialogs()
|
||||
|
@ -114,8 +111,7 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
return false
|
||||
}
|
||||
R.id.toolbar_about -> {
|
||||
return false
|
||||
|
|
|
@ -132,10 +132,22 @@ object DialogContainer {
|
|||
setTitle(activity.getString(R.string.success))
|
||||
setMessage(activity.getString(R.string.vanced_installed))
|
||||
setPositiveButton(activity.getString(R.string.launch)) { _, _ ->
|
||||
run {
|
||||
startActivity(activity, intent, null)
|
||||
activity.finish()
|
||||
}
|
||||
startActivity(activity, intent, null)
|
||||
}
|
||||
setNegativeButton(activity.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
|
||||
create()
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
fun launchMusic(activity: Activity) {
|
||||
val intent = Intent()
|
||||
intent.component = ComponentName("com.vanced.android.youtube.music", "com.vanced.android.youtube.music.MusicActivity")
|
||||
MaterialAlertDialogBuilder(activity).apply {
|
||||
setTitle(activity.getString(R.string.success))
|
||||
setMessage(activity.getString(R.string.music_installed))
|
||||
setPositiveButton(activity.getString(R.string.launch)) { _, _ ->
|
||||
startActivity(activity, intent, null)
|
||||
}
|
||||
setNegativeButton(activity.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
|
||||
create()
|
||||
|
|
|
@ -19,18 +19,21 @@ import com.topjohnwu.superuser.Shell
|
|||
import com.vanced.manager.R
|
||||
import com.vanced.manager.adapter.*
|
||||
import com.vanced.manager.core.downloader.MicrogDownloadService
|
||||
import com.vanced.manager.core.downloader.MusicDownloadService
|
||||
import com.vanced.manager.core.downloader.VancedDownloadService
|
||||
import com.vanced.manager.databinding.FragmentHomeBinding
|
||||
import com.vanced.manager.ui.MainActivity
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.launchVanced
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.launchMusic
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.utils.AppUtils.installing
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
|
||||
class HomeFragment : Fragment(), View.OnClickListener {
|
||||
open class HomeFragment : Fragment(), View.OnClickListener {
|
||||
|
||||
private lateinit var binding: FragmentHomeBinding
|
||||
private lateinit var variant: String
|
||||
private var isExpanded: Boolean = false
|
||||
private val viewModel: HomeViewModel by viewModels()
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
|
||||
|
@ -41,29 +44,21 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
): View? {
|
||||
requireActivity().title = getString(R.string.title_home)
|
||||
setHasOptionsMenu(true)
|
||||
variant = if (requireActivity().findViewById<TabLayout>(R.id.main_tablayout).getSelectedTabPosition() == 1) "root" else "nonroot"
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
|
||||
binding.viewModel = viewModel
|
||||
viewModel.variant = variant
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.viewModel = viewModel
|
||||
|
||||
val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot")
|
||||
val selectedTab = requireActivity().findViewById<TabLayout>(R.id.main_tablayout).getSelectedTabPosition()
|
||||
|
||||
with(binding) {
|
||||
when (selectedTab) {
|
||||
1 -> includeVancedLayout.vancedCard.visibility = View.GONE
|
||||
2 -> {
|
||||
includeMusicLayout.musicCard.visibility = View.GONE
|
||||
includeMicrogLayout.microgCard.visibility = View.GONE
|
||||
}
|
||||
else -> includeMusicLayout.musicCard.visibility = View.GONE
|
||||
}
|
||||
|
||||
includeVancedLayout.vancedInstallbtn.setOnClickListener(this@HomeFragment)
|
||||
includeVancedLayout.vancedUninstallbtn.setOnClickListener(this@HomeFragment)
|
||||
includeMusicLayout.musicInstallbtn.setOnClickListener(this@HomeFragment)
|
||||
includeMusicLayout.musicUninstallbtn.setOnClickListener(this@HomeFragment)
|
||||
includeMicrogLayout.microgInstallbtn.setOnClickListener(this@HomeFragment)
|
||||
includeMicrogLayout.microgUninstallbtn.setOnClickListener(this@HomeFragment)
|
||||
includeChangelogsLayout.changelogButton.setOnClickListener(this@HomeFragment)
|
||||
|
@ -73,6 +68,11 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
true
|
||||
}
|
||||
|
||||
includeMusicLayout.musicCard.setOnLongClickListener {
|
||||
versionToast("Music", viewModel?.music?.get()?.getInstalledVersionName()!!)
|
||||
true
|
||||
}
|
||||
|
||||
includeMicrogLayout.microgCard.setOnLongClickListener {
|
||||
versionToast("MicroG", viewModel?.microg?.get()?.getInstalledVersionName()!!)
|
||||
true
|
||||
|
@ -81,29 +81,26 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
|
||||
with(binding.includeChangelogsLayout) {
|
||||
viewpager.adapter =
|
||||
when (selectedTab) {
|
||||
1 -> SectionPageMusicAdapter(this@HomeFragment)
|
||||
2 -> SectionPageRootAdapter(this@HomeFragment)
|
||||
else -> SectionPageAdapter(this@HomeFragment)
|
||||
}
|
||||
if (variant == "root")
|
||||
SectionPageRootAdapter(this@HomeFragment)
|
||||
else
|
||||
SectionPageAdapter(this@HomeFragment)
|
||||
|
||||
TabLayoutMediator(tablayout, viewpager) { tab, position ->
|
||||
tab.text =
|
||||
when (selectedTab) {
|
||||
1 -> when (position) {
|
||||
0 -> "Vanced"
|
||||
else -> "Manager"
|
||||
}
|
||||
2 -> when (position) {
|
||||
0 -> "Music"
|
||||
else -> "MicroG"
|
||||
}
|
||||
else -> when (position) {
|
||||
0 -> "Vanced"
|
||||
1 -> "MicroG"
|
||||
else -> "Manager"
|
||||
}
|
||||
if (variant == "root") {
|
||||
when (position) {
|
||||
0 -> "Vanced"
|
||||
else -> "Manager"
|
||||
}
|
||||
} else {
|
||||
when (position) {
|
||||
0 -> "Vanced"
|
||||
1 -> "Music"
|
||||
2 -> "MicroG"
|
||||
else -> "Manager"
|
||||
}
|
||||
}
|
||||
|
||||
}.attach()
|
||||
}
|
||||
|
||||
|
@ -111,32 +108,29 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
|
||||
override fun onClick(v: View?) {
|
||||
val prefs = requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot")
|
||||
val vancedPkgName =
|
||||
if (variant == "root") {
|
||||
if (variant == "root")
|
||||
"com.google.android.youtube"
|
||||
} else {
|
||||
else
|
||||
"com.vanced.android.youtube"
|
||||
}
|
||||
|
||||
when (v?.id) {
|
||||
R.id.vanced_installbtn -> {
|
||||
if (!installing) {
|
||||
if (!viewModel.fetching.get()!!) {
|
||||
if (!viewModel.fetching.get()) {
|
||||
if (variant == "nonroot" && !viewModel.microg.get()?.isAppInstalled()!!) {
|
||||
Snackbar.make(
|
||||
binding.homeRefresh,
|
||||
R.string.no_microg,
|
||||
Snackbar.LENGTH_LONG
|
||||
)
|
||||
.setAction(R.string.install) {
|
||||
requireActivity().startService(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
MicrogDownloadService::class.java
|
||||
)
|
||||
).setAction(R.string.install) {
|
||||
requireActivity().startService(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
MicrogDownloadService::class.java
|
||||
)
|
||||
}.show()
|
||||
)
|
||||
}.show()
|
||||
} else {
|
||||
if (prefs?.getBoolean("valuesModified", false)!!) {
|
||||
requireActivity().startService(
|
||||
|
@ -153,14 +147,43 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
} else
|
||||
Toast.makeText(requireActivity(), R.string.installation_wait, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
R.id.music_installbtn -> {
|
||||
if (!installing) {
|
||||
if (!viewModel.fetching.get()) {
|
||||
if (!viewModel.microg.get()?.isAppInstalled()!!) {
|
||||
Snackbar.make(
|
||||
binding.homeRefresh,
|
||||
R.string.no_microg,
|
||||
Snackbar.LENGTH_LONG
|
||||
).setAction(R.string.install) {
|
||||
requireActivity().startService(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
MicrogDownloadService::class.java
|
||||
)
|
||||
)
|
||||
}.show()
|
||||
} else {
|
||||
requireActivity().startService(
|
||||
Intent(
|
||||
requireActivity(),
|
||||
MusicDownloadService::class.java
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} else
|
||||
Toast.makeText(requireActivity(), R.string.installation_wait, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
R.id.microg_installbtn -> {
|
||||
if (!installing)
|
||||
requireActivity().startService(Intent(requireActivity(), MicrogDownloadService::class.java))
|
||||
else
|
||||
Toast.makeText(requireActivity(), R.string.installation_wait, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
R.id.microg_uninstallbtn -> PackageHelper.uninstallApk("com.mgoogle.android.gms", requireActivity())
|
||||
R.id.vanced_uninstallbtn -> PackageHelper.uninstallApk(vancedPkgName, requireActivity())
|
||||
R.id.music_uninstallbtn -> PackageHelper.uninstallApk("com.vanced.android.apps.youtube.music", requireActivity())
|
||||
R.id.microg_uninstallbtn -> PackageHelper.uninstallApk("com.mgoogle.android.gms", requireActivity())
|
||||
R.id.changelog_button -> cardExpandCollapse()
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +227,14 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
vancedDownloadingTxt.text = requireActivity().getString(R.string.downloading_file, intent.getStringExtra("file"))
|
||||
}
|
||||
}
|
||||
MUSIC_DOWNLOADING -> {
|
||||
with(binding.includeMusicLayout) {
|
||||
musicDownloading.visibility = View.VISIBLE
|
||||
musicDownloading.progress = intent.getIntExtra("progress", 0)
|
||||
musicDownloadingTxt.visibility = View.VISIBLE
|
||||
musicDownloadingTxt.text = requireActivity().getString(R.string.downloading_file, "music.apk")
|
||||
}
|
||||
}
|
||||
MICROG_DOWNLOADING -> {
|
||||
with(binding.includeMicrogLayout) {
|
||||
microgDownloading.visibility = View.VISIBLE
|
||||
|
@ -212,13 +243,6 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
microgDownloadingTxt.text = requireActivity().getString(R.string.downloading_file, "microg.apk")
|
||||
}
|
||||
}
|
||||
MICROG_INSTALLING -> {
|
||||
with (binding.includeMicrogLayout) {
|
||||
microgDownloading.visibility = View.GONE
|
||||
microgDownloadingTxt.visibility = View.GONE
|
||||
microgInstalling.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
VANCED_INSTALLING -> {
|
||||
with (binding.includeVancedLayout) {
|
||||
vancedDownloading.visibility = View.GONE
|
||||
|
@ -226,11 +250,30 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
vancedInstalling.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
MUSIC_INSTALLING -> {
|
||||
with (binding.includeMusicLayout) {
|
||||
musicDownloading.visibility = View.GONE
|
||||
musicDownloadingTxt.visibility = View.GONE
|
||||
musicInstalling.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
MICROG_INSTALLING -> {
|
||||
with (binding.includeMicrogLayout) {
|
||||
microgDownloading.visibility = View.GONE
|
||||
microgDownloadingTxt.visibility = View.GONE
|
||||
microgInstalling.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
VANCED_INSTALLED -> {
|
||||
binding.includeVancedLayout.vancedInstalling.visibility = View.GONE
|
||||
launchVanced(requireActivity())
|
||||
installing = false
|
||||
}
|
||||
MUSIC_INSTALLED -> {
|
||||
binding.includeMusicLayout.musicInstalling.visibility = View.GONE
|
||||
launchMusic(requireActivity())
|
||||
installing = false
|
||||
}
|
||||
MICROG_INSTALLED -> {
|
||||
binding.includeMicrogLayout.microgInstalling.visibility = View.GONE
|
||||
installing = false
|
||||
|
@ -239,6 +282,7 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
with(binding) {
|
||||
includeMicrogLayout.microgInstalling.visibility = View.GONE
|
||||
includeVancedLayout.vancedInstalling.visibility = View.GONE
|
||||
includeMusicLayout.musicInstalling.visibility = View.GONE
|
||||
}
|
||||
installAlertBuilder(intent.getStringExtra("errorMsg") as String, requireActivity())
|
||||
installing = false
|
||||
|
@ -254,10 +298,13 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
private fun registerReceivers() {
|
||||
val intentFilter = IntentFilter()
|
||||
intentFilter.addAction(VANCED_DOWNLOADING)
|
||||
intentFilter.addAction(MUSIC_DOWNLOADING)
|
||||
intentFilter.addAction(MICROG_DOWNLOADING)
|
||||
intentFilter.addAction(VANCED_INSTALLING)
|
||||
intentFilter.addAction(MUSIC_INSTALLING)
|
||||
intentFilter.addAction(MICROG_INSTALLING)
|
||||
intentFilter.addAction(VANCED_INSTALLED)
|
||||
intentFilter.addAction(MUSIC_INSTALLED)
|
||||
intentFilter.addAction(MICROG_INSTALLED)
|
||||
intentFilter.addAction(REFRESH_HOME)
|
||||
intentFilter.addAction(INSTALL_FAILED)
|
||||
|
@ -271,10 +318,13 @@ class HomeFragment : Fragment(), View.OnClickListener {
|
|||
|
||||
companion object {
|
||||
const val VANCED_DOWNLOADING = "vanced_downloading"
|
||||
const val MUSIC_DOWNLOADING = "music_downloading"
|
||||
const val MICROG_DOWNLOADING = "microg_downloading"
|
||||
const val VANCED_INSTALLING = "vanced_installing"
|
||||
const val MUSIC_INSTALLING = "music_installing"
|
||||
const val MICROG_INSTALLING = "microg_installing"
|
||||
const val VANCED_INSTALLED = "vanced_installed"
|
||||
const val MUSIC_INSTALLED = "music_installed"
|
||||
const val MICROG_INSTALLED = "microg_installed"
|
||||
const val INSTALL_FAILED = "install_failed"
|
||||
const val REFRESH_HOME = "refresh_home"
|
||||
|
|
|
@ -43,7 +43,7 @@ class MainFragment : Fragment() {
|
|||
requireActivity().findViewById<MaterialToolbar>(R.id.home_toolbar).setupWithNavController(navHost, appBarConfiguration)
|
||||
val tabLayout = requireActivity().findViewById<TabLayout>(R.id.main_tablayout)
|
||||
|
||||
navHost?.addOnDestinationChangedListener { _, currFrag: NavDestination, _ ->
|
||||
navHost.addOnDestinationChangedListener { _, currFrag: NavDestination, _ ->
|
||||
setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment)
|
||||
with (requireActivity()) {
|
||||
val tabHide = AnimationUtils.loadAnimation(this, R.anim.tablayout_exit)
|
||||
|
@ -71,6 +71,10 @@ class MainFragment : Fragment() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
navHost.popBackStack()
|
||||
return true
|
||||
}
|
||||
R.id.toolbar_about -> {
|
||||
navHost.navigate(R.id.toAboutFragment)
|
||||
return true
|
||||
|
|
|
@ -6,18 +6,22 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentManagerChangelogBinding
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class ManagerChangelogFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentManagerChangelogBinding
|
||||
private val viewModel: HomeViewModel by viewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_manager_changelog, container, false)
|
||||
binding.viewModel = viewModel
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
|
|
@ -6,18 +6,22 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentMicrogChangelogBinding
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class MicrogChangelogFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMicrogChangelogBinding
|
||||
private val viewModel: HomeViewModel by viewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_microg_changelog, container, false)
|
||||
binding.viewModel = viewModel
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,15 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentMicrogChangelogBinding
|
||||
import com.vanced.manager.databinding.FragmentMusicChangelogBinding
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class MusicChangelogFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMicrogChangelogBinding
|
||||
private lateinit var binding: FragmentMusicChangelogBinding
|
||||
private val viewModel: HomeViewModel by viewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
|
@ -21,4 +24,9 @@ class MusicChangelogFragment : Fragment() {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.viewModel = viewModel
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,18 +6,22 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentVancedChangelogBinding
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class VancedChangelogFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentVancedChangelogBinding
|
||||
private val viewModel: HomeViewModel by viewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_vanced_changelog, container, false)
|
||||
binding.viewModel = viewModel
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import kotlinx.coroutines.launch
|
|||
open class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
//val variant = getDefaultSharedPreferences(application).getString("vanced_variant", "nonroot")
|
||||
var variant = "nonroot"
|
||||
|
||||
val fetching = ObservableBoolean()
|
||||
|
||||
|
@ -37,10 +38,10 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
CoroutineScope(Dispatchers.IO).launch {
|
||||
fetching.set(true)
|
||||
Crowdin.forceUpdate(getApplication())
|
||||
vanced.set(DataModel("vanced", getApplication()))
|
||||
microg.set(DataModel("microg", getApplication()))
|
||||
music.set(DataModel("music", getApplication()))
|
||||
manager.set(DataModel("manager", getApplication()))
|
||||
vanced.set(DataModel("vanced", variant, getApplication()))
|
||||
microg.set(DataModel("microg", context = getApplication()))
|
||||
music.set(DataModel("music", context = getApplication()))
|
||||
manager.set(DataModel("manager", context = getApplication()))
|
||||
fetching.set(false)
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
startActivity(getApplication(), intent, null)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Toast.makeText(getApplication(), "App not installed", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(getApplication(), "Error", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<translate
|
||||
android:duration="500"
|
||||
android:duration="800"
|
||||
android:fromYDelta="-100%p"
|
||||
android:toYDelta="0"
|
||||
/>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<translate
|
||||
android:duration="500"
|
||||
android:duration="800"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="-100%p"
|
||||
/>
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
android:id="@+id/container"
|
||||
android:background="?colorSurface"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/home_appbar"
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
android:layout_marginStart="@dimen/stdp"
|
||||
android:layout_marginTop="@dimen/stdp"
|
||||
android:layout_marginEnd="@dimen/stdp"
|
||||
android:visibility="@{viewModel.variant.equals(`nonroot`) ? View.VISIBLE : View.GONE}"
|
||||
bind:viewModel="@{viewModel}" />
|
||||
|
||||
<include
|
||||
|
@ -60,6 +61,7 @@
|
|||
android:layout_marginStart="@dimen/stdp"
|
||||
android:layout_marginTop="@dimen/stdp"
|
||||
android:layout_marginEnd="@dimen/stdp"
|
||||
android:visibility="@{viewModel.variant.equals(`nonroot`) ? View.VISIBLE : View.GONE}"
|
||||
bind:viewModel="@{viewModel}" />
|
||||
|
||||
<include
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
<string name="security_context">Make sure that you downloaded the app from vanced.app, the Vanced Discord server or the Vanced GitHub</string>
|
||||
<string name="success">Success!</string>
|
||||
<string name="vanced_installed">Vanced has successfully been installed! Open now?</string>
|
||||
<string name="music_installed">Vanced Music has successfully been installed! Open now?</string>
|
||||
<string name="launch">Open</string>
|
||||
<string name="welcome">Welcome</string>
|
||||
|
||||
|
@ -88,7 +89,7 @@
|
|||
<string name="next">Next</string>
|
||||
|
||||
<!-- About Page -->
|
||||
<string name="manager_dev">Manager Dev</string>
|
||||
<string name="manager_dev">Manager Devs</string>
|
||||
<string name="sources">Sources</string>
|
||||
<string name="vanced_team">Vanced Team</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue