From 4bd54354fa74a383170241c97c642265d4015fc4 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 16 Feb 2017 23:58:24 +0800 Subject: [PATCH] fixed tab type --- .../mariotaku/twidere/annotation/CustomTabType.java | 1 - .../twidere/model/ParcelableMessageConversation.java | 4 ++++ .../main/java/org/mariotaku/twidere/model/Tab.java | 4 ++-- .../mariotaku/twidere/provider/TwidereDataStore.java | 1 + .../main/java/org/mariotaku/twidere/Constants.java | 2 +- .../org/mariotaku/twidere/util/CustomTabUtils.java | 6 +++--- .../mariotaku/twidere/fragment/CustomTabsFragment.kt | 11 ++++++----- .../twidere/task/twitter/message/GetMessagesTask.kt | 12 ++++++++++-- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/CustomTabType.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/CustomTabType.java index 89253cb99..2162fe8df 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/CustomTabType.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/annotation/CustomTabType.java @@ -45,7 +45,6 @@ public @interface CustomTabType { String NOTIFICATIONS_TIMELINE = "notifications_timeline"; String TRENDS_SUGGESTIONS = "trends_suggestions"; String DIRECT_MESSAGES = "direct_messages"; - String DIRECT_MESSAGES_NEXT = "direct_messages_next"; String FAVORITES = "favorites"; String USER_TIMELINE = "user_timeline"; String SEARCH_STATUSES = "search_statuses"; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableMessageConversation.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableMessageConversation.java index 5486219b8..92ec396b6 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableMessageConversation.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableMessageConversation.java @@ -146,6 +146,10 @@ public class ParcelableMessageConversation implements Parcelable { @CursorField(value = Conversations.LAST_READ_ID) public String last_read_id; + @JsonField(name = "last_read_timestamp") + @CursorField(value = Conversations.LAST_READ_TIMESTAMP) + public long last_read_timestamp; + /** * True if this is a temporary conversation, i.e. Created by user but haven't send any message * yet. diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Tab.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Tab.java index 801f80b05..86880547a 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Tab.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/Tab.java @@ -121,7 +121,7 @@ public class Tab implements Parcelable { @CustomTabType public String getType() { - return type; + return getTypeAlias(type); } public void setType(@CustomTabType String type) { @@ -272,7 +272,7 @@ public class Tab implements Parcelable { } @JsonObject - static class InternalExtras { + static class InternalExtras { @JsonField(name = "base") TabExtras base; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java index 0291e1b0c..3511786ee 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/provider/TwidereDataStore.java @@ -383,6 +383,7 @@ public interface TwidereDataStore { String RECIPIENT_KEY = "recipient_key"; String REQUEST_CURSOR = "request_cursor"; String LAST_READ_ID = "last_read_id"; + String LAST_READ_TIMESTAMP = "last_read_timestamp"; String IS_OUTGOING = "is_outgoing"; String IS_TEMP = "is_temp"; String CONVERSATION_EXTRAS = "conversation_extras"; diff --git a/twidere/src/main/java/org/mariotaku/twidere/Constants.java b/twidere/src/main/java/org/mariotaku/twidere/Constants.java index d8bc95e67..c0ce2fa1f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/Constants.java +++ b/twidere/src/main/java/org/mariotaku/twidere/Constants.java @@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING; public interface Constants extends TwidereConstants { String DATABASES_NAME = "twidere.sqlite"; - int DATABASES_VERSION = 177; + int DATABASES_VERSION = 179; int EXTRA_FEATURES_NOTICE_VERSION = 0; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java index 27b1719bb..36492bd7f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java @@ -81,7 +81,7 @@ public class CustomTabUtils implements Constants { List specs = new ArrayList<>(); for (Tab tab : getTabs(context)) { @CustomTabType - final String type = Tab.getTypeAlias(tab.getType()); + final String type = tab.getType(); final int position = tab.getPosition(); final String iconType = tab.getIcon(); final String name = tab.getName(); @@ -148,7 +148,7 @@ public class CustomTabUtils implements Constants { return icon.createDrawable(context); } - public static String getTabTypeName(final Context context, final String type) { + public static String getTabTypeName(final Context context, @CustomTabType final String type) { if (context == null) return null; final TabConfiguration conf = TabConfiguration.ofType(type); if (conf == null) return null; @@ -172,7 +172,7 @@ public class CustomTabUtils implements Constants { } public static boolean hasAccountId(final Context context, @NonNull final Bundle args, - final UserKey[] activatedAccountKeys, UserKey accountKey) { + final UserKey[] activatedAccountKeys, UserKey accountKey) { final UserKey[] accountKeys = Utils.getAccountKeys(context, args); if (accountKeys != null) { return ArrayUtils.contains(accountKeys, accountKey); diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt index e9810a515..5c172d7e2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt @@ -180,7 +180,7 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks, MultiChoice } override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, - checked: Boolean) { + checked: Boolean) { updateTitle(mode) } @@ -466,15 +466,16 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks, MultiChoice R.layout.list_item_custom_tab, null, emptyArray(), intArrayOf(), 0) { private val iconColor: Int = ThemeUtils.getThemeForegroundColor(context) + private val tempTab: Tab = Tab() private var indices: TabCursorIndices? = null override fun bindView(view: View, context: Context?, cursor: Cursor) { super.bindView(view, context, cursor) val holder = view.tag as TwoLineWithIconViewHolder - val indices = indices!! - val type = Tab.getTypeAlias(cursor.getString(indices.type)) - val name = cursor.getString(indices.name) - val iconKey = cursor.getString(indices.icon) + indices?.parseFields(tempTab, cursor) + val type = tempTab.type + val name = tempTab.name + val iconKey = tempTab.icon if (type != null && CustomTabUtils.isTabTypeValid(type)) { val typeName = CustomTabUtils.getTabTypeName(context, type) holder.text1.text = if (TextUtils.isEmpty(name)) typeName else name diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt index 00700d98d..9f23e8370 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt @@ -23,6 +23,7 @@ import android.annotation.SuppressLint import android.content.ContentValues import android.content.Context import org.mariotaku.ktextension.toInt +import org.mariotaku.ktextension.toLong import org.mariotaku.ktextension.useCursor import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException @@ -372,7 +373,7 @@ class GetMessagesTask( } val messagesMap = messages.groupBy(ParcelableMessage::conversation_id) for ((k, v) in respConversations) { - val message = messagesMap[k]?.maxBy(ParcelableMessage::message_timestamp) ?: continue + val recentMessage = messagesMap[k]?.maxBy(ParcelableMessage::message_timestamp) ?: continue val participants = respUsers.filterKeys { userId -> v.participants.any { it.userId == userId } }.values @@ -381,13 +382,20 @@ class GetMessagesTask( DMResponse.Conversation.Type.GROUP_DM -> ConversationType.GROUP else -> ConversationType.ONE_TO_ONE } - val conversation = conversations.addConversation(k, account, message, participants, + val conversation = conversations.addConversation(k, account, recentMessage, participants, conversationType) conversation.conversation_name = v.name conversation.conversation_avatar = v.avatarImageHttps conversation.request_cursor = response.cursor conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.TWITTER_OFFICIAL conversation.last_read_id = v.lastReadEventId + val longEventId = v.lastReadEventId.toLong(-1) + // Find recent message timestamp + conversation.last_read_timestamp = messagesMap[k]?.filter { message -> + if (message.id == v.lastReadEventId) return@filter true + if (longEventId > 0 && longEventId < message.id.toLong(-1)) return@filter true + return@filter false + }?.maxBy(ParcelableMessage::message_timestamp)?.message_timestamp ?: -1 conversation.conversation_extras = TwitterOfficialConversationExtras().apply { this.minEntryId = v.minEntryId this.maxEntryId = v.maxEntryId