0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-27 13:33:00 +00:00

layout initialization fix

This commit is contained in:
X1nto 2020-08-31 20:12:20 +04:00
parent b5ee717bad
commit 7a8322eef2
19 changed files with 305 additions and 176 deletions

View file

@ -0,0 +1,20 @@
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()
}
}
}

View file

@ -2,11 +2,10 @@ package com.vanced.manager.adapter
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.vanced.manager.ui.fragments.MainFragment import com.vanced.manager.ui.fragments.MainFragment
class SectionVariantAdapter(fragmentActivity: FragmentActivity): FragmentStateAdapter(fragmentActivity) { class SectionVariantAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
override fun getItemCount(): Int = 3 override fun getItemCount(): Int = 3

View file

@ -4,11 +4,19 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.vanced.manager.utils.InternetTools.baseUrl
import com.vanced.manager.utils.InternetTools.getJsonInt import com.vanced.manager.utils.InternetTools.getJsonInt
import com.vanced.manager.utils.InternetTools.getJsonString import com.vanced.manager.utils.InternetTools.getJsonString
import com.vanced.manager.utils.InternetTools.getObjectFromJson
import com.vanced.manager.utils.PackageHelper.isPackageInstalled import com.vanced.manager.utils.PackageHelper.isPackageInstalled
import com.vanced.manager.R import com.vanced.manager.R
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
open class DataModel( open class DataModel(
private val jsonName: String, private val jsonName: String,
@ -24,30 +32,54 @@ open class DataModel(
else -> "com.vanced.android.youtube.music" else -> "com.vanced.android.youtube.music"
} }
/*
private var versionName: String = ""
private var installedVersionName: String = ""
private var changelog: String = ""
private var versionCode: Int = 0
private var installedVersionCode: Int = 0
*/
open fun isAppInstalled(): Boolean = isPackageInstalled(appPkg, context.packageManager) open fun isAppInstalled(): Boolean = isPackageInstalled(appPkg, context.packageManager)
open fun getVersionName(): String = runBlocking { getJsonString("$jsonName.json", "version", context) } open fun getVersionName(): String = runBlocking(Dispatchers.IO) {
getJsonString("$jsonName.json", "version", context)
}
open fun getVersionCode(): Int = runBlocking { getJsonInt("$jsonName.json", "versionCode", context) } open fun getVersionCode(): Int = runBlocking(Dispatchers.IO) {
getJsonInt("$jsonName.json", "versionCode", context)
}
open fun getInstalledVersionName(): String = getPkgVersion(isAppInstalled(), appPkg) open fun getInstalledVersionName(): String = runBlocking(Dispatchers.IO) {
getPkgVersionName(isAppInstalled(), appPkg)
}
open fun getInstalledVersionCode(): Int = runBlocking { getJsonInt("$jsonName.json", "versionCode", context) } open fun getInstalledVersionCode(): Int = runBlocking(Dispatchers.IO) {
getPkgVersionCode(isAppInstalled(), appPkg)
}
open fun getButtonTxt(): String = compareInt(getInstalledVersionCode(), getVersionCode()) open fun getButtonTxt(): String = compareInt(getInstalledVersionCode(), getVersionCode())
open fun getButtonIcon(): Drawable? = compareIntDrawable(getInstalledVersionCode(), getVersionCode()) open fun getButtonIcon(): Drawable? = compareIntDrawable(getInstalledVersionCode(), getVersionCode())
private fun getPkgVersion(toCheck: Boolean, pkg: String): String { 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")
}
private fun getPkgVersionName(toCheck: Boolean, pkg: String): String {
return if (toCheck) { return if (toCheck) {
context.packageManager.getPackageInfo(pkg, 0).versionName context.packageManager.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced")
} else { } else {
context.getString(R.string.unavailable) context.getString(R.string.unavailable)
} }
} }
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private fun getPkgVerCode(toCheck: Boolean, pkg: String): Int { private fun getPkgVersionCode(toCheck: Boolean, pkg: String): Int {
return if (toCheck) { return if (toCheck) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
context.packageManager.getPackageInfo(pkg, 0).longVersionCode.and(0xFFFFFFFF).toInt() context.packageManager.getPackageInfo(pkg, 0).longVersionCode.and(0xFFFFFFFF).toInt()

View file

@ -12,6 +12,7 @@ import com.crowdin.platform.Crowdin
import com.crowdin.platform.LoadingStateListener import com.crowdin.platform.LoadingStateListener
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.vanced.manager.adapter.SectionVariantAdapter
import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.FirebaseMessaging
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.ActivityMainBinding import com.vanced.manager.databinding.ActivityMainBinding
@ -21,7 +22,6 @@ import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.InternetTools import com.vanced.manager.utils.InternetTools
import com.vanced.manager.utils.PackageHelper import com.vanced.manager.utils.PackageHelper
import com.vanced.manager.utils.ThemeHelper.setFinalTheme import com.vanced.manager.utils.ThemeHelper.setFinalTheme
import com.vanced.manager.adapter.SectionVariantAdapter
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -45,28 +45,22 @@ class MainActivity : AppCompatActivity() {
private val tabListener = object : TabLayout.OnTabSelectedListener { private val tabListener = object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) { override fun onTabSelected(tab: TabLayout.Tab) {
getDefaultSharedPreferences(this@MainActivity).edit().apply { getDefaultSharedPreferences(this@MainActivity).edit().putString("vanced_variant",
when (tab.position) { when (tab.position) {
0 -> putString("vanced_variant", "nonroot").apply() 1 -> "music"
1 -> putString("vanced_variant", "music").apply() 2 -> "root"
2 -> putString("vanced_variant", "root").apply() else -> "nonroot"
} }
} )
} }
override fun onTabUnselected(tab: TabLayout.Tab) { override fun onTabUnselected(tab: TabLayout.Tab) {
TODO("There's nothing to do here actually") return
} }
override fun onTabReselected(tab: TabLayout.Tab) { override fun onTabReselected(tab: TabLayout.Tab) {
getDefaultSharedPreferences(this@MainActivity).edit().apply { return
when (tab.position) {
0 -> putString("vanced_variant", "nonroot").apply()
1 -> putString("vanced_variant", "music").apply()
2 -> putString("vanced_variant", "root").apply()
}
}
} }
} }
@ -75,27 +69,26 @@ class MainActivity : AppCompatActivity() {
setFinalTheme(this) setFinalTheme(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main) 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) { with(binding) {
lifecycleOwner = this@MainActivity lifecycleOwner = this@MainActivity
setSupportActionBar(homeToolbar) setSupportActionBar(homeToolbar)
mainViewpager.adapter = SectionVariantAdapter(this@MainActivity) mainViewpager.adapter = SectionVariantAdapter(this@MainActivity)
mainViewpager.setUserInputEnabled(false)
TabLayoutMediator(mainTablayout, mainViewpager) { tab, position -> TabLayoutMediator(mainTablayout, mainViewpager) { tab, position ->
when (position) { tab.text = when (position) {
0 -> tab.text = "nonroot" 1 -> "music"
1 -> tab.text = "Music" 2 -> "root"
2 -> tab.text = "root" else -> "nonroot"
} }
}.attach() }.attach()
mainTablayout.getTabAt(tabToSelect)?.select()
when (getDefaultSharedPreferences(this@MainActivity).getString("vanced_variant", "nonroot")) {
"nonroot" -> mainTablayout.getTabAt(0)?.select()
"music" -> mainTablayout.getTabAt(1)?.select()
"root" -> mainTablayout.getTabAt(2)?.select()
}
mainTablayout.addOnTabSelectedListener(tabListener)
} }
initDialogs() initDialogs()
@ -104,14 +97,15 @@ class MainActivity : AppCompatActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
binding.mainTablayout.removeOnTabSelectedListener(tabListener)
Crowdin.unregisterDataLoadingObserver(loadingObserver) Crowdin.unregisterDataLoadingObserver(loadingObserver)
binding.mainTablayout.removeOnTabSelectedListener(tabListener)
} }
override fun onResume() { override fun onResume() {
setFinalTheme(this) setFinalTheme(this)
super.onResume() super.onResume()
Crowdin.registerDataLoadingObserver(loadingObserver) Crowdin.registerDataLoadingObserver(loadingObserver)
binding.mainTablayout.addOnTabSelectedListener(tabListener)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {

View file

@ -13,6 +13,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.vanced.manager.R import com.vanced.manager.R
@ -48,52 +49,60 @@ class HomeFragment : Fragment(), View.OnClickListener {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel binding.viewModel = viewModel
val arg = "variant"
val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot") val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot")
val selectedTab = requireActivity().findViewById<TabLayout>(R.id.main_tablayout).getSelectedTabPosition()
with(binding) { with(binding) {
when (variant) { when (selectedTab) {
"nonroot" -> includeMusicLayout.musicCard.visibility = View.GONE 1 -> includeVancedLayout.vancedCard.visibility = View.GONE
"music" -> includeVancedLayout.vancedCard.visibility = View.GONE 2 -> {
"root" -> {
includeMusicLayout.musicCard.visibility = View.GONE includeMusicLayout.musicCard.visibility = View.GONE
includeMicrogLayout.microgCard.visibility = View.GONE includeMicrogLayout.microgCard.visibility = View.GONE
} }
else -> includeMusicLayout.musicCard.visibility = View.GONE
} }
}
with(binding) {
includeVancedLayout.vancedInstallbtn.setOnClickListener(this@HomeFragment) includeVancedLayout.vancedInstallbtn.setOnClickListener(this@HomeFragment)
includeVancedLayout.vancedUninstallbtn.setOnClickListener(this@HomeFragment) includeVancedLayout.vancedUninstallbtn.setOnClickListener(this@HomeFragment)
includeMicrogLayout.microgInstallbtn.setOnClickListener(this@HomeFragment) includeMicrogLayout.microgInstallbtn.setOnClickListener(this@HomeFragment)
includeMicrogLayout.microgUninstallbtn.setOnClickListener(this@HomeFragment) includeMicrogLayout.microgUninstallbtn.setOnClickListener(this@HomeFragment)
includeChangelogsLayout.changelogButton.setOnClickListener(this@HomeFragment) includeChangelogsLayout.changelogButton.setOnClickListener(this@HomeFragment)
}
binding.includeVancedLayout.vancedCard.setOnLongClickListener { includeVancedLayout.vancedCard.setOnLongClickListener {
versionToast("Vanced", viewModel.vanced.get()?.getInstalledVersionName()!!) versionToast("Vanced", viewModel?.vanced?.get()?.getInstalledVersionName()!!)
true true
} }
binding.includeMicrogLayout.microgCard.setOnLongClickListener { includeMicrogLayout.microgCard.setOnLongClickListener {
versionToast("MicroG", viewModel.microg.get()?.getInstalledVersionName()!!) versionToast("MicroG", viewModel?.microg?.get()?.getInstalledVersionName()!!)
true true
}
} }
with(binding.includeChangelogsLayout) { with(binding.includeChangelogsLayout) {
viewpager.adapter = if (variant == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment) viewpager.adapter =
when (selectedTab) {
1 -> SectionPageMusicAdapter(this@HomeFragment)
2 -> SectionPageRootAdapter(this@HomeFragment)
else -> SectionPageAdapter(this@HomeFragment)
}
TabLayoutMediator(tablayout, viewpager) { tab, position -> TabLayoutMediator(tablayout, viewpager) { tab, position ->
if (variant == "root") tab.text =
when (position) { when (selectedTab) {
0 -> tab.text = "Vanced" 1 -> when (position) {
1 -> tab.text = "Manager" 0 -> "Vanced"
} else -> "Manager"
else }
when (position) { 2 -> when (position) {
0 -> tab.text = "Vanced" 0 -> "Music"
1 -> tab.text = "MicroG" else -> "MicroG"
2 -> tab.text = "Manager" }
} else -> when (position) {
0 -> "Vanced"
1 -> "MicroG"
else -> "Manager"
}
}
}.attach() }.attach()
} }

View file

@ -9,18 +9,21 @@ import android.view.animation.AnimationUtils
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.NavController
import androidx.navigation.NavDestination import androidx.navigation.NavDestination
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.tabs.TabLayout
import com.vanced.manager.databinding.FragmentMainBinding import com.vanced.manager.databinding.FragmentMainBinding
import com.vanced.manager.R import com.vanced.manager.R
class MainFragment : Fragment() { class MainFragment : Fragment() {
private lateinit var binding: FragmentMainBinding private lateinit var binding: FragmentMainBinding
private val navHost by lazy { activity?.findNavController(R.id.nav_host) } private lateinit var navHost: NavController
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
@ -33,42 +36,51 @@ class MainFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val navHostFragment = childFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
navHost = navHostFragment.navController
val appBarConfiguration = AppBarConfiguration(navHost?.graph!!) val appBarConfiguration = AppBarConfiguration(navHost.graph)
activity?.findViewById<MaterialToolbar>(R.id.home_toolbar)?.setupWithNavController(navHost!!, appBarConfiguration) 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) setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment)
with (activity) { with (requireActivity()) {
val tabHide = this.let { AnimationUtils.loadAnimation(it, R.anim.tablayout_exit) } val tabHide = AnimationUtils.loadAnimation(this, R.anim.tablayout_exit)
val tabShow = this.let { AnimationUtils.loadAnimation(it, R.anim.tablayout_enter) } val tabShow = AnimationUtils.loadAnimation(this, R.anim.tablayout_enter)
if (currFrag.id != R.id.home_fragment) { if (currFrag.id != R.id.home_fragment) {
this?.findViewById<LinearLayout>(R.id.variant_tab_container)?.startAnimation(tabHide) if (tabLayout.visibility != View.GONE) {
this?.findViewById<LinearLayout>(R.id.variant_tab_container)?.visibility = View.GONE tabLayout.startAnimation(tabHide)
tabLayout.visibility = View.GONE
}
} else { } else {
this?.findViewById<LinearLayout>(R.id.variant_tab_container)?.visibility = View.VISIBLE if (tabLayout.visibility != View.VISIBLE) {
this?.findViewById<LinearLayout>(R.id.variant_tab_container)?.startAnimation(tabShow) tabLayout.visibility = View.VISIBLE
tabLayout.startAnimation(tabShow)
}
} }
} }
} }
} }
private fun setDisplayHomeAsUpEnabled(isNeeded: Boolean) { private fun setDisplayHomeAsUpEnabled(isNeeded: Boolean) {
activity?.findViewById<MaterialToolbar>(R.id.home_toolbar)?.navigationIcon = if (isNeeded) activity?.getDrawable(R.drawable.ic_keyboard_backspace_black_24dp) else null with(requireActivity()) {
findViewById<MaterialToolbar>(R.id.home_toolbar).navigationIcon = if (isNeeded) getDrawable(R.drawable.ic_keyboard_backspace_black_24dp) else null
}
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.toolbar_about -> { R.id.toolbar_about -> {
navHost?.navigate(R.id.toAboutFragment) navHost.navigate(R.id.toAboutFragment)
return true return true
} }
R.id.toolbar_settings -> { R.id.toolbar_settings -> {
navHost?.navigate(R.id.action_settingsFragment) navHost.navigate(R.id.action_settingsFragment)
return true return true
} }
R.id.dev_settings -> { R.id.dev_settings -> {
navHost?.navigate(R.id.toDevSettingsFragment) navHost.navigate(R.id.toDevSettingsFragment)
return true return true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)

View file

@ -4,28 +4,21 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools import com.vanced.manager.databinding.FragmentManagerChangelogBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class ManagerChangelogFragment : Fragment() { class ManagerChangelogFragment : Fragment() {
private lateinit var binding: FragmentManagerChangelogBinding
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
return inflater.inflate(R.layout.fragment_manager_changelog, container, false) binding = DataBindingUtil.inflate(inflater, R.layout.fragment_manager_changelog, container, false)
return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
CoroutineScope(Dispatchers.Main).launch {
val changelog = InternetTools.getObjectFromJson("https://ytvanced.github.io/VancedBackend/manager.json", "changelog")
view.findViewById<TextView>(R.id.manager_changelog).text = changelog
}
}
} }

View file

@ -4,29 +4,21 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools import com.vanced.manager.databinding.FragmentMicrogChangelogBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MicrogChangelogFragment : Fragment() { class MicrogChangelogFragment : Fragment() {
private lateinit var binding: FragmentMicrogChangelogBinding
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
return inflater.inflate(R.layout.fragment_microg_changelog, container, false) binding = DataBindingUtil.inflate(inflater, R.layout.fragment_microg_changelog, container, false)
return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
CoroutineScope(Dispatchers.Main).launch {
val baseUrl = PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", InternetTools.baseUrl)
view.findViewById<TextView>(R.id.microg_changelog).text = InternetTools.getObjectFromJson("$baseUrl/microg.json", "changelog")
}
}
} }

View file

@ -0,0 +1,24 @@
package com.vanced.manager.ui.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentMicrogChangelogBinding
class MusicChangelogFragment : Fragment() {
private lateinit var binding: FragmentMicrogChangelogBinding
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_music_changelog, container, false)
return binding.root
}
}

