updated data fetch methods
This commit is contained in:
parent
4d1e334dd2
commit
7b2d7a997b
|
@ -56,7 +56,20 @@
|
|||
android:configChanges="layoutDirection|locale"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/DarkTheme.Blue" />
|
||||
android:theme="@style/DarkTheme.Blue">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data
|
||||
android:scheme="https"
|
||||
android:host="vancedapp.com"
|
||||
android:pathPrefix="/downloads"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<meta-data
|
||||
android:name="preloaded_fonts"
|
||||
|
|
|
@ -10,7 +10,11 @@ import com.vanced.manager.databinding.ViewSponsorBinding
|
|||
import com.vanced.manager.model.SponsorModel
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
class SponsorAdapter(context: Context, private val viewModel: HomeViewModel) : RecyclerView.Adapter<SponsorAdapter.LinkViewHolder>() {
|
||||
class SponsorAdapter(
|
||||
context: Context,
|
||||
private val viewModel: HomeViewModel,
|
||||
//private val json: ObservableField<JsonObject?>
|
||||
) : RecyclerView.Adapter<SponsorAdapter.LinkViewHolder>() {
|
||||
|
||||
private val brave = SponsorModel(
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_brave),
|
||||
|
@ -24,11 +28,11 @@ class SponsorAdapter(context: Context, private val viewModel: HomeViewModel) : R
|
|||
"https://vancedapp.com/adguard"
|
||||
)
|
||||
|
||||
val sponsors = arrayOf(brave, adguard)
|
||||
val sponsors = arrayListOf(brave, adguard)
|
||||
|
||||
inner class LinkViewHolder(private val binding: ViewSponsorBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
//val cardBg = binding.linkBg
|
||||
//val descText = binding.linkAppDescription
|
||||
inner class LinkViewHolder(private val binding: ViewSponsorBinding) : RecyclerView.ViewHolder(
|
||||
binding.root
|
||||
) {
|
||||
fun bind(position: Int) {
|
||||
binding.viewModel = viewModel
|
||||
binding.sponsor = sponsors[position]
|
||||
|
@ -42,16 +46,29 @@ class SponsorAdapter(context: Context, private val viewModel: HomeViewModel) : R
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: LinkViewHolder, position: Int) {
|
||||
//holder.cardBg.setCardBackgroundColor()
|
||||
holder.bind(position)
|
||||
// val lp = holder.cardBg
|
||||
// if (lp is FlexboxLayoutManager.LayoutParams) {
|
||||
// val flexboxLp = lp as FlexboxLayoutManager.LayoutParams
|
||||
// flexboxLp.flexGrow = 1.0f
|
||||
// flexboxLp.alignSelf = AlignItems.STRETCH
|
||||
// }
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = 2
|
||||
|
||||
// fun getCountryFromIP(ipAddress: String?): String? {
|
||||
// val db = context.assets.open("GeoLite2-Country.mmdb")
|
||||
// val reader = DatabaseReader.Builder(db).build()
|
||||
// val inetIp = InetAddress.getByName(ipAddress)
|
||||
// return reader.country(inetIp).country.isoCode
|
||||
// }
|
||||
//
|
||||
// init {
|
||||
// json.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
|
||||
// override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
|
||||
// val wm = context.applicationContext.getSystemService(WIFI_SERVICE) as WifiManager?
|
||||
// val ip: String = formatIpAddress(wm!!.connectionInfo.ipAddress)
|
||||
// val promotedTiers = json.get()?.array<String>("tier2")?.value!! + json.get()?.array<String>("tier3")?.value!!
|
||||
// if (promotedTiers.any { getCountryFromIP(ip)?.contains(it)!! })
|
||||
// sponsors.removeAt(1)
|
||||
// }
|
||||
//
|
||||
// })
|
||||
// }
|
||||
|
||||
}
|
|
@ -14,7 +14,6 @@ import com.vanced.manager.utils.JsonHelper.getJson
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
open class App: Application() {
|
||||
|
||||
|
@ -23,22 +22,29 @@ open class App: Application() {
|
|||
var microg = ObservableField<JsonObject?>()
|
||||
var manager = ObservableField<JsonObject?>()
|
||||
|
||||
//var braveTiers = ObservableField<JsonObject?>()
|
||||
|
||||
override fun onCreate() {
|
||||
loadJsonAsync()
|
||||
loadJson()
|
||||
super.onCreate()
|
||||
PRDownloader.initialize(this)
|
||||
|
||||
Crowdin.init(this,
|
||||
CrowdinConfig.Builder()
|
||||
.withDistributionHash("36c51aed3180a4f43073d28j4s6")
|
||||
.withDistributionHash("3b84be9663023b0b1a22988j4s6")
|
||||
.withNetworkType(NetworkType.WIFI)
|
||||
.build()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
open fun loadJsonAsync() = CoroutineScope(Dispatchers.IO).launch {
|
||||
val latest = getJson("${getDefaultSharedPreferences(this@App).getString("install_url", baseUrl)}/latest.json")
|
||||
open fun loadJson() = CoroutineScope(Dispatchers.IO).launch {
|
||||
val installUrl = getDefaultSharedPreferences(this@App).getString("install_url", baseUrl)
|
||||
val latest = getJson("$installUrl/latest.json")
|
||||
// braveTiers.apply {
|
||||
// set(getJson("$installUrl/sponsor.json"))
|
||||
// notifyChange()
|
||||
// }
|
||||
|
||||
vanced.apply {
|
||||
set(latest?.obj("vanced"))
|
||||
|
|
|
@ -21,8 +21,10 @@ import com.vanced.manager.R
|
|||
import com.vanced.manager.databinding.ActivityMainBinding
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer
|
||||
import com.vanced.manager.ui.dialogs.ManagerUpdateDialog
|
||||
import com.vanced.manager.ui.dialogs.URLChangeDialog
|
||||
import com.vanced.manager.ui.fragments.HomeFragmentDirections
|
||||
import com.vanced.manager.ui.fragments.SettingsFragmentDirections
|
||||
import com.vanced.manager.utils.Extensions.show
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.LanguageContextWrapper
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
|
@ -40,7 +42,7 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
override fun onFailure(throwable: Throwable) {
|
||||
Log.d(tag, "Failed to load data")
|
||||
Log.d(tag, "Failed to load data: $throwable")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,11 +132,21 @@ class MainActivity : AppCompatActivity() {
|
|||
val variant = prefs.getString("vanced_variant", "nonroot")
|
||||
prefs.getBoolean("show_root_dialog", true)
|
||||
|
||||
if (intent?.data != null) {
|
||||
val urldialog = URLChangeDialog()
|
||||
val arg = Bundle()
|
||||
arg.putString("url", intent.dataString)
|
||||
urldialog.arguments = arg
|
||||
intent.dataString?.let { Log.d("urlTest", it) }
|
||||
urldialog.show(this)
|
||||
}
|
||||
|
||||
when {
|
||||
firstLaunch -> {
|
||||
DialogContainer.showSecurityDialog(this)
|
||||
with(FirebaseMessaging.getInstance()) {
|
||||
subscribeToTopic("Vanced-Update")
|
||||
subscribeToTopic("Music-Update")
|
||||
subscribeToTopic("MicroG-Update")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import com.vanced.manager.R
|
|||
import com.vanced.manager.databinding.DialogManagerLanguageBinding
|
||||
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
||||
import com.vanced.manager.utils.LanguageHelper.getLanguageFormat
|
||||
import java.util.*
|
||||
|
||||
class ManagerLanguageDialog : BottomSheetDialogFragment() {
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.fragment.app.DialogFragment
|
|||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.Extensions.fetchData
|
||||
import com.vanced.manager.utils.InternetTools.baseUrl
|
||||
|
||||
class URLChangeDialog : DialogFragment() {
|
||||
|
@ -29,7 +30,8 @@ class URLChangeDialog : DialogFragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val urlField = view.findViewById<EditText>(R.id.url_input)
|
||||
urlField.setText(getDefaultSharedPreferences(requireActivity()).getString("install_url", baseUrl), TextView.BufferType.EDITABLE)
|
||||
val fieldTxt = if (arguments != null) arguments?.getString("url") else getDefaultSharedPreferences(requireActivity()).getString("install_url", baseUrl)
|
||||
urlField.setText(fieldTxt, TextView.BufferType.EDITABLE)
|
||||
view.findViewById<MaterialButton>(R.id.url_save).setOnClickListener {
|
||||
val finalUrl =
|
||||
if (urlField.text.startsWith("https://") || urlField.text.startsWith("http://"))
|
||||
|
@ -44,6 +46,7 @@ class URLChangeDialog : DialogFragment() {
|
|||
|
||||
private fun saveUrl(url: String) {
|
||||
getDefaultSharedPreferences(requireActivity()).edit().putString("install_url", url).apply()
|
||||
requireActivity().fetchData()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.view.View
|
|||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import androidx.databinding.ObservableBoolean
|
||||
import androidx.databinding.ObservableField
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.LiveData
|
||||
|
@ -30,6 +29,8 @@ import com.vanced.manager.utils.AppUtils.musicPkg
|
|||
import com.vanced.manager.utils.AppUtils.musicRootPkg
|
||||
import com.vanced.manager.utils.AppUtils.vancedPkg
|
||||
import com.vanced.manager.utils.AppUtils.vancedRootPkg
|
||||
import com.vanced.manager.utils.Extensions.fetchData
|
||||
import com.vanced.manager.utils.Extensions.setRefreshing
|
||||
import com.vanced.manager.utils.Extensions.show
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
import com.vanced.manager.utils.PackageHelper.apkExist
|
||||
|
@ -50,17 +51,16 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
val music = ObservableField<DataModel>()
|
||||
val musicRoot = ObservableField<DataModel>()
|
||||
val manager = ObservableField<DataModel>()
|
||||
val fetching = ObservableBoolean(true)
|
||||
|
||||
private var _navigateDestination = MutableLiveData<Event<Int>>()
|
||||
|
||||
val navigateDestination : LiveData<Event<Int>> = _navigateDestination
|
||||
|
||||
fun fetchData() {
|
||||
fetching.set(true)
|
||||
app.loadJsonAsync()
|
||||
activity.setRefreshing(true)
|
||||
app.loadJson()
|
||||
Crowdin.forceUpdate(activity)
|
||||
fetching.set(false)
|
||||
activity.setRefreshing(false)
|
||||
}
|
||||
|
||||
private val microgToast = Toast.makeText(activity, R.string.no_microg, Toast.LENGTH_LONG)
|
||||
|
@ -131,17 +131,17 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
|
||||
}
|
||||
|
||||
fun uninstallPackage(pkg: String): Any = if (prefs.getString("vanced_variant", "nonroot") == "root") uninstallRootApk(pkg) else uninstallApk(pkg, activity)
|
||||
fun uninstallPackage(pkg: String) = if (prefs.getString("vanced_variant", "nonroot") == "root" && uninstallRootApk(pkg)) activity.fetchData() else uninstallApk(pkg, activity)
|
||||
|
||||
init {
|
||||
fetching.set(true)
|
||||
activity.setRefreshing(true)
|
||||
vanced.set(DataModel(app.vanced, activity, vancedPkg, activity.getString(R.string.vanced), ContextCompat.getDrawable(activity, R.drawable.ic_vanced)))
|
||||
vancedRoot.set(DataModel(app.vanced, activity, vancedRootPkg, activity.getString(R.string.vanced), ContextCompat.getDrawable(activity, R.drawable.ic_vanced)))
|
||||
music.set(DataModel(app.music, activity, musicPkg, activity.getString(R.string.music), ContextCompat.getDrawable(activity, R.drawable.ic_music)))
|
||||
musicRoot.set(DataModel(app.music, activity, musicRootPkg, activity.getString(R.string.music), ContextCompat.getDrawable(activity, R.drawable.ic_music)))
|
||||
microg.set(DataModel(app.microg, activity, microgPkg, activity.getString(R.string.microg), ContextCompat.getDrawable(activity, R.drawable.ic_microg)))
|
||||
manager.set(DataModel(app.manager, activity, managerPkg, activity.getString(R.string.app_name), ContextCompat.getDrawable(activity, R.mipmap.ic_launcher)))
|
||||
fetching.set(false)
|
||||
activity.setRefreshing(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.widget.RadioGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.App
|
||||
|
||||
object Extensions {
|
||||
|
||||
|
@ -15,4 +19,24 @@ object Extensions {
|
|||
this.show(activity.supportFragmentManager, "")
|
||||
}
|
||||
|
||||
fun Activity.fetchData() {
|
||||
val refreshLayout = findViewById<SwipeRefreshLayout>(R.id.home_refresh)
|
||||
setRefreshing(true, refreshLayout)
|
||||
(application as App).loadJson()
|
||||
setRefreshing(false, refreshLayout)
|
||||
}
|
||||
|
||||
fun Activity.setRefreshing(isRefreshing: Boolean) {
|
||||
val refreshLayout = findViewById<SwipeRefreshLayout>(R.id.home_refresh)
|
||||
if (refreshLayout != null) {
|
||||
refreshLayout.isRefreshing = isRefreshing
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.setRefreshing(isRefreshing: Boolean, refreshLayout: SwipeRefreshLayout?) {
|
||||
if (refreshLayout != null) {
|
||||
refreshLayout.isRefreshing = isRefreshing
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import android.content.Context
|
|||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.App
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.*
|
|||
import java.util.regex.Pattern
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
object PackageHelper {
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
android:id="@+id/home_refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
bind:onRefreshListener="@{()-> viewModel.fetchData()}"
|
||||
bind:refreshing="@{viewModel.fetching}">
|
||||
bind:onRefreshListener="@{()-> viewModel.fetchData()}">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue