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

swiperefreshlayout test

This commit is contained in:
X1nto 2020-07-05 16:49:35 +04:00
parent cb988af82d
commit 1ba1d7f570
4 changed files with 150 additions and 129 deletions

View file

@ -66,12 +66,14 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-livedata-core-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
// Other
implementation 'com.crowdin.platform:mobile-sdk:1.1.4'
implementation 'com.github.100rabhkr:GetJSON:1.0'
implementation 'com.github.topjohnwu.libsu:core:2.5.1'
implementation 'com.mindorks.android:prdownloader:0.6.0'

View file

@ -34,27 +34,60 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
val vancedInstallButtonTxt: MutableLiveData<String> = MutableLiveData()
val vancedInstallButtonIcon: MutableLiveData<Drawable> = MutableLiveData()
val microgInstalled: Boolean = isPackageInstalled("com.mgoogle.android.gms", application.packageManager)
val vancedInstalled: Boolean = isPackageInstalled(vancedPkgName, application.packageManager)
val microgInstalled: MutableLiveData<Boolean> = MutableLiveData()
val vancedInstalled: MutableLiveData<Boolean> = MutableLiveData()
val vancedInstalledVersion: MutableLiveData<String> = MutableLiveData()
val microgInstalledVersion: MutableLiveData<String> = MutableLiveData()
val vancedVersion: MutableLiveData<String> = MutableLiveData()
val microgVersion: MutableLiveData<String> = MutableLiveData()
val microgInstallButtonTxt: MutableLiveData<String> = MutableLiveData()
val microgInstallButtonIcon: MutableLiveData<Drawable> = MutableLiveData()
private val vancedInstalledVersionCode = getPkgVerCode(vancedInstalled, vancedPkgName)
private val microgInstalledVersionCode = getPkgVerCode(microgInstalled, "com.mgoogle.android.gms")
private val vancedInstalledVersionCode: MutableLiveData<Int> = MutableLiveData()
private val microgInstalledVersionCode: MutableLiveData<Int> = MutableLiveData()
private val vancedVersionCode = displayJsonInt("vanced.json", "versionCode", application)
private val microgVersionCode = displayJsonInt("microg.json", "versionCode", application)
val microgInstallButtonTxt = compareInt(microgInstalledVersionCode, microgVersionCode, application)
val microgInstallButtonIcon = compareIntDrawable(microgInstalledVersionCode, microgVersionCode, application)
private val vancedVersionCode: MutableLiveData<Int> = MutableLiveData()
private val microgVersionCode: MutableLiveData<Int> = MutableLiveData()
val nonrootModeSelected: Boolean = variant == "nonroot"
val fetching: MutableLiveData<Boolean> = MutableLiveData()
fun fetchData() {
fetching.value = true
vancedVersion.value = displayJsonString("vanced.json", "version", getApplication())
microgVersion.value = displayJsonString("microg.json", "version", getApplication())
vancedInstalledVersion.value = getPkgInfo(vancedInstalled.value!!, vancedPkgName, getApplication())
microgInstalledVersion.value = getPkgInfo(microgInstalled.value!!, "com.mgoogle.android.gms", getApplication())
microgInstalled.value = isPackageInstalled("com.mgoogle.android.gms", pm)
vancedVersionCode.value = displayJsonInt("vanced.json", "versionCode", getApplication())
microgVersionCode.value = displayJsonInt("microg.json", "versionCode", getApplication())
vancedInstalledVersionCode.value = getPkgVerCode(vancedInstalled.value!!, vancedPkgName)
vancedInstalledVersionCode.value = getPkgVerCode(microgInstalled.value!!, "com.mgoogle.android.gms")
vancedInstalled.value = isPackageInstalled(vancedPkgName, pm)
microgInstallButtonTxt.value = compareInt(microgInstalledVersionCode.value!!, microgVersionCode.value!!, getApplication())
microgInstallButtonIcon.value = compareIntDrawable(microgInstalledVersionCode.value!!, microgVersionCode.value!!, getApplication())
vancedInstallButtonIcon.value =
if (variant == "nonroot") {
if (microgInstalled.value!!)
compareIntDrawable(vancedVersionCode.value!!, vancedInstalledVersionCode.value!!, getApplication())
else
null
} else
compareIntDrawable(vancedVersionCode.value!!, vancedInstalledVersionCode.value!!, getApplication())
vancedInstallButtonTxt.value =
if (variant == "nonroot") {
if (microgInstalled.value!!) {
compareInt(vancedVersionCode.value!!, vancedInstalledVersionCode.value!!, getApplication())
} else {
getApplication<Application>().getString(R.string.no_microg)
}
} else
compareInt(vancedVersionCode.value!!, vancedInstalledVersionCode.value!!, getApplication())
fetching.value = false
}
fun openMicrogSettings() {
try {
val intent = Intent()
@ -132,29 +165,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
}
init {
vancedVersion.value = displayJsonString("vanced.json", "version", application)
microgVersion.value = displayJsonString("microg.json", "version", application)
vancedInstalledVersion.value = getPkgInfo(vancedInstalled, vancedPkgName, application)
microgInstalledVersion.value = getPkgInfo(microgInstalled, "com.mgoogle.android.gms", application)
vancedInstallButtonIcon.value =
if (variant == "nonroot") {
if (microgInstalled)
compareIntDrawable(vancedVersionCode, vancedInstalledVersionCode, application)
else
null
} else
compareIntDrawable(vancedVersionCode, vancedInstalledVersionCode, application)
vancedInstallButtonTxt.value =
if (variant == "nonroot") {
if (microgInstalled) {
compareInt(vancedVersionCode, vancedInstalledVersionCode, application)
} else {
application.getString(R.string.no_microg)
}
} else
compareInt(vancedVersionCode, vancedInstalledVersionCode, application)
fetchData()
}
}

