added reload translation after changed language
This commit is contained in:
parent
45a65d099f
commit
5ad7c697e3
|
@ -506,6 +506,11 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||
}
|
||||
}
|
||||
|
||||
internal fun reloadTranslation() {
|
||||
loadTranslationTask = null
|
||||
loadTranslation(adapter.status)
|
||||
}
|
||||
|
||||
private fun setConversation(data: List<ParcelableStatus>?) {
|
||||
val readPosition = saveReadPosition()
|
||||
val changed = adapter.setData(data)
|
||||
|
@ -637,7 +642,8 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||
val (accountLanguage, languages) = settings
|
||||
val fragment = weakThis.get() ?: return@successUi
|
||||
val df = TranslationDestinationDialogFragment.create(languages, accountLanguage)
|
||||
df.show(fragment.childFragmentManager, "translation_destination_settings")
|
||||
df.setTargetFragment(fragment, 0)
|
||||
df.show(fragment.fragmentManager, "translation_destination_settings")
|
||||
}.alwaysUi {
|
||||
val fragment = weakThis.get() ?: return@alwaysUi
|
||||
fragment.dismissProgressDialog("get_language_settings")
|
||||
|
|
|
@ -36,19 +36,25 @@ import org.mariotaku.twidere.extension.onShow
|
|||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import java.text.Collator
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class TranslationDestinationDialogFragment : BaseDialogFragment() {
|
||||
|
||||
private val currentIndex = AtomicInteger(-1)
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
val languages = arguments.getTypedArray<DisplayLanguage>(EXTRA_LANGUAGES).sortedArrayWith(LanguageComparator())
|
||||
val selectedLanguage = preferences[translationDestinationKey] ?: arguments.getString(EXTRA_SELECTED_LANGUAGE)
|
||||
val selectedIndex = languages.indexOfFirst { selectedLanguage == it.code }
|
||||
builder.setSingleChoiceItems(languages.mapToArray { it.name }, selectedIndex) { _, which ->
|
||||
preferences[translationDestinationKey] = languages[which].code
|
||||
currentIndex.set(which)
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok) lambda@ { di, _ ->
|
||||
val idx = currentIndex.get()
|
||||
if (idx < 0) return@lambda
|
||||
preferences[translationDestinationKey] = languages[idx].code
|
||||
(targetFragment as? StatusFragment)?.reloadTranslation()
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel, null)
|
||||
val dialog = builder.create()
|
||||
|
|
|
@ -32,11 +32,13 @@ import java.io.IOException
|
|||
|
||||
class JsonCache(cacheDir: File) {
|
||||
|
||||
private val cache: DiskLruCache? = try {
|
||||
DiskLruCache.open(cacheDir, BuildConfig.VERSION_CODE, 1, 100 * 1048576)
|
||||
} catch (e: IOException) {
|
||||
DebugLog.w(tr = e)
|
||||
null
|
||||
private val cache: DiskLruCache? by lazy {
|
||||
try {
|
||||
return@lazy DiskLruCache.open(cacheDir, BuildConfig.VERSION_CODE, 1, 100 * 1048576)
|
||||
} catch (e: IOException) {
|
||||
DebugLog.w(tr = e)
|
||||
return@lazy null
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> getList(key: String, cls: Class<T>): List<T>? {
|
||||
|
|
Loading…
Reference in New Issue