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

UI improvements

This commit is contained in:
X1nto 2020-05-24 20:08:10 +04:00
parent 5f7d77e88e
commit 2b9ffd938a
3 changed files with 25 additions and 102 deletions

View file

@ -61,6 +61,7 @@ open class BaseFragment : Fragment() {
loadBar.progress = progress.percent().toInt()
},
onComplete = {
loadBar.visibility = View.GONE
view?.findNavController()?.navigate(navigate)
//if (isInstalling) {
//So we should implement installation here.

View file

@ -13,7 +13,6 @@ import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.navigation.findNavController
import com.dezlum.codelabs.getjson.GetJson
import com.google.gson.JsonObject
import com.vanced.manager.R
import com.vanced.manager.core.base.BaseFragment
import io.reactivex.android.schedulers.AndroidSchedulers
@ -52,20 +51,6 @@ open class Home : BaseFragment() {
val microgStatus = pm?.let { isPackageInstalled("com.mgoogle.android.gms", it) }
val vancedStatus = pm?.let { isPackageInstalled("com.vanced.android.youtube", it) }
val vancedLatestTxt = view.findViewById<TextView>(R.id.vanced_latest_version)
val microgLatestTxt = view.findViewById<TextView>(R.id.microg_latest_version)
if (GetJson().isConnected(requireContext())) {
val vancedVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json")
val microgVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
vancedLatestTxt.text = vancedVer.get("version").asString
microgLatestTxt.text = microgVer.get("version").asString
} else {
vancedLatestTxt.text = getString(R.string.unavailable)
microgLatestTxt.text = getString(R.string.unavailable)
}
vancedinstallbtn.setOnClickListener {
view.findNavController().navigate(R.id.toInstallVariantFragment)
}
@ -89,6 +74,9 @@ open class Home : BaseFragment() {
val microgVerText = view.findViewById<TextView>(R.id.microg_installed_version)
if (microgStatus!!) {
microginstallbtn.text = getString(R.string.installed)
microginstallbtn.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.outline_cloud_done_24, 0, 0, 0)
val microgVer = pm.getPackageInfo("com.mgoogle.android.gms", 0).versionName
microguninstallbtn.setOnClickListener {
try {
@ -124,6 +112,8 @@ open class Home : BaseFragment() {
val vancedVerText = view.findViewById<TextView>(R.id.vanced_installed_version)
if (vancedStatus!!) {
vancedinstallbtn.text = getString(R.string.installed)
vancedinstallbtn.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.outline_cloud_done_24, 0, 0, 0)
val vancedVer = pm.getPackageInfo("com.vanced.android.youtube", 0).versionName
vanceduninstallbtn.setOnClickListener {
try {

View file

@ -1,11 +1,6 @@
package com.vanced.manager.ui.fragments
import android.animation.ObjectAnimator
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Bundle
import android.view.*
import android.widget.Button
@ -66,14 +61,26 @@ class HomeFragment : Home() {
}
private fun checkNetwork() {
val networkErrorLayout = view?.findViewById<MaterialCardView>(R.id.home_network_wrapper)
disposable = ReactiveNetwork.observeInternetConnectivity()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { isConnectedToInternet ->
run {
val microginstallbtn = view?.findViewById<Button>(R.id.microg_installbtn)
val vancedinstallbtn = view?.findViewById<Button>(R.id.vanced_installbtn)
val vancedLatestTxt = view?.findViewById<TextView>(R.id.vanced_latest_version)
val microgLatestTxt = view?.findViewById<TextView>(R.id.microg_latest_version)
if (isConnectedToInternet) {
vancedinstallbtn?.visibility = View.VISIBLE
microginstallbtn?.visibility = View.VISIBLE
val vancedVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json")
val microgVer: JsonObject = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
vancedLatestTxt?.text = vancedVer.get("version").asString
microgLatestTxt?.text = microgVer.get("version").asString
val oa2 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0f, 0.3f)
val oa3 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0.3f, -1f)
@ -85,6 +92,12 @@ class HomeFragment : Home() {
start()
}
} else {
vancedinstallbtn?.visibility = View.INVISIBLE
microginstallbtn?.visibility = View.INVISIBLE
vancedLatestTxt?.text = getString(R.string.unavailable)
microgLatestTxt?.text = getString(R.string.unavailable)
val oa2 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", -1f, 0.3f)
val oa3 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0.3f, 0f)
@ -108,86 +121,5 @@ class HomeFragment : Home() {
super .onCreateOptionsMenu(menu, inflater)
}
/*private fun checkNetwork() {
if (!GetJson().isConnected(requireContext())) {
netUnavailable()
}
}
private var networkCallback = object: ConnectivityManager.NetworkCallback() {
override fun onLost(network: Network) {
super.onLost(network)
netUnavailable()
}
override fun onAvailable(network: Network) {
super.onAvailable(network)
activity?.runOnUiThread {
val networkErrorLayout = view?.findViewById<MaterialCardView>(R.id.home_network_wrapper)
val oa2 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0f, 0.3f)
val oa3 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0.3f, -1f)
oa2.start()
oa3.apply {
oa3.addListener(onEnd = {
networkErrorLayout?.visibility = View.GONE
})
start()
}
}
}
}
private fun netUnavailable() {
if (GetJson().isConnected(requireContext())) {
val networkErrorLayout = view?.findViewById<MaterialCardView>(R.id.home_network_wrapper)
if (networkErrorLayout?.visibility != View.VISIBLE) {
activity?.runOnUiThread {
val oa2 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", -1f, 0.3f)
val oa3 = ObjectAnimator.ofFloat(networkErrorLayout, "yFraction", 0.3f, 0f)
oa2.apply {
oa2.addListener(onStart = {
networkErrorLayout?.visibility = View.VISIBLE
})
start()
}
oa3.start()
}
}
}
}
private fun connectionStatus() {
val connectivityManager = context?.applicationContext?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkRequest = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.build()
try {
connectivityManager.unregisterNetworkCallback(networkCallback)
} catch (e: Exception) {}
connectivityManager.registerNetworkCallback(networkRequest, networkCallback)
}
*/
}