enhanced split apk downloading
This commit is contained in:
parent
fde076023f
commit
8125e01638
|
@ -10,7 +10,9 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.findNavController
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.rxkotlin.subscribeBy
|
||||
import zlc.season.rxdownload4.delete
|
||||
import zlc.season.rxdownload4.download
|
||||
import zlc.season.rxdownload4.file
|
||||
import zlc.season.rxdownload4.task.Task
|
||||
|
@ -18,6 +20,8 @@ import zlc.season.rxdownload4.utils.getFileNameFromUrl
|
|||
|
||||
open class BaseFragment : Fragment() {
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
fun openUrl(Url: String, color: Int) {
|
||||
val builder = CustomTabsIntent.Builder()
|
||||
builder.setToolbarColor(ContextCompat.getColor(requireContext(), color))
|
||||
|
@ -44,9 +48,12 @@ open class BaseFragment : Fragment() {
|
|||
else -> return
|
||||
}
|
||||
|
||||
activity?.filesDir?.path?.let {
|
||||
Task(url = url, saveName = getFileNameFromUrl(url), savePath = it)
|
||||
.download()
|
||||
val task = activity?.filesDir?.path?.let { Task(url = url, saveName = getFileNameFromUrl(url), savePath = it) }
|
||||
|
||||
if (task?.file()?.exists()!!)
|
||||
task.delete()
|
||||
|
||||
disposable = task.download()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeBy(
|
||||
onNext = { progress ->
|
||||
|
@ -54,24 +61,26 @@ open class BaseFragment : Fragment() {
|
|||
loadBar.progress = progress.percent().toInt()
|
||||
},
|
||||
onComplete = {
|
||||
view?.findNavController()?.navigate(navigate)
|
||||
//if (isInstalling) {
|
||||
//So we should implement installation here.
|
||||
//That will be done later
|
||||
//}
|
||||
view?.findNavController()?.navigate(navigate)
|
||||
},
|
||||
onError = { throwable ->
|
||||
Toast.makeText(requireContext(), throwable.toString(), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
fun downloadEn() {
|
||||
val url = "https://x1nto.github.io/VancedFiles/Splits/Language/split_config.en.apk"
|
||||
activity?.filesDir?.path?.let {
|
||||
Task(url = url, saveName = getFileNameFromUrl(url), savePath = it)
|
||||
|
||||
val task = activity?.filesDir?.path?.let { Task(url = url, saveName = getFileNameFromUrl(url), savePath = it) }
|
||||
if (task?.file()?.exists()!!)
|
||||
task.delete()
|
||||
|
||||
disposable = task
|
||||
.download()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeBy(
|
||||
|
|
|
@ -21,7 +21,7 @@ open class ThemedActivity : AppCompatActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
pref = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
currentTheme = pref.getString("theme_mode", "").toString()
|
||||
currentTheme = pref.getString("theme_mode", "Light").toString()
|
||||
|
||||
setFinalTheme(currentTheme)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -33,7 +33,7 @@ open class ThemedActivity : AppCompatActivity() {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val theme = pref.getString("theme_mode", "LIGHT")
|
||||
val theme = pref.getString("theme_mode", "Light")
|
||||
|
||||
//if for some weird reasons we get invalid
|
||||
//theme, recreate activity
|
||||
|
@ -57,20 +57,15 @@ open class ThemedActivity : AppCompatActivity() {
|
|||
private fun setFinalTheme(currentTheme: String) {
|
||||
val currentAccent = pref.getString("accent_color", "Blue").toString()
|
||||
when (currentTheme) {
|
||||
"LIGHT" -> setLightAccent(currentAccent)
|
||||
"DARK" -> setDarkAccent(currentAccent)
|
||||
"FOLLOW" -> {
|
||||
"Light" -> setLightAccent(currentAccent)
|
||||
"Dark" -> setDarkAccent(currentAccent)
|
||||
"Follow" -> {
|
||||
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> setDarkAccent(currentAccent)
|
||||
Configuration.UI_MODE_NIGHT_NO -> setLightAccent(currentAccent)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> setDarkAccent("Blue")
|
||||
Configuration.UI_MODE_NIGHT_NO -> setLightAccent("Blue")
|
||||
}
|
||||
}
|
||||
else -> setLightAccent("Blue")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
</string-array>
|
||||
|
||||
<string-array name="theme_modes_values">
|
||||
<item>LIGHT</item>
|
||||
<item>DARK</item>
|
||||
<item>FOLLOW</item>
|
||||
<item>Light</item>
|
||||
<item>Dark</item>
|
||||
<item>Follow</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="accent_color">
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
android:summary="@string/theme_summary"
|
||||
android:entries="@array/theme_modes"
|
||||
android:entryValues="@array/theme_modes_values"
|
||||
android:defaultValue="FOLLOW"/>
|
||||
android:defaultValue="LIGHT"/>
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="Blue"
|
||||
|
|
Loading…
Reference in New Issue