Skip to content

Commit

Permalink
→ Moves: the logic of launching media activities
Browse files Browse the repository at this point in the history
- Removes: the logic of launching media from ActivityLauncher.java
+ Adds: the logic of launching media in ActivityNavigator.kt
↑ Updates: the logic in DeepLinkNavigator to use ActivityNavigator.kt
  • Loading branch information
AjeshRPai committed Dec 13, 2023
1 parent a0d27d1 commit 61fc769
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -695,28 +695,6 @@ public static void viewCurrentBlogMedia(Context context, SiteModel site) {
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.OPENED_MEDIA_LIBRARY, site);
}

public static void openMediaInNewStack(@NonNull Context context, SiteModel site) {
if (site == null) {
ToastUtils.showToast(context, R.string.media_cannot_be_started, ToastUtils.Duration.SHORT);
return;
}
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.OPENED_MEDIA_LIBRARY, site);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
Intent mainActivityIntent = getMainActivityInNewStack(context);
Intent intent = new Intent(context, MediaBrowserActivity.class);
intent.putExtra(WordPress.SITE, site);
taskStackBuilder.addNextIntent(mainActivityIntent);
taskStackBuilder.addNextIntent(intent);
taskStackBuilder.startActivities();
}

public static void openMediaInNewStack(@NonNull Context context) {
AnalyticsTracker.track(AnalyticsTracker.Stat.OPENED_MEDIA_LIBRARY);
Intent intent = getMainActivityInNewStack(context);
intent.putExtra(WPMainActivity.ARG_OPEN_PAGE, WPMainActivity.ARG_MEDIA);
context.startActivity(intent);
}

public static void viewCurrentBlogPages(@NonNull Context context, @NonNull SiteModel site) {
Intent intent = new Intent(context, PagesActivity.class);
intent.putExtra(WordPress.SITE, site);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.wordpress.android.ui

import android.content.Context
import android.content.Intent
import androidx.core.app.TaskStackBuilder
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.fluxc.model.SiteModel
Expand All @@ -18,12 +20,14 @@ import org.wordpress.android.ui.domains.management.purchasedomain.PurchaseDomain
import org.wordpress.android.ui.domains.management.purchasedomain.PurchaseDomainActivity.Companion.PICKED_DOMAIN_KEY
import org.wordpress.android.ui.domains.management.purchasedomain.PurchaseDomainActivity.Companion.PICKED_DOMAIN_PRIVACY
import org.wordpress.android.ui.domains.management.purchasedomain.PurchaseDomainActivity.Companion.PICKED_PRODUCT_ID
import org.wordpress.android.ui.main.WPMainActivity
import org.wordpress.android.ui.media.MediaBrowserActivity
import org.wordpress.android.ui.media.MediaBrowserType
import org.wordpress.android.ui.mysite.menu.KEY_QUICK_START_EVENT
import org.wordpress.android.ui.mysite.menu.MenuActivity
import org.wordpress.android.ui.mysite.personalization.PersonalizationActivity
import org.wordpress.android.ui.quickstart.QuickStartEvent
import org.wordpress.android.util.ToastUtils
import org.wordpress.android.util.analytics.AnalyticsUtils
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -106,5 +110,34 @@ class ActivityNavigator @Inject constructor() {
context.startActivity(intent)
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.OPENED_MEDIA_LIBRARY, site)
}

fun openMediaInNewStack(context: Context, site: SiteModel?) {
if (site == null) {
ToastUtils.showToast(context, R.string.media_cannot_be_started, ToastUtils.Duration.SHORT)
return
}
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.OPENED_MEDIA_LIBRARY, site)
val taskStackBuilder = TaskStackBuilder.create(context)
val mainActivityIntent = getMainActivityInNewStack(context)
val intent = Intent(context, MediaBrowserActivity::class.java)
intent.putExtra(WordPress.SITE, site)
taskStackBuilder
.addNextIntent(mainActivityIntent)
.addNextIntent(intent)
.startActivities()
}

fun openMediaInNewStack(context: Context) {
AnalyticsTracker.track(AnalyticsTracker.Stat.OPENED_MEDIA_LIBRARY)
val intent = getMainActivityInNewStack(context)
intent.putExtra(WPMainActivity.ARG_OPEN_PAGE, WPMainActivity.ARG_MEDIA)
context.startActivity(intent)
}

private fun getMainActivityInNewStack(context: Context): Intent {
val mainActivityIntent = Intent(context, WPMainActivity::class.java)
mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
return mainActivityIntent
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.ActivityNavigator
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.LoginForResult
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.OpenEditor
import org.wordpress.android.ui.deeplinks.DeepLinkNavigator.NavigateAction.OpenEditorForPost
Expand Down Expand Up @@ -31,7 +32,7 @@ import org.wordpress.android.util.UriWrapper
import javax.inject.Inject

class DeepLinkNavigator
@Inject constructor() {
@Inject constructor(private val activityNavigator: ActivityNavigator) {
@Suppress("ComplexMethod")
fun handleNavigationAction(navigateAction: NavigateAction, activity: AppCompatActivity) {
when (navigateAction) {
Expand Down Expand Up @@ -83,8 +84,8 @@ class DeepLinkNavigator
ActivityLauncher.openJetpackForDeeplink(activity, navigateAction.action, navigateAction.uri)
is NavigateAction.OpenJetpackStaticPosterView ->
ActivityLauncher.showJetpackStaticPoster(activity)
is NavigateAction.OpenMediaForSite -> ActivityLauncher.openMediaInNewStack(activity, navigateAction.site)
NavigateAction.OpenMedia -> ActivityLauncher.openMediaInNewStack(activity)
is NavigateAction.OpenMediaForSite -> activityNavigator.openMediaInNewStack(activity, navigateAction.site)
NavigateAction.OpenMedia -> activityNavigator.openMediaInNewStack(activity)
}
if (navigateAction != LoginForResult) {
activity.finish()
Expand Down

0 comments on commit 61fc769

Please sign in to comment.