Skip to content

Commit

Permalink
add option to list open conversations
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
  • Loading branch information
mahibi committed Jun 19, 2023
1 parent 527ba28 commit fa36181
Show file tree
Hide file tree
Showing 22 changed files with 879 additions and 228 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />

<activity
android:name=".openconversations.ListOpenConversationsActivity"
android:theme="@style/AppTheme" />

<activity
android:name=".conversationlist.ConversationsListActivity"
android:theme="@style/AppTheme"
Expand Down
64 changes: 38 additions & 26 deletions app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.controllers.bottomsheet.ConversationOperationEnum
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ControllerContactsRvBinding
import com.nextcloud.talk.databinding.ActivityContactsBinding
import com.nextcloud.talk.events.OpenConversationEvent
import com.nextcloud.talk.jobs.AddParticipantsToConversation
import com.nextcloud.talk.models.RetrofitBucket
Expand All @@ -63,6 +63,7 @@ import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.converters.EnumActorTypeConverter
import com.nextcloud.talk.models.json.participants.Participant
import com.nextcloud.talk.openconversations.ListOpenConversationsActivity
import com.nextcloud.talk.ui.dialog.ContactsBottomDialog
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ApiUtils
Expand Down Expand Up @@ -90,7 +91,7 @@ class ContactsActivity :
BaseActivity(),
SearchView.OnQueryTextListener,
FlexibleAdapter.OnItemClickListener {
private lateinit var binding: ControllerContactsRvBinding
private lateinit var binding: ActivityContactsBinding

@Inject
lateinit var userManager: UserManager
Expand Down Expand Up @@ -125,7 +126,7 @@ class ContactsActivity :
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)

binding = ControllerContactsRvBinding.inflate(layoutInflater)
binding = ActivityContactsBinding.inflate(layoutInflater)
setupActionBar()
setContentView(binding.root)
setupSystemColors()
Expand Down Expand Up @@ -159,13 +160,16 @@ class ContactsActivity :
toggleConversationPrivacyLayout(!isPublicCall)
}
if (isAddingParticipantsView) {
binding.joinConversationViaLink.joinConversationViaLinkRelativeLayout.visibility = View.GONE
binding.conversationPrivacyToggle.callHeaderLayout.visibility = View.GONE
binding.joinConversationViaLink.visibility = View.GONE
binding.callHeaderLayout.visibility = View.GONE
} else {
binding.joinConversationViaLink.joinConversationViaLinkRelativeLayout.setOnClickListener {
binding.joinConversationViaLink.setOnClickListener {
joinConversationViaLink()
}
binding.conversationPrivacyToggle.callHeaderLayout.setOnClickListener {
binding.listOpenConversations.setOnClickListener {
listOpenConversations()
}
binding.callHeaderLayout.setOnClickListener {
toggleCallHeader()
}
}
Expand Down Expand Up @@ -662,26 +666,29 @@ class ContactsActivity :

binding?.controllerGenericRv?.let { viewThemeUtils.androidx.themeSwipeRefreshLayout(it.swipeRefreshLayout) }

binding?.joinConversationViaLink?.joinConversationViaLinkImageView
?.background
?.setColorFilter(
ResourcesCompat.getColor(resources!!, R.color.colorBackgroundDarker, null),
PorterDuff.Mode.SRC_IN
)
binding.listOpenConversationsImage.background?.setColorFilter(
ResourcesCompat.getColor(resources!!, R.color.colorBackgroundDarker, null),
PorterDuff.Mode.SRC_IN
)

binding?.conversationPrivacyToggle?.let {
binding.joinConversationViaLinkImage.background?.setColorFilter(
ResourcesCompat.getColor(resources!!, R.color.colorBackgroundDarker, null),
PorterDuff.Mode.SRC_IN
)

binding?.let {
viewThemeUtils.platform.colorImageViewBackgroundAndIcon(it.publicCallLink)
}
disengageProgressBar()
}

private fun disengageProgressBar() {
if (!alreadyFetching) {
binding?.loadingContent?.visibility = View.GONE
binding?.controllerGenericRv?.root?.visibility = View.VISIBLE
binding.loadingContent.visibility = View.GONE
binding.controllerGenericRv.root.visibility = View.VISIBLE
if (isNewConversationView) {
binding?.conversationPrivacyToggle?.callHeaderLayout?.visibility = View.VISIBLE
binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.VISIBLE
binding.callHeaderLayout.visibility = View.VISIBLE
binding.joinConversationViaLink.visibility = View.VISIBLE
}
}
}
Expand Down Expand Up @@ -715,7 +722,7 @@ class ContactsActivity :
adapter?.updateDataSet(contactItems as List<Nothing>?)
}

binding?.controllerGenericRv?.swipeRefreshLayout?.isEnabled = !adapter!!.hasFilter()
binding.controllerGenericRv?.swipeRefreshLayout?.isEnabled = !adapter!!.hasFilter()

return true
}
Expand Down Expand Up @@ -877,6 +884,11 @@ class ContactsActivity :
prepareAndShowBottomSheetWithBundle(bundle)
}

