improve activity slide in/out handling

This commit is contained in:
Conny Duck 2018-07-31 21:25:25 +02:00
parent 2b246fc379
commit 9a42999451
10 changed files with 39 additions and 51 deletions

View File

@ -40,7 +40,7 @@ class AboutActivity : BottomSheetActivity(), Injectable {
} }
aboutLicensesButton.setOnClickListener { aboutLicensesButton.setOnClickListener {
startActivity(Intent(this, LicenseActivity::class.java)) startActivityWithSlideInAnimation(Intent(this, LicenseActivity::class.java))
} }
} }

View File

@ -50,7 +50,6 @@ import com.keylesspalace.tusky.interfaces.ActionButtonActivity
import com.keylesspalace.tusky.interfaces.LinkListener import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.pager.AccountPagerAdapter import com.keylesspalace.tusky.pager.AccountPagerAdapter
import com.keylesspalace.tusky.util.* import com.keylesspalace.tusky.util.*
import com.keylesspalace.tusky.view.RoundedTransformation
import com.keylesspalace.tusky.viewmodel.AccountViewModel import com.keylesspalace.tusky.viewmodel.AccountViewModel
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
@ -274,7 +273,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
else -> throw AssertionError() else -> throw AssertionError()
} }
val accountListIntent = AccountListActivity.newIntent(this, type, accountId) val accountListIntent = AccountListActivity.newIntent(this, type, accountId)
startActivity(accountListIntent) startActivityWithSlideInAnimation(accountListIntent)
} }
accountFollowers.setOnClickListener(accountListClickListener) accountFollowers.setOnClickListener(accountListClickListener)
accountFollowing.setOnClickListener(accountListClickListener) accountFollowing.setOnClickListener(accountListClickListener)
@ -541,20 +540,20 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
val intent = ComposeActivity.IntentBuilder() val intent = ComposeActivity.IntentBuilder()
.mentionedUsernames(setOf(it.username)) .mentionedUsernames(setOf(it.username))
.build(this) .build(this)
startActivity(intent) startActivityWithSlideInAnimation(intent)
} }
} }
override fun onViewTag(tag: String) { override fun onViewTag(tag: String) {
val intent = Intent(this, ViewTagActivity::class.java) val intent = Intent(this, ViewTagActivity::class.java)
intent.putExtra("hashtag", tag) intent.putExtra("hashtag", tag)
startActivity(intent) startActivityWithSlideInAnimation(intent)
} }
override fun onViewAccount(id: String) { override fun onViewAccount(id: String) {
val intent = Intent(this, AccountActivity::class.java) val intent = Intent(this, AccountActivity::class.java)
intent.putExtra("id", id) intent.putExtra("id", id)
startActivity(intent) startActivityWithSlideInAnimation(intent)
} }
override fun onViewUrl(url: String) { override fun onViewUrl(url: String) {

View File

@ -102,23 +102,13 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
return style; return style;
} }
@Override public void startActivityWithSlideInAnimation(Intent intent) {
public void finish() {
super.finish();
overridePendingTransitionExit();
}
@Override
public void startActivity(Intent intent) {
super.startActivity(intent); super.startActivity(intent);
overridePendingTransitionEnter();
}
private void overridePendingTransitionEnter() {
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); 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); 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) { if (account == null) {
Intent intent = new Intent(this, LoginActivity.class); Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivityWithSlideInAnimation(intent);
finish(); finishWithSlideOutAnimation();
} }
} }

View File

@ -112,13 +112,13 @@ abstract class BottomSheetActivity : BaseActivity() {
val intent = Intent(this, ViewThreadActivity::class.java) val intent = Intent(this, ViewThreadActivity::class.java)
intent.putExtra("id", status.actionableId) intent.putExtra("id", status.actionableId)
intent.putExtra("url", status.actionableStatus.url) intent.putExtra("url", status.actionableStatus.url)
startActivity(intent) startActivityWithSlideInAnimation(intent)
} }
} }
open fun viewAccount(id: String) { open fun viewAccount(id: String) {
val intent = AccountActivity.getIntent(this, id) val intent = AccountActivity.getIntent(this, id)
startActivity(intent) startActivityWithSlideInAnimation(intent)
} }
@VisibleForTesting @VisibleForTesting

View File

