0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-22 19:25:11 +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,19 +9,20 @@ 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",
context.getString(R.string.push_notifications, context.getString(R.string.vanced)), context.getString(R.string.push_notifications, context.getString(R.string.vanced)),
context.getString(R.string.push_notifications_summary, context.getString(R.string.vanced)), context.getString(R.string.push_notifications_summary, context.getString(R.string.vanced)),
"vanced_notifs" "vanced_notifs"
) )
private val music = NotifModel( private val music = NotifModel(
"MicroG-Update", "MicroG-Update",
context.getString(R.string.push_notifications, context.getString(R.string.music)), context.getString(R.string.push_notifications, context.getString(R.string.music)),
context.getString(R.string.push_notifications_summary, context.getString(R.string.music)), context.getString(R.string.push_notifications_summary, context.getString(R.string.music)),
"music_notifs" "music_notifs"
) )
private val microg = NotifModel( private val microg = NotifModel(
"Music-Update", "Music-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 {
return when { if (int2 != null && int1 != null) {
int1 == 0 -> context.getString(R.string.install) return when {
int2 > int1 -> context.getString(R.string.update) int1 == 0 -> context.getString(R.string.install)
int2 == int1 || int1 > int2 -> context.getString(R.string.button_reinstall) int2 > int1 -> context.getString(R.string.update)
else -> context.getString(R.string.install) int2 == int1 || int1 > int2 -> context.getString(R.string.button_reinstall)
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) {
prefKey = key.toString()
preference_switch.isChecked = prefs.getBoolean(key.toString(), value)
}
defValue = value
preference_switch_title.text = title
if (summary != null) {
preference_switch_summary.text = summary
}
typedArray.recycle()
}
} }
interface OnCheckedListener { fun setSummary(summary: CharSequence?) {
fun onChecked(buttonView: CompoundButton, isChecked: Boolean) binding.preferenceSwitchSummary.text = summary
} }
companion object { fun setKey(key: CharSequence?) {
prefKey = key.toString()
@JvmStatic binding.preferenceSwitch.isChecked = prefs.getBoolean(prefKey, defValue)
@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)
}
} }
fun setDefaultValue(newVal: Boolean) {
defValue = newVal
binding.preferenceSwitch.isChecked = prefs.getBoolean(prefKey, 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,40 +1,34 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorSurface"
tools:context=".ui.MainActivity">
<RelativeLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?colorSurface"
app:titleTextAppearance="@style/ToolbarTextTitle"
tools:title="Manager" />
</com.google.android.material.appbar.AppBarLayout>
<fragment
android:id="@+id/nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?colorSurface" android:layout_below="@id/app_bar"
tools:context=".ui.MainActivity"> app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
<com.google.android.material.appbar.AppBarLayout </RelativeLayout>
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?colorSurface"
app:titleTextAppearance="@style/ToolbarTextTitle"
tools:title="Manager" />
</com.google.android.material.appbar.AppBarLayout>
<fragment
android:id="@+id/nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/app_bar"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
</RelativeLayout>
</layout>

View file

@ -1,21 +1,16 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.WelcomeActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <fragment
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/welcome_navhost"
xmlns:tools="http://schemas.android.com/tools" android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.WelcomeActivity"> app:defaultNavHost="true"
app:navGraph="@navigation/welcome_navigation" />
<fragment </RelativeLayout>
android:id="@+id/welcome_navhost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/welcome_navigation" />
</RelativeLayout>
</layout>

View file

@ -1,65 +1,61 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView <LinearLayout
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"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="8dp"
android:paddingTop="16dp">
<LinearLayout <com.vanced.manager.ui.core.PreferenceCategory
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:background="@drawable/category_background"
android:paddingHorizontal="8dp" app:category_title="@string/category_behaviour">
android:paddingTop="16dp">
<com.vanced.manager.ui.core.PreferenceCategory <com.vanced.manager.ui.core.PreferenceSwitch
android:id="@+id/use_custom_tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/category_background" app:switch_def_value="true"
app:category_title="@string/category_behaviour"> app:switch_key="@{@string/use_custom_tabs}"
app:switch_summary="@string/link_custom_tabs"
app:switch_title="@string/link_title" />
<com.vanced.manager.ui.core.PreferenceSwitch <androidx.recyclerview.widget.RecyclerView
android:id="@+id/use_custom_tabs" android:id="@+id/notifications_recycler"
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" android:nestedScrollingEnabled="false"
app:switch_key="@{@string/use_custom_tabs}" tools:itemCount="3"
app:switch_summary="@string/link_custom_tabs" tools:listitem="@layout/view_preference_switch" />
app:switch_title="@string/link_title"/>
<androidx.recyclerview.widget.RecyclerView <com.vanced.manager.ui.core.PreferenceSwitch
android:id="@+id/notifications_recycler" android:id="@+id/firebase"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" app:switch_def_value="true"
tools:itemCount="3" app:switch_key="@{@string/firebase}"
tools:listitem="@layout/view_preference_switch"/> app:switch_summary="@string/firebase_summary"
app:switch_title="@string/firebase_title" />
<com.vanced.manager.ui.core.PreferenceSwitch <com.vanced.manager.ui.core.EmptyPreference
android:id="@+id/firebase" android:id="@+id/manager_variant"
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:preference_title="@string/variant" />
app:switch_key="@{@string/firebase}"
app:switch_summary="@string/firebase_summary"
app:switch_title="@string/firebase_title"/>
<com.vanced.manager.ui.core.EmptyPreference <com.vanced.manager.ui.core.EmptyPreference
android:id="@+id/manager_variant" android:id="@+id/clearFiles"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:preference_title="@string/variant"/> app:preference_title="@string/clear_files" />
</com.vanced.manager.ui.core.PreferenceCategory>
<com.vanced.manager.ui.core.EmptyPreference
android:id="@+id/clearFiles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:preference_title="@string/clear_files"/>
</com.vanced.manager.ui.core.PreferenceCategory>
<com.vanced.manager.ui.core.PreferenceCategory <com.vanced.manager.ui.core.PreferenceCategory
android:layout_width="match_parent" android:layout_width="match_parent"
@ -84,17 +80,13 @@
android:id="@+id/manager_language" android:id="@+id/manager_language"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:preference_title="@string/language_title"/> app:preference_title="@string/language_title" />
<com.vanced.manager.ui.core.EmptyPreference <com.vanced.manager.ui.core.EmptyPreference
android:id="@+id/select_apps" android:id="@+id/select_apps"
android:layout_width="match_parent" android:layout_width="match_parent"
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,113 +1,84 @@
<?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"
android:id="@+id/app_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="16dp"
app:cardElevation="0dp"
app:contentPaddingBottom="4dp"
app:contentPaddingLeft="16dp"
app:contentPaddingRight="16dp"
app:contentPaddingTop="8dp">
<data> <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/app_view_container"
<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:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent"
app:cardBackgroundColor="?colorLinkBG" app:layout_constraintTop_toTopOf="parent">
app:cardCornerRadius="16dp"
app:cardElevation="0dp"
app:contentPaddingBottom="4dp"
app:contentPaddingLeft="16dp"
app:contentPaddingRight="16dp"
app:contentPaddingTop="8dp">
<androidx.constraintlayout.widget.ConstraintLayout <TextView
android:id="@+id/app_view_container" android:id="@+id/app_name"
style="@style/CardTextHeader"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/vanced" />
<com.google.android.material.button.MaterialButton
android:id="@+id/app_install_button"
style="@style/OutlinedButtonStyle"
android:layout_marginTop="4dp"
android:textColor="?colorPrimary"
app:layout_constraintBottom_toTopOf="@id/app_uninstall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/app_uninstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ic_delete_black_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_install_button"
app:tint="?colorLinkImage" />
<ImageButton
android:id="@+id/app_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_app_settings_black_24dp"
app:layout_constraintEnd_toStartOf="@id/app_uninstall"
app:layout_constraintTop_toBottomOf="@id/app_install_button"
app:tint="?colorLinkImage" />
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/app_remote_version_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:flexWrap="wrap"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="@id/app_installed_version_container"
app:layout_constraintEnd_toStartOf="@id/app_install_button"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toBottomOf="@id/app_name">
<TextView <TextView
android:id="@+id/app_name" style="@style/AppVersionText"
style="@style/CardTextHeader" android:text="@string/latest" />
android:text="@{dataModel.appName}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/vanced" />
<com.google.android.material.button.MaterialButton <TextView
android:id="@+id/app_install_button" android:id="@+id/app_remote_version"
style="@style/OutlinedButtonStyle" style="@style/AppVersionText"
android:layout_marginTop="4dp" android:layout_marginStart="4dp" />
android:onClick="@{(v)-> viewModel.openInstallDialog(v, app)}" </com.google.android.flexbox.FlexboxLayout>
android:text="@{dataModel.buttonTxt}"
android:textColor="?colorPrimary"
app:layout_constraintBottom_toTopOf="@id/app_uninstall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/app_uninstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:onClick="@{()-> viewModel.uninstallPackage(dataModel.appPkg)}"
android:scaleType="fitCenter"
android:src="@drawable/ic_delete_black_24dp"
android:visibility="@{dataModel.isAppInstalled() ? View.VISIBLE : View.GONE}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_install_button"
app:tint="?colorLinkImage" />
<ImageButton
android:id="@+id/app_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:background="@android:color/transparent"
android:onClick="@{()-> viewModel.openMicrogSettings()}"
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_constraintTop_toBottomOf="@id/app_install_button"
app:tint="?colorLinkImage" />
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/app_remote_version_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="wrap"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="@id/app_installed_version_container"
app:layout_constraintEnd_toStartOf="@id/app_install_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_name">
<TextView
style="@style/AppVersionText"
android:text="@string/latest" />
<TextView
android:id="@+id/app_remote_version"
style="@style/AppVersionText"
android:layout_marginStart="4dp"
android:text="@{dataModel.versionName}" />
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
android:id="@+id/app_installed_version_container" android:id="@+id/app_installed_version_container"
@ -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,56 +1,51 @@
<?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"
android:id="@+id/app_checkbox_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp">
<androidx.constraintlayout.widget.ConstraintLayout <TextView
android:id="@+id/app_checkbox_bg" android:id="@+id/app_checkbox_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:letterSpacing="0.15"
android:textAllCaps="true"
android:textColor="?colorPrimary"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/vanced" />
<TextView
android:id="@+id/app_checkbox_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginTop="4dp"
android:layout_marginTop="16dp" android:layout_marginEnd="24dp"
android:layout_marginEnd="8dp"> android:gravity="start"
android:paddingBottom="4dp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/app_checkbox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_checkbox_text"
tools:text="YouTube Vanced is the stock Android YouTube App, but better!" />
<TextView <com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/app_checkbox_text" android:id="@+id/app_checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:buttonTint="?colorError"
android:letterSpacing="0.15" android:clickable="false"
android:textAllCaps="true" app:layout_constraintBottom_toBottomOf="parent"
android:textColor="?colorPrimary" app:layout_constraintEnd_toEndOf="parent"
android:textSize="12sp" app:layout_constraintTop_toTopOf="parent"
android:textStyle="bold" tools:checked="true" />
app:layout_constraintStart_toStartOf="parent" </androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/vanced" />
<TextView
android:id="@+id/app_checkbox_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
android:gravity="start"
android:paddingBottom="4dp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/app_checkbox"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_checkbox_text"
tools:text="YouTube Vanced is the stock Android YouTube App, but better!" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/app_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="?colorError"
android:clickable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:checked="true" />
</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"> <com.vanced.manager.ui.core.PreferenceSwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notif_switch"
<data> android:layout_width="match_parent"
android:layout_height="wrap_content" />
<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"
android:id="@+id/notif_switch"
android:layout_width="match_parent"
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,44 +1,26 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout> <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:tools="http://schemas.android.com/tools"
android:id="@+id/link_bg"
android:layout_width="80dp"
android:layout_height="68dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="12dp"
app:cardElevation="0dp"
app:contentPaddingBottom="4dp"
app:contentPaddingLeft="8dp"
app:contentPaddingRight="8dp"
app:contentPaddingTop="2dp">
<data> <ImageView
android:id="@+id/link_image"
<variable android:layout_width="wrap_content"
name="viewModel" android:layout_height="wrap_content"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" /> android:layout_gravity="center"
app:tint="?colorLinkImage"
<variable tools:src="@drawable/ic_instagram" />
name="linkModel" </com.google.android.material.card.MaterialCardView>
type="com.vanced.manager.model.LinkModel" />
</data>
<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:tools="http://schemas.android.com/tools"
android:id="@+id/link_bg"
android:layout_width="80dp"
android:layout_height="68dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:onClick="@{()-> viewModel.openUrl(linkModel.linkUrl)}"
app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="12dp"
app:cardElevation="0dp"
app:contentPaddingBottom="4dp"
app:contentPaddingLeft="8dp"
app:contentPaddingRight="8dp"
app:contentPaddingTop="2dp">
<ImageView
android:id="@+id/link_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:tint="?colorLinkImage"
tools:src="@drawable/ic_instagram" />
</com.google.android.material.card.MaterialCardView>
</layout>

View file

@ -1,68 +1,49 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout> <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:tools="http://schemas.android.com/tools"
android:id="@+id/card_sponsor"
android:layout_width="165dp"
android:layout_height="97dp"
android:layout_marginTop="8dp"
app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="12dp"
app:cardElevation="0dp"
app:contentPaddingTop="12dp">
<data> <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<variable <ImageView
name="viewModel" android:id="@+id/sponsor_logo"
type="com.vanced.manager.ui.viewmodels.HomeViewModel" /> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="?colorLinkImage"
tools:src="@drawable/ic_brave" />
<variable <TextView
name="sponsor" android:id="@+id/sponsor_name"
type="com.vanced.manager.model.SponsorModel" /> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?colorLinkImage"
app:layout_constraintBottom_toTopOf="@id/sponsor_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</data> <TextView
android:id="@+id/sponsor_description"
<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:tools="http://schemas.android.com/tools"
android:layout_width="165dp"
android:layout_height="97dp"
android:layout_marginTop="8dp"
android:onClick="@{()-> viewModel.openUrl(sponsor.url)}"
app:cardBackgroundColor="?colorLinkBG"
app:cardCornerRadius="12dp"
app:cardElevation="0dp"
app:contentPaddingTop="12dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:text="@string/support_us"
<ImageView android:textAlignment="center"
android:id="@+id/sponsor_logo" android:textColor="?colorLinkImage"
android:layout_width="wrap_content" android:textSize="18sp"
android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="16dp" app:layout_constraintTop_toBottomOf="@id/sponsor_name" />
app:layout_constraintStart_toStartOf="parent" </androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent" </com.google.android.material.card.MaterialCardView>
app:tint="?colorLinkImage"
tools:src="@drawable/ic_brave" />
<TextView
android:id="@+id/sponsor_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{sponsor.name}"
android:textColor="?colorLinkImage"
app:layout_constraintBottom_toTopOf="@id/sponsor_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/sponsor_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/support_us"
android:textColor="?colorLinkImage"
android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/sponsor_name" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>