0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-26 13:12:59 +00:00

Merge pull request #280 from HaliksaR/improvement/view-binding

Clear All data binding
This commit is contained in:
Tornike Khintibidze 2020-11-24 00:59:51 +04:00 committed by GitHub
commit 477bda0459
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 439 additions and 525 deletions

View file

@ -48,7 +48,7 @@ android {
} }
buildFeatures { buildFeatures {
dataBinding true dataBinding true // ObservableField migrate to flow or liveData
viewBinding true viewBinding true
} }

View file

@ -2,7 +2,9 @@ package com.vanced.manager.adapter
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LifecycleOwner
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.florent37.viewtooltip.ViewTooltip import com.github.florent37.viewtooltip.ViewTooltip
@ -15,6 +17,7 @@ import com.vanced.manager.ui.viewmodels.HomeViewModel
class AppListAdapter( class AppListAdapter(
private val context: FragmentActivity, private val context: FragmentActivity,
private val viewModel: HomeViewModel, private val viewModel: HomeViewModel,
private val lifecycleOwner: LifecycleOwner,
private val tooltip: ViewTooltip private val tooltip: ViewTooltip
) : RecyclerView.Adapter<AppListAdapter.ListViewHolder>() { ) : RecyclerView.Adapter<AppListAdapter.ListViewHolder>() {
@ -30,14 +33,36 @@ class AppListAdapter(
val appCard = binding.appCard val appCard = binding.appCard
fun bind(position: Int) { fun bind(position: Int) {
binding.viewModel = viewModel val dataModel = if (isRoot) rootDataModels[position] else dataModels[position]
binding.dataModel = if (isRoot) rootDataModels[position] else dataModels[position] with(binding) {
binding.app = apps[position] appName.text = dataModel?.appName
dataModel?.buttonTxt?.observe(this@AppListAdapter.lifecycleOwner) {
appInstallButton.text = it
}
appInstallButton.setOnClickListener {
viewModel.openInstallDialog(it, apps[position])
}
appUninstall.setOnClickListener {
dataModel?.appPkg?.let { it1 -> viewModel.uninstallPackage(it1) }
}
appUninstall.isVisible = dataModel?.isAppInstalled?.value == true
appSettings.setOnClickListener {
viewModel.openMicrogSettings()
}
appSettings.isVisible =
apps[position] == context.getString(R.string.microg) && dataModel?.isAppInstalled?.value == true
dataModel?.versionName?.observe(this@AppListAdapter.lifecycleOwner) {
appRemoteVersion.text = it
}
dataModel?.installedVersionName?.observe(this@AppListAdapter.lifecycleOwner) {
appInstalledVersion.text = it
}
}
} }
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListViewHolder {
val view = ViewAppBinding.inflate(LayoutInflater.from(parent.context), parent, false) val view = ViewAppBinding.inflate(LayoutInflater.from(context), parent, false)
return ListViewHolder(view) return ListViewHolder(view)
} }
@ -49,7 +74,7 @@ class AppListAdapter(
AppInfoDialog.newInstance( AppInfoDialog.newInstance(
appName = apps[position], appName = apps[position],
appIcon = dataModels[position]?.appIcon, appIcon = dataModels[position]?.appIcon,
changelog = dataModels[position]?.changelog?.get() changelog = dataModels[position]?.changelog?.value
).show(context.supportFragmentManager, "info") ).show(context.supportFragmentManager, "info")
} }
} }

View file

