mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-20 10:23:30 -04:00
Fixed: The message was showing in previously chosen language when saving the file, and showing the downloading estimate time.
This commit is contained in:
parent
4c0a5e7402
commit
4379ac2e4d
@ -18,7 +18,8 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.core.downloader.model
|
||||
|
||||
import org.kiwix.kiwixmobile.core.CoreApp
|
||||
import androidx.core.content.ContextCompat
|
||||
import org.kiwix.kiwixmobile.core.CoreApp.Companion.instance
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import java.util.Locale
|
||||
import kotlin.math.roundToLong
|
||||
@ -30,7 +31,11 @@ value class Seconds(val seconds: Long) {
|
||||
val hours = 60 * minutes
|
||||
val days = 24 * hours
|
||||
|
||||
val context = CoreApp.instance
|
||||
// Whenever the language changes, it returns the context
|
||||
// for the selected language. Since per-app language settings do not update the context
|
||||
// outside of AppCompatActivity, we need to retrieve the correct context manually.
|
||||
// See: https://issuetracker.google.com/issues/243457462?hl=pl
|
||||
val context = ContextCompat.getContextForLanguage(instance)
|
||||
return when {
|
||||
(seconds / days).roundToLong() > 0 -> String.format(
|
||||
Locale.getDefault(), "%d %s %s", (seconds / days).roundToLong(),
|
||||
|
@ -27,6 +27,7 @@ import android.util.AttributeSet
|
||||
import android.view.ContextMenu
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import androidx.core.content.ContextCompat
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -175,12 +176,15 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor(
|
||||
CoroutineScope(Dispatchers.Main.immediate).launch {
|
||||
val savedFile =
|
||||
FileUtils.downloadFileFromUrl(url, src, zimReaderContainer, sharedPreferenceUtil)
|
||||
val applicationContextForLanguage = ContextCompat.getContextForLanguage(instance)
|
||||
savedFile?.let {
|
||||
instance.toast(instance.getString(R.string.save_media_saved, it.name)).also {
|
||||
applicationContextForLanguage.toast(
|
||||
applicationContextForLanguage.getString(R.string.save_media_saved, it.name)
|
||||
).also {
|
||||
Log.e("savedFile", "handleMessage: ${savedFile.isFile} ${savedFile.path}")
|
||||
}
|
||||
} ?: run {
|
||||
instance.toast(R.string.save_media_error)
|
||||
applicationContextForLanguage.toast(R.string.save_media_error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user