That fuck shit the fascists are using
at master 91 lines 3.3 kB view raw
1package org.tm.archive; 2 3import android.app.Activity; 4import android.content.Intent; 5 6import androidx.annotation.NonNull; 7import androidx.fragment.app.Fragment; 8import androidx.fragment.app.FragmentManager; 9 10import org.signal.core.util.concurrent.LifecycleDisposable; 11import org.tm.archive.components.settings.app.AppSettingsActivity; 12import org.tm.archive.conversation.ConversationIntents; 13import org.tm.archive.groups.ui.creategroup.CreateGroupActivity; 14import org.tm.archive.recipients.RecipientId; 15 16import io.reactivex.rxjava3.disposables.Disposable; 17 18public class MainNavigator { 19 20 public static final int REQUEST_CONFIG_CHANGES = 901; 21 22 private final MainActivity activity; 23 private final LifecycleDisposable lifecycleDisposable; 24 25 public MainNavigator(@NonNull MainActivity activity) { 26 this.activity = activity; 27 this.lifecycleDisposable = new LifecycleDisposable(); 28 29 lifecycleDisposable.bindTo(activity); 30 } 31 32 public static MainNavigator get(@NonNull Activity activity) { 33 if (!(activity instanceof MainActivity)) { 34 throw new IllegalArgumentException("Activity must be an instance of MainActivity!"); 35 } 36 37 return ((MainActivity) activity).getNavigator(); 38 } 39 40 /** 41 * @return True if the back pressed was handled in our own custom way, false if it should be given 42 * to the system to do the default behavior. 43 */ 44 public boolean onBackPressed() { 45 Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container); 46 47 if (fragment instanceof BackHandler) { 48 return ((BackHandler) fragment).onBackPressed(); 49 } 50 51 return false; 52 } 53 54 public void goToConversation(@NonNull RecipientId recipientId, long threadId, int distributionType, int startingPosition) { 55 Disposable disposable = ConversationIntents.createBuilder(activity, recipientId, threadId) 56 .map(builder -> builder.withDistributionType(distributionType) 57 .withStartingPosition(startingPosition) 58 .build()) 59 .subscribe(intent -> { 60 activity.startActivity(intent); 61 activity.overridePendingTransition(R.anim.slide_from_end, R.anim.fade_scale_out); 62 }); 63 64 lifecycleDisposable.add(disposable); 65 } 66 67 public void goToAppSettings() { 68 activity.startActivityForResult(AppSettingsActivity.home(activity), REQUEST_CONFIG_CHANGES); 69 } 70 71 public void goToGroupCreation() { 72 activity.startActivity(CreateGroupActivity.newIntent(activity)); 73 } 74 75 public void goToInvite() { 76 Intent intent = new Intent(activity, InviteActivity.class); 77 activity.startActivity(intent); 78 } 79 80 private @NonNull FragmentManager getFragmentManager() { 81 return activity.getSupportFragmentManager(); 82 } 83 84 public interface BackHandler { 85 /** 86 * @return True if the back pressed was handled in our own custom way, false if it should be given 87 * to the system to do the default behavior. 88 */ 89 boolean onBackPressed(); 90 } 91}