@ -9,7 +9,8 @@ import com.vanced.manager.R
import com.vanced.manager.databinding.ViewNotificationSettingBinding import com.vanced.manager.databinding.ViewNotificationSettingBinding
import com.vanced.manager.model.NotifModel import com.vanced.manager.model.NotifModel
class GetNotifAdapter(context: Context) : RecyclerView.Adapter<GetNotifAdapter.GetNotifViewHolder>() { class GetNotifAdapter(private val context: Context) :
RecyclerView.Adapter<GetNotifAdapter.GetNotifViewHolder>() {
private val vanced = NotifModel( private val vanced = NotifModel(
"Vanced-Update", "Vanced-Update",
@ -36,12 +37,18 @@ class GetNotifAdapter(context: Context) : RecyclerView.Adapter<GetNotifAdapter.G
val switch = binding.notifSwitch val switch = binding.notifSwitch
fun bind(position: Int) { fun bind(position: Int) {
binding.app = apps[position] with(binding.notifSwitch) {
setKey(apps[position].key)
setSummary(apps[position].switchSummary)
setTitle(apps[position].switchTitle)
setDefaultValue(false)
}
} }
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GetNotifViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GetNotifViewHolder {
val view = ViewNotificationSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false) val view =
ViewNotificationSettingBinding.inflate(LayoutInflater.from(context), parent, false)
return GetNotifViewHolder(view) return GetNotifViewHolder(view)
} }

View file

@ -10,7 +10,10 @@ import com.vanced.manager.databinding.ViewSocialLinkBinding
import com.vanced.manager.model.LinkModel import com.vanced.manager.model.LinkModel
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
class LinkAdapter(context: Context, private val viewModel: HomeViewModel) : RecyclerView.Adapter<LinkAdapter.LinkViewHolder>() { class LinkAdapter(
private val context: Context,
private val viewModel: HomeViewModel
) : RecyclerView.Adapter<LinkAdapter.LinkViewHolder>() {
private val instagram = LinkModel( private val instagram = LinkModel(
AppCompatResources.getDrawable(context, R.drawable.ic_instagram), AppCompatResources.getDrawable(context, R.drawable.ic_instagram),
@ -55,16 +58,18 @@ class LinkAdapter(context: Context, private val viewModel: HomeViewModel) : Recy
val links = arrayOf(instagram, youtube, github, website, telegram, twitter, discord, reddit) val links = arrayOf(instagram, youtube, github, website, telegram, twitter, discord, reddit)
inner class LinkViewHolder(private val binding: ViewSocialLinkBinding) : RecyclerView.ViewHolder(binding.root) { inner class LinkViewHolder(private val binding: ViewSocialLinkBinding) : RecyclerView.ViewHolder(binding.root) {
val logo = binding.linkImage
fun bind(position: Int) {
binding.viewModel = viewModel
binding.linkModel = links[position]
}
val logo = binding.linkImage
fun bind(position: Int) {
binding.linkBg.setOnClickListener {
viewModel.openUrl(links[position].linkUrl)
}
}
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LinkViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LinkViewHolder {
val view = ViewSocialLinkBinding.inflate(LayoutInflater.from(parent.context), parent, false) val view = ViewSocialLinkBinding.inflate(LayoutInflater.from(context), parent, false)
return LinkViewHolder(view) return LinkViewHolder(view)
} }

View file

@ -9,7 +9,8 @@ import com.vanced.manager.R
import com.vanced.manager.databinding.ViewAppCheckboxBinding import com.vanced.manager.databinding.ViewAppCheckboxBinding
import com.vanced.manager.model.SelectAppModel import com.vanced.manager.model.SelectAppModel
class SelectAppsAdapter(context: Context) : RecyclerView.Adapter<SelectAppsAdapter.SelectAppsViewHolder>() { class SelectAppsAdapter(private val context: Context) :
RecyclerView.Adapter<SelectAppsAdapter.SelectAppsViewHolder>() {
private val prefs by lazy { getDefaultSharedPreferences(context) } private val prefs by lazy { getDefaultSharedPreferences(context) }
@ -37,7 +38,7 @@ class SelectAppsAdapter(context: Context) : RecyclerView.Adapter<SelectAppsAdapt
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SelectAppsViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SelectAppsViewHolder {
val view = ViewAppCheckboxBinding.inflate(LayoutInflater.from(parent.context), parent, false) val view = ViewAppCheckboxBinding.inflate(LayoutInflater.from(context), parent, false)
return SelectAppsViewHolder(view) return SelectAppsViewHolder(view)
} }

View file

@ -11,7 +11,7 @@ import com.vanced.manager.model.SponsorModel
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
class SponsorAdapter( class SponsorAdapter(
context: Context, private val context: Context,
private val viewModel: HomeViewModel, private val viewModel: HomeViewModel,
//private val json: ObservableField<JsonObject?> //private val json: ObservableField<JsonObject?>
) : RecyclerView.Adapter<SponsorAdapter.LinkViewHolder>() { ) : RecyclerView.Adapter<SponsorAdapter.LinkViewHolder>() {
@ -35,14 +35,17 @@ class SponsorAdapter(
) { ) {
val logo = binding.sponsorLogo val logo = binding.sponsorLogo
fun bind(position: Int) { fun bind(position: Int) {
binding.viewModel = viewModel with(binding) {
binding.sponsor = sponsors[position] sponsorName.text = sponsors[position].name
cardSponsor.setOnClickListener {
viewModel.openUrl(sponsors[position].url)
}
}
} }
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LinkViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LinkViewHolder {
val view = ViewSponsorBinding.inflate(LayoutInflater.from(parent.context), parent, false) val view = ViewSponsorBinding.inflate(LayoutInflater.from(context), parent, false)
return LinkViewHolder(view) return LinkViewHolder(view)
} }

View file

@ -4,9 +4,8 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import androidx.databinding.Observable import androidx.databinding.Observable
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt import androidx.lifecycle.MutableLiveData
import com.beust.klaxon.JsonObject import com.beust.klaxon.JsonObject
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.PackageHelper.isPackageInstalled import com.vanced.manager.utils.PackageHelper.isPackageInstalled
@ -22,24 +21,28 @@ open class DataModel(
val appIcon: Drawable?, val appIcon: Drawable?,
) { ) {
private val versionCode = ObservableInt() private val versionCode = MutableLiveData<Int>()
private val installedVersionCode = ObservableInt() private val installedVersionCode = MutableLiveData<Int>()
val isAppInstalled = ObservableBoolean() val isAppInstalled = MutableLiveData<Boolean>()
val versionName = ObservableField<String>() val versionName = MutableLiveData<String>()
val installedVersionName = ObservableField<String>() val installedVersionName = MutableLiveData<String>()
val buttonTxt = ObservableField<String>() val buttonTxt = MutableLiveData<String>()
val changelog = ObservableField<String>() val changelog = MutableLiveData<String>()
fun fetch() = CoroutineScope(Dispatchers.IO).launch { fun fetch() = CoroutineScope(Dispatchers.IO).launch {
val jobj = jsonObject.get() val jobj = jsonObject.get()
isAppInstalled.set(isPackageInstalled(appPkg, context.packageManager)) isAppInstalled.postValue(isPackageInstalled(appPkg, context.packageManager))
versionName.set(jobj?.string("version")?.removeSuffix("-vanced") ?: context.getString(R.string.unavailable)) versionName.postValue(
installedVersionName.set(getPkgVersionName(isAppInstalled.get(), appPkg)) jobj?.string("version")?.removeSuffix("-vanced") ?: context.getString(
versionCode.set(jobj?.int("versionCode") ?: 0) R.string.unavailable
installedVersionCode.set(getPkgVersionCode(isAppInstalled.get(), appPkg)) )
buttonTxt.set(compareInt(installedVersionCode.get(), versionCode.get())) )
changelog.set(jobj?.string("changelog") ?: context.getString(R.string.unavailable)) installedVersionName.postValue(getPkgVersionName(isAppInstalled.value, appPkg))
versionCode.postValue(jobj?.int("versionCode") ?: 0)
installedVersionCode.postValue(getPkgVersionCode(isAppInstalled.value, appPkg))
buttonTxt.postValue(compareInt(installedVersionCode.value, versionCode.value))
changelog.postValue(jobj?.string("changelog") ?: context.getString(R.string.unavailable))
} }
init { init {
@ -51,9 +54,9 @@ open class DataModel(
}) })
} }
private fun getPkgVersionName(toCheck: Boolean, pkg: String): String { private fun getPkgVersionName(toCheck: Boolean?, pkg: String): String {
val pm = context.packageManager val pm = context.packageManager
return if (toCheck) { return if (toCheck == true) {
pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced") pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced")
} else { } else {
context.getString(R.string.unavailable) context.getString(R.string.unavailable)
@ -61,23 +64,25 @@ open class DataModel(
} }
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
private fun getPkgVersionCode(toCheck: Boolean, pkg: String): Int { private fun getPkgVersionCode(toCheck: Boolean?, pkg: String): Int {
return if (toCheck) { return if (toCheck == true) {
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()
else else
context.packageManager.getPackageInfo(pkg, 0).versionCode context.packageManager.getPackageInfo(pkg, 0).versionCode
} else 0 } else 0
} }
private fun compareInt(int1: Int, int2: Int): String { private fun compareInt(int1: Int?, int2: Int?): String {
if (int2 != null && int1 != null) {
return when { return when {
int1 == 0 -> context.getString(R.string.install) int1 == 0 -> context.getString(R.string.install)
int2 > int1 -> context.getString(R.string.update) int2 > int1 -> context.getString(R.string.update)
int2 == int1 || int1 > int2 -> context.getString(R.string.button_reinstall) int2 == int1 || int1 > int2 -> context.getString(R.string.button_reinstall)
else -> context.getString(R.string.install) else -> context.getString(R.string.install)
} }
} }
return context.getString(R.string.install)
}
} }

View file

@ -8,7 +8,6 @@ import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.navigation.NavDestination import androidx.navigation.NavDestination
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.AppBarConfiguration
@ -56,12 +55,15 @@ class MainActivity : AppCompatActivity() {
if (ENABLE_CROWDIN_AUTH) if (ENABLE_CROWDIN_AUTH)
authCrowdin() authCrowdin()
binding = DataBindingUtil.setContentView(this, R.layout.activity_main) binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
with(binding) { with(binding) {
lifecycleOwner = this@MainActivity
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
toolbar.setupWithNavController(this@MainActivity.navHost, AppBarConfiguration(this@MainActivity.navHost.graph)) toolbar.setupWithNavController(
this@MainActivity.navHost,
AppBarConfiguration(this@MainActivity.navHost.graph)
)
} }
navHost.addOnDestinationChangedListener { _, currFrag: NavDestination, _ -> navHost.addOnDestinationChangedListener { _, currFrag: NavDestination, _ ->
setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment) setDisplayHomeAsUpEnabled(currFrag.id != R.id.home_fragment)

View file

@ -2,19 +2,16 @@ package com.vanced.manager.ui
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.navigation.findNavController import androidx.navigation.findNavController
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.ActivityWelcomeBinding
class WelcomeActivity : AppCompatActivity() { class WelcomeActivity : AppCompatActivity() {
private lateinit var binding: ActivityWelcomeBinding
private val navHost by lazy { findNavController(R.id.welcome_navhost) } private val navHost by lazy { findNavController(R.id.welcome_navhost) }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_welcome) setContentView(R.layout.activity_welcome)
} }
override fun onBackPressed() { override fun onBackPressed() {

View file

@ -6,10 +6,9 @@ import android.view.LayoutInflater
import android.widget.CompoundButton import android.widget.CompoundButton
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.content.edit import androidx.core.content.edit
import androidx.databinding.BindingAdapter
import androidx.preference.PreferenceManager.getDefaultSharedPreferences import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.vanced.manager.R import com.vanced.manager.R
import kotlinx.android.synthetic.main.view_preference_switch.view.* import com.vanced.manager.databinding.ViewPreferenceSwitchBinding
class PreferenceSwitch @JvmOverloads constructor( class PreferenceSwitch @JvmOverloads constructor(
context: Context, context: Context,
@ -18,26 +17,50 @@ class PreferenceSwitch @JvmOverloads constructor(
defStyleRes: Int = 0 defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyle, defStyleRes) { ) : FrameLayout(context, attrs, defStyle, defStyleRes) {
interface OnCheckedListener {
fun onChecked(buttonView: CompoundButton, isChecked: Boolean)
}
private val prefs by lazy { getDefaultSharedPreferences(context) } private val prefs by lazy { getDefaultSharedPreferences(context) }
var prefKey: String = "" var prefKey: String = ""
private set
var defValue: Boolean = false var defValue: Boolean = false
private set
private var mListener: OnCheckedListener? = null private var mListener: OnCheckedListener? = null
private var _binding: ViewPreferenceSwitchBinding? = null
val binding: ViewPreferenceSwitchBinding
get() = requireNotNull(_binding)
init { init {
LayoutInflater.from(context).inflate(R.layout.view_preference_switch, this, true) _binding = ViewPreferenceSwitchBinding.inflate(LayoutInflater.from(context), this, true)
initAttrs(context, attrs) attrs?.let { mAttrs ->
with(context.obtainStyledAttributes(mAttrs, R.styleable.PreferenceSwitch, 0, 0)) {
val title = getText(R.styleable.PreferenceSwitch_switch_title)
val summary = getText(R.styleable.PreferenceSwitch_switch_summary)
val key = getText(R.styleable.PreferenceSwitch_switch_key)
setDefaultValue(getBoolean(R.styleable.PreferenceSwitch_switch_def_value, false))
setKey(key)
setTitle(title)
setSummary(summary)
recycle()
}
}
} }
override fun onFinishInflate() { override fun onFinishInflate() {
super.onFinishInflate() super.onFinishInflate()
setOnClickListener { setOnClickListener {
preference_switch.isChecked = !preference_switch.isChecked binding.preferenceSwitch.isChecked = !binding.preferenceSwitch.isChecked
} }
preference_switch.setOnCheckedChangeListener { buttonView, isChecked -> binding.preferenceSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
prefs.edit { putBoolean(prefKey, isChecked) } prefs.edit { putBoolean(prefKey, isChecked) }
mListener?.onChecked(buttonView, isChecked) mListener?.onChecked(buttonView, isChecked)
} }
} }
fun setOnCheckedListener(method: (buttonView: CompoundButton, isChecked: Boolean) -> Unit) { fun setOnCheckedListener(method: (buttonView: CompoundButton, isChecked: Boolean) -> Unit) {
@ -52,62 +75,21 @@ class PreferenceSwitch @JvmOverloads constructor(
mListener = listener mListener = listener
} }
private fun initAttrs(context: Context, attrs: AttributeSet?) { fun setTitle(title: CharSequence?) {
attrs?.let { mAttrs -> binding.preferenceSwitchTitle.text = title
val typedArray = context.obtainStyledAttributes(mAttrs, R.styleable.PreferenceSwitch, 0, 0) }
val title = typedArray.getText(R.styleable.PreferenceSwitch_switch_title)
val summary = typedArray.getText(R.styleable.PreferenceSwitch_switch_summary)
val key = typedArray.getText(R.styleable.PreferenceSwitch_switch_key)
val value = typedArray.getBoolean(R.styleable.PreferenceSwitch_switch_def_value, false)
if (key != null) { fun setSummary(summary: CharSequence?) {
binding.preferenceSwitchSummary.text = summary
}
fun setKey(key: CharSequence?) {
prefKey = key.toString() prefKey = key.toString()
preference_switch.isChecked = prefs.getBoolean(key.toString(), value) binding.preferenceSwitch.isChecked = prefs.getBoolean(prefKey, defValue)
} }
defValue = value fun setDefaultValue(newVal: Boolean) {
preference_switch_title.text = title defValue = newVal
binding.preferenceSwitch.isChecked = prefs.getBoolean(prefKey, defValue)
if (summary != null) {
preference_switch_summary.text = summary
}
typedArray.recycle()
} }
} }
interface OnCheckedListener {
fun onChecked(buttonView: CompoundButton, isChecked: Boolean)
}
companion object {
@JvmStatic
@BindingAdapter("app:switch_title")
fun setTitle(view: PreferenceSwitch, newTitle: String) {
view.preference_switch_title.text = newTitle
}
@JvmStatic
@BindingAdapter("app:switch_summary")
fun setSummary(view: PreferenceSwitch, newSummary: String) {
view.preference_switch_summary.text = newSummary
}
@JvmStatic
@BindingAdapter("app:switch_key")
fun setKey(view: PreferenceSwitch, newKey: String) {
view.prefKey = newKey
view.preference_switch.isChecked = view.prefs.getBoolean(view.prefKey, view.defValue)
}
@JvmStatic
@BindingAdapter("app:switch_def_value")
fun setDefaultValue(view: PreferenceSwitch, newVal: Boolean) {
view.defValue = newVal
view.preference_switch.isChecked = view.prefs.getBoolean(view.prefKey, view.defValue)
}
}
}

View file

@ -77,7 +77,7 @@ open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
recyclerAppList.apply { recyclerAppList.apply {
layoutManager = LinearLayoutManager(requireActivity()) layoutManager = LinearLayoutManager(requireActivity())
adapter = AppListAdapter(requireActivity(), this@HomeFragment.viewModel, tooltip) adapter = AppListAdapter(requireActivity(), viewModel, viewLifecycleOwner, tooltip)
setHasFixedSize(true) setHasFixedSize(true)
} }
@ -86,7 +86,7 @@ open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
lm.justifyContent = JustifyContent.SPACE_EVENLY lm.justifyContent = JustifyContent.SPACE_EVENLY
layoutManager = lm layoutManager = lm
setHasFixedSize(true) setHasFixedSize(true)
adapter = SponsorAdapter(requireActivity(), this@HomeFragment.viewModel) adapter = SponsorAdapter(requireActivity(), viewModel)
} }
recyclerLinks.apply { recyclerLinks.apply {
@ -94,7 +94,7 @@ open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
lm.justifyContent = JustifyContent.SPACE_EVENLY lm.justifyContent = JustifyContent.SPACE_EVENLY
layoutManager = lm layoutManager = lm
setHasFixedSize(true) setHasFixedSize(true)
adapter = LinkAdapter(requireActivity(), this@HomeFragment.viewModel) adapter = LinkAdapter(requireActivity(), viewModel)
} }
} }
} }

View file

@ -91,7 +91,7 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
fun openInstallDialog(view: View, app: String) { fun openInstallDialog(view: View, app: String) {
val variant = prefs.getString("vanced_variant", "nonroot") val variant = prefs.getString("vanced_variant", "nonroot")
if (variant == "nonroot" && app != activity.getString(R.string.microg) && !microg.get()?.isAppInstalled?.get()!!) { if (variant == "nonroot" && app != activity.getString(R.string.microg) && !microg.get()?.isAppInstalled?.value!!) {
microgToast.show() microgToast.show()
return return
} }

View file

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
<RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?colorSurface" android:background="?colorSurface"
@ -23,7 +21,6 @@
android:background="?colorSurface" android:background="?colorSurface"
app:titleTextAppearance="@style/ToolbarTextTitle" app:titleTextAppearance="@style/ToolbarTextTitle"
tools:title="Manager" /> tools:title="Manager" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<fragment <fragment
@ -34,7 +31,4 @@
android:layout_below="@id/app_bar" android:layout_below="@id/app_bar"
app:defaultNavHost="true" app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" /> app:navGraph="@navigation/mobile_navigation" />
</RelativeLayout> </RelativeLayout>
</layout>

View file

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
@ -15,7 +13,4 @@
android:layout_height="match_parent" android:layout_height="match_parent"
app:defaultNavHost="true" app:defaultNavHost="true"
app:navGraph="@navigation/welcome_navigation" /> app:navGraph="@navigation/welcome_navigation" />
</RelativeLayout> </RelativeLayout>
</layout>

View file

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout> <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -58,7 +55,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:preference_title="@string/clear_files" /> app:preference_title="@string/clear_files" />
</com.vanced.manager.ui.core.PreferenceCategory> </com.vanced.manager.ui.core.PreferenceCategory>
<com.vanced.manager.ui.core.PreferenceCategory <com.vanced.manager.ui.core.PreferenceCategory
@ -92,9 +88,5 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:preference_title="@string/select_apps" /> app:preference_title="@string/select_apps" />
</com.vanced.manager.ui.core.PreferenceCategory> </com.vanced.manager.ui.core.PreferenceCategory>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
</layout>

View file

@ -1,27 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
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"
<data>
<import type="android.view.View" />
<variable
name="dataModel"
type="com.vanced.manager.model.DataModel" />
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
<variable
name="app"
type="String" />
</data>
<com.google.android.material.card.MaterialCardView
android:id="@+id/app_card" android:id="@+id/app_card"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -44,7 +24,6 @@
<TextView <TextView
android:id="@+id/app_name" android:id="@+id/app_name"
style="@style/CardTextHeader" style="@style/CardTextHeader"
android:text="@{dataModel.appName}"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="@string/vanced" /> tools:text="@string/vanced" />
@ -53,8 +32,6 @@
android:id="@+id/app_install_button" android:id="@+id/app_install_button"
style="@style/OutlinedButtonStyle" style="@style/OutlinedButtonStyle"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:onClick="@{(v)-> viewModel.openInstallDialog(v, app)}"
android:text="@{dataModel.buttonTxt}"
android:textColor="?colorPrimary" android:textColor="?colorPrimary"
app:layout_constraintBottom_toTopOf="@id/app_uninstall" app:layout_constraintBottom_toTopOf="@id/app_uninstall"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -65,10 +42,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:onClick="@{()-> viewModel.uninstallPackage(dataModel.appPkg)}"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/ic_delete_black_24dp" android:src="@drawable/ic_delete_black_24dp"
android:visibility="@{dataModel.isAppInstalled() ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_install_button" app:layout_constraintTop_toBottomOf="@id/app_install_button"
app:tint="?colorLinkImage" /> app:tint="?colorLinkImage" />
@ -79,9 +54,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="2dp" android:layout_marginEnd="2dp"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:onClick="@{()-> viewModel.openMicrogSettings()}"
android:src="@drawable/ic_app_settings_black_24dp" android:src="@drawable/ic_app_settings_black_24dp"
android:visibility="@{(app.equals(@string/microg) &amp;&amp; dataModel.isAppInstalled()) ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toStartOf="@id/app_uninstall" app:layout_constraintEnd_toStartOf="@id/app_uninstall"
app:layout_constraintTop_toBottomOf="@id/app_install_button" app:layout_constraintTop_toBottomOf="@id/app_install_button"
app:tint="?colorLinkImage" /> app:tint="?colorLinkImage" />
@ -104,9 +77,7 @@
<TextView <TextView
android:id="@+id/app_remote_version" android:id="@+id/app_remote_version"
style="@style/AppVersionText" style="@style/AppVersionText"
android:layout_marginStart="4dp" android:layout_marginStart="4dp" />
android:text="@{dataModel.versionName}" />
</com.google.android.flexbox.FlexboxLayout> </com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
@ -127,14 +98,7 @@
<TextView <TextView
android:id="@+id/app_installed_version" android:id="@+id/app_installed_version"
style="@style/AppVersionText" style="@style/AppVersionText"
android:layout_marginStart="4dp" android:layout_marginStart="4dp" />
android:text="@{dataModel.installedVersionName}" />
</com.google.android.flexbox.FlexboxLayout> </com.google.android.flexbox.FlexboxLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout>

View file

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/app_checkbox_bg" android:id="@+id/app_checkbox_bg"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -50,7 +48,4 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:checked="true" /> tools:checked="true" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -1,21 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="app"
type="com.vanced.manager.model.NotifModel" />
</data>
<com.vanced.manager.ui.core.PreferenceSwitch xmlns:android="http://schemas.android.com/apk/res/android" <com.vanced.manager.ui.core.PreferenceSwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notif_switch" android:id="@+id/notif_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
app:switch_def_value="true"
app:switch_key="@{app.key}"
app:switch_summary="@{app.switchSummary}"
app:switch_title="@{app.switchTitle}" />
</layout>

View file

@ -1,18 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
<variable
name="linkModel"
type="com.vanced.manager.model.LinkModel" />
</data>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
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"
@ -22,7 +8,6 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:onClick="@{()-> viewModel.openUrl(linkModel.linkUrl)}"
app:cardBackgroundColor="?colorLinkBG" app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="12dp" app:cardCornerRadius="12dp"
app:cardElevation="0dp" app:cardElevation="0dp"
@ -38,7 +23,4 @@
android:layout_gravity="center" android:layout_gravity="center"
app:tint="?colorLinkImage" app:tint="?colorLinkImage"
tools:src="@drawable/ic_instagram" /> tools:src="@drawable/ic_instagram" />
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout>

View file

@ -1,25 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
<variable
name="sponsor"
type="com.vanced.manager.model.SponsorModel" />
</data>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:id="@+id/card_sponsor"
android:layout_width="165dp" android:layout_width="165dp"
android:layout_height="97dp" android:layout_height="97dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:onClick="@{()-> viewModel.openUrl(sponsor.url)}"
app:cardBackgroundColor="?colorLinkBG" app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="12dp" app:cardCornerRadius="12dp"
app:cardElevation="0dp" app:cardElevation="0dp"
@ -43,7 +29,6 @@
android:id="@+id/sponsor_name" android:id="@+id/sponsor_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{sponsor.name}"
android:textColor="?colorLinkImage" android:textColor="?colorLinkImage"
app:layout_constraintBottom_toTopOf="@id/sponsor_description" app:layout_constraintBottom_toTopOf="@id/sponsor_description"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -55,14 +40,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/support_us" android:text="@string/support_us"
android:textColor="?colorLinkImage"
android:textAlignment="center" android:textAlignment="center"
android:textColor="?colorLinkImage"
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/sponsor_name" /> app:layout_constraintTop_toBottomOf="@id/sponsor_name" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout>