Fixed: The message was showing in previously chosen language when saving the file, and showing the downloading estimate time.

This commit is contained in:
MohitMaliFtechiz 2025-02-17 19:19:34 +05:30
parent 4c0a5e7402
commit 4379ac2e4d
2 changed files with 13 additions and 4 deletions

View File

@ -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(),

View File

@ -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)
}
}
}