2019-11-14 14:35:08 -05:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2023-08-17 15:02:16 -04:00
|
|
|
import android.annotation.SuppressLint;
|
2020-09-26 10:35:18 -04:00
|
|
|
import android.app.Activity;
|
2020-12-19 16:54:00 -04:00
|
|
|
import android.content.Context;
|
2020-08-13 16:39:43 -03:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
2019-11-14 14:35:08 -05:00
|
|
|
import android.os.Bundle;
|
2022-02-24 13:40:28 -04:00
|
|
|
import android.view.View;
|
2023-02-28 11:39:30 -05:00
|
|
|
import android.view.ViewTreeObserver;
|
2019-11-14 14:35:08 -05:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2020-09-26 10:35:18 -04:00
|
|
|
import androidx.annotation.Nullable;
|
2022-02-24 13:40:28 -04:00
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2019-11-14 14:35:08 -05:00
|
|
|
|
2023-07-11 19:51:24 -04:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
|
|
2023-08-17 15:02:16 -04:00
|
|
|
import org.signal.core.util.concurrent.LifecycleDisposable;
|
2023-08-09 12:18:25 -04:00
|
|
|
import org.thoughtcrime.securesms.components.DebugLogsPromptDialogFragment;
|
2023-08-15 12:31:54 -04:00
|
|
|
import org.thoughtcrime.securesms.components.PromptBatterySaverDialogFragment;
|
2021-07-07 14:23:37 -03:00
|
|
|
import org.thoughtcrime.securesms.components.voice.VoiceNoteMediaController;
|
|
|
|
import org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner;
|
2023-03-02 11:32:59 -05:00
|
|
|
import org.thoughtcrime.securesms.conversationlist.RelinkDevicesReminderBottomSheetFragment;
|
2023-07-11 19:51:24 -04:00
|
|
|
import org.thoughtcrime.securesms.devicetransfer.olddevice.OldDeviceExitActivity;
|
2021-03-16 16:50:10 -04:00
|
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
2023-07-11 19:51:24 -04:00
|
|
|
import org.thoughtcrime.securesms.net.DeviceTransferBlockingInterceptor;
|
2023-09-06 15:05:23 -04:00
|
|
|
import org.thoughtcrime.securesms.notifications.VitalsViewModel;
|
2022-02-24 13:40:28 -04:00
|
|
|
import org.thoughtcrime.securesms.stories.tabs.ConversationListTabRepository;
|
|
|
|
import org.thoughtcrime.securesms.stories.tabs.ConversationListTabsViewModel;
|
2021-01-06 15:31:33 -05:00
|
|
|
import org.thoughtcrime.securesms.util.AppStartup;
|
2020-12-02 10:27:20 -05:00
|
|
|
import org.thoughtcrime.securesms.util.CachedInflater;
|
2020-08-13 16:39:43 -03:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2019-11-14 14:35:08 -05:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2022-04-27 14:43:41 -04:00
|
|
|
import org.thoughtcrime.securesms.util.SplashScreenUtil;
|
2022-02-24 13:40:28 -04:00
|
|
|
import org.thoughtcrime.securesms.util.WindowUtil;
|
2019-11-14 14:35:08 -05:00
|
|
|
|
2021-07-07 14:23:37 -03:00
|
|
|
public class MainActivity extends PassphraseRequiredActivity implements VoiceNoteMediaControllerOwner {
|
2019-11-14 14:35:08 -05:00
|
|
|
|
2020-09-26 10:35:18 -04:00
|
|
|
public static final int RESULT_CONFIG_CHANGED = Activity.RESULT_FIRST_USER + 901;
|
|
|
|
|
2019-11-14 14:35:08 -05:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
|
|
|
private final MainNavigator navigator = new MainNavigator(this);
|
|
|
|
|
2022-02-24 13:40:28 -04:00
|
|
|
private VoiceNoteMediaController mediaController;
|
|
|
|
private ConversationListTabsViewModel conversationListTabsViewModel;
|
2023-09-06 15:05:23 -04:00
|
|
|
private VitalsViewModel vitalsViewModel;
|
2023-08-17 15:02:16 -04:00
|
|
|
|
|
|
|
private final LifecycleDisposable lifecycleDisposable = new LifecycleDisposable();
|
2021-07-07 14:23:37 -03:00
|
|
|
|
2023-02-28 11:39:30 -05:00
|
|
|
private boolean onFirstRender = false;
|
|
|
|
|
2020-12-19 16:54:00 -04:00
|
|
|
public static @NonNull Intent clearTop(@NonNull Context context) {
|
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
|
2022-02-24 13:40:28 -04:00
|
|
|
Intent.FLAG_ACTIVITY_NEW_TASK |
|
2020-12-19 16:54:00 -04:00
|
|
|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
|
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2019-11-14 14:35:08 -05:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState, boolean ready) {
|
2021-01-06 15:31:33 -05:00
|
|
|
AppStartup.getInstance().onCriticalRenderEventStart();
|
2019-11-14 14:35:08 -05:00
|
|
|
super.onCreate(savedInstanceState, ready);
|
2022-02-24 13:40:28 -04:00
|
|
|
|
2019-11-14 14:35:08 -05:00
|
|
|
setContentView(R.layout.main_activity);
|
2023-02-28 11:39:30 -05:00
|
|
|
final View content = findViewById(android.R.id.content);
|
|
|
|
content.getViewTreeObserver().addOnPreDrawListener(
|
|
|
|
new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
// Use pre draw listener to delay drawing frames till conversation list is ready
|
|
|
|
if (onFirstRender) {
|
|
|
|
content.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-17 15:02:16 -04:00
|
|
|
lifecycleDisposable.bindTo(this);
|
2019-11-14 14:35:08 -05:00
|
|
|
|
2023-02-23 08:38:11 -05:00
|
|
|
mediaController = new VoiceNoteMediaController(this, true);
|
2022-02-24 13:40:28 -04:00
|
|
|
|
|
|
|
ConversationListTabRepository repository = new ConversationListTabRepository();
|
|
|
|
ConversationListTabsViewModel.Factory factory = new ConversationListTabsViewModel.Factory(repository);
|
|
|
|
|
2020-08-13 16:39:43 -03:00
|
|
|
handleGroupLinkInIntent(getIntent());
|
2021-02-02 16:42:47 -05:00
|
|
|
handleProxyInIntent(getIntent());
|
2021-07-28 11:58:03 -04:00
|
|
|
handleSignalMeIntent(getIntent());
|
2023-05-19 10:28:29 -03:00
|
|
|
handleCallLinkInIntent(getIntent());
|
2020-12-02 10:27:20 -05:00
|
|
|
|
|
|
|
CachedInflater.from(this).clear();
|
2022-02-24 13:40:28 -04:00
|
|
|
|
|
|
|
conversationListTabsViewModel = new ViewModelProvider(this, factory).get(ConversationListTabsViewModel.class);
|
|
|
|
updateTabVisibility();
|
2023-08-17 15:02:16 -04:00
|
|
|
|
2023-09-06 15:05:23 -04:00
|
|
|
vitalsViewModel = new ViewModelProvider(this).get(VitalsViewModel.class);
|
2023-08-17 15:02:16 -04:00
|
|
|
|
|
|
|
lifecycleDisposable.add(
|
2023-09-06 15:05:23 -04:00
|
|
|
vitalsViewModel
|
|
|
|
.getVitalsState()
|
|
|
|
.subscribe(this::presentVitalsState)
|
2023-08-17 15:02:16 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("NewApi")
|
2023-09-06 15:05:23 -04:00
|
|
|
private void presentVitalsState(VitalsViewModel.State state) {
|
|
|
|
switch (state) {
|
2023-08-17 15:02:16 -04:00
|
|
|
case NONE:
|
|
|
|
break;
|
|
|
|
case PROMPT_BATTERY_SAVER_DIALOG:
|
|
|
|
PromptBatterySaverDialogFragment.show(getSupportFragmentManager());
|
|
|
|
break;
|
2023-09-06 15:05:23 -04:00
|
|
|
case PROMPT_DEBUGLOGS_FOR_NOTIFICATIONS:
|
|
|
|
DebugLogsPromptDialogFragment.show(this, getSupportFragmentManager(), DebugLogsPromptDialogFragment.Purpose.NOTIFICATIONS);
|
|
|
|
case PROMPT_DEBUGLOGS_FOR_CRASH:
|
|
|
|
DebugLogsPromptDialogFragment.show(this, getSupportFragmentManager(), DebugLogsPromptDialogFragment.Purpose.CRASH);
|
2023-08-17 15:02:16 -04:00
|
|
|
break;
|
|
|
|
}
|
2020-08-13 16:39:43 -03:00
|
|
|
}
|
|
|
|
|
2021-01-07 10:37:55 -04:00
|
|
|
@Override
|
|
|
|
public Intent getIntent() {
|
|
|
|
return super.getIntent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
|
2022-02-24 13:40:28 -04:00
|
|
|
Intent.FLAG_ACTIVITY_NEW_TASK |
|
2021-01-07 10:37:55 -04:00
|
|
|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
|
}
|
|
|
|
|
2020-08-13 16:39:43 -03:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
handleGroupLinkInIntent(intent);
|
2021-02-02 16:42:47 -05:00
|
|
|
handleProxyInIntent(intent);
|
2021-07-28 11:58:03 -04:00
|
|
|
handleSignalMeIntent(intent);
|
2023-06-14 14:58:04 -03:00
|
|
|
handleCallLinkInIntent(intent);
|
2019-11-14 14:35:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPreCreate() {
|
|
|
|
super.onPreCreate();
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
2021-03-16 16:50:10 -04:00
|
|
|
if (SignalStore.misc().isOldDeviceTransferLocked()) {
|
2023-07-11 19:51:24 -04:00
|
|
|
new MaterialAlertDialogBuilder(this)
|
|
|
|
.setTitle(R.string.OldDeviceTransferLockedDialog__complete_registration_on_your_new_device)
|
|
|
|
.setMessage(R.string.OldDeviceTransferLockedDialog__your_signal_account_has_been_transferred_to_your_new_device)
|
|
|
|
.setPositiveButton(R.string.OldDeviceTransferLockedDialog__done, (d, w) -> OldDeviceExitActivity.exit(this))
|
|
|
|
.setNegativeButton(R.string.OldDeviceTransferLockedDialog__cancel_and_activate_this_device, (d, w) -> {
|
|
|
|
SignalStore.misc().clearOldDeviceTransferLocked();
|
|
|
|
DeviceTransferBlockingInterceptor.getInstance().unblockNetwork();
|
|
|
|
})
|
|
|
|
.setCancelable(false)
|
|
|
|
.show();
|
2021-03-16 16:50:10 -04:00
|
|
|
}
|
2022-02-24 13:40:28 -04:00
|
|
|
|
2023-05-11 11:08:06 -04:00
|
|
|
if (SignalStore.misc().getShouldShowLinkedDevicesReminder()) {
|
2023-03-02 11:32:59 -05:00
|
|
|
SignalStore.misc().setShouldShowLinkedDevicesReminder(false);
|
|
|
|
RelinkDevicesReminderBottomSheetFragment.show(getSupportFragmentManager());
|
|
|
|
}
|
|
|
|
|
2022-02-24 13:40:28 -04:00
|
|
|
updateTabVisibility();
|
2023-08-09 12:18:25 -04:00
|
|
|
|
2023-09-06 15:05:23 -04:00
|
|
|
vitalsViewModel.checkSlowNotificationHeuristics();
|
2019-11-14 14:35:08 -05:00
|
|
|
}
|
|
|
|
|
2022-04-27 14:43:41 -04:00
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
SplashScreenUtil.setSplashScreenThemeIfNecessary(this, SignalStore.settings().getTheme());
|
|
|
|
}
|
|
|
|
|
2019-11-14 14:35:08 -05:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (!navigator.onBackPressed()) {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-26 10:35:18 -04:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
if (requestCode == MainNavigator.REQUEST_CONFIG_CHANGES && resultCode == RESULT_CONFIG_CHANGED) {
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 13:40:28 -04:00
|
|
|
private void updateTabVisibility() {
|
2023-05-25 12:49:36 -03:00
|
|
|
findViewById(R.id.conversation_list_tabs).setVisibility(View.VISIBLE);
|
|
|
|
WindowUtil.setNavigationBarColor(this, ContextCompat.getColor(this, R.color.signal_colorSurface2));
|
2022-02-24 13:40:28 -04:00
|
|
|
}
|
|
|
|
|
2019-11-14 14:35:08 -05:00
|
|
|
public @NonNull MainNavigator getNavigator() {
|
|
|
|
return navigator;
|
|
|
|
}
|
2020-08-13 16:39:43 -03:00
|
|
|
|
|
|
|
private void handleGroupLinkInIntent(Intent intent) {
|
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null) {
|
|
|
|
CommunicationActions.handlePotentialGroupLinkUrl(this, data.toString());
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 16:42:47 -05:00
|
|
|
|
|
|
|
private void handleProxyInIntent(Intent intent) {
|
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null) {
|
|
|
|
CommunicationActions.handlePotentialProxyLinkUrl(this, data.toString());
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 14:23:37 -03:00
|
|
|
|
2021-07-28 11:58:03 -04:00
|
|
|
private void handleSignalMeIntent(Intent intent) {
|
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null) {
|
|
|
|
CommunicationActions.handlePotentialSignalMeUrl(this, data.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:28:29 -03:00
|
|
|
private void handleCallLinkInIntent(Intent intent) {
|
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null) {
|
|
|
|
CommunicationActions.handlePotentialCallLinkUrl(this, data.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 11:39:30 -05:00
|
|
|
public void onFirstRender() {
|
|
|
|
onFirstRender = true;
|
|
|
|
}
|
|
|
|
|
2021-07-07 14:23:37 -03:00
|
|
|
@Override
|
|
|
|
public @NonNull VoiceNoteMediaController getVoiceNoteMediaController() {
|
|
|
|
return mediaController;
|
|
|
|
}
|
2019-11-14 14:35:08 -05:00
|
|
|
}
|