mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-16 11:41:21 +01:00
fix translate crash
This commit is contained in:
parent
f3894f15ec
commit
f054752c65
@ -73,6 +73,7 @@ import org.mariotaku.twidere.constant.KeyboardShortcutConstants.*
|
|||||||
import org.mariotaku.twidere.constant.displaySensitiveContentsKey
|
import org.mariotaku.twidere.constant.displaySensitiveContentsKey
|
||||||
import org.mariotaku.twidere.constant.newDocumentApiKey
|
import org.mariotaku.twidere.constant.newDocumentApiKey
|
||||||
import org.mariotaku.twidere.constant.yandexKeyKey
|
import org.mariotaku.twidere.constant.yandexKeyKey
|
||||||
|
import org.mariotaku.twidere.exception.AccountNotFoundException
|
||||||
import org.mariotaku.twidere.extension.*
|
import org.mariotaku.twidere.extension.*
|
||||||
import org.mariotaku.twidere.extension.model.*
|
import org.mariotaku.twidere.extension.model.*
|
||||||
import org.mariotaku.twidere.extension.model.api.key
|
import org.mariotaku.twidere.extension.model.api.key
|
||||||
@ -94,7 +95,7 @@ import org.mariotaku.twidere.model.pagination.SinceMaxPagination
|
|||||||
import org.mariotaku.twidere.model.util.AccountUtils
|
import org.mariotaku.twidere.model.util.AccountUtils
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses
|
import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
|
||||||
import org.mariotaku.twidere.task.AbsAccountRequestTask
|
import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask
|
||||||
import org.mariotaku.twidere.util.*
|
import org.mariotaku.twidere.util.*
|
||||||
import org.mariotaku.twidere.util.ContentScrollHandler.ContentListSupport
|
import org.mariotaku.twidere.util.ContentScrollHandler.ContentListSupport
|
||||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback
|
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback
|
||||||
@ -107,6 +108,7 @@ import org.mariotaku.twidere.view.holder.StatusViewHolder
|
|||||||
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder
|
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder
|
||||||
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder.StatusClickListener
|
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder.StatusClickListener
|
||||||
import org.mariotaku.yandex.YandexAPIFactory
|
import org.mariotaku.yandex.YandexAPIFactory
|
||||||
|
import org.mariotaku.yandex.YandexException
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@ -687,11 +689,14 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class LoadTranslationTask(fragment: StatusFragment, val status: ParcelableStatus) :
|
internal class LoadTranslationTask(fragment: StatusFragment, val status: ParcelableStatus) :
|
||||||
AbsAccountRequestTask<Any?, TranslationResult, Any?>(fragment.requireContext(), status.account_key) {
|
ExceptionHandlingAbstractTask<Any?, TranslationResult, YandexException, Any?>(fragment.requireContext()) {
|
||||||
|
|
||||||
private val weakFragment = WeakReference(fragment)
|
private val weakFragment = WeakReference(fragment)
|
||||||
|
|
||||||
override fun onExecute(account: AccountDetails, params: Any?): TranslationResult {
|
override fun onExecute(params: Any?): TranslationResult {
|
||||||
|
val am = AccountManager.get(context)
|
||||||
|
val account = status.account_key?.let { AccountUtils.getAccountDetails(am, it, true) } ?:
|
||||||
|
throw AccountNotFoundException()
|
||||||
val prefDest = preferences.getString(KEY_TRANSLATION_DESTINATION, null).orEmpty()
|
val prefDest = preferences.getString(KEY_TRANSLATION_DESTINATION, null).orEmpty()
|
||||||
val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java)
|
val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java)
|
||||||
val dest: String
|
val dest: String
|
||||||
@ -725,9 +730,11 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||||||
fragment.displayTranslation(result)
|
fragment.displayTranslation(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onException(callback: Any?, exception: MicroBlogException) {
|
override fun onException(callback: Any?, exception: YandexException) {
|
||||||
Toast.makeText(context, exception.getErrorMessage(context), Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, exception.getErrorMessage(context), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final override val exceptionClass = YandexException::class.java
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import org.mariotaku.yandex.model.YandexTranslateResult
|
|||||||
|
|
||||||
interface YandexAPI {
|
interface YandexAPI {
|
||||||
@POST("/api/v1.5/tr.json/translate")
|
@POST("/api/v1.5/tr.json/translate")
|
||||||
|
@Throws(YandexException::class)
|
||||||
fun search(@Query("text") text: String,
|
fun search(@Query("text") text: String,
|
||||||
@Query("lang") lang: String): YandexTranslateResult
|
@Query("lang") lang: String): YandexTranslateResult
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user