Skip to content

Commit

Permalink
Avoid to send conversation and user via intent
Browse files Browse the repository at this point in the history
sending too much data via intent always is a bad pattern which can lead to TransactionTooLargeException.

When OpenAI translation is enabled, the capabilities contain a ton of translation combinations. These capabilities are contained in 'currentUser' as well in 'selectedConversation'. So, TransactionTooLargeException was thrown.

this PR:
- avoids passing too much data as parcelables in intents (esp. conversation and user)
- introduces MVVM patterns to load required data (esp conversation) from backend (for now via requests, in the future from database first)
- introduces ConversationModel which is created out of the Conversation json model
- loads user data via injection when possible
- creates some quickfixes in ConversationBottomDialog, EntryMenuController and OperationsMenuController.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
  • Loading branch information
mahibi committed Jun 29, 2023
1 parent fa5e0fb commit c9d5477
Show file tree
Hide file tree
Showing 42 changed files with 1,453 additions and 868 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
android:theme="@style/AppTheme.CallLauncher" />

<activity
android:name=".activities.CallNotificationActivity"
android:name=".callnotification.CallNotificationActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:excludeFromRecents="true"
android:launchMode="singleTask"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import com.nextcloud.talk.utils.VibrationUtils;
import com.nextcloud.talk.utils.animations.PulseAnimation;
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew;
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil;
import com.nextcloud.talk.utils.power.PowerManagerUtils;
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
Expand Down Expand Up @@ -186,7 +187,6 @@
import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN;
import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH;
import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM;
import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY;

@AutoInjector(NextcloudTalkApplication.class)
public class CallActivity extends CallBaseActivity {
Expand All @@ -199,6 +199,9 @@ public class CallActivity extends CallBaseActivity {
@Inject
NcApi ncApi;

@Inject
CurrentUserProviderNew currentUserProvider;

@Inject
UserManager userManager;

Expand Down Expand Up @@ -386,10 +389,11 @@ public void onCreate(Bundle savedInstanceState) {

hideNavigationIfNoPipAvailable();

conversationUser = currentUserProvider.getCurrentUser().blockingGet();

Bundle extras = getIntent().getExtras();
roomId = extras.getString(KEY_ROOM_ID, "");
roomToken = extras.getString(KEY_ROOM_TOKEN, "");
conversationUser = extras.getParcelable(KEY_USER_ENTITY);
conversationPassword = extras.getString(KEY_CONVERSATION_PASSWORD, "");
conversationName = extras.getString(KEY_CONVERSATION_NAME, "");
isVoiceOnlyCall = extras.getBoolean(KEY_CALL_VOICE_ONLY, false);
Expand Down Expand Up @@ -1970,7 +1974,6 @@ public void onNext(@io.reactivex.annotations.NonNull GenericOverall genericOvera
bundle.putBoolean(KEY_SWITCH_TO_ROOM, true);
bundle.putBoolean(KEY_START_CALL_AFTER_ROOM_SWITCH, true);
bundle.putString(KEY_ROOM_TOKEN, switchToRoomToken);
bundle.putParcelable(KEY_USER_ENTITY, conversationUser);
bundle.putBoolean(KEY_CALL_VOICE_ONLY, isVoiceOnlyCall);
intent.putExtras(bundle);
startActivity(intent);
Expand Down Expand Up @@ -3151,7 +3154,7 @@ public void updateUiForNormalMode() {
}

@Override
void suppressFitsSystemWindows() {
public void suppressFitsSystemWindows() {
binding.controllerCallLayout.setFitsSystemWindows(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onCreate(Bundle savedInstanceState) {
getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
}

void hideNavigationIfNoPipAvailable(){
public void hideNavigationIfNoPipAvailable(){
if (!isPipModePossible()) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
Expand Down Expand Up @@ -160,9 +160,9 @@ boolean isGreaterEqualOreo(){
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}

abstract void updateUiForPipMode();
public abstract void updateUiForPipMode();

abstract void updateUiForNormalMode();
public abstract void updateUiForNormalMode();

abstract void suppressFitsSystemWindows();
public abstract void suppressFitsSystemWindows();
}
47 changes: 7 additions & 40 deletions app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.callnotification.CallNotificationActivity
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.controllers.ServerSelectionController
import com.nextcloud.talk.controllers.WebViewLoginController
Expand All @@ -61,16 +62,13 @@ import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.SecurityUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.bundle.BundleKeys.ADD_ACCOUNT
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
import io.reactivex.Observer
import io.reactivex.SingleObserver
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import org.parceler.Parcels
import javax.inject.Inject

@AutoInjector(NextcloudTalkApplication::class)
Expand Down Expand Up @@ -282,45 +280,12 @@ class MainActivity : BaseActivity(), ActionBarProvider {

override fun onNext(roomOverall: RoomOverall) {
val bundle = Bundle()
bundle.putParcelable(KEY_USER_ENTITY, currentUser)
bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs!!.data!!.token)
bundle.putString(KEY_ROOM_ID, roomOverall.ocs!!.data!!.roomId)

// FIXME once APIv2 or later is used only, the createRoom already returns all the data
ncApi.getRoom(
credentials,
ApiUtils.getUrlForRoom(
apiVersion,
currentUser?.baseUrl,
roomOverall.ocs!!.data!!.token
)
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<RoomOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}

override fun onNext(roomOverall: RoomOverall) {
bundle.putParcelable(
KEY_ACTIVE_CONVERSATION,
Parcels.wrap(roomOverall.ocs!!.data)
)

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

override fun onError(e: Throwable) {
// unused atm
}

override fun onComplete() {
// unused atm
}
})
val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(bundle)
startActivity(chatIntent)
}

override fun onError(e: Throwable) {
Expand All @@ -337,7 +302,9 @@ class MainActivity : BaseActivity(), ActionBarProvider {
super.onNewIntent(intent)
Log.d(TAG, "onNewIntent Activity: " + System.identityHashCode(this).toString())

val user = intent.getParcelableExtra<User>(KEY_USER_ENTITY)
val internalUserId = intent.extras?.getLong(BundleKeys.KEY_INTERNAL_USER_ID)
val user = userManager.getUserWithId(internalUserId!!).blockingGet()

if (user != null && userManager.setUserAsActive(user).blockingGet()) {
handleIntent(intent)
}
Expand Down
Loading

0 comments on commit c9d5477

Please sign in to comment.