enhanced split apk downloading

This commit is contained in:
X1nto 2020-05-24 17:15:47 +04:00
parent fde076023f
commit 8125e01638
4 changed files with 42 additions and 38 deletions

View File

@ -10,7 +10,9 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.findNavController import androidx.navigation.findNavController
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import zlc.season.rxdownload4.delete
import zlc.season.rxdownload4.download import zlc.season.rxdownload4.download
import zlc.season.rxdownload4.file import zlc.season.rxdownload4.file
import zlc.season.rxdownload4.task.Task import zlc.season.rxdownload4.task.Task
@ -18,6 +20,8 @@ import zlc.season.rxdownload4.utils.getFileNameFromUrl
open class BaseFragment : Fragment() { open class BaseFragment : Fragment() {
private var disposable: Disposable? = null
fun openUrl(Url: String, color: Int) { fun openUrl(Url: String, color: Int) {
val builder = CustomTabsIntent.Builder() val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(requireContext(), color)) builder.setToolbarColor(ContextCompat.getColor(requireContext(), color))
@ -44,34 +48,39 @@ open class BaseFragment : Fragment() {
else -> return else -> return
} }
activity?.filesDir?.path?.let { val task = activity?.filesDir?.path?.let { Task(url = url, saveName = getFileNameFromUrl(url), savePath = it) }
Task(url = url, saveName = getFileNameFromUrl(url), savePath = it)
.download()
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onNext = { progress ->
loadBar.visibility = View.VISIBLE
loadBar.progress = progress.percent().toInt()
},
onComplete = {
//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()
}
) if (task?.file()?.exists()!!)
task.delete()
disposable = task.download()
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onNext = { progress ->
loadBar.visibility = View.VISIBLE
loadBar.progress = progress.percent().toInt()
},
onComplete = {
view?.findNavController()?.navigate(navigate)
//if (isInstalling) {
//So we should implement installation here.
//That will be done later
//}
},
onError = { throwable ->
Toast.makeText(requireContext(), throwable.toString(), Toast.LENGTH_SHORT).show()
}
)
} }
}
fun downloadEn() { fun downloadEn() {
val url = "https://x1nto.github.io/VancedFiles/Splits/Language/split_config.en.apk" 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() .download()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeBy( .subscribeBy(

View File

@ -21,7 +21,7 @@ open class ThemedActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
pref = PreferenceManager.getDefaultSharedPreferences(this) pref = PreferenceManager.getDefaultSharedPreferences(this)
currentTheme = pref.getString("theme_mode", "").toString() currentTheme = pref.getString("theme_mode", "Light").toString()
setFinalTheme(currentTheme) setFinalTheme(currentTheme)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -33,7 +33,7 @@ open class ThemedActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.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 //if for some weird reasons we get invalid
//theme, recreate activity //theme, recreate activity
@ -57,20 +57,15 @@ open class ThemedActivity : AppCompatActivity() {
private fun setFinalTheme(currentTheme: String) { private fun setFinalTheme(currentTheme: String) {
val currentAccent = pref.getString("accent_color", "Blue").toString() val currentAccent = pref.getString("accent_color", "Blue").toString()
when (currentTheme) { when (currentTheme) {
"LIGHT" -> setLightAccent(currentAccent) "Light" -> setLightAccent(currentAccent)
"DARK" -> setDarkAccent(currentAccent) "Dark" -> setDarkAccent(currentAccent)
"FOLLOW" -> { "Follow" -> {
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) { when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> setDarkAccent(currentAccent) Configuration.UI_MODE_NIGHT_YES -> setDarkAccent(currentAccent)
Configuration.UI_MODE_NIGHT_NO -> setLightAccent(currentAccent) Configuration.UI_MODE_NIGHT_NO -> setLightAccent(currentAccent)
} }
} }
else -> { else -> setLightAccent("Blue")
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> setDarkAccent("Blue")
Configuration.UI_MODE_NIGHT_NO -> setLightAccent("Blue")
}
}
} }
} }

View File

@ -8,9 +8,9 @@
</string-array> </string-array>
<string-array name="theme_modes_values"> <string-array name="theme_modes_values">
<item>LIGHT</item> <item>Light</item>
<item>DARK</item> <item>Dark</item>
<item>FOLLOW</item> <item>Follow</item>
</string-array> </string-array>
<string-array name="accent_color"> <string-array name="accent_color">

View File

@ -33,7 +33,7 @@
android:summary="@string/theme_summary" android:summary="@string/theme_summary"
android:entries="@array/theme_modes" android:entries="@array/theme_modes"
android:entryValues="@array/theme_modes_values" android:entryValues="@array/theme_modes_values"
android:defaultValue="FOLLOW"/> android:defaultValue="LIGHT"/>
<ListPreference <ListPreference
android:defaultValue="Blue" android:defaultValue="Blue"