From 97c590c6d9471005c98abecdcbcda7c128aab50f Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Tue, 31 Jul 2018 21:25:25 +0200 Subject: [PATCH] improve activity slide in/out handling --- .../com/keylesspalace/tusky/AboutActivity.kt | 2 +- .../keylesspalace/tusky/AccountActivity.kt | 9 ++--- .../com/keylesspalace/tusky/BaseActivity.java | 20 +++------- .../tusky/BottomSheetActivity.kt | 4 +- .../tusky/EditProfileActivity.kt | 4 +- .../com/keylesspalace/tusky/ListsActivity.kt | 2 +- .../com/keylesspalace/tusky/MainActivity.java | 39 +++++++++---------- .../tusky/PreferencesActivity.java | 6 +-- .../keylesspalace/tusky/ReportActivity.java | 2 +- .../tusky/ViewMediaActivity.java | 2 +- 10 files changed, 39 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt index 2d4dbcfa..8acc0cc2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt @@ -40,7 +40,7 @@ class AboutActivity : BottomSheetActivity(), Injectable { } aboutLicensesButton.setOnClickListener { - startActivity(Intent(this, LicenseActivity::class.java)) + startActivityWithSlideInAnimation(Intent(this, LicenseActivity::class.java)) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index c55fa19f..76790806 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -50,7 +50,6 @@ import com.keylesspalace.tusky.interfaces.ActionButtonActivity import com.keylesspalace.tusky.interfaces.LinkListener import com.keylesspalace.tusky.pager.AccountPagerAdapter import com.keylesspalace.tusky.util.* -import com.keylesspalace.tusky.view.RoundedTransformation import com.keylesspalace.tusky.viewmodel.AccountViewModel import com.squareup.picasso.Picasso import dagger.android.AndroidInjector @@ -274,7 +273,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF else -> throw AssertionError() } val accountListIntent = AccountListActivity.newIntent(this, type, accountId) - startActivity(accountListIntent) + startActivityWithSlideInAnimation(accountListIntent) } accountFollowers.setOnClickListener(accountListClickListener) accountFollowing.setOnClickListener(accountListClickListener) @@ -541,20 +540,20 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF val intent = ComposeActivity.IntentBuilder() .mentionedUsernames(setOf(it.username)) .build(this) - startActivity(intent) + startActivityWithSlideInAnimation(intent) } } override fun onViewTag(tag: String) { val intent = Intent(this, ViewTagActivity::class.java) intent.putExtra("hashtag", tag) - startActivity(intent) + startActivityWithSlideInAnimation(intent) } override fun onViewAccount(id: String) { val intent = Intent(this, AccountActivity::class.java) intent.putExtra("id", id) - startActivity(intent) + startActivityWithSlideInAnimation(intent) } override fun onViewUrl(url: String) { diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 858974c6..556b60c1 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -102,23 +102,13 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab return style; } - @Override - public void finish() { - super.finish(); - overridePendingTransitionExit(); - } - - @Override - public void startActivity(Intent intent) { + public void startActivityWithSlideInAnimation(Intent intent) { super.startActivity(intent); - overridePendingTransitionEnter(); - } - - private void overridePendingTransitionEnter() { overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); } - private void overridePendingTransitionExit() { + public void finishWithSlideOutAnimation() { + super.finish(); overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right); } @@ -131,8 +121,8 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab if (account == null) { Intent intent = new Intent(this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); - finish(); + startActivityWithSlideInAnimation(intent); + finishWithSlideOutAnimation(); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt b/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt index 2c6c3a7b..8818f629 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt @@ -112,13 +112,13 @@ abstract class BottomSheetActivity : BaseActivity() { val intent = Intent(this, ViewThreadActivity::class.java) intent.putExtra("id", status.actionableId) intent.putExtra("url", status.actionableStatus.url) - startActivity(intent) + startActivityWithSlideInAnimation(intent) } } open fun viewAccount(id: String) { val intent = AccountActivity.getIntent(this, id) - startActivity(intent) + startActivityWithSlideInAnimation(intent) } @VisibleForTesting diff --git a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt index 0b7068f4..4ddb84e2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt @@ -290,7 +290,7 @@ class EditProfileActivity : BaseActivity(), Injectable { if (displayName == null && note == null && locked == null && avatar == null && header == null) { /** if nothing has changed, there is no need to make a network request */ setResult(Activity.RESULT_OK) - finish() + finishWithSlideOutAnimation() return } @@ -304,7 +304,7 @@ class EditProfileActivity : BaseActivity(), Injectable { .putBoolean("refreshProfileHeader", true) .apply() setResult(Activity.RESULT_OK) - finish() + finishWithSlideOutAnimation() } override fun onFailure(call: Call, t: Throwable) { diff --git a/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt b/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt index f28a03ff..890e52e3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt @@ -143,7 +143,7 @@ class ListsActivity : BaseActivity(), ListsView, Injectable { } override fun openTimeline(listId: String) { - startActivity( + startActivityWithSlideInAnimation( ModalTimelineActivity.newIntent(this, TimelineFragment.Kind.LIST, listId)) } diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index c01d0348..58bc287e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -119,12 +119,12 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut setContentView(R.layout.activity_main); - FloatingActionButton floatingBtn = findViewById(R.id.floating_btn); + composeButton = findViewById(R.id.floating_btn); ImageButton drawerToggle = findViewById(R.id.drawer_toggle); TabLayout tabLayout = findViewById(R.id.tab_layout); viewPager = findViewById(R.id.pager); - floatingBtn.setOnClickListener(v -> { + composeButton.setOnClickListener(v -> { Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class); startActivity(composeIntent); }); @@ -211,7 +211,6 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut disablePushNotifications(); } - composeButton = floatingBtn; } @Override @@ -255,7 +254,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut return true; } case KeyEvent.KEYCODE_SEARCH: { - startActivity(new Intent(this, SearchActivity.class)); + startActivityWithSlideInAnimation(new Intent(this, SearchActivity.class)); return true; } } @@ -331,38 +330,38 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) { Intent intent = new Intent(MainActivity.this, EditProfileActivity.class); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) { Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) { Intent intent = new Intent(MainActivity.this, AccountListActivity.class); intent.putExtra("type", AccountListActivity.Type.MUTES); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) { Intent intent = new Intent(MainActivity.this, AccountListActivity.class); intent.putExtra("type", AccountListActivity.Type.BLOCKS); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) { Intent intent = new Intent(MainActivity.this, SearchActivity.class); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) { Intent intent = new Intent(MainActivity.this, PreferencesActivity.class); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) { Intent intent = new Intent(MainActivity.this, AboutActivity.class); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) { logout(); } else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) { Intent intent = new Intent(MainActivity.this, AccountListActivity.class); intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) { Intent intent = new Intent(MainActivity.this, SavedTootActivity.class); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else if (drawerItemIdentifier == DRAWER_ITEM_LISTS) { - startActivity(ListsActivity.newIntent(this)); + startActivityWithSlideInAnimation(ListsActivity.newIntent(this)); } } @@ -390,12 +389,12 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut //open profile when active image was clicked if (current && activeAccount != null) { Intent intent = AccountActivity.getIntent(this, activeAccount.getAccountId()); - startActivity(intent); + startActivityWithSlideInAnimation(intent); return true; } //open LoginActivity to add new account if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) { - startActivity(LoginActivity.getIntent(this, true)); + startActivityWithSlideInAnimation(LoginActivity.getIntent(this, true)); return true; } //change Account @@ -409,8 +408,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - finish(); + startActivityWithSlideInAnimation(intent); + finishWithSlideOutAnimation(); overridePendingTransition(R.anim.explode, R.anim.explode); } @@ -439,8 +438,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut } else { intent = new Intent(MainActivity.this, MainActivity.class); } - startActivity(intent); - finish(); + startActivityWithSlideInAnimation(intent); + finishWithSlideOutAnimation(); }) .setNegativeButton(android.R.string.no, null) .show(); diff --git a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java index 1f1e965d..9022a921 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java @@ -116,8 +116,8 @@ public class PreferencesActivity extends BaseActivity Bundle savedInstanceState = new Bundle(); saveInstanceState(savedInstanceState); intent.putExtras(savedInstanceState); - startActivity(intent); - finish(); + startActivityWithSlideInAnimation(intent); + finishWithSlideOutAnimation(); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } case "statusTextSize": { @@ -156,7 +156,7 @@ public class PreferencesActivity extends BaseActivity if (restartActivitiesOnExit) { Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); + startActivityWithSlideInAnimation(intent); } else { super.onBackPressed(); } diff --git a/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java b/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java index 3a2e04eb..84e1eac8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ReportActivity.java @@ -148,7 +148,7 @@ public class ReportActivity extends BaseActivity implements Injectable { private void onSendSuccess() { Snackbar bar = Snackbar.make(anyView, getString(R.string.confirmation_reported), Snackbar.LENGTH_SHORT); bar.show(); - finish(); + finishWithSlideOutAnimation(); } private void onSendFailure(final String accountId, final String[] statusIds, diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java index eaa880e6..ef9882b3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java @@ -282,7 +282,7 @@ public final class ViewMediaActivity extends BaseActivity private void onOpenStatus() { final AttachmentViewData attach = attachments.get(viewPager.getCurrentItem()); - startActivity(ViewThreadActivity.startIntent(this, attach.getStatusId(), + startActivityWithSlideInAnimation(ViewThreadActivity.startIntent(this, attach.getStatusId(), attach.getStatusUrl())); } }