2019-11-14 14:35:08 -05:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
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;
|
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.Transformations;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2019-11-14 14:35:08 -05:00
|
|
|
|
2021-07-07 14:23:37 -03:00
|
|
|
import org.thoughtcrime.securesms.components.voice.VoiceNoteMediaController;
|
|
|
|
import org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner;
|
2021-03-16 16:50:10 -04:00
|
|
|
import org.thoughtcrime.securesms.devicetransfer.olddevice.OldDeviceTransferLockedDialog;
|
|
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
2022-02-24 13:40:28 -04:00
|
|
|
import org.thoughtcrime.securesms.stories.tabs.ConversationListTabRepository;
|
|
|
|
import org.thoughtcrime.securesms.stories.tabs.ConversationListTabsState;
|
|
|
|
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-02-24 13:40:28 -04:00
|
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
|
|
|
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;
|
2021-07-07 14:23:37 -03:00
|
|
|
|
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);
|
|
|
|
|
2021-07-07 14:23:37 -03:00
|
|
|
mediaController = new VoiceNoteMediaController(this);
|
2022-02-24 13:40:28 -04:00
|
|
|
|
|
|
|
ConversationListTabRepository repository = new ConversationListTabRepository();
|
|
|
|
ConversationListTabsViewModel.Factory factory = new ConversationListTabsViewModel.Factory(repository);
|
|
|
|
|
2019-11-14 14:35:08 -05:00
|
|
|
navigator.onCreate(savedInstanceState);
|
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());
|
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);
|
|
|
|
Transformations.map(conversationListTabsViewModel.getState(), ConversationListTabsState::getTab)
|
|
|
|
.observe(this, tab -> {
|
|
|
|
switch (tab) {
|
|
|
|
case CHATS:
|
|
|
|
getSupportFragmentManager().popBackStack();
|
|
|
|
break;
|
|
|
|
case STORIES:
|
|
|
|
navigator.goToStories();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updateTabVisibility();
|
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);
|
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()) {
|
|
|
|
OldDeviceTransferLockedDialog.show(getSupportFragmentManager());
|
|
|
|
}
|
2022-02-24 13:40:28 -04:00
|
|
|
|
|
|
|
updateTabVisibility();
|
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() {
|
|
|
|
if (FeatureFlags.stories() && !SignalStore.storyValues().isFeatureDisabled()) {
|
|
|
|
findViewById(R.id.conversation_list_tabs).setVisibility(View.VISIBLE);
|
|
|
|
WindowUtil.setNavigationBarColor(getWindow(), ContextCompat.getColor(this, R.color.signal_background_secondary));
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.conversation_list_tabs).setVisibility(View.GONE);
|
|
|
|
WindowUtil.setNavigationBarColor(getWindow(), ContextCompat.getColor(this, R.color.signal_background_primary));
|
|
|
|
navigator.goToChats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 14:23:37 -03:00
|
|
|
@Override
|
|
|
|
public @NonNull VoiceNoteMediaController getVoiceNoteMediaController() {
|
|
|
|
return mediaController;
|
|
|
|
}
|
2019-11-14 14:35:08 -05:00
|
|
|
}
|