View file

@ -1,13 +1,13 @@
package com.vanced.manager.utils
import android.app.Activity
import android.content.res.Configuration
import androidx.preference.PreferenceManager
import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity
object ThemeHelper {
fun setFinalTheme(activity: MainActivity) {
fun setFinalTheme(activity: Activity) {
val currentAccent = PreferenceManager.getDefaultSharedPreferences(activity).getString("accent_color", "Blue")
when (PreferenceManager.getDefaultSharedPreferences(activity)
.getString("theme_mode", "Follow System")) {

View file

@ -12,120 +12,128 @@
</data>
<com.vanced.manager.ui.core.SlidingNestedScrollView
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fillViewport="true"
android:scrollbars="none">
bind:refreshing="@{viewModel.fetching}"
bind:onRefreshListener="@{()-> viewModel.fetchData()}">
<LinearLayout
<com.vanced.manager.ui.core.SlidingNestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:orientation="horizontal">
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
<FrameLayout
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" />
android:layout_alignParentStart="true">
<com.google.android.material.button.MaterialButton
android:id="@+id/nonroot_switch"
style="@style/ButtonStyle"
<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:text="@string/nonroot"
android:visibility="@{viewModel.nonrootModeSelected ? View.GONE : View.VISIBLE}" />
android:layout_alignParentEnd="true">
</FrameLayout>
<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" />
<FrameLayout
android:layout_width="wrap_content"
<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>
<include
android:id="@+id/include_vanced_layout"
layout="@layout/include_vanced"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp"
bind:viewModel="@{viewModel}" />
<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" />
<include
android:id="@+id/include_microg_layout"
layout="@layout/include_microg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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}" />
<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}" />
<include
android:id="@+id/include_changelogs_layout"
layout="@layout/include_changelogs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp" />
</FrameLayout>
<include
layout="@layout/include_useful_links"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp"
bind:viewModel="@{viewModel}" />
</RelativeLayout>
</LinearLayout>
<include
android:id="@+id/include_vanced_layout"
layout="@layout/include_vanced"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp"
bind:viewModel="@{viewModel}" />
</com.vanced.manager.ui.core.SlidingNestedScrollView>
<include
android:id="@+id/include_microg_layout"
layout="@layout/include_microg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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
android:id="@+id/include_changelogs_layout"
layout="@layout/include_changelogs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp" />
<include
layout="@layout/include_useful_links"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp"
bind:viewModel="@{viewModel}" />
</LinearLayout>
</com.vanced.manager.ui.core.SlidingNestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</layout>