improve activity slide in/out handling

This commit is contained in:
Conny Duck 2018-07-31 21:25:25 +02:00
parent 4e2e40602c
commit 97c590c6d9
10 changed files with 39 additions and 51 deletions

View File

@ -40,7 +40,7 @@ class AboutActivity : BottomSheetActivity(), Injectable {
}
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.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) {

View File

@ -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();
}
}

View File

@ -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

View File

@ -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<Account>, t: Throwable) {

View File

@ -143,7 +143,7 @@ class ListsActivity : BaseActivity(), ListsView, Injectable {
}
override fun openTimeline(listId: String) {
startActivity(
startActivityWithSlideInAnimation(
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);
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();

View File

@ -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();
}

View File

@ -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,

View File

@ -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()));
}
}