WIP UI fixes for offline conversations - next up get queued messges to work and show up as temp messages ( I have some creative ideas for the UI )
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
Родитель
aa76636f72
Коммит
db8d7b91d4
|
@ -657,9 +657,7 @@ class ChatActivity :
|
|||
}
|
||||
}
|
||||
|
||||
is ChatViewModel.JoinRoomErrorState -> {
|
||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
is ChatViewModel.JoinRoomErrorState -> {}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
|
@ -812,7 +810,6 @@ class ChatActivity :
|
|||
) {
|
||||
adapter?.clear()
|
||||
adapter?.notifyDataSetChanged()
|
||||
// TODO: remove messages from DB, Should be handled beforehand (in viewModel?)
|
||||
}
|
||||
|
||||
if (lookIntoFuture) {
|
||||
|
|
|
@ -175,6 +175,8 @@ class MessageInputFragment : Fragment() {
|
|||
wasOnline = !binding.fragmentMessageInputView.isShown
|
||||
Log.d(TAG, "isOnline: $isOnline\nwasOnline: $wasOnline\nconnectionGained: $connectionGained")
|
||||
|
||||
// FIXME I think this might be called when remote server is null, because I joined when no internet
|
||||
// thus room not joined. I would need to make sure that the room is joined before I send messages
|
||||
handleMessageQueue(isOnline)
|
||||
handleUI(isOnline, connectionGained)
|
||||
}.collect()
|
||||
|
|
|
@ -322,6 +322,7 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||
val result = network.pullChatMessages(credentials, urlForChatting, fieldMap)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
// .timeout(3, TimeUnit.SECONDS)
|
||||
.map {
|
||||
when (it.code()) {
|
||||
HTTP_CODE_OK -> {
|
||||
|
|
|
@ -81,6 +81,7 @@ import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager
|
|||
import com.nextcloud.talk.chat.ChatActivity
|
||||
import com.nextcloud.talk.contacts.ContactsActivityCompose
|
||||
import com.nextcloud.talk.conversationlist.viewmodels.ConversationsListViewModel
|
||||
import com.nextcloud.talk.data.network.NetworkMonitor
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.databinding.ActivityConversationsBinding
|
||||
import com.nextcloud.talk.events.ConversationsListFetchDataEvent
|
||||
|
@ -106,7 +107,6 @@ import com.nextcloud.talk.utils.BrandingUtils
|
|||
import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil.isServerEOL
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil.isUnifiedSearchAvailable
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil.isUserStatusAvailable
|
||||
import com.nextcloud.talk.utils.ClosedInterfaceImpl
|
||||
import com.nextcloud.talk.utils.ConversationUtils
|
||||
import com.nextcloud.talk.utils.FileUtils
|
||||
|
@ -173,6 +173,9 @@ class ConversationsListActivity :
|
|||
@Inject
|
||||
lateinit var viewModelFactory: ViewModelProvider.Factory
|
||||
|
||||
@Inject
|
||||
lateinit var networkMonitor: NetworkMonitor
|
||||
|
||||
lateinit var conversationsListViewModel: ConversationsListViewModel
|
||||
|
||||
override val appBarLayoutType: AppBarLayoutType
|
||||
|
@ -300,6 +303,12 @@ class ConversationsListActivity :
|
|||
}
|
||||
|
||||
private fun initObservers() {
|
||||
this.lifecycleScope.launch {
|
||||
networkMonitor.isOnline.onEach { isOnline ->
|
||||
showNetworkErrorDialog(!isOnline)
|
||||
}.collect()
|
||||
}
|
||||
|
||||
conversationsListViewModel.getFederationInvitationsViewState.observe(this) { state ->
|
||||
when (state) {
|
||||
is ConversationsListViewModel.GetFederationInvitationsStartState -> {
|
||||
|
@ -315,7 +324,9 @@ class ConversationsListActivity :
|
|||
}
|
||||
|
||||
is ConversationsListViewModel.GetFederationInvitationsErrorState -> {
|
||||
Snackbar.make(binding.root, R.string.get_invitations_error, Snackbar.LENGTH_LONG).show()
|
||||
if (isNetworkAvailable(context)) {
|
||||
Snackbar.make(binding.root, R.string.get_invitations_error, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
|
@ -731,72 +742,7 @@ class ConversationsListActivity :
|
|||
}
|
||||
|
||||
fun fetchRooms() {
|
||||
val includeStatus = isUserStatusAvailable(currentUser!!)
|
||||
conversationsListViewModel.getRooms()
|
||||
|
||||
// checks internet connection before fetching rooms
|
||||
if (isNetworkAvailable(context)) {
|
||||
// Log.d(TAG, "Internet connection available")
|
||||
// dispose(null)
|
||||
// isRefreshing = true
|
||||
// conversationItems = ArrayList()
|
||||
// conversationItemsWithHeader = ArrayList()
|
||||
// val apiVersion = ApiUtils.getConversationApiVersion(
|
||||
// currentUser!!,
|
||||
// intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)
|
||||
// )
|
||||
// val startNanoTime = System.nanoTime()
|
||||
// Log.d(TAG, "fetchData - getRooms - calling: $startNanoTime")
|
||||
// roomsQueryDisposable = ncApi.getRooms(
|
||||
// credentials,
|
||||
// ApiUtils.getUrlForRooms(
|
||||
// apiVersion,
|
||||
// currentUser!!.baseUrl
|
||||
// ),
|
||||
// includeStatus
|
||||
// )
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe({ (ocs): RoomsOverall ->
|
||||
// Log.d(TAG, "fetchData - getRooms - got response: $startNanoTime")
|
||||
//
|
||||
// // This is invoked asynchronously, when server returns a response the view might have been
|
||||
// // unbound in the meantime. Check if the view is still there.
|
||||
// // FIXME - does it make sense to update internal data structures even when view has been unbound?
|
||||
// // if (view == null) {
|
||||
// // Log.d(TAG, "fetchData - getRooms - view is not bound: $startNanoTime")
|
||||
// // return@subscribe
|
||||
// // }
|
||||
//
|
||||
// if (adapterWasNull) {
|
||||
// adapterWasNull = false
|
||||
// binding?.loadingContent?.visibility = View.GONE
|
||||
// }
|
||||
// initOverallLayout(ocs!!.data!!.isNotEmpty())
|
||||
// for (conversation in ocs.data!!) {
|
||||
// addToConversationItems(conversation)
|
||||
// }
|
||||
// sortConversations(conversationItems)
|
||||
// sortConversations(conversationItemsWithHeader)
|
||||
// if (!filterState.containsValue(true)) filterableConversationItems = conversationItems
|
||||
// filterConversation()
|
||||
// adapter!!.updateDataSet(filterableConversationItems, false)
|
||||
// Handler().postDelayed({ checkToShowUnreadBubble() }, UNREAD_BUBBLE_DELAY.toLong())
|
||||
// fetchOpenConversations(apiVersion)
|
||||
// binding?.swipeRefreshLayoutView?.isRefreshing = false
|
||||
// }, { throwable: Throwable ->
|
||||
// handleHttpExceptions(throwable)
|
||||
// binding?.swipeRefreshLayoutView?.isRefreshing = false
|
||||
// dispose(roomsQueryDisposable)
|
||||
// }) {
|
||||
// dispose(roomsQueryDisposable)
|
||||
// binding?.swipeRefreshLayoutView?.isRefreshing = false
|
||||
// isRefreshing = false
|
||||
// }
|
||||
} else {
|
||||
Log.d(TAG, "No internet connection detected")
|
||||
showNetworkErrorDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchPendingInvitations() {
|
||||
|
@ -902,31 +848,8 @@ class ConversationsListActivity :
|
|||
}
|
||||
}
|
||||
|
||||
private fun showNetworkErrorDialog() {
|
||||
binding.floatingActionButton.let {
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(it.context)
|
||||
.setIcon(
|
||||
viewThemeUtils.dialog.colorMaterialAlertDialogIcon(
|
||||
context,
|
||||
R.drawable.ic_baseline_error_outline_24dp
|
||||
)
|
||||
)
|
||||
.setTitle(R.string.nc_check_your_internet)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(R.string.close, null)
|
||||
.setNeutralButton(R.string.nc_refresh) { _, _ ->
|
||||
fetchRooms()
|
||||
fetchPendingInvitations()
|
||||
}
|
||||
|
||||
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(it.context, dialogBuilder)
|
||||
val dialog = dialogBuilder.show()
|
||||
viewThemeUtils.platform.colorTextButtons(
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE),
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE),
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
)
|
||||
}
|
||||
private fun showNetworkErrorDialog(show: Boolean) {
|
||||
binding.chatListConnectionLost.visibility = if (show) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
|
|
|
@ -26,6 +26,17 @@
|
|||
app:liftOnScrollTargetViewId="@id/recycler_view"
|
||||
app:liftOnScrollColor="@color/bg_default">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/chat_list_connection_lost"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/connection_lost"
|
||||
android:textColor="@color/white"
|
||||
android:background="@color/hwSecurityRed"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/search_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -803,4 +803,5 @@ How to translate with transifex:
|
|||
<string name="ban">Ban</string>
|
||||
<string name="show_ban_reason">Show ban reason</string>
|
||||
<string name="error_unbanning">Error occurred when unbanning participant</string>
|
||||
<string name="connection_lost">Connection Lost</string>
|
||||
</resources>
|
||||
|
|
Загрузка…
Ссылка в новой задаче