added mark as read in message entries
This commit is contained in:
parent
4b09db8bde
commit
72a67dfbd5
|
@ -87,6 +87,7 @@ class MessagesEntriesAdapter(
|
|||
interface MessageConversationClickListener {
|
||||
fun onProfileImageClick(position: Int)
|
||||
fun onConversationClick(position: Int)
|
||||
fun onConversationLongClick(position: Int): Boolean
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,14 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks
|
||||
import android.support.v4.content.Loader
|
||||
import android.view.ContextMenu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import com.bumptech.glide.Glide
|
||||
import com.squareup.otto.Subscribe
|
||||
import kotlinx.android.synthetic.main.activity_premium_dashboard.*
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.toStringArray
|
||||
import org.mariotaku.sqliteqb.library.*
|
||||
|
@ -37,7 +43,9 @@ import org.mariotaku.twidere.activity.AccountSelectorActivity
|
|||
import org.mariotaku.twidere.adapter.MessagesEntriesAdapter
|
||||
import org.mariotaku.twidere.adapter.MessagesEntriesAdapter.MessageConversationClickListener
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.constant.nameFirstKey
|
||||
import org.mariotaku.twidere.constant.newDocumentApiKey
|
||||
import org.mariotaku.twidere.extension.model.getTitle
|
||||
import org.mariotaku.twidere.extension.model.user
|
||||
import org.mariotaku.twidere.fragment.AbsContentListRecyclerViewFragment
|
||||
import org.mariotaku.twidere.fragment.iface.IFloatingActionButtonFragment
|
||||
|
@ -49,8 +57,10 @@ import org.mariotaku.twidere.model.event.GetMessagesTaskEvent
|
|||
import org.mariotaku.twidere.provider.TwidereDataStore.Messages
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations
|
||||
import org.mariotaku.twidere.task.twitter.message.GetMessagesTask
|
||||
import org.mariotaku.twidere.task.twitter.message.MarkMessageReadTask
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import org.mariotaku.twidere.view.ExtendedRecyclerView
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/28.
|
||||
|
@ -70,6 +80,7 @@ class MessagesEntriesFragment : AbsContentListRecyclerViewFragment<MessagesEntri
|
|||
adapter.listener = this
|
||||
adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.END
|
||||
loaderManager.initLoader(0, null, this)
|
||||
registerForContextMenu(recyclerView)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -141,6 +152,12 @@ class MessagesEntriesFragment : AbsContentListRecyclerViewFragment<MessagesEntri
|
|||
IntentUtils.openMessageConversation(context, conversation.account_key, conversation.id)
|
||||
}
|
||||
|
||||
override fun onConversationLongClick(position: Int): Boolean {
|
||||
val view = recyclerView.layoutManager.findViewByPosition(position) ?: return false
|
||||
recyclerView.showContextMenuForChild(view)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onProfileImageClick(position: Int) {
|
||||
val conversation = adapter.getConversation(position) ?: return
|
||||
val user = conversation.user ?: return
|
||||
|
@ -162,6 +179,30 @@ class MessagesEntriesFragment : AbsContentListRecyclerViewFragment<MessagesEntri
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
|
||||
if (!userVisibleHint || menuInfo == null) return
|
||||
val info = menuInfo as? ExtendedRecyclerView.ContextMenuInfo ?: return
|
||||
val conversation = adapter.getConversation(info.position) ?: return
|
||||
val inflater = MenuInflater(context)
|
||||
inflater.inflate(R.menu.context_message_entry, menu)
|
||||
menu.setHeaderTitle(conversation.getTitle(context, userColorNameManager,
|
||||
preferences[nameFirstKey]).first)
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
if (!userVisibleHint) return false
|
||||
val menuInfo = item.menuInfo as? ExtendedRecyclerView.ContextMenuInfo ?: return false
|
||||
when (item.itemId) {
|
||||
R.id.mark_read -> {
|
||||
val conversation = adapter.getConversation(menuInfo.position) ?: return true
|
||||
TaskStarter.execute(MarkMessageReadTask(context, conversation.account_key,
|
||||
conversation.id))
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onContextItemSelected(item)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onGetMessagesTaskEvent(event: GetMessagesTaskEvent) {
|
||||
if (!event.running) {
|
||||
|
|
|
@ -60,6 +60,9 @@ class MessageEntryViewHolder(itemView: View, val adapter: MessagesEntriesAdapter
|
|||
itemView.setOnClickListener {
|
||||
adapter.listener?.onConversationClick(layoutPosition)
|
||||
}
|
||||
itemView.setOnLongClickListener {
|
||||
adapter.listener?.onConversationLongClick(layoutPosition) ?: false
|
||||
}
|
||||
profileImage.setOnClickListener {
|
||||
adapter.listener?.onProfileImageClick(layoutPosition)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?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">
|
||||
<item
|
||||
android:id="@+id/mark_read"
|
||||
android:title="@string/action_mark_as_read"/>
|
||||
</menu>
|
|
@ -67,6 +67,7 @@
|
|||
<!-- [verb] e.g. An action label on a tweet to like this tweet. Formerly Twitter favorite. -->
|
||||
<string name="action_like">Like</string>
|
||||
<string name="action_liking">liking</string>
|
||||
<string name="action_mark_as_read">Mark as read</string>
|
||||
<string name="action_modifying_lists">modifying lists</string>
|
||||
<string name="action_mute">Mute</string>
|
||||
<string name="action_mute_notifications">Mute notifications</string>
|
||||
|
|
Loading…
Reference in New Issue