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

Switched to TabLayout for variant selection

This commit is contained in:
X1nto 2020-08-26 15:09:34 +04:00
parent 3805145aba
commit 3a3624e1be
13 changed files with 305 additions and 81 deletions

View file

@ -0,0 +1,14 @@
package com.vanced.manager.adapter
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.vanced.manager.ui.fragments.MainFragment
class SectionVariantAdapter(fragment: Fragment): FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 3
override fun createFragment(position: Int): Fragment = MainFragment()
}

View file

@ -13,6 +13,8 @@ import androidx.navigation.ui.setupWithNavController
import androidx.preference.PreferenceManager
import com.crowdin.platform.Crowdin
import com.crowdin.platform.LoadingStateListener
import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.tabs.TabLayout
import com.google.firebase.messaging.FirebaseMessaging
import com.vanced.manager.R
import com.vanced.manager.databinding.ActivityMainBinding
@ -22,6 +24,7 @@ import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.InternetTools
import com.vanced.manager.utils.PackageHelper
import com.vanced.manager.utils.ThemeHelper.setFinalTheme
import com.vanced.manager.adapter.SectionVariantAdapter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -53,10 +56,61 @@ class MainActivity : AppCompatActivity() {
setSupportActionBar(homeToolbar)
val appBarConfiguration = AppBarConfiguration(navHost.graph)
homeToolbar.setupWithNavController(navHost, appBarConfiguration)
mainViewpager.adapter = SectionVariantAdapter()
TabLayoutMediator(mainTablayout, mainViewpager) { tab, position ->
when (position) {
0 -> tab.text = "nonroot"
1 -> tab.text = "Music"
2 -> tab.text = "root"
}
}.attach()
when (variant) {
"nonroot" -> mainTablayout.getTabAt(0).select()
"music" -> mainTablayout.getTabAt(1).select()
"nonroot" -> mainTablayout.getTabAt(2).select()
}
mainTablayout.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
getDefaultSharedPreferences(requireActivity()).edit().apply {
when (tab.position) {
0 -> putString("vanced_variant", "nonroot")
0 -> putString("vanced_variant", "music")
0 -> putString("vanced_variant", "root")
}
}
}
override fun onTabUnselected(tab: TabLayout.Tab) {}
override fun onTabReselected(tab: TabLayout.Tab) {
getDefaultSharedPreferences(requireActivity()).edit().apply {
when (tab.position) {
0 -> putString("vanced_variant", "nonroot")
0 -> putString("vanced_variant", "music")
0 -> putString("vanced_variant", "root")
}
}
}
}
}
navHost.addOnDestinationChangedListener { _, currFrag: NavDestination, _ ->
setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment)
val tabHide = AnimationUtils.loadAnimation(this, R.anim.tablayout_exit)
val tabShow = AnimationUtils.loadAnimation(this, R.anim.tablayout_enter)
if (currFrag.id != R.id.home_fragment) {
binding.variantTabContainer.startAnimation(tabHide)
binding.variantTabContainer.visibility = View.GONE
} else {
binding.variantTabContainer.visibility = View.VISIBLE
binding.variantTabContainer.startAnimation(tabShow)
}
}
initDialogs()

View file