private fun listOpenConversations() {
val intent = Intent(this, ListOpenConversationsActivity::class.java)
startActivity(intent)
}

private fun toggleCallHeader() {
toggleConversationPrivacyLayout(isPublicCall)
isPublicCall = !isPublicCall
Expand Down Expand Up @@ -917,25 +929,25 @@ class ContactsActivity :

private fun toggleConversationPrivacyLayout(showInitialLayout: Boolean) {
if (showInitialLayout) {
binding?.conversationPrivacyToggle?.initialRelativeLayout?.visibility = View.VISIBLE
binding?.conversationPrivacyToggle?.secondaryRelativeLayout?.visibility = View.GONE
binding.initialRelativeLayout.visibility = View.VISIBLE
binding.secondaryRelativeLayout.visibility = View.GONE
} else {
binding?.conversationPrivacyToggle?.initialRelativeLayout?.visibility = View.GONE
binding?.conversationPrivacyToggle?.secondaryRelativeLayout?.visibility = View.VISIBLE
binding.initialRelativeLayout.visibility = View.GONE
binding.secondaryRelativeLayout.visibility = View.VISIBLE
}
}

private fun toggleConversationViaLinkVisibility(isPublicCall: Boolean) {
if (isPublicCall) {
binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.GONE
binding.joinConversationViaLink.visibility = View.GONE
updateGroupParticipantSelection()
} else {
binding?.joinConversationViaLink?.joinConversationViaLinkRelativeLayout?.visibility = View.VISIBLE
binding.joinConversationViaLink.visibility = View.VISIBLE
}
}

companion object {
const val TAG = "ContactsController"
private val TAG = ContactsActivity::class.simpleName
const val RETRIES: Long = 3
const val CONTACTS_BATCH_SIZE: Int = 50
const val HEADER_ELEVATION: Int = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository
import com.nextcloud.talk.data.storage.ArbitraryStoragesRepositoryImpl
import com.nextcloud.talk.data.user.UsersRepository
import com.nextcloud.talk.data.user.UsersRepositoryImpl
import com.nextcloud.talk.openconversations.data.OpenConversationsRepository
import com.nextcloud.talk.openconversations.data.OpenConversationsRepositoryImpl
import com.nextcloud.talk.polls.repositories.PollRepository
import com.nextcloud.talk.polls.repositories.PollRepositoryImpl
import com.nextcloud.talk.raisehand.RequestAssistanceRepository
Expand Down Expand Up @@ -110,6 +112,12 @@ class RepositoryModule {
return RequestAssistanceRepositoryImpl(ncApi, userProvider)
}

@Provides
fun provideOpenConversationsRepository(ncApi: NcApi, userProvider: CurrentUserProviderNew):
OpenConversationsRepository {
return OpenConversationsRepositoryImpl(ncApi, userProvider)
}

@Provides
fun translateRepository(ncApi: NcApi):
TranslateRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package com.nextcloud.talk.dagger.modules
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.nextcloud.talk.messagesearch.MessageSearchViewModel
import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel
import com.nextcloud.talk.polls.viewmodels.PollCreateViewModel
import com.nextcloud.talk.polls.viewmodels.PollMainViewModel
import com.nextcloud.talk.polls.viewmodels.PollResultsViewModel
Expand Down Expand Up @@ -107,4 +108,9 @@ abstract class ViewModelModule {
@IntoMap
@ViewModelKey(TranslateViewModel::class)
abstract fun translateViewModel(viewModel: TranslateViewModel): ViewModel

@Binds
@IntoMap
@ViewModelKey(OpenConversationsViewModel::class)
abstract fun openConversationsViewModelModel(viewModel: OpenConversationsViewModel): ViewModel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Nextcloud Talk application
*
* @author Marcel Hibbe
* Copyright (C) 2023 Marcel Hibbe <dev@mhibbe.de>
*
* 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.openconversations

import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import autodagger.AutoInjector
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.BaseActivity
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.databinding.ActivityOpenConversationsBinding
import com.nextcloud.talk.openconversations.data.OpenConversation
import com.nextcloud.talk.openconversations.viewmodels.OpenConversationsViewModel
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
import javax.inject.Inject

@AutoInjector(NextcloudTalkApplication::class)
class ListOpenConversationsActivity : BaseActivity() {

private lateinit var binding: ActivityOpenConversationsBinding

@Inject
lateinit var ncApi: NcApi

@Inject
lateinit var viewModelFactory: ViewModelProvider.Factory

@Inject
lateinit var userProvider: CurrentUserProviderNew

lateinit var openConversationsViewModel: OpenConversationsViewModel

lateinit var adapter: OpenConversationsAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)

openConversationsViewModel = ViewModelProvider(this, viewModelFactory)[OpenConversationsViewModel::class.java]

openConversationsViewModel.fetchConversations()

binding = ActivityOpenConversationsBinding.inflate(layoutInflater)
setupActionBar()
setContentView(binding.root)
setupSystemColors()

val user = userProvider.currentUser.blockingGet()

adapter = OpenConversationsAdapter(user) { conversation -> adapterOnClick(conversation) }
binding.openConversationsRecyclerView.adapter = adapter

initObservers()
}

private fun adapterOnClick(conversation: OpenConversation) {
val user = userProvider.currentUser.blockingGet()

val bundle = Bundle()
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, user)
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.roomToken)

val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(bundle)
chatIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(chatIntent)
}

