mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Add predictive back gesture support to MainActivity.
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:resizeableActivity="true"
|
||||
android:fullBackupOnly="false"
|
||||
android:enableOnBackInvokedCallback="false"
|
||||
android:allowBackup="true"
|
||||
android:backupAgent=".absbackup.SignalBackupAgent"
|
||||
android:theme="@style/TextSecure.LightTheme"
|
||||
@@ -1069,6 +1070,7 @@
|
||||
android:exported="false"/>
|
||||
|
||||
<activity android:name=".MainActivity"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:theme="@style/Theme.Signal.DayNight.NoActionBar"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
|
||||
android:resizeableActivity="true"
|
||||
|
||||
@@ -260,12 +260,6 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
|
||||
SplashScreenUtil.setSplashScreenThemeIfNecessary(this, SignalStore.settings.theme)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (!navigator.onBackPressed()) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == MainNavigator.REQUEST_CONFIG_CHANGES && resultCode == RESULT_CONFIG_CHANGED) {
|
||||
|
||||
@@ -6,10 +6,8 @@ import android.content.Intent;
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.viewmodel.internal.ViewModelProviders;
|
||||
|
||||
import org.signal.core.util.concurrent.LifecycleDisposable;
|
||||
import org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity;
|
||||
@@ -54,20 +52,6 @@ public class MainNavigator {
|
||||
return ((NavigatorProvider) activity).getNavigator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the back pressed was handled in our own custom way, false if it should be given
|
||||
* to the system to do the default behavior.
|
||||
*/
|
||||
public boolean onBackPressed() {
|
||||
Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container);
|
||||
|
||||
if (fragment instanceof BackHandler) {
|
||||
return ((BackHandler) fragment).onBackPressed();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void goToConversation(@NonNull RecipientId recipientId, long threadId, int distributionType, int startingPosition) {
|
||||
Disposable disposable = ConversationIntents.createBuilder(activity, recipientId, threadId)
|
||||
.map(builder -> builder.withDistributionType(distributionType)
|
||||
|
||||
@@ -244,6 +244,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
private ConversationListTabsViewModel conversationListTabsViewModel;
|
||||
private ContactSearchMediator contactSearchMediator;
|
||||
private MainToolbarViewModel mainToolbarViewModel;
|
||||
private ChatListBackHandler chatListBackHandler;
|
||||
|
||||
private BannerManager bannerManager;
|
||||
|
||||
@@ -428,16 +429,8 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
|
||||
RatingManager.showRatingDialogIfNecessary(requireContext());
|
||||
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (!closeSearchIfOpen()) {
|
||||
if (!NavHostFragment.findNavController(ConversationListFragment.this).popBackStack()) {
|
||||
requireActivity().finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
chatListBackHandler = new ChatListBackHandler(false);
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), chatListBackHandler);
|
||||
|
||||
conversationListTabsViewModel = new ViewModelProvider(requireActivity()).get(ConversationListTabsViewModel.class);
|
||||
|
||||
@@ -658,15 +651,14 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
return mainToolbarViewModel.getState().getValue().getMode() == MainToolbarMode.SEARCH;
|
||||
}
|
||||
|
||||
private boolean closeSearchIfOpen() {
|
||||
private void closeSearchIfOpen() {
|
||||
if (isSearchOpen()) {
|
||||
setAdapter(defaultAdapter);
|
||||
fadeInButtonsAndMegaphone(250);
|
||||
mainToolbarViewModel.setToolbarMode(MainToolbarMode.FULL);
|
||||
chatListBackHandler.setEnabled(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1690,6 +1682,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
}
|
||||
|
||||
private void onSearchOpen() {
|
||||
chatListBackHandler.setEnabled(true);
|
||||
fadeOutButtonsAndMegaphone(250);
|
||||
}
|
||||
|
||||
@@ -1697,6 +1690,8 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
if (list != null) {
|
||||
setAdapter(defaultAdapter);
|
||||
}
|
||||
|
||||
chatListBackHandler.setEnabled(false);
|
||||
fadeInButtonsAndMegaphone(250);
|
||||
}
|
||||
|
||||
@@ -1970,6 +1965,18 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
||||
}
|
||||
}
|
||||
|
||||
private class ChatListBackHandler extends OnBackPressedCallback {
|
||||
|
||||
public ChatListBackHandler(boolean enabled) {
|
||||
super(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
closeSearchIfOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Callback extends Material3OnScrollHelperBinder {
|
||||
void updateProxyStatus(@NonNull WebSocketConnectionState state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user