@ -48,7 +48,19 @@ class HomeFragment : Fragment(), View.OnClickListener {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
val variantPref = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant", "nonroot")
val arg = "variant"
val variant = getDefaultSharedPreferences(requireActivity()).getString("vanced_variant")
with(binding) {
when (variant) {
"nonroot" -> includeMusicLayout.musicCard.visibility = View.GONE
"music" -> includeVancedLayout.vancedCard.visibility = View.GONE
"root" -> {
includeMusicLayout.musicCard.visibility = View.GONE
includeMicrogLayout.microgCard.visibility = View.GONE
}
}
}
with(binding) {
rootSwitch.setOnClickListener(this@HomeFragment)
@ -72,9 +84,9 @@ class HomeFragment : Fragment(), View.OnClickListener {
}
with(binding.includeChangelogsLayout) {
viewpager.adapter = if (variantPref == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
viewpager.adapter = if (variant == "root") SectionPageRootAdapter(this@HomeFragment) else SectionPageAdapter(this@HomeFragment)
TabLayoutMediator(tablayout, viewpager) { tab, position ->
if (variantPref == "root")
if (variant == "root")
when (position) {
0 -> tab.text = "Vanced"
1 -> tab.text = "Manager"

View file

@ -0,0 +1,14 @@
import androidx.fragment.app.Fragment
class HomeFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
requireActivity().title = getString(R.string.title_home)
setHasOptionsMenu(true)
return inflater.inflate(inflater, R.layout.fragment_main, container, false)
}
}

View file

@ -44,7 +44,6 @@ object AppUtils {
status.contains("IFile_Missing") -> context.getString(R.string.IFile_Missing)
status.contains("ModApk_Missing") -> context.getString(R.string.ModApk_Missing)
status.contains("Files_Missing_VA") -> context.getString(R.string.Files_Missing_VA)
status.contains("Corrupt_Data") -> context.getString(R.string.Corrupt_Data)
else ->
if (MiuiHelper.isMiui())
context.getString(R.string.installation_miui)
@ -70,4 +69,4 @@ object AppUtils {
}
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromYDelta="-100%p"
android:toYDelta="0"
</set>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromYDelta="0"
android:toYDelta="-100%p"
</set>

View file

@ -9,15 +9,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/bottom_nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/home_appbar"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation"/>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/home_appbar"
android:layout_width="match_parent"
@ -33,7 +24,30 @@
android:background="@android:color/transparent"/>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:id="@+id/variant_tab_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.google.android.material.tabs.TabLayout
android:id="@+id/main_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurfaceVariant"
app:tabIndicatorColor="?colorPrimary"
app:tabSelectedTextColor="?colorPrimary"
app:tabTextColor="?colorPrimary" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
</layout>
</layout>

View file

@ -29,68 +29,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nonroot"
android:textAllCaps="false"
android:visibility="@{viewModel.nonrootModeSelected ? View.VISIBLE : View.GONE}"
bind:strokeColor="?colorPrimary"
bind:strokeWidth="2dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/nonroot_switch"
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nonroot"
android:visibility="@{viewModel.nonrootModeSelected ? View.GONE : View.VISIBLE}" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/root"
android:textAllCaps="false"
android:visibility="@{viewModel.nonrootModeSelected ? View.GONE : View.VISIBLE}"
bind:strokeColor="?colorPrimary"
bind:strokeWidth="2dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/root_switch"
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/root"
android:visibility="@{viewModel.nonrootModeSelected ? View.VISIBLE : View.GONE}" />
</FrameLayout>
</RelativeLayout>
android:orientation="horizontal">
<include
android:id="@+id/include_vanced_layout"
@ -110,7 +49,6 @@
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp"
android:visibility="@{viewModel.nonrootModeSelected ? View.VISIBLE : View.GONE}"
bind:viewModel="@{viewModel}" />
<include

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottom_nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/home_appbar"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation"/>

View file

@ -12,4 +12,4 @@
android:layout_height="match_parent"
android:textSize="16sp" />
</FrameLayout>
</FrameLayout>

View file

@ -52,7 +52,6 @@
android:layout_height="wrap_content"
android:background="?colorSurfaceVariant"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="parent"
app:tabIndicatorColor="?colorPrimary"
app:tabSelectedTextColor="?colorPrimary"
app:tabTextColor="?colorPrimary"
@ -70,4 +69,4 @@
</com.google.android.material.card.MaterialCardView>
</layout>
</layout>

View file

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data>
<com.google.android.material.card.MaterialCardView
android:id="@+id/microg_card"
style="@style/MaterialCard">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/home_microg_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/microg_title_buttons_barrier"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_microg" />
<TextView
style="@style/TextAppTitle"
android:text="@string/microg"
app:layout_constraintBottom_toTopOf="@id/microg_title_buttons_barrier"
app:layout_constraintStart_toEndOf="@id/home_microg_logo"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/microg_installbtn"
style="@style/ButtonStyle"
android:text="@{viewModel.microgInstallButtonTxt}"
app:icon="@{viewModel.microgInstallButtonIcon}"
app:layout_constraintBottom_toTopOf="@id/microg_uninstallbtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/microg_title_buttons_barrier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="microg_installbtn" />
<LinearLayout
android:id="@+id/microg_remote_latest_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/linearLayout2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/microg_title_buttons_barrier">
<TextView
style="@style/AppVer"
android:text="@string/latest" />
<TextView
android:id="@+id/microg_latest_version"
style="@style/AppVer.Bold"
android:text="@{viewModel.microgVersion}" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/microg_remote_latest_version">
<TextView
style="@style/AppVer"
android:text="@string/version_installed" />
<TextView
android:id="@+id/microg_installed_version"
style="@style/AppVer.Bold"
android:text="@{viewModel.microgInstalledVersion}" />
</LinearLayout>
<ImageView
android:id="@+id/microg_settingsbtn"
style="@style/ClickableImageWidget"
android:layout_marginEnd="4dp"
android:onClick="@{()-> viewModel.openMicrogSettings()}"
android:visibility="@{viewModel.microgInstalled ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/microg_uninstallbtn"
app:layout_constraintTop_toBottomOf="@id/microg_title_buttons_barrier"
app:srcCompat="@drawable/ic_microg_settings" />
<ImageView
android:id="@+id/microg_uninstallbtn"
style="@style/ClickableImageWidget.Red"
android:visibility="@{viewModel.microgInstalled ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/microg_title_buttons_barrier"
app:srcCompat="@drawable/ic_delete_black_24dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/microg_downloading_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible" />
<ProgressBar
android:id="@+id/microg_downloading"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible" />
<ProgressBar
android:id="@+id/microg_installing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</layout>