View file

@ -4,32 +4,21 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools import com.vanced.manager.databinding.FragmentVancedChangelogBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class VancedChangelogFragment : Fragment() { class VancedChangelogFragment : Fragment() {
private lateinit var binding: FragmentVancedChangelogBinding
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
return inflater.inflate(R.layout.fragment_vanced_changelog, container, false) binding = DataBindingUtil.inflate(inflater, R.layout.fragment_vanced_changelog, container, false)
return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
CoroutineScope(Dispatchers.Main).launch {
val vancedVersion = activity?.let { InternetTools.getJsonString("vanced.json", "version", it).replace('.', '_') }
val baseUrl = PreferenceManager.getDefaultSharedPreferences(activity).getString("install_url", InternetTools.baseUrl)
val changelog = InternetTools.getObjectFromJson("$baseUrl/changelog/$vancedVersion.json", "message")
view.findViewById<TextView>(R.id.vanced_changelog).text = changelog
}
}
} }

View file

@ -12,6 +12,7 @@ import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity import androidx.core.content.ContextCompat.startActivity
import androidx.databinding.ObservableField import androidx.databinding.ObservableField
import androidx.databinding.ObservableBoolean
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.crowdin.platform.Crowdin import com.crowdin.platform.Crowdin
@ -25,19 +26,21 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
//val variant = getDefaultSharedPreferences(application).getString("vanced_variant", "nonroot") //val variant = getDefaultSharedPreferences(application).getString("vanced_variant", "nonroot")
val fetching = ObservableField<Boolean>() val fetching = ObservableBoolean()
val vanced = ObservableField<DataModel>() val vanced = ObservableField<DataModel>()
val microg = ObservableField<DataModel>() val microg = ObservableField<DataModel>()
val music = ObservableField<DataModel>() val music = ObservableField<DataModel>()
val manager = ObservableField<DataModel>()
fun fetchData() { fun fetchData() {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
fetching.set(true) fetching.set(true)
Crowdin.forceUpdate(getApplication()) Crowdin.forceUpdate(getApplication())
vanced.set(DataModel("vanced.json", getApplication())) vanced.set(DataModel("vanced", getApplication()))
microg.set(DataModel("microg.json", getApplication())) microg.set(DataModel("microg", getApplication()))
music.set(DataModel("music.json", getApplication())) music.set(DataModel("music", getApplication()))
manager.set(DataModel("manager", getApplication()))
fetching.set(false) fetching.set(false)
} }
} }