@ -290,7 +290,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
if (displayName == null && note == null && locked == null && avatar == null && header == null) { if (displayName == null && note == null && locked == null && avatar == null && header == null) {
/** if nothing has changed, there is no need to make a network request */ /** if nothing has changed, there is no need to make a network request */
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
finish() finishWithSlideOutAnimation()
return return
} }
@ -304,7 +304,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
.putBoolean("refreshProfileHeader", true) .putBoolean("refreshProfileHeader", true)
.apply() .apply()
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
finish() finishWithSlideOutAnimation()
} }
override fun onFailure(call: Call<Account>, t: Throwable) { override fun onFailure(call: Call<Account>, t: Throwable) {

View File

@ -143,7 +143,7 @@ class ListsActivity : BaseActivity(), ListsView, Injectable {
} }
override fun openTimeline(listId: String) { override fun openTimeline(listId: String) {
startActivity( startActivityWithSlideInAnimation(
ModalTimelineActivity.newIntent(this, TimelineFragment.Kind.LIST, listId)) ModalTimelineActivity.newIntent(this, TimelineFragment.Kind.LIST, listId))
} }

View File

@ -119,12 +119,12 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
setContentView(R.layout.activity_main); 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); ImageButton drawerToggle = findViewById(R.id.drawer_toggle);
TabLayout tabLayout = findViewById(R.id.tab_layout); TabLayout tabLayout = findViewById(R.id.tab_layout);
viewPager = findViewById(R.id.pager); viewPager = findViewById(R.id.pager);
floatingBtn.setOnClickListener(v -> { composeButton.setOnClickListener(v -> {
Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class); Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class);
startActivity(composeIntent); startActivity(composeIntent);
}); });
@ -211,7 +211,6 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
disablePushNotifications(); disablePushNotifications();
} }
composeButton = floatingBtn;
} }
@Override @Override
@ -255,7 +254,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
return true; return true;
} }
case KeyEvent.KEYCODE_SEARCH: { case KeyEvent.KEYCODE_SEARCH: {
startActivity(new Intent(this, SearchActivity.class)); startActivityWithSlideInAnimation(new Intent(this, SearchActivity.class));
return true; return true;
} }
} }
@ -331,38 +330,38 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) { if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) {
Intent intent = new Intent(MainActivity.this, EditProfileActivity.class); Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) { } else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) {
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) { } else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) {
Intent intent = new Intent(MainActivity.this, AccountListActivity.class); Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
intent.putExtra("type", AccountListActivity.Type.MUTES); intent.putExtra("type", AccountListActivity.Type.MUTES);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) { } else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) {
Intent intent = new Intent(MainActivity.this, AccountListActivity.class); Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
intent.putExtra("type", AccountListActivity.Type.BLOCKS); intent.putExtra("type", AccountListActivity.Type.BLOCKS);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) { } else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) {
Intent intent = new Intent(MainActivity.this, SearchActivity.class); Intent intent = new Intent(MainActivity.this, SearchActivity.class);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) { } else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) {
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class); Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) { } else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) {
Intent intent = new Intent(MainActivity.this, AboutActivity.class); Intent intent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) { } else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) {
logout(); logout();
} else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) { } else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) {
Intent intent = new Intent(MainActivity.this, AccountListActivity.class); Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS); intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) { } else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) {
Intent intent = new Intent(MainActivity.this, SavedTootActivity.class); Intent intent = new Intent(MainActivity.this, SavedTootActivity.class);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else if (drawerItemIdentifier == DRAWER_ITEM_LISTS) { } 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 //open profile when active image was clicked
if (current && activeAccount != null) { if (current && activeAccount != null) {
Intent intent = AccountActivity.getIntent(this, activeAccount.getAccountId()); Intent intent = AccountActivity.getIntent(this, activeAccount.getAccountId());
startActivity(intent); startActivityWithSlideInAnimation(intent);
return true; return true;
} }
//open LoginActivity to add new account //open LoginActivity to add new account
if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) { if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) {
startActivity(LoginActivity.getIntent(this, true)); startActivityWithSlideInAnimation(LoginActivity.getIntent(this, true));
return true; return true;
} }
//change Account //change Account
@ -409,8 +408,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent); startActivityWithSlideInAnimation(intent);
finish(); finishWithSlideOutAnimation();
overridePendingTransition(R.anim.explode, R.anim.explode); overridePendingTransition(R.anim.explode, R.anim.explode);
} }
@ -439,8 +438,8 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
} else { } else {
intent = new Intent(MainActivity.this, MainActivity.class); intent = new Intent(MainActivity.this, MainActivity.class);
} }
startActivity(intent); startActivityWithSlideInAnimation(intent);
finish(); finishWithSlideOutAnimation();
}) })
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.show(); .show();

View File

@ -116,8 +116,8 @@ public class PreferencesActivity extends BaseActivity
Bundle savedInstanceState = new Bundle(); Bundle savedInstanceState = new Bundle();
saveInstanceState(savedInstanceState); saveInstanceState(savedInstanceState);
intent.putExtras(savedInstanceState); intent.putExtras(savedInstanceState);
startActivity(intent); startActivityWithSlideInAnimation(intent);
finish(); finishWithSlideOutAnimation();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out); overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
} }
case "statusTextSize": { case "statusTextSize": {
@ -156,7 +156,7 @@ public class PreferencesActivity extends BaseActivity
if (restartActivitiesOnExit) { if (restartActivitiesOnExit) {
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent); startActivityWithSlideInAnimation(intent);
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }

View File

@ -148,7 +148,7 @@ public class ReportActivity extends BaseActivity implements Injectable {
private void onSendSuccess() { private void onSendSuccess() {
Snackbar bar = Snackbar.make(anyView, getString(R.string.confirmation_reported), Snackbar.LENGTH_SHORT); Snackbar bar = Snackbar.make(anyView, getString(R.string.confirmation_reported), Snackbar.LENGTH_SHORT);
bar.show(); bar.show();
finish(); finishWithSlideOutAnimation();
} }
private void onSendFailure(final String accountId, final String[] statusIds, private void onSendFailure(final String accountId, final String[] statusIds,

View File

@ -282,7 +282,7 @@ public final class ViewMediaActivity extends BaseActivity
private void onOpenStatus() { private void onOpenStatus() {
final AttachmentViewData attach = attachments.get(viewPager.getCurrentItem()); final AttachmentViewData attach = attachments.get(viewPager.getCurrentItem());
startActivity(ViewThreadActivity.startIntent(this, attach.getStatusId(), startActivityWithSlideInAnimation(ViewThreadActivity.startIntent(this, attach.getStatusId(),
attach.getStatusUrl())); attach.getStatusUrl()));
} }
} }