improved new dm conversation
supports disable_notification
This commit is contained in:
parent
cfd4e471a7
commit
a6cdf3217c
|
@ -49,6 +49,8 @@ public class TwitterOfficialConversationExtras extends ConversationExtras implem
|
||||||
public long maxEntryTimestamp;
|
public long maxEntryTimestamp;
|
||||||
@JsonField(name = "read_only")
|
@JsonField(name = "read_only")
|
||||||
public boolean readOnly;
|
public boolean readOnly;
|
||||||
|
@JsonField(name = "notifications_disabled")
|
||||||
|
public boolean notificationsDisabled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -58,6 +60,7 @@ public class TwitterOfficialConversationExtras extends ConversationExtras implem
|
||||||
", status='" + status + '\'' +
|
", status='" + status + '\'' +
|
||||||
", maxEntryTimestamp=" + maxEntryTimestamp +
|
", maxEntryTimestamp=" + maxEntryTimestamp +
|
||||||
", readOnly=" + readOnly +
|
", readOnly=" + readOnly +
|
||||||
|
", notificationsDisabled=" + notificationsDisabled +
|
||||||
"} " + super.toString();
|
"} " + super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,4 +63,14 @@ val ParcelableMessageConversation.readOnly: Boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val ParcelableMessageConversation.notificationDisabled: Boolean
|
||||||
|
get() {
|
||||||
|
when (conversation_extras_type) {
|
||||||
|
ExtrasType.TWITTER_OFFICIAL -> {
|
||||||
|
return (conversation_extras as? TwitterOfficialConversationExtras)?.notificationsDisabled ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
|
@ -149,10 +149,9 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
|
||||||
val displayName = userColorNameManager.getDisplayName(user, nameFirst)
|
val displayName = userColorNameManager.getDisplayName(user, nameFirst)
|
||||||
val span = ParticipantSpan(user, displayName, roundRadius, spanPadding)
|
val span = ParticipantSpan(user, displayName, roundRadius, spanPadding)
|
||||||
val start = text.length
|
val start = text.length
|
||||||
text.append(user.screen_name)
|
text.append("${user.screen_name} ")
|
||||||
val end = text.length
|
val end = text.length - 1
|
||||||
text.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
text.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||||
text.append(' ')
|
|
||||||
} else {
|
} else {
|
||||||
text.getSpans(0, text.length, ParticipantSpan::class.java).forEach { span ->
|
text.getSpans(0, text.length, ParticipantSpan::class.java).forEach { span ->
|
||||||
if (user != span.user) {
|
if (user != span.user) {
|
||||||
|
|
|
@ -58,9 +58,9 @@ class CacheUserSearchLoader(
|
||||||
c.close()
|
c.close()
|
||||||
val collator = Collator.getInstance()
|
val collator = Collator.getInstance()
|
||||||
list.sortWith(Comparator { l, r ->
|
list.sortWith(Comparator { l, r ->
|
||||||
val compare = collator.compare(l.name, r.name)
|
val compare = collator.compare(r.name, l.name)
|
||||||
if (compare != 0) return@Comparator compare
|
if (compare != 0) return@Comparator compare
|
||||||
return@Comparator l.screen_name.compareTo(r.screen_name)
|
return@Comparator r.screen_name.compareTo(l.screen_name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,9 +19,19 @@
|
||||||
|
|
||||||
package org.mariotaku.twidere.task.twitter.message
|
package org.mariotaku.twidere.task.twitter.message
|
||||||
|
|
||||||
|
import android.accounts.AccountManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import org.mariotaku.microblog.library.MicroBlog
|
||||||
import org.mariotaku.microblog.library.MicroBlogException
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
|
import org.mariotaku.sqliteqb.library.Expression
|
||||||
|
import org.mariotaku.twidere.annotation.AccountType
|
||||||
|
import org.mariotaku.twidere.extension.model.isOfficial
|
||||||
|
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||||
|
import org.mariotaku.twidere.model.AccountDetails
|
||||||
import org.mariotaku.twidere.model.UserKey
|
import org.mariotaku.twidere.model.UserKey
|
||||||
|
import org.mariotaku.twidere.model.util.AccountUtils
|
||||||
|
import org.mariotaku.twidere.provider.TwidereDataStore.Messages
|
||||||
|
import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations
|
||||||
import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask
|
import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,9 +42,35 @@ class DestroyConversationTask(
|
||||||
context: Context,
|
context: Context,
|
||||||
val accountKey: UserKey,
|
val accountKey: UserKey,
|
||||||
val conversationId: String
|
val conversationId: String
|
||||||
) : ExceptionHandlingAbstractTask<Unit?, Unit, MicroBlogException, Unit?>(context) {
|
) : ExceptionHandlingAbstractTask<Unit?, Boolean, MicroBlogException, Unit?>(context) {
|
||||||
override fun onExecute(params: Unit?) {
|
override fun onExecute(params: Unit?): Boolean {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
val account = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) ?:
|
||||||
|
throw MicroBlogException("No account")
|
||||||
|
val microBlog = account.newMicroBlogInstance(context, cls = MicroBlog::class.java)
|
||||||
|
if (!performDestroyConversation(microBlog, account)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val deleteMessageWhere = Expression.and(Expression.equalsArgs(Messages.ACCOUNT_KEY),
|
||||||
|
Expression.equalsArgs(Messages.CONVERSATION_ID)).sql
|
||||||
|
val deleteMessageWhereArgs = arrayOf(accountKey.toString(), conversationId)
|
||||||
|
context.contentResolver.delete(Messages.CONTENT_URI, deleteMessageWhere, deleteMessageWhereArgs)
|
||||||
|
val deleteConversationWhere = Expression.and(Expression.equalsArgs(Conversations.ACCOUNT_KEY),
|
||||||
|
Expression.equalsArgs(Conversations.CONVERSATION_ID)).sql
|
||||||
|
val deleteConversationWhereArgs = arrayOf(accountKey.toString(), conversationId)
|
||||||
|
context.contentResolver.delete(Conversations.CONTENT_URI, deleteConversationWhere, deleteConversationWhereArgs)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun performDestroyConversation(microBlog: MicroBlog, account: AccountDetails): Boolean {
|
||||||
|
when (account.type) {
|
||||||
|
AccountType.TWITTER -> {
|
||||||
|
if (account.isOfficial(context)) {
|
||||||
|
return microBlog.deleteDmConversation(conversationId).isSuccessful
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,6 +414,7 @@ class GetMessagesTask(
|
||||||
this.maxEntryId = v.maxEntryId
|
this.maxEntryId = v.maxEntryId
|
||||||
this.status = v.status
|
this.status = v.status
|
||||||
this.readOnly = v.isReadOnly
|
this.readOnly = v.isReadOnly
|
||||||
|
this.notificationsDisabled = v.isNotificationsDisabled
|
||||||
val maxEntryTimestamp = messagesMap.findLastReadTimestamp(k, maxEntryId)
|
val maxEntryTimestamp = messagesMap.findLastReadTimestamp(k, maxEntryId)
|
||||||
if (maxEntryTimestamp > 0) {
|
if (maxEntryTimestamp > 0) {
|
||||||
this.maxEntryTimestamp = maxEntryTimestamp
|
this.maxEntryTimestamp = maxEntryTimestamp
|
||||||
|
@ -509,6 +510,7 @@ class GetMessagesTask(
|
||||||
this.participants = participants + ParcelableUserUtils.fromUser(user, accountKey)
|
this.participants = participants + ParcelableUserUtils.fromUser(user, accountKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
participants.sortBy(ParcelableUser::screen_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Map<String, List<ParcelableMessage>>.findLastReadTimestamp(conversationId: String, lastReadEventId: String?): Long {
|
private fun Map<String, List<ParcelableMessage>>.findLastReadTimestamp(conversationId: String, lastReadEventId: String?): Long {
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.mariotaku.twidere.constant.iWantMyStarsBackKey
|
||||||
import org.mariotaku.twidere.constant.nameFirstKey
|
import org.mariotaku.twidere.constant.nameFirstKey
|
||||||
import org.mariotaku.twidere.extension.model.getConversationName
|
import org.mariotaku.twidere.extension.model.getConversationName
|
||||||
import org.mariotaku.twidere.extension.model.getSummaryText
|
import org.mariotaku.twidere.extension.model.getSummaryText
|
||||||
|
import org.mariotaku.twidere.extension.model.notificationDisabled
|
||||||
import org.mariotaku.twidere.extension.rawQuery
|
import org.mariotaku.twidere.extension.rawQuery
|
||||||
import org.mariotaku.twidere.model.*
|
import org.mariotaku.twidere.model.*
|
||||||
import org.mariotaku.twidere.model.util.ParcelableActivityUtils
|
import org.mariotaku.twidere.model.util.ParcelableActivityUtils
|
||||||
|
@ -294,6 +295,7 @@ class ContentNotificationManager(
|
||||||
builder.setContentTitle(notificationTitle)
|
builder.setContentTitle(notificationTitle)
|
||||||
val remaining = cur.forEachRow(5) { cur, pos ->
|
val remaining = cur.forEachRow(5) { cur, pos ->
|
||||||
val conversation = indices.newObject(cur)
|
val conversation = indices.newObject(cur)
|
||||||
|
if (conversation.notificationDisabled) return@forEachRow false
|
||||||
val title = conversation.getConversationName(context, userColorNameManager, nameFirst)
|
val title = conversation.getConversationName(context, userColorNameManager, nameFirst)
|
||||||
val summary = conversation.getSummaryText(context, userColorNameManager, nameFirst)
|
val summary = conversation.getSummaryText(context, userColorNameManager, nameFirst)
|
||||||
val line = SpanFormatter.format(context.getString(R.string.title_summary_line_format),
|
val line = SpanFormatter.format(context.getString(R.string.title_summary_line_format),
|
||||||
|
@ -304,6 +306,7 @@ class ContentNotificationManager(
|
||||||
style.addLine(line)
|
style.addLine(line)
|
||||||
return@forEachRow true
|
return@forEachRow true
|
||||||
}
|
}
|
||||||
|
if (remaining < 0) return
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
style.addLine(context.getString(R.string.and_N_more, remaining))
|
style.addLine(context.getString(R.string.and_N_more, remaining))
|
||||||
}
|
}
|
||||||
|
@ -323,7 +326,7 @@ class ContentNotificationManager(
|
||||||
var current = 0
|
var current = 0
|
||||||
while (!isAfterLast) {
|
while (!isAfterLast) {
|
||||||
if (limit >= 0 && current >= limit) break
|
if (limit >= 0 && current >= limit) break
|
||||||
if (action(this, position)) {
|
if (action(this, current)) {
|
||||||
current++
|
current++
|
||||||
}
|
}
|
||||||
moveToNext()
|
moveToNext()
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Twidere - Twitter client for Android
|
||||||
|
~
|
||||||
|
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||||
|
~
|
||||||
|
~ This program is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by
|
||||||
|
~ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
~ (at your option) any later version.
|
||||||
|
~
|
||||||
|
~ This program is distributed in the hope that it will be useful,
|
||||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
~ GNU General Public License for more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License
|
||||||
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
</menu>
|
Loading…
Reference in New Issue