View file

@ -28,14 +28,15 @@
<LinearLayout <LinearLayout
android:id="@+id/variant_tab_container" android:id="@+id/variant_tab_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"> android:layout_below="@id/home_appbar"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/main_tablayout" android:id="@+id/main_tablayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?colorSurfaceVariant" android:background="?colorSurface"
app:tabIndicatorColor="?colorPrimary" app:tabIndicatorColor="?colorPrimary"
app:tabSelectedTextColor="?colorPrimary" app:tabSelectedTextColor="?colorPrimary"
app:tabTextColor="?colorPrimary" /> app:tabTextColor="?colorPrimary" />

View file

@ -30,7 +30,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="vertical">
<include <include
android:id="@+id/include_vanced_layout" android:id="@+id/include_vanced_layout"

View file

@ -4,20 +4,22 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="horizontal">
<fragment <androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/nav_host" android:id="@+id/nav_host"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:defaultNavHost="true" app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" app:navGraph="@navigation/mobile_navigation" />
tools:context=".ui.fragments.MainFragment" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</layout> </layout>

View file

@ -1,16 +1,26 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <layout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.MicrogChangelogFragment">
<TextView <data>
android:id="@+id/manager_changelog"
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:textSize="16sp"
android:text="" />
</FrameLayout> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="16sp"
android:text="@{viewModel.manager.changelog}"/>
</LinearLayout>
</layout>

