mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-25 04:35:12 +00:00
Optimised changelog viewpager
This commit is contained in:
parent
9b18450ad6
commit
baba594900
19 changed files with 88 additions and 301 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@ build/
|
|||
out/
|
||||
app/src/main/java/com/vanced/manager/core/base/DummyJava.java
|
||||
app/build/
|
||||
app/release
|
||||
local.properties
|
||||
/.github/
|
||||
*.iml
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.vanced.manager.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class ChangelogAdapter(private val variant: String, viewModel: HomeViewModel?): RecyclerView.Adapter<ChangelogAdapter.ChangelogViewHolder>() {
|
||||
|
||||
private val nonrootChangelogs = arrayOf(viewModel?.vanced?.get()?.changelog?.get(), viewModel?.music?.get()?.changelog?.get(), viewModel?.microg?.get()?.changelog?.get(), viewModel?.manager?.get()?.changelog?.get())
|
||||
private val rootChangelogs = arrayOf(viewModel?.vanced?.get()?.changelog?.get(), viewModel?.manager?.get()?.changelog?.get())
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChangelogViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val view = layoutInflater.inflate(R.layout.view_changelog, parent, false)
|
||||
|
||||
return ChangelogViewHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = if (variant == "root") 2 else 4
|
||||
|
||||
override fun onBindViewHolder(holder: ChangelogViewHolder, position: Int) {
|
||||
holder.changelog.text =
|
||||
if (variant == "root")
|
||||
rootChangelogs[position]
|
||||
else
|
||||
nonrootChangelogs[position]
|
||||
|
||||
}
|
||||
|
||||
open class ChangelogViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val changelog: TextView = itemView.findViewById(R.id.changelog_text)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.vanced.manager.adapter
|
||||
|
||||
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) {
|
||||
|
||||
override fun getItemCount(): Int = 3
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> VancedChangelogFragment()
|
||||
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.ManagerChangelogFragment
|
||||
import com.vanced.manager.ui.fragments.VancedChangelogFragment
|
||||
|
||||
class SectionPageRootAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
|
||||
override fun getItemCount(): Int = 2
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> VancedChangelogFragment()
|
||||
1 -> ManagerChangelogFragment()
|
||||
else -> throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@ import androidx.fragment.app.FragmentActivity
|
|||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.vanced.manager.ui.fragments.MainFragment
|
||||
|
||||
class SectionVariantAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
|
||||
class VariantAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
|
||||
|
||||
override fun getItemCount(): Int = 2
|
||||
|
|
@ -3,6 +3,7 @@ package com.vanced.manager.model
|
|||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.databinding.ObservableBoolean
|
||||
import androidx.databinding.ObservableField
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.google.android.material.tabs.TabLayoutMediator
|
|||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.adapter.SectionVariantAdapter
|
||||
import com.vanced.manager.adapter.VariantAdapter
|
||||
import com.vanced.manager.databinding.ActivityMainBinding
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer
|
||||
import com.vanced.manager.ui.fragments.UpdateCheckFragment
|
||||
|
@ -78,7 +78,7 @@ class MainActivity : AppCompatActivity() {
|
|||
with(binding) {
|
||||
lifecycleOwner = this@MainActivity
|
||||
setSupportActionBar(homeToolbar)
|
||||
mainViewpager.adapter = SectionVariantAdapter(this@MainActivity)
|
||||
mainViewpager.adapter = VariantAdapter(this@MainActivity)
|
||||
mainViewpager.isUserInputEnabled = false
|
||||
TabLayoutMediator(mainTablayout, mainViewpager) { tab, position ->
|
||||
tab.text = if (position == 1) "root" else "nonroot"
|
||||
|
|
|
@ -14,12 +14,12 @@ import androidx.navigation.findNavController
|
|||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.adapter.SectionPageAdapter
|
||||
import com.vanced.manager.adapter.SectionPageRootAdapter
|
||||
import com.vanced.manager.adapter.ChangelogAdapter
|
||||
import com.vanced.manager.databinding.FragmentHomeBinding
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder
|
||||
import com.vanced.manager.ui.events.Event
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModelFactory
|
||||
import com.vanced.manager.utils.AppUtils.installing
|
||||
|
||||
open class HomeFragment : Fragment(), View.OnClickListener {
|
||||
|
@ -27,7 +27,9 @@ 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 viewModel: HomeViewModel by viewModels {
|
||||
HomeViewModelFactory(requireActivity().application, variant)
|
||||
}
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
|
||||
|
||||
override fun onCreateView(
|
||||
|
@ -39,13 +41,11 @@ open class HomeFragment : Fragment(), View.OnClickListener {
|
|||
variant = if (requireActivity().findViewById<TabLayout>(R.id.main_tablayout).selectedTabPosition == 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)
|
||||
|
||||
viewModel.navigateDestination.observe(viewLifecycleOwner, Observer<Event<Int>> {
|
||||
val content = it.getContentIfNotHandled()
|
||||
if(content != null){
|
||||
|
@ -73,26 +73,16 @@ open class HomeFragment : Fragment(), View.OnClickListener {
|
|||
}
|
||||
|
||||
with(binding.includeChangelogsLayout) {
|
||||
viewpager.adapter =
|
||||
if (variant == "root")
|
||||
SectionPageRootAdapter(this@HomeFragment)
|
||||
else
|
||||
SectionPageAdapter(this@HomeFragment)
|
||||
viewpager.adapter = ChangelogAdapter(variant, this@HomeFragment.viewModel)
|
||||
val nonrootTitles = arrayOf("Vanced", "Music", "microG", "Manager")
|
||||
val rootTitles = arrayOf("Vanced", "Manager")
|
||||
|
||||
TabLayoutMediator(tablayout, viewpager) { tab, position ->
|
||||
tab.text =
|
||||
if (variant == "root") {
|
||||
when (position) {
|
||||
0 -> "Vanced"
|
||||
else -> "Manager"
|
||||
}
|
||||
rootTitles[position]
|
||||
} else {
|
||||
when (position) {
|
||||
0 -> "Vanced"
|
||||
1 -> "Music"
|
||||
2 -> "MicroG"
|
||||
else -> "Manager"
|
||||
}
|
||||
nonrootTitles[position]
|
||||
}
|
||||
}.attach()
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
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 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
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
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 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
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
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 androidx.fragment.app.viewModels
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentMusicChangelogBinding
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class MusicChangelogFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentMusicChangelogBinding
|
||||
private val viewModel: HomeViewModel by viewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_music_changelog, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.viewModel = viewModel
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
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 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
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import android.content.ActivityNotFoundException
|
|||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import androidx.databinding.ObservableBoolean
|
||||
|
@ -28,13 +29,12 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
open class HomeViewModel(application: Application): AndroidViewModel(application) {
|
||||
open class HomeViewModel(application: Application, val variant: String): AndroidViewModel(application) {
|
||||
|
||||
val app = application
|
||||
private val managerApp = application as App
|
||||
|
||||
//val variant = getDefaultSharedPreferences(application).getString("vanced_variant", "nonroot")
|
||||
var variant = "nonroot"
|
||||
|
||||
val vanced = ObservableField<DataModel>()
|
||||
val microg = ObservableField<DataModel>()
|
||||
|
@ -144,16 +144,14 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
|
||||
init {
|
||||
fetching.set(true)
|
||||
//while (managerApp.manager == null)
|
||||
//this.wait()
|
||||
|
||||
vanced.set(DataModel(managerApp.vanced, variant, "vanced", app))
|
||||
microg.set(DataModel(managerApp.microg, app = "microg", context = app))
|
||||
music.set(DataModel(managerApp.music, app = "music", context = app))
|
||||
microg.set(DataModel(managerApp.microg, app = "microg", context = app))
|
||||
manager.set(DataModel(managerApp.manager, app = "manager", context = app))
|
||||
vancedProgress.set(ProgressModel())
|
||||
musicProgress.set(ProgressModel())
|
||||
microgProgress.set(ProgressModel())
|
||||
Log.d("Test", variant)
|
||||
fetching.set(false)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.vanced.manager.ui.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
||||
class HomeViewModelFactory(private val application: Application, private val variant: String = "nonroot") :
|
||||
ViewModelProvider.Factory {
|
||||
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
return HomeViewModel(application, variant) as T
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?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">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="16sp"
|
||||
android:text="@{viewModel.manager.changelog}"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
|
@ -1,27 +0,0 @@
|
|||
<?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.MicrogChangelogFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="16sp"
|
||||
android:text="@{viewModel.microg.changelog}"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
|
@ -1,27 +0,0 @@
|
|||
<?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>
|
|
@ -1,28 +0,0 @@
|
|||
<?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.VancedChangelogFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="16sp"
|
||||
android:text="@{viewModel.vanced.changelog}"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
12
app/src/main/res/layout/view_changelog.xml
Normal file
12
app/src/main/res/layout/view_changelog.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/changelog_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue