ConversationListController: use NewBaseController + viewBinding

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-08-18 16:58:42 +02:00
parent 6315032e77
commit 929d6b3964
No known key found for this signature in database
GPG Key ID: 2585783189A62105
2 changed files with 81 additions and 116 deletions

View File

@ -38,17 +38,13 @@ import android.os.Handler
import android.text.InputType import android.text.InputType
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
@ -57,12 +53,10 @@ import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.work.Data import androidx.work.Data
import androidx.work.OneTimeWorkRequest import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager import androidx.work.WorkManager
import autodagger.AutoInjector import autodagger.AutoInjector
import butterknife.BindView
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
@ -74,7 +68,6 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
import com.facebook.imagepipeline.image.CloseableImage import com.facebook.imagepipeline.image.CloseableImage
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.activities.MainActivity import com.nextcloud.talk.activities.MainActivity
import com.nextcloud.talk.adapters.items.ConversationItem import com.nextcloud.talk.adapters.items.ConversationItem
@ -85,8 +78,10 @@ import com.nextcloud.talk.adapters.items.MessagesTextHeaderItem
import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.controllers.base.BaseController import com.nextcloud.talk.controllers.base.NewBaseController
import com.nextcloud.talk.controllers.util.viewBinding
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ControllerConversationsRvBinding
import com.nextcloud.talk.events.ConversationsListFetchDataEvent import com.nextcloud.talk.events.ConversationsListFetchDataEvent
import com.nextcloud.talk.events.EventStatus import com.nextcloud.talk.events.EventStatus
import com.nextcloud.talk.interfaces.ConversationMenuInterface import com.nextcloud.talk.interfaces.ConversationMenuInterface
@ -105,7 +100,6 @@ import com.nextcloud.talk.models.json.statuses.StatusesOverall
import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository import com.nextcloud.talk.repositories.unifiedsearch.UnifiedSearchRepository
import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment import com.nextcloud.talk.ui.dialog.ChooseAccountDialogFragment
import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog import com.nextcloud.talk.ui.dialog.ConversationsListBottomDialog
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.users.UserManager import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.AttendeePermissionsUtil import com.nextcloud.talk.utils.AttendeePermissionsUtil
@ -131,9 +125,7 @@ import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.hasSpreedFeatu
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isServerEOL import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isServerEOL
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isUnifiedSearchAvailable import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isUnifiedSearchAvailable
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isUserStatusAvailable import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isUserStatusAvailable
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.nextcloud.talk.utils.rx.SearchViewObservable.Companion.observeSearchView import com.nextcloud.talk.utils.rx.SearchViewObservable.Companion.observeSearchView
import com.nextcloud.ui.popupbubble.PopupBubble
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
@ -155,7 +147,7 @@ import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class ConversationsListController(bundle: Bundle) : class ConversationsListController(bundle: Bundle) :
BaseController(), NewBaseController(R.layout.controller_conversations_rv, bundle),
FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemClickListener,
FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnItemLongClickListener,
ConversationMenuInterface { ConversationMenuInterface {
@ -170,41 +162,16 @@ class ConversationsListController(bundle: Bundle) :
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@Inject
lateinit var context: Context
@Inject
lateinit var appPreferences: AppPreferences
@Inject @Inject
lateinit var unifiedSearchRepository: UnifiedSearchRepository lateinit var unifiedSearchRepository: UnifiedSearchRepository
@Inject private val binding: ControllerConversationsRvBinding by viewBinding(ControllerConversationsRvBinding::bind)
lateinit var viewThemeUtils: ViewThemeUtils
@JvmField override val title: String
@BindView(R.id.recycler_view) get() = resources!!.getString(R.string.nc_app_product_name)
var recyclerView: RecyclerView? = null
@JvmField override val appBarLayoutType: AppBarLayoutType
@BindView(R.id.swipeRefreshLayoutView) get() = AppBarLayoutType.SEARCH_BAR
var swipeRefreshLayout: SwipeRefreshLayout? = null
@JvmField
@BindView(R.id.loading_content)
var loadingContent: LinearLayout? = null
@JvmField
@BindView(R.id.emptyLayout)
var emptyLayoutView: RelativeLayout? = null
@JvmField
@BindView(R.id.floatingActionButton)
var floatingActionButton: FloatingActionButton? = null
@JvmField
@BindView(R.id.newMentionPopupBubble)
var newMentionPopupBubble: PopupBubble? = null
private var currentUser: User? = null private var currentUser: User? = null
private var roomsQueryDisposable: Disposable? = null private var roomsQueryDisposable: Disposable? = null
@ -234,20 +201,14 @@ class ConversationsListController(bundle: Bundle) :
private var searchHelper: MessageSearchHelper? = null private var searchHelper: MessageSearchHelper? = null
private var searchViewDisposable: Disposable? = null private var searchViewDisposable: Disposable? = null
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
return inflater.inflate(R.layout.controller_conversations_rv, container, false)
}
override fun onViewBound(view: View) { override fun onViewBound(view: View) {
super.onViewBound(view) super.onViewBound(view)
sharedApplication!!.componentApplication.inject(this) sharedApplication!!.componentApplication.inject(this)
if (actionBar != null) { actionBar?.show()
actionBar.show()
}
if (adapter == null) { if (adapter == null) {
adapter = FlexibleAdapter(conversationItems, activity, true) adapter = FlexibleAdapter(conversationItems, activity, true)
} else { } else {
loadingContent!!.visibility = View.GONE binding.loadingContent.visibility = View.GONE
} }
adapter!!.addListener(this) adapter!!.addListener(this)
prepareViews() prepareViews()
@ -378,10 +339,10 @@ class ConversationsListController(bundle: Bundle) :
showShareToScreen = !showShareToScreen && hasActivityActionSendIntent() showShareToScreen = !showShareToScreen && hasActivityActionSendIntent()
if (showShareToScreen) { if (showShareToScreen) {
hideSearchBar() hideSearchBar()
actionBar.setTitle(R.string.send_to_three_dots) actionBar?.setTitle(R.string.send_to_three_dots)
} else if (forwardMessage) { } else if (forwardMessage) {
hideSearchBar() hideSearchBar()
actionBar.setTitle(R.string.nc_forward_to_three_dots) actionBar?.setTitle(R.string.nc_forward_to_three_dots)
} else { } else {
val activity = activity as MainActivity? val activity = activity as MainActivity?
searchItem!!.isVisible = conversationItems.size > 0 searchItem!!.isVisible = conversationItems.size > 0
@ -411,8 +372,8 @@ class ConversationsListController(bundle: Bundle) :
adapter!!.setHeadersShown(true) adapter!!.setHeadersShown(true)
adapter!!.updateDataSet(searchableConversationItems, false) adapter!!.updateDataSet(searchableConversationItems, false)
adapter!!.showAllHeaders() adapter!!.showAllHeaders()
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isEnabled = false binding.swipeRefreshLayoutView!!.isEnabled = false
} }
return true return true
} }
@ -424,10 +385,10 @@ class ConversationsListController(bundle: Bundle) :
if (searchHelper != null) { if (searchHelper != null) {
// cancel any pending searches // cancel any pending searches
searchHelper!!.cancelSearch() searchHelper!!.cancelSearch()
swipeRefreshLayout!!.isRefreshing = false binding.swipeRefreshLayoutView!!.isRefreshing = false
} }
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isEnabled = true binding.swipeRefreshLayoutView!!.isEnabled = true
} }
searchView!!.onActionViewCollapsed() searchView!!.onActionViewCollapsed()
val activity = getActivity() as MainActivity? val activity = getActivity() as MainActivity?
@ -442,7 +403,7 @@ class ConversationsListController(bundle: Bundle) :
viewThemeUtils.resetStatusBar(activity, activity.binding.searchToolbar) viewThemeUtils.resetStatusBar(activity, activity.binding.searchToolbar)
} }
} }
val layoutManager = recyclerView!!.layoutManager as SmoothScrollLinearLayoutManager? val layoutManager = binding.recyclerView!!.layoutManager as SmoothScrollLinearLayoutManager?
layoutManager?.scrollToPositionWithOffset(0, 0) layoutManager?.scrollToPositionWithOffset(0, 0)
return true return true
} }
@ -462,7 +423,7 @@ class ConversationsListController(bundle: Bundle) :
} }
} }
fun showSearchView(activity: MainActivity, searchView: SearchView?, searchItem: MenuItem?) { private fun showSearchView(activity: MainActivity, searchView: SearchView?, searchItem: MenuItem?) {
activity.binding.appBar.stateListAnimator = AnimatorInflater.loadStateListAnimator( activity.binding.appBar.stateListAnimator = AnimatorInflater.loadStateListAnimator(
activity.binding.appBar.context, activity.binding.appBar.context,
R.animator.appbar_elevation_on R.animator.appbar_elevation_on
@ -530,21 +491,21 @@ class ConversationsListController(bundle: Bundle) :
} }
if (adapterWasNull) { if (adapterWasNull) {
adapterWasNull = false adapterWasNull = false
loadingContent!!.visibility = View.GONE binding.loadingContent!!.visibility = View.GONE
} }
if (ocs!!.data!!.size > 0) { if (ocs!!.data!!.size > 0) {
if (emptyLayoutView!!.visibility != View.GONE) { if (binding.emptyLayout!!.visibility != View.GONE) {
emptyLayoutView!!.visibility = View.GONE binding.emptyLayout!!.visibility = View.GONE
} }
if (swipeRefreshLayout!!.visibility != View.VISIBLE) { if (binding.swipeRefreshLayoutView!!.visibility != View.VISIBLE) {
swipeRefreshLayout!!.visibility = View.VISIBLE binding.swipeRefreshLayoutView!!.visibility = View.VISIBLE
} }
} else { } else {
if (emptyLayoutView!!.visibility != View.VISIBLE) { if (binding.emptyLayout!!.visibility != View.VISIBLE) {
emptyLayoutView!!.visibility = View.VISIBLE binding.emptyLayout!!.visibility = View.VISIBLE
} }
if (swipeRefreshLayout!!.visibility != View.GONE) { if (binding.swipeRefreshLayoutView!!.visibility != View.GONE) {
swipeRefreshLayout!!.visibility = View.GONE binding.swipeRefreshLayoutView!!.visibility = View.GONE
} }
} }
for (conversation in ocs.data!!) { for (conversation in ocs.data!!) {
@ -586,19 +547,19 @@ class ConversationsListController(bundle: Bundle) :
adapter!!.updateDataSet(conversationItems, false) adapter!!.updateDataSet(conversationItems, false)
Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong()) Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong())
fetchOpenConversations(apiVersion) fetchOpenConversations(apiVersion)
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isRefreshing = false binding.swipeRefreshLayoutView!!.isRefreshing = false
} }
}, { throwable: Throwable -> }, { throwable: Throwable ->
handleHttpExceptions(throwable) handleHttpExceptions(throwable)
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isRefreshing = false binding.swipeRefreshLayoutView!!.isRefreshing = false
} }
dispose(roomsQueryDisposable) dispose(roomsQueryDisposable)
}) { }) {
dispose(roomsQueryDisposable) dispose(roomsQueryDisposable)
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isRefreshing = false binding.swipeRefreshLayoutView!!.isRefreshing = false
} }
isRefreshing = false isRefreshing = false
} }
@ -682,10 +643,10 @@ class ConversationsListController(bundle: Bundle) :
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
private fun prepareViews() { private fun prepareViews() {
layoutManager = SmoothScrollLinearLayoutManager(Objects.requireNonNull(activity)) layoutManager = SmoothScrollLinearLayoutManager(Objects.requireNonNull(activity))
recyclerView!!.layoutManager = layoutManager binding.recyclerView!!.layoutManager = layoutManager
recyclerView!!.setHasFixedSize(true) binding.recyclerView!!.setHasFixedSize(true)
recyclerView!!.adapter = adapter binding.recyclerView!!.adapter = adapter
recyclerView!!.addOnScrollListener(object : RecyclerView.OnScrollListener() { binding.recyclerView!!.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState) super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (newState == RecyclerView.SCROLL_STATE_IDLE) {
@ -693,21 +654,21 @@ class ConversationsListController(bundle: Bundle) :
} }
} }
}) })
recyclerView!!.setOnTouchListener { v: View, event: MotionEvent? -> binding.recyclerView!!.setOnTouchListener { v: View, event: MotionEvent? ->
if (isAttached && (!isBeingDestroyed || !isDestroyed)) { if (isAttached && (!isBeingDestroyed || !isDestroyed)) {
val imm = activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager val imm = activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(v.windowToken, 0) imm.hideSoftInputFromWindow(v.windowToken, 0)
} }
false false
} }
swipeRefreshLayout!!.setOnRefreshListener { fetchData() } binding.swipeRefreshLayoutView!!.setOnRefreshListener { fetchData() }
viewThemeUtils.themeSwipeRefreshLayout(swipeRefreshLayout!!) viewThemeUtils.themeSwipeRefreshLayout(binding.swipeRefreshLayoutView!!)
emptyLayoutView!!.setOnClickListener { v: View? -> showNewConversationsScreen() } binding.emptyLayout!!.setOnClickListener { v: View? -> showNewConversationsScreen() }
floatingActionButton!!.setOnClickListener { v: View? -> binding.floatingActionButton!!.setOnClickListener { v: View? ->
run(context) run(context)
showNewConversationsScreen() showNewConversationsScreen()
} }
viewThemeUtils.themeFAB(floatingActionButton!!) viewThemeUtils.themeFAB(binding.floatingActionButton!!)
if (activity != null && activity is MainActivity) { if (activity != null && activity is MainActivity) {
val activity = activity as MainActivity? val activity = activity as MainActivity?
activity!!.binding.switchAccountButton.setOnClickListener { v: View? -> activity!!.binding.switchAccountButton.setOnClickListener { v: View? ->
@ -726,13 +687,13 @@ class ConversationsListController(bundle: Bundle) :
} }
} }
} }
newMentionPopupBubble!!.hide() binding.newMentionPopupBubble!!.hide()
newMentionPopupBubble!!.setPopupBubbleListener { binding.newMentionPopupBubble!!.setPopupBubbleListener {
recyclerView!!.smoothScrollToPosition( binding.recyclerView!!.smoothScrollToPosition(
nextUnreadConversationScrollPosition nextUnreadConversationScrollPosition
) )
} }
viewThemeUtils.colorMaterialButtonPrimaryFilled(newMentionPopupBubble!!) viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.newMentionPopupBubble!!)
} }
private fun checkToShowUnreadBubble() { private fun checkToShowUnreadBubble() {
@ -748,14 +709,14 @@ class ConversationsListController(bundle: Bundle) :
) && position > lastVisibleItem ) && position > lastVisibleItem
) { ) {
nextUnreadConversationScrollPosition = position nextUnreadConversationScrollPosition = position
if (!newMentionPopupBubble!!.isShown) { if (!binding.newMentionPopupBubble!!.isShown) {
newMentionPopupBubble!!.show() binding.newMentionPopupBubble!!.show()
} }
return return
} }
} }
nextUnreadConversationScrollPosition = 0 nextUnreadConversationScrollPosition = 0
newMentionPopupBubble!!.hide() binding.newMentionPopupBubble!!.hide()
} catch (e: NullPointerException) { } catch (e: NullPointerException) {
Log.d( Log.d(
TAG, TAG,
@ -856,8 +817,8 @@ class ConversationsListController(bundle: Bundle) :
@SuppressLint("CheckResult") // handled by helper @SuppressLint("CheckResult") // handled by helper
private fun startMessageSearch(search: String?) { private fun startMessageSearch(search: String?) {
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isRefreshing = true binding.swipeRefreshLayoutView!!.isRefreshing = true
} }
searchHelper?.startMessageSearch(search!!) searchHelper?.startMessageSearch(search!!)
?.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
@ -871,7 +832,7 @@ class ConversationsListController(bundle: Bundle) :
@SuppressLint("CheckResult") // handled by helper @SuppressLint("CheckResult") // handled by helper
private fun loadMoreMessages() { private fun loadMoreMessages() {
swipeRefreshLayout!!.isRefreshing = true binding.swipeRefreshLayoutView!!.isRefreshing = true
val observable = searchHelper!!.loadMore() val observable = searchHelper!!.loadMore()
observable?.observeOn(AndroidSchedulers.mainThread()) observable?.observeOn(AndroidSchedulers.mainThread())
?.subscribe({ results: MessageSearchResults -> onMessageSearchResult(results) }) { throwable: Throwable -> ?.subscribe({ results: MessageSearchResults -> onMessageSearchResult(results) }) { throwable: Throwable ->
@ -881,10 +842,6 @@ class ConversationsListController(bundle: Bundle) :
} }
} }
override fun getTitle(): String {
return resources!!.getString(R.string.nc_app_product_name)
}
override fun onItemClick(view: View, position: Int): Boolean { override fun onItemClick(view: View, position: Int): Boolean {
val item = adapter!!.getItem(position) val item = adapter!!.getItem(position)
if (item != null) { if (item != null) {
@ -978,7 +935,7 @@ class ConversationsListController(bundle: Bundle) :
selectedConversation!!.displayName selectedConversation!!.displayName
) )
} }
val dialogBuilder = MaterialAlertDialogBuilder(floatingActionButton!!.context) val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton!!.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.upload)) .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.upload))
.setTitle(confirmationQuestion) .setTitle(confirmationQuestion)
.setMessage(fileNamesWithLineBreaks.toString()) .setMessage(fileNamesWithLineBreaks.toString())
@ -990,7 +947,7 @@ class ConversationsListController(bundle: Bundle) :
Log.d(TAG, "sharing files aborted, going back to share-to screen") Log.d(TAG, "sharing files aborted, going back to share-to screen")
showShareToScreen = true showShareToScreen = true
} }
viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton!!.context, dialogBuilder) viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton!!.context, dialogBuilder)
val dialog = dialogBuilder.show() val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons( viewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE), dialog.getButton(AlertDialog.BUTTON_POSITIVE),
@ -1168,7 +1125,7 @@ class ConversationsListController(bundle: Bundle) :
) { ) {
val conversation = Parcels.unwrap<Conversation>(conversationMenuBundle!!.getParcelable(KEY_ROOM)) val conversation = Parcels.unwrap<Conversation>(conversationMenuBundle!!.getParcelable(KEY_ROOM))
if (conversation != null) { if (conversation != null) {
val dialogBuilder = MaterialAlertDialogBuilder(floatingActionButton!!.context) val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton!!.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp)) .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setTitle(R.string.nc_delete_call) .setTitle(R.string.nc_delete_call)
.setMessage(R.string.nc_delete_conversation_more) .setMessage(R.string.nc_delete_conversation_more)
@ -1185,7 +1142,7 @@ class ConversationsListController(bundle: Bundle) :
.setNegativeButton(R.string.nc_cancel) { dialog: DialogInterface?, which: Int -> .setNegativeButton(R.string.nc_cancel) { dialog: DialogInterface?, which: Int ->
conversationMenuBundle = null conversationMenuBundle = null
} }
viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton!!.context, dialogBuilder) viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton!!.context, dialogBuilder)
val dialog = dialogBuilder.show() val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons( viewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE), dialog.getButton(AlertDialog.BUTTON_POSITIVE),
@ -1197,7 +1154,7 @@ class ConversationsListController(bundle: Bundle) :
private fun showUnauthorizedDialog() { private fun showUnauthorizedDialog() {
if (activity != null) { if (activity != null) {
val dialogBuilder = MaterialAlertDialogBuilder(floatingActionButton!!.context) val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton!!.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp)) .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_delete_black_24dp))
.setTitle(R.string.nc_dialog_invalid_password) .setTitle(R.string.nc_dialog_invalid_password)
.setMessage(R.string.nc_dialog_reauth_or_delete) .setMessage(R.string.nc_dialog_reauth_or_delete)
@ -1230,7 +1187,7 @@ class ConversationsListController(bundle: Bundle) :
.popChangeHandler(VerticalChangeHandler()) .popChangeHandler(VerticalChangeHandler())
) )
} }
viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton!!.context, dialogBuilder) viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton!!.context, dialogBuilder)
val dialog = dialogBuilder.show() val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons( viewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE), dialog.getButton(AlertDialog.BUTTON_POSITIVE),
@ -1240,7 +1197,7 @@ class ConversationsListController(bundle: Bundle) :
} }
private fun showServerEOLDialog() { private fun showServerEOLDialog() {
val dialogBuilder = MaterialAlertDialogBuilder(floatingActionButton!!.context) val dialogBuilder = MaterialAlertDialogBuilder(binding.floatingActionButton!!.context)
.setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_warning_white)) .setIcon(viewThemeUtils.colorMaterialAlertDialogIcon(context, R.drawable.ic_warning_white))
.setTitle(R.string.nc_settings_server_eol_title) .setTitle(R.string.nc_settings_server_eol_title)
.setMessage(R.string.nc_settings_server_eol) .setMessage(R.string.nc_settings_server_eol)
@ -1272,7 +1229,7 @@ class ConversationsListController(bundle: Bundle) :
activity!!.finish() activity!!.finish()
} }
} }
viewThemeUtils.colorMaterialAlertDialogBackground(floatingActionButton!!.context, dialogBuilder) viewThemeUtils.colorMaterialAlertDialogBackground(binding.floatingActionButton!!.context, dialogBuilder)
val dialog = dialogBuilder.show() val dialog = dialogBuilder.show()
viewThemeUtils.colorTextButtons( viewThemeUtils.colorTextButtons(
dialog.getButton(AlertDialog.BUTTON_POSITIVE), dialog.getButton(AlertDialog.BUTTON_POSITIVE),
@ -1286,10 +1243,6 @@ class ConversationsListController(bundle: Bundle) :
WorkManager.getInstance().enqueue(deleteConversationWorker) WorkManager.getInstance().enqueue(deleteConversationWorker)
} }
override fun getAppBarLayoutType(): AppBarLayoutType {
return AppBarLayoutType.SEARCH_BAR
}
fun onMessageSearchResult(results: MessageSearchResults) { fun onMessageSearchResult(results: MessageSearchResults) {
if (searchView!!.query.length > 0) { if (searchView!!.query.length > 0) {
clearMessageSearchResults() clearMessageSearchResults()
@ -1312,18 +1265,18 @@ class ConversationsListController(bundle: Bundle) :
adapterItems.add(LoadMoreResultsItem) adapterItems.add(LoadMoreResultsItem)
} }
adapter!!.addItems(0, adapterItems) adapter!!.addItems(0, adapterItems)
recyclerView!!.scrollToPosition(0) binding.recyclerView!!.scrollToPosition(0)
} }
} }
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isRefreshing = false binding.swipeRefreshLayoutView!!.isRefreshing = false
} }
} }
fun onMessageSearchError(throwable: Throwable) { fun onMessageSearchError(throwable: Throwable) {
handleHttpExceptions(throwable) handleHttpExceptions(throwable)
if (swipeRefreshLayout != null) { if (binding.swipeRefreshLayoutView != null) {
swipeRefreshLayout!!.isRefreshing = false binding.swipeRefreshLayoutView!!.isRefreshing = false
} }
} }

