viewmodel haha yEs

This commit is contained in:
X1nto 2020-05-20 23:40:19 +04:00
parent 4746a3e696
commit d3132b68dd
4 changed files with 195 additions and 160 deletions

View File

@ -48,7 +48,7 @@ open class Home : BaseFragment() {
val microgStatus = pm?.let { isPackageInstalled("com.mgoogle.android.gms", it) } val microgStatus = pm?.let { isPackageInstalled("com.mgoogle.android.gms", it) }
val vancedStatus = pm?.let { isPackageInstalled("com.vanced.android.youtube", it) } val vancedStatus = pm?.let { isPackageInstalled("com.vanced.android.youtube", it) }
val vancedLatestTxt = view.findViewById<TextView>(R.id.vanced_latest_version) /*val vancedLatestTxt = view.findViewById<TextView>(R.id.vanced_latest_version)
val microgLatestTxt = view.findViewById<TextView>(R.id.microg_latest_version) val microgLatestTxt = view.findViewById<TextView>(R.id.microg_latest_version)
if (GetJson().isConnected(requireContext())) { if (GetJson().isConnected(requireContext())) {
@ -60,7 +60,7 @@ open class Home : BaseFragment() {
} else { } else {
vancedLatestTxt.text = getString(R.string.unavailable) vancedLatestTxt.text = getString(R.string.unavailable)
microgLatestTxt.text = getString(R.string.unavailable) microgLatestTxt.text = getString(R.string.unavailable)
} }*/
vancedinstallbtn.setOnClickListener { vancedinstallbtn.setOnClickListener {
view.findNavController().navigate(R.id.toInstallThemeFragment) view.findNavController().navigate(R.id.toInstallThemeFragment)

View File

@ -1,12 +1,16 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.app.Activity import android.app.Activity
import android.app.Application
import android.content.pm.PackageManager import android.content.pm.PackageManager
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.dezlum.codelabs.getjson.GetJson
import com.google.gson.JsonObject
class HomeViewModel { class HomeViewModel(application: Application): AndroidViewModel(application) {
private val pm: PackageManager? = Activity().packageManager /*private val pm: PackageManager? = Activity().packageManager
//we need to check whether these apps are installed or not //we need to check whether these apps are installed or not
val microgStatus: Boolean? = pm?.let { isPackageInstalled("com.mgoogle.android.gms", it) } val microgStatus: Boolean? = pm?.let { isPackageInstalled("com.mgoogle.android.gms", it) }
@ -23,5 +27,12 @@ class HomeViewModel {
val microgInstalledTxt: String? = pm?.getPackageInfo("com.mgoogle.android.gms", 0)?.versionName val microgInstalledTxt: String? = pm?.getPackageInfo("com.mgoogle.android.gms", 0)?.versionName
val vancedInstalledTxt: String? = pm?.getPackageInfo("com.vanced.android.youtube", 0)?.versionName val vancedInstalledTxt: String? = pm?.getPackageInfo("com.vanced.android.youtube", 0)?.versionName
*/
val isConnected: Boolean = GetJson().isConnected(getApplication())
private val vancedVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json")
private val microgVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
val vancedLatestTxt: String? = vancedVer.get("version").asString
val microgLatestTxt: String? = microgVer.get("version").asString
} }

View File

@ -1,7 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView <layout
xmlns:android="http://schemas.android.com/apk/res/android" 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">
<data>
<variable
name="viewModel"
type="com.vanced.manager.ui.fragments.HomeViewModel" />
</data>
<com.google.android.material.card.MaterialCardView
style="@style/MaterialCard"> style="@style/MaterialCard">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
@ -57,7 +67,7 @@
<TextView <TextView
style="@style/AppVer.Bold" style="@style/AppVer.Bold"
android:id="@+id/microg_latest_version" android:id="@+id/microg_latest_version"
android:text="@string/loading" /> android:text="@{ viewModel.isConnected ? viewModel.microgLatestTxt : @string/unavailable}" />
</LinearLayout> </LinearLayout>
@ -100,4 +110,6 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout>

View File

@ -1,8 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView <layout
xmlns:android="http://schemas.android.com/apk/res/android" 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>
<variable
name="viewModel"
type="com.vanced.manager.ui.fragments.HomeViewModel" />
</data>
<com.google.android.material.card.MaterialCardView
style="@style/MaterialCard" style="@style/MaterialCard"
tools:ignore="ContentDescription, KeyboardInaccessibleWidget"> tools:ignore="ContentDescription, KeyboardInaccessibleWidget">
@ -66,7 +76,7 @@
<TextView <TextView
style="@style/AppVer.Bold" style="@style/AppVer.Bold"
android:id="@+id/vanced_latest_version" android:id="@+id/vanced_latest_version"
android:text="@string/loading" /> android:text="@{ viewModel.isConnected ? viewModel.vancedLatestTxt : @string/unavailable}" />
</LinearLayout> </LinearLayout>
@ -91,6 +101,8 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</layout>