private fun initObservers() {
openConversationsViewModel.viewState.observe(this) { state ->
when (state) {
is OpenConversationsViewModel.FetchConversationsStartState -> {
binding.openConversationsRecyclerView.visibility = View.GONE
binding.progressBarWrapper.visibility = View.VISIBLE
}
is OpenConversationsViewModel.FetchConversationsSuccessState -> {
binding.openConversationsRecyclerView.visibility = View.VISIBLE
binding.progressBarWrapper.visibility = View.GONE
adapter.submitList(state.conversations)
}
is OpenConversationsViewModel.FetchConversationsEmptyState -> {
binding.openConversationsRecyclerView.visibility = View.GONE
binding.progressBarWrapper.visibility = View.GONE

binding.emptyList.emptyListView.visibility = View.VISIBLE
binding.emptyList.emptyListViewHeadline.text = getString(R.string.nc_no_open_conversations_headline)
binding.emptyList.emptyListViewText.text = getString(R.string.nc_no_open_conversations_text)
binding.emptyList.emptyListIcon.setImageResource(R.drawable.baseline_info_24)
binding.emptyList.emptyListIcon.visibility = View.VISIBLE
binding.emptyList.emptyListViewText.visibility = View.VISIBLE
}
is OpenConversationsViewModel.FetchConversationsErrorState -> {
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
}
else -> {}
}
}
}

private fun setupActionBar() {
setSupportActionBar(binding.openConversationsToolbar)
binding.openConversationsToolbar.setNavigationOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setIcon(ColorDrawable(resources!!.getColor(R.color.transparent, null)))
viewThemeUtils.material.themeToolbar(binding.openConversationsToolbar)
}
}
Loading

0 comments on commit fa36181

Please sign in to comment.