View File

@ -145,7 +145,7 @@ abstract class NewBaseController(@LayoutRes var layoutRes: Int, args: Bundle? =
super.onAttach(view) super.onAttach(view)
} }
protected fun showSearchOrToolbar() { open fun showSearchOrToolbar() {
if (isValidActivity(activity)) { if (isValidActivity(activity)) {
val showSearchBar = appBarLayoutType == AppBarLayoutType.SEARCH_BAR val showSearchBar = appBarLayoutType == AppBarLayoutType.SEARCH_BAR
val activity = activity as MainActivity val activity = activity as MainActivity
@ -202,6 +202,18 @@ abstract class NewBaseController(@LayoutRes var layoutRes: Int, args: Bundle? =
binding.searchToolbar.visibility = View.GONE binding.searchToolbar.visibility = View.GONE
} }
fun hideSearchBar() {
val activity = activity as MainActivity?
val layoutParams = activity!!.binding.searchToolbar.layoutParams as AppBarLayout.LayoutParams
activity.binding.searchToolbar.visibility = View.GONE
activity.binding.toolbar.visibility = View.VISIBLE
layoutParams.scrollFlags = 0
activity.binding.appBar.stateListAnimator = AnimatorInflater.loadStateListAnimator(
activity.binding.appBar.context,
R.animator.appbar_elevation_on
)
}
private fun colorizeStatusBar(showSearchBar: Boolean, activity: Activity?, resources: Resources?) { private fun colorizeStatusBar(showSearchBar: Boolean, activity: Activity?, resources: Resources?) {
if (activity != null && resources != null) { if (activity != null && resources != null) {
if (showSearchBar) { if (showSearchBar) {