Skip to content

Commit

Permalink
MBL-1876: Firebase crashes Caused by android.os.TransactionTooLargeEx…
Browse files Browse the repository at this point in the history
…ception (#2171)

(cherry picked from commit f63ea03)
  • Loading branch information
leighdouglas authored and Arkariang committed Nov 16, 2024
1 parent 2fef312 commit 8cc01e7
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,14 @@ fun Project.reduce(): Project {
* The end goal is to reduce to the bare minimum the amount of memory required to be serialized on Intents
* when presenting screens in order to avoid `android.os.TransactionTooLargeException`
*/
fun Project.reduceToPreLaunchProject(): Project {
fun Project.reduceProjectPayload(): Project {
val web = Web.builder()
.project(this.webProjectUrl())
.build()

return Project.Builder()
.id(this.id())
.canComment(this.canComment())
.slug(this.slug())
.name(this.name())
.creator(this.creator())
Expand All @@ -331,9 +332,14 @@ fun Project.reduceToPreLaunchProject(): Project {
.currentCurrency(this.currentCurrency())
.sendThirdPartyEvents(this.sendThirdPartyEvents())
.isStarred(this.isStarred())
.isBacking(this.isBacking())
.currency(this.currency())
.currencySymbol(this.currencySymbol())
.currencyTrailingCode(this.currencyTrailingCode())
.urls(Urls.builder().web(web).build())
.isInPostCampaignPledgingPhase(this.isInPostCampaignPledgingPhase())
.postCampaignPledgingEnabled(this.postCampaignPledgingEnabled())
.sendThirdPartyEvents(this.sendThirdPartyEvents())
.state(this.state())
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.kickstarter.libs.utils.TransitionUtils
import com.kickstarter.libs.utils.UrlUtils
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.reduceProjectPayload
import com.kickstarter.libs.utils.extensions.showAlertDialog
import com.kickstarter.libs.utils.extensions.toVisibility
import com.kickstarter.models.Comment
Expand Down Expand Up @@ -302,8 +303,9 @@ class CommentsActivity :
* // TODO: https://kickstarter.atlassian.net/browse/NT-1955
*/
private fun startThreadActivity(commentData: CommentCardData, openKeyboard: Boolean, projectUpdateId: String? = null) {
val reducedProject = commentData.project?.reduceProjectPayload()
val threadIntent = Intent(this, ThreadActivity::class.java).apply {
putExtra(IntentKey.COMMENT_CARD_DATA, commentData)
putExtra(IntentKey.COMMENT_CARD_DATA, commentData.toBuilder().project(reducedProject).build())
putExtra(IntentKey.REPLY_EXPAND, openKeyboard)
putExtra(IntentKey.UPDATE_POST_ID, projectUpdateId)
}
Expand All @@ -315,8 +317,9 @@ class CommentsActivity :
}

private fun startThreadActivityFromDeepLink(commentData: CommentCardData, projectUpdateId: String? = null) {
val reducedProject = commentData.project?.reduceProjectPayload()
val threadIntent = Intent(this, ThreadActivity::class.java).apply {
putExtra(IntentKey.COMMENT_CARD_DATA, commentData)
putExtra(IntentKey.COMMENT_CARD_DATA, commentData.toBuilder().project(reducedProject).build())
putExtra(IntentKey.REPLY_EXPAND, false)
putExtra(IntentKey.REPLY_SCROLL_BOTTOM, true)
putExtra(IntentKey.UPDATE_POST_ID, projectUpdateId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kickstarter.ui.activities

import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
Expand All @@ -16,14 +15,13 @@ import com.kickstarter.libs.KSString
import com.kickstarter.libs.featureflag.FlagKey
import com.kickstarter.libs.utils.ViewUtils
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.libs.utils.extensions.getCreatorBioWebViewActivityIntent
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.models.Project
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.SharedPreferenceKey
import com.kickstarter.ui.activities.compose.PreLaunchProjectPageScreen
import com.kickstarter.ui.compose.designsystem.KickstarterApp
import com.kickstarter.ui.data.LoginReason
import com.kickstarter.ui.extensions.startCreatorBioWebViewActivity
import com.kickstarter.viewmodels.projectpage.PrelaunchProjectViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand Down Expand Up @@ -144,11 +142,6 @@ class PreLaunchProjectPageActivity : ComponentActivity() {
startActivityForResult(intent, ActivityRequestCodes.LOGIN_FLOW)
}

fun Activity.startCreatorBioWebViewActivity(project: Project) {
startActivity(Intent().getCreatorBioWebViewActivityIntent(this, project))
overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left)
}

@Override
override fun onDestroy() {
compositeDisposable.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.kickstarter.libs.utils.ViewUtils
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.getPaymentSheetConfiguration
import com.kickstarter.libs.utils.extensions.reduceProjectPayload
import com.kickstarter.libs.utils.extensions.showLatePledgeFlow
import com.kickstarter.libs.utils.extensions.toVisibility
import com.kickstarter.models.Project
Expand Down Expand Up @@ -1065,7 +1066,7 @@ class ProjectPageActivity :
if (clearFragmentBackStack() || (projectData.project().showLatePledgeFlow() && fFLatePledge)) {
startActivity(
Intent(this, ThanksActivity::class.java)
.putExtra(IntentKey.PROJECT, projectData.project())
.putExtra(IntentKey.PROJECT, projectData.project().reduceProjectPayload())
.putExtra(IntentKey.CHECKOUT_DATA, checkoutData)
.putExtra(IntentKey.PLEDGE_DATA, pledgeData)
)
Expand Down Expand Up @@ -1135,7 +1136,7 @@ class ProjectPageActivity :
startActivity(
Intent(this, MessagesActivity::class.java)
.putExtra(IntentKey.MESSAGE_SCREEN_SOURCE_CONTEXT, MessagePreviousScreenType.PROJECT_PAGE)
.putExtra(IntentKey.PROJECT, project)
.putExtra(IntentKey.PROJECT, project.reduceProjectPayload())
.putExtra(IntentKey.BACKING, project.backing())
)
}
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/kickstarter/ui/extensions/ActivityExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.kickstarter.libs.utils.extensions.getReportProjectActivityIntent
import com.kickstarter.libs.utils.extensions.getRootCommentsActivityIntent
import com.kickstarter.libs.utils.extensions.getUpdatesActivityIntent
import com.kickstarter.libs.utils.extensions.getVideoActivityIntent
import com.kickstarter.libs.utils.extensions.reduceToPreLaunchProject
import com.kickstarter.libs.utils.extensions.reduceProjectPayload
import com.kickstarter.libs.utils.extensions.withData
import com.kickstarter.models.Project
import com.kickstarter.models.chrome.ChromeTabsHelperActivity
Expand Down Expand Up @@ -168,8 +168,9 @@ fun Activity.startPledgeRedemption(project: Project) {
* @param commentableId -> specific for deeplinking to a concrete thread
*/
fun Activity.startRootCommentsActivity(projectData: ProjectData, commentableId: String? = null) {
val reducedProject = projectData.project().reduceProjectPayload()
startActivity(
Intent().getRootCommentsActivityIntent(this, projectData, commentableId)
Intent().getRootCommentsActivityIntent(this, projectData.toBuilder().project(reducedProject).build(), commentableId)
)

this.let {
Expand All @@ -185,12 +186,12 @@ fun Activity.startReportProjectActivity(
project: Project,
startForResult: ActivityResultLauncher<Intent>
) {
startForResult.launch(Intent().getReportProjectActivityIntent(this, project = project))
startForResult.launch(Intent().getReportProjectActivityIntent(this, project = project.reduceProjectPayload()))
overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left)
}

fun Activity.startCreatorBioWebViewActivity(project: Project) {
startActivity(Intent().getCreatorBioWebViewActivityIntent(this, project))
startActivity(Intent().getCreatorBioWebViewActivityIntent(this, project.reduceProjectPayload()))
overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left)
}

Expand Down Expand Up @@ -235,7 +236,8 @@ fun Activity.startUpdatesActivity(
* @param projectAndData
*/
fun Activity.startProjectUpdatesActivity(projectAndData: ProjectData) {
startActivity(Intent().getProjectUpdatesActivityIntent(this, projectAndData))
val reducedProject = projectAndData.project().reduceProjectPayload()
startActivity(Intent().getProjectUpdatesActivityIntent(this, projectAndData.toBuilder().project(reducedProject).build()))
overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left)
}

Expand All @@ -259,7 +261,7 @@ fun Activity.startPreLaunchProjectActivity(uri: Uri, project: Project, previousS
val intent = Intent().getPreLaunchProjectActivity(
this,
project.slug(),
project.reduceToPreLaunchProject()
project.reduceProjectPayload()
)
// Pass full deeplink for attribution tracking purposes when launching from deeplink
intent.setData(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.kickstarter.libs.MessagePreviousScreenType
import com.kickstarter.libs.SimpleDividerItemDecoration
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.reduceProjectPayload
import com.kickstarter.models.Project
import com.kickstarter.ui.ArgumentsKey
import com.kickstarter.ui.IntentKey
Expand Down Expand Up @@ -120,7 +121,7 @@ class FrequentlyAskedQuestionFragment : Fragment(), Configure {
startActivity(
Intent(requireContext(), MessagesActivity::class.java)
.putExtra(IntentKey.MESSAGE_SCREEN_SOURCE_CONTEXT, MessagePreviousScreenType.CREATOR_BIO_MODAL)
.putExtra(IntentKey.PROJECT, project)
.putExtra(IntentKey.PROJECT, project.reduceProjectPayload())
.putExtra(IntentKey.BACKING, project.backing())
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class ProjectExtTest : KSRobolectricTestCase() {
val user = UserFactory.germanUser().toBuilder().chosenCurrency("CAD").build()
val deadline = DateTime(DateTimeZone.UTC).plusDays(10)
val project = ProjectFactory.project().toBuilder().watchesCount(10).isStarred(true).creator(user).build()
val reducedProject = project.reduceToPreLaunchProject().toBuilder().deadline(deadline).build()
val reducedProject = project.reduceProjectPayload().toBuilder().deadline(deadline).build()

assertEquals(project.id(), reducedProject.id())
assertEquals(project.name(), reducedProject.name())
Expand Down
Loading

0 comments on commit 8cc01e7

Please sign in to comment.