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>?) {
|
private fun setConversation(data: List<ParcelableStatus>?) {
|
||||||
val readPosition = saveReadPosition()
|
val readPosition = saveReadPosition()
|
||||||
val changed = adapter.setData(data)
|
val changed = adapter.setData(data)
|
||||||
|
@ -637,7 +642,8 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
||||||
val (accountLanguage, languages) = settings
|
val (accountLanguage, languages) = settings
|
||||||
val fragment = weakThis.get() ?: return@successUi
|
val fragment = weakThis.get() ?: return@successUi
|
||||||
val df = TranslationDestinationDialogFragment.create(languages, accountLanguage)
|
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 {
|
}.alwaysUi {
|
||||||
val fragment = weakThis.get() ?: return@alwaysUi
|
val fragment = weakThis.get() ?: return@alwaysUi
|
||||||
fragment.dismissProgressDialog("get_language_settings")
|
fragment.dismissProgressDialog("get_language_settings")
|
||||||
|
|
|
@ -36,19 +36,25 @@ import org.mariotaku.twidere.extension.onShow
|
||||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
class TranslationDestinationDialogFragment : BaseDialogFragment() {
|
class TranslationDestinationDialogFragment : BaseDialogFragment() {
|
||||||
|
|
||||||
|
private val currentIndex = AtomicInteger(-1)
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
val languages = arguments.getTypedArray<DisplayLanguage>(EXTRA_LANGUAGES).sortedArrayWith(LanguageComparator())
|
val languages = arguments.getTypedArray<DisplayLanguage>(EXTRA_LANGUAGES).sortedArrayWith(LanguageComparator())
|
||||||
val selectedLanguage = preferences[translationDestinationKey] ?: arguments.getString(EXTRA_SELECTED_LANGUAGE)
|
val selectedLanguage = preferences[translationDestinationKey] ?: arguments.getString(EXTRA_SELECTED_LANGUAGE)
|
||||||
val selectedIndex = languages.indexOfFirst { selectedLanguage == it.code }
|
val selectedIndex = languages.indexOfFirst { selectedLanguage == it.code }
|
||||||
builder.setSingleChoiceItems(languages.mapToArray { it.name }, selectedIndex) { _, which ->
|
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)
|
builder.setNegativeButton(android.R.string.cancel, null)
|
||||||
val dialog = builder.create()
|
val dialog = builder.create()
|
||||||
|
|
|
@ -32,11 +32,13 @@ import java.io.IOException
|
||||||
|
|
||||||
class JsonCache(cacheDir: File) {
|
class JsonCache(cacheDir: File) {
|
||||||
|
|
||||||
private val cache: DiskLruCache? = try {
|
private val cache: DiskLruCache? by lazy {
|
||||||
DiskLruCache.open(cacheDir, BuildConfig.VERSION_CODE, 1, 100 * 1048576)
|
try {
|
||||||
} catch (e: IOException) {
|
return@lazy DiskLruCache.open(cacheDir, BuildConfig.VERSION_CODE, 1, 100 * 1048576)
|
||||||
DebugLog.w(tr = e)
|
} catch (e: IOException) {
|
||||||
null
|
DebugLog.w(tr = e)
|
||||||
|
return@lazy null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> getList(key: String, cls: Class<T>): List<T>? {
|
fun <T> getList(key: String, cls: Class<T>): List<T>? {
|
||||||
|
|
Loading…
Reference in New Issue