This commit is contained in:
Mariotaku Lee 2017-02-28 09:41:09 +08:00
parent 67b7b83795
commit ea2b634b15
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 22 additions and 17 deletions

View File

@ -53,6 +53,7 @@ import org.mariotaku.abstask.library.TaskStarter
import org.mariotaku.chameleon.Chameleon
import org.mariotaku.chameleon.ChameleonUtils
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.setItemAvailability
import org.mariotaku.ktextension.useCursor
import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException
@ -203,6 +204,14 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
inflater.inflate(R.menu.menu_messages_conversation_info, menu)
}
override fun onPrepareOptionsMenu(menu: Menu) {
if (adapter.conversation?.conversation_extras_type == ExtrasType.TWITTER_OFFICIAL) {
menu.setItemAvailability(R.id.leave_conversation, true)
} else {
menu.setItemAvailability(R.id.leave_conversation, false)
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.leave_conversation -> {
@ -210,9 +219,6 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
df.show(childFragmentManager, "destroy_conversation_confirm")
return true
}
R.id.delete_messages -> {
}
}
return false
}

View File

@ -47,7 +47,7 @@ class DestroyMessageTask(
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
throw MicroBlogException("No account")
val microBlog = account.newMicroBlogInstance(context, cls = MicroBlog::class.java)
if (!performDestroyMessage(microBlog, account)) {
if (!performDestroyMessage(context, microBlog, account, messageId)) {
return false
}
val deleteWhere: String
@ -66,17 +66,20 @@ class DestroyMessageTask(
return true
}
private fun performDestroyMessage(microBlog: MicroBlog, account: AccountDetails): Boolean {
when (account.type) {
AccountType.TWITTER -> {
if (account.isOfficial(context)) {
return microBlog.destroyDm(messageId).isSuccessful
companion object {
private fun performDestroyMessage(context: Context, microBlog: MicroBlog,
account: AccountDetails, messageId: String): Boolean {
when (account.type) {
AccountType.TWITTER -> {
if (account.isOfficial(context)) {
return microBlog.destroyDm(messageId).isSuccessful
}
}
}
microBlog.destroyDirectMessage(messageId)
return true
}
microBlog.destroyDirectMessage(messageId)
return true
}
}

View File

@ -23,8 +23,4 @@
android:id="@+id/leave_conversation"
android:icon="@drawable/ic_action_delete"
android:title="@string/action_leave_conversation"/>
<item
android:id="@+id/delete_messages"
android:icon="@drawable/ic_action_delete"
android:title="@string/action_delete_messages"/>
</menu>