View file

@ -1,18 +1,27 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <layout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.MicrogChangelogFragment">
<TextView <data>
android:id="@+id/microg_changelog"
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:textSize="16sp" tools:context=".ui.fragments.MicrogChangelogFragment">
android:text="Changes:\n - Added casting support\n
- Fixed notifications\n\nMicroG now requires Vanced 14.21.54 and up"
tools:ignore="HardcodedText" />
</FrameLayout> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="16sp"
android:text="@{viewModel.microg.changelog}"/>
</LinearLayout>
</layout>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.MusicChangelogFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="16sp"
android:text="@{viewModel.music.changelog}"/>
</LinearLayout>
</layout>

View file

@ -1,15 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <layout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.VancedChangelogFragment">
<TextView <data>
android:id="@+id/vanced_changelog"
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:textSize="16sp" /> tools:context=".ui.fragments.VancedChangelogFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="16sp"
android:text="@{viewModel.vanced.changelog}"/>
</LinearLayout>
</layout>
</FrameLayout>

View file

@ -94,7 +94,7 @@
<TextView <TextView
android:id="@+id/microg_installed_version" android:id="@+id/microg_installed_version"
style="@style/AppVer.Bold" style="@style/AppVer.Bold"
android:text="@{viewModel.microg.installedVersionCode}" /> android:text="@{viewModel.microg.installedVersionName}" />
</LinearLayout> </LinearLayout>