Skip to content

Commit

Permalink
Feature/debug menu (#1645)
Browse files Browse the repository at this point in the history
* Reorganised cells

* Clipping content

* Simplifying Cell and leaving responsibility to modifier and content

* Fixing animations

Also fixing compose copy that wasn't set up properly...

* Debug menu

Added a debug menu
It can be accessed from the settings page or via an app shortcut (from the app icon)

* Finalising the debug menu

We can now switch environments between mainnet and testnet

* Update app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenu.kt

Co-authored-by: AL-Session <[email protected]>

---------

Co-authored-by: AL-Session <[email protected]>
  • Loading branch information
ThomasSession and AL-Session authored Aug 26, 2024
1 parent bfbe4a8 commit 1393335
Show file tree
Hide file tree
Showing 29 changed files with 766 additions and 99 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-process:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.paging:paging-runtime-ktx:$pagingVersion"
implementation 'androidx.activity:activity-ktx:1.5.1'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
android:name="org.thoughtcrime.securesms.preferences.SettingsActivity"
android:screenOrientation="portrait"
android:label="@string/activity_settings_title" />
<activity
android:name="org.thoughtcrime.securesms.debugmenu.DebugActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Session.DayNight.NoActionBar" />
<activity
android:name="org.thoughtcrime.securesms.home.PathActivity"
android:screenOrientation="portrait" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import android.os.HandlerThread;

import androidx.annotation.NonNull;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ProcessLifecycleOwner;
Expand All @@ -42,6 +45,7 @@
import org.session.libsession.utilities.Address;
import org.session.libsession.utilities.ConfigFactoryUpdateListener;
import org.session.libsession.utilities.Device;
import org.session.libsession.utilities.Environment;
import org.session.libsession.utilities.ProfilePictureUtilities;
import org.session.libsession.utilities.SSKEnvironment;
import org.session.libsession.utilities.TextSecurePreferences;
Expand All @@ -62,6 +66,7 @@
import org.thoughtcrime.securesms.database.Storage;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.database.model.EmojiSearchData;
import org.thoughtcrime.securesms.debugmenu.DebugActivity;
import org.thoughtcrime.securesms.dependencies.AppComponent;
import org.thoughtcrime.securesms.dependencies.ConfigFactory;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
Expand Down Expand Up @@ -107,6 +112,7 @@
import dagger.hilt.android.HiltAndroidApp;
import kotlin.Unit;
import network.loki.messenger.BuildConfig;
import network.loki.messenger.R;
import network.loki.messenger.libsession_util.ConfigBase;
import network.loki.messenger.libsession_util.UserProfile;

Expand Down Expand Up @@ -232,7 +238,8 @@ public void onCreate() {
messageNotifier = new OptimizedMessageNotifier(new DefaultMessageNotifier());
broadcaster = new Broadcaster(this);
LokiAPIDatabase apiDB = getDatabaseComponent().lokiAPIDatabase();
SnodeModule.Companion.configure(apiDB, broadcaster);
boolean useTestNet = textSecurePreferences.getEnvironment() == Environment.TEST_NET;
SnodeModule.Companion.configure(apiDB, broadcaster, useTestNet);
initializeExpiringMessageManager();
initializeTypingStatusRepository();
initializeTypingStatusSender();
Expand All @@ -248,6 +255,22 @@ public void onCreate() {

NetworkConstraint networkConstraint = new NetworkConstraint.Factory(this).create();
HTTP.INSTANCE.setConnectedToNetwork(networkConstraint::isMet);

// add our shortcut debug menu if we are not in a release build
if (BuildConfig.BUILD_TYPE != "release") {
// add the config settings shortcut
Intent intent = new Intent(this, DebugActivity.class);
intent.setAction(Intent.ACTION_VIEW);

ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, "shortcut_debug_menu")
.setShortLabel("Debug Menu")
.setLongLabel("Debug Menu")
.setIcon(IconCompat.createWithResource(this, R.drawable.ic_settings))
.setIntent(intent)
.build();

ShortcutManagerCompat.pushDynamicShortcut(this, shortcut);
}
}

@Override
Expand Down Expand Up @@ -486,7 +509,7 @@ private void loadEmojiSearchIndexIfNeeded() {
// Method to clear the local data - returns true on success otherwise false

/**
* Clear all local profile data and message history then restart the app after a brief delay.
* Clear all local profile data and message history.
* @return true on success, false otherwise.
*/
@SuppressLint("ApplySharedPref")
Expand All @@ -498,6 +521,16 @@ public boolean clearAllData() {
return false;
}
configFactory.keyPairChanged();
return true;
}

/**
* Clear all local profile data and message history then restart the app after a brief delay.
* @return true on success, false otherwise.
*/
@SuppressLint("ApplySharedPref")
public boolean clearAllDataAndRestart() {
clearAllData();
Util.runOnMain(() -> new Handler().postDelayed(ApplicationContext.this::restartApplication, 200));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
override fun showMessageDetail(messages: Set<MessageRecord>) {
Intent(this, MessageDetailActivity::class.java)
.apply { putExtra(MESSAGE_TIMESTAMP, messages.first().timestamp) }
.let { handleMessageDetail.launch(it) }
.let {
handleMessageDetail.launch(it)
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left)
}

endActionMode()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.conversation.v2

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MotionEvent.ACTION_UP
Expand All @@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -28,13 +30,15 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
Expand All @@ -58,23 +62,21 @@ import org.thoughtcrime.securesms.ui.Avatar
import org.thoughtcrime.securesms.ui.CarouselNextButton
import org.thoughtcrime.securesms.ui.CarouselPrevButton
import org.thoughtcrime.securesms.ui.Cell
import org.thoughtcrime.securesms.ui.CellNoMargin
import org.thoughtcrime.securesms.ui.CellWithPaddingAndMargin
import org.thoughtcrime.securesms.ui.Divider
import org.thoughtcrime.securesms.ui.GetString
import org.thoughtcrime.securesms.ui.HorizontalPagerIndicator
import org.thoughtcrime.securesms.ui.LargeItemButton
import org.thoughtcrime.securesms.ui.TitledText
import org.thoughtcrime.securesms.ui.setComposeContent
import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
import org.thoughtcrime.securesms.ui.theme.PreviewTheme
import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.TitledText
import org.thoughtcrime.securesms.ui.theme.ThemeColors
import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.blackAlpha40
import org.thoughtcrime.securesms.ui.theme.dangerButtonColors
import org.thoughtcrime.securesms.ui.setComposeContent
import org.thoughtcrime.securesms.ui.theme.LocalType
import org.thoughtcrime.securesms.ui.theme.bold
import org.thoughtcrime.securesms.ui.theme.dangerButtonColors
import org.thoughtcrime.securesms.ui.theme.monospace
import javax.inject.Inject

Expand Down Expand Up @@ -191,8 +193,11 @@ fun CellMetadata(
) {
state.apply {
if (listOfNotNull(sent, received, error, senderInfo).isEmpty()) return
CellWithPaddingAndMargin {
Column(verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing)) {
Cell(modifier = Modifier.padding(horizontal = LocalDimensions.current.spacing)) {
Column(
modifier = Modifier.padding(LocalDimensions.current.spacing),
verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing)
) {
TitledText(sent)
TitledText(received)
TitledErrorText(error)
Expand All @@ -215,7 +220,7 @@ fun CellButtons(
onResend: (() -> Unit)? = null,
onDelete: () -> Unit = {},
) {
Cell {
Cell(modifier = Modifier.padding(horizontal = LocalDimensions.current.spacing)) {
Column {
onReply?.let {
LargeItemButton(
Expand Down Expand Up @@ -254,8 +259,11 @@ fun Carousel(attachments: List<Attachment>, onClick: (Int) -> Unit) {
Row {
CarouselPrevButton(pagerState)
Box(modifier = Modifier.weight(1f)) {
CellCarousel(pagerState, attachments, onClick)
HorizontalPagerIndicator(pagerState)
CarouselPager(pagerState, attachments, onClick)
HorizontalPagerIndicator(
pagerState = pagerState,
modifier = Modifier.padding(bottom = LocalDimensions.current.xxsSpacing)
)
ExpandButton(
modifier = Modifier
.align(Alignment.BottomEnd)
Expand All @@ -273,12 +281,15 @@ fun Carousel(attachments: List<Attachment>, onClick: (Int) -> Unit) {
ExperimentalGlideComposeApi::class
)
@Composable
private fun CellCarousel(
private fun CarouselPager(
pagerState: PagerState,
attachments: List<Attachment>,
onClick: (Int) -> Unit
) {
CellNoMargin {
Cell(
modifier = Modifier
.clip(MaterialTheme.shapes.small)
) {
HorizontalPager(state = pagerState) { i ->
GlideImage(
contentScale = ContentScale.Crop,
Expand Down Expand Up @@ -317,6 +328,33 @@ fun PreviewMessageDetails(
PreviewTheme(colors) {
MessageDetails(
state = MessageDetailsState(
imageAttachments = listOf(
Attachment(
fileDetails = listOf(
TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png")
),
fileName = "Screen Shot 2023-07-06 at 11.35.50 am.png",
uri = Uri.parse(""),
hasImage = true
),
Attachment(
fileDetails = listOf(
TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png")
),
fileName = "Screen Shot 2023-07-06 at 11.35.50 am.png",
uri = Uri.parse(""),
hasImage = true
),
Attachment(
fileDetails = listOf(
TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png")
),
fileName = "Screen Shot 2023-07-06 at 11.35.50 am.png",
uri = Uri.parse(""),
hasImage = true
)

),
nonImageAttachmentFileDetails = listOf(
TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png"),
TitledText(R.string.message_details_header__file_type, "image/png"),
Expand All @@ -337,7 +375,7 @@ fun PreviewMessageDetails(
fun FileDetails(fileDetails: List<TitledText>) {
if (fileDetails.isEmpty()) return

Cell {
Cell(modifier = Modifier.padding(horizontal = LocalDimensions.current.spacing)) {
FlowRow(
modifier = Modifier.padding(horizontal = LocalDimensions.current.xsSpacing, vertical = LocalDimensions.current.spacing),
verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.thoughtcrime.securesms.debugmenu

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import dagger.hilt.android.AndroidEntryPoint
import org.thoughtcrime.securesms.ui.setComposeContent


@AndroidEntryPoint
class DebugActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setComposeContent {
DebugMenuScreen(
onClose = { finish() }
)
}
}
}
Loading

0 comments on commit 1393335

Please sign in to comment.