From 7b39ea8a6e818953ff3bb00ca316b2ccf0224e1d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 26 Jun 2023 15:20:34 +0200 Subject: [PATCH] WIP. add MVVM's & load stuff from repos to avoid passing too big bundles. Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/chat/ChatActivity.kt | 138 +----------------- .../talk/chat/data/ChatRepositoryImpl.kt | 7 +- .../ConversationsListActivity.kt | 11 -- .../talk/data/source/local/TalkDatabase.kt | 3 +- .../ListOpenConversationsActivity.kt | 3 - 5 files changed, 12 insertions(+), 150 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index d557776fe52..c1abfa40fe1 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -130,6 +130,7 @@ import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.callbacks.MentionAutocompleteCallback import com.nextcloud.talk.chat.data.ChatRepository +import com.nextcloud.talk.chat.data.ChatRepositoryImpl import com.nextcloud.talk.chat.viewmodels.ChatViewModel import com.nextcloud.talk.conversationinfo.ConversationInfoActivity import com.nextcloud.talk.conversationlist.ConversationsListActivity @@ -395,7 +396,6 @@ class ChatActivity : handleIntent(intent) chatViewModel = ViewModelProvider(this, viewModelFactory)[ChatViewModel::class.java] - // chatViewModel.getRoom(conversationUser!!, roomToken) binding.progressBar.visibility = View.VISIBLE @@ -436,11 +436,6 @@ class ChatActivity : Log.d(TAG, " roomToken was null or empty!") } - // if (intent.hasExtra(KEY_ACTIVE_CONVERSATION)) { - // currentConversation = Parcels.unwrap(extras?.getParcelable(KEY_ACTIVE_CONVERSATION)) - // participantPermissions = ParticipantPermissions(conversationUser!!, currentConversation!!) - // } - roomPassword = extras?.getString(BundleKeys.KEY_CONVERSATION_PASSWORD).orEmpty() credentials = if (conversationUser?.userId == "?") { @@ -594,7 +589,6 @@ class ChatActivity : cancelNotificationsForCurrentConversation() - // getRoomInfo() // remove chatViewModel.getRoom(conversationUser!!, roomToken) actionBar?.show() @@ -1186,68 +1180,6 @@ class ChatActivity : !CapabilitiesUtilNew.isTypingStatusPrivate(conversationUser!!) } - // private fun getRoomInfo() { - // logConversationInfos("getRoomInfo") - // - // conversationUser?.let { - // val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1)) - // - // val startNanoTime = System.nanoTime() - // Log.d(TAG, "getRoomInfo - getRoom - calling: $startNanoTime") - // ncApi.getRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, it.baseUrl, roomToken)) - // ?.subscribeOn(Schedulers.io()) - // ?.observeOn(AndroidSchedulers.mainThread()) - // ?.subscribe(object : Observer { - // override fun onSubscribe(d: Disposable) { - // disposables.add(d) - // } - // - // @Suppress("Detekt.TooGenericExceptionCaught") - // override fun onNext(roomOverall: RoomOverall) { - // Log.d(TAG, "getRoomInfo - getRoom - got response: $startNanoTime") - // currentConversation = roomOverall.ocs!!.data - // - // logConversationInfos("getRoomInfo#onNext") - // - // loadAvatarForStatusBar() - // setActionBarTitle() - // participantPermissions = ParticipantPermissions(it, currentConversation!!) - // - // setupSwipeToReply() - // setupMentionAutocomplete() - // checkShowCallButtons() - // checkShowMessageInputView() - // checkLobbyState() - // - // if (!validSessionId()) { - // joinRoomWithPassword() - // } else { - // Log.d(TAG, "already inConversation. joinRoomWithPassword is skipped") - // } - // } - // - // override fun onError(e: Throwable) { - // Log.e(TAG, "getRoomInfo - getRoom - ERROR", e) - // } - // - // override fun onComplete() { - // Log.d(TAG, "getRoomInfo - getRoom - onComplete: $startNanoTime") - // - // val delayForRecursiveCall = if (shouldShowLobby()) { - // GET_ROOM_INFO_DELAY_LOBBY - // } else { - // GET_ROOM_INFO_DELAY_NORMAL - // } - // - // if (getRoomInfoTimerHandler == null) { - // getRoomInfoTimerHandler = Handler() - // } - // getRoomInfoTimerHandler?.postDelayed({ getRoomInfo() }, delayForRecursiveCall) - // } - // }) - // } - // } - private fun setupSwipeToReply() { if (this::participantPermissions.isInitialized && participantPermissions.hasChatPermission() && @@ -2346,66 +2278,6 @@ class ChatActivity : Log.d(TAG, "joinRoomWithPassword - joinRoom - calling: $startNanoTime") chatViewModel.joinRoom(conversationUser!!, roomToken, roomPassword) - - // ncApi.joinRoom( - // credentials, - // ApiUtils.getUrlForParticipantsActive(apiVersion, conversationUser?.baseUrl, roomToken), - // roomPassword - // ) - // ?.subscribeOn(Schedulers.io()) - // ?.observeOn(AndroidSchedulers.mainThread()) - // ?.retry(RETRIES) - // ?.subscribe(object : Observer { - // override fun onSubscribe(d: Disposable) { - // disposables.add(d) - // } - // - // @Suppress("Detekt.TooGenericExceptionCaught") - // override fun onNext(roomOverall: RoomOverall) { - // Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: $startNanoTime") - // - // val conversation = roomOverall.ocs!!.data!! - // currentConversation = conversation - // - // sessionIdAfterRoomJoined = conversation.sessionId - // ApplicationWideCurrentRoomHolder.getInstance().session = conversation.sessionId - // ApplicationWideCurrentRoomHolder.getInstance().currentRoomId = conversation.roomId - // ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken = conversation.token - // ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser - // - // logConversationInfos("joinRoomWithPassword#onNext") - // - // if (isFirstMessagesProcessing) { - // pullChatMessages(false) - // } else { - // pullChatMessages(true, false) - // } - // - // if (webSocketInstance != null) { - // webSocketInstance?.joinRoomWithRoomTokenAndSession( - // roomToken!!, - // sessionIdAfterRoomJoined - // ) - // } - // if (startCallFromNotification != null && startCallFromNotification ?: false) { - // startCallFromNotification = false - // startACall(voiceOnly, false) - // } - // - // if (startCallFromRoomSwitch) { - // startCallFromRoomSwitch = false - // startACall(voiceOnly, true) - // } - // } - // - // override fun onError(e: Throwable) { - // Log.e(TAG, "joinRoomWithPassword - joinRoom - ERROR", e) - // } - // - // override fun onComplete() { - // // unused atm - // } - // }) } else { Log.d(TAG, "sessionID was valid -> skip joinRoom") @@ -3753,8 +3625,12 @@ class ChatActivity : // TODO: change return type of createRoom to ConversationModel. // TODO: move createRoom to ChatRepository - // bundle.putBoolean(KEY_IS_MODERATOR, - // ConversationUtils.isParticipantOwnerOrModerator(roomOverall.ocs!!.data!!)) + bundle.putBoolean( + KEY_IS_MODERATOR, + ConversationUtils.isParticipantOwnerOrModerator( + ChatRepositoryImpl.mapToConversationModel(roomOverall.ocs!!.data!!) + ) + ) if (conversationUser != null) { bundle.putParcelable( diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/ChatRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/chat/data/ChatRepositoryImpl.kt index 0630a15a29b..445b63c403f 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/ChatRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/ChatRepositoryImpl.kt @@ -27,10 +27,6 @@ import com.nextcloud.talk.utils.ApiUtils import io.reactivex.Observable class ChatRepositoryImpl(private val ncApi: NcApi) : ChatRepository { - - // val currentUser: User = currentUserProvider.currentUser.blockingGet() - // val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token) - override fun getRoom( user: User, roomToken: String @@ -60,6 +56,9 @@ class ChatRepositoryImpl(private val ncApi: NcApi) : ChatRepository { } companion object { + + // TODO: only use this method inside ChatRepositoryImpl. For now, it might be temporarily used outside for + // conversions. fun mapToConversationModel( conversation: Conversation ): ChatRepository.ConversationModel { diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index a2762ac241b..015721334b0 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -40,7 +40,6 @@ import android.net.Uri import android.os.Build import android.os.Bundle import android.os.Handler -import android.os.Parcel import android.text.InputType import android.text.TextUtils import android.util.Log @@ -1192,8 +1191,6 @@ class ConversationsListActivity : selectedMessageId = null } - Log.d(TAG, "bundle size: " + getBundleSizeInBytes(bundle)) - val intent = Intent(context, ChatActivity::class.java) intent.putExtras(bundle) startActivity(intent) @@ -1201,14 +1198,6 @@ class ConversationsListActivity : clearIntentAction() } - fun getBundleSizeInBytes(bundle: Bundle?): Int { - val parcel: Parcel = Parcel.obtain() - parcel.writeBundle(bundle) - val size: Int = parcel.dataSize() - parcel.recycle() - return size - } - @Subscribe(sticky = true, threadMode = ThreadMode.BACKGROUND) fun onMessageEvent(eventStatus: EventStatus) { if (currentUser != null && eventStatus.userId == currentUser!!.id) { diff --git a/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt b/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt index 78e3eecd2c8..de64a74d328 100644 --- a/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt +++ b/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt @@ -94,7 +94,8 @@ abstract class TalkDatabase : RoomDatabase() { return Room .databaseBuilder(context.applicationContext, TalkDatabase::class.java, dbName) - // .openHelperFactory(factory) + // comment out openHelperFactory to view the database entries in Android Studio for debugging + .openHelperFactory(factory) .addMigrations(Migrations.MIGRATION_6_8, Migrations.MIGRATION_7_8) .allowMainThreadQueries() .addCallback( diff --git a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt index 5632831bfa5..6f1eefd8309 100644 --- a/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/openconversations/ListOpenConversationsActivity.kt @@ -79,10 +79,7 @@ class ListOpenConversationsActivity : BaseActivity() { } 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)