full sdk 34 support (#4224)
builds upon work from #4082 Additionally fixes some deprecations and adds support for [predictive back](https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture). I also refactored how the activity transitions work because they are closely related to predictive back. The awkward `finishWithoutSlideOutAnimation` is gone, activities that have been started with slide in will now automatically close with slide out. To test predictive back you need an emulator or device with Sdk 34 (Android 14) and then enable it in the developer settings. Predictive back requires the back action to be determined before it actually occurs so the system can play the right predictive animation, which made a few reorganisations necessary. closes #4082 closes #4005 unlocks a bunch of dependency upgrades that require sdk 34 --------- Co-authored-by: Goooler <wangzongler@gmail.com>
This commit is contained in:
parent
fa8bede7d6
commit
b976fe5296
36 changed files with 272 additions and 186 deletions
|
|
@ -24,6 +24,7 @@ import android.content.res.Configuration;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -49,6 +50,7 @@ import com.keylesspalace.tusky.interfaces.AccountSelectionListener;
|
|||
import com.keylesspalace.tusky.interfaces.PermissionRequester;
|
||||
import com.keylesspalace.tusky.settings.AppTheme;
|
||||
import com.keylesspalace.tusky.settings.PrefKeys;
|
||||
import com.keylesspalace.tusky.util.ActivityExtensions;
|
||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -60,6 +62,9 @@ import javax.inject.Inject;
|
|||
import static com.keylesspalace.tusky.settings.PrefKeys.APP_THEME;
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements Injectable {
|
||||
|
||||
public static final String OPEN_WITH_SLIDE_IN = "OPEN_WITH_SLIDE_IN";
|
||||
|
||||
private static final String TAG = "BaseActivity";
|
||||
|
||||
@Inject
|
||||
|
|
@ -73,6 +78,11 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && getIntent().getBooleanExtra(OPEN_WITH_SLIDE_IN, false)) {
|
||||
overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, R.anim.slide_from_right, R.anim.slide_to_left);
|
||||
overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, R.anim.slide_from_left, R.anim.slide_to_right);
|
||||
}
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
/* There isn't presently a way to globally change the theme of a whole application at
|
||||
|
|
@ -166,11 +176,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
return style;
|
||||
}
|
||||
|
||||
public void startActivityWithSlideInAnimation(@NonNull Intent intent) {
|
||||
super.startActivity(intent);
|
||||
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
|
|
@ -183,11 +188,10 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);
|
||||
}
|
||||
|
||||
public void finishWithoutSlideOutAnimation() {
|
||||
super.finish();
|
||||
// if this activity was opened with slide-in, close it with slide out
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE && getIntent().getBooleanExtra(OPEN_WITH_SLIDE_IN, false)) {
|
||||
overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right);
|
||||
}
|
||||
}
|
||||
|
||||
protected void redirectIfNotLoggedIn() {
|
||||
|
|
@ -195,7 +199,7 @@ 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);
|
||||
startActivityWithSlideInAnimation(intent);
|
||||
ActivityExtensions.startActivityWithSlideInAnimation(this, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
@ -235,9 +239,9 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
adapter.addAll(accounts);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(dialogTitle)
|
||||
.setAdapter(adapter, (dialogInterface, index) -> listener.onAccountSelected(accounts.get(index)))
|
||||
.show();
|
||||
.setTitle(dialogTitle)
|
||||
.setAdapter(adapter, (dialogInterface, index) -> listener.onAccountSelected(accounts.get(index)))
|
||||
.show();
|
||||
}
|
||||
|
||||
public @Nullable String getOpenAsText() {
|
||||
|
|
@ -263,7 +267,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
Intent intent = MainActivity.redirectIntent(this, account.getId(), url);
|
||||
|
||||
startActivity(intent);
|
||||
finishWithoutSlideOutAnimation();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue