mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-08 07:48:45 +01:00
fixed possible NPEs
This commit is contained in:
parent
2c05797197
commit
9b828b16ff
@ -22,6 +22,8 @@ abstract class AbsFriendshipOperationTask(
|
||||
) : ExceptionHandlingAbstractTask<AbsFriendshipOperationTask.Arguments, ParcelableUser,
|
||||
MicroBlogException, Any?>(context) {
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun beforeExecute() {
|
||||
microBlogWrapper.addUpdatingRelationshipId(params.accountKey, params.userKey)
|
||||
val event = FriendshipTaskEvent(action, params.accountKey,
|
||||
@ -59,13 +61,13 @@ abstract class AbsFriendshipOperationTask(
|
||||
|
||||
@Throws(MicroBlogException::class)
|
||||
protected abstract fun perform(twitter: MicroBlog,
|
||||
details: AccountDetails,
|
||||
args: Arguments): User
|
||||
details: AccountDetails,
|
||||
args: Arguments): User
|
||||
|
||||
protected abstract fun succeededWorker(twitter: MicroBlog,
|
||||
details: AccountDetails,
|
||||
args: Arguments,
|
||||
user: ParcelableUser)
|
||||
details: AccountDetails,
|
||||
args: Arguments,
|
||||
user: ParcelableUser)
|
||||
|
||||
protected abstract fun showSucceededMessage(params: Arguments, user: ParcelableUser)
|
||||
|
||||
|
@ -26,18 +26,24 @@ import org.mariotaku.twidere.model.SingleResponse
|
||||
* Created by mariotaku on 2017/2/10.
|
||||
*/
|
||||
|
||||
abstract class ExceptionHandlingAbstractTask<Params, Result, in TaskException : Exception, Callback>(
|
||||
abstract class ExceptionHandlingAbstractTask<Params, Result, TaskException : Exception, Callback>(
|
||||
context: Context
|
||||
) : BaseAbstractTask<Params, SingleResponse<Result>, Callback>(context) {
|
||||
|
||||
protected abstract val exceptionClass: Class<TaskException>
|
||||
|
||||
override final fun afterExecute(callback: Callback?, result: SingleResponse<Result>) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
afterExecute(callback, result.data, result.exception as? TaskException)
|
||||
if (result.data != null) {
|
||||
onSucceed(callback, result.data)
|
||||
} else if (result.exception != null) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
onException(callback, result.exception as TaskException)
|
||||
if (exceptionClass.isInstance(result.exception)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
onException(callback, result.exception as TaskException)
|
||||
} else {
|
||||
throw result.exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,8 @@ class AddParticipantsTask(
|
||||
|
||||
private val profileImageSize: String = context.getString(R.string.profile_image_size)
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: Unit?): Boolean {
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
throw MicroBlogException("No account")
|
||||
|
@ -45,6 +45,8 @@ class DestroyConversationTask(
|
||||
val conversationId: String
|
||||
) : ExceptionHandlingAbstractTask<Unit?, Boolean, MicroBlogException, ((Boolean) -> Unit)?>(context) {
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: Unit?): Boolean {
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
throw MicroBlogException("No account")
|
||||
|
@ -43,6 +43,9 @@ class DestroyMessageTask(
|
||||
val conversationId: String?,
|
||||
val messageId: String
|
||||
) : ExceptionHandlingAbstractTask<Unit?, Boolean, MicroBlogException, Unit?>(context) {
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: Unit?): Boolean {
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
throw MicroBlogException("No account")
|
||||
|
@ -53,6 +53,9 @@ class MarkMessageReadTask(
|
||||
val accountKey: UserKey,
|
||||
val conversationId: String
|
||||
) : ExceptionHandlingAbstractTask<Unit?, Boolean, MicroBlogException, Unit?>(context) {
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: Unit?): Boolean {
|
||||
if (conversationId.startsWith(TEMP_CONVERSATION_ID_PREFIX)) return true
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
|
@ -54,8 +54,10 @@ class SendMessageTask(
|
||||
|
||||
private val profileImageSize = context.getString(R.string.profile_image_size)
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: ParcelableNewMessage): SendMessageResult {
|
||||
val account = params.account
|
||||
val account = params.account ?: throw MicroBlogException("No account")
|
||||
val microBlog = account.newMicroBlogInstance(context, cls = MicroBlog::class.java)
|
||||
val updateData = requestSendMessage(microBlog, account, params)
|
||||
if (params.is_temp_conversation && params.conversation_id != null) {
|
||||
|
@ -43,6 +43,9 @@ class SetConversationNotificationDisabledTask(
|
||||
val conversationId: String,
|
||||
val notificationDisabled: Boolean
|
||||
) : ExceptionHandlingAbstractTask<Unit?, Boolean, MicroBlogException, ((Boolean) -> Unit)?>(context) {
|
||||
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: Unit?): Boolean {
|
||||
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||
throw MicroBlogException("No account")
|
||||
|
@ -328,6 +328,8 @@ class AsyncTwitterWrapper(
|
||||
|
||||
fun updateFriendship(accountKey: UserKey, userKey: UserKey, update: FriendshipUpdate) {
|
||||
TaskStarter.execute(object : ExceptionHandlingAbstractTask<Any?, Relationship, Exception, Any>(context) {
|
||||
override val exceptionClass = Exception::class.java
|
||||
|
||||
override fun onExecute(params: Any?): Relationship {
|
||||
val microBlog = MicroBlogAPIFactory.getInstance(context, accountKey)
|
||||
?: throw MicroBlogException("No account")
|
||||
@ -371,6 +373,8 @@ class AsyncTwitterWrapper(
|
||||
|
||||
fun setActivitiesAboutMeUnreadAsync(accountKeys: Array<UserKey>, cursor: Long) {
|
||||
val task = object : ExceptionHandlingAbstractTask<Any?, Unit, MicroBlogException, Any?>(context) {
|
||||
override val exceptionClass = MicroBlogException::class.java
|
||||
|
||||
override fun onExecute(params: Any?) {
|
||||
for (accountId in accountKeys) {
|
||||
val microBlog = MicroBlogAPIFactory.getInstance(context, accountId) ?: continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user