mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-14 16:25:05 +01:00
Long click & other improvements
This commit is contained in:
parent
9d6feca3f9
commit
ef8dd28151
@ -45,7 +45,7 @@ import kotlinx.android.synthetic.main.rv_item_conversation_with_last_message.vie
|
|||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
import org.koin.core.inject
|
import org.koin.core.inject
|
||||||
|
|
||||||
open class ConversationsPresenter(context: Context, onElementClick: ((Page, Holder, Element<Conversation>) -> Unit)?) : Presenter<Conversation>(context, onElementClick), KoinComponent {
|
open class ConversationsPresenter(context: Context, onElementClick: ((Page, Holder, Element<Conversation>) -> Unit)?, private val onElementLongClick: ((Page, Holder, Element<Conversation>) -> Unit)?) : Presenter<Conversation>(context, onElementClick), KoinComponent {
|
||||||
private val globalService: GlobalService by inject()
|
private val globalService: GlobalService by inject()
|
||||||
|
|
||||||
override val elementTypes: Collection<Int>
|
override val elementTypes: Collection<Int>
|
||||||
@ -57,6 +57,12 @@ open class ConversationsPresenter(context: Context, onElementClick: ((Page, Hold
|
|||||||
|
|
||||||
override fun onBind(page: Page, holder: Holder, element: Element<Conversation>, payloads: List<Any>) {
|
override fun onBind(page: Page, holder: Holder, element: Element<Conversation>, payloads: List<Any>) {
|
||||||
super.onBind(page, holder, element, payloads)
|
super.onBind(page, holder, element, payloads)
|
||||||
|
|
||||||
|
holder.itemView.setOnLongClickListener {
|
||||||
|
onElementLongClick?.invoke(page, holder, element)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
val conversation = element.data
|
val conversation = element.data
|
||||||
val user = globalService.currentUserLiveData.value
|
val user = globalService.currentUserLiveData.value
|
||||||
|
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Nextcloud Talk application
|
|
||||||
* *
|
|
||||||
* * @author Mario Danic
|
|
||||||
* * Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.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/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.nextcloud.talk.adapters
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
|
||||||
import com.otaliastudios.elements.extensions.LiveDataSource
|
|
||||||
|
|
||||||
class ConversationsSource(data: LiveData<List<Conversation>>, elementType: Int) : LiveDataSource<Conversation>(data, elementType) {
|
|
||||||
}
|
|
@ -66,7 +66,7 @@ class GenericTextHeaderItem(val model: String) : AbstractHeaderItem<GenericTextH
|
|||||||
if (payloads.size > 0) {
|
if (payloads.size > 0) {
|
||||||
Log.d(TAG, "We have payloads, so ignoring!")
|
Log.d(TAG, "We have payloads, so ignoring!")
|
||||||
} else {
|
} else {
|
||||||
holder.titleTextView!!.text = model
|
holder.titleTextView?.text = model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,13 @@ package com.nextcloud.talk.newarch.features.conversationsList
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.lifecycle.observe
|
import androidx.lifecycle.observe
|
||||||
import butterknife.OnClick
|
import butterknife.OnClick
|
||||||
|
import com.afollestad.materialdialogs.LayoutMode
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||||
import com.bluelinelabs.conductor.RouterTransaction
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.bluelinelabs.conductor.autodispose.ControllerScopeProvider
|
import com.bluelinelabs.conductor.autodispose.ControllerScopeProvider
|
||||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
|
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
|
||||||
@ -36,10 +40,12 @@ import com.nextcloud.talk.adapters.ConversationsPresenter
|
|||||||
import com.nextcloud.talk.controllers.ContactsController
|
import com.nextcloud.talk.controllers.ContactsController
|
||||||
import com.nextcloud.talk.controllers.SettingsController
|
import com.nextcloud.talk.controllers.SettingsController
|
||||||
import com.nextcloud.talk.controllers.bottomsheet.items.BasicListItemWithImage
|
import com.nextcloud.talk.controllers.bottomsheet.items.BasicListItemWithImage
|
||||||
|
import com.nextcloud.talk.controllers.bottomsheet.items.listItemsWithImage
|
||||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||||
import com.nextcloud.talk.newarch.conversationsList.mvp.BaseView
|
import com.nextcloud.talk.newarch.conversationsList.mvp.BaseView
|
||||||
import com.nextcloud.talk.newarch.mvvm.ext.initRecyclerView
|
import com.nextcloud.talk.newarch.mvvm.ext.initRecyclerView
|
||||||
import com.nextcloud.talk.utils.ConductorRemapping
|
import com.nextcloud.talk.utils.ConductorRemapping
|
||||||
|
import com.nextcloud.talk.utils.DisplayUtils
|
||||||
import com.nextcloud.talk.utils.animations.SharedElementTransition
|
import com.nextcloud.talk.utils.animations.SharedElementTransition
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||||
import com.otaliastudios.elements.*
|
import com.otaliastudios.elements.*
|
||||||
@ -74,6 +80,7 @@ class ConversationsListView : BaseView() {
|
|||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
super.onPrepareOptionsMenu(menu)
|
super.onPrepareOptionsMenu(menu)
|
||||||
settingsItem = menu.findItem(R.id.action_settings)
|
settingsItem = menu.findItem(R.id.action_settings)
|
||||||
|
settingsItem?.actionView?.transitionName = "userAvatar.transitionTag"
|
||||||
viewModel.loadAvatar()
|
viewModel.loadAvatar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +148,7 @@ class ConversationsListView : BaseView() {
|
|||||||
|
|
||||||
val adapter = Adapter.builder(this)
|
val adapter = Adapter.builder(this)
|
||||||
.addSource(Source.fromLiveData(viewModel.conversationsLiveData))
|
.addSource(Source.fromLiveData(viewModel.conversationsLiveData))
|
||||||
.addPresenter(ConversationsPresenter(context, ::onElementClick))
|
.addPresenter(ConversationsPresenter(context, ::onElementClick, ::onElementLongClick))
|
||||||
.addPresenter(Presenter.forLoadingIndicator(context, R.layout.loading_state))
|
.addPresenter(Presenter.forLoadingIndicator(context, R.layout.loading_state))
|
||||||
.addPresenter(Presenter.forEmptyIndicator(context, R.layout.message_state))
|
.addPresenter(Presenter.forEmptyIndicator(context, R.layout.message_state))
|
||||||
.addPresenter(Presenter.forErrorIndicator(context, R.layout.message_state) { view, throwable ->
|
.addPresenter(Presenter.forErrorIndicator(context, R.layout.message_state) { view, throwable ->
|
||||||
@ -149,7 +156,6 @@ class ConversationsListView : BaseView() {
|
|||||||
view.messageStateImageView.setImageDrawable(context.getDrawable(drawable.ic_announcement_white_24dp))
|
view.messageStateImageView.setImageDrawable(context.getDrawable(drawable.ic_announcement_white_24dp))
|
||||||
})
|
})
|
||||||
.into(view.recyclerView)
|
.into(view.recyclerView)
|
||||||
view.recyclerView.initRecyclerView(SmoothScrollLinearLayoutManager(activity), adapter, false)
|
|
||||||
|
|
||||||
view.apply {
|
view.apply {
|
||||||
recyclerView.initRecyclerView(SmoothScrollLinearLayoutManager(activity), adapter, false)
|
recyclerView.initRecyclerView(SmoothScrollLinearLayoutManager(activity), adapter, false)
|
||||||
@ -189,16 +195,66 @@ class ConversationsListView : BaseView() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onElementLongClick(page: Page, holder: Presenter.Holder, element: Element<Conversation>) {
|
||||||
|
val conversation = element.data
|
||||||
|
|
||||||
|
conversation?.let { conversation ->
|
||||||
|
activity?.let { activity ->
|
||||||
|
MaterialDialog(activity, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||||
|
cornerRadius(res = R.dimen.corner_radius)
|
||||||
|
title(text = conversation.displayName)
|
||||||
|
|
||||||
|
listItemsWithImage(getConversationMenuItemsForConversation(conversation)) { dialog, index, item ->
|
||||||
|
when (item.iconRes) {
|
||||||
|
drawable.ic_star_border_black_24dp -> {
|
||||||
|
viewModel.changeFavoriteValueForConversation(conversation, false)
|
||||||
|
|
||||||
|
}
|
||||||
|
drawable.ic_star_black_24dp -> {
|
||||||
|
viewModel.changeFavoriteValueForConversation(conversation, true)
|
||||||
|
}
|
||||||
|
drawable.ic_exit_to_app_black_24dp -> {
|
||||||
|
MaterialDialog(activity).show {
|
||||||
|
title(R.string.nc_leave)
|
||||||
|
message(R.string.nc_leave_message)
|
||||||
|
positiveButton(R.string.nc_simple_leave) {
|
||||||
|
viewModel.leaveConversation(conversation)
|
||||||
|
}
|
||||||
|
negativeButton(R.string.nc_cancel)
|
||||||
|
icon(drawable.ic_exit_to_app_black_24dp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drawable.ic_delete_grey600_24dp -> {
|
||||||
|
MaterialDialog(activity).show {
|
||||||
|
title(R.string.nc_delete)
|
||||||
|
message(text = conversation.deleteWarningMessage)
|
||||||
|
positiveButton(R.string.nc_delete_call) { dialog ->
|
||||||
|
viewModel.deleteConversation(conversation)
|
||||||
|
}
|
||||||
|
negativeButton(R.string.nc_cancel)
|
||||||
|
icon(
|
||||||
|
drawable = DisplayUtils.getTintedDrawable(
|
||||||
|
resources!!, drawable
|
||||||
|
.ic_delete_grey600_24dp, R.color.nc_darkRed
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getLayoutId(): Int {
|
override fun getLayoutId(): Int {
|
||||||
return R.layout.controller_conversations_rv
|
return R.layout.controller_conversations_rv
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.floatingActionButton)
|
@OnClick(R.id.floatingActionButton)
|
||||||
fun onFloatingActionButtonClick() {
|
fun onFloatingActionButtonClick() {
|
||||||
openNewConversationScreen()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openNewConversationScreen() {
|
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putBoolean(BundleKeys.KEY_NEW_CONVERSATION, true)
|
bundle.putBoolean(BundleKeys.KEY_NEW_CONVERSATION, true)
|
||||||
router.pushController(
|
router.pushController(
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
android:visibility="gone"
|
|
||||||
app:backgroundTint="@color/colorPrimary"
|
app:backgroundTint="@color/colorPrimary"
|
||||||
app:srcCompat="@drawable/ic_add_white_24px"
|
app:srcCompat="@drawable/ic_add_white_24px"
|
||||||
app:tint="@color/white" />
|
app:tint="@color/white" />
|
||||||
|
Loading…
Reference in New Issue
Block a user