Skip to content

Commit

Permalink
#1857 Override activity transition API 34+
Browse files Browse the repository at this point in the history
  • Loading branch information
sictiru committed May 9, 2024
1 parent ffec600 commit ff7671c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.newsblur.util.FeedSet;
import com.newsblur.util.FeedUtils;
import com.newsblur.util.Log;
import com.newsblur.util.PendingTransitionUtils;
import com.newsblur.util.ReadingActionListener;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.Session;
Expand Down Expand Up @@ -82,7 +83,7 @@ protected void onCreate(Bundle bundle) {
Trace.beginSection("ItemsListOnCreate");
super.onCreate(bundle);

overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_to_left);
PendingTransitionUtils.overrideEnterTransition(this);

contextMenuDelegate = new ItemListContextMenuDelegateImpl(this, feedUtils);
viewModel = new ViewModelProvider(this).get(ItemListViewModel.class);
Expand Down Expand Up @@ -313,13 +314,7 @@ private void handleReadingActivityResult(ActivityResult result) {
@Override
public void finish() {
super.finish();
/*
* Animate out the list by sliding it to the right and the Main activity in from
* the left. Do this when going back to Main as a subtle hint to the swipe gesture,
* to make the gesture feel more natural, and to override the really ugly transition
* used in some of the newer platforms.
*/
overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
PendingTransitionUtils.overrideExitTransition(this);
}

abstract String getSaveSearchFeedId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@file:Suppress("DEPRECATION")

package com.newsblur.util

import android.app.Activity
import android.os.Build
import com.newsblur.R

object PendingTransitionUtils {

@JvmStatic
fun overrideEnterTransition(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
activity.overrideActivityTransition(
Activity.OVERRIDE_TRANSITION_OPEN,
R.anim.slide_in_from_right,
R.anim.slide_out_to_left,
)
} else {
activity.overridePendingTransition(
R.anim.slide_in_from_right,
R.anim.slide_out_to_left,
)
}
}

@JvmStatic
fun overrideNoEnterTransition(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
activity.overrideActivityTransition(
Activity.OVERRIDE_TRANSITION_OPEN,
0,
0,
)
} else {
activity.overridePendingTransition(
0,
0,
)
}
}

@JvmStatic
fun overrideExitTransition(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
activity.overrideActivityTransition(
Activity.OVERRIDE_TRANSITION_CLOSE,
R.anim.slide_in_from_left,
R.anim.slide_out_to_right,
)
} else {
activity.overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right)
}
}

@JvmStatic
fun overrideNoExitTransition(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
activity.overrideActivityTransition(
Activity.OVERRIDE_TRANSITION_CLOSE,
0,
0,
)
} else {
activity.overridePendingTransition(0, 0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ public static void restartActivity(final Activity activity) {
public void run() {
Intent intent = activity.getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.overridePendingTransition(0, 0);
PendingTransitionUtils.overrideNoExitTransition(activity);
activity.finish();

activity.overridePendingTransition(0, 0);
PendingTransitionUtils.overrideNoEnterTransition(activity);
activity.startActivity(intent);
}
});
Expand Down

0 comments on commit ff7671c

Please sign in to comment.