diff --git a/app/build.gradle b/app/build.gradle
index 94edee60ad..a1a6d43ced 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -221,11 +221,13 @@ android {
}
dependencies {
+ implementation project(':content-descriptions')
+
+ ksp("androidx.hilt:hilt-compiler:$jetpackHiltVersion")
+ ksp("com.google.dagger:hilt-compiler:$daggerHiltVersion")
+ ksp("com.github.bumptech.glide:ksp:$glideVersion")
implementation("com.google.dagger:hilt-android:$daggerHiltVersion")
- ksp("com.google.dagger:hilt-compiler:$daggerHiltVersion")
- ksp("androidx.hilt:hilt-compiler:$jetpackHiltVersion")
-
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation "com.google.android.material:material:$materialVersion"
@@ -249,12 +251,15 @@ dependencies {
implementation 'androidx.fragment:fragment-ktx:1.5.3'
implementation "androidx.core:core-ktx:$coreVersion"
implementation "androidx.work:work-runtime-ktx:2.7.1"
+
playImplementation ("com.google.firebase:firebase-messaging:24.0.0") {
exclude group: 'com.google.firebase', module: 'firebase-core'
exclude group: 'com.google.firebase', module: 'firebase-analytics'
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
}
+
if (project.hasProperty('huawei')) huaweiImplementation 'com.huawei.hms:push:6.7.0.300'
+
implementation 'androidx.media3:media3-exoplayer:1.4.0'
implementation 'androidx.media3:media3-ui:1.4.0'
implementation 'org.conscrypt:conscrypt-android:2.5.2'
@@ -268,7 +273,6 @@ dependencies {
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation "com.github.bumptech.glide:glide:$glideVersion"
implementation "com.github.bumptech.glide:compose:1.0.0-beta01"
- ksp "com.github.bumptech.glide:ksp:$glideVersion"
implementation 'com.makeramen:roundedimageview:2.1.0'
implementation 'com.pnikosis:materialish-progress:1.5'
implementation 'org.greenrobot:eventbus:3.0.0'
diff --git a/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt b/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt
index 2f3ba9fb10..43b347ba42 100644
--- a/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt
+++ b/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt
@@ -2,8 +2,6 @@ package network.loki.messenger
import android.Manifest
import android.app.Instrumentation
-import android.content.ClipboardManager
-import android.content.Context
import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
@@ -16,8 +14,6 @@ import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
-import androidx.test.espresso.matcher.ViewMatchers.withSubstring
-import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
@@ -25,6 +21,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import com.adevinta.android.barista.interaction.PermissionGranter
+import com.bumptech.glide.Glide
import network.loki.messenger.util.InputBarButtonDrawableMatcher.Companion.inputButtonWithDrawable
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
@@ -36,11 +33,9 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview
import org.session.libsession.utilities.TextSecurePreferences
-import org.session.libsignal.utilities.guava.Optional
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBar
import org.thoughtcrime.securesms.home.HomeActivity
-import com.bumptech.glide.Glide
/**
* Currently not used as part of our CI/Deployment processes !!!!
@@ -62,7 +57,6 @@ class HomeActivityTests {
@Before
fun setUp() {
InstrumentationRegistry.getInstrumentation().addMonitor(activityMonitor)
-
}
@After
@@ -96,10 +90,10 @@ class HomeActivityTests {
device.pressKeyCode(67)
// Continue with display name
- objectFromDesc(R.string.continue_2).click()
+ objectFromDesc(R.string.theContinue).click()
// Continue with default push notification setting
- objectFromDesc(R.string.continue_2).click()
+ objectFromDesc(R.string.theContinue).click()
// PN select
if (hasViewedSeed) {
@@ -110,7 +104,6 @@ class HomeActivityTests {
PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.POST_NOTIFICATIONS)
}
-
/* private fun goToMyChat() {
onView(withId(R.id.newConversationButton)).perform(ViewActions.click())
onView(withId(R.id.createPrivateChatButton)).perform(ViewActions.click())
@@ -131,7 +124,7 @@ class HomeActivityTests {
@Test
fun testLaunches_dismiss_seedView() {
setupLoggedInState()
- objectFromDesc(R.string.continue_2).click()
+ objectFromDesc(R.string.theContinue).click()
objectFromDesc(R.string.copy).click()
pressBack()
onView(withId(R.id.seedReminderView)).check(matches(not(isDisplayed())))
@@ -182,6 +175,7 @@ class HomeActivityTests {
onView(withText(dialogPromptText)).check(matches(isDisplayed()))
}*/
+
/**
* Perform action of waiting for a specific time.
*/
@@ -198,5 +192,4 @@ class HomeActivityTests {
}
}
}
-
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f8765ff7bd..eac4ef3300 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -37,7 +37,7 @@
-
+
@@ -79,7 +79,7 @@
android:networkSecurityConfig="@xml/network_security_configuration"
android:supportsRtl="true"
android:theme="@style/Theme.Session.DayNight"
- tools:replace="android:allowBackup">
+ tools:replace="android:allowBackup,android:label" >
@@ -130,12 +130,12 @@
+ android:label="@string/sessionSettings" />
@@ -268,18 +268,10 @@
-
0) {
- relativeTimeSpan = DateUtils.getDisplayFormattedTimeSpanString(this, Locale.getDefault(), mediaItem.date);
+ relativeTimeSpan = DateUtils.INSTANCE.getDisplayFormattedTimeSpanString(this, Locale.getDefault(), mediaItem.date);
} else {
- relativeTimeSpan = getString(R.string.MediaPreviewActivity_draft);
+ relativeTimeSpan = getString(R.string.draft);
}
- if (mediaItem.outgoing) getSupportActionBar().setTitle(getString(R.string.MediaPreviewActivity_you));
+ if (mediaItem.outgoing) getSupportActionBar().setTitle(getString(R.string.you));
else if (mediaItem.recipient != null) getSupportActionBar().setTitle(mediaItem.recipient.toShortString());
else getSupportActionBar().setTitle("");
@@ -258,7 +256,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
@Override
public void onResume() {
super.onResume();
-
initializeMedia();
}
@@ -291,7 +288,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
captionContainer = findViewById(R.id.media_preview_caption_container);
playbackControlsContainer = findViewById(R.id.media_preview_playback_controls_container);
- setSupportActionBar(findViewById(R.id.toolbar));
+ setSupportActionBar(findViewById(R.id.search_toolbar));
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
@@ -361,7 +358,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
private void initializeMedia() {
if (!isContentTypeSupported(initialMediaType)) {
Log.w(TAG, "Unsupported media type sent to MediaPreviewActivity, finishing.");
- Toast.makeText(getApplicationContext(), R.string.MediaPreviewActivity_unssuported_media_type, Toast.LENGTH_LONG).show();
+ Toast.makeText(getApplicationContext(), R.string.attachmentsErrorNotSupported, Toast.LENGTH_LONG).show();
finish();
}
@@ -411,12 +408,19 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
MediaItem mediaItem = getCurrentMediaItem();
if (mediaItem == null) return;
- SaveAttachmentTask.showWarningDialog(this, 1, () -> {
+ SaveAttachmentTask.showOneTimeWarningDialogOrSave(this, 1, () -> {
Permissions.with(this)
.request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
.maxSdkVersion(Build.VERSION_CODES.P)
- .withPermanentDenialDialog(getString(R.string.MediaPreviewActivity_signal_needs_the_storage_permission_in_order_to_write_to_external_storage_but_it_has_been_permanently_denied))
- .onAnyDenied(() -> Toast.makeText(this, R.string.MediaPreviewActivity_unable_to_write_to_external_storage_without_permission, Toast.LENGTH_LONG).show())
+ .withPermanentDenialDialog(Phrase.from(getApplicationContext(), R.string.permissionsStorageSaveDenied)
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .format().toString())
+ .onAnyDenied(() -> {
+ String txt = Phrase.from(getApplicationContext(), R.string.permissionsStorageSaveDenied)
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .format().toString();
+ Toast.makeText(this, txt, Toast.LENGTH_LONG).show();
+ })
.onAllGranted(() -> {
SaveAttachmentTask saveTask = new SaveAttachmentTask(MediaPreviewActivity.this);
long saveDate = (mediaItem.date > 0) ? mediaItem.date : SnodeAPI.getNowWithOffset();
@@ -482,6 +486,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
+ // TODO / WARNING: R.id values are NON-CONSTANT in Gradle 8.0+ - what would be the best way to address this?! -AL 2024/08/26
case R.id.media_preview__overview: showOverview(); return true;
case R.id.media_preview__forward: forward(); return true;
case R.id.save: saveToDisk(); return true;
@@ -532,15 +537,11 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
throw new RuntimeException("restartItem = " + restartItem + ", data.second = " + data.second + " leftIsRecent = " + leftIsRecent, e);
}
- if (item == 0) {
- viewPagerListener.onPageSelected(0);
- }
+ if (item == 0) { viewPagerListener.onPageSelected(0); }
}
@Override
- public void onLoaderReset(@NonNull Loader> loader) {
-
- }
+ public void onLoaderReset(@NonNull Loader> loader) { /* Do nothing */ }
private class ViewPagerListener implements ViewPager.OnPageChangeListener {
@@ -575,13 +576,11 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
+ /* Do nothing */
}
@Override
- public void onPageScrollStateChanged(int state) {
-
- }
+ public void onPageScrollStateChanged(int state) { /* Do nothing */ }
}
private static class SingleItemPagerAdapter extends MediaItemAdapter {
@@ -646,9 +645,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
}
@Override
- public void pause(int position) {
-
- }
+ public void pause(int position) { /* Do nothing */ }
@Override
public @Nullable View getPlaybackControls(int position) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt
index 071da43311..b45d1e9f8e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/MuteDialog.kt
@@ -4,24 +4,45 @@ import android.content.Context
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import network.loki.messenger.R
+import org.session.libsession.LocalisedTimeUtil
+import org.session.libsession.utilities.StringSubstitutionConstants.TIME_LARGE_KEY
+import org.thoughtcrime.securesms.ui.getSubbedString
import java.util.concurrent.TimeUnit
+import kotlin.time.Duration.Companion.milliseconds
+import kotlin.time.Duration.Companion.seconds
fun showMuteDialog(
context: Context,
onMuteDuration: (Long) -> Unit
): AlertDialog = context.showSessionDialog {
- title(R.string.MuteDialog_mute_notifications)
- items(Option.values().map { it.stringRes }.map(context::getString).toTypedArray()) {
- onMuteDuration(Option.values()[it].getTime())
+ title(R.string.notificationsMute)
+
+ items(Option.entries.mapIndexed { index, entry ->
+
+ if (entry.stringRes == R.string.notificationsMute) {
+ context.getString(R.string.notificationsMute)
+ } else {
+ val largeTimeUnitString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit(context, Option.entries[index].getTime().milliseconds)
+ context.getSubbedString(entry.stringRes, TIME_LARGE_KEY to largeTimeUnitString)
+ }
+ }.toTypedArray()) {
+ // Note: We add the current timestamp to the mute duration to get the un-mute timestamp
+ // that gets stored in the database via ConversationMenuHelper.mute().
+ // Also: This is a kludge, but we ADD one second to the mute duration because otherwise by
+ // the time the view for how long the conversation is muted for gets set then it's actually
+ // less than the entire duration - so 1 hour becomes 59 minutes, 1 day becomes 23 hours etc.
+ // As we really want to see the actual set time (1 hour / 1 day etc.) then we'll bump it by
+ // 1 second which is neither here nor there in the grand scheme of things.
+ onMuteDuration(Option.entries[it].getTime() + System.currentTimeMillis() + 1.seconds.inWholeMilliseconds)
}
}
private enum class Option(@StringRes val stringRes: Int, val getTime: () -> Long) {
- ONE_HOUR(R.string.arrays__mute_for_one_hour, duration = TimeUnit.HOURS.toMillis(1)),
- TWO_HOURS(R.string.arrays__mute_for_two_hours, duration = TimeUnit.HOURS.toMillis(2)),
- ONE_DAY(R.string.arrays__mute_for_one_day, duration = TimeUnit.DAYS.toMillis(1)),
- SEVEN_DAYS(R.string.arrays__mute_for_seven_days, duration = TimeUnit.DAYS.toMillis(7)),
- FOREVER(R.string.arrays__mute_forever, getTime = { Long.MAX_VALUE });
+ ONE_HOUR(R.string.notificationsMuteFor, duration = TimeUnit.HOURS.toMillis(1)),
+ TWO_HOURS(R.string.notificationsMuteFor, duration = TimeUnit.HOURS.toMillis(2)),
+ ONE_DAY(R.string.notificationsMuteFor, duration = TimeUnit.DAYS.toMillis(1)),
+ SEVEN_DAYS(R.string.notificationsMuteFor, duration = TimeUnit.DAYS.toMillis(7)),
+ FOREVER(R.string.notificationsMute, getTime = { Long.MAX_VALUE } );
- constructor(@StringRes stringRes: Int, duration: Long): this(stringRes, { System.currentTimeMillis() + duration })
-}
+ constructor(@StringRes stringRes: Int, duration: Long): this(stringRes, { duration } )
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/PassphrasePromptActivity.java b/app/src/main/java/org/thoughtcrime/securesms/PassphrasePromptActivity.java
index afc993df8a..16b5856766 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/PassphrasePromptActivity.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/PassphrasePromptActivity.java
@@ -16,6 +16,8 @@
*/
package org.thoughtcrime.securesms;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
+
import android.animation.Animator;
import android.app.KeyguardManager;
import android.content.ComponentName;
@@ -25,20 +27,18 @@ import android.content.ServiceConnection;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.os.IBinder;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.style.RelativeSizeSpan;
-import android.text.style.TypefaceSpan;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.BounceInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
-
+import android.widget.TextView;
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;
import androidx.core.os.CancellationSignal;
-
+import com.squareup.phrase.Phrase;
+import java.security.Signature;
+import network.loki.messenger.R;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsignal.utilities.Log;
import org.thoughtcrime.securesms.components.AnimatingToggle;
@@ -46,11 +46,6 @@ import org.thoughtcrime.securesms.crypto.BiometricSecretProvider;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.AnimationCompleteListener;
-import java.security.InvalidKeyException;
-import java.security.Signature;
-
-import network.loki.messenger.R;
-
//TODO Rename to ScreenLockActivity and refactor to Kotlin.
public class PassphrasePromptActivity extends BaseActionBarActivity {
@@ -158,6 +153,16 @@ public class PassphrasePromptActivity extends BaseActionBarActivity {
}
private void initializeResources() {
+
+ TextView statusTitle = findViewById(R.id.app_lock_status_title);
+ if (statusTitle != null) {
+ Context c = getApplicationContext();
+ String lockedTxt = Phrase.from(c, R.string.lockAppLocked)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+ statusTitle.setText(lockedTxt);
+ }
+
visibilityToggle = findViewById(R.id.button_toggle);
fingerprintPrompt = findViewById(R.id.fingerprint_auth_container);
lockScreenButton = findViewById(R.id.lock_screen_auth_container);
@@ -165,10 +170,6 @@ public class PassphrasePromptActivity extends BaseActionBarActivity {
fingerprintCancellationSignal = new CancellationSignal();
fingerprintListener = new FingerprintListener();
- SpannableString hint = new SpannableString(" " + getString(R.string.PassphrasePromptActivity_enter_passphrase));
- hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
- hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
-
fingerprintPrompt.setImageResource(R.drawable.ic_fingerprint_white_48dp);
fingerprintPrompt.getBackground().setColorFilter(getResources().getColor(R.color.signal_primary), PorterDuff.Mode.SRC_IN);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt
index 71e04230f2..69d58411f3 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt
@@ -1,5 +1,7 @@
package org.thoughtcrime.securesms
+import android.content.ClipData
+import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
@@ -7,12 +9,14 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
+import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.LinearLayout
import android.widget.LinearLayout.VERTICAL
import android.widget.Space
import android.widget.TextView
import androidx.annotation.AttrRes
+import androidx.annotation.ColorRes
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
@@ -30,6 +34,7 @@ annotation class DialogDsl
@DialogDsl
class SessionDialogBuilder(val context: Context) {
+ private val dp8 = toPx(8, context.resources)
private val dp20 = toPx(20, context.resources)
private val dp40 = toPx(40, context.resources)
private val dp60 = toPx(60, context.resources)
@@ -37,13 +42,15 @@ class SessionDialogBuilder(val context: Context) {
private val dialogBuilder: AlertDialog.Builder = AlertDialog.Builder(context)
private var dialog: AlertDialog? = null
- private fun dismiss() = dialog?.dismiss()
+ fun dismiss() = dialog?.dismiss()
private val topView = LinearLayout(context)
.apply { setPadding(0, dp20, 0, 0) }
.apply { orientation = VERTICAL }
.also(dialogBuilder::setCustomTitle)
+
private val contentView = LinearLayout(context).apply { orientation = VERTICAL }
+
private val buttonLayout = LinearLayout(context)
private val root = LinearLayout(context).apply { orientation = VERTICAL }
@@ -53,24 +60,29 @@ class SessionDialogBuilder(val context: Context) {
addView(buttonLayout)
}
- fun title(@StringRes id: Int) = title(context.getString(id))
-
- fun title(text: CharSequence?) = title(text?.toString())
+ // Main title entry point
fun title(text: String?) {
- text(text, R.style.TextAppearance_AppCompat_Title) { setPadding(dp20, 0, dp20, 0) }
+ text(text, R.style.TextAppearance_Session_Dialog_Title) { setPadding(dp20, 0, dp20, 0) }
}
- fun text(@StringRes id: Int, style: Int = 0) = text(context.getString(id), style)
- fun text(text: CharSequence?, @StyleRes style: Int = 0) {
+ // Convenience assessor for title that takes a string resource
+ fun title(@StringRes id: Int) = title(context.getString(id))
+
+ // Convenience accessor for title that takes a CharSequence
+ fun title(text: CharSequence?) = title(text?.toString())
+
+ fun text(@StringRes id: Int, style: Int? = null) = text(context.getString(id), style)
+
+ fun text(text: CharSequence?, @StyleRes style: Int? = null) {
text(text, style) {
layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
.apply { updateMargins(dp40, 0, dp40, 0) }
}
}
- private fun text(text: CharSequence?, @StyleRes style: Int, modify: TextView.() -> Unit) {
+ private fun text(text: CharSequence?, @StyleRes style: Int? = null, modify: TextView.() -> Unit) {
text ?: return
- TextView(context, null, 0, style)
+ TextView(context, null, 0, style ?: R.style.TextAppearance_Session_Dialog_Message)
.apply {
setText(text)
textAlignment = View.TEXT_ALIGNMENT_CENTER
@@ -78,7 +90,7 @@ class SessionDialogBuilder(val context: Context) {
}.let(topView::addView)
Space(context).apply {
- layoutParams = LinearLayout.LayoutParams(0, dp20)
+ layoutParams = LinearLayout.LayoutParams(0, dp8)
}.let(topView::addView)
}
@@ -95,17 +107,31 @@ class SessionDialogBuilder(val context: Context) {
fun singleChoiceItems(
options: Collection,
currentSelected: Int = 0,
+ dismissOnRadioSelect: Boolean = true,
onSelect: (Int) -> Unit
- ) = singleChoiceItems(options.toTypedArray(), currentSelected, onSelect)
+ ) = singleChoiceItems(
+ options.toTypedArray(),
+ currentSelected,
+ dismissOnRadioSelect,
+ onSelect
+ )
fun singleChoiceItems(
options: Array,
currentSelected: Int = 0,
+ dismissOnRadioSelect: Boolean = true,
onSelect: (Int) -> Unit
- ): AlertDialog.Builder = dialogBuilder.setSingleChoiceItems(
- options,
- currentSelected
- ) { dialog, it -> onSelect(it); dialog.dismiss() }
+ ): AlertDialog.Builder{
+ val adapter = ArrayAdapter(context, R.layout.view_dialog_single_choice_item, options)
+
+ return dialogBuilder.setSingleChoiceItems(
+ adapter,
+ currentSelected
+ ) { dialog, it ->
+ onSelect(it)
+ if(dismissOnRadioSelect) dialog.dismiss()
+ }
+ }
fun items(
options: Array,
@@ -125,16 +151,21 @@ class SessionDialogBuilder(val context: Context) {
) { listener() }
fun okButton(listener: (() -> Unit) = {}) = button(android.R.string.ok) { listener() }
- fun cancelButton(listener: (() -> Unit) = {}) = button(android.R.string.cancel, R.string.AccessibilityId_cancel_button) { listener() }
+
+ fun cancelButton(listener: (() -> Unit) = {}) = button(android.R.string.cancel, R.string.AccessibilityId_cancel) { listener() }
fun button(
@StringRes text: Int,
@StringRes contentDescriptionRes: Int = text,
@StyleRes style: Int = R.style.Widget_Session_Button_Dialog_UnimportantText,
+ @ColorRes textColor: Int? = null,
dismiss: Boolean = true,
listener: (() -> Unit) = {}
) = Button(context, null, 0, style).apply {
setText(text)
+ textColor?.let{
+ setTextColor(it)
+ }
contentDescription = resources.getString(contentDescriptionRes)
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, dp60, 1f)
setOnClickListener {
@@ -149,22 +180,18 @@ class SessionDialogBuilder(val context: Context) {
fun Context.showSessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
SessionDialogBuilder(this).apply { build() }.show()
-fun Context.showOpenUrlDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
- SessionDialogBuilder(this).apply {
- title(R.string.urlOpen)
- text(R.string.urlOpenBrowser)
- build()
- }.show()
-fun Context.showOpenUrlDialog(url: String): AlertDialog =
- showOpenUrlDialog {
- okButton { openUrl(url) }
- cancelButton()
- }
+public fun Context.copyURLToClipboard(url: String) {
+ val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
+ val clip = ClipData.newPlainText(url, url)
+ clipboard.setPrimaryClip(clip)
+}
+// Method to actually open a given URL via an Intent that will use the default browser
fun Context.openUrl(url: String) = Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity)
fun Fragment.showSessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
SessionDialogBuilder(requireContext()).apply { build() }.show()
+
fun Fragment.createSessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
SessionDialogBuilder(requireContext()).apply { build() }.create()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java b/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java
index f03840c1ab..815cb5c947 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java
@@ -29,12 +29,14 @@ import android.provider.OpenableColumns;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
-
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import network.loki.messenger.R;
import org.session.libsession.utilities.Address;
import org.session.libsession.utilities.DistributionTypes;
import org.session.libsession.utilities.ViewUtil;
@@ -49,12 +51,6 @@ import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.util.MediaUtil;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import network.loki.messenger.R;
-
/**
* An activity to quickly share content with contacts
*
@@ -69,7 +65,6 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
public static final String EXTRA_ADDRESS_MARSHALLED = "address_marshalled";
public static final String EXTRA_DISTRIBUTION_TYPE = "distribution_type";
-
private ContactSelectionListFragment contactsFragment;
private SearchToolbar searchToolbar;
private ImageView searchAction;
@@ -132,7 +127,7 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
}
private void initializeToolbar() {
- Toolbar toolbar = findViewById(R.id.toolbar);
+ Toolbar toolbar = findViewById(R.id.search_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ShortcutLauncherActivity.java b/app/src/main/java/org/thoughtcrime/securesms/ShortcutLauncherActivity.java
index 37fdf2367d..2090e64925 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ShortcutLauncherActivity.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/ShortcutLauncherActivity.java
@@ -37,7 +37,7 @@ public class ShortcutLauncherActivity extends AppCompatActivity {
String serializedAddress = getIntent().getStringExtra(KEY_SERIALIZED_ADDRESS);
if (serializedAddress == null) {
- Toast.makeText(this, R.string.ShortcutLauncherActivity_invalid_shortcut, Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, R.string.invalidShortcut, Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, HomeActivity.class));
finish();
return;
diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java
index fc88656469..ac70a6024a 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java
@@ -8,10 +8,9 @@ import android.hardware.SensorManager;
import android.media.AudioManager;
import android.os.Handler;
import android.os.Message;
-import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
+import android.os.PowerManager;
import android.util.Pair;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
@@ -23,7 +22,8 @@ import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.ExoPlayer;
-
+import java.io.IOException;
+import java.lang.ref.WeakReference;
import org.jetbrains.annotations.NotNull;
import org.session.libsession.utilities.ServiceUtil;
import org.session.libsession.utilities.Util;
@@ -32,9 +32,6 @@ import org.session.libsignal.utilities.guava.Optional;
import org.thoughtcrime.securesms.attachments.AttachmentServer;
import org.thoughtcrime.securesms.mms.AudioSlide;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-
public class AudioSlidePlayer implements SensorEventListener {
private static final String TAG = AudioSlidePlayer.class.getSimpleName();
@@ -170,7 +167,6 @@ public class AudioSlidePlayer implements SensorEventListener {
}
}
-
@Override
public void onPlayerError(PlaybackException error) {
Log.w(TAG, "MediaPlayer Error: " + error);
@@ -209,9 +205,7 @@ public class AudioSlidePlayer implements SensorEventListener {
this.mediaPlayer.release();
}
- if (this.audioAttachmentServer != null) {
- this.audioAttachmentServer.stop();
- }
+ if (this.audioAttachmentServer != null) { this.audioAttachmentServer.stop(); }
sensorManager.unregisterListener(AudioSlidePlayer.this);
@@ -220,9 +214,7 @@ public class AudioSlidePlayer implements SensorEventListener {
}
public synchronized static void stopAll() {
- if (playing.isPresent()) {
- playing.get().stop();
- }
+ if (playing.isPresent()) { playing.get().stop(); }
}
public synchronized boolean isReady() {
@@ -364,9 +356,8 @@ public class AudioSlidePlayer implements SensorEventListener {
}
@Override
- public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ public void onAccuracyChanged(Sensor sensor, int accuracy) { /* Do nothing */ }
- }
public interface Listener {
void onPlayerStart(@NonNull AudioSlidePlayer player);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/avatar/AvatarSelection.kt b/app/src/main/java/org/thoughtcrime/securesms/avatar/AvatarSelection.kt
index ddf7ac5c77..f6f9634ca4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/avatar/AvatarSelection.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/avatar/AvatarSelection.kt
@@ -32,7 +32,7 @@ class AvatarSelection(
private val bgColor by lazy { activity.getColorFromAttr(android.R.attr.colorPrimary) }
private val txtColor by lazy { activity.getColorFromAttr(android.R.attr.textColorPrimary) }
private val imageScrim by lazy { ContextCompat.getColor(activity, R.color.avatar_background) }
- private val activityTitle by lazy { activity.getString(R.string.CropImageActivity_profile_avatar) }
+ private val activityTitle by lazy { activity.getString(R.string.image) }
/**
* Returns result on [.REQUEST_CODE_CROP_IMAGE]
@@ -120,7 +120,7 @@ class AvatarSelection(
val chooserIntent = Intent.createChooser(
galleryIntent,
- context.getString(R.string.CreateProfileActivity_profile_photo)
+ context.getString(R.string.image)
)
if (!extraIntents.isEmpty()) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt
index 2bded3cccb..69bcef2242 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt
@@ -13,11 +13,13 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewOutlineProvider
import android.view.WindowManager
+import android.widget.TextView
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@@ -27,6 +29,7 @@ import network.loki.messenger.R
import network.loki.messenger.databinding.ActivityWebrtcBinding
import org.apache.commons.lang3.time.DurationFormatUtils
import org.session.libsession.messaging.contacts.Contact
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.truncateIdForDisplay
import org.session.libsignal.utilities.Log
@@ -202,6 +205,10 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity() {
update()
}
}
+
+ // Substitute "Session" into the "{app_name} Call" text
+ val sessionCallTV = findViewById(R.id.sessionCallText)
+ sessionCallTV?.text = Phrase.from(this, R.string.callsSessionCall).put(APP_NAME_KEY, getString(R.string.app_name)).format()
}
/**
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java b/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java
deleted file mode 100644
index 1c6a4097f5..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java
+++ /dev/null
@@ -1,299 +0,0 @@
-package org.thoughtcrime.securesms.components;
-
-import android.Manifest;
-import android.animation.Animator;
-import android.app.Activity;
-import android.content.Context;
-import android.graphics.drawable.BitmapDrawable;
-import android.net.Uri;
-import android.util.Pair;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewAnimationUtils;
-import android.view.ViewTreeObserver;
-import android.view.animation.Animation;
-import android.view.animation.AnimationSet;
-import android.view.animation.OvershootInterpolator;
-import android.view.animation.ScaleAnimation;
-import android.view.animation.TranslateAnimation;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.PopupWindow;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.loader.app.LoaderManager;
-
-import org.session.libsession.utilities.ViewUtil;
-import org.thoughtcrime.securesms.permissions.Permissions;
-
-import network.loki.messenger.R;
-
-public class AttachmentTypeSelector extends PopupWindow {
-
- public static final int ADD_GALLERY = 1;
- public static final int ADD_DOCUMENT = 2;
- public static final int ADD_SOUND = 3;
- public static final int ADD_CONTACT_INFO = 4;
- public static final int TAKE_PHOTO = 5;
- public static final int ADD_LOCATION = 6;
- public static final int ADD_GIF = 7;
-
- private static final int ANIMATION_DURATION = 300;
-
- @SuppressWarnings("unused")
- private static final String TAG = AttachmentTypeSelector.class.getSimpleName();
-
- private final @NonNull Context context;
- public int keyboardHeight;
- private final @NonNull LoaderManager loaderManager;
- private final @NonNull RecentPhotoViewRail recentRail;
- private final @NonNull ImageView imageButton;
- private final @NonNull ImageView audioButton;
- private final @NonNull ImageView documentButton;
- private final @NonNull ImageView contactButton;
- private final @NonNull ImageView cameraButton;
- private final @NonNull ImageView locationButton;
- private final @NonNull ImageView gifButton;
- private final @NonNull ImageView closeButton;
-
- private @Nullable View currentAnchor;
- private @Nullable AttachmentClickedListener listener;
-
- public AttachmentTypeSelector(@NonNull Context context, @NonNull LoaderManager loaderManager, @Nullable AttachmentClickedListener listener, int keyboardHeight) {
- super(context);
-
- this.context = context;
- this.keyboardHeight = keyboardHeight;
-
- LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.attachment_type_selector, null, true);
-
- this.listener = listener;
- this.loaderManager = loaderManager;
- this.recentRail = ViewUtil.findById(layout, R.id.recent_photos);
- this.imageButton = ViewUtil.findById(layout, R.id.gallery_button);
- this.audioButton = ViewUtil.findById(layout, R.id.audio_button);
- this.documentButton = ViewUtil.findById(layout, R.id.document_button);
- this.contactButton = ViewUtil.findById(layout, R.id.contact_button);
- this.cameraButton = ViewUtil.findById(layout, R.id.camera_button);
- this.locationButton = ViewUtil.findById(layout, R.id.location_button);
- this.gifButton = ViewUtil.findById(layout, R.id.giphy_button);
- this.closeButton = ViewUtil.findById(layout, R.id.close_button);
-
- this.imageButton.setOnClickListener(new PropagatingClickListener(ADD_GALLERY));
- this.audioButton.setOnClickListener(new PropagatingClickListener(ADD_SOUND));
- this.documentButton.setOnClickListener(new PropagatingClickListener(ADD_DOCUMENT));
- this.contactButton.setOnClickListener(new PropagatingClickListener(ADD_CONTACT_INFO));
- this.cameraButton.setOnClickListener(new PropagatingClickListener(TAKE_PHOTO));
- this.locationButton.setOnClickListener(new PropagatingClickListener(ADD_LOCATION));
- this.gifButton.setOnClickListener(new PropagatingClickListener(ADD_GIF));
- this.closeButton.setOnClickListener(new CloseClickListener());
- this.recentRail.setListener(new RecentPhotoSelectedListener());
-
- setContentView(layout);
- setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
- setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
- setBackgroundDrawable(new BitmapDrawable());
- setAnimationStyle(0);
- setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
- setFocusable(true);
- setTouchable(true);
-
- updateHeight();
-
- loaderManager.initLoader(1, null, recentRail);
- }
-
- public void show(@NonNull Activity activity, final @NonNull View anchor) {
- updateHeight();
-
- if (Permissions.hasAll(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) {
- recentRail.setVisibility(View.VISIBLE);
- loaderManager.restartLoader(1, null, recentRail);
- } else {
- recentRail.setVisibility(View.GONE);
- }
-
- this.currentAnchor = anchor;
-
- showAtLocation(anchor, Gravity.BOTTOM, 0, 0);
-
- getContentView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- getContentView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
-
- animateWindowInCircular(anchor, getContentView());
- }
- });
-
- animateButtonIn(imageButton, ANIMATION_DURATION / 2);
- animateButtonIn(cameraButton, ANIMATION_DURATION / 2);
-
- animateButtonIn(audioButton, ANIMATION_DURATION / 3);
- animateButtonIn(locationButton, ANIMATION_DURATION / 3);
- animateButtonIn(documentButton, ANIMATION_DURATION / 4);
- animateButtonIn(gifButton, ANIMATION_DURATION / 4);
- animateButtonIn(contactButton, 0);
- animateButtonIn(closeButton, 0);
- }
-
- private void updateHeight() {
- int thresholdInDP = 120;
- float scale = context.getResources().getDisplayMetrics().density;
- int thresholdInPX = (int)(thresholdInDP * scale);
- View contentView = ViewUtil.findById(getContentView(), R.id.contentView);
- LinearLayout.LayoutParams contentViewLayoutParams = (LinearLayout.LayoutParams)contentView.getLayoutParams();
- contentViewLayoutParams.height = keyboardHeight > thresholdInPX ? keyboardHeight : LinearLayout.LayoutParams.WRAP_CONTENT;
- contentView.setLayoutParams(contentViewLayoutParams);
- }
-
- @Override
- public void dismiss() {
- animateWindowOutCircular(currentAnchor, getContentView());
- }
-
- public void setListener(@Nullable AttachmentClickedListener listener) {
- this.listener = listener;
- }
-
- private void animateButtonIn(View button, int delay) {
- AnimationSet animation = new AnimationSet(true);
- Animation scale = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
- Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.0f);
-
- animation.addAnimation(scale);
- animation.setInterpolator(new OvershootInterpolator(1));
- animation.setDuration(ANIMATION_DURATION);
- animation.setStartOffset(delay);
- button.startAnimation(animation);
- }
-
- private void animateWindowInCircular(@Nullable View anchor, @NonNull View contentView) {
- Pair coordinates = getClickOrigin(anchor, contentView);
- Animator animator = ViewAnimationUtils.createCircularReveal(contentView,
- coordinates.first,
- coordinates.second,
- 0,
- Math.max(contentView.getWidth(), contentView.getHeight()));
- animator.setDuration(ANIMATION_DURATION);
- animator.start();
- }
-
- private void animateWindowInTranslate(@NonNull View contentView) {
- Animation animation = new TranslateAnimation(0, 0, contentView.getHeight(), 0);
- animation.setDuration(ANIMATION_DURATION);
-
- getContentView().startAnimation(animation);
- }
-
- private void animateWindowOutCircular(@Nullable View anchor, @NonNull View contentView) {
- Pair coordinates = getClickOrigin(anchor, contentView);
- Animator animator = ViewAnimationUtils.createCircularReveal(getContentView(),
- coordinates.first,
- coordinates.second,
- Math.max(getContentView().getWidth(), getContentView().getHeight()),
- 0);
-
- animator.setDuration(ANIMATION_DURATION);
- animator.addListener(new Animator.AnimatorListener() {
- @Override
- public void onAnimationStart(Animator animation) {
- }
-
- @Override
- public void onAnimationEnd(Animator animation) {
- AttachmentTypeSelector.super.dismiss();
- }
-
- @Override
- public void onAnimationCancel(Animator animation) {
- }
-
- @Override
- public void onAnimationRepeat(Animator animation) {
- }
- });
-
- animator.start();
- }
-
- private void animateWindowOutTranslate(@NonNull View contentView) {
- Animation animation = new TranslateAnimation(0, 0, 0, contentView.getTop() + contentView.getHeight());
- animation.setDuration(ANIMATION_DURATION);
- animation.setAnimationListener(new Animation.AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- AttachmentTypeSelector.super.dismiss();
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- });
-
- getContentView().startAnimation(animation);
- }
-
- private Pair getClickOrigin(@Nullable View anchor, @NonNull View contentView) {
- if (anchor == null) return new Pair<>(0, 0);
-
- final int[] anchorCoordinates = new int[2];
- anchor.getLocationOnScreen(anchorCoordinates);
- anchorCoordinates[0] += anchor.getWidth() / 2;
- anchorCoordinates[1] += anchor.getHeight() / 2;
-
- final int[] contentCoordinates = new int[2];
- contentView.getLocationOnScreen(contentCoordinates);
-
- int x = anchorCoordinates[0] - contentCoordinates[0];
- int y = anchorCoordinates[1] - contentCoordinates[1];
-
- return new Pair<>(x, y);
- }
-
- private class RecentPhotoSelectedListener implements RecentPhotoViewRail.OnItemClickedListener {
- @Override
- public void onItemClicked(Uri uri, String mimeType, String bucketId, long dateTaken, int width, int height, long size) {
- animateWindowOutTranslate(getContentView());
-
- if (listener != null) listener.onQuickAttachment(uri, mimeType, bucketId, dateTaken, width, height, size);
- }
- }
-
- private class PropagatingClickListener implements View.OnClickListener {
-
- private final int type;
-
- private PropagatingClickListener(int type) {
- this.type = type;
- }
-
- @Override
- public void onClick(View v) {
- animateWindowOutTranslate(getContentView());
-
- if (listener != null) listener.onClick(type);
- }
-
- }
-
- private class CloseClickListener implements View.OnClickListener {
- @Override
- public void onClick(View v) {
- dismiss();
- }
- }
-
- public interface AttachmentClickedListener {
- void onClick(int type);
- void onQuickAttachment(Uri uri, String mimeType, String bucketId, long dateTaken, int width, int height, long size);
- }
-
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java b/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java
deleted file mode 100644
index 178803a9f0..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/components/CustomDefaultPreference.java
+++ /dev/null
@@ -1,259 +0,0 @@
-package org.thoughtcrime.securesms.components;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
-import androidx.preference.DialogPreference;
-import androidx.preference.PreferenceDialogFragmentCompat;
-import android.text.Editable;
-import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.util.AttributeSet;
-import org.session.libsignal.utilities.Log;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.Spinner;
-import android.widget.TextView;
-
-import network.loki.messenger.R;
-import org.thoughtcrime.securesms.components.CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.CustomPreferenceValidator;
-import org.session.libsession.utilities.TextSecurePreferences;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-
-public class CustomDefaultPreference extends DialogPreference {
-
- private static final String TAG = CustomDefaultPreference.class.getSimpleName();
-
- private final int inputType;
- private final String customPreference;
- private final String customToggle;
-
- private CustomPreferenceValidator validator;
- private String defaultValue;
-
- public CustomDefaultPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- int[] attributeNames = new int[]{android.R.attr.inputType, R.attr.custom_pref_toggle};
- TypedArray attributes = context.obtainStyledAttributes(attrs, attributeNames);
-
- this.inputType = attributes.getInt(0, 0);
- this.customPreference = getKey();
- this.customToggle = attributes.getString(1);
- this.validator = new CustomDefaultPreferenceDialogFragmentCompat.NullValidator();
-
- attributes.recycle();
-
- setPersistent(false);
- setDialogLayoutResource(R.layout.custom_default_preference_dialog);
- }
-
- public CustomDefaultPreference setValidator(CustomPreferenceValidator validator) {
- this.validator = validator;
- return this;
- }
-
- public CustomDefaultPreference setDefaultValue(String defaultValue) {
- this.defaultValue = defaultValue;
- this.setSummary(getSummary());
- return this;
- }
-
- @Override
- public String getSummary() {
- if (isCustom()) {
- return getContext().getString(R.string.CustomDefaultPreference_using_custom,
- getPrettyPrintValue(getCustomValue()));
- } else {
- return getContext().getString(R.string.CustomDefaultPreference_using_default,
- getPrettyPrintValue(getDefaultValue()));
- }
- }
-
- private String getPrettyPrintValue(String value) {
- if (TextUtils.isEmpty(value)) return getContext().getString(R.string.CustomDefaultPreference_none);
- else return value;
- }
-
- private boolean isCustom() {
- return TextSecurePreferences.getBooleanPreference(getContext(), customToggle, false);
- }
-
- private void setCustom(boolean custom) {
- TextSecurePreferences.setBooleanPreference(getContext(), customToggle, custom);
- }
-
- private String getCustomValue() {
- return TextSecurePreferences.getStringPreference(getContext(), customPreference, "");
- }
-
- private void setCustomValue(String value) {
- TextSecurePreferences.setStringPreference(getContext(), customPreference, value);
- }
-
- private String getDefaultValue() {
- return defaultValue;
- }
-
-
- public static class CustomDefaultPreferenceDialogFragmentCompat extends PreferenceDialogFragmentCompat {
-
- private static final String INPUT_TYPE = "input_type";
-
- private Spinner spinner;
- private EditText customText;
- private TextView defaultLabel;
-
- public static CustomDefaultPreferenceDialogFragmentCompat newInstance(String key) {
- CustomDefaultPreferenceDialogFragmentCompat fragment = new CustomDefaultPreferenceDialogFragmentCompat();
- Bundle b = new Bundle(1);
- b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key);
- fragment.setArguments(b);
- return fragment;
- }
-
- @Override
- protected void onBindDialogView(@NonNull View view) {
- Log.i(TAG, "onBindDialogView");
- super.onBindDialogView(view);
-
- CustomDefaultPreference preference = (CustomDefaultPreference)getPreference();
-
- this.spinner = (Spinner) view.findViewById(R.id.default_or_custom);
- this.defaultLabel = (TextView) view.findViewById(R.id.default_label);
- this.customText = (EditText) view.findViewById(R.id.custom_edit);
-
- this.customText.setInputType(preference.inputType);
- this.customText.addTextChangedListener(new TextValidator());
- this.customText.setText(preference.getCustomValue());
- this.spinner.setOnItemSelectedListener(new SelectionLister());
- this.defaultLabel.setText(preference.getPrettyPrintValue(preference.defaultValue));
- }
-
-
- @Override
- public @NonNull Dialog onCreateDialog(Bundle instanceState) {
- Dialog dialog = super.onCreateDialog(instanceState);
-
- CustomDefaultPreference preference = (CustomDefaultPreference)getPreference();
-
- if (preference.isCustom()) spinner.setSelection(1, true);
- else spinner.setSelection(0, true);
-
- return dialog;
- }
-
- @Override
- public void onDialogClosed(boolean positiveResult) {
- CustomDefaultPreference preference = (CustomDefaultPreference)getPreference();
-
- if (positiveResult) {
- if (spinner != null) preference.setCustom(spinner.getSelectedItemPosition() == 1);
- if (customText != null) preference.setCustomValue(customText.getText().toString());
-
- preference.setSummary(preference.getSummary());
- }
- }
-
- interface CustomPreferenceValidator {
- public boolean isValid(String value);
- }
-
- private static class NullValidator implements CustomPreferenceValidator {
- @Override
- public boolean isValid(String value) {
- return true;
- }
- }
-
- private class TextValidator implements TextWatcher {
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
-
- @Override
- public void afterTextChanged(Editable s) {
- CustomDefaultPreference preference = (CustomDefaultPreference)getPreference();
-
- if (spinner.getSelectedItemPosition() == 1) {
- Button positiveButton = ((AlertDialog)getDialog()).getButton(AlertDialog.BUTTON_POSITIVE);
- positiveButton.setEnabled(preference.validator.isValid(s.toString()));
- }
- }
- }
-
- public static class UriValidator implements CustomPreferenceValidator {
- @Override
- public boolean isValid(String value) {
- if (TextUtils.isEmpty(value)) return true;
-
- try {
- new URI(value);
- return true;
- } catch (URISyntaxException mue) {
- return false;
- }
- }
- }
-
- public static class HostnameValidator implements CustomPreferenceValidator {
- @Override
- public boolean isValid(String value) {
- if (TextUtils.isEmpty(value)) return true;
-
- try {
- URI uri = new URI(null, value, null, null);
- return true;
- } catch (URISyntaxException mue) {
- return false;
- }
- }
- }
-
- public static class PortValidator implements CustomPreferenceValidator {
- @Override
- public boolean isValid(String value) {
- try {
- Integer.parseInt(value);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
- }
-
- private class SelectionLister implements AdapterView.OnItemSelectedListener {
-
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- CustomDefaultPreference preference = (CustomDefaultPreference)getPreference();
- Button positiveButton = ((AlertDialog)getDialog()).getButton(AlertDialog.BUTTON_POSITIVE);
-
- defaultLabel.setVisibility(position == 0 ? View.VISIBLE : View.GONE);
- customText.setVisibility(position == 0 ? View.GONE : View.VISIBLE);
- positiveButton.setEnabled(position == 0 || preference.validator.isValid(customText.getText().toString()));
- }
-
- @Override
- public void onNothingSelected(AdapterView> parent) {
- defaultLabel.setVisibility(View.VISIBLE);
- customText.setVisibility(View.GONE);
- }
- }
-
- }
-
-
-
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/DocumentView.java b/app/src/main/java/org/thoughtcrime/securesms/components/DocumentView.java
index d1d70fdac0..f51b4a7d93 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/components/DocumentView.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/components/DocumentView.java
@@ -105,7 +105,7 @@ public class DocumentView extends FrameLayout {
this.documentSlide = documentSlide;
- this.fileName.setText(documentSlide.getFileName().or(getContext().getString(R.string.DocumentView_unknown_file)));
+ this.fileName.setText(documentSlide.getFileName().or(getContext().getString(R.string.attachmentsErrorNotSupported)));
this.fileSize.setText(Util.getPrettyFileSize(documentSlide.getFileSize()));
this.document.setText(getFileType(documentSlide.getFileName()));
this.setOnClickListener(new OpenClickedListener(documentSlide));
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/FromTextView.java b/app/src/main/java/org/thoughtcrime/securesms/components/FromTextView.java
index d98c56ede5..ae9f5e6e70 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/components/FromTextView.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/components/FromTextView.java
@@ -54,7 +54,7 @@ public class FromTextView extends EmojiTextView {
if (recipient.isLocalNumber()) {
- builder.append(getContext().getString(R.string.note_to_self));
+ builder.append(getContext().getString(R.string.noteToSelf));
} else if (recipient.getName() == null && !TextUtils.isEmpty(recipient.getProfileName())) {
SpannableString profileName = new SpannableString(" (~" + recipient.getProfileName() + ") ");
profileName.setSpan(new CenterAlignedRelativeSizeSpan(0.75f), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java b/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java
index 07d0883bd2..37d5cfad05 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java
@@ -44,10 +44,9 @@ public class SearchToolbar extends LinearLayout {
inflate(getContext(), R.layout.search_toolbar, this);
setOrientation(VERTICAL);
- Toolbar toolbar = findViewById(R.id.toolbar);
+ Toolbar toolbar = findViewById(R.id.search_toolbar);
- toolbar.setNavigationIcon(
- getContext().getResources().getDrawable(R.drawable.ic_baseline_clear_24));
+ toolbar.setNavigationIcon(getContext().getResources().getDrawable(R.drawable.ic_baseline_clear_24));
toolbar.inflateMenu(R.menu.conversation_list_search);
this.searchItem = toolbar.getMenu().findItem(R.id.action_filter_search);
@@ -56,8 +55,8 @@ public class SearchToolbar extends LinearLayout {
searchView.setSubmitButtonEnabled(false);
- if (searchText != null) searchText.setHint(R.string.SearchToolbar_search);
- else searchView.setQueryHint(getResources().getString(R.string.SearchToolbar_search));
+ if (searchText != null) searchText.setHint(R.string.search);
+ else searchView.setQueryHint(getResources().getString(R.string.search));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/SwitchPreferenceCompat.java b/app/src/main/java/org/thoughtcrime/securesms/components/SwitchPreferenceCompat.java
deleted file mode 100644
index 6e7993a575..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/components/SwitchPreferenceCompat.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.thoughtcrime.securesms.components;
-
-import android.content.Context;
-import android.util.AttributeSet;
-
-import androidx.preference.CheckBoxPreference;
-import androidx.preference.Preference;
-
-import network.loki.messenger.R;
-
-public class SwitchPreferenceCompat extends CheckBoxPreference {
-
- private Preference.OnPreferenceClickListener listener;
-
- public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- setLayoutRes();
- }
-
- public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- setLayoutRes();
- }
-
- public SwitchPreferenceCompat(Context context, AttributeSet attrs) {
- super(context, attrs);
- setLayoutRes();
- }
-
- public SwitchPreferenceCompat(Context context) {
- super(context);
- setLayoutRes();
- }
-
- private void setLayoutRes() {
- setWidgetLayoutResource(R.layout.switch_compat_preference);
- }
-
- @Override
- public void setOnPreferenceClickListener(Preference.OnPreferenceClickListener listener) {
- this.listener = listener;
- }
-
- @Override
- protected void onClick() {
- if (listener == null || !listener.onPreferenceClick(this)) {
- super.onClick();
- }
- }
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/SwitchPreferenceCompat.kt b/app/src/main/java/org/thoughtcrime/securesms/components/SwitchPreferenceCompat.kt
new file mode 100644
index 0000000000..9161dd828d
--- /dev/null
+++ b/app/src/main/java/org/thoughtcrime/securesms/components/SwitchPreferenceCompat.kt
@@ -0,0 +1,59 @@
+package org.thoughtcrime.securesms.components
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.preference.CheckBoxPreference
+import com.squareup.phrase.Phrase
+import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
+import org.thoughtcrime.securesms.ui.getSubbedString
+
+class SwitchPreferenceCompat : CheckBoxPreference {
+ private var listener: OnPreferenceClickListener? = null
+
+ constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context!!, attrs, defStyleAttr) {
+ setLayoutRes()
+ }
+
+ constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context!!, attrs, defStyleAttr, defStyleRes) {
+ setLayoutRes()
+ }
+
+ constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {
+ setLayoutRes()
+ }
+
+ constructor(context: Context?) : super(context!!) {
+ setLayoutRes()
+ }
+
+ private fun setLayoutRes() {
+ widgetLayoutResource = R.layout.switch_compat_preference
+
+ if (this.hasKey()) {
+ val key = this.key
+
+ // Substitute app name into lockscreen preference summary
+ if (key.equals(LOCK_SCREEN_KEY, ignoreCase = true)) {
+ val c = context
+ val substitutedSummaryCS = c.getSubbedCharSequence(R.string.lockAppDescription, APP_NAME_KEY to c.getString(R.string.app_name))
+ this.summary = substitutedSummaryCS
+ }
+ }
+ }
+
+ override fun setOnPreferenceClickListener(listener: OnPreferenceClickListener?) {
+ this.listener = listener
+ }
+
+ override fun onClick() {
+ if (listener == null || !listener!!.onPreferenceClick(this)) {
+ super.onClick()
+ }
+ }
+
+ companion object {
+ private const val LOCK_SCREEN_KEY = "pref_android_screen_lock"
+ }
+}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java b/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java
deleted file mode 100644
index 36a607c819..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java
+++ /dev/null
@@ -1,227 +0,0 @@
-package org.thoughtcrime.securesms.components;
-
-import android.animation.LayoutTransition;
-import android.content.Context;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.core.content.ContextCompat;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.FrameLayout;
-import android.widget.TextView;
-
-import com.annimon.stream.Stream;
-import com.pnikosis.materialishprogress.ProgressWheel;
-
-import org.greenrobot.eventbus.EventBus;
-import org.greenrobot.eventbus.Subscribe;
-import org.greenrobot.eventbus.ThreadMode;
-import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
-import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress;
-import org.thoughtcrime.securesms.database.AttachmentDatabase;
-import org.thoughtcrime.securesms.events.PartProgressEvent;
-import org.thoughtcrime.securesms.mms.Slide;
-
-import org.session.libsession.utilities.ViewUtil;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import network.loki.messenger.R;
-
-public class TransferControlView extends FrameLayout {
-
- @Nullable private List slides;
- @Nullable private View current;
-
- private final ProgressWheel progressWheel;
- private final View downloadDetails;
- private final TextView downloadDetailsText;
-
- private final Map downloadProgress;
-
- public TransferControlView(Context context) {
- this(context, null);
- }
-
- public TransferControlView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public TransferControlView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- inflate(context, R.layout.transfer_controls_view, this);
-
- setLongClickable(false);
- ViewUtil.setBackground(this, ContextCompat.getDrawable(context, R.drawable.transfer_controls_background));
- setVisibility(GONE);
- setLayoutTransition(new LayoutTransition());
-
- this.downloadProgress = new HashMap<>();
- this.progressWheel = ViewUtil.findById(this, R.id.progress_wheel);
- this.downloadDetails = ViewUtil.findById(this, R.id.download_details);
- this.downloadDetailsText = ViewUtil.findById(this, R.id.download_details_text);
- }
-
- @Override
- public void setFocusable(boolean focusable) {
- super.setFocusable(focusable);
- downloadDetails.setFocusable(focusable);
- }
-
- @Override
- public void setClickable(boolean clickable) {
- super.setClickable(clickable);
- downloadDetails.setClickable(clickable);
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().register(this);
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- EventBus.getDefault().unregister(this);
- }
-
- public void setSlide(final @NonNull Slide slides) {
- setSlides(Collections.singletonList(slides));
- }
-
- public void setSlides(final @NonNull List slides) {
- if (slides.isEmpty()) {
- throw new IllegalArgumentException("Must provide at least one slide.");
- }
-
- this.slides = slides;
-
- if (!isUpdateToExistingSet(slides)) {
- downloadProgress.clear();
- Stream.of(slides).forEach(s -> downloadProgress.put(s.asAttachment(), 0f));
- }
-
- for (Slide slide : slides) {
- if (slide.asAttachment().getTransferState() == AttachmentTransferProgress.TRANSFER_PROGRESS_DONE) {
- downloadProgress.put(slide.asAttachment(), 1f);
- }
- }
-
- switch (getTransferState(slides)) {
- case AttachmentTransferProgress.TRANSFER_PROGRESS_STARTED:
- showProgressSpinner(calculateProgress(downloadProgress));
- break;
- case AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING:
- case AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED:
- downloadDetailsText.setText(getDownloadText(this.slides));
- display(downloadDetails);
- break;
- default:
- display(null);
- break;
- }
- }
-
- public void showProgressSpinner() {
- showProgressSpinner(calculateProgress(downloadProgress));
- }
-
- public void showProgressSpinner(float progress) {
- if (progress == 0) {
- progressWheel.spin();
- } else {
- progressWheel.setInstantProgress(progress);
- }
-
- display(progressWheel);
- }
-
- public void setDownloadClickListener(final @Nullable OnClickListener listener) {
- downloadDetails.setOnClickListener(listener);
- }
-
- public void clear() {
- clearAnimation();
- setVisibility(GONE);
- if (current != null) {
- current.clearAnimation();
- current.setVisibility(GONE);
- }
- current = null;
- slides = null;
- }
-
- public void setShowDownloadText(boolean showDownloadText) {
- downloadDetailsText.setVisibility(showDownloadText ? VISIBLE : GONE);
- forceLayout();
- }
-
- private boolean isUpdateToExistingSet(@NonNull List slides) {
- if (slides.size() != downloadProgress.size()) {
- return false;
- }
-
- for (Slide slide : slides) {
- if (!downloadProgress.containsKey(slide.asAttachment())) {
- return false;
- }
- }
-
- return true;
- }
-
- private int getTransferState(@NonNull List slides) {
- int transferState = AttachmentTransferProgress.TRANSFER_PROGRESS_DONE;
- for (Slide slide : slides) {
- if (slide.getTransferState() == AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING && transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_DONE) {
- transferState = slide.getTransferState();
- } else {
- transferState = Math.max(transferState, slide.getTransferState());
- }
- }
- return transferState;
- }
-
- private String getDownloadText(@NonNull List slides) {
- if (slides.size() == 1) {
- return slides.get(0).getContentDescription();
- } else {
- int downloadCount = Stream.of(slides).reduce(0, (count, slide) -> slide.getTransferState() != AttachmentTransferProgress.TRANSFER_PROGRESS_DONE ? count + 1 : count);
- return getContext().getResources().getQuantityString(R.plurals.TransferControlView_n_items, downloadCount, downloadCount);
- }
- }
-
- private void display(@Nullable final View view) {
- if (current != null) {
- current.setVisibility(GONE);
- }
-
- if (view != null) {
- view.setVisibility(VISIBLE);
- } else {
- setVisibility(GONE);
- }
-
- current = view;
- }
-
- private float calculateProgress(@NonNull Map downloadProgress) {
- float totalProgress = 0;
- for (float progress : downloadProgress.values()) {
- totalProgress += progress / downloadProgress.size();
- }
- return totalProgress;
- }
-
- @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
- public void onEventAsync(final PartProgressEvent event) {
- if (downloadProgress.containsKey(event.attachment)) {
- downloadProgress.put(event.attachment, ((float) event.progress) / event.total);
- progressWheel.setInstantProgress(calculateProgress(downloadProgress));
- }
- }
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.kt b/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.kt
new file mode 100644
index 0000000000..03604079a5
--- /dev/null
+++ b/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.kt
@@ -0,0 +1,182 @@
+package org.thoughtcrime.securesms.components
+
+import android.animation.LayoutTransition
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import android.widget.FrameLayout
+import android.widget.TextView
+import androidx.core.content.ContextCompat
+import com.annimon.stream.Stream
+import com.pnikosis.materialishprogress.ProgressWheel
+import kotlin.math.max
+import network.loki.messenger.R
+import org.greenrobot.eventbus.EventBus
+import org.greenrobot.eventbus.Subscribe
+import org.greenrobot.eventbus.ThreadMode
+import org.session.libsession.messaging.sending_receiving.attachments.Attachment
+import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
+import org.session.libsession.utilities.ViewUtil
+import org.thoughtcrime.securesms.events.PartProgressEvent
+import org.thoughtcrime.securesms.mms.Slide
+import org.thoughtcrime.securesms.ui.getSubbedString
+
+class TransferControlView @JvmOverloads constructor(context: Context?, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context!!, attrs, defStyleAttr) {
+ private var slides: List? = null
+ private var current: View? = null
+
+ private val progressWheel: ProgressWheel
+ private val downloadDetails: View
+ private val downloadDetailsText: TextView
+ private val downloadProgress: MutableMap
+
+ init {
+ inflate(context, R.layout.transfer_controls_view, this)
+
+ isLongClickable = false
+ ViewUtil.setBackground(this, ContextCompat.getDrawable(context!!, R.drawable.transfer_controls_background))
+ visibility = GONE
+ layoutTransition = LayoutTransition()
+
+ this.downloadProgress = HashMap()
+ this.progressWheel = ViewUtil.findById(this, R.id.progress_wheel)
+ this.downloadDetails = ViewUtil.findById(this, R.id.download_details)
+ this.downloadDetailsText = ViewUtil.findById(this, R.id.download_details_text)
+ }
+
+ override fun setFocusable(focusable: Boolean) {
+ super.setFocusable(focusable)
+ downloadDetails.isFocusable = focusable
+ }
+
+ override fun setClickable(clickable: Boolean) {
+ super.setClickable(clickable)
+ downloadDetails.isClickable = clickable
+ }
+
+ override fun onAttachedToWindow() {
+ super.onAttachedToWindow()
+ if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().register(this)
+ }
+
+ override fun onDetachedFromWindow() {
+ super.onDetachedFromWindow()
+ EventBus.getDefault().unregister(this)
+ }
+
+ private fun setSlides(slides: List) {
+ require(slides.isNotEmpty()) { "Must provide at least one slide." }
+
+ this.slides = slides
+
+ if (!isUpdateToExistingSet(slides)) {
+ downloadProgress.clear()
+ Stream.of(slides).forEach { s: Slide -> downloadProgress[s.asAttachment()] = 0f }
+ }
+
+ for (slide in slides) {
+ if (slide.asAttachment().transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_DONE) {
+ downloadProgress[slide.asAttachment()] = 1f
+ }
+ }
+
+ when (getTransferState(slides)) {
+ AttachmentTransferProgress.TRANSFER_PROGRESS_STARTED -> showProgressSpinner(calculateProgress(downloadProgress))
+ AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING, AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED -> {
+ downloadDetailsText.text = getDownloadText(this.slides!!)
+ display(downloadDetails)
+ }
+
+ else -> display(null)
+ }
+ }
+
+ @JvmOverloads
+ fun showProgressSpinner(progress: Float = calculateProgress(downloadProgress)) {
+ if (progress == 0f) {
+ progressWheel.spin()
+ } else {
+ progressWheel.setInstantProgress(progress)
+ }
+ display(progressWheel)
+ }
+
+ fun clear() {
+ clearAnimation()
+ visibility = GONE
+ if (current != null) {
+ current!!.clearAnimation()
+ current!!.visibility = GONE
+ }
+ current = null
+ slides = null
+ }
+
+ private fun isUpdateToExistingSet(slides: List): Boolean {
+ if (slides.size != downloadProgress.size) {
+ return false
+ }
+
+ for (slide in slides) {
+ if (!downloadProgress.containsKey(slide.asAttachment())) {
+ return false
+ }
+ }
+
+ return true
+ }
+
+ private fun getTransferState(slides: List): Int {
+ var transferState = AttachmentTransferProgress.TRANSFER_PROGRESS_DONE
+ for (slide in slides) {
+ transferState = if (slide.transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING && transferState == AttachmentTransferProgress.TRANSFER_PROGRESS_DONE) {
+ slide.transferState
+ } else {
+ max(transferState.toDouble(), slide.transferState.toDouble()).toInt()
+ }
+ }
+ return transferState
+ }
+
+ private fun getDownloadText(slides: List): String {
+ if (slides.size == 1) {
+ return slides[0].contentDescription
+ } else {
+ val downloadCount = Stream.of(slides).reduce(0) { count: Int, slide: Slide ->
+ if (slide.transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_DONE) count + 1 else count
+ }
+ return context.getSubbedString(R.string.andMore, COUNT_KEY to downloadCount.toString())
+ }
+ }
+
+ private fun display(view: View?) {
+ if (current != null) {
+ current!!.visibility = GONE
+ }
+
+ if (view != null) {
+ view.visibility = VISIBLE
+ } else {
+ visibility = GONE
+ }
+
+ current = view
+ }
+
+ private fun calculateProgress(downloadProgress: Map): Float {
+ var totalProgress = 0f
+ for (progress in downloadProgress.values) {
+ totalProgress += progress / downloadProgress.size
+ }
+ return totalProgress
+ }
+
+ @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
+ fun onEventAsync(event: PartProgressEvent) {
+ if (downloadProgress.containsKey(event.attachment)) {
+ downloadProgress[event.attachment] = event.progress.toFloat() / event.total
+ progressWheel.setInstantProgress(calculateProgress(downloadProgress))
+ }
+ }
+}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiPages.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiPages.java
index 78d085fb71..dddcb56a8e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiPages.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiPages.java
@@ -1,13 +1,9 @@
package org.thoughtcrime.securesms.components.emoji;
import android.net.Uri;
-
import network.loki.messenger.R;
-import org.session.libsignal.utilities.Pair;
import org.thoughtcrime.securesms.emoji.EmojiCategory;
-
import java.util.Arrays;
-import java.util.LinkedList;
import java.util.List;
class EmojiPages {
@@ -58,24 +54,6 @@ class EmojiPages {
new Emoji("\ud83c\udfc1"), new Emoji("\ud83d\udea9"), new Emoji("\ud83c\udf8c"), new Emoji("\ud83c\udff4"), new Emoji("\ud83c\udff3\ufe0f"), new Emoji("\ud83c\udff3\ufe0f\u200d\ud83c\udf08"), new Emoji("\ud83c\udde6\ud83c\udde8"), new Emoji("\ud83c\udde6\ud83c\udde9"), new Emoji("\ud83c\udde6\ud83c\uddea"), new Emoji("\ud83c\udde6\ud83c\uddeb"), new Emoji("\ud83c\udde6\ud83c\uddec"), new Emoji("\ud83c\udde6\ud83c\uddee"), new Emoji("\ud83c\udde6\ud83c\uddf1"), new Emoji("\ud83c\udde6\ud83c\uddf2"), new Emoji("\ud83c\udde6\ud83c\uddf4"), new Emoji("\ud83c\udde6\ud83c\uddf6"), new Emoji("\ud83c\udde6\ud83c\uddf7"), new Emoji("\ud83c\udde6\ud83c\uddf8"), new Emoji("\ud83c\udde6\ud83c\uddf9"), new Emoji("\ud83c\udde6\ud83c\uddfa"), new Emoji("\ud83c\udde6\ud83c\uddfc"), new Emoji("\ud83c\udde6\ud83c\uddfd"), new Emoji("\ud83c\udde6\ud83c\uddff"), new Emoji("\ud83c\udde7\ud83c\udde6"), new Emoji("\ud83c\udde7\ud83c\udde7"), new Emoji("\ud83c\udde7\ud83c\udde9"), new Emoji("\ud83c\udde7\ud83c\uddea"), new Emoji("\ud83c\udde7\ud83c\uddeb"), new Emoji("\ud83c\udde7\ud83c\uddec"), new Emoji("\ud83c\udde7\ud83c\udded"), new Emoji("\ud83c\udde7\ud83c\uddee"), new Emoji("\ud83c\udde7\ud83c\uddef"), new Emoji("\ud83c\udde7\ud83c\uddf1"), new Emoji("\ud83c\udde7\ud83c\uddf2"), new Emoji("\ud83c\udde7\ud83c\uddf3"), new Emoji("\ud83c\udde7\ud83c\uddf4"), new Emoji("\ud83c\udde7\ud83c\uddf6"), new Emoji("\ud83c\udde7\ud83c\uddf7"), new Emoji("\ud83c\udde7\ud83c\uddf8"), new Emoji("\ud83c\udde7\ud83c\uddf9"), new Emoji("\ud83c\udde7\ud83c\uddfb"), new Emoji("\ud83c\udde7\ud83c\uddfc"), new Emoji("\ud83c\udde7\ud83c\uddfe"), new Emoji("\ud83c\udde7\ud83c\uddff"), new Emoji("\ud83c\udde8\ud83c\udde6"), new Emoji("\ud83c\udde8\ud83c\udde8"), new Emoji("\ud83c\udde8\ud83c\udde9"), new Emoji("\ud83c\udde8\ud83c\uddeb"), new Emoji("\ud83c\udde8\ud83c\uddec"), new Emoji("\ud83c\udde8\ud83c\udded"), new Emoji("\ud83c\udde8\ud83c\uddee"), new Emoji("\ud83c\udde8\ud83c\uddf0"), new Emoji("\ud83c\udde8\ud83c\uddf1"), new Emoji("\ud83c\udde8\ud83c\uddf2"), new Emoji("\ud83c\udde8\ud83c\uddf3"), new Emoji("\ud83c\udde8\ud83c\uddf4"), new Emoji("\ud83c\udde8\ud83c\uddf5"), new Emoji("\ud83c\udde8\ud83c\uddf7"), new Emoji("\ud83c\udde8\ud83c\uddfa"), new Emoji("\ud83c\udde8\ud83c\uddfb"), new Emoji("\ud83c\udde8\ud83c\uddfc"), new Emoji("\ud83c\udde8\ud83c\uddfd"), new Emoji("\ud83c\udde8\ud83c\uddfe"), new Emoji("\ud83c\udde8\ud83c\uddff"), new Emoji("\ud83c\udde9\ud83c\uddea"), new Emoji("\ud83c\udde9\ud83c\uddec"), new Emoji("\ud83c\udde9\ud83c\uddef"), new Emoji("\ud83c\udde9\ud83c\uddf0"), new Emoji("\ud83c\udde9\ud83c\uddf2"), new Emoji("\ud83c\udde9\ud83c\uddf4"), new Emoji("\ud83c\udde9\ud83c\uddff"), new Emoji("\ud83c\uddea\ud83c\udde6"), new Emoji("\ud83c\uddea\ud83c\udde8"), new Emoji("\ud83c\uddea\ud83c\uddea"), new Emoji("\ud83c\uddea\ud83c\uddec"), new Emoji("\ud83c\uddea\ud83c\udded"), new Emoji("\ud83c\uddea\ud83c\uddf7"), new Emoji("\ud83c\uddea\ud83c\uddf8"), new Emoji("\ud83c\uddea\ud83c\uddf9"), new Emoji("\ud83c\uddea\ud83c\uddfa"), new Emoji("\ud83c\uddeb\ud83c\uddee"), new Emoji("\ud83c\uddeb\ud83c\uddef"), new Emoji("\ud83c\uddeb\ud83c\uddf0"), new Emoji("\ud83c\uddeb\ud83c\uddf2"), new Emoji("\ud83c\uddeb\ud83c\uddf4"), new Emoji("\ud83c\uddeb\ud83c\uddf7"), new Emoji("\ud83c\uddec\ud83c\udde6"), new Emoji("\ud83c\uddec\ud83c\udde7"), new Emoji("\ud83c\uddec\ud83c\udde9"), new Emoji("\ud83c\uddec\ud83c\uddea"), new Emoji("\ud83c\uddec\ud83c\uddeb"), new Emoji("\ud83c\uddec\ud83c\uddec"), new Emoji("\ud83c\uddec\ud83c\udded"), new Emoji("\ud83c\uddec\ud83c\uddee"), new Emoji("\ud83c\uddec\ud83c\uddf1"), new Emoji("\ud83c\uddec\ud83c\uddf2"), new Emoji("\ud83c\uddec\ud83c\uddf3"), new Emoji("\ud83c\uddec\ud83c\uddf5"), new Emoji("\ud83c\uddec\ud83c\uddf6"), new Emoji("\ud83c\uddec\ud83c\uddf7"), new Emoji("\ud83c\uddec\ud83c\uddf8"), new Emoji("\ud83c\uddec\ud83c\uddf9"), new Emoji("\ud83c\uddec\ud83c\uddfa"), new Emoji("\ud83c\uddec\ud83c\uddfc"), new Emoji("\ud83c\uddec\ud83c\uddfe"), new Emoji("\ud83c\udded\ud83c\uddf0"), new Emoji("\ud83c\udded\ud83c\uddf2"), new Emoji("\ud83c\udded\ud83c\uddf3"), new Emoji("\ud83c\udded\ud83c\uddf7"), new Emoji("\ud83c\udded\ud83c\uddf9"), new Emoji("\ud83c\udded\ud83c\uddfa"), new Emoji("\ud83c\uddee\ud83c\udde8"), new Emoji("\ud83c\uddee\ud83c\udde9"), new Emoji("\ud83c\uddee\ud83c\uddea"), new Emoji("\ud83c\uddee\ud83c\uddf1"), new Emoji("\ud83c\uddee\ud83c\uddf2"), new Emoji("\ud83c\uddee\ud83c\uddf3"), new Emoji("\ud83c\uddee\ud83c\uddf4"), new Emoji("\ud83c\uddee\ud83c\uddf6"), new Emoji("\ud83c\uddee\ud83c\uddf7"), new Emoji("\ud83c\uddee\ud83c\uddf8"), new Emoji("\ud83c\uddee\ud83c\uddf9"), new Emoji("\ud83c\uddef\ud83c\uddea"), new Emoji("\ud83c\uddef\ud83c\uddf2"), new Emoji("\ud83c\uddef\ud83c\uddf4"), new Emoji("\ud83c\uddef\ud83c\uddf5"), new Emoji("\ud83c\uddf0\ud83c\uddea"), new Emoji("\ud83c\uddf0\ud83c\uddec"), new Emoji("\ud83c\uddf0\ud83c\udded"), new Emoji("\ud83c\uddf0\ud83c\uddee"), new Emoji("\ud83c\uddf0\ud83c\uddf2"), new Emoji("\ud83c\uddf0\ud83c\uddf3"), new Emoji("\ud83c\uddf0\ud83c\uddf5"), new Emoji("\ud83c\uddf0\ud83c\uddf7"), new Emoji("\ud83c\uddf0\ud83c\uddfc"), new Emoji("\ud83c\uddf0\ud83c\uddfe"), new Emoji("\ud83c\uddf0\ud83c\uddff"), new Emoji("\ud83c\uddf1\ud83c\udde6"), new Emoji("\ud83c\uddf1\ud83c\udde7"), new Emoji("\ud83c\uddf1\ud83c\udde8"), new Emoji("\ud83c\uddf1\ud83c\uddee"), new Emoji("\ud83c\uddf1\ud83c\uddf0"), new Emoji("\ud83c\uddf1\ud83c\uddf7"), new Emoji("\ud83c\uddf1\ud83c\uddf8"), new Emoji("\ud83c\uddf1\ud83c\uddf9"), new Emoji("\ud83c\uddf1\ud83c\uddfa"), new Emoji("\ud83c\uddf1\ud83c\uddfb"), new Emoji("\ud83c\uddf1\ud83c\uddfe"), new Emoji("\ud83c\uddf2\ud83c\udde6"), new Emoji("\ud83c\uddf2\ud83c\udde8"), new Emoji("\ud83c\uddf2\ud83c\udde9"), new Emoji("\ud83c\uddf2\ud83c\uddea"), new Emoji("\ud83c\uddf2\ud83c\uddeb"), new Emoji("\ud83c\uddf2\ud83c\uddec"), new Emoji("\ud83c\uddf2\ud83c\udded"), new Emoji("\ud83c\uddf2\ud83c\uddf0"), new Emoji("\ud83c\uddf2\ud83c\uddf1"), new Emoji("\ud83c\uddf2\ud83c\uddf2"), new Emoji("\ud83c\uddf2\ud83c\uddf3"), new Emoji("\ud83c\uddf2\ud83c\uddf4"), new Emoji("\ud83c\uddf2\ud83c\uddf5"), new Emoji("\ud83c\uddf2\ud83c\uddf6"), new Emoji("\ud83c\uddf2\ud83c\uddf7"), new Emoji("\ud83c\uddf2\ud83c\uddf8"), new Emoji("\ud83c\uddf2\ud83c\uddf9"), new Emoji("\ud83c\uddf2\ud83c\uddfa"), new Emoji("\ud83c\uddf2\ud83c\uddfb"), new Emoji("\ud83c\uddf2\ud83c\uddfc"), new Emoji("\ud83c\uddf2\ud83c\uddfd"), new Emoji("\ud83c\uddf2\ud83c\uddfe"), new Emoji("\ud83c\uddf2\ud83c\uddff"), new Emoji("\ud83c\uddf3\ud83c\udde6"), new Emoji("\ud83c\uddf3\ud83c\udde8"), new Emoji("\ud83c\uddf3\ud83c\uddea"), new Emoji("\ud83c\uddf3\ud83c\uddeb"), new Emoji("\ud83c\uddf3\ud83c\uddec"), new Emoji("\ud83c\uddf3\ud83c\uddee"), new Emoji("\ud83c\uddf3\ud83c\uddf1"), new Emoji("\ud83c\uddf3\ud83c\uddf4"), new Emoji("\ud83c\uddf3\ud83c\uddf5"), new Emoji("\ud83c\uddf3\ud83c\uddf7"), new Emoji("\ud83c\uddf3\ud83c\uddfa"), new Emoji("\ud83c\uddf3\ud83c\uddff"), new Emoji("\ud83c\uddf4\ud83c\uddf2"), new Emoji("\ud83c\uddf5\ud83c\udde6"), new Emoji("\ud83c\uddf5\ud83c\uddea"), new Emoji("\ud83c\uddf5\ud83c\uddeb"), new Emoji("\ud83c\uddf5\ud83c\uddec"), new Emoji("\ud83c\uddf5\ud83c\udded"), new Emoji("\ud83c\uddf5\ud83c\uddf0"), new Emoji("\ud83c\uddf5\ud83c\uddf1"), new Emoji("\ud83c\uddf5\ud83c\uddf2"), new Emoji("\ud83c\uddf5\ud83c\uddf3"), new Emoji("\ud83c\uddf5\ud83c\uddf7"), new Emoji("\ud83c\uddf5\ud83c\uddf8"), new Emoji("\ud83c\uddf5\ud83c\uddf9"), new Emoji("\ud83c\uddf5\ud83c\uddfc"), new Emoji("\ud83c\uddf5\ud83c\uddfe"), new Emoji("\ud83c\uddf6\ud83c\udde6"), new Emoji("\ud83c\uddf7\ud83c\uddea"), new Emoji("\ud83c\uddf7\ud83c\uddf4"), new Emoji("\ud83c\uddf7\ud83c\uddf8"), new Emoji("\ud83c\uddf7\ud83c\uddfa"), new Emoji("\ud83c\uddf7\ud83c\uddfc"), new Emoji("\ud83c\uddf8\ud83c\udde6"), new Emoji("\ud83c\uddf8\ud83c\udde7"), new Emoji("\ud83c\uddf8\ud83c\udde8"), new Emoji("\ud83c\uddf8\ud83c\udde9"), new Emoji("\ud83c\uddf8\ud83c\uddea"), new Emoji("\ud83c\uddf8\ud83c\uddec"), new Emoji("\ud83c\uddf8\ud83c\udded"), new Emoji("\ud83c\uddf8\ud83c\uddee"), new Emoji("\ud83c\uddf8\ud83c\uddef"), new Emoji("\ud83c\uddf8\ud83c\uddf0"), new Emoji("\ud83c\uddf8\ud83c\uddf1"), new Emoji("\ud83c\uddf8\ud83c\uddf2"), new Emoji("\ud83c\uddf8\ud83c\uddf3"), new Emoji("\ud83c\uddf8\ud83c\uddf4"), new Emoji("\ud83c\uddf8\ud83c\uddf7"), new Emoji("\ud83c\uddf8\ud83c\uddf8"), new Emoji("\ud83c\uddf8\ud83c\uddf9"), new Emoji("\ud83c\uddf8\ud83c\uddfb"), new Emoji("\ud83c\uddf8\ud83c\uddfd"), new Emoji("\ud83c\uddf8\ud83c\uddfe"), new Emoji("\ud83c\uddf8\ud83c\uddff"), new Emoji("\ud83c\uddf9\ud83c\udde6"), new Emoji("\ud83c\uddf9\ud83c\udde8"), new Emoji("\ud83c\uddf9\ud83c\udde9"), new Emoji("\ud83c\uddf9\ud83c\uddeb"), new Emoji("\ud83c\uddf9\ud83c\uddec"), new Emoji("\ud83c\uddf9\ud83c\udded"), new Emoji("\ud83c\uddf9\ud83c\uddef"), new Emoji("\ud83c\uddf9\ud83c\uddf0"), new Emoji("\ud83c\uddf9\ud83c\uddf1"), new Emoji("\ud83c\uddf9\ud83c\uddf2"), new Emoji("\ud83c\uddf9\ud83c\uddf3"), new Emoji("\ud83c\uddf9\ud83c\uddf4"), new Emoji("\ud83c\uddf9\ud83c\uddf7"), new Emoji("\ud83c\uddf9\ud83c\uddf9"), new Emoji("\ud83c\uddf9\ud83c\uddfb"), new Emoji("\ud83c\uddf9\ud83c\uddfc"), new Emoji("\ud83c\uddf9\ud83c\uddff"), new Emoji("\ud83c\uddfa\ud83c\udde6"), new Emoji("\ud83c\uddfa\ud83c\uddec"), new Emoji("\ud83c\uddfa\ud83c\uddf2"), new Emoji("\ud83c\uddfa\ud83c\uddf8"), new Emoji("\ud83c\uddfa\ud83c\uddfe"), new Emoji("\ud83c\uddfa\ud83c\uddff"), new Emoji("\ud83c\uddfb\ud83c\udde6"), new Emoji("\ud83c\uddfb\ud83c\udde8"), new Emoji("\ud83c\uddfb\ud83c\uddea"), new Emoji("\ud83c\uddfb\ud83c\uddec"), new Emoji("\ud83c\uddfb\ud83c\uddee"), new Emoji("\ud83c\uddfb\ud83c\uddf3"), new Emoji("\ud83c\uddfb\ud83c\uddfa"), new Emoji("\ud83c\uddfc\ud83c\uddeb"), new Emoji("\ud83c\uddfc\ud83c\uddf8"), new Emoji("\ud83c\uddfd\ud83c\uddf0"), new Emoji("\ud83c\uddfe\ud83c\uddea"), new Emoji("\ud83c\uddfe\ud83c\uddf9"), new Emoji("\ud83c\uddff\ud83c\udde6"), new Emoji("\ud83c\uddff\ud83c\uddf2"), new Emoji("\ud83c\uddff\ud83c\uddfc"), new Emoji("\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f"), new Emoji("\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc73\udb40\udc63\udb40\udc74\udb40\udc7f"), new Emoji("\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc77\udb40\udc6c\udb40\udc73\udb40\udc7f")
), Uri.parse("emoji/Flags.png"));
- private static final EmojiPageModel PAGE_EMOTICONS = new StaticEmojiPageModel(EmojiCategory.EMOTICONS, new String[] {
- ":-)", ";-)", "(-:", ":->", ":-D", "\\o/",
- ":-P", "B-)", ":-$", ":-*", "O:-)", "=-O",
- "O_O", "O_o", "o_O", ":O", ":-!", ":-x",
- ":-|", ":-\\", ":-(", ":'(", ":-[", ">:-(",
- "^.^", "^_^", "\\(\u02c6\u02da\u02c6)/",
- "\u30fd(\u00b0\u25c7\u00b0 )\u30ce", "\u00af\\(\u00b0_o)/\u00af",
- "\u00af\\_(\u30c4)_/\u00af", "(\u00ac_\u00ac)",
- "(>_<)", "(\u2565\ufe4f\u2565)", "(\u261e\uff9f\u30ee\uff9f)\u261e",
- "\u261c(\uff9f\u30ee\uff9f\u261c)", "\u261c(\u2312\u25bd\u2312)\u261e",
- "(\u256f\u00b0\u25a1\u00b0)\u256f\ufe35", "\u253b\u2501\u253b",
- "\u252c\u2500\u252c", "\u30ce(\u00b0\u2013\u00b0\u30ce)",
- "(^._.^)\uff89", "\u0e05^\u2022\ufecc\u2022^\u0e05",
- "\u0295\u2022\u1d25\u2022\u0294", "(\u2022_\u2022)",
- " \u25a0-\u25a0\u00ac <(\u2022_\u2022) ", "(\u25a0_\u25a0\u00ac)",
- "\u01aa(\u0693\u05f2)\u200e\u01aa\u200b\u200b"
- }, null);
-
static final List DISPLAY_PAGES = Arrays.asList(PAGE_PEOPLE,
PAGE_NATURE,
PAGE_FOODS,
@@ -83,226 +61,7 @@ class EmojiPages {
PAGE_PLACES,
PAGE_OBJECTS,
PAGE_SYMBOLS,
- PAGE_FLAGS,
- PAGE_EMOTICONS);
+ PAGE_FLAGS);
- static final List DATA_PAGES = Arrays.asList(PAGE_PEOPLE_0,
- PAGE_PEOPLE_1,
- PAGE_PEOPLE_2,
- PAGE_PEOPLE_3,
- PAGE_NATURE,
- PAGE_FOODS,
- PAGE_ACTIVITY,
- PAGE_PLACES,
- PAGE_OBJECTS,
- PAGE_SYMBOLS,
- PAGE_FLAGS,
- PAGE_EMOTICONS);
- static final List> OBSOLETE = new LinkedList>() {{
- add(new Pair<>("\ud83d\udc6e", "\ud83d\udc6e\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc6e\ud83c\udffb", "\ud83d\udc6e\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc6e\ud83c\udffc", "\ud83d\udc6e\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc6e\ud83c\udffd", "\ud83d\udc6e\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc6e\ud83c\udffe", "\ud83d\udc6e\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc6e\ud83c\udfff", "\ud83d\udc6e\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udd75\ufe0f", "\ud83d\udd75\ufe0f\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udd75\ud83c\udffb", "\ud83d\udd75\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udd75\ud83c\udffc", "\ud83d\udd75\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udd75\ud83c\udffd", "\ud83d\udd75\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udd75\ud83c\udffe", "\ud83d\udd75\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udd75\ud83c\udfff", "\ud83d\udd75\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc82", "\ud83d\udc82\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc82\ud83c\udffb", "\ud83d\udc82\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc82\ud83c\udffc", "\ud83d\udc82\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc82\ud83c\udffd", "\ud83d\udc82\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc82\ud83c\udffe", "\ud83d\udc82\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc82\ud83c\udfff", "\ud83d\udc82\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc77", "\ud83d\udc77\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc77\ud83c\udffb", "\ud83d\udc77\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc77\ud83c\udffc", "\ud83d\udc77\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc77\ud83c\udffd", "\ud83d\udc77\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc77\ud83c\udffe", "\ud83d\udc77\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc77\ud83c\udfff", "\ud83d\udc77\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc73", "\ud83d\udc73\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc73\ud83c\udffb", "\ud83d\udc73\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc73\ud83c\udffc", "\ud83d\udc73\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc73\ud83c\udffd", "\ud83d\udc73\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc73\ud83c\udffe", "\ud83d\udc73\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc73\ud83c\udfff", "\ud83d\udc73\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc71", "\ud83d\udc71\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc71\ud83c\udffb", "\ud83d\udc71\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc71\ud83c\udffc", "\ud83d\udc71\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc71\ud83c\udffd", "\ud83d\udc71\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc71\ud83c\udffe", "\ud83d\udc71\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc71\ud83c\udfff", "\ud83d\udc71\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd9", "\ud83e\uddd9\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd9\ud83c\udffb", "\ud83e\uddd9\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd9\ud83c\udffc", "\ud83e\uddd9\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd9\ud83c\udffd", "\ud83e\uddd9\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd9\ud83c\udffe", "\ud83e\uddd9\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd9\ud83c\udfff", "\ud83e\uddd9\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddda", "\ud83e\uddda\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddda\ud83c\udffb", "\ud83e\uddda\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddda\ud83c\udffc", "\ud83e\uddda\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddda\ud83c\udffd", "\ud83e\uddda\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddda\ud83c\udffe", "\ud83e\uddda\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddda\ud83c\udfff", "\ud83e\uddda\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddb", "\ud83e\udddb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddb\ud83c\udffb", "\ud83e\udddb\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddb\ud83c\udffc", "\ud83e\udddb\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddb\ud83c\udffd", "\ud83e\udddb\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddb\ud83c\udffe", "\ud83e\udddb\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddb\ud83c\udfff", "\ud83e\udddb\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\udddc", "\ud83e\udddc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddc\ud83c\udffb", "\ud83e\udddc\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddc\ud83c\udffc", "\ud83e\udddc\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddc\ud83c\udffd", "\ud83e\udddc\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddc\ud83c\udffe", "\ud83e\udddc\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddc\ud83c\udfff", "\ud83e\udddc\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddd", "\ud83e\udddd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddd\ud83c\udffb", "\ud83e\udddd\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddd\ud83c\udffc", "\ud83e\udddd\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddd\ud83c\udffd", "\ud83e\udddd\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddd\ud83c\udffe", "\ud83e\udddd\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddd\ud83c\udfff", "\ud83e\udddd\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddde", "\ud83e\uddde\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\udddf", "\ud83e\udddf\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\ude4d", "\ud83d\ude4d\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4d\ud83c\udffb", "\ud83d\ude4d\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4d\ud83c\udffc", "\ud83d\ude4d\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4d\ud83c\udffd", "\ud83d\ude4d\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4d\ud83c\udffe", "\ud83d\ude4d\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4d\ud83c\udfff", "\ud83d\ude4d\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4e", "\ud83d\ude4e\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4e\ud83c\udffb", "\ud83d\ude4e\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4e\ud83c\udffc", "\ud83d\ude4e\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4e\ud83c\udffd", "\ud83d\ude4e\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4e\ud83c\udffe", "\ud83d\ude4e\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4e\ud83c\udfff", "\ud83d\ude4e\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude45", "\ud83d\ude45\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude45\ud83c\udffb", "\ud83d\ude45\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude45\ud83c\udffc", "\ud83d\ude45\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude45\ud83c\udffd", "\ud83d\ude45\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude45\ud83c\udffe", "\ud83d\ude45\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude45\ud83c\udfff", "\ud83d\ude45\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude46", "\ud83d\ude46\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude46\ud83c\udffb", "\ud83d\ude46\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude46\ud83c\udffc", "\ud83d\ude46\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude46\ud83c\udffd", "\ud83d\ude46\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude46\ud83c\udffe", "\ud83d\ude46\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude46\ud83c\udfff", "\ud83d\ude46\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc81", "\ud83d\udc81\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc81\ud83c\udffb", "\ud83d\udc81\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc81\ud83c\udffc", "\ud83d\udc81\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc81\ud83c\udffd", "\ud83d\udc81\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc81\ud83c\udffe", "\ud83d\udc81\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc81\ud83c\udfff", "\ud83d\udc81\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4b", "\ud83d\ude4b\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4b\ud83c\udffb", "\ud83d\ude4b\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4b\ud83c\udffc", "\ud83d\ude4b\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4b\ud83c\udffd", "\ud83d\ude4b\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4b\ud83c\udffe", "\ud83d\ude4b\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude4b\ud83c\udfff", "\ud83d\ude4b\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\ude47", "\ud83d\ude47\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\ude47\ud83c\udffb", "\ud83d\ude47\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\ude47\ud83c\udffc", "\ud83d\ude47\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\ude47\ud83c\udffd", "\ud83d\ude47\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\ude47\ud83c\udffe", "\ud83d\ude47\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\ude47\ud83c\udfff", "\ud83d\ude47\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc86", "\ud83d\udc86\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc86\ud83c\udffb", "\ud83d\udc86\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc86\ud83c\udffc", "\ud83d\udc86\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc86\ud83c\udffd", "\ud83d\udc86\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc86\ud83c\udffe", "\ud83d\udc86\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc86\ud83c\udfff", "\ud83d\udc86\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc87", "\ud83d\udc87\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc87\ud83c\udffb", "\ud83d\udc87\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc87\ud83c\udffc", "\ud83d\udc87\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc87\ud83c\udffd", "\ud83d\udc87\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc87\ud83c\udffe", "\ud83d\udc87\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udc87\ud83c\udfff", "\ud83d\udc87\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83d\udeb6", "\ud83d\udeb6\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb6\ud83c\udffb", "\ud83d\udeb6\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb6\ud83c\udffc", "\ud83d\udeb6\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb6\ud83c\udffd", "\ud83d\udeb6\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb6\ud83c\udffe", "\ud83d\udeb6\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb6\ud83c\udfff", "\ud83d\udeb6\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc3", "\ud83c\udfc3\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc3\ud83c\udffb", "\ud83c\udfc3\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc3\ud83c\udffc", "\ud83c\udfc3\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc3\ud83c\udffd", "\ud83c\udfc3\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc3\ud83c\udffe", "\ud83c\udfc3\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc3\ud83c\udfff", "\ud83c\udfc3\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc6f", "\ud83d\udc6f\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd6", "\ud83e\uddd6\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd6\ud83c\udffb", "\ud83e\uddd6\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd6\ud83c\udffc", "\ud83e\uddd6\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd6\ud83c\udffd", "\ud83e\uddd6\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd6\ud83c\udffe", "\ud83e\uddd6\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd6\ud83c\udfff", "\ud83e\uddd6\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83e\uddd7", "\ud83e\uddd7\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd7\ud83c\udffb", "\ud83e\uddd7\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd7\ud83c\udffc", "\ud83e\uddd7\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd7\ud83c\udffd", "\ud83e\uddd7\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd7\ud83c\udffe", "\ud83e\uddd7\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd7\ud83c\udfff", "\ud83e\uddd7\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd8", "\ud83e\uddd8\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd8\ud83c\udffb", "\ud83e\uddd8\ud83c\udffb\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd8\ud83c\udffc", "\ud83e\uddd8\ud83c\udffc\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd8\ud83c\udffd", "\ud83e\uddd8\ud83c\udffd\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd8\ud83c\udffe", "\ud83e\uddd8\ud83c\udffe\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83e\uddd8\ud83c\udfff", "\ud83e\uddd8\ud83c\udfff\u200d\u2640\ufe0f"));
- add(new Pair<>("\ud83c\udfcc\ufe0f", "\ud83c\udfcc\ufe0f\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcc\ud83c\udffb", "\ud83c\udfcc\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcc\ud83c\udffc", "\ud83c\udfcc\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcc\ud83c\udffd", "\ud83c\udfcc\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcc\ud83c\udffe", "\ud83c\udfcc\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcc\ud83c\udfff", "\ud83c\udfcc\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc4", "\ud83c\udfc4\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc4\ud83c\udffb", "\ud83c\udfc4\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc4\ud83c\udffc", "\ud83c\udfc4\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc4\ud83c\udffd", "\ud83c\udfc4\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc4\ud83c\udffe", "\ud83c\udfc4\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfc4\ud83c\udfff", "\ud83c\udfc4\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udea3", "\ud83d\udea3\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udea3\ud83c\udffb", "\ud83d\udea3\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udea3\ud83c\udffc", "\ud83d\udea3\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udea3\ud83c\udffd", "\ud83d\udea3\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udea3\ud83c\udffe", "\ud83d\udea3\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udea3\ud83c\udfff", "\ud83d\udea3\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfca", "\ud83c\udfca\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfca\ud83c\udffb", "\ud83c\udfca\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfca\ud83c\udffc", "\ud83c\udfca\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfca\ud83c\udffd", "\ud83c\udfca\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfca\ud83c\udffe", "\ud83c\udfca\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfca\ud83c\udfff", "\ud83c\udfca\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\u26f9\ufe0f", "\u26f9\ufe0f\u200d\u2642\ufe0f"));
- add(new Pair<>("\u26f9\ud83c\udffb", "\u26f9\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\u26f9\ud83c\udffc", "\u26f9\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\u26f9\ud83c\udffd", "\u26f9\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\u26f9\ud83c\udffe", "\u26f9\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\u26f9\ud83c\udfff", "\u26f9\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcb\ufe0f", "\ud83c\udfcb\ufe0f\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcb\ud83c\udffb", "\ud83c\udfcb\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcb\ud83c\udffc", "\ud83c\udfcb\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcb\ud83c\udffd", "\ud83c\udfcb\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcb\ud83c\udffe", "\ud83c\udfcb\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83c\udfcb\ud83c\udfff", "\ud83c\udfcb\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb4", "\ud83d\udeb4\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb4\ud83c\udffb", "\ud83d\udeb4\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb4\ud83c\udffc", "\ud83d\udeb4\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb4\ud83c\udffd", "\ud83d\udeb4\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb4\ud83c\udffe", "\ud83d\udeb4\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb4\ud83c\udfff", "\ud83d\udeb4\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb5", "\ud83d\udeb5\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb5\ud83c\udffb", "\ud83d\udeb5\ud83c\udffb\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb5\ud83c\udffc", "\ud83d\udeb5\ud83c\udffc\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb5\ud83c\udffd", "\ud83d\udeb5\ud83c\udffd\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb5\ud83c\udffe", "\ud83d\udeb5\ud83c\udffe\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udeb5\ud83c\udfff", "\ud83d\udeb5\ud83c\udfff\u200d\u2642\ufe0f"));
- add(new Pair<>("\ud83d\udc8f", "\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68"));
- add(new Pair<>("\ud83d\udc91", "\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc68"));
- add(new Pair<>("\ud83d\udc6a", "\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66"));
- }};
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java
index d560247fb9..01317bc9b9 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactAccessor.java
@@ -73,7 +73,7 @@ public class ContactAccessor {
}
}
-// if (context.getString(R.string.note_to_self).toLowerCase().contains(constraint.toLowerCase()) &&
+// if (context.getString(R.string.noteToSelf).toLowerCase().contains(constraint.toLowerCase()) &&
// !numberList.contains(TextSecurePreferences.getLocalNumber(context)))
// {
// numberList.add(TextSecurePreferences.getLocalNumber(context));
diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListLoader.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListLoader.kt
index 90e0ce50f2..0db2ec8962 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListLoader.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListLoader.kt
@@ -36,7 +36,7 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
list.addAll(getClosedGroups(contacts))
}
if (isFlagSet(DisplayMode.FLAG_OPEN_GROUPS)) {
- list.addAll(getOpenGroups(contacts))
+ list.addAll(getCommunities(contacts))
}
if (isFlagSet(DisplayMode.FLAG_CONTACTS)) {
list.addAll(getContacts(contacts))
@@ -45,19 +45,19 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
}
private fun getContacts(contacts: List): List {
- return getItems(contacts, context.getString(R.string.fragment_contact_selection_contacts_title)) {
+ return getItems(contacts, context.getString(R.string.contactContacts)) {
!it.isGroupRecipient
}
}
private fun getClosedGroups(contacts: List): List {
- return getItems(contacts, context.getString(R.string.fragment_contact_selection_closed_groups_title)) {
+ return getItems(contacts, context.getString(R.string.conversationsGroups)) {
it.address.isClosedGroup
}
}
- private fun getOpenGroups(contacts: List): List {
- return getItems(contacts, context.getString(R.string.fragment_contact_selection_open_groups_title)) {
+ private fun getCommunities(contacts: List): List {
+ return getItems(contacts, context.getString(R.string.conversationsCommunities)) {
it.address.isCommunity
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactUtil.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactUtil.java
index 5284fb0015..046c20002d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactUtil.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactUtil.java
@@ -18,10 +18,10 @@ public final class ContactUtil {
String contactName = ContactUtil.getDisplayName(contact);
if (!TextUtils.isEmpty(contactName)) {
- return context.getString(R.string.MessageNotifier_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, contactName);
+ return EmojiStrings.BUST_IN_SILHOUETTE + " " + contactName;
}
- return SpanUtil.italic(context.getString(R.string.MessageNotifier_unknown_contact_message));
+ return SpanUtil.italic(context.getString(R.string.unknown));
}
private static @NonNull String getDisplayName(@Nullable Contact contact) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java
index e1ea0c5e2e..83084d2673 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java
@@ -159,7 +159,7 @@ public class ContactsCursorLoader extends CursorLoader {
private Cursor getGroupsHeaderCursor() {
MatrixCursor groupHeader = new MatrixCursor(CONTACT_PROJECTION, 1);
- groupHeader.addRow(new Object[]{ getContext().getString(R.string.ContactsCursorLoader_groups),
+ groupHeader.addRow(new Object[]{ getContext().getString(R.string.conversationsGroups),
"",
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE,
"",
@@ -221,16 +221,6 @@ public class ContactsCursorLoader extends CursorLoader {
return groupContacts;
}
- private Cursor getNewNumberCursor() {
- MatrixCursor newNumberCursor = new MatrixCursor(CONTACT_PROJECTION, 1);
- newNumberCursor.addRow(new Object[] { getContext().getString(R.string.contact_selection_list__unknown_contact),
- filter,
- ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM,
- "\u21e2",
- NEW_TYPE });
- return newNumberCursor;
- }
-
private static boolean isCursorListEmpty(List list) {
int sum = 0;
for (Cursor cursor : list) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsActivity.kt
index 1160ed92ab..a3fd6ac1dd 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsActivity.kt
@@ -35,7 +35,7 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderMana
super.onCreate(savedInstanceState, isReady)
binding = ActivitySelectContactsBinding.inflate(layoutInflater)
setContentView(binding.root)
- supportActionBar!!.title = resources.getString(R.string.activity_select_contacts_title)
+ supportActionBar!!.title = resources.getString(R.string.membersInvite)
usersToExclude = intent.getStringArrayExtra(usersToExcludeKey)?.toSet() ?: setOf()
val emptyStateText = intent.getStringExtra(emptyStateTextKey)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt
index e0ca2a4242..77f579e14d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt
@@ -14,7 +14,6 @@ import com.bumptech.glide.RequestManager
class UserView : LinearLayout {
private lateinit var binding: ViewUserBinding
- var openGroupThreadID: Long = -1 // FIXME: This is a bit ugly
enum class ActionIndicator {
None,
@@ -47,11 +46,13 @@ class UserView : LinearLayout {
// region Updating
fun bind(user: Recipient, glide: RequestManager, actionIndicator: ActionIndicator, isSelected: Boolean = false) {
val isLocalUser = user.isLocalNumber
+
fun getUserDisplayName(publicKey: String): String {
- if (isLocalUser) return context.getString(R.string.MessageRecord_you)
+ if (isLocalUser) return context.getString(R.string.you)
val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithAccountID(publicKey)
return contact?.displayName(Contact.ContactContext.REGULAR) ?: publicKey
}
+
val address = user.address.serialize()
binding.profilePictureView.update(user)
binding.actionIndicatorImageView.setImageResource(R.drawable.ic_baseline_edit_24)
@@ -84,8 +85,6 @@ class UserView : LinearLayout {
}
}
- fun unbind() {
- binding.profilePictureView.recycle()
- }
+ fun unbind() { binding.profilePictureView.recycle() }
// endregion
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt
index 8f2da7a733..1c6442824d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActionBarView.kt
@@ -11,21 +11,26 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.google.android.material.tabs.TabLayoutMediator
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
+import javax.inject.Inject
+import kotlin.time.Duration.Companion.milliseconds
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewConversationActionBarBinding
import network.loki.messenger.databinding.ViewConversationSettingBinding
-import network.loki.messenger.libsession_util.util.ExpiryMode
+import network.loki.messenger.libsession_util.util.ExpiryMode.AfterRead
+import org.session.libsession.LocalisedTimeUtil
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.open_groups.OpenGroup
import org.session.libsession.utilities.ExpirationUtil
+import org.session.libsession.utilities.StringSubstitutionConstants.DISAPPEARING_MESSAGES_TYPE_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.TIME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.TIME_LARGE_KEY
import org.session.libsession.utilities.modifyLayoutParams
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.database.GroupDatabase
import org.thoughtcrime.securesms.database.LokiAPIDatabase
-import org.thoughtcrime.securesms.util.DateUtils
-import java.util.Locale
-import javax.inject.Inject
+import org.thoughtcrime.securesms.ui.getSubbedString
@AndroidEntryPoint
class ConversationActionBarView @JvmOverloads constructor(
@@ -82,7 +87,7 @@ class ConversationActionBarView @JvmOverloads constructor(
fun update(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
binding.profilePictureView.update(recipient)
- binding.conversationTitleView.text = recipient.takeUnless { it.isLocalNumber }?.toShortString() ?: context.getString(R.string.note_to_self)
+ binding.conversationTitleView.text = recipient.takeUnless { it.isLocalNumber }?.toShortString() ?: context.getString(R.string.noteToSelf)
updateSubtitle(recipient, openGroup, config)
binding.conversationTitleContainer.modifyLayoutParams {
@@ -92,37 +97,56 @@ class ConversationActionBarView @JvmOverloads constructor(
fun updateSubtitle(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
val settings = mutableListOf()
+
+ // Specify the disappearing messages subtitle if we should
if (config?.isEnabled == true) {
- val prefix = when (config.expiryMode) {
- is ExpiryMode.AfterRead -> R.string.expiration_type_disappear_after_read
- else -> R.string.expiration_type_disappear_after_send
- }.let(context::getString)
+ // Get the type of disappearing message and the abbreviated duration..
+ val dmTypeString = when (config.expiryMode) {
+ is AfterRead -> context.getString(R.string.read)
+ else -> context.getString(R.string.send)
+ }
+ val durationAbbreviated = ExpirationUtil.getExpirationAbbreviatedDisplayValue(config.expiryMode.expirySeconds)
+
+ // ..then substitute into the string..
+ val subtitleTxt = context.getSubbedString(R.string.disappearingMessagesDisappear,
+ DISAPPEARING_MESSAGES_TYPE_KEY to dmTypeString,
+ TIME_KEY to durationAbbreviated
+ )
+
+ // .. and apply to the subtitle.
settings += ConversationSetting(
- "$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode.expirySeconds)}",
+ subtitleTxt,
ConversationSettingType.EXPIRATION,
R.drawable.ic_timer,
- resources.getString(R.string.AccessibilityId_disappearing_messages_type_and_time)
+ resources.getString(R.string.AccessibilityId_disappearingMessagesDisappear)
)
}
+
if (recipient.isMuted) {
settings += ConversationSetting(
recipient.mutedUntil.takeUnless { it == Long.MAX_VALUE }
- ?.let { context.getString(R.string.ConversationActivity_muted_until_date, DateUtils.getFormattedDateTime(it, "EEE, MMM d, yyyy HH:mm", Locale.getDefault())) }
- ?: context.getString(R.string.ConversationActivity_muted_forever),
+ ?.let {
+ val mutedDuration = (it - System.currentTimeMillis()).milliseconds
+ val durationString = LocalisedTimeUtil.getDurationWithSingleLargestTimeUnit(context, mutedDuration)
+ context.getSubbedString(R.string.notificationsMuteFor, TIME_LARGE_KEY to durationString)
+ }
+ ?: context.getString(R.string.notificationsMuted),
ConversationSettingType.NOTIFICATION,
R.drawable.ic_outline_notifications_off_24
)
}
+
if (recipient.isGroupRecipient) {
val title = if (recipient.isCommunityRecipient) {
val userCount = openGroup?.let { lokiApiDb.getUserCount(it.room, it.server) } ?: 0
- context.getString(R.string.ConversationActivity_active_member_count, userCount)
+ resources.getQuantityString(R.plurals.membersActive, userCount, userCount)
} else {
val userCount = groupDb.getGroupMemberAddresses(recipient.address.toGroupString(), true).size
- context.getString(R.string.ConversationActivity_member_count, userCount)
+ resources.getQuantityString(R.plurals.members, userCount, userCount)
}
settings += ConversationSetting(title, ConversationSettingType.MEMBER_COUNT)
}
+
settingsAdapter.submitList(settings)
binding.settingsTabLayout.isVisible = settings.size > 1
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt
index 38da11ae24..e086c95924 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessages.kt
@@ -12,10 +12,14 @@ import org.session.libsession.snode.SnodeAPI
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.ExpirationUtil
import org.session.libsession.utilities.SSKEnvironment.MessageExpirationManagerProtocol
+import org.session.libsession.utilities.StringSubstitutionConstants.DISAPPEARING_MESSAGES_TYPE_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.TIME_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.getExpirationTypeDisplayValue
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.showSessionDialog
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
+import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
@@ -43,22 +47,18 @@ class DisappearingMessages @Inject constructor(
}
fun showFollowSettingDialog(context: Context, message: MessageRecord) = context.showSessionDialog {
- title(R.string.dialog_disappearing_messages_follow_setting_title)
+ title(R.string.disappearingMessagesFollowSetting)
text(if (message.expiresIn == 0L) {
- context.getString(R.string.dialog_disappearing_messages_follow_setting_off_body)
+ context.getText(R.string.disappearingMessagesFollowSettingOff)
} else {
- context.getString(
- R.string.dialog_disappearing_messages_follow_setting_on_body,
- ExpirationUtil.getExpirationDisplayValue(
- context,
- message.expiresIn.milliseconds
- ),
- context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead)
- )
+ context.getSubbedCharSequence(R.string.disappearingMessagesFollowSettingOn,
+ TIME_KEY to ExpirationUtil.getExpirationDisplayValue(context, message.expiresIn.milliseconds),
+ DISAPPEARING_MESSAGES_TYPE_KEY to context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead))
})
+
dangerButton(
- text = if (message.expiresIn == 0L) R.string.dialog_disappearing_messages_follow_setting_confirm else R.string.dialog_disappearing_messages_follow_setting_set,
- contentDescription = if (message.expiresIn == 0L) R.string.AccessibilityId_confirm else R.string.AccessibilityId_set_button
+ text = if (message.expiresIn == 0L) R.string.confirm else R.string.set,
+ contentDescription = if (message.expiresIn == 0L) R.string.AccessibilityId_confirm else R.string.AccessibilityId_setButton
) {
set(message.threadId, message.recipient.address, message.expiryMode, message.recipient.isClosedGroupRecipient)
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesActivity.kt
index f66512d79f..2716a3d883 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/DisappearingMessagesActivity.kt
@@ -52,7 +52,7 @@ class DisappearingMessagesActivity: PassphraseRequiredActionBarActivity() {
viewModel.event.collect {
when (it) {
Event.SUCCESS -> finish()
- Event.FAIL -> showToast(getString(R.string.DisappearingMessagesActivity_settings_not_updated))
+ Event.FAIL -> showToast(getString(R.string.communityErrorDescription))
}
}
}
@@ -72,9 +72,9 @@ class DisappearingMessagesActivity: PassphraseRequiredActionBarActivity() {
}
private fun setUpToolbar() {
- setSupportActionBar(binding.toolbar)
+ setSupportActionBar(binding.searchToolbar)
supportActionBar?.apply {
- title = getString(R.string.activity_disappearing_messages_title)
+ title = getString(R.string.disappearingMessages)
setDisplayHomeAsUpEnabled(true)
setHomeButtonEnabled(true)
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/State.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/State.kt
index ced4cc0035..739d7d6c9f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/State.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/State.kt
@@ -24,8 +24,8 @@ data class State(
val showDebugOptions: Boolean = false
) {
val subtitle get() = when {
- isGroup || isNoteToSelf -> GetString(R.string.activity_disappearing_messages_subtitle_sent)
- else -> GetString(R.string.activity_disappearing_messages_subtitle)
+ isGroup || isNoteToSelf -> GetString(R.string.disappearingMessagesDisappearAfterSendDescription)
+ else -> GetString(R.string.disappearingMessagesDescription1)
}
val typeOptionsHidden get() = isNoteToSelf || (isGroup && isNewConfigEnabled)
@@ -51,25 +51,25 @@ enum class ExpiryType(
) {
NONE(
{ ExpiryMode.NONE },
- R.string.expiration_off,
- contentDescription = R.string.AccessibilityId_disable_disappearing_messages,
+ R.string.off,
+ contentDescription = R.string.AccessibilityId_disappearingMessagesOff,
),
LEGACY(
ExpiryMode::Legacy,
R.string.expiration_type_disappear_legacy,
- contentDescription = R.string.expiration_type_disappear_legacy_description
+ contentDescription = R.string.AccessibilityId_disappearingMessagesLegacy
),
AFTER_READ(
ExpiryMode::AfterRead,
- R.string.expiration_type_disappear_after_read,
- R.string.expiration_type_disappear_after_read_description,
- R.string.AccessibilityId_disappear_after_read_option
+ R.string.disappearingMessagesDisappearAfterRead,
+ R.string.disappearingMessagesDisappearAfterReadDescription,
+ R.string.AccessibilityId_disappearingMessagesDisappearAfterRead
),
AFTER_SEND(
ExpiryMode::AfterSend,
- R.string.expiration_type_disappear_after_send,
- R.string.expiration_type_disappear_after_send_description,
- R.string.AccessibilityId_disappear_after_send_option
+ R.string.disappearingMessagesDisappearAfterSend,
+ R.string.disappearingMessagesDisappearAfterSendDescription,
+ R.string.AccessibilityId_disappearingMessagesDisappearAfterSent
);
fun mode(seconds: Long) = if (seconds != 0L) createMode(seconds) else ExpiryMode.NONE
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/Adapter.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/Adapter.kt
index d78d33a2f9..dbd40354a2 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/Adapter.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/Adapter.kt
@@ -13,8 +13,8 @@ import kotlin.time.Duration.Companion.seconds
fun State.toUiState() = UiState(
cards = listOfNotNull(
- typeOptions()?.let { ExpiryOptionsCardData(GetString(R.string.activity_disappearing_messages_delete_type), it) },
- timeOptions()?.let { ExpiryOptionsCardData(GetString(R.string.activity_disappearing_messages_timer), it) }
+ typeOptions()?.let { ExpiryOptionsCardData(GetString(R.string.disappearingMessagesDeleteType), it) },
+ timeOptions()?.let { ExpiryOptionsCardData(GetString(R.string.disappearingMessagesTimer), it) }
),
showGroupFooter = isGroup && isNewConfigEnabled,
showSetButton = isSelfAdmin
@@ -66,11 +66,14 @@ private fun State.typeOption(
)
private fun debugTimes(isDebug: Boolean) = if (isDebug) listOf(10.seconds, 30.seconds, 1.minutes) else emptyList()
+
private fun debugModes(isDebug: Boolean, type: ExpiryType) =
debugTimes(isDebug).map { type.mode(it.inWholeSeconds) }
+
private fun State.debugOptions(): List =
debugModes(showDebugOptions, nextType).map { timeOption(it, subtitle = GetString("for testing purposes")) }
+// Standard list of available disappearing message times
private val afterSendTimes = listOf(12.hours, 1.days, 7.days, 14.days)
private val afterReadTimes = buildList {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/DisappearingMessages.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/DisappearingMessages.kt
index ae17e6a09b..ace4097c48 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/DisappearingMessages.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/disappearingmessages/ui/DisappearingMessages.kt
@@ -1,6 +1,5 @@
package org.thoughtcrime.securesms.conversation.disappearingmessages.ui
-import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
@@ -16,21 +15,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.unit.dp
import network.loki.messenger.R
import network.loki.messenger.libsession_util.util.ExpiryMode
import org.thoughtcrime.securesms.ui.Callbacks
-import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.NoOpCallbacks
import org.thoughtcrime.securesms.ui.OptionsCard
import org.thoughtcrime.securesms.ui.RadioOption
-import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.components.SlimOutlineButton
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.fadingEdges
+import org.thoughtcrime.securesms.ui.theme.LocalColors
+import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
-typealias ExpiryCallbacks = Callbacks
+typealias ExpiryCallbacks = Callbacks
typealias ExpiryRadioOption = RadioOption
@Composable
@@ -59,7 +57,9 @@ fun DisappearingMessages(
}
if (state.showGroupFooter) Text(
- text = stringResource(R.string.activity_disappearing_messages_group_footer),
+ text = stringResource(R.string.disappearingMessagesDescription) +
+ "\n" +
+ stringResource(R.string.disappearingMessagesOnlyAdmins),
style = LocalType.current.extraSmall,
fontWeight = FontWeight(400),
color = LocalColors.current.textSecondary,
@@ -72,9 +72,9 @@ fun DisappearingMessages(
}
if (state.showSetButton) SlimOutlineButton(
- stringResource(R.string.disappearing_messages_set_button_title),
+ stringResource(R.string.set),
modifier = Modifier
- .contentDescription(R.string.AccessibilityId_set_button)
+ .contentDescription(R.string.AccessibilityId_setButton)
.align(Alignment.CenterHorizontally)
.padding(bottom = LocalDimensions.current.spacing),
onClick = callbacks::onSetClick
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/home/StartConversation.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/home/StartConversation.kt
index 15ca216777..f00fbf44a9 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/home/StartConversation.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/home/StartConversation.kt
@@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
@@ -41,12 +42,14 @@ internal fun StartConversationScreen(
accountId: String,
delegate: StartConversationDelegate
) {
+ val context = LocalContext.current
+
Column(modifier = Modifier.background(
LocalColors.current.backgroundSecondary,
shape = MaterialTheme.shapes.small
)) {
BasicAppBar(
- title = stringResource(R.string.dialog_start_conversation_title),
+ title = stringResource(R.string.conversationsStart),
backgroundColor = Color.Transparent, // transparent to show the rounded shape of the container
actions = { AppBarCloseIcon(onClose = delegate::onDialogClosePressed) }
)
@@ -57,30 +60,31 @@ internal fun StartConversationScreen(
Column(
modifier = Modifier.verticalScroll(rememberScrollState())
) {
+ val newMessageTitleTxt:String = context.resources.getQuantityString(R.plurals.messageNew, 1, 1)
ItemButton(
- textId = R.string.messageNew,
+ text = newMessageTitleTxt,
icon = R.drawable.ic_message,
- modifier = Modifier.contentDescription(R.string.AccessibilityId_new_direct_message),
+ modifier = Modifier.contentDescription(R.string.AccessibilityId_messageNew),
onClick = delegate::onNewMessageSelected)
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(
- textId = R.string.activity_create_group_title,
+ textId = R.string.groupCreate,
icon = R.drawable.ic_group,
- modifier = Modifier.contentDescription(R.string.AccessibilityId_create_group),
+ modifier = Modifier.contentDescription(R.string.AccessibilityId_groupCreate),
onClick = delegate::onCreateGroupSelected
)
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(
- textId = R.string.dialog_join_community_title,
+ textId = R.string.communityJoin,
icon = R.drawable.ic_globe,
- modifier = Modifier.contentDescription(R.string.AccessibilityId_join_community),
+ modifier = Modifier.contentDescription(R.string.AccessibilityId_communityJoin),
onClick = delegate::onJoinCommunitySelected
)
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(
- textId = R.string.activity_settings_invite_button_title,
+ textId = R.string.sessionInviteAFriend,
icon = R.drawable.ic_invite_friend,
- Modifier.contentDescription(R.string.AccessibilityId_invite_friend_button),
+ Modifier.contentDescription(R.string.AccessibilityId_sessionInviteAFriendButton),
onClick = delegate::onInviteFriend
)
Column(
@@ -99,7 +103,7 @@ internal fun StartConversationScreen(
Spacer(modifier = Modifier.height(LocalDimensions.current.smallSpacing))
QrImage(
string = accountId,
- Modifier.contentDescription(R.string.AccessibilityId_qr_code),
+ Modifier.contentDescription(R.string.AccessibilityId_qrCode),
icon = R.drawable.session
)
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/invitefriend/InviteFriend.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/invitefriend/InviteFriend.kt
index 3453fb5722..bc298c5bd3 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/invitefriend/InviteFriend.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/invitefriend/InviteFriend.kt
@@ -14,10 +14,13 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.thoughtcrime.securesms.ui.components.AppBarCloseIcon
import org.thoughtcrime.securesms.ui.components.BackAppBar
import org.thoughtcrime.securesms.ui.components.SlimOutlineButton
@@ -43,7 +46,7 @@ internal fun InviteFriend(
shape = MaterialTheme.shapes.small
)) {
BackAppBar(
- title = stringResource(R.string.invite_a_friend),
+ title = stringResource(R.string.sessionInviteAFriend),
backgroundColor = Color.Transparent, // transparent to show the rounded shape of the container
onBack = onBack,
actions = { AppBarCloseIcon(onClose = onClose) }
@@ -55,7 +58,7 @@ internal fun InviteFriend(
Text(
accountId,
modifier = Modifier
- .contentDescription(R.string.AccessibilityId_account_id)
+ .contentDescription(R.string.AccessibilityId_shareAccountId)
.fillMaxWidth()
.border()
.padding(LocalDimensions.current.spacing),
@@ -66,7 +69,10 @@ internal fun InviteFriend(
Spacer(modifier = Modifier.height(LocalDimensions.current.xsSpacing))
Text(
- stringResource(R.string.invite_your_friend_to_chat_with_you_on_session_by_sharing_your_account_id_with_them),
+ stringResource(R.string.shareAccountIdDescription).let { txt ->
+ val c = LocalContext.current
+ Phrase.from(txt).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString()
+ },
textAlign = TextAlign.Center,
style = LocalType.current.small,
color = LocalColors.current.textSecondary,
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessage.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessage.kt
index df54f9cae8..0a40c6ee39 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessage.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessage.kt
@@ -32,6 +32,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
@@ -61,7 +62,7 @@ import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.theme.ThemeColors
import kotlin.math.max
-private val TITLES = listOf(R.string.enter_account_id, R.string.qrScan)
+private val TITLES = listOf(R.string.accountIdEnter, R.string.qrScan)
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
@@ -79,8 +80,12 @@ internal fun NewMessage(
LocalColors.current.backgroundSecondary,
shape = MaterialTheme.shapes.small
)) {
+ // `messageNew` is now a plurals string so get the singular version
+ val context = LocalContext.current
+ val newMessageTitleTxt:String = context.resources.getQuantityString(R.plurals.messageNew, 1, 1)
+
BackAppBar(
- title = stringResource(R.string.messageNew),
+ title = newMessageTitleTxt,
backgroundColor = Color.Transparent, // transparent to show the rounded shape of the container
onBack = onBack,
actions = { AppBarCloseIcon(onClose = onClose) }
@@ -88,7 +93,7 @@ internal fun NewMessage(
SessionTabRow(pagerState, TITLES)
HorizontalPager(pagerState) {
when (TITLES[it]) {
- R.string.enter_account_id -> EnterAccountId(state, callbacks, onHelp)
+ R.string.accountIdEnter -> EnterAccountId(state, callbacks, onHelp)
R.string.qrScan -> QRScannerScreen(qrErrors, onScan = callbacks::onScanQrCode)
}
}
@@ -116,7 +121,7 @@ private fun EnterAccountId(
.verticalScroll(rememberScrollState())
// There is a known issue with the ime padding on android versions below 30
- /// So on these older versions we need to resort to some manual padding based on the visible height
+ // So on these older versions we need to resort to some manual padding based on the visible height
// when the keyboard is up
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
val keyboardHeight by keyboardHeight()
@@ -149,9 +154,9 @@ private fun EnterAccountId(
Spacer(modifier = Modifier.height(LocalDimensions.current.xxxsSpacing))
BorderlessButtonWithIcon(
- text = stringResource(R.string.messageNewDescription),
+ text = stringResource(R.string.messageNewDescriptionMobile),
modifier = Modifier
- .contentDescription(R.string.AccessibilityId_help_desk_link)
+ .contentDescription(R.string.AccessibilityId_messageNewDescriptionMobile)
.padding(horizontal = LocalDimensions.current.mediumSpacing)
.fillMaxWidth(),
style = LocalType.current.small,
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessageViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessageViewModel.kt
index 6ed8a08233..0eea896a06 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessageViewModel.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/newmessage/NewMessageViewModel.kt
@@ -4,6 +4,8 @@ import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
+import java.util.concurrent.TimeoutException
+import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.BufferOverflow
@@ -19,8 +21,6 @@ import org.session.libsession.snode.SnodeAPI
import org.session.libsignal.utilities.PublicKeyValidation
import org.session.libsignal.utilities.timeout
import org.thoughtcrime.securesms.ui.GetString
-import java.util.concurrent.TimeoutException
-import javax.inject.Inject
@HiltViewModel
internal class NewMessageViewModel @Inject constructor(
@@ -41,7 +41,6 @@ internal class NewMessageViewModel @Inject constructor(
override fun onChange(value: String) {
loadOnsJob?.cancel()
loadOnsJob = null
-
_state.update { it.copy(newMessageIdOrOns = value, isTextErrorColor = false, loading = false) }
}
@@ -59,7 +58,7 @@ internal class NewMessageViewModel @Inject constructor(
if (PublicKeyValidation.isValid(value, isPrefixRequired = false) && PublicKeyValidation.hasValidPrefix(value)) {
onPublicKey(value)
} else {
- _qrErrors.tryEmit(application.getString(R.string.this_qr_code_does_not_contain_an_account_id))
+ _qrErrors.tryEmit(application.getString(R.string.qrNotAccountId))
}
}
@@ -99,7 +98,7 @@ internal class NewMessageViewModel @Inject constructor(
private fun Exception.toMessage() = when (this) {
is SnodeAPI.Error.Generic -> application.getString(R.string.onsErrorNotRecognized)
is TimeoutException -> application.getString(R.string.onsErrorUnableToSearch)
- else -> application.getString(R.string.fragment_enter_public_key_error_message)
+ else -> application.getString(R.string.accountIdErrorInvalid)
}
}
@@ -112,4 +111,4 @@ internal data class State(
val isNextButtonEnabled: Boolean get() = newMessageIdOrOns.isNotBlank()
}
-internal data class Success(val publicKey: String)
+internal data class Success(val publicKey: String)
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt
index 306b1699ae..51ca3bf685 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt
@@ -7,6 +7,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
+import android.content.pm.PackageManager
import android.content.res.Resources
import android.database.Cursor
import android.graphics.Rect
@@ -18,10 +19,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
-import android.text.SpannableStringBuilder
-import android.text.SpannedString
import android.text.TextUtils
-import android.text.style.StyleSpan
import android.util.Pair
import android.util.TypedValue
import android.view.ActionMode
@@ -35,8 +33,12 @@ import android.widget.Toast
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
-import androidx.core.text.set
-import androidx.core.text.toSpannable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.platform.ViewCompositionStrategy
+import androidx.core.content.ContextCompat
+import androidx.core.view.drawToBitmap
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.DialogFragment
@@ -51,6 +53,8 @@ import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.annimon.stream.Stream
+import com.bumptech.glide.Glide
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
@@ -64,7 +68,6 @@ import network.loki.messenger.databinding.ActivityConversationV2Binding
import network.loki.messenger.libsession_util.util.ExpiryMode
import nl.komponents.kovenant.ui.successUi
import org.session.libsession.messaging.MessagingModuleConfiguration
-import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.messaging.messages.applyExpiryMode
import org.session.libsession.messaging.messages.control.DataExtractionNotification
@@ -84,6 +87,10 @@ import org.session.libsession.utilities.Address
import org.session.libsession.utilities.Address.Companion.fromSerialized
import org.session.libsession.utilities.GroupUtil
import org.session.libsession.utilities.MediaTypes
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.CONVERSATION_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.session.libsession.utilities.Stub
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.concurrent.SimpleTask
@@ -97,6 +104,7 @@ import org.session.libsignal.utilities.guava.Optional
import org.session.libsignal.utilities.hexEncodedPrivateKey
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
+import org.thoughtcrime.securesms.SessionDialogBuilder
import org.thoughtcrime.securesms.attachments.ScreenshotObserver
import org.thoughtcrime.securesms.audio.AudioRecorder
import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel
@@ -155,7 +163,6 @@ import org.thoughtcrime.securesms.mediasend.Media
import org.thoughtcrime.securesms.mediasend.MediaSendActivity
import org.thoughtcrime.securesms.mms.AudioSlide
import org.thoughtcrime.securesms.mms.GifSlide
-import com.bumptech.glide.Glide
import org.thoughtcrime.securesms.mms.ImageSlide
import org.thoughtcrime.securesms.mms.MediaConstraints
import org.thoughtcrime.securesms.mms.Slide
@@ -165,19 +172,21 @@ import org.thoughtcrime.securesms.permissions.Permissions
import org.thoughtcrime.securesms.reactions.ReactionsDialogFragment
import org.thoughtcrime.securesms.reactions.any.ReactWithAnyEmojiDialogFragment
import org.thoughtcrime.securesms.showSessionDialog
+import org.thoughtcrime.securesms.ui.OpenURLAlertDialog
+import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme
import org.thoughtcrime.securesms.util.ActivityDispatcher
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.MediaUtil
import org.thoughtcrime.securesms.util.NetworkUtils
import org.thoughtcrime.securesms.util.SaveAttachmentTask
-import org.thoughtcrime.securesms.util.drawToBitmap
import org.thoughtcrime.securesms.util.isScrolledToBottom
import org.thoughtcrime.securesms.util.isScrolledToWithin30dpOfBottom
import org.thoughtcrime.securesms.util.push
import org.thoughtcrime.securesms.util.show
import org.thoughtcrime.securesms.util.toPx
import java.lang.ref.WeakReference
+import java.util.LinkedList
import java.util.Locale
import java.util.concurrent.ExecutionException
import java.util.concurrent.atomic.AtomicBoolean
@@ -188,6 +197,8 @@ import kotlin.math.abs
import kotlin.math.min
import kotlin.math.roundToInt
import kotlin.math.sqrt
+import kotlin.time.Duration.Companion.minutes
+
private const val TAG = "ConversationActivityV2"
@@ -231,6 +242,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
.get(LinkPreviewViewModel::class.java)
}
+ private var openLinkDialogUrl: String? by mutableStateOf(null)
+
private val threadId: Long by lazy {
var threadId = intent.getLongExtra(THREAD_ID, -1L)
if (threadId == -1L) {
@@ -279,8 +292,17 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
var searchViewItem: MenuItem? = null
private val bufferedLastSeenChannel = Channel(capacity = 512, onBufferOverflow = BufferOverflow.DROP_OLDEST)
+
private var emojiPickerVisible = false
+ // Queue of timestamps used to rate-limit emoji reactions
+ private val emojiRateLimiterQueue = LinkedList()
+
+ // Constants used to enforce the given maximum emoji reactions allowed per minute (emoji reactions
+ // that occur above this limit will result in a "Slow down" toast rather than adding the reaction).
+ private val EMOJI_REACTIONS_ALLOWED_PER_MINUTE = 20
+ private val ONE_MINUTE_IN_MILLISECONDS = 1.minutes.inWholeMilliseconds
+
private val isScrolledToBottom: Boolean
get() = binding.conversationRecyclerView.isScrolledToBottom
@@ -385,12 +407,33 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
// endregion
+ fun showOpenUrlDialog(url: String){
+ openLinkDialogUrl = url
+ }
+
// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
binding = ActivityConversationV2Binding.inflate(layoutInflater)
setContentView(binding.root)
+ // set the compose dialog content
+ binding.dialogOpenUrl.apply {
+ setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
+ setContent {
+ SessionMaterialTheme {
+ if(!openLinkDialogUrl.isNullOrEmpty()){
+ OpenURLAlertDialog(
+ url = openLinkDialogUrl!!,
+ onDismissRequest = {
+ openLinkDialogUrl = null
+ }
+ )
+ }
+ }
+ }
+ }
+
// messageIdToScroll
messageToScrollTimestamp.set(intent.getLongExtra(SCROLL_MESSAGE_ID, -1))
messageToScrollAuthor.set(intent.getParcelableExtra(SCROLL_MESSAGE_AUTHOR))
@@ -704,7 +747,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
override fun onFailure(e: ExecutionException?) {
- Toast.makeText(this@ConversationActivityV2, R.string.activity_conversation_attachment_prep_failed, Toast.LENGTH_LONG).show()
+ Toast.makeText(this@ConversationActivityV2, R.string.attachmentsErrorLoad, Toast.LENGTH_LONG).show()
}
})
return
@@ -755,9 +798,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
// called from onCreate
private fun setUpBlockedBanner() {
val recipient = viewModel.recipient?.takeUnless { it.isGroupRecipient } ?: return
- val accountID = recipient.address.toString()
- val name = sessionContactDb.getContactWithAccountID(accountID)?.displayName(Contact.ContactContext.REGULAR) ?: accountID
- binding.blockedBannerTextView.text = resources.getString(R.string.activity_conversation_blocked_banner_text, name)
+ binding.blockedBannerTextView.text = applicationContext.getString(R.string.blockBlockedDescription)
binding.blockedBanner.isVisible = recipient.isBlocked
binding.blockedBanner.setOnClickListener { viewModel.unblock() }
}
@@ -770,8 +811,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
binding.outdatedBanner.isVisible = shouldShowLegacy
if (shouldShowLegacy) {
- binding.outdatedBannerTextView.text =
- resources.getString(R.string.activity_conversation_outdated_client_banner_text, legacyRecipient!!.name)
+
+ val txt = Phrase.from(applicationContext, R.string.disappearingMessagesLegacy)
+ .put(NAME_KEY, legacyRecipient!!.name)
+ .format()
+ binding?.outdatedBannerTextView?.text = txt
}
}
@@ -1056,34 +1100,48 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
updateUnreadCountIndicator()
}
+ // Update placeholder / control messages in a conversation
private fun updatePlaceholder() {
val recipient = viewModel.recipient ?: return Log.w("Loki", "recipient was null in placeholder update")
val blindedRecipient = viewModel.blindedRecipient
val openGroup = viewModel.openGroup
- val (textResource, insertParam) = when {
- recipient.isLocalNumber -> R.string.activity_conversation_empty_state_note_to_self to null
- openGroup != null && !openGroup.canWrite -> R.string.activity_conversation_empty_state_read_only to recipient.toShortString()
- blindedRecipient?.blocksCommunityMessageRequests == true -> R.string.activity_conversation_empty_state_blocks_community_requests to recipient.toShortString()
- else -> R.string.activity_conversation_empty_state_default to recipient.toShortString()
+ // Get the correct placeholder text for this type of empty conversation
+ val isNoteToSelf = recipient.isLocalNumber
+ val txtCS: CharSequence = when {
+ recipient.isLocalNumber -> getString(R.string.noteToSelfEmpty)
+
+ // If this is a community which we cannot write to
+ openGroup != null && !openGroup.canWrite -> {
+ Phrase.from(applicationContext, R.string.conversationsEmpty)
+ .put(CONVERSATION_NAME_KEY, openGroup.name)
+ .format()
+ }
+
+ // If we're trying to message someone who has blocked community message requests
+ blindedRecipient?.blocksCommunityMessageRequests == true -> {
+ Phrase.from(applicationContext, R.string.messageRequestsTurnedOff)
+ .put(NAME_KEY, recipient.toShortString())
+ .format()
+ }
+
+ recipient.isGroupRecipient -> {
+ // If this is a group or community that we CAN send messages to
+ Phrase.from(applicationContext, R.string.groupNoMessages)
+ .put(GROUP_NAME_KEY, recipient.toShortString())
+ .format()
+ }
+
+ else -> {
+ Log.w(TAG, "Something else happened in updatePlaceholder - we're not sure what.")
+ ""
+ }
}
+
val showPlaceholder = adapter.itemCount == 0
binding.placeholderText.isVisible = showPlaceholder
if (showPlaceholder) {
- if (insertParam != null) {
- val span = getText(textResource) as SpannedString
- val annotations = span.getSpans(0, span.length, StyleSpan::class.java)
- val boldSpan = annotations.first()
- val spannedParam = insertParam.toSpannable()
- spannedParam[0 until spannedParam.length] = StyleSpan(boldSpan.style)
- val originalStart = span.getSpanStart(boldSpan)
- val originalEnd = span.getSpanEnd(boldSpan)
- val newString = SpannableStringBuilder(span)
- .replace(originalStart, originalEnd, spannedParam)
- binding.placeholderText.text = newString
- } else {
- binding.placeholderText.setText(textResource)
- }
+ binding.placeholderText.text = txtCS
}
}
@@ -1117,11 +1175,21 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
override fun block(deleteThread: Boolean) {
+ val recipient = viewModel.recipient ?: return Log.w("Loki", "Recipient was null for block action")
showSessionDialog {
- title(R.string.RecipientPreferenceActivity_block_this_contact_question)
- text(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
- dangerButton(R.string.RecipientPreferenceActivity_block, R.string.AccessibilityId_block_confirm) {
+ title(R.string.block)
+ text(
+ Phrase.from(context, R.string.blockDescription)
+ .put(NAME_KEY, recipient.name)
+ .format()
+ )
+ dangerButton(R.string.block, R.string.AccessibilityId_blockConfirm) {
viewModel.block()
+
+ // Block confirmation toast added as per SS-64
+ val txt = Phrase.from(context, R.string.blockBlockedUser).put(NAME_KEY, recipient.name).format().toString()
+ Toast.makeText(context, txt, Toast.LENGTH_LONG).show()
+
if (deleteThread) {
viewModel.deleteThread()
finish()
@@ -1135,7 +1203,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val clip = ClipData.newPlainText("Account ID", accountId)
val manager = getSystemService(PassphraseRequiredActionBarActivity.CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(clip)
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
}
override fun copyOpenGroupUrl(thread: Recipient) {
@@ -1147,7 +1215,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val clip = ClipData.newPlainText("Community URL", openGroup.joinURL)
val manager = getSystemService(PassphraseRequiredActionBarActivity.CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(clip)
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
}
override fun showDisappearingMessages(thread: Recipient) {
@@ -1160,13 +1228,20 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
override fun unblock() {
+ val recipient = viewModel.recipient ?: return Log.w("Loki", "Recipient was null for unblock action")
+
+ if (!recipient.isContactRecipient) {
+ return Log.w("Loki", "Cannot unblock a user who is not a contact recipient - aborting unblock attempt.")
+ }
+
showSessionDialog {
- title(R.string.ConversationActivity_unblock_this_contact_question)
- text(R.string.ConversationActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
- dangerButton(
- R.string.ConversationActivity_unblock,
- R.string.AccessibilityId_block_confirm
- ) { viewModel.unblock() }
+ title(R.string.blockUnblock)
+ text(
+ Phrase.from(context, R.string.blockUnblockName)
+ .put(NAME_KEY, recipient.name)
+ .format()
+ )
+ dangerButton(R.string.blockUnblock, R.string.AccessibilityId_unblockConfirm) { viewModel.unblock() }
cancelButton()
}
}
@@ -1177,10 +1252,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (actionMode != null) {
onDeselect(message, position, actionMode)
} else {
- // NOTE:
- // We have to use onContentClick (rather than a click listener directly on
+ // NOTE: We have to use onContentClick (rather than a click listener directly on
// the view) so as to not interfere with all the other gestures. Do not add
- // onClickListeners directly to message content views.
+ // onClickListeners directly to message content views!
view.onContentClick(event)
}
}
@@ -1279,7 +1353,45 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
}
+ // Method to add an emoji to a queue and remove it a short while later - this is used as a
+ // rate-limiting mechanism and is called from the `sendEmojiReaction` method, below.
+
+ fun canPerformEmojiReaction(timestamp: Long): Boolean {
+ // If the emoji reaction queue is full..
+ if (emojiRateLimiterQueue.size >= EMOJI_REACTIONS_ALLOWED_PER_MINUTE) {
+ // ..grab the timestamp of the oldest emoji reaction.
+ val headTimestamp = emojiRateLimiterQueue.peekFirst()
+ if (headTimestamp == null) {
+ Log.w(TAG, "Could not get emoji react head timestamp - should never happen, but we'll allow the emoji reaction.")
+ return true
+ }
+
+ // With the queue full, if the earliest emoji reaction occurred less than 1 minute ago
+ // then we reject it..
+ if (System.currentTimeMillis() - headTimestamp <= ONE_MINUTE_IN_MILLISECONDS) {
+ return false
+ } else {
+ // ..otherwise if the earliest emoji reaction was more than a minute ago we'll
+ // remove that early reaction to move the timestamp at index 1 into index 0, add
+ // our new timestamp and return true to accept the emoji reaction.
+ emojiRateLimiterQueue.removeFirst()
+ emojiRateLimiterQueue.addLast(timestamp)
+ return true
+ }
+ } else {
+ // If the queue isn't already full then we add the new timestamp to the back of the queue and allow the emoji reaction
+ emojiRateLimiterQueue.addLast(timestamp)
+ return true
+ }
+ }
+
private fun sendEmojiReaction(emoji: String, originalMessage: MessageRecord) {
+ // Only allow the emoji reaction if we aren't currently rate limited
+ if (!canPerformEmojiReaction(System.currentTimeMillis())) {
+ Toast.makeText(this, getString(R.string.emojiReactsCoolDown), Toast.LENGTH_SHORT).show()
+ return
+ }
+
// Create the message
val recipient = viewModel.recipient ?: return Log.w(TAG, "Could not locate recipient when sending emoji reaction")
val reactionMessage = VisibleMessage()
@@ -1325,6 +1437,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
}
+ // Method to remove a emoji reaction from a message.
+ // Note: We do not count emoji removal towards the emojiRateLimiterQueue.
private fun sendEmojiRemoval(emoji: String, originalMessage: MessageRecord) {
val recipient = viewModel.recipient ?: return
val message = VisibleMessage()
@@ -1591,9 +1705,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val isNoteToSelf = (recipient.isContactRecipient && recipient.address.toString() == userPublicKey)
if (seed in text && !isNoteToSelf && !hasPermissionToSendSeed) {
showSessionDialog {
- title(R.string.dialog_send_seed_title)
- text(R.string.dialog_send_seed_explanation)
- button(R.string.dialog_send_seed_send_button_title) { sendTextOnlyMessage(true) }
+ title(R.string.warning)
+ text(R.string.recoveryPasswordWarningSendDescription)
+ button(R.string.send) { sendTextOnlyMessage(true) }
cancelButton()
}
@@ -1673,9 +1787,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val hasSeenGIFMetaDataWarning: Boolean = textSecurePreferences.hasSeenGIFMetaDataWarning()
if (!hasSeenGIFMetaDataWarning) {
showSessionDialog {
- title(R.string.giphy_permission_title)
- text(R.string.giphy_permission_message)
- button(R.string.continue_2) {
+ title(R.string.giphyWarning)
+ text(Phrase.from(context, R.string.giphyWarningDescription).put(APP_NAME_KEY, getString(R.string.app_name)).format())
+ button(R.string.theContinue) {
textSecurePreferences.setHasSeenGIFMetaDataWarning()
selectGif()
}
@@ -1718,11 +1832,27 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val mediaPreppedListener = object : ListenableFuture.Listener {
override fun onSuccess(result: Boolean?) {
+ if (result == null) {
+ Log.w(TAG, "Media prepper returned a null result - bailing.")
+ return
+ }
+
+ // If the attachment was too large or MediaConstraints.isSatisfied failed for some
+ // other reason then we reset the attachment manager & shown buttons then bail..
+ if (!result) {
+ attachmentManager.clear()
+ if (isShowingAttachmentOptions) { toggleAttachmentOptions() }
+ return
+ }
+
+ // ..otherwise we can attempt to send the attachment(s).
+ // Note: The only multi-attachment message type is when sending images - all others
+ // attempt send the attachment immediately upon file selection.
sendAttachments(attachmentManager.buildSlideDeck().asAttachments(), null)
}
override fun onFailure(e: ExecutionException?) {
- Toast.makeText(this@ConversationActivityV2, R.string.activity_conversation_attachment_prep_failed, Toast.LENGTH_LONG).show()
+ Toast.makeText(this@ConversationActivityV2, R.string.attachmentsErrorLoad, Toast.LENGTH_LONG).show()
}
}
when (requestCode) {
@@ -1805,8 +1935,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} else {
Permissions.with(this)
.request(Manifest.permission.RECORD_AUDIO)
- .withRationaleDialog(getString(R.string.ConversationActivity_to_send_audio_messages_allow_signal_access_to_your_microphone), R.drawable.ic_baseline_mic_48)
- .withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_requires_the_microphone_permission_in_order_to_send_audio_messages))
+ .withRationaleDialog(getString(R.string.permissionsMicrophoneAccessRequired), R.drawable.ic_baseline_mic_48)
+ .withPermanentDenialDialog(Phrase.from(applicationContext, R.string.permissionsMicrophoneAccessRequired)
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .format().toString())
.execute()
}
}
@@ -1876,7 +2008,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
override fun onFailure(e: ExecutionException) {
- Toast.makeText(this@ConversationActivityV2, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show()
+ Toast.makeText(this@ConversationActivityV2, R.string.audioUnableToRecord, Toast.LENGTH_LONG).show()
}
})
}
@@ -1927,10 +2059,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
private fun showDeleteLocallyUI(messages: Set) {
- val messageCount = 1
showSessionDialog {
- title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
- text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
+ title(resources.getQuantityString(R.plurals.deleteMessage, messages.count(), messages.count()))
+ text(resources.getString(R.string.deleteMessagesDescriptionDevice))
button(R.string.delete) { messages.forEach(viewModel::deleteLocally); endActionMode() }
cancelButton(::endActionMode)
}
@@ -1950,13 +2081,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
// If the recipient is a community OR a Note-to-Self then we delete the message for everyone
if (recipient.isCommunityRecipient || recipient.isLocalNumber) {
- val messageCount = 1 // Only used for plurals string
showSessionDialog {
- title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
- text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
- button(R.string.delete) {
- messages.forEach(viewModel::deleteForEveryone); endActionMode()
- }
+ title(resources.getQuantityString(R.plurals.deleteMessage, messages.count(), messages.count()))
+ text(resources.getString(R.string.deleteMessageDescriptionEveryone))
+ button(R.string.delete) { messages.forEach(viewModel::deleteForEveryone); endActionMode() }
cancelButton { endActionMode() }
}
// Otherwise if this is a 1-on-1 conversation we may decided to delete just for ourselves or delete for everyone
@@ -1981,13 +2109,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
else // Finally, if this is a closed group and you are deleting someone else's message(s) then we can only delete locally.
{
- val messageCount = 1
showSessionDialog {
- title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount))
- text(resources.getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messageCount, messageCount))
- button(R.string.delete) {
- messages.forEach(viewModel::deleteLocally); endActionMode()
- }
+ title(resources.getQuantityString(R.plurals.deleteMessage, messages.count(), messages.count()))
+ text(resources.getString(R.string.deleteMessageDescriptionDevice))
+ dangerButton(R.string.delete) { messages.forEach(viewModel::deleteLocally); endActionMode() }
cancelButton(::endActionMode)
}
}
@@ -1995,18 +2120,18 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
override fun banUser(messages: Set) {
showSessionDialog {
- title(R.string.ConversationFragment_ban_selected_user)
- text("This will ban the selected user from this room. It won't ban them from other rooms.")
- button(R.string.ban) { viewModel.banUser(messages.first().individualRecipient); endActionMode() }
+ title(R.string.banUser)
+ text(R.string.communityBanDescription)
+ button(R.string.banUser) { viewModel.banUser(messages.first().individualRecipient); endActionMode() }
cancelButton(::endActionMode)
}
}
override fun banAndDeleteAll(messages: Set) {
showSessionDialog {
- title(R.string.ConversationFragment_ban_selected_user)
- text("This will ban the selected user from this room and delete all messages sent by them. It won't ban them from other rooms or delete the messages they sent there.")
- button(R.string.ban) { viewModel.banAndDeleteAll(messages.first()); endActionMode() }
+ title(R.string.banUser)
+ text(R.string.communityBanDeleteDescription)
+ button(R.string.banUser) { viewModel.banAndDeleteAll(messages.first()); endActionMode() }
cancelButton(::endActionMode)
}
}
@@ -2042,7 +2167,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (TextUtils.isEmpty(result)) { return }
val manager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(ClipData.newPlainText("Message Content", result))
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
endActionMode()
}
@@ -2051,7 +2176,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val clip = ClipData.newPlainText("Account ID", accountID)
val manager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(clip)
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
endActionMode()
}
@@ -2093,41 +2218,95 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
endActionMode()
}
+ private fun saveAttachments(message: MmsMessageRecord) {
+ val attachments: List = Stream.of(message.slideDeck.slides)
+ .filter { s: Slide -> s.uri != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument()) }
+ .map { s: Slide -> SaveAttachmentTask.Attachment(s.uri!!, s.contentType, message.dateReceived, s.fileName.orNull()) }
+ .toList()
+ if (attachments.isNotEmpty()) {
+ val saveTask = SaveAttachmentTask(this)
+ saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, *attachments.toTypedArray())
+ if (!message.isOutgoing) { sendMediaSavedNotification() }
+ return
+ }
+ // Implied else that there were no attachment(s)
+ Toast.makeText(this, resources.getString(R.string.attachmentsSaveError), Toast.LENGTH_LONG).show()
+ }
+
+ private fun hasPermission(permission: String): Boolean {
+ val result = ContextCompat.checkSelfPermission(this, permission)
+ return result == PackageManager.PERMISSION_GRANTED
+ }
+
override fun saveAttachment(messages: Set) {
val message = messages.first() as MmsMessageRecord
- // Do not allow the user to download a file attachment before it has finished downloading
+ // Note: The save option is only added to the menu in ConversationReactionOverlay.getMenuActionItems
+ // if the attachment has finished downloading, so we don't really have to check for message.isMediaPending
+ // here - but we'll do it anyway and bail should that be the case as a defensive programming strategy.
if (message.isMediaPending) {
- Toast.makeText(this, resources.getString(R.string.conversation_activity__wait_until_attachment_has_finished_downloading), Toast.LENGTH_LONG).show()
+ Log.w(TAG, "Somehow we were asked to download an attachment before it had finished downloading - aborting download.")
return
}
- SaveAttachmentTask.showWarningDialog(this) {
+ // Before saving an attachment, regardless of Android API version or permissions, we always want to ensure
+ // that we've warned the user just _once_ that any attachments they save can be accessed by other apps.
+ val haveWarned = TextSecurePreferences.getHaveWarnedUserAboutSavingAttachments(this)
+ if (haveWarned) {
+ // On Android versions below 30 we require the WRITE_EXTERNAL_STORAGE permission to save attachments.
+ if (Build.VERSION.SDK_INT < 30) {
+ // Save the attachment(s) then bail if we already have permission to do so
+ if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
+ saveAttachments(message)
+ return
+ } else {
+ /* If we don't have the permission then do nothing - which means we continue on to the SaveAttachmentTask part below where we ask for permissions */
+ }
+ } else {
+ // On more modern versions of Android on API 30+ WRITE_EXTERNAL_STORAGE is no longer used and we can just
+ // save files to the public directories like "Downloads", "Pictures" etc.
+ saveAttachments(message)
+ return
+ }
+ }
+
+ // ..otherwise we must ask for it first (only on Android APIs up to 28).
+ SaveAttachmentTask.showOneTimeWarningDialogOrSave(this) {
Permissions.with(this)
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
- .maxSdkVersion(Build.VERSION_CODES.P)
- .withPermanentDenialDialog(getString(R.string.MediaPreviewActivity_signal_needs_the_storage_permission_in_order_to_write_to_external_storage_but_it_has_been_permanently_denied))
+ .maxSdkVersion(Build.VERSION_CODES.P) // P is 28
+ .withPermanentDenialDialog(Phrase.from(applicationContext, R.string.permissionsStorageSaveDenied)
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .format().toString())
.onAnyDenied {
endActionMode()
- Toast.makeText(this@ConversationActivityV2, R.string.MediaPreviewActivity_unable_to_write_to_external_storage_without_permission, Toast.LENGTH_LONG).show()
+
+ // If permissions were denied inform the user that we can't proceed without them and offer to take the user to Settings
+ showSessionDialog {
+ title(R.string.permissionsRequired)
+
+ val txt = Phrase.from(applicationContext, R.string.permissionsStorageSaveDenied)
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .format().toString()
+ text(txt)
+
+ // Take the user directly to the settings app for Session to grant the permission if they
+ // initially denied it but then have a change of heart when they realise they can't
+ // proceed without it.
+ dangerButton(R.string.theContinue) {
+ val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ val uri = Uri.fromParts("package", packageName, null)
+ intent.setData(uri)
+ startActivity(intent)
+ }
+
+ button(R.string.cancel)
+ }
}
.onAllGranted {
endActionMode()
- val attachments: List = Stream.of(message.slideDeck.slides)
- .filter { s: Slide -> s.uri != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument()) }
- .map { s: Slide -> SaveAttachmentTask.Attachment(s.uri!!, s.contentType, message.dateReceived, s.fileName.orNull()) }
- .toList()
- if (attachments.isNotEmpty()) {
- val saveTask = SaveAttachmentTask(this)
- saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, *attachments.toTypedArray())
- if (!message.isOutgoing) {
- sendMediaSavedNotification()
- }
- return@onAllGranted
- }
- Toast.makeText(this,
- resources.getQuantityString(R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card, 1),
- Toast.LENGTH_LONG).show()
+ saveAttachments(message)
}
.execute()
}
@@ -2182,6 +2361,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
searchViewModel.onMissingResult() }
}
}
+
binding.searchBottomBar.setData(result.position, result.getResults().size)
})
}
@@ -2191,6 +2371,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
binding.searchBottomBar.visibility = View.VISIBLE
binding.searchBottomBar.setData(0, 0)
binding.inputBar.visibility = View.INVISIBLE
+
}
fun onSearchClosed() {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt
index 1c57dc8d5f..d75d14ea4a 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt
@@ -12,6 +12,8 @@ import androidx.core.util.getOrDefault
import androidx.core.util.set
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.recyclerview.widget.RecyclerView.ViewHolder
+import java.util.concurrent.atomic.AtomicLong
+import kotlin.math.min
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
@@ -20,6 +22,7 @@ import kotlinx.coroutines.launch
import network.loki.messenger.R
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.thoughtcrime.securesms.conversation.v2.messages.ControlMessageView
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageViewDelegate
@@ -29,8 +32,8 @@ import org.thoughtcrime.securesms.dependencies.DatabaseComponent
import com.bumptech.glide.RequestManager
import org.thoughtcrime.securesms.preferences.PrivacySettingsActivity
import org.thoughtcrime.securesms.showSessionDialog
-import java.util.concurrent.atomic.AtomicLong
-import kotlin.math.min
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
+import org.thoughtcrime.securesms.ui.getSubbedString
class ConversationAdapter(
context: Context,
@@ -154,9 +157,13 @@ class ConversationAdapter(
if (message.isCallLog && message.isFirstMissedCall) {
viewHolder.view.setOnClickListener {
context.showSessionDialog {
- title(R.string.CallNotificationBuilder_first_call_title)
- text(R.string.CallNotificationBuilder_first_call_message)
- button(R.string.activity_settings_title) {
+ val titleTxt = context.getSubbedString(R.string.callsMissedCallFrom, NAME_KEY to message.individualRecipient.name!!)
+ title(titleTxt)
+
+ val bodyTxt = context.getSubbedCharSequence(R.string.callsYouMissedCallPermissions, NAME_KEY to message.individualRecipient.name!!)
+ text(bodyTxt)
+
+ button(R.string.sessionSettings) {
Intent(context, PrivacySettingsActivity::class.java)
.let(context::startActivity)
}
@@ -190,7 +197,7 @@ class ConversationAdapter(
private fun getMessageBefore(position: Int, cursor: Cursor): MessageRecord? {
// The message that's visually before the current one is actually after the current
// one for the cursor because the layout is reversed
- if (isReversed && !cursor.moveToPosition(position + 1)) { return null }
+ if (isReversed && !cursor.moveToPosition(position + 1)) { return null }
if (!isReversed && !cursor.moveToPosition(position - 1)) { return null }
return messageDB.readerFor(cursor).current
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt
index 9f2046334b..8fff54833f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt
@@ -22,7 +22,11 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.view.doOnLayout
import androidx.vectordrawable.graphics.drawable.AnimatorInflaterCompat
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
+import java.util.Locale
+import javax.inject.Inject
+import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -30,7 +34,9 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import network.loki.messenger.R
+import org.session.libsession.LocalisedTimeUtil.toShortTwoPartString
import org.session.libsession.snode.SnodeAPI
+import org.session.libsession.utilities.StringSubstitutionConstants.TIME_LARGE_KEY
import org.session.libsession.utilities.TextSecurePreferences.Companion.getLocalNumber
import org.session.libsession.utilities.ThemeUtil
import org.thoughtcrime.securesms.components.emoji.EmojiImageView
@@ -46,14 +52,6 @@ import org.thoughtcrime.securesms.dependencies.DatabaseComponent.Companion.get
import org.thoughtcrime.securesms.repository.ConversationRepository
import org.thoughtcrime.securesms.util.AnimationCompleteListener
import org.thoughtcrime.securesms.util.DateUtils
-import java.util.Locale
-import javax.inject.Inject
-import kotlin.time.Duration
-import kotlin.time.Duration.Companion.days
-import kotlin.time.Duration.Companion.hours
-import kotlin.time.Duration.Companion.milliseconds
-import kotlin.time.Duration.Companion.minutes
-import kotlin.time.Duration.Companion.seconds
@AndroidEntryPoint
class ConversationReactionOverlay : FrameLayout {
@@ -529,11 +527,11 @@ class ConversationReactionOverlay : FrameLayout {
?: return emptyList()
val userPublicKey = getLocalNumber(context)!!
// Select message
- items += ActionItem(R.attr.menu_select_icon, R.string.conversation_context__menu_select, { handleActionItemClicked(Action.SELECT) }, R.string.AccessibilityId_select)
+ items += ActionItem(R.attr.menu_select_icon, R.string.select, { handleActionItemClicked(Action.SELECT) }, R.string.AccessibilityId_select)
// Reply
val canWrite = openGroup == null || openGroup.canWrite
if (canWrite && !message.isPending && !message.isFailed && !message.isOpenGroupInvitation) {
- items += ActionItem(R.attr.menu_reply_icon, R.string.conversation_context__menu_reply, { handleActionItemClicked(Action.REPLY) }, R.string.AccessibilityId_reply_message)
+ items += ActionItem(R.attr.menu_reply_icon, R.string.reply, { handleActionItemClicked(Action.REPLY) }, R.string.AccessibilityId_reply)
}
// Copy message text
if (!containsControlMessage && hasText) {
@@ -541,34 +539,42 @@ class ConversationReactionOverlay : FrameLayout {
}
// Copy Account ID
if (recipient.isGroupRecipient && !recipient.isCommunityRecipient && message.recipient.address.toString() != userPublicKey) {
- items += ActionItem(R.attr.menu_copy_icon, R.string.activity_conversation_menu_copy_account_id, { handleActionItemClicked(Action.COPY_ACCOUNT_ID) })
+ items += ActionItem(R.attr.menu_copy_icon, R.string.accountIDCopy, { handleActionItemClicked(Action.COPY_ACCOUNT_ID) })
}
// Delete message
if (userCanDeleteSelectedItems(context, message, openGroup, userPublicKey, blindedPublicKey)) {
items += ActionItem(R.attr.menu_trash_icon, R.string.delete, { handleActionItemClicked(Action.DELETE) },
- R.string.AccessibilityId_delete_message, message.subtitle, ThemeUtil.getThemedColor(context, R.attr.danger))
+ R.string.AccessibilityId_deleteMessage, message.subtitle, ThemeUtil.getThemedColor(context, R.attr.danger))
}
// Ban user
if (userCanBanSelectedUsers(context, message, openGroup, userPublicKey, blindedPublicKey)) {
- items += ActionItem(R.attr.menu_block_icon, R.string.conversation_context__menu_ban_user, { handleActionItemClicked(Action.BAN_USER) })
+ items += ActionItem(R.attr.menu_block_icon, R.string.banUser, { handleActionItemClicked(Action.BAN_USER) })
}
// Ban and delete all
if (userCanBanSelectedUsers(context, message, openGroup, userPublicKey, blindedPublicKey)) {
- items += ActionItem(R.attr.menu_trash_icon, R.string.conversation_context__menu_ban_and_delete_all, { handleActionItemClicked(Action.BAN_AND_DELETE_ALL) })
+ items += ActionItem(R.attr.menu_trash_icon, R.string.banDeleteAll, { handleActionItemClicked(Action.BAN_AND_DELETE_ALL) })
}
// Message detail
- items += ActionItem(R.attr.menu_info_icon, R.string.conversation_context__menu_message_details, { handleActionItemClicked(Action.VIEW_INFO) })
+ items += ActionItem(R.attr.menu_info_icon, R.string.messageInfo, { handleActionItemClicked(Action.VIEW_INFO) })
// Resend
if (message.isFailed) {
- items += ActionItem(R.attr.menu_reply_icon, R.string.conversation_context__menu_resend_message, { handleActionItemClicked(Action.RESEND) })
+ items += ActionItem(R.attr.menu_reply_icon, R.string.resend, { handleActionItemClicked(Action.RESEND) })
}
// Resync
if (message.isSyncFailed) {
- items += ActionItem(R.attr.menu_reply_icon, R.string.conversation_context__menu_resync_message, { handleActionItemClicked(Action.RESYNC) })
+ items += ActionItem(R.attr.menu_reply_icon, R.string.resync, { handleActionItemClicked(Action.RESYNC) })
}
- // Save media
- if (message.isMms && (message as MediaMmsMessageRecord).containsMediaSlide()) {
- items += ActionItem(R.attr.menu_save_icon, R.string.conversation_context_image__save_attachment, { handleActionItemClicked(Action.DOWNLOAD) }, R.string.AccessibilityId_save_attachment)
+ // Save media..
+ if (message.isMms) {
+ // ..but only provide the save option if the there is a media attachment which has finished downloading.
+ val mmsMessage = message as MediaMmsMessageRecord
+ if (mmsMessage.containsMediaSlide() && !mmsMessage.isMediaPending) {
+ items += ActionItem(R.attr.menu_save_icon,
+ R.string.save,
+ { handleActionItemClicked(Action.DOWNLOAD) },
+ R.string.AccessibilityId_save
+ )
+ }
}
backgroundView.visibility = VISIBLE
foregroundView.visibility = VISIBLE
@@ -704,10 +710,6 @@ class ConversationReactionOverlay : FrameLayout {
}
}
-private fun Duration.to2partString(): String? =
- toComponents { days, hours, minutes, seconds, nanoseconds -> listOf(days.days, hours.hours, minutes.minutes, seconds.seconds) }
- .filter { it.inWholeSeconds > 0L }.take(2).takeIf { it.isNotEmpty() }?.joinToString(" ")
-
private val MessageRecord.subtitle: ((Context) -> CharSequence?)?
get() = if (expiresIn <= 0) {
null
@@ -715,6 +717,10 @@ private val MessageRecord.subtitle: ((Context) -> CharSequence?)?
(expiresIn - (SnodeAPI.nowWithOffset - (expireStarted.takeIf { it > 0 } ?: timestamp)))
.coerceAtLeast(0L)
.milliseconds
- .to2partString()
- ?.let { context.getString(R.string.auto_deletes_in, it) }
+ .toShortTwoPartString()
+ .let {
+ Phrase.from(context, R.string.disappearingMessagesCountdownBigMobile)
+ .put(TIME_LARGE_KEY, it)
+ .format().toString()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/DeleteOptionsBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/DeleteOptionsBottomSheet.kt
index ca5b1cec11..58c5536248 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/DeleteOptionsBottomSheet.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/DeleteOptionsBottomSheet.kt
@@ -58,7 +58,7 @@ class DeleteOptionsBottomSheet : BottomSheetDialogFragment(), View.OnClickListen
}
if (!recipient.isGroupRecipient && !contact.isNullOrEmpty()) {
binding.deleteForEveryoneTextView.text =
- resources.getString(R.string.delete_message_for_me_and_recipient, contact)
+ resources.getString(R.string.clearMessagesForEveryone, contact)
}
binding.deleteForEveryoneTextView.isVisible = !recipient.isClosedGroupRecipient
binding.deleteForMeTextView.setOnClickListener(this)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt
index 065ae8e11d..a830543ec1 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt
@@ -100,7 +100,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
super.onCreate(savedInstanceState, ready)
- title = resources.getString(R.string.conversation_context__menu_message_details)
+ title = resources.getString(R.string.messageInfo)
viewModel.timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
@@ -313,7 +313,7 @@ fun ExpandButton(modifier: Modifier = Modifier, onClick: () -> Unit) {
) {
Icon(
painter = painterResource(id = R.drawable.ic_expand),
- contentDescription = stringResource(id = R.string.expand),
+ contentDescription = stringResource(id = R.string.AccessibilityId_expand),
modifier = Modifier.clickable { onClick() },
)
}
@@ -331,7 +331,7 @@ fun PreviewMessageDetails(
imageAttachments = listOf(
Attachment(
fileDetails = listOf(
- TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png")
+ TitledText(R.string.attachmentsFileId, "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(""),
@@ -339,7 +339,7 @@ fun PreviewMessageDetails(
),
Attachment(
fileDetails = listOf(
- TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png")
+ TitledText(R.string.attachmentsFileId, "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(""),
@@ -347,7 +347,7 @@ fun PreviewMessageDetails(
),
Attachment(
fileDetails = listOf(
- TitledText(R.string.message_details_header__file_id, "Screen Shot 2023-07-06 at 11.35.50 am.png")
+ TitledText(R.string.attachmentsFileId, "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(""),
@@ -356,14 +356,14 @@ fun PreviewMessageDetails(
),
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"),
- TitledText(R.string.message_details_header__file_size, "195.6kB"),
- TitledText(R.string.message_details_header__resolution, "342x312"),
+ TitledText(R.string.attachmentsFileId, "Screen Shot 2023-07-06 at 11.35.50 am.png"),
+ TitledText(R.string.attachmentsFileType, "image/png"),
+ TitledText(R.string.attachmentsFileSize, "195.6kB"),
+ TitledText(R.string.attachmentsResolution, "342x312"),
),
- sent = TitledText(R.string.message_details_header__sent, "6:12 AM Tue, 09/08/2022"),
- received = TitledText(R.string.message_details_header__received, "6:12 AM Tue, 09/08/2022"),
- error = TitledText(R.string.message_details_header__error, "Message failed to send"),
+ sent = TitledText(R.string.sent, "6:12 AM Tue, 09/08/2022"),
+ received = TitledText(R.string.received, "6:12 AM Tue, 09/08/2022"),
+ error = TitledText(R.string.error, "Message failed to send"),
senderInfo = TitledText("Connor", "d4f1g54sdf5g1d5f4g65ds4564df65f4g65d54"),
)
)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt
index fc54b652ae..fcaca71c6a 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt
@@ -78,9 +78,9 @@ class MessageDetailsViewModel @Inject constructor(
MessageDetailsState(
attachments = slides.map(::Attachment),
record = record,
- sent = dateSent.let(::Date).toString().let { TitledText(R.string.message_details_header__sent, it) },
- received = dateReceived.let(::Date).toString().let { TitledText(R.string.message_details_header__received, it) },
- error = lokiMessageDatabase.getErrorMessage(id)?.let { TitledText(R.string.message_details_header__error, it) },
+ sent = dateSent.let(::Date).toString().let { TitledText(R.string.sent, it) },
+ received = dateReceived.let(::Date).toString().let { TitledText(R.string.received, it) },
+ error = lokiMessageDatabase.getErrorMessage(id)?.let { TitledText(R.string.theError, it) },
senderInfo = individualRecipient.run { name?.let { TitledText(it, address.serialize()) } },
sender = individualRecipient,
thread = threadDb.getRecipientForThreadId(threadId)!!,
@@ -90,14 +90,14 @@ class MessageDetailsViewModel @Inject constructor(
private val Slide.details: List
get() = listOfNotNull(
- fileName.orNull()?.let { TitledText(R.string.message_details_header__file_id, it) },
- TitledText(R.string.message_details_header__file_type, asAttachment().contentType),
- TitledText(R.string.message_details_header__file_size, Util.getPrettyFileSize(fileSize)),
+ fileName.orNull()?.let { TitledText(R.string.attachmentsFileId, it) },
+ TitledText(R.string.attachmentsFileType, asAttachment().contentType),
+ TitledText(R.string.attachmentsFileSize, Util.getPrettyFileSize(fileSize)),
takeIf { it is ImageSlide }
?.let(Slide::asAttachment)
?.run { "${width}x$height" }
- ?.let { TitledText(R.string.message_details_header__resolution, it) },
- attachmentDb.duration(this)?.let { TitledText(R.string.message_details_header__duration, it) },
+ ?.let { TitledText(R.string.attachmentsResolution, it) },
+ attachmentDb.duration(this)?.let { TitledText(R.string.attachmentsDuration, it) },
)
private fun AttachmentDatabase.duration(slide: Slide): String? =
@@ -157,7 +157,7 @@ data class MessageDetailsState(
val sender: Recipient? = null,
val thread: Recipient? = null,
) {
- val fromTitle = GetString(R.string.message_details_header__from)
+ val fromTitle = GetString(R.string.from)
val canReply = record?.isOpenGroupInvitation != true
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ModalUrlBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ModalUrlBottomSheet.kt
index 54deea1c8d..b31c298f26 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ModalUrlBottomSheet.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ModalUrlBottomSheet.kt
@@ -15,9 +15,12 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
import network.loki.messenger.databinding.FragmentModalUrlBottomSheetBinding
-import org.thoughtcrime.securesms.util.UiModeUtilities
+import org.session.libsession.utilities.StringSubstitutionConstants.URL_KEY
+import org.session.libsignal.utilities.Log
+import org.thoughtcrime.securesms.ui.getSubbedString
class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(), View.OnClickListener {
private lateinit var binding: FragmentModalUrlBottomSheetBinding
@@ -29,7 +32,8 @@ class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- val explanation = resources.getString(R.string.dialog_open_url_explanation, url)
+ if (context == null) { return Log.w("MUBS", "Context is null") }
+ val explanation = requireContext().getSubbedString(R.string.urlOpenDescription, URL_KEY to url)
val spannable = SpannableStringBuilder(explanation)
val startIndex = explanation.indexOf(url)
spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + url.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
@@ -44,7 +48,7 @@ class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(),
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
requireContext().startActivity(intent)
} catch (e: Exception) {
- Toast.makeText(context, R.string.invalid_url, Toast.LENGTH_SHORT).show()
+ Toast.makeText(context, R.string.communityEnterUrlErrorInvalid, Toast.LENGTH_SHORT).show()
}
dismiss()
}
@@ -53,7 +57,7 @@ class ModalUrlBottomSheet(private val url: String): BottomSheetDialogFragment(),
val clip = ClipData.newPlainText("URL", url)
val manager = requireContext().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(clip)
- Toast.makeText(requireContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(requireContext(), R.string.copied, Toast.LENGTH_SHORT).show()
dismiss()
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/Util.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/Util.kt
index da8852d1d6..f2b19f539b 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/Util.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/Util.kt
@@ -17,22 +17,12 @@
package org.thoughtcrime.securesms.conversation.v2
import android.content.Context
-import android.graphics.Typeface
import android.net.Uri
-import android.text.Spannable
-import android.text.SpannableString
import android.text.TextUtils
-import android.text.style.StyleSpan
import android.view.View
import com.annimon.stream.Stream
-import com.google.android.mms.pdu_alt.CharacterSets
-import com.google.android.mms.pdu_alt.EncodedStringValue
-import org.session.libsignal.utilities.Log
-import org.thoughtcrime.securesms.components.ComposeText
-import java.io.ByteArrayOutputStream
-import java.io.IOException
-import java.io.UnsupportedEncodingException
import java.util.Collections
+import org.session.libsignal.utilities.Log
object Util {
private val TAG: String = Log.tag(Util::class.java)
@@ -92,22 +82,6 @@ object Util {
return sb.toString()
}
- fun isEmpty(value: Array?): Boolean {
- return value == null || value.size == 0
- }
-
- fun isEmpty(value: ComposeText?): Boolean {
- return value == null || value.text == null || TextUtils.isEmpty(value.textTrimmed)
- }
-
- fun isEmpty(collection: Collection<*>?): Boolean {
- return collection == null || collection.isEmpty()
- }
-
- fun isEmpty(charSequence: CharSequence?): Boolean {
- return charSequence == null || charSequence.length == 0
- }
-
fun wait(lock: Any, timeout: Long) {
try {
(lock as Object).wait(timeout)
@@ -123,8 +97,7 @@ object Util {
return results
}
- val elements =
- source.split(delimiter.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+ val elements = source.split(delimiter.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
Collections.addAll(results, *elements)
return results
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt
index dba6bf5b7b..0b61dec9d4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt
@@ -11,10 +11,12 @@ import android.widget.RelativeLayout
import android.widget.TextView
import androidx.core.view.children
import androidx.core.view.isVisible
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
import network.loki.messenger.databinding.AlbumThumbnailViewBinding
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.MediaPreviewActivity
import org.thoughtcrime.securesms.components.CornerMask
@@ -97,7 +99,10 @@ class AlbumThumbnailView : RelativeLayout {
binding.albumCellContainer.findViewById(R.id.album_cell_overflow_text)?.let { overflowText ->
// overflowText will be null if !overflowed
overflowText.isVisible = overflowed // more than max album size
- overflowText.text = context.getString(R.string.AlbumThumbnailView_plus, slides.size - MAX_ALBUM_DISPLAY_SIZE)
+ val txt = Phrase.from(context, R.string.andMore)
+ .put(COUNT_KEY, slides.size - MAX_ALBUM_DISPLAY_SIZE)
+ .format()
+ overflowText.text = txt
}
this.slideSize = slides.size
}
@@ -110,10 +115,9 @@ class AlbumThumbnailView : RelativeLayout {
// endregion
-
fun layoutRes(slideCount: Int) = when (slideCount) {
- 1 -> R.layout.album_thumbnail_1 // single
- 2 -> R.layout.album_thumbnail_2// two sidebyside
+ 1 -> R.layout.album_thumbnail_1 // single
+ 2 -> R.layout.album_thumbnail_2 // two side-by-side
else -> R.layout.album_thumbnail_3 // three stacked with additional text
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt
index 46feefb608..9113f8ed46 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt
@@ -11,9 +11,11 @@ import androidx.fragment.app.DialogFragment
import network.loki.messenger.R
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.contacts.Contact
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.createSessionDialog
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
/** Shown upon sending a message to a user that's blocked. */
class BlockedDialog(private val recipient: Recipient, private val context: Context) : DialogFragment() {
@@ -24,14 +26,14 @@ class BlockedDialog(private val recipient: Recipient, private val context: Conte
val contact = contactDB.getContactWithAccountID(accountID)
val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: accountID
- val explanation = resources.getString(R.string.dialog_blocked_explanation, name)
- val spannable = SpannableStringBuilder(explanation)
- val startIndex = explanation.indexOf(name)
+ val explanationCS = context.getSubbedCharSequence(R.string.blockUnblockName, NAME_KEY to name)
+ val spannable = SpannableStringBuilder(explanationCS)
+ val startIndex = explanationCS.indexOf(name)
spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + name.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
- title(resources.getString(R.string.dialog_blocked_title, name))
+ title(resources.getString(R.string.blockUnblock))
text(spannable)
- button(R.string.ConversationActivity_unblock) { unblock() }
+ dangerButton(R.string.blockUnblock, R.string.AccessibilityId_unblockConfirm) { unblock() }
cancelButton { dismiss() }
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt
index 1af1d669cf..d3e1de9912 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt
@@ -7,12 +7,14 @@ import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.StyleSpan
import androidx.fragment.app.DialogFragment
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
import network.loki.messenger.R
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.jobs.AttachmentDownloadJob
import org.session.libsession.messaging.jobs.JobQueue
import org.session.libsession.utilities.recipients.Recipient
+import org.session.libsession.utilities.StringSubstitutionConstants.CONVERSATION_NAME_KEY
import org.thoughtcrime.securesms.createSessionDialog
import org.thoughtcrime.securesms.database.SessionContactDatabase
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
@@ -29,15 +31,19 @@ class DownloadDialog(private val recipient: Recipient) : DialogFragment() {
val accountID = recipient.address.toString()
val contact = contactDB.getContactWithAccountID(accountID)
val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: accountID
- title(resources.getString(R.string.dialog_download_title, name))
- val explanation = resources.getString(R.string.dialog_download_explanation, name)
+ title(getString(R.string.attachmentsAutoDownloadModalTitle))
+
+ val explanation = Phrase.from(context, R.string.attachmentsAutoDownloadModalDescription)
+ .put(CONVERSATION_NAME_KEY, recipient.name)
+ .format()
val spannable = SpannableStringBuilder(explanation)
+
val startIndex = explanation.indexOf(name)
spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + name.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
text(spannable)
- button(R.string.dialog_download_button_title, R.string.AccessibilityId_download_media) { trust() }
+ button(R.string.download, R.string.AccessibilityId_download) { trust() }
cancelButton { dismiss() }
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt
index a886e89192..21405b26c5 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt
@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.conversation.v2.dialogs
+import org.thoughtcrime.securesms.createSessionDialog
import android.app.Dialog
import android.graphics.Typeface
import android.os.Bundle
@@ -8,11 +9,13 @@ import android.text.SpannableStringBuilder
import android.text.style.StyleSpan
import android.widget.Toast
import androidx.fragment.app.DialogFragment
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.utilities.OpenGroupUrlParser
+import org.session.libsession.utilities.StringSubstitutionConstants.COMMUNITY_NAME_KEY
+import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.ThreadUtils
-import org.thoughtcrime.securesms.createSessionDialog
import org.thoughtcrime.securesms.groups.OpenGroupManager
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
@@ -20,14 +23,18 @@ import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
class JoinOpenGroupDialog(private val name: String, private val url: String) : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = createSessionDialog {
- title(resources.getString(R.string.dialog_join_open_group_title, name))
- val explanation = resources.getString(R.string.dialog_join_open_group_explanation, name)
+ title(resources.getString(R.string.communityJoin))
+ val explanation = Phrase.from(context, R.string.communityJoinDescription).put(COMMUNITY_NAME_KEY, name).format()
val spannable = SpannableStringBuilder(explanation)
- val startIndex = explanation.indexOf(name)
+ var startIndex = explanation.indexOf(name)
+ if (startIndex < 0) {
+ Log.w("JoinOpenGroupDialog", "Could not find $name in explanation dialog: $explanation")
+ startIndex = 0 // Limit the startIndex to zero if not found (will be -1) to prevent a crash
+ }
spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + name.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
text(spannable)
cancelButton { dismiss() }
- button(R.string.open_group_invitation_view__join_accessibility_description) { join() }
+ button(R.string.join) { join() }
}
private fun join() {
@@ -39,7 +46,7 @@ class JoinOpenGroupDialog(private val name: String, private val url: String) : D
MessagingModuleConfiguration.shared.storage.onOpenGroupAdded(openGroup.server, openGroup.room)
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(activity)
} catch (e: Exception) {
- Toast.makeText(activity, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show()
+ Toast.makeText(activity, R.string.communityErrorDescription, Toast.LENGTH_SHORT).show()
}
}
dismiss()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt
index 996dd41f94..416a796ea6 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/LinkPreviewDialog.kt
@@ -4,18 +4,22 @@ import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import network.loki.messenger.R
+import org.session.libsession.utilities.NonTranslatableStringConstants.APP_NAME
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.createSessionDialog
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
/** Shown the first time the user inputs a URL that could generate a link preview, to
* let them know that Session offers the ability to send and receive link previews. */
class LinkPreviewDialog(private val onEnabled: () -> Unit) : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = createSessionDialog {
- title(R.string.dialog_link_preview_title)
- text(R.string.dialog_link_preview_explanation)
- button(R.string.dialog_link_preview_enable_button_title) { enable() }
- cancelButton { dismiss() }
+ title(R.string.linkPreviewsEnable)
+ val txt = context.getSubbedCharSequence(R.string.linkPreviewsFirstDescription, APP_NAME_KEY to APP_NAME)
+ text(txt)
+ button(R.string.enable) { enable() }
+ cancelButton { dismiss() }
}
private fun enable() {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt
index c8aacdeb6e..cd911b2ace 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt
@@ -79,9 +79,9 @@ class InputBar @JvmOverloads constructor(
var voiceMessageDurationMS = 0L
var voiceRecorderState = VoiceRecorderState.Idle
- private val attachmentsButton = InputBarButton(context, R.drawable.ic_plus_24).apply { contentDescription = context.getString(R.string.AccessibilityId_attachments_button)}
- val microphoneButton = InputBarButton(context, R.drawable.ic_microphone).apply { contentDescription = context.getString(R.string.AccessibilityId_microphone_button)}
- private val sendButton = InputBarButton(context, R.drawable.ic_arrow_up, true).apply { contentDescription = context.getString(R.string.AccessibilityId_send_message_button)}
+ private val attachmentsButton = InputBarButton(context, R.drawable.ic_plus_24).apply { contentDescription = context.getString(R.string.AccessibilityId_attachmentsButton)}
+ val microphoneButton = InputBarButton(context, R.drawable.ic_microphone).apply { contentDescription = context.getString(R.string.AccessibilityId_voiceMessageNew)}
+ private val sendButton = InputBarButton(context, R.drawable.ic_arrow_up, true).apply { contentDescription = context.getString(R.string.AccessibilityId_send)}
init {
// Attachments button
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt
index 24b48ecdf7..f245dcadf4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarRecordingView.kt
@@ -19,7 +19,6 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewInputBarRecordingBinding
-import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.animateSizeChange
import org.thoughtcrime.securesms.util.disableClipping
import org.thoughtcrime.securesms.util.toPx
@@ -106,8 +105,7 @@ class InputBarRecordingView : RelativeLayout {
timerJob = scope.launch {
while (isActive) {
val duration = (Date().time - startTimestamp) / 1000L
- binding.recordingViewDurationTextView.text = DateUtils.formatElapsedTime(duration)
-
+ binding.recordingViewDurationTextView.text = android.text.format.DateUtils.formatElapsedTime(duration)
delay(500)
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt
index c7862ca22e..720310fa5e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationActionModeCallback.kt
@@ -40,6 +40,8 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p
val edKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!
val blindedPublicKey = openGroup?.publicKey?.let { SodiumUtilities.blindedKeyPair(it, edKeyPair)?.publicKey?.asBytes }
?.let { AccountId(IdPrefix.BLINDED, it) }?.hexString
+
+ // Embedded function
fun userCanDeleteSelectedItems(): Boolean {
val allSentByCurrentUser = selectedItems.all { it.isOutgoing }
val allReceivedByCurrentUser = selectedItems.all { !it.isOutgoing }
@@ -47,6 +49,8 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p
if (allSentByCurrentUser) { return true }
return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey, blindedPublicKey)
}
+
+ // Embedded function
fun userCanBanSelectedUsers(): Boolean {
if (openGroup == null) { return false }
val anySentByCurrentUser = selectedItems.any { it.isOutgoing }
@@ -55,6 +59,9 @@ class ConversationActionModeCallback(private val adapter: ConversationAdapter, p
if (selectedUsers.size > 1) { return false }
return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey, blindedPublicKey)
}
+
+
+
// Delete message
menu.findItem(R.id.menu_context_delete_message).isVisible = userCanDeleteSelectedItems()
// Ban user
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt
index 8d018d6813..090bf47574 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuHelper.kt
@@ -16,10 +16,13 @@ import androidx.appcompat.widget.SearchView.OnQueryTextListener
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
+import com.squareup.phrase.Phrase
+import java.io.IOException
import network.loki.messenger.R
import org.session.libsession.messaging.sending_receiving.MessageSender
import org.session.libsession.messaging.sending_receiving.leave
import org.session.libsession.utilities.GroupUtil.doubleDecodeGroupID
+import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.utilities.guava.Optional
@@ -38,7 +41,6 @@ import org.thoughtcrime.securesms.service.WebRtcCallService
import org.thoughtcrime.securesms.showMuteDialog
import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.util.BitmapUtil
-import java.io.IOException
object ConversationMenuHelper {
@@ -50,11 +52,11 @@ object ConversationMenuHelper {
) {
// Prepare
menu.clear()
- val isOpenGroup = thread.isCommunityRecipient
+ val isCommunity = thread.isCommunityRecipient
// Base menu (options that should always be present)
inflater.inflate(R.menu.menu_conversation, menu)
// Expiring messages
- if (!isOpenGroup && (thread.hasApprovedMe() || thread.isClosedGroupRecipient || thread.isLocalNumber)) {
+ if (!isCommunity && (thread.hasApprovedMe() || thread.isClosedGroupRecipient || thread.isLocalNumber)) {
inflater.inflate(R.menu.menu_conversation_expiration, menu)
}
// One-on-one chat menu allows copying the account id
@@ -74,7 +76,7 @@ object ConversationMenuHelper {
inflater.inflate(R.menu.menu_conversation_closed_group, menu)
}
// Open group menu
- if (isOpenGroup) {
+ if (isCommunity) {
inflater.inflate(R.menu.menu_conversation_open_group, menu)
}
// Muting
@@ -162,9 +164,9 @@ object ConversationMenuHelper {
if (!TextSecurePreferences.isCallNotificationsEnabled(context)) {
context.showSessionDialog {
- title(R.string.ConversationActivity_call_title)
- text(R.string.ConversationActivity_call_prompt)
- button(R.string.activity_settings_title, R.string.AccessibilityId_settings) {
+ title(R.string.callsPermissionsRequired)
+ text(R.string.callsPermissionsRequiredDescription)
+ button(R.string.sessionSettings, R.string.AccessibilityId_sessionSettings) {
Intent(context, PrivacySettingsActivity::class.java).let(context::startActivity)
}
cancelButton()
@@ -178,7 +180,6 @@ object ConversationMenuHelper {
Intent(context, WebRtcCallActivity::class.java)
.apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK }
.let(context::startActivity)
-
}
@SuppressLint("StaticFieldLeak")
@@ -215,7 +216,7 @@ object ConversationMenuHelper {
.setIntent(ShortcutLauncherActivity.createIntent(context, thread.address))
.build()
if (ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null)) {
- Toast.makeText(context, context.resources.getString(R.string.ConversationActivity_added_to_home_screen), Toast.LENGTH_LONG).show()
+ Toast.makeText(context, context.resources.getString(R.string.conversationsAddedToHome), Toast.LENGTH_LONG).show()
}
}
}.execute()
@@ -272,15 +273,24 @@ object ConversationMenuHelper {
val accountID = TextSecurePreferences.getLocalNumber(context)
val isCurrentUserAdmin = admins.any { it.toString() == accountID }
val message = if (isCurrentUserAdmin) {
- "Because you are the creator of this group it will be deleted for everyone. This cannot be undone."
+ Phrase.from(context, R.string.groupLeaveDescriptionAdmin)
+ .put(GROUP_NAME_KEY, group.title)
+ .format().toString()
} else {
- context.resources.getString(R.string.ConversationActivity_are_you_sure_you_want_to_leave_this_group)
+ Phrase.from(context, R.string.groupLeaveDescription)
+ .put(GROUP_NAME_KEY, group.title)
+ .format().toString()
}
- fun onLeaveFailed() = Toast.makeText(context, R.string.ConversationActivity_error_leaving_group, Toast.LENGTH_LONG).show()
+ fun onLeaveFailed() {
+ val txt = Phrase.from(context, R.string.groupLeaveErrorFailed)
+ .put(GROUP_NAME_KEY, group.title)
+ .format().toString()
+ Toast.makeText(context, txt, Toast.LENGTH_LONG).show()
+ }
context.showSessionDialog {
- title(R.string.ConversationActivity_leave_group)
+ title(R.string.groupLeave)
text(message)
button(R.string.yes) {
try {
@@ -309,7 +319,7 @@ object ConversationMenuHelper {
}
private fun mute(context: Context, thread: Recipient) {
- showMuteDialog(ContextThemeWrapper(context, context.theme)) { until ->
+ showMuteDialog(ContextThemeWrapper(context, context.theme)) { until: Long ->
DatabaseComponent.get(context).recipientDatabase().setMuted(thread, until)
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt
index 1177b4afc9..ab8498acf4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt
@@ -8,17 +8,19 @@ import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
+import javax.inject.Inject
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewControlMessageBinding
import network.loki.messenger.libsession_util.util.ExpiryMode
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.ExpirationConfiguration
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.thoughtcrime.securesms.conversation.disappearingmessages.DisappearingMessages
import org.thoughtcrime.securesms.conversation.disappearingmessages.expiryMode
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
-import javax.inject.Inject
@AndroidEntryPoint
class ControlMessageView : LinearLayout {
@@ -75,8 +77,10 @@ class ControlMessageView : LinearLayout {
}
}
message.isMessageRequestResponse -> {
- binding.textView.text = context.getString(R.string.message_requests_accepted)
- binding.root.contentDescription=context.getString(R.string.AccessibilityId_message_request_config_message)
+ binding.textView.text = context.getString(R.string.messageRequestsAccepted)
+ binding.root.contentDescription = Phrase.from(context, R.string.messageRequestYouHaveAccepted)
+ .put(NAME_KEY, message.individualRecipient.name)
+ .format()
}
message.isCallLog -> {
val drawable = when {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DeletedMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DeletedMessageView.kt
index 9c725ee048..5b64df059e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DeletedMessageView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/DeletedMessageView.kt
@@ -21,7 +21,7 @@ class DeletedMessageView : LinearLayout {
// region Updating
fun bind(message: MessageRecord, @ColorInt textColor: Int) {
assert(message.isDeleted)
- binding.deleteTitleTextView.text = context.getString(R.string.deleted_message)
+ binding.deleteTitleTextView.text = context.resources.getQuantityString(R.plurals.deleteMessageDeleted, 1, 1)
binding.deleteTitleTextView.setTextColor(textColor)
binding.deletedMessageViewIconImageView.imageTintList = ColorStateList.valueOf(textColor)
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt
index 9f4ce88879..27714fbc05 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt
@@ -12,8 +12,10 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.view.setPadding
import com.google.android.flexbox.JustifyContent
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewEmojiReactionsBinding
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
import org.session.libsession.utilities.TextSecurePreferences.Companion.getLocalNumber
import org.session.libsession.utilities.ThemeUtil
import org.thoughtcrime.securesms.components.emoji.EmojiImageView
@@ -199,7 +201,7 @@ class EmojiReactionsView : ConstraintLayout, OnTouchListener {
} else {
emojiView.visibility = GONE
spacer.visibility = GONE
- countView.text = context.getString(R.string.ReactionsConversationView_plus, reaction.count)
+ countView.text = Phrase.from(context, R.string.andMore).put(COUNT_KEY, reaction.count.toInt()).format()
}
if (reaction.userWasSender && !isCompact) {
root.background = ContextCompat.getDrawable(context, R.drawable.reaction_pill_background_selected)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt
index 8cf80dc090..d064d02872 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt
@@ -6,16 +6,16 @@ import android.graphics.Rect
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.LinearLayout
-import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
+import com.bumptech.glide.RequestManager
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewLinkPreviewBinding
import org.session.libsession.utilities.getColorFromAttr
+import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.components.CornerMask
-import org.thoughtcrime.securesms.conversation.v2.ModalUrlBottomSheet
+import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
-import com.bumptech.glide.RequestManager
import org.thoughtcrime.securesms.mms.ImageSlide
class LinkPreviewView : LinearLayout {
@@ -84,10 +84,11 @@ class LinkPreviewView : LinearLayout {
}
}
- fun openURL() {
- val url = this.url ?: return
- val activity = context as AppCompatActivity
- ModalUrlBottomSheet(url).show(activity.supportFragmentManager, "Open URL Dialog")
+ // Method to show the open or copy URL dialog
+ private fun openURL() {
+ val url = this.url ?: return Log.w("LinkPreviewView", "Cannot open a null URL")
+ val activity = context as? ConversationActivityV2
+ activity?.showOpenUrlDialog(url)
}
// endregion
}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt
index 40cf4bc1e0..6a5f852409 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt
@@ -75,13 +75,13 @@ class QuoteView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
val quoteIsLocalUser = localNumber != null && authorPublicKey == localNumber
val authorDisplayName =
- if (quoteIsLocalUser) context.getString(R.string.QuoteView_you)
+ if (quoteIsLocalUser) context.getString(R.string.you)
else author?.displayName(Contact.contextForRecipient(thread)) ?: "${authorPublicKey.take(4)}...${authorPublicKey.takeLast(4)}"
binding.quoteViewAuthorTextView.text = authorDisplayName
binding.quoteViewAuthorTextView.setTextColor(getTextColor(isOutgoingMessage))
// Body
binding.quoteViewBodyTextView.text = if (isOpenGroupInvitation)
- resources.getString(R.string.open_group_invitation_view__open_group_invitation)
+ resources.getString(R.string.communityInvitation)
else MentionUtilities.highlightMentions(
text = (body ?: "").toSpannable(),
isOutgoingMessage = isOutgoingMessage,
@@ -106,7 +106,7 @@ class QuoteView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
attachments.audioSlide != null -> {
binding.quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_microphone)
binding.quoteViewAttachmentPreviewImageView.isVisible = true
- binding.quoteViewBodyTextView.text = resources.getString(R.string.Slide_audio)
+ binding.quoteViewBodyTextView.text = resources.getString(R.string.audio)
}
attachments.documentSlide != null -> {
binding.quoteViewAttachmentPreviewImageView.setImageResource(R.drawable.ic_document_large_light)
@@ -120,7 +120,7 @@ class QuoteView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
.root.setRoundedCorners(toPx(4, resources))
binding.quoteViewAttachmentThumbnailImageView.root.setImageResource(glide, slide, false)
binding.quoteViewAttachmentThumbnailImageView.root.isVisible = true
- binding.quoteViewBodyTextView.text = if (MediaUtil.isVideo(slide.asAttachment())) resources.getString(R.string.Slide_video) else resources.getString(R.string.Slide_image)
+ binding.quoteViewBodyTextView.text = if (MediaUtil.isVideo(slide.asAttachment())) resources.getString(R.string.video) else resources.getString(R.string.image)
}
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/UntrustedAttachmentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/UntrustedAttachmentView.kt
index 47034cf8ed..7d1dc625f6 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/UntrustedAttachmentView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/UntrustedAttachmentView.kt
@@ -5,12 +5,13 @@ import android.util.AttributeSet
import android.widget.LinearLayout
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewUntrustedAttachmentBinding
+import org.session.libsession.utilities.StringSubstitutionConstants.FILE_TYPE_KEY
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.conversation.v2.dialogs.DownloadDialog
import org.thoughtcrime.securesms.util.ActivityDispatcher
-import java.util.Locale
class UntrustedAttachmentView: LinearLayout {
private val binding: ViewUntrustedAttachmentBinding by lazy { ViewUntrustedAttachmentBinding.bind(this) }
@@ -30,13 +31,17 @@ class UntrustedAttachmentView: LinearLayout {
// region Updating
fun bind(attachmentType: AttachmentType, @ColorInt textColor: Int) {
val (iconRes, stringRes) = when (attachmentType) {
- AttachmentType.AUDIO -> R.drawable.ic_microphone to R.string.Slide_audio
- AttachmentType.DOCUMENT -> R.drawable.ic_document_large_light to R.string.document
+ AttachmentType.AUDIO -> R.drawable.ic_microphone to R.string.audio
+ AttachmentType.DOCUMENT -> R.drawable.ic_document_large_light to R.string.files
AttachmentType.MEDIA -> R.drawable.ic_image_white_24dp to R.string.media
}
val iconDrawable = ContextCompat.getDrawable(context,iconRes)!!
iconDrawable.mutate().setTint(textColor)
- val text = context.getString(R.string.UntrustedAttachmentView_download_attachment, context.getString(stringRes).toLowerCase(Locale.ROOT))
+
+ val text = Phrase.from(context, R.string.attachmentsTapToDownload)
+ .put(FILE_TYPE_KEY, context.getString(stringRes))
+ .format()
+ binding.untrustedAttachmentTitle.text = text
binding.untrustedAttachmentIcon.setImageDrawable(iconDrawable)
binding.untrustedAttachmentTitle.text = text
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt
index dcce528234..d62cc532c4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt
@@ -12,34 +12,29 @@ import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.annotation.ColorInt
-import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.graphics.ColorUtils
import androidx.core.text.getSpans
import androidx.core.text.toSpannable
import androidx.core.view.children
import androidx.core.view.isVisible
+import com.bumptech.glide.Glide
+import com.bumptech.glide.RequestManager
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewVisibleMessageContentBinding
-import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
-import org.session.libsession.messaging.MessagingModuleConfiguration
-import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
import org.session.libsession.utilities.ThemeUtil
import org.session.libsession.utilities.getColorFromAttr
import org.session.libsession.utilities.modifyLayoutParams
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
-import org.thoughtcrime.securesms.conversation.v2.ModalUrlBottomSheet
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities
import org.thoughtcrime.securesms.conversation.v2.utilities.ModalURLSpan
import org.thoughtcrime.securesms.conversation.v2.utilities.TextUtilities.getIntersectedModalSpans
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
import org.thoughtcrime.securesms.database.model.SmsMessageRecord
-import com.bumptech.glide.Glide
-import com.bumptech.glide.RequestManager
import org.thoughtcrime.securesms.util.GlowViewUtilities
import org.thoughtcrime.securesms.util.SearchUtil
import org.thoughtcrime.securesms.util.getAccentColor
@@ -117,7 +112,7 @@ class VisibleMessageContentView : ConstraintLayout {
binding.quoteView.root.isVisible = true
val quote = message.quote!!
val quoteText = if (quote.isOriginalMissing) {
- context.getString(R.string.QuoteView_original_missing)
+ context.getString(R.string.messageErrorOriginal)
} else {
quote.text
}
@@ -292,8 +287,8 @@ class VisibleMessageContentView : ConstraintLayout {
body.getSpans(0, body.length).toList().forEach { urlSpan ->
val updatedUrl = urlSpan.url.let { it.toHttpUrlOrNull().toString() }
val replacementSpan = ModalURLSpan(updatedUrl) { url ->
- val activity = context as AppCompatActivity
- ModalUrlBottomSheet(url).show(activity.supportFragmentManager, "Open URL Dialog")
+ val activity = context as? ConversationActivityV2
+ activity?.showOpenUrlDialog(url)
}
val start = body.getSpanStart(urlSpan)
val end = body.getSpanEnd(urlSpan)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt
index 9f7f620ab5..205f28a078 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt
@@ -27,6 +27,13 @@ import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.core.view.marginBottom
import dagger.hilt.android.AndroidEntryPoint
+import java.util.Date
+import java.util.Locale
+import javax.inject.Inject
+import kotlin.math.abs
+import kotlin.math.min
+import kotlin.math.roundToInt
+import kotlin.math.sqrt
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewEmojiReactionsBinding
import network.loki.messenger.databinding.ViewVisibleMessageBinding
@@ -58,13 +65,6 @@ import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.disableClipping
import org.thoughtcrime.securesms.util.toDp
import org.thoughtcrime.securesms.util.toPx
-import java.util.Date
-import java.util.Locale
-import javax.inject.Inject
-import kotlin.math.abs
-import kotlin.math.min
-import kotlin.math.roundToInt
-import kotlin.math.sqrt
private const val TAG = "VisibleMessageView"
@@ -269,8 +269,7 @@ class VisibleMessageView : FrameLayout {
// Method to display or hide the status of a message.
// Note: Although most commonly used to display the delivery status of a message, we also use the
// message status area to display the disappearing messages state - so in this latter case we'll
- // be displaying the "Sent" and the animating clock icon for outgoing messages or "Read" and the
- // animated clock icon for incoming messages.
+ // be displaying either "Sent" or "Read" and the animating clock icon.
private fun showStatusMessage(message: MessageRecord) {
// We'll start by hiding everything and then only make visible what we need
binding.messageStatusTextView.isVisible = false
@@ -384,37 +383,47 @@ class VisibleMessageView : FrameLayout {
message.isFailed ->
MessageStatusInfo(R.drawable.ic_delivery_status_failed,
getThemedColor(context, R.attr.danger),
- R.string.delivery_status_failed
+ R.string.messageStatusFailedToSend
)
message.isSyncFailed ->
MessageStatusInfo(
R.drawable.ic_delivery_status_failed,
context.getColor(R.color.accent_orange),
- R.string.delivery_status_sync_failed
+ R.string.messageStatusFailedToSync
)
message.isPending ->
- MessageStatusInfo(
- R.drawable.ic_delivery_status_sending,
- context.getColorFromAttr(R.attr.message_status_color),
- R.string.delivery_status_sending
- )
+ // Non-mms messages display 'Sending'..
+ if (!message.isMms) {
+ MessageStatusInfo(
+ R.drawable.ic_delivery_status_sending,
+ context.getColorFromAttr(R.attr.message_status_color),
+ R.string.sending
+ )
+ } else {
+ // ..and Mms messages display 'Uploading'.
+ MessageStatusInfo(
+ R.drawable.ic_delivery_status_sending,
+ context.getColorFromAttr(R.attr.message_status_color),
+ R.string.messageStatusUploading
+ )
+ }
message.isSyncing || message.isResyncing ->
MessageStatusInfo(
R.drawable.ic_delivery_status_sending,
context.getColorFromAttr(R.attr.message_status_color),
- R.string.delivery_status_sending // We COULD tell the user that we're `syncing` (R.string.delivery_status_syncing) but it will likely make more sense to them if we say "Sending"
+ R.string.messageStatusSyncing
)
message.isRead || message.isIncoming ->
MessageStatusInfo(
R.drawable.ic_delivery_status_read,
context.getColorFromAttr(R.attr.message_status_color),
- R.string.delivery_status_read
+ R.string.read
)
message.isSent ->
MessageStatusInfo(
R.drawable.ic_delivery_status_sent,
context.getColorFromAttr(R.attr.message_status_color),
- R.string.delivery_status_sent
+ R.string.disappearingMessagesSent
)
else -> {
// The message isn't one we care about for message statuses we display to the user (i.e.,
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchBottomBar.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchBottomBar.kt
index afed74b1cc..a379a23445 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchBottomBar.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchBottomBar.kt
@@ -5,9 +5,11 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewSearchBottomBarBinding
-
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.TOTAL_COUNT_KEY
class SearchBottomBar : LinearLayout {
private lateinit var binding: ViewSearchBottomBarBinding
@@ -35,7 +37,7 @@ class SearchBottomBar : LinearLayout {
}
}
if (count > 0) {
- searchPosition.text = resources.getString(R.string.ConversationActivity_search_position, position + 1, count)
+ searchPosition.text = resources.getQuantityString(R.plurals.searchMatches, count, position + 1, count)
} else {
searchPosition.text = ""
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchViewModel.kt
index 48bb731c68..82156b32e7 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchViewModel.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/search/SearchViewModel.kt
@@ -94,6 +94,8 @@ class SearchViewModel @Inject constructor(
}
}
+ public fun getActiveQuery() = activeQuery
+
class SearchResult(private val results: CursorList, val position: Int) : Closeable {
fun getResults(): List {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java
index ee98f623f2..221e1b76c2 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java
@@ -16,6 +16,9 @@
*/
package org.thoughtcrime.securesms.conversation.v2.utilities;
+import static com.google.android.gms.common.util.CollectionUtils.listOf;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
+
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
@@ -30,10 +33,14 @@ import android.provider.OpenableColumns;
import android.text.TextUtils;
import android.util.Pair;
import android.widget.Toast;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-
+import com.squareup.phrase.Phrase;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import network.loki.messenger.R;
import org.session.libsession.utilities.recipients.Recipient;
import org.session.libsignal.utilities.ListenableFuture;
import org.session.libsignal.utilities.Log;
@@ -55,17 +62,13 @@ import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.util.MediaUtil;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import network.loki.messenger.R;
-
public class AttachmentManager {
private final static String TAG = AttachmentManager.class.getSimpleName();
+ // Max attachment size is 10MB, above which we display a warning toast rather than sending the msg
+ private final long MAX_ATTACHMENTS_FILE_SIZE_BYTES = 10 * 1024 * 1024;
+
private final @NonNull Context context;
private final @NonNull AttachmentListener attachmentListener;
@@ -252,13 +255,31 @@ public class AttachmentManager {
} else {
builder = builder.request(Manifest.permission.READ_EXTERNAL_STORAGE);
}
- builder.withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio))
- .withRationaleDialog(activity.getString(R.string.ConversationActivity_to_send_photos_and_video_allow_signal_access_to_storage), R.drawable.ic_baseline_photo_library_24)
+
+ Context c = activity.getApplicationContext();
+
+ String needStoragePermissionTxt = Phrase.from(c, R.string.permissionsStorageSend).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString();
+
+ String storagePermissionDeniedTxt = Phrase.from(c, R.string.permissionsStorageSaveDenied)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+
+ builder.withPermanentDenialDialog(storagePermissionDeniedTxt)
+ .withRationaleDialog(needStoragePermissionTxt, R.drawable.ic_baseline_photo_library_24)
.onAllGranted(() -> selectMediaType(activity, "*/*", null, requestCode)) // Note: We can use startActivityForResult w/ the ACTION_OPEN_DOCUMENT or ACTION_OPEN_DOCUMENT_TREE intent if we need to modernise this.
.execute();
}
public static void selectGallery(Activity activity, int requestCode, @NonNull Recipient recipient, @NonNull String body) {
+
+ Context c = activity.getApplicationContext();
+ String needStoragePermissionTxt = Phrase.from(c, R.string.permissionsStorageSend)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+ String cameraPermissionDeniedTxt = Phrase.from(c, R.string.cameraGrantAccessDenied)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+
Permissions.PermissionsBuilder builder = Permissions.with(activity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
builder = builder.request(Manifest.permission.READ_MEDIA_VIDEO)
@@ -266,8 +287,8 @@ public class AttachmentManager {
} else {
builder = builder.request(Manifest.permission.READ_EXTERNAL_STORAGE);
}
- builder.withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_external_storage_permission_in_order_to_attach_photos_videos_or_audio))
- .withRationaleDialog(activity.getString(R.string.ConversationActivity_to_send_photos_and_video_allow_signal_access_to_storage), R.drawable.ic_baseline_photo_library_24)
+ builder.withPermanentDenialDialog(cameraPermissionDeniedTxt)
+ .withRationaleDialog(needStoragePermissionTxt, R.drawable.ic_baseline_photo_library_24)
.onAllGranted(() -> activity.startActivityForResult(MediaSendActivity.buildGalleryIntent(activity, recipient, body), requestCode))
.execute();
}
@@ -291,10 +312,19 @@ public class AttachmentManager {
}
public void capturePhoto(Activity activity, int requestCode, Recipient recipient) {
+
+ String cameraPermissionDeniedTxt = Phrase.from(context, R.string.cameraGrantAccessDenied)
+ .put(APP_NAME_KEY, context.getString(R.string.app_name))
+ .format().toString();
+
+ String requireCameraPermissionTxt = Phrase.from(context, R.string.cameraGrantAccessDescription)
+ .put(APP_NAME_KEY, context.getString(R.string.app_name))
+ .format().toString();
+
Permissions.with(activity)
.request(Manifest.permission.CAMERA)
- .withPermanentDenialDialog(activity.getString(R.string.AttachmentManager_signal_requires_the_camera_permission_in_order_to_take_photos_but_it_has_been_permanently_denied))
- .withRationaleDialog(activity.getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera),R.drawable.ic_baseline_photo_camera_24)
+ .withPermanentDenialDialog(cameraPermissionDeniedTxt)
+ .withRationaleDialog(requireCameraPermissionTxt, R.drawable.ic_baseline_photo_camera_24)
.onAllGranted(() -> {
Intent captureIntent = MediaSendActivity.buildCameraIntent(activity, recipient);
if (captureIntent.resolveActivity(activity.getPackageManager()) != null) {
@@ -326,7 +356,7 @@ public class AttachmentManager {
activity.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException anfe) {
Log.w(TAG, "couldn't complete ACTION_GET_CONTENT intent, no activity found. falling back.");
- Toast.makeText(activity, R.string.AttachmentManager_cant_open_media_selection, Toast.LENGTH_LONG).show();
+ Toast.makeText(activity, R.string.attachmentsErrorNoApp, Toast.LENGTH_LONG).show();
}
}
@@ -334,9 +364,21 @@ public class AttachmentManager {
final @Nullable Slide slide,
final @NonNull MediaConstraints constraints)
{
- return slide == null ||
- constraints.isSatisfied(context, slide.asAttachment()) ||
- constraints.canResize(slide.asAttachment());
+ // Null attachment? Not satisfied.
+ if (slide == null) return false;
+
+ // Attachments are excessively large? Not satisfied.
+ // Note: This file size test must come BEFORE the `constraints.isSatisfied` check below because
+ // it is a more specific type of check.
+ if (slide.asAttachment().getSize() > MAX_ATTACHMENTS_FILE_SIZE_BYTES) {
+ Toast.makeText(context, R.string.attachmentsErrorSize, Toast.LENGTH_SHORT).show();
+ return false;
+ }
+
+ // Otherwise we return whether our constraints are satisfied OR if we can resize the attachment
+ // (in the case of one or more images) - either one will be acceptable, but if both aren't then
+ // we fail the constraint test.
+ return constraints.isSatisfied(context, slide.asAttachment()) || constraints.canResize(slide.asAttachment());
}
public interface AttachmentListener {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt
index 4d3e48bc5b..39301cd69f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt
@@ -54,13 +54,14 @@ object MentionUtilities {
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
val openGroup by lazy { DatabaseComponent.get(context).storage().getOpenGroup(threadID) }
- // format the mention text
+ // Format the mention text
if (matcher.find(startIndex)) {
while (true) {
val publicKey = text.subSequence(matcher.start() + 1, matcher.end()).toString() // +1 to get rid of the @
+
val isYou = isYou(publicKey, userPublicKey, openGroup)
val userDisplayName: String? = if (isYou) {
- context.getString(R.string.MessageRecord_you)
+ context.getString(R.string.you)
} else {
val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithAccountID(publicKey)
@Suppress("NAME_SHADOWING") val context = if (openGroup != null) Contact.ContactContext.OPEN_GROUP else Contact.ContactContext.REGULAR
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/NotificationUtils.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/NotificationUtils.kt
index c0ce83f631..f012f925ed 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/NotificationUtils.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/NotificationUtils.kt
@@ -8,7 +8,7 @@ import org.thoughtcrime.securesms.showSessionDialog
object NotificationUtils {
fun showNotifyDialog(context: Context, thread: Recipient, notifyTypeHandler: (Int)->Unit) {
context.showSessionDialog {
- title(R.string.RecipientPreferenceActivity_notification_settings)
+ title(R.string.sessionNotifications)
singleChoiceItems(
context.resources.getStringArray(R.array.notify_types),
thread.notifyType
diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt
index 7a47b92756..23d81e2513 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt
@@ -1,9 +1,13 @@
package org.thoughtcrime.securesms.conversation.v2.utilities
import android.graphics.Rect
+import android.graphics.Typeface
import android.text.Layout
+import android.text.SpannableString
+import android.text.Spanned
import android.text.StaticLayout
import android.text.TextPaint
+import android.text.style.StyleSpan
import android.view.MotionEvent
import android.widget.TextView
import androidx.core.text.getSpans
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/DraftDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/DraftDatabase.java
index 822e40129e..be083256db 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/DraftDatabase.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/DraftDatabase.java
@@ -3,14 +3,8 @@ package org.thoughtcrime.securesms.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
-import android.net.Uri;
-import androidx.annotation.Nullable;
-
import net.zetetic.database.sqlcipher.SQLiteDatabase;
-
-import network.loki.messenger.R;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
-
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -24,10 +18,10 @@ public class DraftDatabase extends Database {
public static final String DRAFT_VALUE = "value";
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY, " +
- THREAD_ID + " INTEGER, " + DRAFT_TYPE + " TEXT, " + DRAFT_VALUE + " TEXT);";
+ THREAD_ID + " INTEGER, " + DRAFT_TYPE + " TEXT, " + DRAFT_VALUE + " TEXT);";
public static final String[] CREATE_INDEXS = {
- "CREATE INDEX IF NOT EXISTS draft_thread_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
+ "CREATE INDEX IF NOT EXISTS draft_thread_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
};
public DraftDatabase(Context context, SQLCipherOpenHelper databaseHelper) {
@@ -59,8 +53,8 @@ public class DraftDatabase extends Database {
for (long threadId : threadIds) {
where.append(" OR ")
- .append(THREAD_ID)
- .append(" = ?");
+ .append(THREAD_ID)
+ .append(" = ?");
arguments.add(String.valueOf(threadId));
}
@@ -95,12 +89,10 @@ public class DraftDatabase extends Database {
}
}
+ // Class to save drafts of text (only) messages if the user is in the middle of writing a message
+ // and then the app loses focus or is closed.
public static class Draft {
- public static final String TEXT = "text";
- public static final String IMAGE = "image";
- public static final String VIDEO = "video";
- public static final String AUDIO = "audio";
- public static final String QUOTE = "quote";
+ public static final String TEXT = "text";
private final String type;
private final String value;
@@ -117,48 +109,10 @@ public class DraftDatabase extends Database {
public String getValue() {
return value;
}
-
- String getSnippet(Context context) {
- switch (type) {
- case TEXT: return value;
- case IMAGE: return context.getString(R.string.DraftDatabase_Draft_image_snippet);
- case VIDEO: return context.getString(R.string.DraftDatabase_Draft_video_snippet);
- case AUDIO: return context.getString(R.string.DraftDatabase_Draft_audio_snippet);
- case QUOTE: return context.getString(R.string.DraftDatabase_Draft_quote_snippet);
- default: return null;
- }
- }
}
public static class Drafts extends LinkedList {
- private Draft getDraftOfType(String type) {
- for (Draft draft : this) {
- if (type.equals(draft.getType())) {
- return draft;
- }
- }
- return null;
- }
-
- public String getSnippet(Context context) {
- Draft textDraft = getDraftOfType(Draft.TEXT);
- if (textDraft != null) {
- return textDraft.getSnippet(context);
- } else if (size() > 0) {
- return get(0).getSnippet(context);
- } else {
- return "";
- }
- }
-
- public @Nullable Uri getUriSnippet() {
- Draft imageDraft = getDraftOfType(Draft.IMAGE);
-
- if (imageDraft != null && imageDraft.getValue() != null) {
- return Uri.parse(imageDraft.getValue());
- }
-
- return null;
- }
+ // We don't do anything with drafts of a given type anymore (image, audio etc.) - we store TEXT
+ // drafts, and any files or audio get sent to the recipient when added as a message.
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
index 08aad8b6df..a39598c55b 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
@@ -633,7 +633,11 @@ open class Storage(
// Notify the user
val threadID = getOrCreateThreadIdFor(Address.fromSerialized(groupId))
threadDb.setDate(threadID, formationTimestamp)
- insertOutgoingInfoMessage(context, groupId, SignalServiceGroup.Type.CREATION, title, members.map { it.serialize() }, admins.map { it.serialize() }, threadID, formationTimestamp)
+
+ // Note: Commenting out this line prevents the timestamp of room creation being added to a new closed group,
+ // which in turn allows us to show the `groupNoMessages` control message text.
+ //insertOutgoingInfoMessage(context, groupId, SignalServiceGroup.Type.CREATION, title, members.map { it.serialize() }, admins.map { it.serialize() }, threadID, formationTimestamp)
+
// Don't create config group here, it's from a config update
// Start polling
ClosedGroupPollerV2.shared.startPolling(group.accountId)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java
index f5c6da5fb9..f48686aded 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java
@@ -808,8 +808,8 @@ public class ThreadDatabase extends Database {
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
if (messageRecord.isMms()) {
MmsMessageRecord record = (MmsMessageRecord) messageRecord;
- if (record.getSharedContacts().size() > 0) {
- Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
+ if (!record.getSharedContacts().isEmpty()) {
+ Contact contact = ((MmsMessageRecord)messageRecord).getSharedContacts().get(0);
return ContactUtil.getStringSummary(context, contact).toString();
}
String attachmentString = record.getSlideDeck().getBody();
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java
index 9ee3a6957c..b6ebd6db84 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java
@@ -1,18 +1,20 @@
package org.thoughtcrime.securesms.database.helpers;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
+
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.database.Cursor;
-
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
-
+import com.squareup.phrase.Phrase;
+import java.io.File;
import net.zetetic.database.sqlcipher.SQLiteConnection;
import net.zetetic.database.sqlcipher.SQLiteDatabase;
import net.zetetic.database.sqlcipher.SQLiteDatabaseHook;
import net.zetetic.database.sqlcipher.SQLiteOpenHelper;
-
+import network.loki.messenger.R;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsignal.utilities.Log;
import org.thoughtcrime.securesms.crypto.DatabaseSecret;
@@ -39,13 +41,8 @@ import org.thoughtcrime.securesms.database.SessionContactDatabase;
import org.thoughtcrime.securesms.database.SessionJobDatabase;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase;
-import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities;
-import java.io.File;
-
-import network.loki.messenger.R;
-
public class SQLCipherOpenHelper extends SQLiteOpenHelper {
@SuppressWarnings("unused")
@@ -250,18 +247,22 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
// Notify the user of the issue so they know they can downgrade until the issue is fixed
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
- String channelId = context.getString(R.string.NotificationChannel_failures);
+ String channelId = context.getString(R.string.failures);
NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH);
channel.enableVibration(true);
notificationManager.createNotificationChannel(channel);
+ CharSequence errorTxt = Phrase.from(context, R.string.databaseErrorGeneric)
+ .put(APP_NAME_KEY, R.string.app_name)
+ .format();
+
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setColor(context.getResources().getColor(R.color.textsecure_primary))
.setCategory(NotificationCompat.CATEGORY_ERROR)
- .setContentTitle(context.getString(R.string.ErrorNotifier_migration))
- .setContentText(context.getString(R.string.ErrorNotifier_migration_downgrade))
+ .setContentTitle(context.getString(R.string.errorDatabase))
+ .setContentText(errorTxt)
.setAutoCancel(true);
notificationManager.notify(5874, builder.build());
diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/loaders/BucketedThreadMediaLoader.java b/app/src/main/java/org/thoughtcrime/securesms/database/loaders/BucketedThreadMediaLoader.java
index 05c13cc55d..40b8c36dd2 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/database/loaders/BucketedThreadMediaLoader.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/database/loaders/BucketedThreadMediaLoader.java
@@ -14,6 +14,8 @@ import org.session.libsession.utilities.Address;
import org.session.libsession.utilities.recipients.Recipient;
import org.thoughtcrime.securesms.database.MediaDatabase;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
+import org.thoughtcrime.securesms.util.DateUtils;
+import org.thoughtcrime.securesms.util.RelativeDay;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -88,16 +90,18 @@ public class BucketedThreadMediaLoader extends AsyncTaskLoader= dateSent) {
+ return context.getString(R.string.disappearingMessagesSent);
+ }
+ return context.getString(R.string.read);
+ }
- public int getUnreadMentionCount() {
- return unreadMentionCount;
- }
+ @Override
+ public SpannableString getDisplayBody(@NonNull Context context) {
+ if (isGroupUpdateMessage()) {
+ return emphasisAdded(context.getString(R.string.groupUpdated));
+ } else if (isOpenGroupInvitation()) {
+ return emphasisAdded(context.getString(R.string.communityInvitation));
+ } else if (MmsSmsColumns.Types.isLegacyType(type)) {
+ String txt = Phrase.from(context, R.string.messageErrorOld)
+ .put(APP_NAME_KEY, context.getString(R.string.app_name))
+ .format().toString();
+ return emphasisAdded(txt);
+ } else if (MmsSmsColumns.Types.isDraftMessageType(type)) {
+ String draftText = context.getString(R.string.draft);
+ return emphasisAdded(draftText + " " + getBody(), 0, draftText.length());
+ } else if (SmsDatabase.Types.isOutgoingCall(type)) {
+ String txt = Phrase.from(context, R.string.callsYouCalled)
+ .put(NAME_KEY, getName())
+ .format().toString();
+ return emphasisAdded(txt);
+ } else if (SmsDatabase.Types.isIncomingCall(type)) {
+ String txt = Phrase.from(context, R.string.callsCalledYou)
+ .put(NAME_KEY, getName())
+ .format().toString();
+ return emphasisAdded(txt);
+ } else if (SmsDatabase.Types.isMissedCall(type)) {
+ String txt = Phrase.from(context, R.string.callsMissedCallFrom)
+ .put(NAME_KEY, getName())
+ .format().toString();
+ return emphasisAdded(txt);
+ } else if (SmsDatabase.Types.isExpirationTimerUpdate(type)) {
+ int seconds = (int) (getExpiresIn() / 1000);
+ if (seconds <= 0) {
+ String txt = Phrase.from(context, R.string.disappearingMessagesTurnedOff)
+ .put(NAME_KEY, getName())
+ .format().toString();
+ return emphasisAdded(txt);
+ }
- public long getDate() {
- return getDateReceived();
- }
+ // Implied that disappearing messages is enabled..
+ String time = ExpirationUtil.getExpirationDisplayValue(context, seconds);
+ String disappearAfterWhat = getDisappearingMsgExpiryTypeString(context); // Disappear after send or read?
+ String txt = Phrase.from(context, R.string.disappearingMessagesSet)
+ .put(NAME_KEY, getName())
+ .put(TIME_KEY, time)
+ .put(DISAPPEARING_MESSAGES_TYPE_KEY, disappearAfterWhat)
+ .format().toString();
+ return emphasisAdded(txt);
- public boolean isArchived() {
- return archived;
- }
+ } else if (MmsSmsColumns.Types.isMediaSavedExtraction(type)) {
+ String txt = Phrase.from(context, R.string.attachmentsMediaSaved)
+ .put(NAME_KEY, getName())
+ .format().toString();
+ return emphasisAdded(txt);
- public int getDistributionType() {
- return distributionType;
- }
+ } else if (MmsSmsColumns.Types.isScreenshotExtraction(type)) {
+ String txt = Phrase.from(context, R.string.screenshotTaken)
+ .put(NAME_KEY, getName())
+ .format().toString();
+ return emphasisAdded(txt);
- public long getExpiresIn() {
- return expiresIn;
- }
+ } else if (MmsSmsColumns.Types.isMessageRequestResponse(type)) {
+ return emphasisAdded(context.getString(R.string.messageRequestsAccepted));
+ } else if (getCount() == 0) {
+ return new SpannableString(context.getString(R.string.messageEmpty));
+ } else {
+ // This block hits when we receive a media message from an unaccepted contact - however,
+ // unaccepted contacts aren't allowed to send us media - so we'll return an empty string
+ // if it's JUST an image, or the body text that accompanied the image should any exist.
+ // We could return null here - but then we have to find all the usages of this
+ // `getDisplayBody` method and make sure it doesn't fall over if it has a null result.
+ if (TextUtils.isEmpty(getBody())) {
+ return new SpannableString("");
+ // Old behaviour was: return new SpannableString(emphasisAdded(context.getString(R.string.mediaMessage)));
+ } else {
+ return new SpannableString(getBody());
+ }
+ }
+ }
- public long getLastSeen() {
- return lastSeen;
- }
+ private SpannableString emphasisAdded(String sequence) {
+ return emphasisAdded(sequence, 0, sequence.length());
+ }
- public boolean isPinned() {
- return pinned;
- }
+ private SpannableString emphasisAdded(String sequence, int start, int end) {
+ SpannableString spannable = new SpannableString(sequence);
+ spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),
+ start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ return spannable;
+ }
- public int getInitialRecipientHash() {
- return initialRecipientHash;
- }
+ public long getCount() { return count; }
+
+ public int getUnreadCount() { return unreadCount; }
+
+ public int getUnreadMentionCount() { return unreadMentionCount; }
+
+ public long getDate() { return getDateReceived(); }
+
+ public boolean isArchived() { return archived; }
+
+ public int getDistributionType() { return distributionType; }
+
+ public long getExpiresIn() { return expiresIn; }
+
+ public long getLastSeen() { return lastSeen; }
+
+ public boolean isPinned() { return pinned; }
+
+ public int getInitialRecipientHash() { return initialRecipientHash; }
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiCategory.kt b/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiCategory.kt
index 714996e6c8..c9a59b2107 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiCategory.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiCategory.kt
@@ -15,8 +15,7 @@ enum class EmojiCategory(val priority: Int, val key: String, @AttrRes val icon:
PLACES(4, "Places", R.attr.emoji_category_places),
OBJECTS(5, "Objects", R.attr.emoji_category_objects),
SYMBOLS(6, "Symbols", R.attr.emoji_category_symbol),
- FLAGS(7, "Flags", R.attr.emoji_category_flags),
- EMOTICONS(8, "Emoticons", R.attr.emoji_category_emoticons);
+ FLAGS(7, "Flags", R.attr.emoji_category_flags);
@StringRes
fun getCategoryLabel(): Int {
@@ -31,15 +30,14 @@ enum class EmojiCategory(val priority: Int, val key: String, @AttrRes val icon:
@StringRes
fun getCategoryLabel(@AttrRes iconAttr: Int): Int {
return when (iconAttr) {
- R.attr.emoji_category_people -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__smileys_and_people
- R.attr.emoji_category_nature -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__nature
- R.attr.emoji_category_foods -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__food
- R.attr.emoji_category_activity -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__activities
- R.attr.emoji_category_places -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__places
- R.attr.emoji_category_objects -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__objects
- R.attr.emoji_category_symbol -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__symbols
- R.attr.emoji_category_flags -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__flags
- R.attr.emoji_category_emoticons -> R.string.ReactWithAnyEmojiBottomSheetDialogFragment__emoticons
+ R.attr.emoji_category_people -> R.string.emojiCategorySmileys
+ R.attr.emoji_category_nature -> R.string.emojiCategoryAnimals
+ R.attr.emoji_category_foods -> R.string.emojiCategoryFood
+ R.attr.emoji_category_activity -> R.string.emojiCategoryActivities
+ R.attr.emoji_category_places -> R.string.emojiCategoryTravel
+ R.attr.emoji_category_objects -> R.string.emojiCategoryObjects
+ R.attr.emoji_category_symbol -> R.string.emojiCategorySymbols
+ R.attr.emoji_category_flags -> R.string.emojiCategoryFlags
else -> throw AssertionError()
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiSource.kt b/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiSource.kt
index 0b221eb3d1..75b1496cc4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiSource.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/emoji/EmojiSource.kt
@@ -110,10 +110,12 @@ class EmojiSource(
val parsedData: ParsedEmojiData = EmojiJsonParser.parse(it, ::getAssetsUri).getOrThrow()
return EmojiSource(
ScreenDensity.xhdpiRelativeDensityScaleFactor("xhdpi"),
+
parsedData.copy(
- displayPages = parsedData.displayPages + PAGE_EMOTICONS,
- dataPages = parsedData.dataPages + PAGE_EMOTICONS
+ displayPages = parsedData.displayPages,
+ dataPages = parsedData.dataPages
)
+
) { uri: Uri -> EmojiPage.Asset(uri) }
}
}
@@ -137,25 +139,3 @@ data class ObsoleteEmoji(val obsolete: String, val replaceWith: String)
data class EmojiMetrics(val rawHeight: Int, val rawWidth: Int, val perRow: Int)
private fun getAssetsUri(name: String, format: String): Uri = Uri.parse("file:///android_asset/emoji/$name.$format")
-
-private val PAGE_EMOTICONS: EmojiPageModel = StaticEmojiPageModel(
- EmojiCategory.EMOTICONS,
- arrayOf(
- ":-)", ";-)", "(-:", ":->", ":-D", "\\o/",
- ":-P", "B-)", ":-$", ":-*", "O:-)", "=-O",
- "O_O", "O_o", "o_O", ":O", ":-!", ":-x",
- ":-|", ":-\\", ":-(", ":'(", ":-[", ">:-(",
- "^.^", "^_^", "\\(\u02c6\u02da\u02c6)/",
- "\u30fd(\u00b0\u25c7\u00b0 )\u30ce", "\u00af\\(\u00b0_o)/\u00af",
- "\u00af\\_(\u30c4)_/\u00af", "(\u00ac_\u00ac)",
- "(>_<)", "(\u2565\ufe4f\u2565)", "(\u261e\uff9f\u30ee\uff9f)\u261e",
- "\u261c(\uff9f\u30ee\uff9f\u261c)", "\u261c(\u2312\u25bd\u2312)\u261e",
- "(\u256f\u00b0\u25a1\u00b0)\u256f\ufe35", "\u253b\u2501\u253b",
- "\u252c\u2500\u252c", "\u30ce(\u00b0\u2013\u00b0\u30ce)",
- "(^._.^)\uff89", "\u0e05^\u2022\ufecc\u2022^\u0e05",
- "\u0295\u2022\u1d25\u2022\u0294", "(\u2022_\u2022)",
- " \u25a0-\u25a0\u00ac <(\u2022_\u2022) ", "(\u25a0_\u25a0\u00ac)",
- "\u01aa(\u0693\u05f2)\u200e\u01aa\u200b\u200b"
- ),
- null
-)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java
index dcfdb66112..a9edadfcb1 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java
@@ -19,6 +19,7 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import org.session.libsession.utilities.MediaTypes;
+import org.session.libsession.utilities.NonTranslatableStringConstants;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.session.libsignal.utilities.Log;
import org.thoughtcrime.securesms.providers.BlobProvider;
@@ -120,7 +121,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
protected void onPostExecute(@Nullable Uri uri) {
if (uri == null) {
- Toast.makeText(GiphyActivity.this, R.string.GiphyActivity_error_while_retrieving_full_resolution_gif, Toast.LENGTH_LONG).show();
+ Toast.makeText(GiphyActivity.this, R.string.errorUnknown, Toast.LENGTH_LONG).show();
} else if (viewHolder == finishingImage) {
Intent intent = new Intent();
intent.setData(uri);
@@ -165,8 +166,8 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
@Override
public CharSequence getPageTitle(int position) {
- if (position == 0) return context.getString(R.string.GiphyFragmentPagerAdapter_gifs);
- else return context.getString(R.string.GiphyFragmentPagerAdapter_stickers);
+ if (position == 0) return NonTranslatableStringConstants.GIF;
+ else return context.getString(R.string.stickers);
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt
index acb3af8db4..0f562c80b7 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt
@@ -76,17 +76,20 @@ class CreateGroupFragment : Fragment() {
if (isLoading) return@setOnClickListener
val name = binding.nameEditText.text.trim()
if (name.isEmpty()) {
- return@setOnClickListener Toast.makeText(context, R.string.activity_create_closed_group_group_name_missing_error, Toast.LENGTH_LONG).show()
+ return@setOnClickListener Toast.makeText(context, R.string.groupNameEnterPlease, Toast.LENGTH_LONG).show()
}
+
+ // Limit the group name length if it exceeds the limit
if (name.length > resources.getInteger(R.integer.max_group_and_community_name_length_chars)) {
- return@setOnClickListener Toast.makeText(context, R.string.activity_create_closed_group_group_name_too_long_error, Toast.LENGTH_LONG).show()
+ return@setOnClickListener Toast.makeText(context, R.string.groupNameEnterShorter, Toast.LENGTH_LONG).show()
}
+
val selectedMembers = adapter.selectedMembers
if (selectedMembers.isEmpty()) {
- return@setOnClickListener Toast.makeText(context, R.string.activity_create_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
+ return@setOnClickListener Toast.makeText(context, R.string.groupCreateErrorNoMembers, Toast.LENGTH_LONG).show()
}
if (selectedMembers.count() >= groupSizeLimit) { // Minus one because we're going to include self later
- return@setOnClickListener Toast.makeText(context, R.string.activity_create_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
+ return@setOnClickListener Toast.makeText(context, R.string.groupAddMemberMaximum, Toast.LENGTH_LONG).show()
}
val userPublicKey = TextSecurePreferences.getLocalNumber(requireContext())!!
isLoading = true
diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt
index 2d9192ac7a..11dde4b93e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt
@@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.groups
import android.content.Context
import android.content.Intent
import android.os.Bundle
+import android.text.SpannableString
+import android.text.style.StyleSpan
import android.view.Menu
import android.view.MenuItem
import android.view.View
@@ -16,7 +18,10 @@ import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
+import java.io.IOException
+import javax.inject.Inject
import network.loki.messenger.R
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.task
@@ -26,6 +31,7 @@ import org.session.libsession.messaging.sending_receiving.MessageSender
import org.session.libsession.messaging.sending_receiving.groupSizeLimit
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.GroupUtil
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.ThemeUtil
import org.session.libsession.utilities.recipients.Recipient
@@ -40,8 +46,6 @@ import org.thoughtcrime.securesms.groups.ClosedGroupManager.updateLegacyGroup
import com.bumptech.glide.Glide
import org.thoughtcrime.securesms.util.fadeIn
import org.thoughtcrime.securesms.util.fadeOut
-import java.io.IOException
-import javax.inject.Inject
@AndroidEntryPoint
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
@@ -107,17 +111,17 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
groupID = intent.getStringExtra(groupIDKey)!!
val groupInfo = DatabaseComponent.get(this).groupDatabase().getGroup(groupID).get()
originalName = groupInfo.title
- isSelfAdmin = groupInfo.admins.any{ it.serialize() == TextSecurePreferences.getLocalNumber(this) }
+ isSelfAdmin = groupInfo.admins.any { it.serialize() == TextSecurePreferences.getLocalNumber(this) }
name = originalName
mainContentContainer = findViewById(R.id.mainContentContainer)
- cntGroupNameEdit = findViewById(R.id.cntGroupNameEdit)
- cntGroupNameDisplay = findViewById(R.id.cntGroupNameDisplay)
- edtGroupName = findViewById(R.id.edtGroupName)
- emptyStateContainer = findViewById(R.id.emptyStateContainer)
- lblGroupNameDisplay = findViewById(R.id.lblGroupNameDisplay)
- loaderContainer = findViewById(R.id.loaderContainer)
+ cntGroupNameEdit = findViewById(R.id.cntGroupNameEdit)
+ cntGroupNameDisplay = findViewById(R.id.cntGroupNameDisplay)
+ edtGroupName = findViewById(R.id.edtGroupName)
+ emptyStateContainer = findViewById(R.id.emptyStateContainer)
+ lblGroupNameDisplay = findViewById(R.id.lblGroupNameDisplay)
+ loaderContainer = findViewById(R.id.loaderContainer)
findViewById(R.id.addMembersClosedGroupButton).setOnClickListener {
onAddMembersClick()
@@ -129,7 +133,19 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
}
lblGroupNameDisplay.text = originalName
- cntGroupNameDisplay.setOnClickListener { isEditingName = true }
+
+ // Only allow admins to click on the name of closed groups to edit them..
+ if (isSelfAdmin) {
+ cntGroupNameDisplay.setOnClickListener { isEditingName = true }
+ }
+ else // ..and also hide the edit `drawableEnd` for non-admins.
+ {
+ // Note: compoundDrawables returns 4 drawables (drawablesStart/Top/End/Bottom) -
+ // so the `drawableEnd` component is at index 2, which we replace with null.
+ val cd = lblGroupNameDisplay.compoundDrawables
+ lblGroupNameDisplay.setCompoundDrawables(cd[0], cd[1], null, cd[3])
+ }
+
findViewById(R.id.btnCancelGroupNameEdit).setOnClickListener { isEditingName = false }
findViewById(R.id.btnSaveGroupNameEdit).setOnClickListener { saveName() }
edtGroupName.setImeActionLabel(getString(R.string.save), EditorInfo.IME_ACTION_DONE)
@@ -245,10 +261,10 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
private fun saveName() {
val name = edtGroupName.text.toString().trim()
if (name.isEmpty()) {
- return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_missing_error, Toast.LENGTH_SHORT).show()
+ return Toast.makeText(this, R.string.groupNameEnterPlease, Toast.LENGTH_SHORT).show()
}
if (name.length >= 64) {
- return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_too_long_error, Toast.LENGTH_SHORT).show()
+ return Toast.makeText(this, R.string.groupNameEnterShorter, Toast.LENGTH_SHORT).show()
}
this.name = name
lblGroupNameDisplay.text = name
@@ -283,20 +299,22 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
}
if (members.isEmpty()) {
- return Toast.makeText(this, R.string.activity_edit_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
+ return Toast.makeText(this, R.string.groupCreateErrorNoMembers, Toast.LENGTH_LONG).show()
}
val maxGroupMembers = if (isClosedGroup) groupSizeLimit else legacyGroupSizeLimit
if (members.size >= maxGroupMembers) {
- return Toast.makeText(this, R.string.activity_create_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
+ return Toast.makeText(this, R.string.groupAddMemberMaximum, Toast.LENGTH_LONG).show()
}
val userPublicKey = TextSecurePreferences.getLocalNumber(this)!!
val userAsRecipient = Recipient.from(this, Address.fromSerialized(userPublicKey), false)
+ // There's presently no way in the UI to get into the state whereby you could remove yourself from the group when removing any other members
+ // (you can't unselect yourself - the only way to leave is to "Leave Group" from the menu) - but it's possible that this was not always
+ // the case - so we can leave this in as defensive code in-case something goes screwy.
if (!members.contains(userAsRecipient) && !members.map { it.address.toString() }.containsAll(originalMembers.minus(userPublicKey))) {
- val message = "Can't leave while adding or removing other members."
- return Toast.makeText(this@EditClosedGroupActivity, message, Toast.LENGTH_LONG).show()
+ return Log.w("EditClosedGroup", "Can't leave group while adding or removing other members.")
}
if (isClosedGroup) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/JoinCommunityFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/JoinCommunityFragment.kt
index 964e1e1770..a968775ff1 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/groups/JoinCommunityFragment.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/groups/JoinCommunityFragment.kt
@@ -12,6 +12,7 @@ import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.tabs.TabLayoutMediator
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -22,6 +23,7 @@ import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.GroupUtil
import org.session.libsession.utilities.OpenGroupUrlParser
+import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_KEY
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.conversation.start.StartConversationDelegate
@@ -47,6 +49,7 @@ class JoinCommunityFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
binding.backButton.setOnClickListener { delegate.onDialogBackPressed() }
binding.closeButton.setOnClickListener { delegate.onDialogClosePressed() }
+
fun showLoader() {
binding.loader.visibility = View.VISIBLE
binding.loader.animate().setDuration(150).alpha(1.0f).start()
@@ -61,18 +64,23 @@ class JoinCommunityFragment : Fragment() {
}
})
}
+
fun joinCommunityIfPossible(url: String) {
val openGroup = try {
OpenGroupUrlParser.parseUrl(url)
} catch (e: OpenGroupUrlParser.Error) {
when (e) {
- is OpenGroupUrlParser.Error.MalformedURL -> return Toast.makeText(activity, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show()
- is OpenGroupUrlParser.Error.InvalidPublicKey -> return Toast.makeText(activity, R.string.invalid_public_key, Toast.LENGTH_SHORT).show()
- is OpenGroupUrlParser.Error.NoPublicKey -> return Toast.makeText(activity, R.string.invalid_public_key, Toast.LENGTH_SHORT).show()
- is OpenGroupUrlParser.Error.NoRoom -> return Toast.makeText(activity, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show()
+ is OpenGroupUrlParser.Error.MalformedURL, OpenGroupUrlParser.Error.NoRoom -> {
+ return Toast.makeText(activity, context?.resources?.getString(R.string.communityJoinError), Toast.LENGTH_SHORT).show()
+ }
+ is OpenGroupUrlParser.Error.InvalidPublicKey, OpenGroupUrlParser.Error.NoPublicKey -> {
+ return Toast.makeText(activity, R.string.communityEnterUrlErrorInvalidDescription, Toast.LENGTH_SHORT).show()
+ }
}
}
+
showLoader()
+
lifecycleScope.launch(Dispatchers.IO) {
try {
val sanitizedServer = openGroup.server.removeSuffix("/")
@@ -90,10 +98,11 @@ class JoinCommunityFragment : Fragment() {
delegate.onDialogClosePressed()
}
} catch (e: Exception) {
- Log.e("Loki", "Couldn't join open group.", e)
+ Log.e("Loki", "Couldn't join community.", e)
withContext(Dispatchers.Main) {
hideLoader()
- Toast.makeText(activity, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show()
+ val txt = Phrase.from(context, R.string.groupErrorJoin).put(GROUP_NAME_KEY, url).format().toString()
+ Toast.makeText(activity, txt, Toast.LENGTH_SHORT).show()
}
return@launch
}
@@ -107,8 +116,8 @@ class JoinCommunityFragment : Fragment() {
)
val mediator = TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, pos ->
tab.text = when (pos) {
- 0 -> getString(R.string.activity_join_public_chat_enter_community_url_tab_title)
- 1 -> getString(R.string.activity_join_public_chat_scan_qr_code_tab_title)
+ 0 -> getString(R.string.communityUrl)
+ 1 -> getString(R.string.qrScan)
else -> throw IllegalStateException()
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt
index 8bb7a39d4a..b8f3ba8012 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt
@@ -1,18 +1,20 @@
package org.thoughtcrime.securesms.groups
import android.content.Context
+import android.widget.Toast
import androidx.annotation.WorkerThread
-import okhttp3.HttpUrl
+import com.squareup.phrase.Phrase
+import java.util.concurrent.Executors
+import network.loki.messenger.R
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.session.libsession.messaging.MessagingModuleConfiguration
-import org.session.libsession.messaging.open_groups.GroupMemberRole
import org.session.libsession.messaging.open_groups.OpenGroup
import org.session.libsession.messaging.open_groups.OpenGroupApi
import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPoller
+import org.session.libsession.utilities.StringSubstitutionConstants.COMMUNITY_NAME_KEY
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
-import java.util.concurrent.Executors
object OpenGroupManager {
private val executorService = Executors.newScheduledThreadPool(4)
@@ -111,35 +113,43 @@ object OpenGroupManager {
@WorkerThread
fun delete(server: String, room: String, context: Context) {
- val storage = MessagingModuleConfiguration.shared.storage
- val configFactory = MessagingModuleConfiguration.shared.configFactory
- val threadDB = DatabaseComponent.get(context).threadDatabase()
- val openGroupID = "${server.removeSuffix("/")}.$room"
- val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
- val recipient = threadDB.getRecipientForThreadId(threadID) ?: return
- threadDB.setThreadArchived(threadID)
- val groupID = recipient.address.serialize()
- // Stop the poller if needed
- val openGroups = storage.getAllOpenGroups().filter { it.value.server == server }
- if (openGroups.isNotEmpty()) {
- synchronized(pollUpdaterLock) {
- val poller = pollers[server]
- poller?.stop()
- pollers.remove(server)
+ try {
+ val storage = MessagingModuleConfiguration.shared.storage
+ val configFactory = MessagingModuleConfiguration.shared.configFactory
+ val threadDB = DatabaseComponent.get(context).threadDatabase()
+ val openGroupID = "${server.removeSuffix("/")}.$room"
+ val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
+ val recipient = threadDB.getRecipientForThreadId(threadID) ?: return
+ threadDB.setThreadArchived(threadID)
+ val groupID = recipient.address.serialize()
+ // Stop the poller if needed
+ val openGroups = storage.getAllOpenGroups().filter { it.value.server == server }
+ if (openGroups.isNotEmpty()) {
+ synchronized(pollUpdaterLock) {
+ val poller = pollers[server]
+ poller?.stop()
+ pollers.remove(server)
+ }
}
+ configFactory.userGroups?.eraseCommunity(server, room)
+ configFactory.convoVolatile?.eraseCommunity(server, room)
+ // Delete
+ storage.removeLastDeletionServerID(room, server)
+ storage.removeLastMessageServerID(room, server)
+ storage.removeLastInboxMessageId(server)
+ storage.removeLastOutboxMessageId(server)
+ val lokiThreadDB = DatabaseComponent.get(context).lokiThreadDatabase()
+ lokiThreadDB.removeOpenGroupChat(threadID)
+ storage.deleteConversation(threadID) // Must be invoked on a background thread
+ GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread
+ ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context)
+ }
+ catch (e: Exception) {
+ Log.e("Loki", "Failed to leave (delete) community", e)
+ val serverAndRoom = "$server.$room"
+ val txt = Phrase.from(context, R.string.communityLeaveError).put(COMMUNITY_NAME_KEY, serverAndRoom).format().toString()
+ Toast.makeText(context, txt, Toast.LENGTH_LONG).show()
}
- configFactory.userGroups?.eraseCommunity(server, room)
- configFactory.convoVolatile?.eraseCommunity(server, room)
- // Delete
- storage.removeLastDeletionServerID(room, server)
- storage.removeLastMessageServerID(room, server)
- storage.removeLastInboxMessageId(server)
- storage.removeLastOutboxMessageId(server)
- val lokiThreadDB = DatabaseComponent.get(context).lokiThreadDatabase()
- lokiThreadDB.removeOpenGroupChat(threadID)
- storage.deleteConversation(threadID) // Must be invoked on a background thread
- GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread
- ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context)
}
@WorkerThread
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/ConversationView.kt b/app/src/main/java/org/thoughtcrime/securesms/home/ConversationView.kt
index 68aea84417..d87941fcc1 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/ConversationView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/ConversationView.kt
@@ -136,7 +136,7 @@ class ConversationView : LinearLayout {
}
private fun getTitle(recipient: Recipient): String? = when {
- recipient.isLocalNumber -> context.getString(R.string.note_to_self)
+ recipient.isLocalNumber -> context.getString(R.string.noteToSelf)
else -> recipient.toShortString() // Internally uses the Contact API
}
@@ -147,7 +147,7 @@ class ConversationView : LinearLayout {
private fun ThreadRecord.getSnippetPrefix(): CharSequence? = when {
recipient.isLocalNumber || lastMessage?.isControlMessage == true -> null
- lastMessage?.isOutgoing == true -> resources.getString(R.string.MessageRecord_you)
+ lastMessage?.isOutgoing == true -> resources.getString(R.string.you)
else -> lastMessage?.individualRecipient?.toShortString()
}
// endregion
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/EmptyView.kt b/app/src/main/java/org/thoughtcrime/securesms/home/EmptyView.kt
index aa4e0d9017..1457d731d7 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/EmptyView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/EmptyView.kt
@@ -9,20 +9,25 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.NonTranslatableStringConstants.WAVING_HAND_EMOJI
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.EMOJI_KEY
import org.thoughtcrime.securesms.ui.Divider
+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.theme.ThemeColors
-import org.thoughtcrime.securesms.ui.theme.LocalColors
-import org.thoughtcrime.securesms.ui.theme.LocalType
@Composable
internal fun EmptyView(newAccount: Boolean) {
@@ -44,7 +49,13 @@ internal fun EmptyView(newAccount: Boolean) {
textAlign = TextAlign.Center
)
Text(
- stringResource(R.string.welcome_to_session),
+ stringResource(R.string.onboardingBubbleWelcomeToSession).let { txt ->
+ val c = LocalContext.current
+ Phrase.from(txt)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .put(EMOJI_KEY, WAVING_HAND_EMOJI)
+ .format().toString()
+ },
style = LocalType.current.base,
color = LocalColors.current.primary,
textAlign = TextAlign.Center
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
index 2d683abe8f..5af7e7be52 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
@@ -8,8 +8,11 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
+import android.text.format.DateUtils
import android.widget.Toast
import androidx.activity.viewModels
+import androidx.annotation.PluralsRes
+import androidx.annotation.StringRes
import androidx.core.os.bundleOf
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
@@ -17,6 +20,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.LinearLayoutManager
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
@@ -42,6 +46,9 @@ import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.ThreadUtils
import org.session.libsignal.utilities.toHexString
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.start.StartConversationFragment
@@ -73,13 +80,22 @@ import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.ui.setThemedContent
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.IP2Country
+import org.thoughtcrime.securesms.util.RelativeDay
import org.thoughtcrime.securesms.util.disableClipping
import org.thoughtcrime.securesms.util.push
import org.thoughtcrime.securesms.util.show
import org.thoughtcrime.securesms.util.start
import java.io.IOException
+import java.util.Calendar
+import java.util.Locale
import javax.inject.Inject
+import kotlin.math.abs
+import kotlin.time.Duration.Companion.days
+import kotlin.time.Duration.Companion.hours
+import kotlin.time.Duration.Companion.minutes
+import kotlin.time.Duration.Companion.seconds
+// Intent extra keys so we know where we came from
private const val NEW_ACCOUNT = "HomeActivity_NEW_ACCOUNT"
private const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING"
@@ -88,6 +104,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
ConversationClickListener,
GlobalSearchInputLayout.GlobalSearchInputLayoutListener {
+ private val TAG = "HomeActivity"
+
private lateinit var binding: ActivityHomeBinding
private lateinit var glide: RequestManager
@@ -244,17 +262,17 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
globalSearchViewModel.result.map { result ->
result.query to when {
result.query.isEmpty() -> buildList {
- add(GlobalSearchAdapter.Model.Header(R.string.contacts))
+ add(GlobalSearchAdapter.Model.Header(R.string.contactContacts))
add(GlobalSearchAdapter.Model.SavedMessages(publicKey))
addAll(result.groupedContacts)
}
else -> buildList {
result.contactAndGroupList.takeUnless { it.isEmpty() }?.let {
- add(GlobalSearchAdapter.Model.Header(R.string.conversations))
+ add(GlobalSearchAdapter.Model.Header(R.string.sessionConversations))
addAll(it)
}
result.messageResults.takeUnless { it.isEmpty() }?.let {
- add(GlobalSearchAdapter.Model.Header(R.string.global_search_messages))
+ add(GlobalSearchAdapter.Model.Header(R.string.messages))
addAll(it)
}
}
@@ -427,7 +445,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
val clip = ClipData.newPlainText("Account ID", thread.recipient.address.toString())
val manager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(clip)
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
}
else if (thread.recipient.isCommunityRecipient) {
val threadId = threadDb.getThreadIdIfExistsFor(thread.recipient)
@@ -436,7 +454,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
val clip = ClipData.newPlainText("Community URL", openGroup.joinURL)
val manager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(clip)
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
}
}
bottomSheet.onBlockTapped = {
@@ -482,9 +500,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
private fun blockConversation(thread: ThreadRecord) {
showSessionDialog {
- title(R.string.RecipientPreferenceActivity_block_this_contact_question)
- text(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
- button(R.string.RecipientPreferenceActivity_block) {
+ title(R.string.block)
+ text(Phrase.from(context, R.string.blockDescription)
+ .put(NAME_KEY, thread.recipient.name)
+ .format())
+ dangerButton(R.string.block, R.string.AccessibilityId_blockConfirm) {
lifecycleScope.launch(Dispatchers.IO) {
storage.setBlocked(listOf(thread.recipient), true)
@@ -492,6 +512,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
binding.recyclerView.adapter!!.notifyDataSetChanged()
}
}
+ // Block confirmation toast added as per SS-64
+ val txt = Phrase.from(context, R.string.blockBlockedUser).put(NAME_KEY, thread.recipient.name).format().toString()
+ Toast.makeText(context, txt, Toast.LENGTH_LONG).show()
}
cancelButton()
}
@@ -499,12 +522,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
private fun unblockConversation(thread: ThreadRecord) {
showSessionDialog {
- title(R.string.RecipientPreferenceActivity_unblock_this_contact_question)
- text(R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
- button(R.string.RecipientPreferenceActivity_unblock) {
+ title(R.string.blockUnblock)
+ text(Phrase.from(context, R.string.blockUnblockName).put(NAME_KEY, thread.recipient.name).format())
+ dangerButton(R.string.blockUnblock, R.string.AccessibilityId_unblockConfirm) {
lifecycleScope.launch(Dispatchers.IO) {
storage.setBlocked(listOf(thread.recipient), false)
-
withContext(Dispatchers.Main) {
binding.recyclerView.adapter!!.notifyDataSetChanged()
}
@@ -559,18 +581,42 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
private fun deleteConversation(thread: ThreadRecord) {
val threadID = thread.threadId
val recipient = thread.recipient
- val message = if (recipient.isGroupRecipient) {
+ val title: String
+ val message: CharSequence
+
+ if (recipient.isGroupRecipient) {
val group = groupDatabase.getGroup(recipient.address.toString()).orNull()
+
+ // If you are an admin of this group you can delete it
if (group != null && group.admins.map { it.toString() }.contains(textSecurePreferences.getLocalNumber())) {
- getString(R.string.admin_group_leave_warning)
+ title = getString(R.string.groupDelete)
+ message = Phrase.from(this.applicationContext, R.string.groupDeleteDescription)
+ .put(GROUP_NAME_KEY, group.title)
+ .format()
} else {
- resources.getString(R.string.activity_home_leave_group_dialog_message)
+ // Otherwise this is either a community, or it's a group you're not an admin of
+ title = if (recipient.isCommunityRecipient) getString(R.string.communityLeave) else getString(R.string.groupLeave)
+ message = Phrase.from(this.applicationContext, R.string.groupLeaveDescription)
+ .put(GROUP_NAME_KEY, group.title)
+ .format()
}
} else {
- resources.getString(R.string.activity_home_delete_conversation_dialog_message)
+ // If this is a 1-on-1 conversation
+ if (recipient.name != null) {
+ title = getString(R.string.conversationsDelete)
+ message = Phrase.from(this.applicationContext, R.string.conversationsDeleteDescription)
+ .put(NAME_KEY, recipient.name)
+ .format()
+ }
+ else {
+ // If not group-related and we don't have a recipient name then this must be our Note to Self conversation
+ title = getString(R.string.noteToSelf)
+ message = getString(R.string.clearMessagesNoteToSelfDescription)
+ }
}
showSessionDialog {
+ title(title)
text(message)
button(R.string.yes) {
lifecycleScope.launch(Dispatchers.Main) {
@@ -583,7 +629,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
GroupUtil.doubleDecodeGroupID(recipient.address.toString()).toHexString()
.takeIf(DatabaseComponent.get(context).lokiAPIDatabase()::isClosedGroup)
?.let { MessageSender.explicitLeave(it, false) }
- } catch (_: IOException) {
+ } catch (ioe: IOException) {
+ Log.w(TAG, "Got an IOException while sending leave group message")
}
}
// Delete the conversation
@@ -597,8 +644,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
}
// Update the badge count
ApplicationContext.getInstance(context).messageNotifier.updateNotification(context)
+
// Notify the user
- val toastMessage = if (recipient.isGroupRecipient) R.string.MessageRecord_left_group else R.string.activity_home_conversation_deleted_message
+ val toastMessage = if (recipient.isGroupRecipient) R.string.groupMemberYouLeft else R.string.conversationsDeleted
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show()
}
}
@@ -618,7 +666,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
private fun hideMessageRequests() {
showSessionDialog {
- text(getString(R.string.hide_message_requests))
+ text(getString(R.string.hide))
button(R.string.yes) {
textSecurePreferences.setHasHiddenMessageRequests()
homeViewModel.tryReload()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt
index f399b602b4..1530845300 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt
@@ -27,9 +27,12 @@ import kotlinx.coroutines.withContext
import network.loki.messenger.R
import network.loki.messenger.databinding.ActivityPathBinding
import org.session.libsession.snode.OnionRequestAPI
+import org.session.libsession.utilities.NonTranslatableStringConstants.APP_NAME
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsession.utilities.getColorFromAttr
import org.session.libsignal.utilities.Snode
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
+import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.util.GlowViewUtilities
import org.thoughtcrime.securesms.util.IP2Country
import org.thoughtcrime.securesms.util.PathDotView
@@ -49,7 +52,12 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
super.onCreate(savedInstanceState, isReady)
binding = ActivityPathBinding.inflate(layoutInflater)
setContentView(binding.root)
- supportActionBar!!.title = resources.getString(R.string.activity_path_title)
+ supportActionBar!!.title = resources.getString(R.string.onionRoutingPath)
+
+ // Substitute "Session" into the path description. Note: This is a non-translatable string.
+ val txt = applicationContext.getSubbedString(R.string.onionRoutingPathDescription,APP_NAME_KEY to APP_NAME)
+ binding.pathDescription.text = txt
+
binding.pathRowsContainer.disableClipping()
binding.learnMoreButton.setOnClickListener { learnMore() }
update(false)
@@ -98,6 +106,7 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
private fun update(isAnimated: Boolean) {
binding.pathRowsContainer.removeAllViews()
+
if (OnionRequestAPI.paths.isNotEmpty()) {
val path = OnionRequestAPI.paths.firstOrNull() ?: return finish()
val dotAnimationRepeatInterval = path.count().toLong() * 1000 + 1000
@@ -105,8 +114,8 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
val isGuardSnode = (OnionRequestAPI.guardSnodes.contains(snode))
getPathRow(snode, LineView.Location.Middle, index.toLong() * 1000 + 2000, dotAnimationRepeatInterval, isGuardSnode)
}
- val youRow = getPathRow(resources.getString(R.string.activity_path_device_row_title), null, LineView.Location.Top, 1000, dotAnimationRepeatInterval)
- val destinationRow = getPathRow(resources.getString(R.string.activity_path_destination_row_title), null, LineView.Location.Bottom, path.count().toLong() * 1000 + 2000, dotAnimationRepeatInterval)
+ val youRow = getPathRow(resources.getString(R.string.onionRoutingPath), null, LineView.Location.Top, 1000, dotAnimationRepeatInterval)
+ val destinationRow = getPathRow(resources.getString(R.string.onionRoutingPathDestination), null, LineView.Location.Bottom, path.count().toLong() * 1000 + 2000, dotAnimationRepeatInterval)
val rows = listOf( youRow ) + pathRows + listOf( destinationRow )
for (row in rows) {
binding.pathRowsContainer.addView(row)
@@ -162,11 +171,11 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
}
private fun getPathRow(snode: Snode, location: LineView.Location, dotAnimationStartDelay: Long, dotAnimationRepeatInterval: Long, isGuardSnode: Boolean): LinearLayout {
- val title = if (isGuardSnode) resources.getString(R.string.activity_path_guard_node_row_title) else resources.getString(R.string.activity_path_service_node_row_title)
+ val title = if (isGuardSnode) resources.getString(R.string.onionRoutingPathEntryNode) else resources.getString(R.string.onionRoutingPathServiceNode)
val subtitle = if (IP2Country.isInitialized) {
- IP2Country.shared.countryNamesCache[snode.ip] ?: resources.getString(R.string.activity_path_resolving_progress)
+ IP2Country.shared.countryNamesCache[snode.ip] ?: resources.getString(R.string.resolving)
} else {
- resources.getString(R.string.activity_path_resolving_progress)
+ resources.getString(R.string.resolving)
}
return getPathRow(title, subtitle, location, dotAnimationStartDelay, dotAnimationRepeatInterval)
}
@@ -179,7 +188,7 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} catch (e: Exception) {
- Toast.makeText(this, R.string.invalid_url, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.communityEnterUrlErrorInvalid, Toast.LENGTH_SHORT).show()
}
}
// endregion
@@ -250,13 +259,11 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
override fun onAttachedToWindow() {
super.onAttachedToWindow()
-
startAnimation()
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
-
stopAnimation()
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt b/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt
index 33bdd2f2f6..617f98a9cd 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/SeedReminder.kt
@@ -18,15 +18,15 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import network.loki.messenger.R
-import org.thoughtcrime.securesms.ui.theme.LocalDimensions
-import org.thoughtcrime.securesms.ui.theme.PreviewTheme
-import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.SessionShieldIcon
-import org.thoughtcrime.securesms.ui.theme.ThemeColors
-import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.components.SlimPrimaryOutlineButton
import org.thoughtcrime.securesms.ui.contentDescription
+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.theme.ThemeColors
@Composable
internal fun SeedReminder(startRecoveryPasswordActivity: () -> Unit) {
@@ -49,23 +49,23 @@ internal fun SeedReminder(startRecoveryPasswordActivity: () -> Unit) {
Column(Modifier.weight(1f)) {
Row {
Text(
- stringResource(R.string.save_your_recovery_password),
+ stringResource(R.string.recoveryPasswordBannerTitle),
style = LocalType.current.h8
)
Spacer(Modifier.requiredWidth(LocalDimensions.current.xxsSpacing))
SessionShieldIcon()
}
Text(
- stringResource(R.string.save_your_recovery_password_to_make_sure_you_don_t_lose_access_to_your_account),
+ stringResource(R.string.recoveryPasswordBannerDescription),
style = LocalType.current.small
)
}
Spacer(Modifier.width(LocalDimensions.current.xsSpacing))
SlimPrimaryOutlineButton(
- text = stringResource(R.string.continue_2),
+ text = stringResource(R.string.theContinue),
modifier = Modifier
.align(Alignment.CenterVertically)
- .contentDescription(R.string.AccessibilityId_reveal_recovery_phrase_button),
+ .contentDescription(R.string.AccessibilityId_recoveryPasswordBanner),
onClick = startRecoveryPasswordActivity
)
}
@@ -78,6 +78,6 @@ private fun PreviewSeedReminder(
@PreviewParameter(SessionColorsParameterProvider::class) colors: ThemeColors
) {
PreviewTheme(colors) {
- SeedReminder {}
+ SeedReminder { }
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt
index cae399dcbf..d5fad90c4a 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt
@@ -100,7 +100,7 @@ class UserDetailsBottomSheet: BottomSheetDialogFragment() {
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Account ID", publicKey)
clipboard.setPrimaryClip(clip)
- Toast.makeText(requireContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT)
+ Toast.makeText(requireContext(), R.string.copied, Toast.LENGTH_SHORT)
.show()
true
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/search/GlobalSearchAdapterUtils.kt b/app/src/main/java/org/thoughtcrime/securesms/home/search/GlobalSearchAdapterUtils.kt
index d390776d1c..947edc3d8e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/home/search/GlobalSearchAdapterUtils.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/home/search/GlobalSearchAdapterUtils.kt
@@ -6,12 +6,14 @@ import android.text.SpannableStringBuilder
import android.text.style.StyleSpan
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
+import java.util.Locale
import network.loki.messenger.R
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsession.utilities.truncateIdForDisplay
import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.ContentView
+import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.Contact as ContactModel
import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.GroupConversation
import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.Header
import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.Message
@@ -19,9 +21,6 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.SavedMes
import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.SubHeader
import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.SearchUtil
-import java.util.Locale
-import org.thoughtcrime.securesms.home.search.GlobalSearchAdapter.Model.Contact as ContactModel
-
class GlobalSearchDiff(
private val oldQuery: String?,
@@ -78,8 +77,8 @@ fun ContentView.bindQuery(query: String, model: GlobalSearchAdapter.Model) {
}
binding.searchResultSubtitle.text = getHighlight(query, membersString)
}
- is Header, // do nothing for header
- is SubHeader, // do nothing for subheader
+ is Header, // do nothing for header
+ is SubHeader, // do nothing for subheader
is SavedMessages -> Unit // do nothing for saved messages (displays note to self)
}
}
@@ -112,7 +111,7 @@ fun ContentView.bindModel(query: String?, model: ContactModel) = binding.run {
searchResultSubtitle.text = null
val recipient = Recipient.from(root.context, Address.fromSerialized(model.contact.accountID), false)
searchResultProfilePicture.update(recipient)
- val nameString = if (model.isSelf) root.context.getString(R.string.note_to_self)
+ val nameString = if (model.isSelf) root.context.getString(R.string.noteToSelf)
else model.contact.getSearchName()
searchResultTitle.text = getHighlight(query, nameString)
}
@@ -120,7 +119,7 @@ fun ContentView.bindModel(query: String?, model: ContactModel) = binding.run {
fun ContentView.bindModel(model: SavedMessages) {
binding.searchResultSubtitle.isVisible = false
binding.searchResultTimestamp.isVisible = false
- binding.searchResultTitle.setText(R.string.note_to_self)
+ binding.searchResultTitle.setText(R.string.noteToSelf)
binding.searchResultProfilePicture.update(Address.fromSerialized(model.currentUserPublicKey))
binding.searchResultProfilePicture.isVisible = true
}
@@ -128,11 +127,13 @@ fun ContentView.bindModel(model: SavedMessages) {
fun ContentView.bindModel(query: String?, model: Message) = binding.apply {
searchResultProfilePicture.isVisible = true
searchResultTimestamp.isVisible = true
+
// val hasUnreads = model.unread > 0
// unreadCountIndicator.isVisible = hasUnreads
// if (hasUnreads) {
// unreadCountTextView.text = model.unread.toString()
// }
+
searchResultTimestamp.text = DateUtils.getDisplayFormattedTimeSpanString(root.context, Locale.getDefault(), model.messageResult.sentTimestampMs)
searchResultProfilePicture.update(model.messageResult.conversationRecipient)
val textSpannable = SpannableStringBuilder()
@@ -146,7 +147,7 @@ fun ContentView.bindModel(query: String?, model: Message) = binding.apply {
model.messageResult.bodySnippet
))
searchResultSubtitle.text = textSpannable
- searchResultTitle.text = if (model.isSelf) root.context.getString(R.string.note_to_self)
+ searchResultTitle.text = if (model.isSelf) root.context.getString(R.string.noteToSelf)
else model.messageResult.conversationRecipient.getSearchName()
searchResultSubtitle.isVisible = true
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java
index 807c4548a7..6f44f7523c 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java
@@ -1,216 +1,233 @@
package org.thoughtcrime.securesms.linkpreview;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
import android.annotation.SuppressLint;
+import android.os.Build;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.URLSpan;
import android.text.util.Linkify;
-
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import com.annimon.stream.Stream;
-
-import org.thoughtcrime.securesms.util.DateUtils;
-import org.session.libsignal.utilities.guava.Optional;
-
-import org.session.libsession.utilities.Util;
-
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import okhttp3.HttpUrl;
+import org.session.libsession.utilities.Util;
+import org.session.libsignal.utilities.Log;
+import org.session.libsignal.utilities.guava.Optional;
public final class LinkPreviewUtil {
- private static final Pattern DOMAIN_PATTERN = Pattern.compile("^(https?://)?([^/]+).*$", Pattern.CASE_INSENSITIVE);
- private static final Pattern ALL_ASCII_PATTERN = Pattern.compile("^[\\x00-\\x7F]*$", Pattern.CASE_INSENSITIVE);
- private static final Pattern ALL_NON_ASCII_PATTERN = Pattern.compile("^[^\\x00-\\x7F]*$", Pattern.CASE_INSENSITIVE);
- private static final Pattern OPEN_GRAPH_TAG_PATTERN = Pattern.compile("<\\s*meta[^>]*property\\s*=\\s*\"\\s*og:([^\"]+)\"[^>]*/?\\s*>", Pattern.CASE_INSENSITIVE);
- private static final Pattern ARTICLE_TAG_PATTERN = Pattern.compile("<\\s*meta[^>]*property\\s*=\\s*\"\\s*article:([^\"]+)\"[^>]*/?\\s*>", Pattern.CASE_INSENSITIVE);
- private static final Pattern OPEN_GRAPH_CONTENT_PATTERN = Pattern.compile("content\\s*=\\s*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE);
- private static final Pattern TITLE_PATTERN = Pattern.compile("<\\s*title[^>]*>(.*)<\\s*/title[^>]*>", Pattern.CASE_INSENSITIVE);
- private static final Pattern FAVICON_PATTERN = Pattern.compile("<\\s*link[^>]*rel\\s*=\\s*\".*icon.*\"[^>]*>", Pattern.CASE_INSENSITIVE);
- private static final Pattern FAVICON_HREF_PATTERN = Pattern.compile("href\\s*=\\s*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE);
+ private static final Pattern DOMAIN_PATTERN = Pattern.compile("^(https?://)?([^/]+).*$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern ALL_ASCII_PATTERN = Pattern.compile("^[\\x00-\\x7F]*$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern ALL_NON_ASCII_PATTERN = Pattern.compile("^[^\\x00-\\x7F]*$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPEN_GRAPH_TAG_PATTERN = Pattern.compile("<\\s*meta[^>]*property\\s*=\\s*\"\\s*og:([^\"]+)\"[^>]*/?\\s*>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern ARTICLE_TAG_PATTERN = Pattern.compile("<\\s*meta[^>]*property\\s*=\\s*\"\\s*article:([^\"]+)\"[^>]*/?\\s*>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPEN_GRAPH_CONTENT_PATTERN = Pattern.compile("content\\s*=\\s*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE);
+ private static final Pattern TITLE_PATTERN = Pattern.compile("<\\s*title[^>]*>(.*)<\\s*/title[^>]*>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern FAVICON_PATTERN = Pattern.compile("<\\s*link[^>]*rel\\s*=\\s*\".*icon.*\"[^>]*>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern FAVICON_HREF_PATTERN = Pattern.compile("href\\s*=\\s*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE);
- /**
- * @return All whitelisted URLs in the source text.
- */
- public static @NonNull List findWhitelistedUrls(@NonNull String text) {
- SpannableString spannable = new SpannableString(text);
- boolean found = Linkify.addLinks(spannable, Linkify.WEB_URLS);
+ /**
+ * @return All whitelisted URLs in the source text.
+ */
+ public static @NonNull List findWhitelistedUrls(@NonNull String text) {
+ SpannableString spannable = new SpannableString(text);
+ boolean found = Linkify.addLinks(spannable, Linkify.WEB_URLS);
- if (!found) {
- return Collections.emptyList();
- }
-
- return Stream.of(spannable.getSpans(0, spannable.length(), URLSpan.class))
- .map(span -> new Link(span.getURL(), spannable.getSpanStart(span)))
- .filter(link -> isValidLinkUrl(link.getUrl()))
- .toList();
- }
-
- /**
- * @return True if the host is valid.
- */
- public static boolean isValidLinkUrl(@Nullable String linkUrl) {
- if (linkUrl == null) return false;
-
- HttpUrl url = HttpUrl.parse(linkUrl);
- return url != null &&
- !TextUtils.isEmpty(url.scheme()) &&
- "https".equals(url.scheme()) &&
- isLegalUrl(linkUrl);
- }
-
- /**
- * @return True if the top-level domain is valid.
- */
- public static boolean isValidMediaUrl(@Nullable String mediaUrl) {
- if (mediaUrl == null) return false;
-
- HttpUrl url = HttpUrl.parse(mediaUrl);
- return url != null &&
- !TextUtils.isEmpty(url.scheme()) &&
- "https".equals(url.scheme()) &&
- isLegalUrl(mediaUrl);
- }
-
- public static boolean isLegalUrl(@NonNull String url) {
- Matcher matcher = DOMAIN_PATTERN.matcher(url);
-
- if (matcher.matches()) {
- String domain = matcher.group(2);
- String cleanedDomain = domain.replaceAll("\\.", "");
-
- return ALL_ASCII_PATTERN.matcher(cleanedDomain).matches() ||
- ALL_NON_ASCII_PATTERN.matcher(cleanedDomain).matches();
- } else {
- return false;
- }
- }
-
- public static boolean isValidMimeType(@NonNull String url) {
- String[] validMimeType = {".jpg", ".png", ".gif", ".jpeg"};
- if (url.contains(".")) {
- for (String mimeType : validMimeType) {
- if (url.contains(mimeType)) {
- return true;
+ if (!found) {
+ return Collections.emptyList();
}
- }
- return false;
- }
- return true;
- }
- public static @NonNull OpenGraph parseOpenGraphFields(@Nullable String html) {
- return parseOpenGraphFields(html, text -> Html.fromHtml(text).toString());
- }
-
- static @NonNull OpenGraph parseOpenGraphFields(@Nullable String html, @NonNull HtmlDecoder htmlDecoder) {
- if (html == null) {
- return new OpenGraph(Collections.emptyMap(), null, null);
+ return Stream.of(spannable.getSpans(0, spannable.length(), URLSpan.class))
+ .map(span -> new Link(span.getURL(), spannable.getSpanStart(span)))
+ .filter(link -> isValidLinkUrl(link.getUrl()))
+ .toList();
}
- Map openGraphTags = new HashMap<>();
- Matcher openGraphMatcher = OPEN_GRAPH_TAG_PATTERN.matcher(html);
+ /**
+ * @return True if the host is valid.
+ */
+ public static boolean isValidLinkUrl(@Nullable String linkUrl) {
+ if (linkUrl == null) return false;
- while (openGraphMatcher.find()) {
- String tag = openGraphMatcher.group();
- String property = openGraphMatcher.groupCount() > 0 ? openGraphMatcher.group(1) : null;
+ HttpUrl url = HttpUrl.parse(linkUrl);
+ return url != null &&
+ !TextUtils.isEmpty(url.scheme()) &&
+ "https".equals(url.scheme()) &&
+ isLegalUrl(linkUrl);
+ }
- if (property != null) {
- Matcher contentMatcher = OPEN_GRAPH_CONTENT_PATTERN.matcher(tag);
- if (contentMatcher.find() && contentMatcher.groupCount() > 0) {
- String content = htmlDecoder.fromEncoded(contentMatcher.group(1));
- openGraphTags.put(property.toLowerCase(), content);
+ /**
+ * @return True if the top-level domain is valid.
+ */
+ public static boolean isValidMediaUrl(@Nullable String mediaUrl) {
+ if (mediaUrl == null) return false;
+
+ HttpUrl url = HttpUrl.parse(mediaUrl);
+ return url != null &&
+ !TextUtils.isEmpty(url.scheme()) &&
+ "https".equals(url.scheme()) &&
+ isLegalUrl(mediaUrl);
+ }
+
+ public static boolean isLegalUrl(@NonNull String url) {
+ Matcher matcher = DOMAIN_PATTERN.matcher(url);
+
+ if (matcher.matches()) {
+ String domain = matcher.group(2);
+ String cleanedDomain = domain.replaceAll("\\.", "");
+
+ return ALL_ASCII_PATTERN.matcher(cleanedDomain).matches() ||
+ ALL_NON_ASCII_PATTERN.matcher(cleanedDomain).matches();
+ } else {
+ return false;
}
- }
}
- Matcher articleMatcher = ARTICLE_TAG_PATTERN.matcher(html);
-
- while (articleMatcher.find()) {
- String tag = articleMatcher.group();
- String property = articleMatcher.groupCount() > 0 ? articleMatcher.group(1) : null;
-
- if (property != null) {
- Matcher contentMatcher = OPEN_GRAPH_CONTENT_PATTERN.matcher(tag);
- if (contentMatcher.find() && contentMatcher.groupCount() > 0) {
- String content = htmlDecoder.fromEncoded(contentMatcher.group(1));
- openGraphTags.put(property.toLowerCase(), content);
+ public static boolean isValidMimeType(@NonNull String url) {
+ String[] validMimeType = {".jpg", ".png", ".gif", ".jpeg"};
+ if (url.contains(".")) {
+ for (String mimeType : validMimeType) {
+ if (url.contains(mimeType)) {
+ return true;
+ }
+ }
+ return false;
}
- }
+ return true;
}
- String htmlTitle = "";
- String faviconUrl = "";
-
- Matcher titleMatcher = TITLE_PATTERN.matcher(html);
- if (titleMatcher.find() && titleMatcher.groupCount() > 0) {
- htmlTitle = htmlDecoder.fromEncoded(titleMatcher.group(1));
+ public static @NonNull OpenGraph parseOpenGraphFields(@Nullable String html) {
+ return parseOpenGraphFields(html, text -> Html.fromHtml(text).toString());
}
- Matcher faviconMatcher = FAVICON_PATTERN.matcher(html);
- if (faviconMatcher.find()) {
- Matcher faviconHrefMatcher = FAVICON_HREF_PATTERN.matcher(faviconMatcher.group());
- if (faviconHrefMatcher.find() && faviconHrefMatcher.groupCount() > 0) {
- faviconUrl = faviconHrefMatcher.group(1);
- }
+ static @NonNull OpenGraph parseOpenGraphFields(@Nullable String html, @NonNull HtmlDecoder htmlDecoder) {
+ if (html == null) {
+ return new OpenGraph(Collections.emptyMap(), null, null);
+ }
+
+ Map openGraphTags = new HashMap<>();
+ Matcher openGraphMatcher = OPEN_GRAPH_TAG_PATTERN.matcher(html);
+
+ while (openGraphMatcher.find()) {
+ String tag = openGraphMatcher.group();
+ String property = openGraphMatcher.groupCount() > 0 ? openGraphMatcher.group(1) : null;
+
+ if (property != null) {
+ Matcher contentMatcher = OPEN_GRAPH_CONTENT_PATTERN.matcher(tag);
+ if (contentMatcher.find() && contentMatcher.groupCount() > 0) {
+ String content = htmlDecoder.fromEncoded(contentMatcher.group(1));
+ openGraphTags.put(property.toLowerCase(), content);
+ }
+ }
+ }
+
+ Matcher articleMatcher = ARTICLE_TAG_PATTERN.matcher(html);
+
+ while (articleMatcher.find()) {
+ String tag = articleMatcher.group();
+ String property = articleMatcher.groupCount() > 0 ? articleMatcher.group(1) : null;
+
+ if (property != null) {
+ Matcher contentMatcher = OPEN_GRAPH_CONTENT_PATTERN.matcher(tag);
+ if (contentMatcher.find() && contentMatcher.groupCount() > 0) {
+ String content = htmlDecoder.fromEncoded(contentMatcher.group(1));
+ openGraphTags.put(property.toLowerCase(), content);
+ }
+ }
+ }
+
+ String htmlTitle = "";
+ String faviconUrl = "";
+
+ Matcher titleMatcher = TITLE_PATTERN.matcher(html);
+ if (titleMatcher.find() && titleMatcher.groupCount() > 0) {
+ htmlTitle = htmlDecoder.fromEncoded(titleMatcher.group(1));
+ }
+
+ Matcher faviconMatcher = FAVICON_PATTERN.matcher(html);
+ if (faviconMatcher.find()) {
+ Matcher faviconHrefMatcher = FAVICON_HREF_PATTERN.matcher(faviconMatcher.group());
+ if (faviconHrefMatcher.find() && faviconHrefMatcher.groupCount() > 0) {
+ faviconUrl = faviconHrefMatcher.group(1);
+ }
+ }
+
+ return new OpenGraph(openGraphTags, htmlTitle, faviconUrl);
}
- return new OpenGraph(openGraphTags, htmlTitle, faviconUrl);
- }
+ public static final class OpenGraph {
- public static final class OpenGraph {
+ private final Map values;
- private final Map values;
+ private final @Nullable String htmlTitle;
+ private final @Nullable String faviconUrl;
- private final @Nullable String htmlTitle;
- private final @Nullable String faviconUrl;
+ private static final String KEY_TITLE = "title";
+ private static final String KEY_DESCRIPTION_URL = "description";
+ private static final String KEY_IMAGE_URL = "image";
+ private static final String KEY_PUBLISHED_TIME_1 = "published_time";
+ private static final String KEY_PUBLISHED_TIME_2 = "article:published_time";
+ private static final String KEY_MODIFIED_TIME_1 = "modified_time";
+ private static final String KEY_MODIFIED_TIME_2 = "article:modified_time";
- private static final String KEY_TITLE = "title";
- private static final String KEY_DESCRIPTION_URL = "description";
- private static final String KEY_IMAGE_URL = "image";
- private static final String KEY_PUBLISHED_TIME_1 = "published_time";
- private static final String KEY_PUBLISHED_TIME_2 = "article:published_time";
- private static final String KEY_MODIFIED_TIME_1 = "modified_time";
- private static final String KEY_MODIFIED_TIME_2 = "article:modified_time";
+ public OpenGraph(@NonNull Map values, @Nullable String htmlTitle, @Nullable String faviconUrl) {
+ this.values = values;
+ this.htmlTitle = htmlTitle;
+ this.faviconUrl = faviconUrl;
+ }
- public OpenGraph(@NonNull Map values, @Nullable String htmlTitle, @Nullable String faviconUrl) {
- this.values = values;
- this.htmlTitle = htmlTitle;
- this.faviconUrl = faviconUrl;
+ public @NonNull Optional getTitle() {
+ return Optional.of(Util.getFirstNonEmpty(values.get(KEY_TITLE), htmlTitle));
+ }
+
+ public @NonNull Optional getImageUrl() {
+ return Optional.of(Util.getFirstNonEmpty(values.get(KEY_IMAGE_URL), faviconUrl));
+ }
+
+ private static long parseISO8601(String date) {
+
+ if (date == null || date.isEmpty()) { return -1L; }
+
+ SimpleDateFormat format;
+ if (Build.VERSION.SDK_INT >= 24) {
+ format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.getDefault());
+ } else {
+ format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault());
+ }
+
+ try {
+ return format.parse(date).getTime();
+ } catch (ParseException pe) {
+ Log.w("OpenGraph", "Failed to parse date.", pe);
+ return -1L;
+ }
+ }
+
+ @SuppressLint("ObsoleteSdkInt")
+ public long getDate() {
+ return Stream.of(values.get(KEY_PUBLISHED_TIME_1),
+ values.get(KEY_PUBLISHED_TIME_2),
+ values.get(KEY_MODIFIED_TIME_1),
+ values.get(KEY_MODIFIED_TIME_2))
+ .map(OpenGraph::parseISO8601)
+ .filter(time -> time > 0)
+ .findFirst()
+ .orElse(0L);
+ }
}
- public @NonNull Optional getTitle() {
- return Optional.of(Util.getFirstNonEmpty(values.get(KEY_TITLE), htmlTitle));
+ public interface HtmlDecoder {
+ @NonNull String fromEncoded(@NonNull String html);
}
- public @NonNull Optional getImageUrl() {
- return Optional.of(Util.getFirstNonEmpty(values.get(KEY_IMAGE_URL), faviconUrl));
- }
-
- @SuppressLint("ObsoleteSdkInt")
- public long getDate() {
- return Stream.of(values.get(KEY_PUBLISHED_TIME_1),
- values.get(KEY_PUBLISHED_TIME_2),
- values.get(KEY_MODIFIED_TIME_1),
- values.get(KEY_MODIFIED_TIME_2))
- .map(DateUtils::parseIso8601)
- .filter(time -> time > 0)
- .findFirst()
- .orElse(0L);
- }
- }
-
- public interface HtmlDecoder {
- @NonNull String fromEncoded(@NonNull String html);
- }
-
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/media/DocumentsPage.kt b/app/src/main/java/org/thoughtcrime/securesms/media/DocumentsPage.kt
index 0f4b8c58b8..4d132f009b 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/media/DocumentsPage.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/media/DocumentsPage.kt
@@ -44,7 +44,7 @@ fun DocumentsPage(
content.isEmpty() -> {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
- text = stringResource(R.string.media_overview_documents_fragment__no_documents_found),
+ text = stringResource(R.string.attachmentsFilesEmpty),
style = LocalType.current.base,
color = LocalColors.current.text
)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/media/FixedTimeBuckets.kt b/app/src/main/java/org/thoughtcrime/securesms/media/FixedTimeBuckets.kt
index f01276f78e..85b00f66bc 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/media/FixedTimeBuckets.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/media/FixedTimeBuckets.kt
@@ -35,10 +35,10 @@ class FixedTimeBuckets(
@StringRes
fun getBucketText(time: ZonedDateTime): Int? {
return when {
- time >= startOfToday -> R.string.BucketedThreadMedia_Today
+ time >= startOfToday -> R.string.BucketedThreadMedia_Today
time >= startOfYesterday -> R.string.BucketedThreadMedia_Yesterday
- time >= startOfThisWeek -> R.string.BucketedThreadMedia_This_week
- time >= startOfThisMonth -> R.string.BucketedThreadMedia_This_month
+ time >= startOfThisWeek -> R.string.attachmentsThisWeek
+ time >= startOfThisMonth -> R.string.attachmentsThisMonth
else -> null
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewScreen.kt b/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewScreen.kt
index 2f72751265..e395987e3f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewScreen.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewScreen.kt
@@ -34,6 +34,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
@@ -68,7 +69,7 @@ fun MediaOverviewScreen(
} else {
Toast.makeText(
context,
- R.string.MediaPreviewActivity_unable_to_write_to_external_storage_without_permission,
+ R.string.cameraGrantAccessDenied,
Toast.LENGTH_LONG
).show()
}
@@ -101,31 +102,18 @@ fun MediaOverviewScreen(
} catch (e: ActivityNotFoundException) {
Toast.makeText(
context,
- R.string.ConversationItem_unable_to_open_media,
+ R.string.attachmentsErrorOpen,
Toast.LENGTH_LONG
).show()
}
}
is MediaOverviewEvent.ShowSaveAttachmentError -> {
- val message = context.resources.getQuantityText(
- R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card,
- event.errorCount
- )
- Toast.makeText(context, message, Toast.LENGTH_LONG).show()
+ Toast.makeText(context, R.string.attachmentsSaveError, Toast.LENGTH_LONG).show()
}
is MediaOverviewEvent.ShowSaveAttachmentSuccess -> {
- val message = if (event.directory.isNotBlank()) {
- context.resources.getString(
- R.string.SaveAttachmentTask_saved_to,
- event.directory
- )
- } else {
- context.resources.getString(R.string.SaveAttachmentTask_saved)
- }
-
- Toast.makeText(context, message, Toast.LENGTH_LONG).show()
+ Toast.makeText(context, R.string.saved, Toast.LENGTH_LONG).show()
}
}
}
@@ -241,15 +229,11 @@ private fun SaveAttachmentWarningDialog(
val context = LocalContext.current
AlertDialog(
onDismissRequest = onDismissRequest,
- title = context.getString(R.string.ConversationFragment_save_to_sd_card),
- text = context.resources.getQuantityString(
- R.plurals.ConversationFragment_saving_n_media_to_storage_warning,
- numSelected,
- numSelected
- ),
+ title = context.getString(R.string.warning),
+ text = context.resources.getString(R.string.attachmentsWarning),
buttons = listOf(
- DialogButtonModel(GetString(R.string.save), onClick = onAccepted),
- DialogButtonModel(GetString(android.R.string.cancel), dismissOnClick = true)
+ DialogButtonModel(GetString(R.string.save), GetString(R.string.AccessibilityId_save), color = LocalColors.current.danger, onClick = onAccepted),
+ DialogButtonModel(GetString(android.R.string.cancel), GetString(R.string.AccessibilityId_cancel), dismissOnClick = true)
)
)
}
@@ -305,7 +289,6 @@ private fun ActionProgressDialog(
private val MediaOverviewTab.titleResId: Int
get() = when (this) {
- MediaOverviewTab.Media -> R.string.MediaOverviewActivity_Media
- MediaOverviewTab.Documents -> R.string.MediaOverviewActivity_Documents
- }
-
+ MediaOverviewTab.Media -> R.string.media
+ MediaOverviewTab.Documents -> R.string.document
+ }
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewTopAppBar.kt b/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewTopAppBar.kt
index 570885f212..c6fa7d4a1f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewTopAppBar.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewTopAppBar.kt
@@ -50,7 +50,7 @@ fun MediaOverviewTopAppBar(
IconButton(onClick = onSelectAllClicked) {
Icon(
painterResource(R.drawable.ic_baseline_select_all_24),
- contentDescription = stringResource(R.string.MediaOverviewActivity_Select_all),
+ contentDescription = stringResource(R.string.selectAll),
tint = LocalColors.current.text,
)
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewViewModel.kt
index a0b629737d..25ea26b197 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewViewModel.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/media/MediaOverviewViewModel.kt
@@ -234,11 +234,7 @@ class MediaOverviewViewModel(
viewModelScope.launch {
val selectedMedia = selectedMedia.toList()
- mutableShowingActionProgress.value = application.resources.getQuantityString(
- R.plurals.ConversationFragment_saving_n_attachments,
- selectedMedia.size,
- selectedMedia.size,
- )
+ mutableShowingActionProgress.value = application.resources.getString(R.string.saving)
val attachments = selectedMedia
.asSequence()
@@ -308,7 +304,7 @@ class MediaOverviewViewModel(
}
viewModelScope.launch {
- mutableShowingActionProgress.value = application.getString(R.string.MediaOverviewActivity_Media_delete_progress_message)
+ mutableShowingActionProgress.value = application.getString(R.string.deleting)
// Delete the selected media items, and retrieve the thread ID for the address if any
val threadId = withContext(Dispatchers.Default) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/media/MediaPage.kt b/app/src/main/java/org/thoughtcrime/securesms/media/MediaPage.kt
index 49b44b5055..35479ae503 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/media/MediaPage.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/media/MediaPage.kt
@@ -64,7 +64,7 @@ fun MediaPage(
state.isEmpty() -> {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
- text = stringResource(R.string.media_overview_activity__no_media),
+ text = stringResource(R.string.attachmentsMediaEmpty),
style = LocalType.current.base,
color = LocalColors.current.text
)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderFragment.java
index 290d09778a..82d6b93085 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderFragment.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderFragment.java
@@ -1,5 +1,7 @@
package org.thoughtcrime.securesms.mediasend;
+import static org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY;
+
import androidx.appcompat.app.ActionBar;
import androidx.lifecycle.ViewModelProvider;
@@ -20,7 +22,10 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import com.bumptech.glide.Glide;
+import com.squareup.phrase.Phrase;
+
import org.session.libsession.utilities.recipients.Recipient;
+import org.session.libsignal.utilities.Log;
import org.session.libsignal.utilities.guava.Optional;
import network.loki.messenger.R;
@@ -110,11 +115,15 @@ public class MediaPickerFolderFragment extends Fragment implements MediaPickerFo
private void initToolbar(Toolbar toolbar) {
((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
- actionBar.setTitle(getString(R.string.MediaPickerActivity_send_to, recipientName));
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setHomeButtonEnabled(true);
-
- toolbar.setNavigationOnClickListener(v -> requireActivity().onBackPressed());
+ if (actionBar == null) {
+ Log.w("MediaPickerFolderFragment", "ActionBar is null in initToolbar - cannot continue.");
+ } else {
+ CharSequence txt = Phrase.from(requireContext(), R.string.attachmentsSendTo).put(NAME_KEY, recipientName).format();
+ actionBar.setTitle(txt);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setHomeButtonEnabled(true);
+ toolbar.setNavigationOnClickListener(v -> requireActivity().onBackPressed());
+ }
}
private void onScreenWidthChanged(int newWidth) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java
index 8fd7559b4d..b1c104e32e 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java
@@ -163,7 +163,7 @@ public class MediaPickerItemFragment extends Fragment implements MediaPickerItem
@Override
public void onMediaSelectionOverflow(int maxSelection) {
- Toast.makeText(requireContext(), getResources().getQuantityString(R.plurals.MediaSendActivity_cant_share_more_than_n_items, maxSelection, maxSelection), Toast.LENGTH_SHORT).show();
+ Toast.makeText(requireContext(), getString(R.string.attachmentsErrorNumber), Toast.LENGTH_SHORT).show();
}
private void initToolbar(Toolbar toolbar) {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaRepository.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaRepository.java
index a9e7081ef8..f74910f870 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaRepository.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaRepository.java
@@ -94,7 +94,7 @@ class MediaRepository {
Uri allMediaThumbnail = imageFolders.getThumbnailTimestamp() > videoFolders.getThumbnailTimestamp() ? imageFolders.getThumbnail() : videoFolders.getThumbnail();
if (allMediaThumbnail != null) {
int allMediaCount = Stream.of(mediaFolders).reduce(0, (count, folder) -> count + folder.getItemCount());
- mediaFolders.add(0, new MediaFolder(allMediaThumbnail, context.getString(R.string.MediaRepository_all_media), allMediaCount, Media.ALL_MEDIA_BUCKET_ID));
+ mediaFolders.add(0, new MediaFolder(allMediaThumbnail, context.getString(R.string.conversationsSettingsAllMedia), allMediaCount, Media.ALL_MEDIA_BUCKET_ID));
}
return mediaFolders;
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java
index 3e9fd7905e..13783729fc 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java
@@ -1,5 +1,7 @@
package org.thoughtcrime.securesms.mediasend;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
+
import android.Manifest;
import android.content.Context;
import android.content.Intent;
@@ -20,6 +22,8 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
+import com.squareup.phrase.Phrase;
+
import org.session.libsession.utilities.Address;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsession.utilities.Util;
@@ -159,7 +163,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
int maxSelection = viewModel.getMaxSelection();
if (viewModel.getSelectedMedia().getValue() != null && viewModel.getSelectedMedia().getValue().size() >= maxSelection) {
- Toast.makeText(this, getResources().getQuantityString(R.plurals.MediaSendActivity_cant_share_more_than_n_items, maxSelection, maxSelection), Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, getString(R.string.attachmentsErrorNumber), Toast.LENGTH_SHORT).show();
} else {
navigateToCamera();
}
@@ -252,7 +256,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
@Override
public void onCameraError() {
- Toast.makeText(this, R.string.MediaSendActivity_camera_unavailable, Toast.LENGTH_SHORT).show();
+ Toast.makeText(this, R.string.cameraErrorUnavailable, Toast.LENGTH_SHORT).show();
setResult(RESULT_CANCELED, new Intent());
finish();
}
@@ -328,11 +332,12 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
switch (error) {
case ITEM_TOO_LARGE:
- Toast.makeText(this, R.string.MediaSendActivity_an_item_was_removed_because_it_exceeded_the_size_limit, Toast.LENGTH_LONG).show();
+ Toast.makeText(this, R.string.attachmentsErrorSize, Toast.LENGTH_LONG).show();
break;
case TOO_MANY_ITEMS:
- int maxSelection = viewModel.getMaxSelection();
- Toast.makeText(this, getResources().getQuantityString(R.plurals.MediaSendActivity_cant_share_more_than_n_items, maxSelection, maxSelection), Toast.LENGTH_SHORT).show();
+ // In modern session we'll say you can't sent more than 32 items, but if we ever want
+ // the exact count of how many items the user attempted to send it's: viewModel.getMaxSelection()
+ Toast.makeText(this, getString(R.string.attachmentsErrorNumber), Toast.LENGTH_SHORT).show();
break;
}
});
@@ -355,10 +360,19 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
}
private void navigateToCamera() {
+
+ Context c = getApplicationContext();
+ String permanentDenialTxt = Phrase.from(c, R.string.cameraGrantAccessDenied)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+ String requireCameraPermissionsTxt = Phrase.from(c, R.string.cameraGrantAccessDescription)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+
Permissions.with(this)
.request(Manifest.permission.CAMERA)
- .withRationaleDialog(getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera), R.drawable.ic_baseline_photo_camera_48)
- .withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_the_camera_permission_to_take_photos_or_video))
+ .withRationaleDialog(requireCameraPermissionsTxt, R.drawable.ic_baseline_photo_camera_48)
+ .withPermanentDenialDialog(permanentDenialTxt)
.onAllGranted(() -> {
Camera1Fragment fragment = getOrCreateCameraFragment();
getSupportFragmentManager().beginTransaction()
@@ -367,7 +381,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
.addToBackStack(null)
.commit();
})
- .onAnyDenied(() -> Toast.makeText(MediaSendActivity.this, R.string.ConversationActivity_signal_needs_camera_permissions_to_take_photos_or_video, Toast.LENGTH_LONG).show())
+ .onAnyDenied(() -> Toast.makeText(MediaSendActivity.this, requireCameraPermissionsTxt, Toast.LENGTH_LONG).show())
.execute();
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java
index 84722c24c9..169ac83ead 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java
@@ -208,7 +208,7 @@ public class MediaSendFragment extends Fragment implements ViewTreeObserver.OnGl
String displayName = Optional.fromNullable(recipient.getName())
.or(Optional.fromNullable(recipient.getProfileName())
.or(recipient.getAddress().serialize()));
- composeText.setHint(getString(R.string.MediaSendActivity_message_to_s, displayName), null);
+ composeText.setHint(getString(R.string.message, displayName), null);
composeText.setOnEditorActionListener((v, actionId, event) -> {
boolean isSend = actionId == EditorInfo.IME_ACTION_SEND;
if (isSend) sendButton.performClick();
diff --git a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt
index 1fb1f38ce4..2faac58487 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt
@@ -59,7 +59,7 @@ class MessageRequestView : LinearLayout {
private fun getUserDisplayName(recipient: Recipient): String? {
return if (recipient.isLocalNumber) {
- context.getString(R.string.note_to_self)
+ context.getString(R.string.noteToSelf)
} else {
recipient.name // Internally uses the Contact API
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt
index 233222dabb..93f79d2b16 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt
@@ -8,11 +8,14 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
+import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import network.loki.messenger.R
import network.loki.messenger.databinding.ActivityMessageRequestsBinding
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.database.ThreadDatabase
@@ -22,7 +25,6 @@ import com.bumptech.glide.RequestManager
import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.push
-import javax.inject.Inject
@AndroidEntryPoint
class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), ConversationClickListener, LoaderManager.LoaderCallbacks {
@@ -83,10 +85,14 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat
}
showSessionDialog {
- title(R.string.RecipientPreferenceActivity_block_this_contact_question)
- text(R.string.message_requests_block_message)
- button(R.string.recipient_preferences__block) { doBlock() }
- button(R.string.no)
+ title(R.string.block)
+ text(Phrase.from(context, R.string.blockDescription)
+ .put(NAME_KEY, thread.recipient.name)
+ .format())
+ dangerButton(R.string.block, R.string.AccessibilityId_blockConfirm) {
+ doBlock()
+ }
+ button(R.string.no)
}
}
@@ -100,10 +106,10 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat
}
showSessionDialog {
- title(R.string.decline)
- text(resources.getString(R.string.message_requests_decline_message))
- button(R.string.decline) { doDecline() }
- button(R.string.no)
+ title(R.string.delete)
+ text(resources.getString(R.string.messageRequestsDelete))
+ button(R.string.delete) { doDecline() }
+ button(R.string.cancel)
}
}
@@ -123,7 +129,7 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat
}
showSessionDialog {
- text(resources.getString(R.string.message_requests_clear_all_message))
+ text(resources.getString(R.string.messageRequestsClearAllExplanation))
button(R.string.yes) { doDeleteAllAndBlock() }
button(R.string.no)
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java
index 3d45e6a6e7..de3d1c3925 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java
@@ -69,7 +69,7 @@ public class AudioSlide extends Slide {
@NonNull
@Override
public String getContentDescription() {
- return context.getString(R.string.Slide_audio);
+ return context.getString(R.string.audio);
}
@Override
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java
index 87d66743c0..042486dc36 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java
@@ -62,6 +62,6 @@ public class ImageSlide extends Slide {
@NonNull
@Override
public String getContentDescription() {
- return context.getString(R.string.Slide_image);
+ return context.getString(R.string.image);
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.kt b/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.kt
index 05d8167d9a..9b3db2efd3 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.kt
@@ -49,7 +49,7 @@ abstract class Slide(@JvmField protected val context: Context, protected val att
// A missing file name is the legacy way to determine if an audio attachment is
// a voice note vs. other arbitrary audio attachments.
if (attachment.isVoiceNote || attachment.fileName.isNullOrEmpty()) {
- val baseString = context.getString(R.string.attachment_type_voice_message)
+ val baseString = context.getString(R.string.messageVoice)
val languageIsLTR = Util.usingLeftToRightLanguage(context)
val attachmentString = if (languageIsLTR) {
"🎙 $baseString"
diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java
index 1017ad1107..8bd3afb4fd 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java
@@ -70,6 +70,6 @@ public class VideoSlide extends Slide {
@NonNull @Override
public String getContentDescription() {
- return context.getString(R.string.Slide_video);
+ return context.getString(R.string.video);
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java
index d67ad47832..2e2440d6a2 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/AbstractNotificationBuilder.java
@@ -72,9 +72,9 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui
if (privacy.isDisplayMessage()) {
setTicker(getStyledMessage(recipient, trimToDisplayLength(message)));
} else if (privacy.isDisplayContact()) {
- setTicker(getStyledMessage(recipient, context.getString(R.string.AbstractNotificationBuilder_new_message)));
+ setTicker(getStyledMessage(recipient, context.getResources().getQuantityString(R.plurals.messageNew, 1, 1)));
} else {
- setTicker(context.getString(R.string.AbstractNotificationBuilder_new_message));
+ setTicker(context.getResources().getQuantityString(R.plurals.messageNew, 1, 1));
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java
deleted file mode 100644
index e80c47a9f6..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java
+++ /dev/null
@@ -1,727 +0,0 @@
-/*
- * Copyright (C) 2011 Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.thoughtcrime.securesms.notifications;
-
-import android.annotation.SuppressLint;
-import android.app.AlarmManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Build;
-import android.service.notification.StatusBarNotification;
-import android.text.SpannableString;
-import android.text.TextUtils;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.core.app.NotificationCompat;
-import androidx.core.app.NotificationManagerCompat;
-
-import com.annimon.stream.Optional;
-import com.annimon.stream.Stream;
-import com.goterl.lazysodium.utils.KeyPair;
-
-import org.session.libsession.messaging.open_groups.OpenGroup;
-import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier;
-import org.session.libsession.messaging.utilities.AccountId;
-import org.session.libsession.messaging.utilities.SodiumUtilities;
-import org.session.libsession.snode.SnodeAPI;
-import org.session.libsession.utilities.Address;
-import org.session.libsession.utilities.Contact;
-import org.session.libsession.utilities.ServiceUtil;
-import org.session.libsession.utilities.TextSecurePreferences;
-import org.session.libsession.utilities.recipients.Recipient;
-import org.session.libsignal.utilities.IdPrefix;
-import org.session.libsignal.utilities.Log;
-import org.session.libsignal.utilities.Util;
-import org.thoughtcrime.securesms.ApplicationContext;
-import org.thoughtcrime.securesms.contacts.ContactUtil;
-import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2;
-import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities;
-import org.thoughtcrime.securesms.crypto.KeyPairUtilities;
-import org.thoughtcrime.securesms.database.LokiThreadDatabase;
-import org.thoughtcrime.securesms.database.MmsSmsDatabase;
-import org.thoughtcrime.securesms.database.RecipientDatabase;
-import org.thoughtcrime.securesms.database.ThreadDatabase;
-import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
-import org.thoughtcrime.securesms.database.model.MessageRecord;
-import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
-import org.thoughtcrime.securesms.database.model.Quote;
-import org.thoughtcrime.securesms.database.model.ReactionRecord;
-import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
-import org.thoughtcrime.securesms.mms.SlideDeck;
-import org.thoughtcrime.securesms.service.KeyCachingService;
-import org.thoughtcrime.securesms.util.SessionMetaProtocol;
-import org.thoughtcrime.securesms.util.SpanUtil;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import me.leolin.shortcutbadger.ShortcutBadger;
-import network.loki.messenger.R;
-
-/**
- * Handles posting system notifications for new messages.
- *
- *
- * @author Moxie Marlinspike
- */
-
-public class DefaultMessageNotifier implements MessageNotifier {
-
- private static final String TAG = DefaultMessageNotifier.class.getSimpleName();
-
- public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply";
- public static final String LATEST_MESSAGE_ID_TAG = "extra_latest_message_id";
-
- private static final int FOREGROUND_ID = 313399;
- private static final int SUMMARY_NOTIFICATION_ID = 1338;
- private static final int PENDING_MESSAGES_ID = 1111;
- private static final String NOTIFICATION_GROUP = "messages";
- private static final long MIN_AUDIBLE_PERIOD_MILLIS = TimeUnit.SECONDS.toMillis(5);
- private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1);
-
- private volatile static long visibleThread = -1;
- private volatile static boolean homeScreenVisible = false;
- private volatile static long lastDesktopActivityTimestamp = -1;
- private volatile static long lastAudibleNotification = -1;
- private static final CancelableExecutor executor = new CancelableExecutor();
-
- @Override
- public void setVisibleThread(long threadId) {
- visibleThread = threadId;
- }
-
- @Override
- public void setHomeScreenVisible(boolean isVisible) {
- homeScreenVisible = isVisible;
- }
-
- @Override
- public void setLastDesktopActivityTimestamp(long timestamp) {
- lastDesktopActivityTimestamp = timestamp;
- }
-
- @Override
- public void notifyMessageDeliveryFailed(Context context, Recipient recipient, long threadId) {
- if (visibleThread != threadId) {
- Intent intent = new Intent(context, ConversationActivityV2.class);
- intent.putExtra(ConversationActivityV2.ADDRESS, recipient.getAddress());
- intent.putExtra(ConversationActivityV2.THREAD_ID, threadId);
- intent.setData((Uri.parse("custom://" + SnodeAPI.getNowWithOffset())));
-
- FailedNotificationBuilder builder = new FailedNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context), intent);
- ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
- .notify((int)threadId, builder.build());
- }
- }
-
- public void notifyMessagesPending(Context context) {
-
- if (!TextSecurePreferences.isNotificationsEnabled(context)) { return; }
-
- PendingMessageNotificationBuilder builder = new PendingMessageNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context));
- ServiceUtil.getNotificationManager(context).notify(PENDING_MESSAGES_ID, builder.build());
- }
-
- @Override
- public void cancelDelayedNotifications() {
- executor.cancel();
- }
-
- private boolean cancelActiveNotifications(@NonNull Context context) {
- NotificationManager notifications = ServiceUtil.getNotificationManager(context);
- boolean hasNotifications = notifications.getActiveNotifications().length > 0;
- notifications.cancel(SUMMARY_NOTIFICATION_ID);
-
- try {
- StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
-
- for (StatusBarNotification activeNotification : activeNotifications) {
- notifications.cancel(activeNotification.getId());
- }
- } catch (Throwable e) {
- // XXX Appears to be a ROM bug, see #6043
- Log.w(TAG, e);
- notifications.cancelAll();
- }
- return hasNotifications;
- }
-
- private void cancelOrphanedNotifications(@NonNull Context context, NotificationState notificationState) {
- try {
- NotificationManager notifications = ServiceUtil.getNotificationManager(context);
- StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
-
- for (StatusBarNotification notification : activeNotifications) {
- boolean validNotification = false;
-
- if (notification.getId() != SUMMARY_NOTIFICATION_ID &&
- notification.getId() != KeyCachingService.SERVICE_RUNNING_ID &&
- notification.getId() != FOREGROUND_ID &&
- notification.getId() != PENDING_MESSAGES_ID)
- {
- for (NotificationItem item : notificationState.getNotifications()) {
- if (notification.getId() == (SUMMARY_NOTIFICATION_ID + item.getThreadId())) {
- validNotification = true;
- break;
- }
- }
-
- if (!validNotification) { notifications.cancel(notification.getId()); }
- }
- }
- } catch (Throwable e) {
- // XXX Android ROM Bug, see #6043
- Log.w(TAG, e);
- }
- }
-
- @Override
- public void updateNotification(@NonNull Context context) {
- if (!TextSecurePreferences.isNotificationsEnabled(context)) {
- return;
- }
-
- updateNotification(context, false, 0);
- }
-
- @Override
- public void updateNotification(@NonNull Context context, long threadId)
- {
- if (System.currentTimeMillis() - lastDesktopActivityTimestamp < DESKTOP_ACTIVITY_PERIOD) {
- Log.i(TAG, "Scheduling delayed notification...");
- executor.execute(new DelayedNotification(context, threadId));
- } else {
- updateNotification(context, threadId, true);
- }
- }
-
- @Override
- public void updateNotification(@NonNull Context context, long threadId, boolean signal)
- {
- boolean isVisible = visibleThread == threadId;
-
- ThreadDatabase threads = DatabaseComponent.get(context).threadDatabase();
- Recipient recipient = threads.getRecipientForThreadId(threadId);
-
- if (recipient != null && !recipient.isGroupRecipient() && threads.getMessageCount(threadId) == 1 &&
- !(recipient.isApproved() || threads.getLastSeenAndHasSent(threadId).second())) {
- TextSecurePreferences.removeHasHiddenMessageRequests(context);
- }
-
- if (!TextSecurePreferences.isNotificationsEnabled(context) ||
- (recipient != null && recipient.isMuted()))
- {
- return;
- }
-
- if ((!isVisible && !homeScreenVisible) || hasExistingNotifications(context)) {
- updateNotification(context, signal, 0);
- }
- }
-
- private boolean hasExistingNotifications(Context context) {
- NotificationManager notifications = ServiceUtil.getNotificationManager(context);
- try {
- StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
- return activeNotifications.length > 0;
- } catch (Exception e) {
- return false;
- }
- }
-
- @Override
- public void updateNotification(@NonNull Context context, boolean signal, int reminderCount)
- {
- Cursor telcoCursor = null;
- Cursor pushCursor = null;
-
- try {
- telcoCursor = DatabaseComponent.get(context).mmsSmsDatabase().getUnread(); // TODO: add a notification specific lighter query here
-
- if ((telcoCursor == null || telcoCursor.isAfterLast()) || TextSecurePreferences.getLocalNumber(context) == null)
- {
- updateBadge(context, 0);
- cancelActiveNotifications(context);
- clearReminder(context);
- return;
- }
-
- NotificationState notificationState = constructNotificationState(context, telcoCursor);
-
- if (signal && (System.currentTimeMillis() - lastAudibleNotification) < MIN_AUDIBLE_PERIOD_MILLIS) {
- signal = false;
- } else if (signal) {
- lastAudibleNotification = System.currentTimeMillis();
- }
-
- try {
- if (notificationState.hasMultipleThreads()) {
- for (long threadId : notificationState.getThreads()) {
- sendSingleThreadNotification(context, new NotificationState(notificationState.getNotificationsForThread(threadId)), false, true);
- }
- sendMultipleThreadNotification(context, notificationState, signal);
- } else if (notificationState.getMessageCount() > 0) {
- sendSingleThreadNotification(context, notificationState, signal, false);
- } else {
- cancelActiveNotifications(context);
- }
- } catch (Exception e) {
- Log.e(TAG, "Error creating notification", e);
- }
- cancelOrphanedNotifications(context, notificationState);
- updateBadge(context, notificationState.getMessageCount());
-
- if (signal) {
- scheduleReminder(context, reminderCount);
- }
- } finally {
- if (telcoCursor != null) telcoCursor.close();
- }
- }
-
- private void sendSingleThreadNotification(@NonNull Context context,
- @NonNull NotificationState notificationState,
- boolean signal, boolean bundled)
- {
- Log.i(TAG, "sendSingleThreadNotification() signal: " + signal + " bundled: " + bundled);
-
- if (notificationState.getNotifications().isEmpty()) {
- if (!bundled) cancelActiveNotifications(context);
- Log.i(TAG, "Empty notification state. Skipping.");
- return;
- }
-
- SingleRecipientNotificationBuilder builder = new SingleRecipientNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context));
- List notifications = notificationState.getNotifications();
- Recipient recipient = notifications.get(0).getRecipient();
- int notificationId = (int) (SUMMARY_NOTIFICATION_ID + (bundled ? notifications.get(0).getThreadId() : 0));
- String messageIdTag = String.valueOf(notifications.get(0).getTimestamp());
-
- NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
- for (StatusBarNotification notification: notificationManager.getActiveNotifications()) {
- if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && notification.isAppGroup() == bundled)
- && messageIdTag.equals(notification.getNotification().extras.getString(LATEST_MESSAGE_ID_TAG))) {
- return;
- }
- }
-
- long timestamp = notifications.get(0).getTimestamp();
- if (timestamp != 0) builder.setWhen(timestamp);
-
- builder.putStringExtra(LATEST_MESSAGE_ID_TAG, messageIdTag);
-
- CharSequence text = notifications.get(0).getText();
-
- builder.setThread(notifications.get(0).getRecipient());
- builder.setMessageCount(notificationState.getMessageCount());
-
- CharSequence builderCS = text == null ? "" : text;
- SpannableString ss = MentionUtilities.highlightMentions(
- builderCS,
- false,
- false,
- true,
- bundled ? notifications.get(0).getThreadId() : 0,
- context
- );
-
- builder.setPrimaryMessageBody(recipient,
- notifications.get(0).getIndividualRecipient(),
- ss,
- notifications.get(0).getSlideDeck());
-
- builder.setContentIntent(notifications.get(0).getPendingIntent(context));
- builder.setDeleteIntent(notificationState.getDeleteIntent(context));
- builder.setOnlyAlertOnce(!signal);
- builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
- builder.setAutoCancel(true);
-
- ReplyMethod replyMethod = ReplyMethod.forRecipient(context, recipient);
-
- boolean canReply = SessionMetaProtocol.canUserReplyToNotification(recipient);
-
- PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, recipient) : null;
- PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, recipient, replyMethod) : null;
-
- builder.addActions(notificationState.getMarkAsReadIntent(context, notificationId),
- quickReplyIntent,
- remoteReplyIntent,
- replyMethod);
-
- if (canReply) {
- builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, recipient),
- notificationState.getAndroidAutoHeardIntent(context, notificationId),
- notifications.get(0).getTimestamp());
- }
-
- ListIterator iterator = notifications.listIterator(notifications.size());
-
- while(iterator.hasPrevious()) {
- NotificationItem item = iterator.previous();
- builder.addMessageBody(item.getRecipient(), item.getIndividualRecipient(), item.getText());
- }
-
- if (signal) {
- builder.setAlarms(notificationState.getRingtone(context), notificationState.getVibrate());
- builder.setTicker(notifications.get(0).getIndividualRecipient(),
- notifications.get(0).getText());
- }
-
- if (bundled) {
- builder.setGroup(NOTIFICATION_GROUP);
- builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
- }
-
- Notification notification = builder.build();
- NotificationManagerCompat.from(context).notify(notificationId, notification);
- Log.i(TAG, "Posted notification. " + notification.toString());
- }
-
- private void sendMultipleThreadNotification(@NonNull Context context,
- @NonNull NotificationState notificationState,
- boolean signal)
- {
- Log.i(TAG, "sendMultiThreadNotification() signal: " + signal);
-
- MultipleRecipientNotificationBuilder builder = new MultipleRecipientNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context));
- List notifications = notificationState.getNotifications();
-
- builder.setMessageCount(notificationState.getMessageCount(), notificationState.getThreadCount());
- builder.setMostRecentSender(notifications.get(0).getIndividualRecipient(), notifications.get(0).getRecipient());
- builder.setGroup(NOTIFICATION_GROUP);
- builder.setDeleteIntent(notificationState.getDeleteIntent(context));
- builder.setOnlyAlertOnce(!signal);
- builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
- builder.setAutoCancel(true);
-
- String messageIdTag = String.valueOf(notifications.get(0).getTimestamp());
-
- NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
- for (StatusBarNotification notification: notificationManager.getActiveNotifications()) {
- if (notification.getId() == SUMMARY_NOTIFICATION_ID
- && messageIdTag.equals(notification.getNotification().extras.getString(LATEST_MESSAGE_ID_TAG))) {
- return;
- }
- }
-
- long timestamp = notifications.get(0).getTimestamp();
- if (timestamp != 0) builder.setWhen(timestamp);
-
- builder.addActions(notificationState.getMarkAsReadIntent(context, SUMMARY_NOTIFICATION_ID));
-
- ListIterator iterator = notifications.listIterator(notifications.size());
-
- while(iterator.hasPrevious()) {
- NotificationItem item = iterator.previous();
- builder.addMessageBody(item.getIndividualRecipient(), item.getRecipient(),
- MentionUtilities.highlightMentions(
- item.getText() != null ? item.getText() : "",
- false,
- false,
- true, // no styling here, only text formatting
- item.getThreadId(),
- context
- )
- );
- }
-
- if (signal) {
- builder.setAlarms(notificationState.getRingtone(context), notificationState.getVibrate());
- CharSequence text = notifications.get(0).getText();
- builder.setTicker(notifications.get(0).getIndividualRecipient(),
- MentionUtilities.highlightMentions(
- text != null ? text : "",
- false,
- false,
- true, // no styling here, only text formatting
- notifications.get(0).getThreadId(),
- context
- )
- );
- }
-
- builder.putStringExtra(LATEST_MESSAGE_ID_TAG, messageIdTag);
-
- Notification notification = builder.build();
- NotificationManagerCompat.from(context).notify(SUMMARY_NOTIFICATION_ID, notification);
- Log.i(TAG, "Posted notification. " + notification);
- }
-
- private NotificationState constructNotificationState(@NonNull Context context,
- @NonNull Cursor cursor)
- {
- NotificationState notificationState = new NotificationState();
- MmsSmsDatabase.Reader reader = DatabaseComponent.get(context).mmsSmsDatabase().readerFor(cursor);
- ThreadDatabase threadDatabase = DatabaseComponent.get(context).threadDatabase();
-
- MessageRecord record;
- Map cache = new HashMap();
-
- while ((record = reader.getNext()) != null) {
- long id = record.getId();
- boolean mms = record.isMms() || record.isMmsNotification();
- Recipient recipient = record.getIndividualRecipient();
- Recipient conversationRecipient = record.getRecipient();
- long threadId = record.getThreadId();
- CharSequence body = record.getDisplayBody(context);
- Recipient threadRecipients = null;
- SlideDeck slideDeck = null;
- long timestamp = record.getTimestamp();
- boolean messageRequest = false;
-
- if (threadId != -1) {
- threadRecipients = threadDatabase.getRecipientForThreadId(threadId);
- messageRequest = threadRecipients != null && !threadRecipients.isGroupRecipient() &&
- !threadRecipients.isApproved() && !threadDatabase.getLastSeenAndHasSent(threadId).second();
- if (messageRequest && (threadDatabase.getMessageCount(threadId) > 1 || !TextSecurePreferences.hasHiddenMessageRequests(context))) {
- continue;
- }
- }
-
- // If this is a message request from an unknown user..
- if (messageRequest) {
- body = SpanUtil.italic(context.getString(R.string.message_requests_notification));
-
- // If we received some manner of notification but Session is locked..
- } else if (KeyCachingService.isLocked(context)) {
- body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
-
- // ----- All further cases assume we know the contact and that Session isn't locked -----
-
- // If this is a notification about a multimedia message from a contact we know about..
- } else if (record.isMms() && !((MmsMessageRecord) record).getSharedContacts().isEmpty()) {
- Contact contact = ((MmsMessageRecord) record).getSharedContacts().get(0);
- body = ContactUtil.getStringSummary(context, contact);
-
- // If this is a notification about a multimedia message which contains no text but DOES contain a slide deck with at least one slide..
- } else if (record.isMms() && TextUtils.isEmpty(body) && !((MmsMessageRecord) record).getSlideDeck().getSlides().isEmpty()) {
- slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
- body = SpanUtil.italic(slideDeck.getBody());
-
- // If this is a notification about a multimedia message, but it's not ITSELF a multimedia notification AND it contains a slide deck with at least one slide..
- } else if (record.isMms() && !record.isMmsNotification() && !((MmsMessageRecord) record).getSlideDeck().getSlides().isEmpty()) {
- slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
- String message = slideDeck.getBody() + ": " + record.getBody();
- int italicLength = message.length() - body.length();
- body = SpanUtil.italic(message, italicLength);
-
- // If this is a notification about an invitation to a community..
- } else if (record.isOpenGroupInvitation()) {
- body = SpanUtil.italic(context.getString(R.string.ThreadRecord_open_group_invitation));
- }
-
- String userPublicKey = TextSecurePreferences.getLocalNumber(context);
- String blindedPublicKey = cache.get(threadId);
- if (blindedPublicKey == null) {
- blindedPublicKey = generateBlindedId(threadId, context);
- cache.put(threadId, blindedPublicKey);
- }
- if (threadRecipients == null || !threadRecipients.isMuted()) {
- if (threadRecipients != null && threadRecipients.notifyType == RecipientDatabase.NOTIFY_TYPE_MENTIONS) {
- // check if mentioned here
- boolean isQuoteMentioned = false;
- if (record instanceof MmsMessageRecord) {
- Quote quote = ((MmsMessageRecord) record).getQuote();
- Address quoteAddress = quote != null ? quote.getAuthor() : null;
- String serializedAddress = quoteAddress != null ? quoteAddress.serialize() : null;
- isQuoteMentioned = (serializedAddress!= null && Objects.equals(userPublicKey, serializedAddress)) ||
- (blindedPublicKey != null && Objects.equals(userPublicKey, blindedPublicKey));
- }
- if (body.toString().contains("@"+userPublicKey) || body.toString().contains("@"+blindedPublicKey) || isQuoteMentioned) {
- notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, slideDeck));
- }
- } else if (threadRecipients != null && threadRecipients.notifyType == RecipientDatabase.NOTIFY_TYPE_NONE) {
- // do nothing, no notifications
- } else {
- notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, slideDeck));
- }
-
- String userBlindedPublicKey = blindedPublicKey;
- Optional lastReact = Stream.of(record.getReactions())
- .filter(r -> !(r.getAuthor().equals(userPublicKey) || r.getAuthor().equals(userBlindedPublicKey)))
- .findLast();
-
- if (lastReact.isPresent()) {
- if (threadRecipients != null && !threadRecipients.isGroupRecipient()) {
- ReactionRecord reaction = lastReact.get();
- Recipient reactor = Recipient.from(context, Address.fromSerialized(reaction.getAuthor()), false);
- String emoji = context.getString(R.string.reaction_notification, reactor.toShortString(), reaction.getEmoji());
- notificationState.addNotification(new NotificationItem(id, mms, reactor, reactor, threadRecipients, threadId, emoji, reaction.getDateSent(), slideDeck));
- }
- }
- }
- }
-
- reader.close();
- return notificationState;
- }
-
- private @Nullable String generateBlindedId(long threadId, Context context) {
- LokiThreadDatabase lokiThreadDatabase = DatabaseComponent.get(context).lokiThreadDatabase();
- OpenGroup openGroup = lokiThreadDatabase.getOpenGroupChat(threadId);
- KeyPair edKeyPair = KeyPairUtilities.INSTANCE.getUserED25519KeyPair(context);
- if (openGroup != null && edKeyPair != null) {
- KeyPair blindedKeyPair = SodiumUtilities.blindedKeyPair(openGroup.getPublicKey(), edKeyPair);
- if (blindedKeyPair != null) {
- return new AccountId(IdPrefix.BLINDED, blindedKeyPair.getPublicKey().getAsBytes()).getHexString();
- }
- }
- return null;
- }
-
- private void updateBadge(Context context, int count) {
- try {
- if (count == 0) ShortcutBadger.removeCount(context);
- else ShortcutBadger.applyCount(context, count);
- } catch (Throwable t) {
- // NOTE :: I don't totally trust this thing, so I'm catching
- // everything.
- Log.w("MessageNotifier", t);
- }
- }
-
- private void scheduleReminder(Context context, int count) {
- if (count >= TextSecurePreferences.getRepeatAlertsCount(context)) {
- return;
- }
-
- AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
- alarmIntent.putExtra("reminder_count", count);
-
- PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
- long timeout = TimeUnit.MINUTES.toMillis(2);
-
- alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
- }
-
- @Override
- public void clearReminder(Context context) {
- Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
- PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
- AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- alarmManager.cancel(pendingIntent);
- }
-
- public static class ReminderReceiver extends BroadcastReceiver {
-
- public static final String REMINDER_ACTION = "network.loki.securesms.MessageNotifier.REMINDER_ACTION";
-
- @SuppressLint("StaticFieldLeak")
- @Override
- public void onReceive(final Context context, final Intent intent) {
- new AsyncTask() {
- @Override
- protected Void doInBackground(Void... params) {
- int reminderCount = intent.getIntExtra("reminder_count", 0);
- ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, true, reminderCount + 1);
-
- return null;
- }
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- }
- }
-
- private static class DelayedNotification implements Runnable {
-
- private static final long DELAY = TimeUnit.SECONDS.toMillis(5);
-
- private final AtomicBoolean canceled = new AtomicBoolean(false);
-
- private final Context context;
- private final long threadId;
- private final long delayUntil;
-
- private DelayedNotification(Context context, long threadId) {
- this.context = context;
- this.threadId = threadId;
- this.delayUntil = System.currentTimeMillis() + DELAY;
- }
-
- @Override
- public void run() {
- long delayMillis = delayUntil - System.currentTimeMillis();
- Log.i(TAG, "Waiting to notify: " + delayMillis);
-
- if (delayMillis > 0) {
- Util.sleep(delayMillis);
- }
-
- if (!canceled.get()) {
- Log.i(TAG, "Not canceled, notifying...");
- ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, threadId, true);
- ApplicationContext.getInstance(context).messageNotifier.cancelDelayedNotifications();
- } else {
- Log.w(TAG, "Canceled, not notifying...");
- }
- }
-
- public void cancel() {
- canceled.set(true);
- }
- }
-
- private static class CancelableExecutor {
-
- private final Executor executor = Executors.newSingleThreadExecutor();
- private final Set tasks = new HashSet<>();
-
- public void execute(final DelayedNotification runnable) {
- synchronized (tasks) {
- tasks.add(runnable);
- }
-
- Runnable wrapper = new Runnable() {
- @Override
- public void run() {
- runnable.run();
-
- synchronized (tasks) {
- tasks.remove(runnable);
- }
- }
- };
-
- executor.execute(wrapper);
- }
-
- public void cancel() {
- synchronized (tasks) {
- for (DelayedNotification task : tasks) {
- task.cancel();
- }
- }
- }
- }
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt
new file mode 100644
index 0000000000..cbf53e6a8b
--- /dev/null
+++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.kt
@@ -0,0 +1,725 @@
+/*
+ * Copyright (C) 2011 Whisper Systems
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.thoughtcrime.securesms.notifications
+
+import android.Manifest
+import android.annotation.SuppressLint
+import android.app.AlarmManager
+import android.app.PendingIntent
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.content.pm.PackageManager
+import android.database.Cursor
+import android.os.AsyncTask
+import android.os.Build
+import android.text.TextUtils
+import android.widget.Toast
+import androidx.camera.core.impl.utils.ContextUtil.getApplicationContext
+import androidx.core.app.ActivityCompat
+import androidx.core.app.NotificationCompat
+import androidx.core.app.NotificationManagerCompat
+import com.annimon.stream.Stream
+import com.squareup.phrase.Phrase
+import java.util.concurrent.Executor
+import java.util.concurrent.Executors
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicBoolean
+import kotlin.concurrent.Volatile
+import me.leolin.shortcutbadger.ShortcutBadger
+import network.loki.messenger.R
+import org.session.libsession.messaging.sending_receiving.notifications.MessageNotifier
+import org.session.libsession.messaging.utilities.AccountId
+import org.session.libsession.messaging.utilities.SodiumUtilities.blindedKeyPair
+import org.session.libsession.utilities.Address.Companion.fromSerialized
+import org.session.libsession.utilities.ServiceUtil
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.EMOJI_KEY
+import org.session.libsession.utilities.TextSecurePreferences.Companion.getLocalNumber
+import org.session.libsession.utilities.TextSecurePreferences.Companion.getNotificationPrivacy
+import org.session.libsession.utilities.TextSecurePreferences.Companion.getRepeatAlertsCount
+import org.session.libsession.utilities.TextSecurePreferences.Companion.hasHiddenMessageRequests
+import org.session.libsession.utilities.TextSecurePreferences.Companion.isNotificationsEnabled
+import org.session.libsession.utilities.TextSecurePreferences.Companion.removeHasHiddenMessageRequests
+import org.session.libsession.utilities.recipients.Recipient
+import org.session.libsignal.utilities.IdPrefix
+import org.session.libsignal.utilities.Log
+import org.session.libsignal.utilities.Util
+import org.thoughtcrime.securesms.ApplicationContext
+import org.thoughtcrime.securesms.contacts.ContactUtil
+import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities.highlightMentions
+import org.thoughtcrime.securesms.crypto.KeyPairUtilities.getUserED25519KeyPair
+import org.thoughtcrime.securesms.database.RecipientDatabase
+import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord
+import org.thoughtcrime.securesms.database.model.MessageRecord
+import org.thoughtcrime.securesms.database.model.MmsMessageRecord
+import org.thoughtcrime.securesms.database.model.ReactionRecord
+import org.thoughtcrime.securesms.dependencies.DatabaseComponent.Companion.get
+import org.thoughtcrime.securesms.mms.SlideDeck
+import org.thoughtcrime.securesms.permissions.Permissions
+import org.thoughtcrime.securesms.preferences.ShareLogsDialog
+import org.thoughtcrime.securesms.service.KeyCachingService
+import org.thoughtcrime.securesms.util.SessionMetaProtocol.canUserReplyToNotification
+import org.thoughtcrime.securesms.util.SpanUtil
+
+/**
+ * Handles posting system notifications for new messages.
+ *
+ *
+ * @author Moxie Marlinspike
+ */
+class DefaultMessageNotifier : MessageNotifier {
+ override fun setVisibleThread(threadId: Long) {
+ visibleThread = threadId
+ }
+
+ override fun setHomeScreenVisible(isVisible: Boolean) {
+ homeScreenVisible = isVisible
+ }
+
+ override fun setLastDesktopActivityTimestamp(timestamp: Long) {
+ lastDesktopActivityTimestamp = timestamp
+ }
+
+ override fun notifyMessageDeliveryFailed(context: Context?, recipient: Recipient?, threadId: Long) {
+ // We do not provide notifications for message delivery failure.
+ }
+
+ override fun cancelDelayedNotifications() {
+ executor.cancel()
+ }
+
+ private fun cancelActiveNotifications(context: Context): Boolean {
+ val notifications = ServiceUtil.getNotificationManager(context)
+ val hasNotifications = notifications.activeNotifications.size > 0
+ notifications.cancel(SUMMARY_NOTIFICATION_ID)
+
+ try {
+ val activeNotifications = notifications.activeNotifications
+
+ for (activeNotification in activeNotifications) {
+ notifications.cancel(activeNotification.id)
+ }
+ } catch (e: Throwable) {
+ // XXX Appears to be a ROM bug, see #6043
+ Log.w(TAG, e)
+ notifications.cancelAll()
+ }
+ return hasNotifications
+ }
+
+ private fun cancelOrphanedNotifications(context: Context, notificationState: NotificationState) {
+ try {
+ val notifications = ServiceUtil.getNotificationManager(context)
+ val activeNotifications = notifications.activeNotifications
+
+ for (notification in activeNotifications) {
+ var validNotification = false
+
+ if (notification.id != SUMMARY_NOTIFICATION_ID && notification.id != KeyCachingService.SERVICE_RUNNING_ID && notification.id != FOREGROUND_ID && notification.id != PENDING_MESSAGES_ID) {
+ for (item in notificationState.notifications) {
+ if (notification.id.toLong() == (SUMMARY_NOTIFICATION_ID + item.threadId)) {
+ validNotification = true
+ break
+ }
+ }
+
+ if (!validNotification) {
+ notifications.cancel(notification.id)
+ }
+ }
+ }
+ } catch (e: Throwable) {
+ // XXX Android ROM Bug, see #6043
+ Log.w(TAG, e)
+ }
+ }
+
+ override fun updateNotification(context: Context) {
+ if (!isNotificationsEnabled(context)) {
+ return
+ }
+
+ updateNotification(context, false, 0)
+ }
+
+ override fun updateNotification(context: Context, threadId: Long) {
+ if (System.currentTimeMillis() - lastDesktopActivityTimestamp < DESKTOP_ACTIVITY_PERIOD) {
+ Log.i(TAG, "Scheduling delayed notification...")
+ executor.execute(DelayedNotification(context, threadId))
+ } else {
+ updateNotification(context, threadId, true)
+ }
+ }
+
+ override fun updateNotification(context: Context, threadId: Long, signal: Boolean) {
+ val isVisible = visibleThread == threadId
+
+ val threads = get(context).threadDatabase()
+ val recipient = threads.getRecipientForThreadId(threadId)
+
+ if (recipient != null && !recipient.isGroupRecipient && threads.getMessageCount(threadId) == 1 &&
+ !(recipient.isApproved || threads.getLastSeenAndHasSent(threadId).second())
+ ) {
+ removeHasHiddenMessageRequests(context)
+ }
+
+ if (!isNotificationsEnabled(context) ||
+ (recipient != null && recipient.isMuted)
+ ) {
+ return
+ }
+
+ if ((!isVisible && !homeScreenVisible) || hasExistingNotifications(context)) {
+ updateNotification(context, signal, 0)
+ }
+ }
+
+ private fun hasExistingNotifications(context: Context): Boolean {
+ val notifications = ServiceUtil.getNotificationManager(context)
+ try {
+ val activeNotifications = notifications.activeNotifications
+ return activeNotifications.isNotEmpty()
+ } catch (e: Exception) {
+ return false
+ }
+ }
+
+ override fun updateNotification(context: Context, signal: Boolean, reminderCount: Int) {
+ var playNotificationAudio = signal // Local copy of the argument so we can modify it
+ var telcoCursor: Cursor? = null
+ val pushCursor: Cursor? = null
+
+ try {
+ telcoCursor = get(context).mmsSmsDatabase().unread // TODO: add a notification specific lighter query here
+
+ if ((telcoCursor == null || telcoCursor.isAfterLast) || getLocalNumber(context) == null) {
+ updateBadge(context, 0)
+ cancelActiveNotifications(context)
+ clearReminder(context)
+ return
+ }
+
+ try {
+ val notificationState = constructNotificationState(context, telcoCursor)
+
+ if (playNotificationAudio && (System.currentTimeMillis() - lastAudibleNotification) < MIN_AUDIBLE_PERIOD_MILLIS) {
+ playNotificationAudio = false
+ } else if (playNotificationAudio) {
+ lastAudibleNotification = System.currentTimeMillis()
+ }
+
+ if (notificationState.hasMultipleThreads()) {
+ for (threadId in notificationState.threads) {
+ sendSingleThreadNotification(context, NotificationState(notificationState.getNotificationsForThread(threadId)), false, true)
+ }
+ sendMultipleThreadNotification(context, notificationState, playNotificationAudio)
+ } else if (notificationState.messageCount > 0) {
+ sendSingleThreadNotification(context, notificationState, playNotificationAudio, false)
+ } else {
+ cancelActiveNotifications(context)
+ }
+
+ cancelOrphanedNotifications(context, notificationState)
+ updateBadge(context, notificationState.messageCount)
+
+ if (playNotificationAudio) {
+ scheduleReminder(context, reminderCount)
+ }
+ }
+ catch (e: Exception) {
+ Log.e(TAG, "Error creating notification", e)
+ }
+
+ } finally {
+ telcoCursor?.close()
+ }
+ }
+
+ // Note: The `signal` parameter means "play an audio signal for the notification".
+ private fun sendSingleThreadNotification(
+ context: Context,
+ notificationState: NotificationState,
+ signal: Boolean,
+ bundled: Boolean
+ ) {
+ Log.i(TAG, "sendSingleThreadNotification() signal: $signal bundled: $bundled")
+
+ if (notificationState.notifications.isEmpty()) {
+ if (!bundled) cancelActiveNotifications(context)
+ Log.i(TAG, "Empty notification state. Skipping.")
+ return
+ }
+
+ val builder = SingleRecipientNotificationBuilder(context, getNotificationPrivacy(context))
+ val notifications = notificationState.notifications
+ val recipient = notifications[0].recipient
+ val notificationId = (SUMMARY_NOTIFICATION_ID + (if (bundled) notifications[0].threadId else 0)).toInt()
+ val messageIdTag = notifications[0].timestamp.toString()
+
+ val notificationManager = ServiceUtil.getNotificationManager(context)
+ for (notification in notificationManager.activeNotifications) {
+ if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && notification.isAppGroup == bundled)
+ && (messageIdTag == notification.notification.extras.getString(LATEST_MESSAGE_ID_TAG))
+ ) {
+ return
+ }
+ }
+
+ val timestamp = notifications[0].timestamp
+ if (timestamp != 0L) builder.setWhen(timestamp)
+
+ builder.putStringExtra(LATEST_MESSAGE_ID_TAG, messageIdTag)
+
+ val text = notifications[0].text
+
+ builder.setThread(notifications[0].recipient)
+ builder.setMessageCount(notificationState.messageCount)
+
+ val builderCS = text ?: ""
+ val ss = highlightMentions(
+ builderCS,
+ false,
+ false,
+ true,
+ if (bundled) notifications[0].threadId else 0,
+ context
+ )
+
+ builder.setPrimaryMessageBody(
+ recipient,
+ notifications[0].individualRecipient,
+ ss,
+ notifications[0].slideDeck
+ )
+
+ builder.setContentIntent(notifications[0].getPendingIntent(context))
+ builder.setDeleteIntent(notificationState.getDeleteIntent(context))
+ builder.setOnlyAlertOnce(!signal)
+ builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
+ builder.setAutoCancel(true)
+
+ val replyMethod = ReplyMethod.forRecipient(context, recipient)
+
+ val canReply = canUserReplyToNotification(recipient)
+
+ val quickReplyIntent = if (canReply) notificationState.getQuickReplyIntent(context, recipient) else null
+ val remoteReplyIntent = if (canReply) notificationState.getRemoteReplyIntent(context, recipient, replyMethod) else null
+
+ builder.addActions(
+ notificationState.getMarkAsReadIntent(context, notificationId),
+ quickReplyIntent,
+ remoteReplyIntent,
+ replyMethod
+ )
+
+ if (canReply) {
+ builder.addAndroidAutoAction(
+ notificationState.getAndroidAutoReplyIntent(context, recipient),
+ notificationState.getAndroidAutoHeardIntent(context, notificationId),
+ notifications[0].timestamp
+ )
+ }
+
+ val iterator: ListIterator = notifications.listIterator(notifications.size)
+
+ while (iterator.hasPrevious()) {
+ val item = iterator.previous()
+ builder.addMessageBody(item.recipient, item.individualRecipient, item.text)
+ }
+
+ if (signal) {
+ builder.setAlarms(notificationState.getRingtone(context), notificationState.vibrate)
+ builder.setTicker(
+ notifications[0].individualRecipient,
+ notifications[0].text
+ )
+ }
+
+ if (bundled) {
+ builder.setGroup(NOTIFICATION_GROUP)
+ builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
+ }
+
+ val notification = builder.build()
+
+ // TODO - ACL to fix this properly & will do on 2024-08-26, but just skipping for now so review can start
+ if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return
+ }
+ NotificationManagerCompat.from(context).notify(notificationId, notification)
+ Log.i(TAG, "Posted notification. $notification")
+ }
+
+ // Note: The `signal` parameter means "play an audio signal for the notification".
+ private fun sendMultipleThreadNotification(
+ context: Context,
+ notificationState: NotificationState,
+ signal: Boolean
+ ) {
+ Log.i(TAG, "sendMultiThreadNotification() signal: $signal")
+
+ val builder = MultipleRecipientNotificationBuilder(context, getNotificationPrivacy(context))
+ val notifications = notificationState.notifications
+
+ builder.setMessageCount(notificationState.messageCount, notificationState.threadCount)
+ builder.setMostRecentSender(notifications[0].individualRecipient, notifications[0].recipient)
+ builder.setGroup(NOTIFICATION_GROUP)
+ builder.setDeleteIntent(notificationState.getDeleteIntent(context))
+ builder.setOnlyAlertOnce(!signal)
+ builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
+ builder.setAutoCancel(true)
+
+ val messageIdTag = notifications[0].timestamp.toString()
+
+ val notificationManager = ServiceUtil.getNotificationManager(context)
+ for (notification in notificationManager.activeNotifications) {
+ if (notification.id == SUMMARY_NOTIFICATION_ID && messageIdTag == notification.notification.extras.getString(LATEST_MESSAGE_ID_TAG)) {
+ return
+ }
+ }
+
+ val timestamp = notifications[0].timestamp
+ if (timestamp != 0L) builder.setWhen(timestamp)
+
+ builder.addActions(notificationState.getMarkAsReadIntent(context, SUMMARY_NOTIFICATION_ID))
+
+ val iterator: ListIterator = notifications.listIterator(notifications.size)
+ while (iterator.hasPrevious()) {
+ val item = iterator.previous()
+ builder.addMessageBody(
+ item.individualRecipient, item.recipient,
+ highlightMentions(
+ (if (item.text != null) item.text else "")!!,
+ false,
+ false,
+ true, // no styling here, only text formatting
+ item.threadId,
+ context
+ )
+ )
+ }
+
+ if (signal) {
+ builder.setAlarms(notificationState.getRingtone(context), notificationState.vibrate)
+ val text = notifications[0].text
+ builder.setTicker(
+ notifications[0].individualRecipient,
+ highlightMentions(
+ text ?: "",
+ false,
+ false,
+ true, // no styling here, only text formatting
+ notifications[0].threadId,
+ context
+ )
+ )
+ }
+
+ builder.putStringExtra(LATEST_MESSAGE_ID_TAG, messageIdTag)
+
+ // TODO - ACL to fix this properly & will do on 2024-08-26, but just skipping for now so review can start
+ if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
+ // TODO: Consider calling
+ // ActivityCompat#requestPermissions
+ // here to request the missing permissions, and then overriding
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ // int[] grantResults)
+ // to handle the case where the user grants the permission. See the documentation
+ // for ActivityCompat#requestPermissions for more details.
+ return
+ }
+
+ val notification = builder.build()
+ NotificationManagerCompat.from(context).notify(SUMMARY_NOTIFICATION_ID, notification)
+ Log.i(TAG, "Posted notification. $notification")
+ }
+
+ private fun constructNotificationState(context: Context, cursor: Cursor): NotificationState {
+ val notificationState = NotificationState()
+ val reader = get(context).mmsSmsDatabase().readerFor(cursor)
+ if (reader == null) {
+ Log.e(TAG, "No reader for cursor - aborting constructNotificationState")
+ return NotificationState()
+ }
+
+ val threadDatabase = get(context).threadDatabase()
+ val cache: MutableMap = HashMap()
+
+ // CAREFUL: Do not put this loop back as `while ((reader.next.also { record = it }) != null) {` because it breaks with a Null Pointer Exception!
+ var record: MessageRecord? = null
+ do {
+ record = reader.next
+ if (record == null) break // Bail if there are no more MessageRecords
+
+ val id = record.getId()
+ val mms = record.isMms || record.isMmsNotification
+ val recipient = record.individualRecipient
+ val conversationRecipient = record.recipient
+ val threadId = record.threadId
+ var body: CharSequence = record.getDisplayBody(context)
+ var threadRecipients: Recipient? = null
+ var slideDeck: SlideDeck? = null
+ val timestamp = record.timestamp
+ var messageRequest = false
+
+ if (threadId != -1L) {
+ threadRecipients = threadDatabase.getRecipientForThreadId(threadId)
+ messageRequest = threadRecipients != null && !threadRecipients.isGroupRecipient &&
+ !threadRecipients.isApproved && !threadDatabase.getLastSeenAndHasSent(threadId).second()
+ if (messageRequest && (threadDatabase.getMessageCount(threadId) > 1 || !hasHiddenMessageRequests(context))) {
+ continue
+ }
+ }
+
+ // If this is a message request from an unknown user..
+ if (messageRequest) {
+ body = SpanUtil.italic(context.getString(R.string.messageRequestsNew))
+
+ // If we received some manner of notification but Session is locked..
+ } else if (KeyCachingService.isLocked(context)) {
+ // Note: We provide 1 because `messageNewYouveGot` is now a plurals string and we don't have a count yet, so just
+ // giving it 1 will result in "You got a new message".
+ body = SpanUtil.italic(context.resources.getQuantityString(R.plurals.messageNewYouveGot, 1, 1))
+
+ // ----- Note: All further cases assume we know the contact and that Session isn't locked -----
+
+ // If this is a notification about a multimedia message from a contact we know about..
+ } else if (record.isMms && !(record as MmsMessageRecord).sharedContacts.isEmpty()) {
+ val contact = (record as MmsMessageRecord).sharedContacts[0]
+ body = ContactUtil.getStringSummary(context, contact)
+
+ // If this is a notification about a multimedia message which contains no text but DOES contain a slide deck with at least one slide..
+ } else if (record.isMms && TextUtils.isEmpty(body) && !(record as MmsMessageRecord).slideDeck.slides.isEmpty()) {
+ slideDeck = (record as MediaMmsMessageRecord).slideDeck
+ body = SpanUtil.italic(slideDeck.body)
+
+ // If this is a notification about a multimedia message, but it's not ITSELF a multimedia notification AND it contains a slide deck with at least one slide..
+ } else if (record.isMms && !record.isMmsNotification && !(record as MmsMessageRecord).slideDeck.slides.isEmpty()) {
+ slideDeck = (record as MediaMmsMessageRecord).slideDeck
+ val message = slideDeck.body + ": " + record.body
+ val italicLength = message.length - body.length
+ body = SpanUtil.italic(message, italicLength)
+
+ // If this is a notification about an invitation to a community..
+ } else if (record.isOpenGroupInvitation) {
+ body = SpanUtil.italic(context.getString(R.string.communityInvitation))
+ }
+
+ val userPublicKey = getLocalNumber(context)
+ var blindedPublicKey = cache[threadId]
+ if (blindedPublicKey == null) {
+ blindedPublicKey = generateBlindedId(threadId, context)
+ cache[threadId] = blindedPublicKey
+ }
+ if (threadRecipients == null || !threadRecipients.isMuted) {
+ if (threadRecipients != null && threadRecipients.notifyType == RecipientDatabase.NOTIFY_TYPE_MENTIONS) {
+ // check if mentioned here
+ var isQuoteMentioned = false
+ if (record is MmsMessageRecord) {
+ val quote = (record as MmsMessageRecord).quote
+ val quoteAddress = quote?.author
+ val serializedAddress = quoteAddress?.serialize()
+ isQuoteMentioned = (serializedAddress != null && userPublicKey == serializedAddress) ||
+ (blindedPublicKey != null && userPublicKey == blindedPublicKey)
+ }
+ if (body.toString().contains("@$userPublicKey") || body.toString().contains("@$blindedPublicKey") || isQuoteMentioned) {
+ notificationState.addNotification(NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, slideDeck))
+ }
+ } else if (threadRecipients != null && threadRecipients.notifyType == RecipientDatabase.NOTIFY_TYPE_NONE) {
+ // do nothing, no notifications
+ } else {
+ notificationState.addNotification(NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, slideDeck))
+ }
+
+ val userBlindedPublicKey = blindedPublicKey
+ val lastReact = Stream.of(record.reactions)
+ .filter { r: ReactionRecord -> !(r.author == userPublicKey || r.author == userBlindedPublicKey) }
+ .findLast()
+
+ if (lastReact.isPresent) {
+ if (threadRecipients != null && !threadRecipients.isGroupRecipient) {
+ val reaction = lastReact.get()
+ val reactor = Recipient.from(context, fromSerialized(reaction.author), false)
+ val emoji = Phrase.from(context, R.string.emojiReactsNotification).put(EMOJI_KEY, reaction.emoji).format().toString()
+ notificationState.addNotification(NotificationItem(id, mms, reactor, reactor, threadRecipients, threadId, emoji, reaction.dateSent, slideDeck))
+ }
+ }
+ }
+ } while (record != null) // This will never hit because we break early if we get a null record at the start of the do..while loop
+
+ reader.close()
+ return notificationState
+ }
+
+ private fun generateBlindedId(threadId: Long, context: Context): String? {
+ val lokiThreadDatabase = get(context).lokiThreadDatabase()
+ val openGroup = lokiThreadDatabase.getOpenGroupChat(threadId)
+ val edKeyPair = getUserED25519KeyPair(context)
+ if (openGroup != null && edKeyPair != null) {
+ val blindedKeyPair = blindedKeyPair(openGroup.publicKey, edKeyPair)
+ if (blindedKeyPair != null) {
+ return AccountId(IdPrefix.BLINDED, blindedKeyPair.publicKey.asBytes).hexString
+ }
+ }
+ return null
+ }
+
+ private fun updateBadge(context: Context, count: Int) {
+ try {
+ if (count == 0) ShortcutBadger.removeCount(context)
+ else ShortcutBadger.applyCount(context, count)
+ } catch (t: Throwable) {
+ Log.w("MessageNotifier", t)
+ }
+ }
+
+ private fun scheduleReminder(context: Context, count: Int) {
+ if (count >= getRepeatAlertsCount(context)) {
+ return
+ }
+
+ val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
+ val alarmIntent = Intent(ReminderReceiver.REMINDER_ACTION)
+ alarmIntent.putExtra("reminder_count", count)
+
+ val pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE)
+ val timeout = TimeUnit.MINUTES.toMillis(2)
+
+ alarmManager[AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout] = pendingIntent
+ }
+
+ override fun clearReminder(context: Context) {
+ val alarmIntent = Intent(ReminderReceiver.REMINDER_ACTION)
+ val pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE)
+ val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
+ alarmManager.cancel(pendingIntent)
+ }
+
+ class ReminderReceiver : BroadcastReceiver() {
+ @SuppressLint("StaticFieldLeak")
+ override fun onReceive(context: Context, intent: Intent) {
+ object : AsyncTask() {
+
+ override fun doInBackground(vararg params: Void?): Void? {
+ val reminderCount = intent.getIntExtra("reminder_count", 0)
+ ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, true, reminderCount + 1)
+ return null
+ }
+
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
+ }
+
+ companion object {
+ const val REMINDER_ACTION: String = "network.loki.securesms.MessageNotifier.REMINDER_ACTION"
+ }
+ }
+
+ // ACL: What is the concept behind delayed notifications? Why would we ever want this? To batch them up so
+ // that we get a bunch of notifications once per minute or something rather than a constant stream of them
+ // if that's what was incoming?!?
+ private class DelayedNotification(private val context: Context, private val threadId: Long) : Runnable {
+ private val canceled = AtomicBoolean(false)
+
+ private val delayUntil: Long
+
+ init {
+ this.delayUntil = System.currentTimeMillis() + DELAY
+ }
+
+ override fun run() {
+ val delayMillis = delayUntil - System.currentTimeMillis()
+ Log.i(TAG, "Waiting to notify: $delayMillis")
+
+ if (delayMillis > 0) { Util.sleep(delayMillis) }
+
+ if (!canceled.get()) {
+ Log.i(TAG, "Not canceled, notifying...")
+ ApplicationContext.getInstance(context).messageNotifier.updateNotification(context, threadId, true)
+ ApplicationContext.getInstance(context).messageNotifier.cancelDelayedNotifications()
+ } else {
+ Log.w(TAG, "Canceled, not notifying...")
+ }
+ }
+
+ fun cancel() {
+ canceled.set(true)
+ }
+
+ companion object {
+ private val DELAY = TimeUnit.SECONDS.toMillis(5)
+ }
+ }
+
+ private class CancelableExecutor {
+ private val executor: Executor = Executors.newSingleThreadExecutor()
+ private val tasks: MutableSet = HashSet()
+
+ fun execute(runnable: DelayedNotification) {
+ synchronized(tasks) { tasks.add(runnable) }
+
+ val wrapper = Runnable {
+ runnable.run()
+ synchronized(tasks) {
+ tasks.remove(runnable)
+ }
+ }
+
+ executor.execute(wrapper)
+ }
+
+ fun cancel() {
+ synchronized(tasks) {
+ for (task in tasks) { task.cancel() }
+ }
+ }
+ }
+
+ companion object {
+ private val TAG: String = DefaultMessageNotifier::class.java.simpleName
+
+ const val EXTRA_REMOTE_REPLY: String = "extra_remote_reply"
+ const val LATEST_MESSAGE_ID_TAG: String = "extra_latest_message_id"
+
+ private const val FOREGROUND_ID = 313399
+ private const val SUMMARY_NOTIFICATION_ID = 1338
+ private const val PENDING_MESSAGES_ID = 1111
+ private const val NOTIFICATION_GROUP = "messages"
+ private val MIN_AUDIBLE_PERIOD_MILLIS = TimeUnit.SECONDS.toMillis(5)
+ private val DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1)
+
+ @Volatile
+ private var visibleThread: Long = -1
+
+ @Volatile
+ private var homeScreenVisible = false
+
+ @Volatile
+ private var lastDesktopActivityTimestamp: Long = -1
+
+ @Volatile
+ private var lastAudibleNotification: Long = -1
+ private val executor = CancelableExecutor()
+ }
+}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/FailedNotificationBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/FailedNotificationBuilder.java
deleted file mode 100644
index dc0e52abc6..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/FailedNotificationBuilder.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.thoughtcrime.securesms.notifications;
-
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.BitmapFactory;
-
-import org.session.libsession.utilities.NotificationPrivacyPreference;
-import org.session.libsession.utilities.recipients.Recipient;
-
-import network.loki.messenger.R;
-
-public class FailedNotificationBuilder extends AbstractNotificationBuilder {
-
- public FailedNotificationBuilder(Context context, NotificationPrivacyPreference privacy, Intent intent) {
- super(context, privacy);
-
- setSmallIcon(R.drawable.ic_notification);
- setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
- R.drawable.ic_action_warning_red));
- setContentTitle(context.getString(R.string.MessageNotifier_message_delivery_failed));
- setContentText(context.getString(R.string.MessageNotifier_failed_to_deliver_message));
- setTicker(context.getString(R.string.MessageNotifier_error_delivering_message));
- setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE));
- setAutoCancel(true);
- setAlarms(null, Recipient.VibrateState.DEFAULT);
- setChannelId(NotificationChannels.FAILURES);
- }
-
-
-
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java
deleted file mode 100644
index 0578bb2c9c..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package org.thoughtcrime.securesms.notifications;
-
-import android.app.Notification;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.text.SpannableStringBuilder;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.core.app.NotificationCompat;
-
-import org.session.libsession.messaging.contacts.Contact;
-import org.session.libsession.utilities.NotificationPrivacyPreference;
-import org.session.libsession.utilities.TextSecurePreferences;
-import org.session.libsession.utilities.Util;
-import org.session.libsession.utilities.recipients.Recipient;
-import org.thoughtcrime.securesms.database.SessionContactDatabase;
-import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
-import org.thoughtcrime.securesms.home.HomeActivity;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import network.loki.messenger.R;
-
-public class MultipleRecipientNotificationBuilder extends AbstractNotificationBuilder {
-
- private final List messageBodies = new LinkedList<>();
-
- public MultipleRecipientNotificationBuilder(Context context, NotificationPrivacyPreference privacy) {
- super(context, privacy);
-
- setColor(context.getResources().getColor(R.color.textsecure_primary));
- setSmallIcon(R.drawable.ic_notification);
- setContentTitle(context.getString(R.string.app_name));
- setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, HomeActivity.class), PendingIntent.FLAG_IMMUTABLE));
- setCategory(NotificationCompat.CATEGORY_MESSAGE);
- setGroupSummary(true);
- }
-
- public void setMessageCount(int messageCount, int threadCount) {
- setSubText(context.getString(R.string.MessageNotifier_d_new_messages_in_d_conversations,
- messageCount, threadCount));
- setContentInfo(String.valueOf(messageCount));
- setNumber(messageCount);
- }
-
- public void setMostRecentSender(Recipient recipient, Recipient threadRecipient) {
- String displayName = recipient.toShortString();
- if (threadRecipient.isGroupRecipient()) {
- displayName = getGroupDisplayName(recipient, threadRecipient.isCommunityRecipient());
- }
- if (privacy.isDisplayContact()) {
- setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s, displayName));
- }
-
- if (recipient.getNotificationChannel() != null) {
- setChannelId(recipient.getNotificationChannel());
- }
- }
-
- public void addActions(PendingIntent markAsReadIntent) {
- NotificationCompat.Action markAllAsReadAction = new NotificationCompat.Action(R.drawable.check,
- context.getString(R.string.MessageNotifier_mark_all_as_read),
- markAsReadIntent);
- addAction(markAllAsReadAction);
- extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
- }
-
- public void putStringExtra(String key, String value) {
- extras.putString(key,value);
- }
-
- public void addMessageBody(@NonNull Recipient sender, Recipient threadRecipient, @Nullable CharSequence body) {
- String displayName = sender.toShortString();
- if (threadRecipient.isGroupRecipient()) {
- displayName = getGroupDisplayName(sender, threadRecipient.isCommunityRecipient());
- }
- if (privacy.isDisplayMessage()) {
- SpannableStringBuilder builder = new SpannableStringBuilder();
- builder.append(Util.getBoldedString(displayName));
- builder.append(": ");
- builder.append(body == null ? "" : body);
-
- messageBodies.add(builder);
- } else if (privacy.isDisplayContact()) {
- messageBodies.add(Util.getBoldedString(displayName));
- }
-
- if (privacy.isDisplayContact() && sender.getContactUri() != null) {
-// addPerson(sender.getContactUri().toString());
- }
- }
-
- @Override
- public Notification build() {
- if (privacy.isDisplayMessage() || privacy.isDisplayContact()) {
- NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
-
- for (CharSequence body : messageBodies) {
- style.addLine(trimToDisplayLength(body));
- }
-
- setStyle(style);
- }
-
- return super.build();
- }
-
- /**
- * @param recipient the * individual * recipient for which to get the display name.
- * @param openGroupRecipient whether in an open group context
- */
- private String getGroupDisplayName(Recipient recipient, boolean openGroupRecipient) {
- SessionContactDatabase contactDB = DatabaseComponent.get(context).sessionContactDatabase();
- String accountID = recipient.getAddress().serialize();
- Contact contact = contactDB.getContactWithAccountID(accountID);
- if (contact == null) { return accountID; }
- String displayName = contact.displayName(openGroupRecipient ? Contact.ContactContext.OPEN_GROUP : Contact.ContactContext.REGULAR);
- if (displayName == null) { return accountID; }
- return displayName;
- }
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.kt
new file mode 100644
index 0000000000..a526f9e8f2
--- /dev/null
+++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/MultipleRecipientNotificationBuilder.kt
@@ -0,0 +1,112 @@
+package org.thoughtcrime.securesms.notifications
+
+import android.app.Notification
+import android.app.PendingIntent
+import android.content.Context
+import android.content.Intent
+import android.text.SpannableStringBuilder
+import androidx.core.app.NotificationCompat
+import com.squareup.phrase.Phrase
+import network.loki.messenger.R
+import org.session.libsession.messaging.contacts.Contact
+import org.session.libsession.utilities.NotificationPrivacyPreference
+import org.session.libsession.utilities.StringSubstitutionConstants.CONVERSATION_COUNT_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.MESSAGE_COUNT_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
+import org.session.libsession.utilities.Util.getBoldedString
+import org.session.libsession.utilities.recipients.Recipient
+import org.thoughtcrime.securesms.dependencies.DatabaseComponent.Companion.get
+import org.thoughtcrime.securesms.home.HomeActivity
+import org.thoughtcrime.securesms.ui.getSubbedString
+import java.util.LinkedList
+
+class MultipleRecipientNotificationBuilder(context: Context, privacy: NotificationPrivacyPreference?) : AbstractNotificationBuilder(context, privacy) {
+ private val messageBodies: MutableList = LinkedList()
+
+ init {
+ color = context.resources.getColor(R.color.textsecure_primary)
+ setSmallIcon(R.drawable.ic_notification)
+ setContentTitle(context.getString(R.string.app_name))
+ setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, HomeActivity::class.java), PendingIntent.FLAG_IMMUTABLE))
+ setCategory(NotificationCompat.CATEGORY_MESSAGE)
+ setGroupSummary(true)
+ }
+
+ fun setMessageCount(messageCount: Int, threadCount: Int) {
+ val txt = context.getSubbedString(R.string.notificationsSystem, MESSAGE_COUNT_KEY to messageCount.toString(), CONVERSATION_COUNT_KEY to threadCount.toString())
+ setSubText(txt)
+ setNumber(messageCount)
+ }
+
+ fun setMostRecentSender(recipient: Recipient, threadRecipient: Recipient) {
+ var displayName = recipient.toShortString()
+ if (threadRecipient.isGroupRecipient) {
+ displayName = getGroupDisplayName(recipient, threadRecipient.isCommunityRecipient)
+ }
+ if (privacy.isDisplayContact) {
+ val txt = Phrase.from(context, R.string.notificationsMostRecent)
+ .put(NAME_KEY, displayName)
+ .format().toString()
+ setContentText(txt)
+ }
+
+ if (recipient.notificationChannel != null) {
+ setChannelId(recipient.notificationChannel!!)
+ }
+ }
+
+ fun addActions(markAsReadIntent: PendingIntent?) {
+ val markAllAsReadAction = NotificationCompat.Action(
+ R.drawable.check,
+ context.getString(R.string.messageMarkRead),
+ markAsReadIntent
+ )
+ addAction(markAllAsReadAction)
+ extend(NotificationCompat.WearableExtender().addAction(markAllAsReadAction))
+ }
+
+ fun putStringExtra(key: String?, value: String?) { extras.putString(key, value) }
+
+ fun addMessageBody(sender: Recipient, threadRecipient: Recipient, body: CharSequence?) {
+ var displayName = sender.toShortString()
+ if (threadRecipient.isGroupRecipient) {
+ displayName = getGroupDisplayName(sender, threadRecipient.isCommunityRecipient)
+ }
+ if (privacy.isDisplayMessage) {
+ val builder = SpannableStringBuilder()
+ builder.append(getBoldedString(displayName))
+ builder.append(": ")
+ builder.append(body ?: "")
+ messageBodies.add(builder)
+ } else if (privacy.isDisplayContact) {
+ messageBodies.add(getBoldedString(displayName))
+ }
+
+ // TODO: What on earth is this? Why is it commented out? It's also commented out in dev... remove? -ACL 2024-08-29
+ if (privacy.isDisplayContact && sender.contactUri != null) {
+// addPerson(sender.getContactUri().toString());
+ }
+ }
+
+ override fun build(): Notification {
+ if (privacy.isDisplayMessage || privacy.isDisplayContact) {
+ val style = NotificationCompat.InboxStyle()
+ for (body in messageBodies) { style.addLine(trimToDisplayLength(body)) }
+ setStyle(style)
+ }
+ return super.build()
+ }
+
+ /**
+ * @param recipient the * individual * recipient for which to get the display name.
+ * @param openGroupRecipient whether in an open group context
+ */
+ private fun getGroupDisplayName(recipient: Recipient, openGroupRecipient: Boolean): String {
+ val contactDB = get(context).sessionContactDatabase()
+ val accountID = recipient.address.serialize()
+ val contact = contactDB.getContactWithAccountID(accountID) ?: return accountID
+ val displayName = contact.displayName(if (openGroupRecipient) Contact.ContactContext.OPEN_GROUP else Contact.ContactContext.REGULAR)
+ if (displayName == null) { return accountID }
+ return displayName
+ }
+}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java
index 51ff467549..0c3422b757 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java
@@ -92,7 +92,7 @@ public class NotificationChannels {
} else if (!TextUtils.isEmpty(address.serialize())) {
return address.serialize();
} else {
- return context.getString(R.string.NotificationChannel_missing_display_name);
+ return context.getString(R.string.unknown);
}
}
@@ -179,15 +179,14 @@ public class NotificationChannels {
}
private static void onCreate(@NonNull Context context, @NonNull NotificationManager notificationManager) {
- NotificationChannelGroup messagesGroup = new NotificationChannelGroup(CATEGORY_MESSAGES, context.getResources().getString(R.string.NotificationChannel_group_messages));
+ NotificationChannelGroup messagesGroup = new NotificationChannelGroup(CATEGORY_MESSAGES, context.getResources().getString(R.string.messages));
notificationManager.createNotificationChannelGroup(messagesGroup);
- NotificationChannel messages = new NotificationChannel(getMessagesChannel(context), context.getString(R.string.NotificationChannel_messages), NotificationManager.IMPORTANCE_HIGH);
- NotificationChannel calls = new NotificationChannel(CALLS, context.getString(R.string.NotificationChannel_calls), NotificationManager.IMPORTANCE_HIGH);
- NotificationChannel failures = new NotificationChannel(FAILURES, context.getString(R.string.NotificationChannel_failures), NotificationManager.IMPORTANCE_HIGH);
- NotificationChannel backups = new NotificationChannel(BACKUPS, context.getString(R.string.NotificationChannel_backups), NotificationManager.IMPORTANCE_LOW);
- NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.NotificationChannel_locked_status), NotificationManager.IMPORTANCE_LOW);
- NotificationChannel other = new NotificationChannel(OTHER, context.getString(R.string.NotificationChannel_other), NotificationManager.IMPORTANCE_LOW);
+ NotificationChannel messages = new NotificationChannel(getMessagesChannel(context), context.getString(R.string.theDefault), NotificationManager.IMPORTANCE_HIGH);
+ NotificationChannel calls = new NotificationChannel(CALLS, context.getString(R.string.callsSettings), NotificationManager.IMPORTANCE_HIGH);
+ NotificationChannel failures = new NotificationChannel(FAILURES, context.getString(R.string.failures), NotificationManager.IMPORTANCE_HIGH);
+ NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.lockAppStatus), NotificationManager.IMPORTANCE_LOW);
+ NotificationChannel other = new NotificationChannel(OTHER, context.getString(R.string.other), NotificationManager.IMPORTANCE_LOW);
messages.setGroup(CATEGORY_MESSAGES);
messages.enableVibration(TextSecurePreferences.isNotificationVibrateEnabled(context));
@@ -196,14 +195,13 @@ public class NotificationChannels {
calls.setShowBadge(false);
calls.setSound(null, null);
- backups.setShowBadge(false);
lockedStatus.setShowBadge(false);
other.setShowBadge(false);
- notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, backups, lockedStatus, other));
+ notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, lockedStatus, other));
if (BuildConfig.PLAY_STORE_DISABLED) {
- NotificationChannel appUpdates = new NotificationChannel(APP_UPDATES, context.getString(R.string.NotificationChannel_app_updates), NotificationManager.IMPORTANCE_HIGH);
+ NotificationChannel appUpdates = new NotificationChannel(APP_UPDATES, context.getString(R.string.updateApp), NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(appUpdates);
} else {
notificationManager.deleteNotificationChannel(APP_UPDATES);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java
deleted file mode 100644
index ef69abdc26..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/PendingMessageNotificationBuilder.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.thoughtcrime.securesms.notifications;
-
-
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-
-import androidx.core.app.NotificationCompat;
-
-import org.session.libsession.utilities.NotificationPrivacyPreference;
-import org.session.libsession.utilities.TextSecurePreferences;
-import org.session.libsession.utilities.recipients.Recipient;
-import org.thoughtcrime.securesms.home.HomeActivity;
-
-import network.loki.messenger.R;
-
-public class PendingMessageNotificationBuilder extends AbstractNotificationBuilder {
-
- public PendingMessageNotificationBuilder(Context context, NotificationPrivacyPreference privacy) {
- super(context, privacy);
-
- Intent intent = new Intent(context, HomeActivity.class);
-
- setSmallIcon(R.drawable.ic_notification);
- setColor(context.getResources().getColor(R.color.textsecure_primary));
- setCategory(NotificationCompat.CATEGORY_MESSAGE);
-
- setContentTitle(context.getString(R.string.MessageNotifier_pending_signal_messages));
- setContentText(context.getString(R.string.MessageNotifier_you_have_pending_signal_messages));
- setTicker(context.getString(R.string.MessageNotifier_you_have_pending_signal_messages));
-
- setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE));
- setAutoCancel(true);
- setAlarms(null, Recipient.VibrateState.DEFAULT);
- }
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt
index 5f218a7a9f..8eaca4000b 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt
@@ -3,14 +3,13 @@ package org.thoughtcrime.securesms.notifications
import android.content.Context
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
-import com.goterl.lazysodium.LazySodiumAndroid
-import com.goterl.lazysodium.SodiumAndroid
+import androidx.core.content.ContextCompat.getString
import com.goterl.lazysodium.interfaces.AEAD
import com.goterl.lazysodium.utils.Key
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
-import kotlinx.serialization.json.JsonBuilder
+import network.loki.messenger.R
import org.session.libsession.messaging.jobs.BatchMessageReceiveJob
import org.session.libsession.messaging.jobs.JobQueue
import org.session.libsession.messaging.jobs.MessageReceiveParameters
@@ -53,10 +52,13 @@ class PushReceiver @Inject constructor(@ApplicationContext val context: Context)
private fun onPush() {
Log.d(TAG, "Failed to decode data for message.")
val builder = NotificationCompat.Builder(context, NotificationChannels.OTHER)
- .setSmallIcon(network.loki.messenger.R.drawable.ic_notification)
- .setColor(context.getColor(network.loki.messenger.R.color.textsecure_primary))
- .setContentTitle("Session")
- .setContentText("You've got a new message.")
+ .setSmallIcon(R.drawable.ic_notification)
+ .setColor(context.getColor(R.color.textsecure_primary))
+ .setContentTitle(getString(context, R.string.app_name))
+
+ // Note: We set the count to 1 in the below plurals string so it says "You've got a new message" (singular)
+ .setContentText(context.resources.getQuantityString(R.plurals.messageNewYouveGot, 1, 1))
+
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
NotificationManagerCompat.from(context).notify(11111, builder.build())
diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java
index 0ac16ea652..6764f46069 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java
@@ -102,7 +102,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
}
} else {
- setContentTitle(context.getString(R.string.SingleRecipientNotificationBuilder_signal));
+ setContentTitle(context.getString(R.string.app_name));
setLargeIcon(AvatarPlaceholderGenerator.generate(context, ICON_SIZE, "", "Unknown"));
}
}
@@ -128,7 +128,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
setContentText(stringBuilder.append(message));
this.slideDeck = slideDeck;
} else {
- setContentText(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)));
+ setContentText(stringBuilder.append(context.getResources().getQuantityString(R.plurals.messageNew, 1, 1)));
}
}
@@ -140,7 +140,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
return;
RemoteInput remoteInput = new RemoteInput.Builder(AndroidAutoReplyReceiver.VOICE_REPLY_KEY)
- .setLabel(context.getString(R.string.MessageNotifier_reply))
+ .setLabel(context.getString(R.string.reply))
.build();
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder =
@@ -159,7 +159,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
@NonNull ReplyMethod replyMethod)
{
Action markAsReadAction = new Action(R.drawable.check,
- context.getString(R.string.MessageNotifier_mark_read),
+ context.getString(R.string.messageMarkRead),
markReadIntent);
addAction(markAsReadAction);
@@ -167,7 +167,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(markAsReadAction);
if (quickReplyIntent != null) {
- String actionName = context.getString(R.string.MessageNotifier_reply);
+ String actionName = context.getString(R.string.reply);
String label = context.getString(replyMethodLongDescription(replyMethod));
Action replyAction = new Action(R.drawable.ic_reply_white_36dp, actionName, quickReplyIntent);
@@ -194,7 +194,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
@StringRes
private static int replyMethodLongDescription(@NonNull ReplyMethod replyMethod) {
- return R.string.MessageNotifier_reply;
+ return R.string.reply;
}
public void putStringExtra(String key, String value) {
@@ -215,7 +215,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
if (privacy.isDisplayMessage()) {
messageBodies.add(stringBuilder.append(messageBody == null ? "" : messageBody));
} else {
- messageBodies.add(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)));
+ messageBodies.add(stringBuilder.append(context.getResources().getQuantityString(R.plurals.messageNew, 1, 1)));
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/OnboardingBackPressAlertDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/OnboardingBackPressAlertDialog.kt
index 2820a64a66..4481f524d8 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/OnboardingBackPressAlertDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/OnboardingBackPressAlertDialog.kt
@@ -2,8 +2,11 @@ package org.thoughtcrime.securesms.onboarding
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.thoughtcrime.securesms.ui.AlertDialog
import org.thoughtcrime.securesms.ui.DialogButtonModel
import org.thoughtcrime.securesms.ui.GetString
@@ -12,13 +15,16 @@ import org.thoughtcrime.securesms.ui.theme.LocalColors
@Composable
fun OnboardingBackPressAlertDialog(
dismissDialog: () -> Unit,
- @StringRes textId: Int = R.string.you_cannot_go_back_further_in_order_to_stop_loading_your_account_session_needs_to_quit,
+ @StringRes textId: Int = R.string.onboardingBackAccountCreation,
quit: () -> Unit
) {
AlertDialog(
onDismissRequest = dismissDialog,
title = stringResource(R.string.warning),
- text = stringResource(textId),
+ text = stringResource(textId).let { txt ->
+ val c = LocalContext.current
+ Phrase.from(txt).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString()
+ },
buttons = listOf(
DialogButtonModel(
GetString(stringResource(R.string.quit)),
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt
index e40328b1d8..9a478e6ecc 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt
@@ -34,8 +34,13 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
+import com.squareup.phrase.Phrase
import kotlinx.coroutines.delay
import network.loki.messenger.R
+import org.session.libsession.utilities.NonTranslatableStringConstants.BACKHAND_INDEX_POINTING_DOWN_EMOJI
+import org.session.libsession.utilities.NonTranslatableStringConstants.WAVING_HAND_EMOJI
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.EMOJI_KEY
import org.thoughtcrime.securesms.ui.AlertDialog
import org.thoughtcrime.securesms.ui.DialogButtonModel
import org.thoughtcrime.securesms.ui.GetString
@@ -81,13 +86,13 @@ internal fun LandingScreen(
showCloseButton = true, // display the 'x' button
buttons = listOf(
DialogButtonModel(
- text = GetString(R.string.activity_landing_terms_of_service),
- contentDescription = GetString(R.string.AccessibilityId_terms_of_service_button),
+ text = GetString(R.string.onboardingTos),
+ contentDescription = GetString(R.string.AccessibilityId_onboardingTos),
onClick = openTerms
),
DialogButtonModel(
- text = GetString(R.string.activity_landing_privacy_policy),
- contentDescription = GetString(R.string.AccessibilityId_privacy_policy_button),
+ text = GetString(R.string.onboardingPrivacy),
+ contentDescription = GetString(R.string.AccessibilityId_onboardingPrivacy),
onClick = openPrivacyPolicy
)
)
@@ -129,8 +134,31 @@ internal fun LandingScreen(
MESSAGES.take(count),
key = { it.stringId }
) { item ->
+ // Perform string substitution only in the bubbles that require it
+ val bubbleTxt = when (item.stringId) {
+ R.string.onboardingBubbleWelcomeToSession -> {
+ Phrase.from(stringResource(item.stringId))
+ .put(APP_NAME_KEY, stringResource(R.string.app_name))
+ .put(EMOJI_KEY, WAVING_HAND_EMOJI)
+ .format().toString()
+ }
+ R.string.onboardingBubbleSessionIsEngineered -> {
+ Phrase.from(stringResource(item.stringId))
+ .put(APP_NAME_KEY, stringResource(R.string.app_name))
+ .format().toString()
+ }
+ R.string.onboardingBubbleCreatingAnAccountIsEasy -> {
+ Phrase.from(stringResource(item.stringId))
+ .put(EMOJI_KEY, BACKHAND_INDEX_POINTING_DOWN_EMOJI)
+ .format().toString()
+ }
+ else -> {
+ stringResource(item.stringId)
+ }
+ }
+
AnimateMessageText(
- stringResource(item.stringId),
+ bubbleTxt,
item.isOutgoing
)
}
@@ -145,7 +173,7 @@ internal fun LandingScreen(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
- .contentDescription(R.string.AccessibilityId_create_account_button),
+ .contentDescription(R.string.AccessibilityId_onboardingAccountCreate),
onClick = createAccount
)
Spacer(modifier = Modifier.height(LocalDimensions.current.smallSpacing))
@@ -154,7 +182,7 @@ internal fun LandingScreen(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
- .contentDescription(R.string.AccessibilityId_restore_account_button),
+ .contentDescription(R.string.AccessibilityId_onboardingAccountExists),
onClick = loadAccount
)
BorderlessHtmlButton(
@@ -162,7 +190,7 @@ internal fun LandingScreen(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
- .contentDescription(R.string.AccessibilityId_open_url),
+ .contentDescription(R.string.AccessibilityId_urlOpenBrowser),
onClick = { isUrlDialogVisible = true }
)
Spacer(modifier = Modifier.height(LocalDimensions.current.xxsSpacing))
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt
index 56d1c54ea4..c87d5fc568 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccount.kt
@@ -24,12 +24,12 @@ import androidx.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.flow.Flow
import network.loki.messenger.R
import org.thoughtcrime.securesms.onboarding.ui.ContinuePrimaryOutlineButton
-import org.thoughtcrime.securesms.ui.theme.LocalDimensions
-import org.thoughtcrime.securesms.ui.theme.PreviewTheme
import org.thoughtcrime.securesms.ui.components.QRScannerScreen
import org.thoughtcrime.securesms.ui.components.SessionOutlinedTextField
import org.thoughtcrime.securesms.ui.components.SessionTabRow
+import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
+import org.thoughtcrime.securesms.ui.theme.PreviewTheme
private val TITLES = listOf(R.string.sessionRecoveryPassword, R.string.qrScan)
@@ -93,14 +93,14 @@ private fun RecoveryPassword(state: State, onChange: (String) -> Unit = {}, onCo
}
Spacer(Modifier.height(LocalDimensions.current.smallSpacing))
Text(
- stringResource(R.string.activity_link_enter_your_recovery_password_to_load_your_account_if_you_haven_t_saved_it_you_can_find_it_in_your_app_settings),
+ stringResource(R.string.recoveryPasswordRestoreDescription),
style = LocalType.current.base
)
Spacer(Modifier.height(LocalDimensions.current.spacing))
SessionOutlinedTextField(
text = state.recoveryPhrase,
modifier = Modifier.fillMaxWidth(),
- contentDescription = stringResource(R.string.AccessibilityId_recovery_phrase_input),
+ contentDescription = stringResource(R.string.AccessibilityId_recoveryPasswordEnter),
placeholder = stringResource(R.string.recoveryPasswordEnter),
onChange = onChange,
onContinue = onContinue,
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt
index 8669db87e4..85fbeba78f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt
@@ -28,7 +28,7 @@ class LoadAccountActivity : BaseActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- supportActionBar?.setTitle(R.string.activity_link_load_account)
+ supportActionBar?.setTitle(R.string.loadAccount)
prefs.setConfigurationMessageSynced(false)
prefs.setRestorationTime(System.currentTimeMillis())
prefs.setLastProfileUpdateTime(0)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt
index 8c2e10e765..001562c7ff 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt
@@ -20,7 +20,7 @@ internal fun LoadingScreen(progress: Float) {
Spacer(modifier = Modifier.weight(1f))
ProgressArc(
progress,
- modifier = Modifier.contentDescription(R.string.AccessibilityId_loading_animation)
+ modifier = Modifier.contentDescription(R.string.AccessibilityId_loadAccountProgressMessage)
)
Text(
stringResource(R.string.waitOneMoment),
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt
index c2f32e553c..7e9846a385 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt
@@ -18,7 +18,9 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.thoughtcrime.securesms.onboarding.OnboardingBackPressAlertDialog
import org.thoughtcrime.securesms.onboarding.messagenotifications.MessageNotificationsViewModel.UiState
import org.thoughtcrime.securesms.onboarding.ui.ContinuePrimaryOutlineButton
@@ -55,29 +57,37 @@ internal fun MessageNotificationsScreen(
Column {
Spacer(Modifier.weight(1f))
-
Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.mediumSpacing)) {
Text(stringResource(R.string.notificationsMessage), style = LocalType.current.h4)
Spacer(Modifier.height(LocalDimensions.current.smallSpacing))
- Text(stringResource(R.string.onboardingMessageNotificationExplaination), style = LocalType.current.base)
+ Text(
+ Phrase.from(stringResource(R.string.onboardingMessageNotificationExplanation))
+ .put(APP_NAME_KEY, stringResource(R.string.app_name))
+ .format().toString(),
+ style = LocalType.current.base
+ )
Spacer(Modifier.height(LocalDimensions.current.spacing))
}
NotificationRadioButton(
- R.string.activity_pn_mode_fast_mode,
- R.string.activity_pn_mode_fast_mode_explanation,
- modifier = Modifier.contentDescription(R.string.AccessibilityId_fast_mode_notifications_button),
- tag = R.string.activity_pn_mode_recommended_option_tag,
+ R.string.notificationsFastMode,
+ R.string.notificationsFastModeDescription,
+ modifier = Modifier.contentDescription(R.string.AccessibilityId_notificationsFastMode),
+ tag = R.string.recommended,
checked = state.pushEnabled,
onClick = { setEnabled(true) }
)
// spacing between buttons is provided by ripple/downstate of NotificationRadioButton
+ val explanationTxt = Phrase.from(stringResource(R.string.notificationsSlowModeDescription))
+ .put(APP_NAME_KEY, stringResource(R.string.app_name))
+ .format().toString()
+
NotificationRadioButton(
- R.string.activity_pn_mode_slow_mode,
- R.string.activity_pn_mode_slow_mode_explanation,
- modifier = Modifier.contentDescription(R.string.AccessibilityId_slow_mode_notifications_button),
+ stringResource(R.string.notificationsSlowMode),
+ explanationTxt,
+ modifier = Modifier.contentDescription(R.string.AccessibilityId_notificationsSlowMode),
checked = state.pushDisabled,
onClick = { setEnabled(false) }
)
@@ -90,8 +100,28 @@ internal fun MessageNotificationsScreen(
@Composable
private fun NotificationRadioButton(
- @StringRes title: Int,
- @StringRes explanation: Int,
+ @StringRes titleId: Int,
+ @StringRes explanationId: Int,
+ modifier: Modifier = Modifier,
+ @StringRes tag: Int? = null,
+ checked: Boolean = false,
+ onClick: () -> Unit = {}
+) {
+ // Pass-through from this string ID version to the version that takes strings
+ NotificationRadioButton(
+ titleTxt = stringResource(titleId),
+ explanationTxt = stringResource(explanationId),
+ modifier = modifier,
+ tag = tag,
+ checked = checked,
+ onClick = onClick
+ )
+}
+
+@Composable
+private fun NotificationRadioButton(
+ titleTxt: String,
+ explanationTxt: String,
modifier: Modifier = Modifier,
@StringRes tag: Int? = null,
checked: Boolean = false,
@@ -112,13 +142,19 @@ private fun NotificationRadioButton(
RoundedCornerShape(8.dp)
),
) {
- Column(modifier = Modifier
- .padding(horizontal = LocalDimensions.current.smallSpacing,
- vertical = LocalDimensions.current.xsSpacing)
- ) {
- Text(stringResource(title), style = LocalType.current.h8)
+ Column(
+ modifier = Modifier.padding(horizontal = LocalDimensions.current.smallSpacing, vertical = LocalDimensions.current.xsSpacing)) {
+ Text(
+ titleTxt,
+ style = LocalType.current.h8
+ )
+
+ Text(
+ explanationTxt,
+ style = LocalType.current.small,
+ modifier = Modifier.padding(top = LocalDimensions.current.xxsSpacing)
+ )
- Text(stringResource(explanation), style = LocalType.current.small, modifier = Modifier.padding(top = LocalDimensions.current.xxsSpacing))
tag?.let {
Text(
stringResource(it),
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayName.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayName.kt
index 04124a5bfd..1481695a3a 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayName.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/pickname/PickDisplayName.kt
@@ -41,7 +41,7 @@ internal fun PickDisplayName(
if (state.showDialog) OnboardingBackPressAlertDialog(
dismissDialog,
- R.string.you_cannot_go_back_further_cancel_account_creation,
+ R.string.onboardingBackAccountCreation,
quit
)
@@ -66,7 +66,7 @@ internal fun PickDisplayName(
SessionOutlinedTextField(
text = state.displayName,
modifier = Modifier.fillMaxWidth(),
- contentDescription = stringResource(R.string.AccessibilityId_enter_display_name),
+ contentDescription = stringResource(R.string.AccessibilityId_displayNameEnter),
placeholder = stringResource(R.string.displayNameEnter),
onChange = onChange,
onContinue = onContinue,
diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/ui/ContinueButton.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/ui/ContinueButton.kt
index 0d31363d76..51a5d0f35b 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/ui/ContinueButton.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/ui/ContinueButton.kt
@@ -13,9 +13,9 @@ import org.thoughtcrime.securesms.ui.contentDescription
@Composable
fun ContinuePrimaryOutlineButton(modifier: Modifier, onContinue: () -> Unit) {
PrimaryOutlineButton(
- stringResource(R.string.continue_2),
+ stringResource(R.string.theContinue),
modifier = modifier
- .contentDescription(R.string.AccessibilityId_continue)
+ .contentDescription(R.string.AccessibilityId_theContinue)
.fillMaxWidth()
.padding(horizontal = LocalDimensions.current.xlargeSpacing)
.padding(bottom = LocalDimensions.current.smallSpacing),
diff --git a/app/src/main/java/org/thoughtcrime/securesms/permissions/RationaleDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/permissions/RationaleDialog.kt
index 373da62c12..021b67facb 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/permissions/RationaleDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/permissions/RationaleDialog.kt
@@ -53,8 +53,8 @@ object RationaleDialog {
return context.showSessionDialog {
view(view)
- button(R.string.Permissions_continue) { onPositive.run() }
- button(R.string.Permissions_not_now) { onNegative.run() }
+ button(R.string.theContinue) { onPositive.run() }
+ button(R.string.notNow) { onNegative.run() }
}
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt
index a4efd8d870..b77acfd261 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/permissions/SettingsDialog.kt
@@ -9,9 +9,9 @@ class SettingsDialog {
@JvmStatic
fun show(context: Context, message: String) {
context.showSessionDialog {
- title(R.string.Permissions_permission_required)
+ title(R.string.permissionsRequired)
text(message)
- button(R.string.Permissions_continue, R.string.AccessibilityId_continue) {
+ button(R.string.theContinue, R.string.AccessibilityId_theContinue) {
context.startActivity(Permissions.getApplicationSettingsIntent(context))
}
cancelButton()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsActivity.kt
index 16499cc4bc..d01990fe05 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsActivity.kt
@@ -18,11 +18,11 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity() {
val adapter: BlockedContactsAdapter by lazy { BlockedContactsAdapter(viewModel) }
- fun unblock() {
+ private fun unblock() {
showSessionDialog {
title(viewModel.getTitle(this@BlockedContactsActivity))
- text(viewModel.getMessage(this@BlockedContactsActivity))
- button(R.string.continue_2) { viewModel.unblock() }
+ text(viewModel.getText(context, viewModel.state.selectedItems))
+ dangerButton(R.string.blockUnblock, R.string.AccessibilityId_unblockConfirm) { viewModel.unblock() }
cancelButton()
}
}
@@ -43,6 +43,5 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity() {
}
binding.unblockButton.setOnClickListener { unblock() }
-
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt
index dbe09668c5..ae9dfe4760 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsViewModel.kt
@@ -6,11 +6,10 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.cash.copper.flow.observeQuery
+import com.squareup.phrase.Phrase
import dagger.hilt.android.lifecycle.HiltViewModel
-import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
-import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collect
@@ -20,10 +19,11 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import kotlinx.coroutines.withContext
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.database.DatabaseContentProviders
import org.thoughtcrime.securesms.database.Storage
-import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.adapter.SelectableItem
import javax.inject.Inject
@@ -75,36 +75,30 @@ class BlockedContactsViewModel @Inject constructor(private val storage: Storage)
}
}
- fun getTitle(context: Context): String =
- if (state.selectedItems.size == 1) {
- context.getString(R.string.Unblock_dialog__title_single, state.selectedItems.first().name)
- } else {
- context.getString(R.string.Unblock_dialog__title_multiple)
- }
+ fun getTitle(context: Context): String = context.getString(R.string.blockUnblock)
- fun getMessage(context: Context): String {
- if (state.selectedItems.size == 1) {
- return context.getString(R.string.Unblock_dialog__message, state.selectedItems.first().name)
+ // Method to get the appropriate text to display when unblocking 1, 2, or several contacts
+ fun getText(context: Context, contactsToUnblock: Set): CharSequence {
+ return when (contactsToUnblock.size) {
+ // Note: We do not have to handle 0 because if no contacts are chosen then the unblock button is deactivated
+ 1 -> Phrase.from(context, R.string.blockUnblockName)
+ .put(NAME_KEY, contactsToUnblock.elementAt(0).name)
+ .format()
+ 2 -> Phrase.from(context, R.string.blockUnblockNameTwo)
+ .put(NAME_KEY, contactsToUnblock.elementAt(0).name)
+ .format()
+ else -> {
+ val othersCount = contactsToUnblock.size - 1
+ Phrase.from(context, R.string.blockUnblockNameMultiple)
+ .put(NAME_KEY, contactsToUnblock.elementAt(0).name)
+ .put(COUNT_KEY, othersCount)
+ .format()
+ }
}
- val stringBuilder = StringBuilder()
- val iterator = state.selectedItems.iterator()
- var numberAdded = 0
- while (iterator.hasNext() && numberAdded < 3) {
- val nextRecipient = iterator.next()
- if (numberAdded > 0) stringBuilder.append(", ")
-
- stringBuilder.append(nextRecipient.name)
- numberAdded++
- }
- val overflow = state.selectedItems.size - numberAdded
- if (overflow > 0) {
- stringBuilder.append(" ")
- val string = context.resources.getQuantityString(R.plurals.Unblock_dialog__message_multiple_overflow, overflow)
- stringBuilder.append(string.format(overflow))
- }
- return context.getString(R.string.Unblock_dialog__message, stringBuilder.toString())
}
+ fun getMessage(context: Context): String = context.getString(R.string.blockUnblock)
+
fun toggle(selectable: SelectableItem) {
_state.value = state.run {
if (selectable.item in selectedItems) copy(selectedItems = selectedItems - selectable.item)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/CallToggleListener.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/CallToggleListener.kt
index ea747798c8..7383b708e0 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/CallToggleListener.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/CallToggleListener.kt
@@ -19,9 +19,9 @@ internal class CallToggleListener(
// check if we've shown the info dialog and check for microphone permissions
context.showSessionDialog {
- title(R.string.dialog_voice_video_title)
- text(R.string.dialog_voice_video_message)
- button(R.string.dialog_link_preview_enable_button_title, R.string.AccessibilityId_enable) { requestMicrophonePermission() }
+ title(R.string.callsVoiceAndVideoBeta)
+ text(R.string.callsVoiceAndVideoModalDescription)
+ button(R.string.enable, R.string.AccessibilityId_enable) { requestMicrophonePermission() }
cancelButton()
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ChatSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ChatSettingsActivity.kt
index 6852d2f63f..f2217b66e8 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ChatSettingsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ChatSettingsActivity.kt
@@ -9,7 +9,7 @@ class ChatSettingsActivity : PassphraseRequiredActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
setContentView(R.layout.activity_fragment_wrapper)
- supportActionBar!!.title = resources.getString(R.string.activity_conversations_settings_title)
+ supportActionBar!!.title = resources.getString(R.string.sessionConversations)
val fragment = ChatsPreferenceFragment()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragmentContainer, fragment)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt
index 80c8da8a3f..98ad62dcb3 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt
@@ -63,7 +63,6 @@ class ClearAllDataDialog : DialogFragment() {
binding.recyclerView.apply {
itemAnimator = null
adapter = optionAdapter
- addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL))
setHasFixedSize(true)
}
optionAdapter.submitList(listOf(device, network))
@@ -93,10 +92,10 @@ class ClearAllDataDialog : DialogFragment() {
when (step) {
Steps.INFO_PROMPT -> {
- binding.dialogDescriptionText.setText(R.string.dialog_clear_all_data_message)
+ binding.dialogDescriptionText.setText(R.string.clearDataAllDescription)
}
Steps.NETWORK_PROMPT -> {
- binding.dialogDescriptionText.setText(R.string.dialog_clear_all_data_clear_device_and_network_confirmation)
+ binding.dialogDescriptionText.text = getString(R.string.clearDeviceAndNetworkConfirm)
}
Steps.DELETING -> { /* do nothing intentionally */ }
Steps.RETRY_LOCAL_DELETE_ONLY_PROMPT -> {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/CorrectedPreferenceFragment.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/CorrectedPreferenceFragment.java
index 8c3e6190ed..d626b9ce5f 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/CorrectedPreferenceFragment.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/CorrectedPreferenceFragment.java
@@ -21,18 +21,15 @@ import androidx.preference.PreferenceGroupAdapter;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.recyclerview.widget.RecyclerView;
-
-import org.thoughtcrime.securesms.components.CustomDefaultPreference;
import org.thoughtcrime.securesms.conversation.v2.ViewUtil;
-
import network.loki.messenger.R;
public abstract class CorrectedPreferenceFragment extends PreferenceFragmentCompat {
- public static final int SINGLE_TYPE = 21;
- public static final int TOP_TYPE = 22;
- public static final int MIDDLE_TYPE = 23;
- public static final int BOTTOM_TYPE = 24;
+ public static final int SINGLE_TYPE = 21;
+ public static final int TOP_TYPE = 22;
+ public static final int MIDDLE_TYPE = 23;
+ public static final int BOTTOM_TYPE = 24;
public static final int CATEGORY_TYPE = 25;
public int horizontalPadding;
@@ -56,18 +53,7 @@ public abstract class CorrectedPreferenceFragment extends PreferenceFragmentComp
@Override
public void onDisplayPreferenceDialog(Preference preference) {
- DialogFragment dialogFragment = null;
-
- if (preference instanceof CustomDefaultPreference) {
- dialogFragment = CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.newInstance(preference.getKey());
- }
-
- if (dialogFragment != null) {
- dialogFragment.setTargetFragment(this, 0);
- dialogFragment.show(getFragmentManager(), "android.support.v7.preference.PreferenceFragment.DIALOG");
- } else {
- super.onDisplayPreferenceDialog(preference);
- }
+ if (preference != null) super.onDisplayPreferenceDialog(preference);
}
@Override
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt
index 339047bbf6..d3c68a814d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt
@@ -10,11 +10,13 @@ import android.widget.TextView
import android.widget.Toast
import androidx.core.view.isInvisible
import androidx.preference.Preference
-
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.permissions.Permissions
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
+import org.thoughtcrime.securesms.ui.getSubbedString
class HelpSettingsActivity: PassphraseRequiredActionBarActivity() {
@@ -30,20 +32,27 @@ class HelpSettingsActivity: PassphraseRequiredActionBarActivity() {
class HelpSettingsFragment: CorrectedPreferenceFragment() {
companion object {
- private const val EXPORT_LOGS = "export_logs"
- private const val TRANSLATE = "translate_session"
- private const val FEEDBACK = "feedback"
- private const val FAQ = "faq"
- private const val SUPPORT = "support"
-
- private const val CROWDIN_URL = "https://getsession.org/translate"
+ private const val EXPORT_LOGS = "export_logs"
+ private const val TRANSLATE = "translate_session"
+ private const val FEEDBACK = "feedback"
+ private const val FAQ = "faq"
+ private const val SUPPORT = "support"
+ private const val CROWDIN_URL = "https://getsession.org/translate"
private const val FEEDBACK_URL = "https://getsession.org/survey"
- private const val FAQ_URL = "https://getsession.org/faq"
- private const val SUPPORT_URL = "https://sessionapp.zendesk.com/hc/en-us"
+ private const val FAQ_URL = "https://getsession.org/faq"
+ private const val SUPPORT_URL = "https://sessionapp.zendesk.com/hc/en-us"
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences_help)
+
+ // String sub the summary text of the `export_logs` element in preferences_help.xml
+ val exportPref = preferenceScreen.findPreference(EXPORT_LOGS)
+ exportPref?.summary = context?.getSubbedCharSequence(R.string.helpReportABugExportLogsDescription, APP_NAME_KEY to getString(R.string.app_name))
+
+ // String sub the summary text of the `translate_session` element in preferences_help.xml
+ val translatePref = preferenceScreen.findPreference(TRANSLATE)
+ translatePref?.title = context?.getSubbedCharSequence(R.string.helpHelpUsTranslateSession, APP_NAME_KEY to getString(R.string.app_name))
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
@@ -77,7 +86,7 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
// Change export logs button text
val exportLogsButton = this.activity?.findViewById(R.id.export_logs_button) as TextView?
if (exportLogsButton == null) { Log.w("Loki", "Could not find export logs button view.") }
- exportLogsButton?.text = if (exportJobRunning) getString(R.string.cancel) else getString(R.string.activity_help_settings__export_logs)
+ exportLogsButton?.text = if (exportJobRunning) getString(R.string.cancel) else getString(R.string.helpReportABugExportLogs)
// Show progress bar
val exportProgressBar = this.activity?.findViewById(R.id.export_progress_bar) as ProgressBar?
@@ -89,9 +98,11 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
Permissions.with(this)
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.maxSdkVersion(Build.VERSION_CODES.P)
- .withPermanentDenialDialog(getString(R.string.MediaPreviewActivity_signal_needs_the_storage_permission_in_order_to_write_to_external_storage_but_it_has_been_permanently_denied))
+ .withPermanentDenialDialog(requireContext().getSubbedString(R.string.permissionsStorageSaveDenied, APP_NAME_KEY to getString(R.string.app_name)))
.onAnyDenied {
- Toast.makeText(requireActivity(), R.string.MediaPreviewActivity_unable_to_write_to_external_storage_without_permission, Toast.LENGTH_LONG).show()
+ val c = requireContext()
+ val txt = c.getSubbedString(R.string.permissionsStorageSaveDenied, APP_NAME_KEY to getString(R.string.app_name))
+ Toast.makeText(c, txt, Toast.LENGTH_LONG).show()
}
.onAllGranted {
ShareLogsDialog(::updateExportButtonAndProgressBarUI).show(parentFragmentManager,"Share Logs Dialog")
@@ -104,7 +115,7 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} catch (e: Exception) {
- Toast.makeText(requireActivity(), "Can't open URL", Toast.LENGTH_LONG).show()
+ Toast.makeText(requireActivity(), requireContext().getString(R.string.errorUnknown), Toast.LENGTH_LONG).show()
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java
index 4314b9ae62..a57c0ad728 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java
@@ -18,7 +18,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length
? listPref.getEntries()[entryIndex]
- : getString(R.string.preferences__led_color_unknown));
+ : getString(R.string.unknown));
return true;
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt
index 2a34de808b..0e32cc4335 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationSettingsActivity.kt
@@ -11,7 +11,7 @@ class NotificationSettingsActivity : PassphraseRequiredActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
setContentView(R.layout.activity_fragment_wrapper)
- supportActionBar!!.title = resources.getString(R.string.activity_notification_settings_title)
+ supportActionBar!!.title = resources.getString(R.string.sessionNotifications)
val fragment = NotificationsPreferenceFragment()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragmentContainer, fragment)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.kt
index 2d26284877..5614091473 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.kt
@@ -71,6 +71,7 @@ class NotificationsPreferenceFragment : ListSummaryPreferenceFragment() {
NotificationChannels.updateMessageVibrate(requireContext(), newValue as Boolean)
true
}
+
findPreference(TextSecurePreferences.RINGTONE_PREF)!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
val current = prefs.getNotificationRingtone()
@@ -89,10 +90,10 @@ class NotificationsPreferenceFragment : ListSummaryPreferenceFragment() {
startActivityForResult(intent, 1)
true
}
+
findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF)!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener { preference: Preference ->
val listPreference = preference as ListPreference
- listPreference.setDialogMessage(R.string.preferences_notifications__content_message)
listPreferenceDialog(requireContext(), listPreference) {
initializeListSummary(findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF))
}
@@ -138,7 +139,7 @@ class NotificationsPreferenceFragment : ListSummaryPreferenceFragment() {
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
val value = newValue as? Uri
if (value == null || TextUtils.isEmpty(value.toString())) {
- preference.setSummary(R.string.preferences__silent)
+ preference.setSummary(R.string.none)
} else {
RingtoneManager.getRingtone(activity, value)
?.getTitle(activity)
@@ -176,8 +177,8 @@ class NotificationsPreferenceFragment : ListSummaryPreferenceFragment() {
@Suppress("unused")
private val TAG = NotificationsPreferenceFragment::class.java.simpleName
fun getSummary(context: Context): CharSequence = when (isNotificationsEnabled(context)) {
- true -> R.string.ApplicationPreferencesActivity_On
- false -> R.string.ApplicationPreferencesActivity_Off
+ true -> R.string.on
+ false -> R.string.off
}.let(context::getString)
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsActivity.kt
index de136694ff..7d8e254205 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsActivity.kt
@@ -11,8 +11,7 @@ class PrivacySettingsActivity : PassphraseRequiredActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
setContentView(R.layout.activity_fragment_wrapper)
- val fragment =
- PrivacySettingsPreferenceFragment()
+ val fragment = PrivacySettingsPreferenceFragment()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragmentContainer, fragment)
transaction.commit()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsPreferenceFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsPreferenceFragment.kt
index 8404a4f8e2..361f7b5fd5 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsPreferenceFragment.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsPreferenceFragment.kt
@@ -3,14 +3,13 @@ package org.thoughtcrime.securesms.preferences
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
-import android.net.Uri
-import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceDataStore
import dagger.hilt.android.AndroidEntryPoint
+import javax.inject.Inject
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
import org.session.libsession.utilities.TextSecurePreferences
@@ -24,7 +23,6 @@ import org.thoughtcrime.securesms.service.KeyCachingService
import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.areNotificationsEnabled
import org.thoughtcrime.securesms.util.IntentUtils
-import javax.inject.Inject
@AndroidEntryPoint
class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
@@ -39,7 +37,7 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
.onPreferenceChangeListener = TypingIndicatorsToggleListener()
findPreference(TextSecurePreferences.CALL_NOTIFICATIONS_ENABLED)!!
.onPreferenceChangeListener = CallToggleListener(this) { setCall(it) }
- findPreference(getString(R.string.preferences__message_requests_category))?.let { category ->
+ findPreference(getString(R.string.sessionMessageRequests))?.let { category ->
when (val user = configFactory.user) {
null -> category.isVisible = false
else -> SwitchPreferenceCompat(requireContext()).apply {
@@ -61,8 +59,8 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
super.putBoolean(key, value)
}
}
- title = getString(R.string.preferences__message_requests_title)
- summary = getString(R.string.preferences__message_requests_summary)
+ title = getString(R.string.messageRequestsCommunities)
+ summary = getString(R.string.messageRequestsCommunitiesDescription)
}.let(category::addPreference)
}
}
@@ -75,9 +73,9 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
if (isEnabled && !areNotificationsEnabled(requireActivity())) {
// show a dialog saying that calls won't work properly if you don't have notifications on at a system level
showSessionDialog {
- title(R.string.CallNotificationBuilder_system_notification_title)
- text(R.string.CallNotificationBuilder_system_notification_message)
- button(R.string.activity_notification_settings_title) {
+ title(R.string.sessionNotifications)
+ text(R.string.callsNotificationsRequired)
+ button(R.string.sessionNotifications) {
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -100,7 +98,7 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
- addPreferencesFromResource(R.xml.preferences_app_protection)
+ addPreferencesFromResource(R.xml.preferences_privacy)
}
override fun onResume() {
@@ -113,6 +111,8 @@ class PrivacySettingsPreferenceFragment : ListSummaryPreferenceFragment() {
requireContext().getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (!keyguardManager.isKeyguardSecure) {
findPreference(TextSecurePreferences.SCREEN_LOCK)!!.isChecked = false
+
+ // TODO: Ticket SES-2182 raised to investigate & fix app lock / unlock functionality -ACL 2024/06/20
findPreference(TextSecurePreferences.SCREEN_LOCK)!!.isEnabled = false
}
} else {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/QRCodeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/QRCodeActivity.kt
index 52cb345fab..fbf0affb8c 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/QRCodeActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/QRCodeActivity.kt
@@ -43,7 +43,7 @@ class QRCodeActivity : PassphraseRequiredActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
- supportActionBar!!.title = resources.getString(R.string.activity_qr_code_title)
+ supportActionBar!!.title = resources.getString(R.string.qrCode)
setComposeContent {
Tabs(
@@ -56,7 +56,7 @@ class QRCodeActivity : PassphraseRequiredActionBarActivity() {
private fun onScan(string: String) {
if (!PublicKeyValidation.isValid(string)) {
- errors.tryEmit(getString(R.string.this_qr_code_does_not_contain_an_account_id))
+ errors.tryEmit(getString(R.string.qrNotAccountId))
} else if (!isFinishing) {
val recipient = Recipient.from(this, Address.fromSerialized(string), false)
start {
@@ -101,12 +101,12 @@ fun QrPage(string: String) {
string = string,
modifier = Modifier
.padding(top = LocalDimensions.current.mediumSpacing, bottom = LocalDimensions.current.xsSpacing)
- .contentDescription(R.string.AccessibilityId_qr_code),
+ .contentDescription(R.string.AccessibilityId_qrCode),
icon = R.drawable.session
)
Text(
- text = stringResource(R.string.this_is_your_account_id_other_users_can_scan_it_to_start_a_conversation_with_you),
+ text = stringResource(R.string.accountIdYoursDescription),
color = LocalColors.current.textSecondary,
textAlign = TextAlign.Center,
style = LocalType.current.small
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt
index 1a77201bc9..bfba7377a7 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsActivity.kt
@@ -36,7 +36,10 @@ import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.canhub.cropper.CropImage
import com.canhub.cropper.CropImageContract
+import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
+import java.io.File
+import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@@ -57,9 +60,11 @@ import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.snode.OnionRequestAPI
import org.session.libsession.snode.SnodeAPI
import org.session.libsession.utilities.Address
+import org.session.libsession.utilities.NonTranslatableStringConstants.DEBUG_MENU
import org.session.libsession.utilities.ProfileKeyUtil
import org.session.libsession.utilities.ProfilePictureUtilities
import org.session.libsession.utilities.SSKEnvironment.ProfileManagerProtocol
+import org.session.libsession.utilities.StringSubstitutionConstants.VERSION_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsession.utilities.truncateIdForDisplay
@@ -92,8 +97,7 @@ import org.thoughtcrime.securesms.util.BitmapUtil
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.NetworkUtils
import org.thoughtcrime.securesms.util.push
-import java.io.File
-import javax.inject.Inject
+import org.thoughtcrime.securesms.util.show
@AndroidEntryPoint
class SettingsActivity : PassphraseRequiredActionBarActivity() {
@@ -178,7 +182,9 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
publicKeyTextView.text = hexEncodedPublicKey
val gitCommitFirstSixChars = BuildConfig.GIT_HASH.take(6)
val environment: String = if(BuildConfig.BUILD_TYPE == "release") "" else " - ${prefs.getEnvironment().label}"
- versionTextView.text = String.format(getString(R.string.version_s), "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE} - $gitCommitFirstSixChars) $environment")
+ val versionDetails = " ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE} - $gitCommitFirstSixChars) $environment"
+ val versionString = Phrase.from(applicationContext, R.string.updateVersion).put(VERSION_KEY, versionDetails).format()
+ versionTextView.text = versionString
}
binding.composeView.setThemedContent {
@@ -219,7 +225,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.settings_general, menu)
if (BuildConfig.DEBUG) {
- menu.findItem(R.id.action_qr_code)?.contentDescription = resources.getString(R.string.AccessibilityId_view_qr_code)
+ menu.findItem(R.id.action_qr_code)?.contentDescription = resources.getString(R.string.AccessibilityId_qrView)
}
return true
}
@@ -397,24 +403,30 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
*/
private fun saveDisplayName(): Boolean {
val displayName = binding.displayNameEditText.text.toString().trim()
+
if (displayName.isEmpty()) {
- Toast.makeText(this, R.string.activity_settings_display_name_missing_error, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.displayNameErrorDescription, Toast.LENGTH_SHORT).show()
return false
}
+
if (displayName.toByteArray().size > ProfileManagerProtocol.NAME_PADDED_LENGTH) {
- Toast.makeText(this, R.string.activity_settings_display_name_too_long_error, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.displayNameErrorDescriptionShorter, Toast.LENGTH_SHORT).show()
return false
}
+
return updateDisplayName(displayName)
}
private fun showEditProfilePictureUI() {
showSessionDialog {
- title(R.string.activity_settings_set_display_picture)
+ title(R.string.profileDisplayPictureSet)
view(R.layout.dialog_change_avatar)
- button(R.string.activity_settings_upload) { startAvatarSelection() }
+
+ // Note: This is the only instance in a dialog where the "Save" button is not a `dangerButton`
+ button(R.string.save) { startAvatarSelection() }
+
if (prefs.getProfileAvatarId() != 0) {
- button(R.string.activity_settings_remove) { removeProfilePicture() }
+ button(R.string.remove) { removeProfilePicture() }
}
cancelButton()
}.apply {
@@ -453,7 +465,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
private inner class DisplayNameEditActionModeCallback: ActionMode.Callback {
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
- mode.title = getString(R.string.activity_settings_display_name_edit_text_hint)
+ mode.title = getString(R.string.displayNameEnter)
mode.menuInflater.inflate(R.menu.menu_apply, menu)
this@SettingsActivity.displayNameEditActionMode = mode
return true
@@ -511,33 +523,55 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
Column {
// add the debug menu in non release builds
if (BuildConfig.BUILD_TYPE != "release") {
- LargeItemButton(R.string.activity_settings_debug_button_title, R.drawable.ic_settings) { push() }
+ LargeItemButton(DEBUG_MENU, R.drawable.ic_settings) { push() }
Divider()
}
Crossfade(if (hasPaths) R.drawable.ic_status else R.drawable.ic_path_yellow, label = "path") {
- LargeItemButtonWithDrawable(R.string.activity_path_title, it) { push() }
+ LargeItemButtonWithDrawable(R.string.onionRoutingPath, it) { push() }
}
Divider()
- LargeItemButton(R.string.activity_settings_privacy_button_title, R.drawable.ic_privacy_icon) { push() }
+
+ LargeItemButton(R.string.sessionPrivacy, R.drawable.ic_privacy_icon) { push() }
Divider()
- LargeItemButton(R.string.activity_settings_notifications_button_title, R.drawable.ic_speaker, Modifier.contentDescription(R.string.AccessibilityId_notifications)) { push() }
+
+ LargeItemButton(R.string.sessionNotifications, R.drawable.ic_speaker, Modifier.contentDescription(R.string.AccessibilityId_notifications)) { push() }
Divider()
- LargeItemButton(R.string.activity_settings_conversations_button_title, R.drawable.ic_conversations, Modifier.contentDescription(R.string.AccessibilityId_conversations)) { push() }
+
+ LargeItemButton(R.string.sessionConversations, R.drawable.ic_conversations, Modifier.contentDescription(R.string.AccessibilityId_sessionConversations)) { push() }
Divider()
- LargeItemButton(R.string.activity_settings_message_requests_button_title, R.drawable.ic_message_requests, Modifier.contentDescription(R.string.AccessibilityId_message_requests)) { push() }
+
+ LargeItemButton(R.string.sessionMessageRequests, R.drawable.ic_message_requests, Modifier.contentDescription(R.string.AccessibilityId_sessionMessageRequests)) { push() }
Divider()
- LargeItemButton(R.string.activity_settings_message_appearance_button_title, R.drawable.ic_appearance, Modifier.contentDescription(R.string.AccessibilityId_appearance)) { push() }
+
+ LargeItemButton(R.string.sessionAppearance, R.drawable.ic_appearance, Modifier.contentDescription(R.string.AccessibilityId_sessionAppearance)) { push() }
Divider()
- LargeItemButton(R.string.activity_settings_invite_button_title, R.drawable.ic_invite_friend, Modifier.contentDescription(R.string.AccessibilityId_invite_friend)) { sendInvitationToUseSession() }
+
+ LargeItemButton(
+ R.string.sessionInviteAFriend,
+ R.drawable.ic_invite_friend,
+ Modifier.contentDescription(R.string.AccessibilityId_sessionInviteAFriend)
+ ) { sendInvitationToUseSession() }
Divider()
+
+ // Only show the recovery password option if the user has not chosen to permanently hide it
if (!prefs.getHidePassword()) {
- LargeItemButton(R.string.sessionRecoveryPassword, R.drawable.ic_shield_outline, Modifier.contentDescription(R.string.AccessibilityId_recovery_password_menu_item)) { push() }
+ LargeItemButton(
+ R.string.sessionRecoveryPassword,
+ R.drawable.ic_shield_outline,
+ Modifier.contentDescription(R.string.AccessibilityId_sessionRecoveryPasswordMenuItem)
+ ) { push() }
Divider()
}
- LargeItemButton(R.string.activity_settings_help_button, R.drawable.ic_help, Modifier.contentDescription(R.string.AccessibilityId_help)) { push() }
+
+ LargeItemButton(R.string.sessionHelp, R.drawable.ic_help, Modifier.contentDescription(R.string.AccessibilityId_help)) { push() }
Divider()
- LargeItemButton(R.string.activity_settings_clear_all_data_button_title, R.drawable.ic_delete, Modifier.contentDescription(R.string.AccessibilityId_clear_data), dangerButtonColors()) { ClearAllDataDialog().show(supportFragmentManager, "Clear All Data Dialog") }
+
+ LargeItemButton(R.string.sessionClearData,
+ R.drawable.ic_delete,
+ Modifier.contentDescription(R.string.AccessibilityId_sessionClearData),
+ dangerButtonColors()
+ ) { ClearAllDataDialog().show(supportFragmentManager, "Clear All Data Dialog") }
}
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt
index 9bfc1dabf2..29ce563c5d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ShareLogsDialog.kt
@@ -11,22 +11,23 @@ import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.webkit.MimeTypeMap
-import android.widget.ProgressBar
-import android.widget.TextView
import android.widget.Toast
-import androidx.core.view.isInvisible
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
-
+import com.squareup.phrase.Phrase
+import java.io.File
+import java.io.FileOutputStream
+import java.io.IOException
+import java.util.Objects
+import java.util.concurrent.TimeUnit
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
-
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
-
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsignal.utilities.ExternalStorageUtil
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.ApplicationContext
@@ -34,21 +35,18 @@ import org.thoughtcrime.securesms.createSessionDialog
import org.thoughtcrime.securesms.util.FileProviderUtil
import org.thoughtcrime.securesms.util.StreamUtil
-import java.io.File
-import java.io.FileOutputStream
-import java.io.IOException
-import java.util.Objects
-import java.util.concurrent.TimeUnit
-
-
class ShareLogsDialog(private val updateCallback: (Boolean)->Unit): DialogFragment() {
private val TAG = "ShareLogsDialog"
private var shareJob: Job? = null
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = createSessionDialog {
- title(R.string.dialog_share_logs_title)
- text(R.string.dialog_share_logs_explanation)
+ title(R.string.helpReportABugExportLogs)
+ val appName = context.getString(R.string.app_name)
+ val txt = Phrase.from(context, R.string.helpReportABugDescription)
+ .put(APP_NAME_KEY, appName)
+ .format().toString()
+ text(txt)
button(R.string.share, dismiss = false) { runShareLogsJob() }
cancelButton { updateCallback(false) }
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/Util.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/Util.kt
index 1271ece02e..a136dab26b 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/Util.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/Util.kt
@@ -5,21 +5,31 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.widget.Toast
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.ACCOUNT_ID_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
+import org.session.libsession.utilities.StringSubstitutionConstants.DOWNLOAD_URL_KEY
import org.session.libsession.utilities.TextSecurePreferences
fun Context.sendInvitationToUseSession() {
+
+ val DOWNLOAD_URL = "https://getsession.org/download"
+
+ val txt = Phrase.from(getString(R.string.accountIdShare))
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .put(ACCOUNT_ID_KEY, TextSecurePreferences.getLocalNumber(this@sendInvitationToUseSession))
+ .put(DOWNLOAD_URL_KEY, DOWNLOAD_URL)
+ .format().toString()
+
Intent().apply {
action = Intent.ACTION_SEND
putExtra(
Intent.EXTRA_TEXT,
- getString(
- R.string.accountIdShare,
- TextSecurePreferences.getLocalNumber(this@sendInvitationToUseSession)
- )
+ txt
)
type = "text/plain"
- }.let { Intent.createChooser(it, getString(R.string.activity_settings_invite_button_title)) }
+ }.let { Intent.createChooser(it, getString(R.string.sessionInviteAFriend)) }
.let(::startActivity)
}
@@ -27,5 +37,5 @@ fun Context.copyPublicKey() {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Account ID", TextSecurePreferences.getLocalNumber(this))
clipboard.setPrimaryClip(clip)
- Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, R.string.copied, Toast.LENGTH_SHORT).show()
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsActivity.kt
index 34547c999e..ddf28e9211 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/appearance/AppearanceSettingsActivity.kt
@@ -116,7 +116,7 @@ class AppearanceSettingsActivity: PassphraseRequiredActionBarActivity(), View.On
setContentView(binding.root)
savedInstanceState?.getSparseParcelableArray(SCROLL_PARCEL)
?.let(binding.scrollView::restoreHierarchyState)
- supportActionBar!!.title = getString(R.string.activity_settings_message_appearance_button_title)
+ supportActionBar!!.title = getString(R.string.sessionAppearance)
with (binding) {
// accent toggles
accentContainer.children.forEach { view ->
diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java
index 6cafc6035f..1c483a43e7 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/widgets/SignalListPreference.java
@@ -1,13 +1,10 @@
package org.thoughtcrime.securesms.preferences.widgets;
-
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
-
import androidx.preference.ListPreference;
import androidx.preference.PreferenceViewHolder;
-
import network.loki.messenger.R;
public class SignalListPreference extends ListPreference {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java
index 05817f4923..37bd7e4695 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java
@@ -7,20 +7,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
-
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
-
-import org.session.libsession.messaging.utilities.AccountId;
+import java.util.Collections;
+import java.util.List;
+import network.loki.messenger.R;
import org.thoughtcrime.securesms.components.ProfilePictureView;
import org.thoughtcrime.securesms.components.emoji.EmojiImageView;
import org.thoughtcrime.securesms.database.model.MessageId;
-import com.bumptech.glide.Glide;
-
-import java.util.Collections;
-import java.util.List;
-
-import network.loki.messenger.R;
final class ReactionRecipientsAdapter extends RecyclerView.Adapter {
@@ -159,11 +153,11 @@ final class ReactionRecipientsAdapter extends RecyclerView.Adapter 5) {
TextView count = itemView.findViewById(R.id.footer_view_emoji_count);
- count.setText(itemView.getContext().getResources().getQuantityString(R.plurals.ReactionsRecipientAdapter_other_reactors, emoji.getCount() - 5, emoji.getCount() - 5, emoji.getBaseEmoji()));
+
+ // We display the first 5 people to react w/ a given emoji so we'll subtract that to get the 'others' count
+ int othersCount = emoji.getCount() - 5;
+ String s = itemView.getResources().getQuantityString(R.plurals.emojiReactsCountOthers, othersCount, othersCount, emoji.getBaseEmoji());
+ count.setText(s);
+
itemView.setVisibility(View.VISIBLE);
} else {
itemView.setVisibility(View.GONE);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/reactions/any/ReactWithAnyEmojiRepository.java b/app/src/main/java/org/thoughtcrime/securesms/reactions/any/ReactWithAnyEmojiRepository.java
index e17634a7a7..bab8591cb6 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/reactions/any/ReactWithAnyEmojiRepository.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/reactions/any/ReactWithAnyEmojiRepository.java
@@ -31,7 +31,6 @@ final class ReactWithAnyEmojiRepository {
this.emojiPages = new LinkedList<>();
emojiPages.addAll(Stream.of(EmojiSource.getLatest().getDisplayPages())
- .filterNot(p -> p.getIconAttr() == EmojiCategory.EMOTICONS.getIcon())
.map(page -> new ReactWithAnyEmojiPage(Collections.singletonList(new ReactWithAnyEmojiPageBlock(EmojiCategory.getCategoryLabel(page.getIconAttr()), page))))
.toList());
}
@@ -39,7 +38,7 @@ final class ReactWithAnyEmojiRepository {
List getEmojiPageModels() {
List pages = new LinkedList<>();
- pages.add(new ReactWithAnyEmojiPage(Collections.singletonList(new ReactWithAnyEmojiPageBlock(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__recently_used, recentEmojiPageModel))));
+ pages.add(new ReactWithAnyEmojiPage(Collections.singletonList(new ReactWithAnyEmojiPageBlock(R.string.emojiCategoryRecentlyUsed, recentEmojiPageModel))));
pages.addAll(emojiPages);
return pages;
diff --git a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt
index 0b47708b5d..4bc2724d6d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt
@@ -51,7 +51,7 @@ internal fun RecoveryPasswordScreen(
Column(
verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing),
modifier = Modifier
- .contentDescription(R.string.AccessibilityId_recovery_password)
+ .contentDescription(R.string.AccessibilityId_sessionRecoveryPassword)
.verticalScroll(rememberScrollState())
.padding(bottom = LocalDimensions.current.smallSpacing)
.padding(horizontal = LocalDimensions.current.spacing)
@@ -103,7 +103,7 @@ private fun RecoveryPasswordCell(
seed,
modifier = Modifier
.padding(vertical = LocalDimensions.current.spacing)
- .contentDescription(R.string.AccessibilityId_qr_code),
+ .contentDescription(R.string.AccessibilityId_qrCode),
contentPadding = 10.dp,
icon = R.drawable.session_shield
)
@@ -140,7 +140,7 @@ private fun RecoveryPassword(mnemonic: String) {
Text(
mnemonic,
modifier = Modifier
- .contentDescription(R.string.AccessibilityId_recovery_password_container)
+ .contentDescription(R.string.AccessibilityId_sessionRecoveryPasswordContainer)
.padding(vertical = LocalDimensions.current.spacing)
.border()
.padding(LocalDimensions.current.spacing),
@@ -174,7 +174,7 @@ private fun HideRecoveryPasswordCell(onHide: () -> Unit = {}) {
modifier = Modifier
.wrapContentWidth()
.align(Alignment.CenterVertically)
- .contentDescription(R.string.AccessibilityId_hide_recovery_password_button),
+ .contentDescription(R.string.AccessibilityId_recoveryPasswordHideRecoveryPassword),
color = LocalColors.current.danger,
onClick = onHide
)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt
index a46b4a1d63..62b602f6f3 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt
@@ -34,7 +34,7 @@ class RecoveryPasswordActivity : BaseActionBarActivity() {
showSessionDialog {
title(R.string.recoveryPasswordHidePermanently)
htmlText(R.string.recoveryPasswordHidePermanentlyDescription1)
- dangerButton(R.string.continue_2, R.string.AccessibilityId_continue) { onHideConfirm() }
+ dangerButton(R.string.theContinue, R.string.AccessibilityId_theContinue) { onHideConfirm() }
cancelButton()
}
}
@@ -46,7 +46,7 @@ class RecoveryPasswordActivity : BaseActionBarActivity() {
cancelButton()
dangerButton(
R.string.yes,
- contentDescription = R.string.AccessibilityId_confirm_button
+ contentDescription = R.string.AccessibilityId_recoveryPasswordHidePermanentlyConfirm
) {
viewModel.permanentlyHidePassword()
finish()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java
index cf250665ef..9d95ac5d49 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/service/KeyCachingService.java
@@ -16,6 +16,8 @@
*/
package org.thoughtcrime.securesms.service;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
+
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.Notification;
@@ -31,12 +33,13 @@ import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.SystemClock;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.app.ServiceCompat;
-
+import com.squareup.phrase.Phrase;
+import java.util.concurrent.TimeUnit;
+import network.loki.messenger.R;
import org.session.libsession.utilities.ServiceUtil;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsignal.utilities.Log;
@@ -46,16 +49,12 @@ import org.thoughtcrime.securesms.DummyActivity;
import org.thoughtcrime.securesms.home.HomeActivity;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
-import java.util.concurrent.TimeUnit;
-
-import network.loki.messenger.R;
-
/**
* Small service that stays running to keep a key cached in memory.
*
* @author Moxie Marlinspike
*/
-//TODO AC: This service does only serve one purpose now - to track the screen lock state and handle the timer.
+// TODO: This service does only serve one purpose now - to track the screen lock state and handle the timer.
// We need to refactor it and cleanup from all the old Signal code.
public class KeyCachingService extends Service {
@@ -71,7 +70,7 @@ public class KeyCachingService extends Service {
private final IBinder binder = new KeySetBinder();
- // AC: This is a temporal drop off replacement for the refactoring time being.
+ // This is a temporal drop off replacement for the refactoring time being.
// This field only indicates if the app was unlocked or not (null means locked).
private static Object masterSecret = null;
@@ -243,13 +242,19 @@ public class KeyCachingService extends Service {
Log.i(TAG, "foregrounding KCS");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannels.LOCKED_STATUS);
- builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached));
- builder.setContentText(getString(R.string.KeyCachingService_signal_passphrase_cached));
+ // Replace app name in title string
+ Context c = getApplicationContext();
+ String unlockedTxt = Phrase.from(c, R.string.lockAppUnlocked)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+ builder.setContentTitle(unlockedTxt);
+
+ builder.setContentText(getString(R.string.lockAppUnlock));
builder.setSmallIcon(R.drawable.icon_cached);
builder.setWhen(0);
builder.setPriority(Notification.PRIORITY_MIN);
- builder.addAction(R.drawable.ic_menu_lock_dark, getString(R.string.KeyCachingService_lock), buildLockIntent());
+ builder.addAction(R.drawable.ic_menu_lock_dark, getString(R.string.lockApp), buildLockIntent());
builder.setContentIntent(buildLaunchIntent());
stopForeground(true);
diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/QuickResponseService.java b/app/src/main/java/org/thoughtcrime/securesms/service/QuickResponseService.java
index a56bc8c0de..22f0addd71 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/service/QuickResponseService.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/service/QuickResponseService.java
@@ -1,23 +1,24 @@
package org.thoughtcrime.securesms.service;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
+
import android.app.IntentService;
+import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.widget.Toast;
-
+import com.squareup.phrase.Phrase;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
import network.loki.messenger.R;
-
import org.session.libsession.messaging.messages.visible.VisibleMessage;
+import org.session.libsession.messaging.sending_receiving.MessageSender;
import org.session.libsession.snode.SnodeAPI;
import org.session.libsession.utilities.Address;
import org.session.libsignal.utilities.Log;
-import org.session.libsession.messaging.sending_receiving.MessageSender;
import org.thoughtcrime.securesms.util.Rfc5724Uri;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-
public class QuickResponseService extends IntentService {
private static final String TAG = QuickResponseService.class.getSimpleName();
@@ -28,14 +29,29 @@ public class QuickResponseService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
- if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
+ if (intent == null) {
+ Log.w(TAG, "Got null intent from QuickResponseService");
+ return;
+ }
+
+ String actionString = intent.getAction();
+ if (actionString == null) {
+ Log.w(TAG, "Got null action from QuickResponseService intent");
+ return;
+ }
+
+ if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(actionString)) {
Log.w(TAG, "Received unknown intent: " + intent.getAction());
return;
}
if (KeyCachingService.isLocked(this)) {
Log.w(TAG, "Got quick response request when locked...");
- Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
+ Context c = getApplicationContext();
+ String txt = Phrase.from(c, R.string.lockAppQuickResponse)
+ .put(APP_NAME_KEY, c.getString(R.string.app_name))
+ .format().toString();
+ Toast.makeText(this, txt, Toast.LENGTH_LONG).show();
return;
}
@@ -55,7 +71,7 @@ public class QuickResponseService extends IntentService {
MessageSender.send(message, Address.fromExternal(this, number));
}
} catch (URISyntaxException e) {
- Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
+ Toast.makeText(this, R.string.errorUnknown, Toast.LENGTH_LONG).show();
Log.w(TAG, e);
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java b/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java
index eea6ba00f8..85d00ec8e5 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java
@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.service;
+import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
import android.app.DownloadManager;
import android.app.Notification;
@@ -9,10 +10,14 @@ import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
-
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
-
+import com.squareup.phrase.Phrase;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.MessageDigest;
+import network.loki.messenger.R;
import org.session.libsession.utilities.FileUtils;
import org.session.libsession.utilities.ServiceUtil;
import org.session.libsession.utilities.TextSecurePreferences;
@@ -21,13 +26,6 @@ import org.session.libsignal.utilities.Log;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.util.FileProviderUtil;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.security.MessageDigest;
-
-import network.loki.messenger.R;
-
public class UpdateApkReadyListener extends BroadcastReceiver {
private static final String TAG = UpdateApkReadyListener.class.getSimpleName();
@@ -64,10 +62,17 @@ public class UpdateApkReadyListener extends BroadcastReceiver {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
+ CharSequence title = Phrase.from(context, R.string.updateSession)
+ .put(APP_NAME_KEY, context.getString(R.string.app_name)).format();
+
+ CharSequence txt = Phrase.from(context, R.string.updateNewVersion)
+ .put(APP_NAME_KEY, context.getString(R.string.app_name)).format();
+
+
Notification notification = new NotificationCompat.Builder(context, NotificationChannels.APP_UPDATES)
.setOngoing(true)
- .setContentTitle(context.getString(R.string.UpdateApkReadyListener_Signal_update))
- .setContentText(context.getString(R.string.UpdateApkReadyListener_a_new_version_of_signal_is_available_tap_to_update))
+ .setContentTitle(title)
+ .setContentText(txt)
.setSmallIcon(R.drawable.ic_notification)
.setColor(context.getResources().getColor(R.color.textsecure_primary))
.setPriority(NotificationCompat.PRIORITY_HIGH)
@@ -118,4 +123,4 @@ public class UpdateApkReadyListener extends BroadcastReceiver {
return false;
}
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt
index 552e24cc58..fed01640e4 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt
@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.ui
+import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
@@ -12,7 +13,8 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
@@ -26,13 +28,24 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.takeOrElse
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.max
+import androidx.compose.ui.unit.times
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.URL_KEY
+import org.thoughtcrime.securesms.copyURLToClipboard
+import org.thoughtcrime.securesms.openUrl
import org.thoughtcrime.securesms.ui.components.CircularProgressIndicator
+import org.thoughtcrime.securesms.ui.components.annotatedStringResource
import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
@@ -48,13 +61,37 @@ class DialogButtonModel(
val onClick: () -> Unit = {},
)
-@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AlertDialog(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
title: String? = null,
text: String? = null,
+ maxLines: Int? = null,
+ buttons: List? = null,
+ showCloseButton: Boolean = false,
+ content: @Composable () -> Unit = {}
+) {
+ AlertDialog(
+ onDismissRequest = onDismissRequest,
+ modifier = modifier,
+ title = if(title != null) AnnotatedString(title) else null,
+ text = if(text != null) AnnotatedString(text) else null,
+ maxLines = maxLines,
+ buttons = buttons,
+ showCloseButton = showCloseButton,
+ content = content
+ )
+}
+
+@OptIn(ExperimentalMaterial3Api::class)
+@Composable
+fun AlertDialog(
+ onDismissRequest: () -> Unit,
+ modifier: Modifier = Modifier,
+ title: AnnotatedString? = null,
+ text: AnnotatedString? = null,
+ maxLines: Int? = null,
buttons: List? = null,
showCloseButton: Boolean = false,
content: @Composable () -> Unit = {}
@@ -88,18 +125,32 @@ fun AlertDialog(
) {
title?.let {
Text(
- it,
+ text = it,
textAlign = TextAlign.Center,
style = LocalType.current.h7,
modifier = Modifier.padding(bottom = LocalDimensions.current.xxsSpacing)
)
}
text?.let {
+ val textStyle = LocalType.current.large
+ var textModifier = Modifier.padding(bottom = LocalDimensions.current.xxsSpacing)
+
+ // if we have a maxLines, make the text scrollable
+ if(maxLines != null) {
+ val textHeight = with(LocalDensity.current) {
+ textStyle.lineHeight.toDp()
+ } * maxLines
+
+ textModifier = textModifier
+ .height(textHeight)
+ .verticalScroll(rememberScrollState())
+ }
+
Text(
- it,
+ text = it,
textAlign = TextAlign.Center,
- style = LocalType.current.large,
- modifier = Modifier.padding(bottom = LocalDimensions.current.xxsSpacing)
+ style = textStyle,
+ modifier = textModifier
)
}
content()
@@ -127,6 +178,45 @@ fun AlertDialog(
)
}
+@Composable
+fun OpenURLAlertDialog(
+ onDismissRequest: () -> Unit,
+ modifier: Modifier = Modifier,
+ url: String,
+ content: @Composable () -> Unit = {}
+) {
+ val context = LocalContext.current
+ val unformattedText = Phrase.from(context.getText(R.string.urlOpenDescription))
+ .put(URL_KEY, url).format()
+
+
+ AlertDialog(
+ modifier = modifier,
+ title = AnnotatedString(stringResource(R.string.urlOpen)),
+ text = annotatedStringResource(text = unformattedText),
+ maxLines = 5,
+ showCloseButton = true, // display the 'x' button
+ buttons = listOf(
+ DialogButtonModel(
+ text = GetString(R.string.open),
+ contentDescription = GetString(R.string.AccessibilityId_urlOpenBrowser),
+ color = LocalColors.current.danger,
+ onClick = { context.openUrl(url) }
+ ),
+ DialogButtonModel(
+ text = GetString(android.R.string.copyUrl),
+ contentDescription = GetString(R.string.AccessibilityId_copy),
+ onClick = {
+ context.copyURLToClipboard(url)
+ Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).show()
+ }
+ )
+ ),
+ onDismissRequest = onDismissRequest,
+ content = content
+ )
+}
+
@Composable
fun DialogButton(
text: String,
@@ -214,15 +304,15 @@ fun PreviewSimpleDialog() {
AlertDialog(
onDismissRequest = {},
title = stringResource(R.string.warning),
- text = stringResource(R.string.you_cannot_go_back_further_in_order_to_stop_loading_your_account_session_needs_to_quit),
+ text = stringResource(R.string.onboardingBackAccountCreation),
buttons = listOf(
DialogButtonModel(
- GetString(stringResource(R.string.quit)),
+ GetString(stringResource(R.string.cancel)),
color = LocalColors.current.danger,
- onClick = {}
+ onClick = { }
),
DialogButtonModel(
- GetString(stringResource(R.string.cancel))
+ GetString(stringResource(R.string.ok))
)
)
)
@@ -239,13 +329,13 @@ fun PreviewXCloseDialog() {
showCloseButton = true, // display the 'x' button
buttons = listOf(
DialogButtonModel(
- text = GetString(R.string.activity_landing_terms_of_service),
- contentDescription = GetString(R.string.AccessibilityId_terms_of_service_button),
+ text = GetString(R.string.onboardingTos),
+ contentDescription = GetString(R.string.AccessibilityId_onboardingTos),
onClick = {}
),
DialogButtonModel(
- text = GetString(R.string.activity_landing_privacy_policy),
- contentDescription = GetString(R.string.AccessibilityId_privacy_policy_button),
+ text = GetString(R.string.onboardingPrivacy),
+ contentDescription = GetString(R.string.AccessibilityId_onboardingPrivacy),
onClick = {}
)
),
@@ -254,6 +344,17 @@ fun PreviewXCloseDialog() {
}
}
+@Preview
+@Composable
+fun PreviewOpenURLDialog() {
+ PreviewTheme {
+ OpenURLAlertDialog(
+ url = "https://getsession.org/",
+ onDismissRequest = {}
+ )
+ }
+}
+
@Preview
@Composable
fun PreviewLoadingDialog() {
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt
index df64f093ec..baf0c1f122 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt
@@ -11,8 +11,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.ColumnScope
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
@@ -174,6 +172,45 @@ fun LargeItemButton(
)
}
+@Composable
+fun LargeItemButton(
+ text: String,
+ @DrawableRes icon: Int,
+ modifier: Modifier = Modifier,
+ colors: ButtonColors = transparentButtonColors(),
+ onClick: () -> Unit
+) {
+ ItemButton(
+ text, icon, modifier.heightIn(min = LocalDimensions.current.minLargeItemButtonHeight),
+ LocalType.current.h8, colors, onClick
+ )
+}
+
+@Composable
+fun ItemButton(
+ text: String,
+ icon: Int,
+ modifier: Modifier,
+ textStyle: TextStyle = LocalType.current.xl,
+ colors: ButtonColors = transparentButtonColors(),
+ onClick: () -> Unit
+) {
+ ItemButton(
+ text = text,
+ modifier = modifier,
+ icon = {
+ Icon(
+ painter = painterResource(id = icon),
+ contentDescription = null,
+ modifier = Modifier.align(Alignment.Center)
+ )
+ },
+ textStyle = textStyle,
+ colors = colors,
+ onClick = onClick
+ )
+}
+
/**
* Courtesy [ItemButton] implementation that takes a [DrawableRes] for the [icon]
*/
@@ -246,10 +283,10 @@ fun ItemButton(
@Preview
@Composable
-fun PrewviewItemButton() {
+fun PreviewItemButton() {
PreviewTheme {
ItemButton(
- textId = R.string.activity_create_group_title,
+ textId = R.string.groupCreate,
icon = R.drawable.ic_group,
onClick = {}
)
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt
index b49f9c6d60..6f0bda8c96 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt
@@ -5,6 +5,7 @@ import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
+import com.squareup.phrase.Phrase
import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme
fun Activity.setComposeContent(content: @Composable () -> Unit) {
@@ -18,6 +19,21 @@ fun Context.createThemedComposeView(content: @Composable () -> Unit): ComposeVie
setThemedContent(content)
}
+// Extension method to use the Phrase library to substitute strings & return a CharSequence.
+// The pair is the key name, such as APP_NAME_KEY and the value is the localised string, such as context.getString(R.string.app_name).
+// Note: We cannot have Pair versions of this or the `getSubbedString` method because the JVM sees the signatures as identical.
+fun Context.getSubbedCharSequence(stringId: Int, vararg substitutionPairs: Pair): CharSequence {
+ val phrase = Phrase.from(this, stringId)
+ for ((key, value) in substitutionPairs) { phrase.put(key, value) }
+ return phrase.format()
+}
+
+// Extension method to use the Phrase library to substitute strings & return the substituted String.
+// The pair is the key name, such as APP_NAME_KEY and the value is the localised string, such as context.getString(R.string.app_name).
+fun Context.getSubbedString(stringId: Int, vararg substitutionPairs: Pair): String {
+ return getSubbedCharSequence(stringId, *substitutionPairs).toString()
+}
+
fun ComposeView.setThemedContent(content: @Composable () -> Unit) = setContent {
SessionMaterialTheme {
content()
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt
index 5834f2f859..a65b341a54 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt
@@ -177,7 +177,7 @@ fun OutlineCopyButton(
val interactionSource = remember { MutableInteractionSource() }
Button(
- modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button),
+ modifier = modifier.contentDescription(R.string.AccessibilityId_copy),
interactionSource = interactionSource,
style = style,
type = ButtonType.Outline(color),
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Html.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Html.kt
index 951db1816e..15f0292853 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Html.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Html.kt
@@ -14,6 +14,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
@@ -26,6 +27,9 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.core.text.HtmlCompat
+import com.squareup.phrase.Phrase
+import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.URL_KEY
// TODO Remove this file once we update to composeVersion=1.7.0-alpha06 fixes https://issuetracker.google.com/issues/139320238?pli=1
// which allows Stylized string in string resources
@@ -71,6 +75,14 @@ fun annotatedStringResource(@StringRes id: Int): AnnotatedString {
}
}
+@Composable
+fun annotatedStringResource(text: CharSequence): AnnotatedString {
+ val density = LocalDensity.current
+ return remember(text.hashCode()) {
+ spannableStringToAnnotatedString(text, density)
+ }
+}
+
private fun spannableStringToAnnotatedString(
text: CharSequence,
density: Density
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt
index 9661b3bc06..70b6634cb8 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt
@@ -55,10 +55,12 @@ import com.google.zxing.PlanarYUVLuminanceSource
import com.google.zxing.Result
import com.google.zxing.common.HybridBinarizer
import com.google.zxing.qrcode.QRCodeReader
+import com.squareup.phrase.Phrase
import java.util.concurrent.Executors
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
@@ -93,7 +95,10 @@ fun QRScannerScreen(
.padding(horizontal = 60.dp)
) {
Text(
- stringResource(R.string.activity_link_camera_permission_permanently_denied_configure_in_settings),
+ stringResource(R.string.cameraGrantAccessDenied).let { txt ->
+ val c = LocalContext.current
+ Phrase.from(txt).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString()
+ },
style = LocalType.current.base,
textAlign = TextAlign.Center
)
@@ -112,8 +117,14 @@ fun QRScannerScreen(
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.weight(1f))
- Text(stringResource(R.string.fragment_scan_qr_code_camera_access_explanation),
- style = LocalType.current.xl, textAlign = TextAlign.Center)
+ Text(
+ stringResource(R.string.cameraGrantAccessQr).let { txt ->
+ val c = LocalContext.current
+ Phrase.from(txt).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString()
+ },
+ style = LocalType.current.xl,
+ textAlign = TextAlign.Center
+ )
Spacer(modifier = Modifier.height(LocalDimensions.current.spacing))
PrimaryOutlineButton(
stringResource(R.string.cameraGrantAccess),
diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt
index 5e09f78b65..58e1ff8533 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Text.kt
@@ -134,7 +134,7 @@ fun SessionOutlinedTextField(
Text(
it,
modifier = Modifier.fillMaxWidth()
- .contentDescription(R.string.AccessibilityId_error_message),
+ .contentDescription(R.string.AccessibilityId_theError),
textAlign = TextAlign.Center,
style = LocalType.current.base.bold(),
color = LocalColors.current.danger
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt
index 0ba63fc549..4ffe12d006 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt
@@ -9,12 +9,16 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
+import com.squareup.phrase.Phrase
import network.loki.messenger.R
+import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.calls.WebRtcCallActivity
import org.thoughtcrime.securesms.notifications.NotificationChannels
import org.thoughtcrime.securesms.preferences.SettingsActivity
import org.thoughtcrime.securesms.service.WebRtcCallService
+import org.thoughtcrime.securesms.ui.getSubbedCharSequence
+import org.thoughtcrime.securesms.ui.getSubbedString
class CallNotificationBuilder {
@@ -34,21 +38,25 @@ class CallNotificationBuilder {
}
@JvmStatic
- fun getFirstCallNotification(context: Context): Notification {
+ fun getFirstCallNotification(context: Context, callerName: String): Notification {
val contentIntent = Intent(context, SettingsActivity::class.java)
val pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
- val text = context.getString(R.string.CallNotificationBuilder_first_call_message)
+ val titleTxt = context.getSubbedString(R.string.callsMissedCallFrom, NAME_KEY to callerName)
+ val bodyTxt = context.getSubbedCharSequence(
+ R.string.callsYouMissedCallPermissions,
+ NAME_KEY to callerName
+ )
val builder = NotificationCompat.Builder(context, NotificationChannels.CALLS)
.setSound(null)
.setSmallIcon(R.drawable.ic_baseline_call_24)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
- .setContentTitle(context.getString(R.string.CallNotificationBuilder_first_call_title))
- .setContentText(text)
- .setStyle(NotificationCompat.BigTextStyle().bigText(text))
+ .setContentTitle(titleTxt)
+ .setContentText(bodyTxt)
+ .setStyle(NotificationCompat.BigTextStyle().bigText(bodyTxt))
.setAutoCancel(true)
return builder.build()
@@ -67,27 +75,29 @@ class CallNotificationBuilder {
.setContentIntent(pendingIntent)
.setOngoing(true)
-
+ var recipName = "Unknown"
recipient?.name?.let { name ->
builder.setContentTitle(name)
+ recipName = name
}
when (type) {
TYPE_INCOMING_CONNECTING -> {
- builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting))
+ builder.setContentText(context.getString(R.string.callsConnecting))
.setNotificationSilent()
}
TYPE_INCOMING_PRE_OFFER,
TYPE_INCOMING_RINGING -> {
- builder.setContentText(context.getString(R.string.NotificationBarManager__incoming_signal_call))
+ val txt = Phrase.from(context, R.string.callsIncoming).put(NAME_KEY, recipName).format()
+ builder.setContentText(txt)
.setCategory(NotificationCompat.CATEGORY_CALL)
builder.addAction(getServiceNotificationAction(
context,
WebRtcCallService.ACTION_DENY_CALL,
R.drawable.ic_close_grey600_32dp,
- R.string.NotificationBarManager__deny_call
+ R.string.decline
))
- // if notifications aren't enabled, we will trigger the intent from WebRtcCallService
+ // If notifications aren't enabled, we will trigger the intent from WebRtcCallService
builder.setFullScreenIntent(getFullScreenPendingIntent(
context
), true)
@@ -95,26 +105,26 @@ class CallNotificationBuilder {
context,
if (type == TYPE_INCOMING_PRE_OFFER) WebRtcCallActivity.ACTION_PRE_OFFER else WebRtcCallActivity.ACTION_ANSWER,
R.drawable.ic_phone_grey600_32dp,
- R.string.NotificationBarManager__answer_call
+ R.string.accept
))
builder.priority = NotificationCompat.PRIORITY_MAX
}
TYPE_OUTGOING_RINGING -> {
- builder.setContentText(context.getString(R.string.NotificationBarManager__establishing_signal_call))
+ builder.setContentText(context.getString(R.string.callsConnecting))
builder.addAction(getServiceNotificationAction(
context,
WebRtcCallService.ACTION_LOCAL_HANGUP,
R.drawable.ic_call_end_grey600_32dp,
- R.string.NotificationBarManager__cancel_call
+ R.string.cancel
))
}
else -> {
- builder.setContentText(context.getString(R.string.NotificationBarManager_call_in_progress))
+ builder.setContentText(context.getString(R.string.callsInProgress))
builder.addAction(getServiceNotificationAction(
context,
WebRtcCallService.ACTION_LOCAL_HANGUP,
R.drawable.ic_call_end_grey600_32dp,
- R.string.NotificationBarManager__end_call
+ R.string.callsEnd
)).setUsesChronometer(true)
}
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java b/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java
index 7e65e63e8b..0d900ea391 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java
@@ -1,22 +1,15 @@
package org.thoughtcrime.securesms.util;
-import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
-import android.net.Uri;
import android.os.AsyncTask;
-import android.widget.Toast;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.TaskStackBuilder;
-
import org.session.libsession.utilities.recipients.Recipient;
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
-import network.loki.messenger.R;
-
public class CommunicationActions {
public static void startConversation(@NonNull Context context,
@@ -45,13 +38,4 @@ public class CommunicationActions {
}
}.execute();
}
-
- public static void openBrowserLink(@NonNull Context context, @NonNull String link) {
- try {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
- context.startActivity(intent);
- } catch (ActivityNotFoundException e) {
- Toast.makeText(context, R.string.CommunicationActions_no_browser_found, Toast.LENGTH_SHORT).show();
- }
- }
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.java b/app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.java
deleted file mode 100644
index 6fe2193c9b..0000000000
--- a/app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2014 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package org.thoughtcrime.securesms.util;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.text.format.DateFormat;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import org.session.libsignal.utilities.Log;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
-
-import network.loki.messenger.R;
-
-/**
- * Utility methods to help display dates in a nice, easily readable way.
- */
-public class DateUtils extends android.text.format.DateUtils {
-
- @SuppressWarnings("unused")
- private static final String TAG = DateUtils.class.getSimpleName();
- private static final SimpleDateFormat DAY_PRECISION_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
- private static final SimpleDateFormat HOUR_PRECISION_DATE_FORMAT = new SimpleDateFormat("yyyyMMddHH");
-
- private static boolean isWithin(final long millis, final long span, final TimeUnit unit) {
- return System.currentTimeMillis() - millis <= unit.toMillis(span);
- }
-
- private static boolean isYesterday(final long when) {
- return DateUtils.isToday(when + TimeUnit.DAYS.toMillis(1));
- }
-
- private static int convertDelta(final long millis, TimeUnit to) {
- return (int) to.convert(System.currentTimeMillis() - millis, TimeUnit.MILLISECONDS);
- }
-
- public static String getFormattedDateTime(long time, String template, Locale locale) {
- final String localizedPattern = getLocalizedPattern(template, locale);
- return new SimpleDateFormat(localizedPattern, locale).format(new Date(time));
- }
-
- public static String getHourFormat(Context c) {
- return (DateFormat.is24HourFormat(c)) ? "HH:mm" : "hh:mm a";
- }
-
- public static String getDisplayFormattedTimeSpanString(final Context c, final Locale locale, final long timestamp) {
- // If the timestamp is invalid (ie. 0) then assume we're waiting on data and just use the 'Now' copy
- if (timestamp == 0 || isWithin(timestamp, 1, TimeUnit.MINUTES)) {
- return c.getString(R.string.DateUtils_just_now);
- } else if (isToday(timestamp)) {
- return getFormattedDateTime(timestamp, getHourFormat(c), locale);
- } else if (isWithin(timestamp, 6, TimeUnit.DAYS)) {
- return getFormattedDateTime(timestamp, "EEE " + getHourFormat(c), locale);
- } else if (isWithin(timestamp, 365, TimeUnit.DAYS)) {
- return getFormattedDateTime(timestamp, "MMM d " + getHourFormat(c), locale);
- } else {
- return getFormattedDateTime(timestamp, "MMM d " + getHourFormat(c) + ", yyyy", locale);
- }
- }
-
- public static SimpleDateFormat getDetailedDateFormatter(Context context, Locale locale) {
- String dateFormatPattern;
-
- if (DateFormat.is24HourFormat(context)) {
- dateFormatPattern = getLocalizedPattern("MMM d, yyyy HH:mm:ss zzz", locale);
- } else {
- dateFormatPattern = getLocalizedPattern("MMM d, yyyy hh:mm:ss a zzz", locale);
- }
-
- return new SimpleDateFormat(dateFormatPattern, locale);
- }
-
- public static String getRelativeDate(@NonNull Context context,
- @NonNull Locale locale,
- long timestamp)
- {
- if (isToday(timestamp)) {
- return context.getString(R.string.DateUtils_today);
- } else if (isYesterday(timestamp)) {
- return context.getString(R.string.DateUtils_yesterday);
- } else {
- return getFormattedDateTime(timestamp, "EEE, MMM d, yyyy", locale);
- }
- }
-
- public static boolean isSameDay(long t1, long t2) {
- return DAY_PRECISION_DATE_FORMAT.format(new Date(t1)).equals(DAY_PRECISION_DATE_FORMAT.format(new Date(t2)));
- }
-
- public static boolean isSameHour(long t1, long t2) {
- return HOUR_PRECISION_DATE_FORMAT.format(new Date(t1)).equals(HOUR_PRECISION_DATE_FORMAT.format(new Date(t2)));
- }
-
- private static String getLocalizedPattern(String template, Locale locale) {
- return DateFormat.getBestDateTimePattern(locale, template);
- }
-
- /**
- * e.g. 2020-09-04T19:17:51Z
- * https://www.iso.org/iso-8601-date-and-time-format.html
- *
- * @return The timestamp if able to be parsed, otherwise -1.
- */
- @SuppressLint("ObsoleteSdkInt")
- public static long parseIso8601(@Nullable String date) {
- SimpleDateFormat format;
- format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.getDefault());
-
- if (date.isEmpty()) {
- return -1;
- }
-
- try {
- return format.parse(date).getTime();
- } catch (ParseException e) {
- Log.w(TAG, "Failed to parse date.", e);
- return -1;
- }
- }
-
- // region Deprecated
- public static String getBriefRelativeTimeSpanString(final Context c, final Locale locale, final long timestamp) {
- if (isWithin(timestamp, 1, TimeUnit.MINUTES)) {
- return c.getString(R.string.DateUtils_just_now);
- } else if (isWithin(timestamp, 1, TimeUnit.HOURS)) {
- int mins = convertDelta(timestamp, TimeUnit.MINUTES);
- return c.getResources().getString(R.string.DateUtils_minutes_ago, mins);
- } else if (isWithin(timestamp, 1, TimeUnit.DAYS)) {
- int hours = convertDelta(timestamp, TimeUnit.HOURS);
- return c.getResources().getQuantityString(R.plurals.hours_ago, hours, hours);
- } else if (isWithin(timestamp, 6, TimeUnit.DAYS)) {
- return getFormattedDateTime(timestamp, "EEE", locale);
- } else if (isWithin(timestamp, 365, TimeUnit.DAYS)) {
- return getFormattedDateTime(timestamp, "MMM d", locale);
- } else {
- return getFormattedDateTime(timestamp, "MMM d, yyyy", locale);
- }
- }
-
- public static String getExtendedRelativeTimeSpanString(final Context c, final Locale locale, final long timestamp) {
- if (isWithin(timestamp, 1, TimeUnit.MINUTES)) {
- return c.getString(R.string.DateUtils_just_now);
- } else if (isWithin(timestamp, 1, TimeUnit.HOURS)) {
- int mins = (int)TimeUnit.MINUTES.convert(System.currentTimeMillis() - timestamp, TimeUnit.MILLISECONDS);
- return c.getResources().getString(R.string.DateUtils_minutes_ago, mins);
- } else {
- StringBuilder format = new StringBuilder();
- if (isWithin(timestamp, 6, TimeUnit.DAYS)) format.append("EEE ");
- else if (isWithin(timestamp, 365, TimeUnit.DAYS)) format.append("MMM d, ");
- else format.append("MMM d, yyyy, ");
-
- if (DateFormat.is24HourFormat(c)) format.append("HH:mm");
- else format.append("hh:mm a");
-
- return getFormattedDateTime(timestamp, format.toString(), locale);
- }
- }
- // endregion
-}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.kt b/app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.kt
new file mode 100644
index 0000000000..10d2fceb79
--- /dev/null
+++ b/app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.kt
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2014 Open Whisper Systems
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.thoughtcrime.securesms.util
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.os.Build
+import android.text.format.DateFormat
+import androidx.compose.ui.text.capitalize
+import org.session.libsignal.utilities.Log
+import java.text.DateFormat.SHORT
+import java.text.DateFormat.getTimeInstance
+import java.text.ParseException
+import java.text.SimpleDateFormat
+import java.util.Calendar
+import java.util.Date
+import java.util.Locale
+import java.util.concurrent.TimeUnit
+
+// Enums used to get the locale-aware String for one of the three relative days
+enum class RelativeDay { TODAY, YESTERDAY, TOMORROW }
+
+/**
+ * Utility methods to help display dates in a nice, easily readable way.
+ */
+object DateUtils : android.text.format.DateUtils() {
+
+ @Suppress("unused")
+ private val TAG: String = DateUtils::class.java.simpleName
+ private val DAY_PRECISION_DATE_FORMAT = SimpleDateFormat("yyyyMMdd")
+ private val HOUR_PRECISION_DATE_FORMAT = SimpleDateFormat("yyyyMMddHH")
+
+ private fun isWithin(millis: Long, span: Long, unit: TimeUnit): Boolean {
+ return System.currentTimeMillis() - millis <= unit.toMillis(span)
+ }
+
+ private fun isYesterday(`when`: Long): Boolean {
+ return isToday(`when` + TimeUnit.DAYS.toMillis(1))
+ }
+
+ private fun convertDelta(millis: Long, to: TimeUnit): Int {
+ return to.convert(System.currentTimeMillis() - millis, TimeUnit.MILLISECONDS).toInt()
+ }
+
+ // Method to get the String for a relative day in a locale-aware fashion
+ public fun getLocalisedRelativeDayString(relativeDay: RelativeDay): String {
+
+ val now = Calendar.getInstance()
+
+ // To compare a time to 'now' we need to use get a date relative it, so plus or minus a day, or not
+ val dayAddition = when (relativeDay) {
+ RelativeDay.TOMORROW -> { 1 }
+ RelativeDay.YESTERDAY -> { -1 }
+ else -> 0 // Today
+ }
+
+ val comparisonTime = Calendar.getInstance().apply {
+ add(Calendar.DAY_OF_YEAR, dayAddition)
+ set(Calendar.HOUR_OF_DAY, 0)
+ set(Calendar.MINUTE, 0)
+ set(Calendar.SECOND, 0)
+ set(Calendar.MILLISECOND, 0)
+ }
+
+ return getRelativeTimeSpanString(comparisonTime.timeInMillis,
+ now.timeInMillis,
+ DAY_IN_MILLIS,
+ FORMAT_SHOW_DATE).toString()
+ }
+
+ fun getFormattedDateTime(time: Long, template: String, locale: Locale): String {
+ val localizedPattern = getLocalizedPattern(template, locale)
+ return SimpleDateFormat(localizedPattern, locale).format(Date(time))
+ }
+
+ fun getHourFormat(c: Context?): String {
+ return if ((DateFormat.is24HourFormat(c))) "HH:mm" else "hh:mm a"
+ }
+
+ fun getDisplayFormattedTimeSpanString(c: Context, locale: Locale, timestamp: Long): String {
+ // If the timestamp is within the last 24 hours we just give the time, e.g, "1:23 PM" or
+ // "13:23" depending on 12/24 hour formatting.
+ return if (isToday(timestamp)) {
+ getFormattedDateTime(timestamp, getHourFormat(c), locale)
+ } else if (isWithin(timestamp, 6, TimeUnit.DAYS)) {
+ getFormattedDateTime(timestamp, "EEE " + getHourFormat(c), locale)
+ } else if (isWithin(timestamp, 365, TimeUnit.DAYS)) {
+ getFormattedDateTime(timestamp, "MMM d " + getHourFormat(c), locale)
+ } else {
+ getFormattedDateTime(timestamp, "MMM d " + getHourFormat(c) + ", yyyy", locale)
+ }
+ }
+
+ fun getDetailedDateFormatter(context: Context?, locale: Locale): SimpleDateFormat {
+ val dateFormatPattern = if (DateFormat.is24HourFormat(context)) {
+ getLocalizedPattern("MMM d, yyyy HH:mm:ss zzz", locale)
+ } else {
+ getLocalizedPattern("MMM d, yyyy hh:mm:ss a zzz", locale)
+ }
+
+ return SimpleDateFormat(dateFormatPattern, locale)
+ }
+
+ // Method to get the String for a relative day in a locale-aware fashion, including using the
+ // auto-localised words for "today" and "yesterday" as appropriate.
+ fun getRelativeDate(
+ context: Context,
+ locale: Locale,
+ timestamp: Long
+ ): String {
+ return if (isToday(timestamp)) {
+ getLocalisedRelativeDayString(RelativeDay.TODAY)
+ } else if (isYesterday(timestamp)) {
+ getLocalisedRelativeDayString(RelativeDay.YESTERDAY)
+ } else {
+ getFormattedDateTime(timestamp, "EEE, MMM d, yyyy", locale)
+ }
+ }
+
+ fun isSameDay(t1: Long, t2: Long): Boolean {
+ return DAY_PRECISION_DATE_FORMAT.format(Date(t1)) == DAY_PRECISION_DATE_FORMAT.format(Date(t2))
+ }
+
+ fun isSameHour(t1: Long, t2: Long): Boolean {
+ return HOUR_PRECISION_DATE_FORMAT.format(Date(t1)) == HOUR_PRECISION_DATE_FORMAT.format(Date(t2))
+ }
+
+ private fun getLocalizedPattern(template: String, locale: Locale): String {
+ return DateFormat.getBestDateTimePattern(locale, template)
+ }
+
+ /**
+ * e.g. 2020-09-04T19:17:51Z
+ * https://www.iso.org/iso-8601-date-and-time-format.html
+ *
+ * @return The timestamp if able to be parsed, otherwise -1.
+ */
+ @SuppressLint("ObsoleteSdkInt")
+ @JvmStatic
+ public fun parseIso8601(date: String?): Long {
+
+ if (date.isNullOrEmpty()) { return -1 }
+
+ val format = if (Build.VERSION.SDK_INT >= 24) {
+ SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.getDefault())
+ } else {
+ SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault())
+ }
+
+ try {
+ return format.parse(date).time
+ } catch (e: ParseException) {
+ Log.w(TAG, "Failed to parse date.", e)
+ return -1
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt b/app/src/main/java/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt
index ccbab486c6..2f89ccbc43 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/util/SaveAttachmentTask.kt
@@ -8,22 +8,21 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
-import android.text.TextUtils
import android.webkit.MimeTypeMap
import android.widget.Toast
-import network.loki.messenger.R
-import org.session.libsession.utilities.task.ProgressDialogAsyncTask
-import org.session.libsignal.utilities.ExternalStorageUtil
-import org.session.libsignal.utilities.Log
-import org.thoughtcrime.securesms.mms.PartAuthority
-import org.thoughtcrime.securesms.showSessionDialog
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.lang.ref.WeakReference
import java.text.SimpleDateFormat
-import java.util.*
import java.util.concurrent.TimeUnit
+import network.loki.messenger.R
+import org.session.libsession.utilities.TextSecurePreferences
+import org.session.libsession.utilities.task.ProgressDialogAsyncTask
+import org.session.libsignal.utilities.ExternalStorageUtil
+import org.session.libsignal.utilities.Log
+import org.thoughtcrime.securesms.mms.PartAuthority
+import org.thoughtcrime.securesms.showSessionDialog
/**
* Saves attachment files to an external storage using [MediaStore] API.
@@ -32,8 +31,8 @@ import java.util.concurrent.TimeUnit
class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int = 1) :
ProgressDialogAsyncTask>(
context,
- context.resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments, count, count),
- context.resources.getQuantityString(R.plurals.ConversationFragment_saving_n_attachments_to_sd_card, count, count)
+ context.resources.getString(R.string.saving),
+ context.resources.getString(R.string.saving)
) {
companion object {
@@ -45,16 +44,26 @@ class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int
@JvmStatic
@JvmOverloads
- fun showWarningDialog(context: Context, count: Int = 1, onAcceptListener: () -> Unit = {}) {
- context.showSessionDialog {
- title(R.string.ConversationFragment_save_to_sd_card)
- iconAttribute(R.attr.dialog_alert_icon)
- text(context.resources.getQuantityString(
- R.plurals.ConversationFragment_saving_n_media_to_storage_warning,
- count,
- count))
- button(R.string.yes) { onAcceptListener() }
- button(R.string.no)
+ fun showOneTimeWarningDialogOrSave(context: Context, count: Int = 1, onAcceptListener: () -> Unit = {}) {
+ // If we've already warned the user that saved attachments can be accessed by other apps
+ // then we'll just perform the save..
+ val haveWarned = TextSecurePreferences.getHaveWarnedUserAboutSavingAttachments(context)
+ if (haveWarned) {
+ onAcceptListener()
+ } else {
+ // .. otherwise we'll show a warning dialog and only save if the user accepts the
+ // potential risks of other apps accessing their saved attachments.
+ context.showSessionDialog {
+ title(R.string.warning)
+ iconAttribute(R.attr.dialog_alert_icon)
+ text(context.getString(R.string.attachmentsWarning))
+ dangerButton(R.string.save) {
+ // Set our 'haveWarned' SharedPref and perform the save on accept
+ TextSecurePreferences.setHaveWarnedUserAboutSavingAttachments(context)
+ onAcceptListener()
+ }
+ button(R.string.cancel)
+ }
}
}
@@ -125,6 +134,11 @@ class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int
}
private fun createOutputUri(context: Context, outputUri: Uri, contentType: String, fileName: String): Uri? {
+
+ // TODO: This method may pass an empty string as the filename in Android API 28 and below. This requires
+ // TODO: follow-up investigation, but has temporarily been worked around, see:
+ // TODO: https://github.com/oxen-io/session-android/commit/afbb71351a74220c312a09c25cc1c79738453c12
+
val fileParts: Array = getFileNameParts(fileName)
val base = fileParts[0]
val extension = fileParts[1]
@@ -233,18 +247,12 @@ class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int
when (result.first) {
RESULT_FAILURE -> {
- val message = context.resources.getQuantityText(
- R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card,
- attachmentCount)
+ val message = context.resources.getString(R.string.attachmentsSaveError)
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
}
RESULT_SUCCESS -> {
- val message = if (!TextUtils.isEmpty(result.second)) {
- context.resources.getString(R.string.SaveAttachmentTask_saved_to, result.second)
- } else {
- context.resources.getString(R.string.SaveAttachmentTask_saved)
- }
+ val message = context.resources.getString(R.string.saved)
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ScanQRCodePlaceholderFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ScanQRCodePlaceholderFragment.kt
index 7e14b7234f..a0528ad432 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/util/ScanQRCodePlaceholderFragment.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/util/ScanQRCodePlaceholderFragment.kt
@@ -5,7 +5,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
+import com.squareup.phrase.Phrase
+import network.loki.messenger.R
import network.loki.messenger.databinding.FragmentScanQrCodePlaceholderBinding
+import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
class ScanQRCodePlaceholderFragment: Fragment() {
private lateinit var binding: FragmentScanQrCodePlaceholderBinding
@@ -19,10 +22,13 @@ class ScanQRCodePlaceholderFragment: Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.grantCameraAccessButton.setOnClickListener { delegate?.requestCameraAccess() }
+
+ binding.needCameraPermissionsTV.text = Phrase.from(context, R.string.cameraGrantAccessQr)
+ .put(APP_NAME_KEY, getString(R.string.app_name))
+ .format()
}
}
interface ScanQRCodePlaceholderFragmentDelegate {
-
fun requestCameraAccess()
}
\ No newline at end of file
diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/Trimmer.java b/app/src/main/java/org/thoughtcrime/securesms/util/Trimmer.java
index dd5e146edd..6707a078c8 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/util/Trimmer.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/util/Trimmer.java
@@ -30,8 +30,8 @@ public class Trimmer {
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(false);
- progressDialog.setTitle(R.string.trimmer__deleting);
- progressDialog.setMessage(context.getString(R.string.trimmer__deleting_old_messages));
+ progressDialog.setTitle(R.string.deleting);
+ progressDialog.setMessage(context.getString(R.string.deleting));
progressDialog.setMax(100);
progressDialog.show();
}
@@ -53,9 +53,6 @@ public class Trimmer {
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
- Toast.makeText(context,
- R.string.trimmer__old_messages_successfully_deleted,
- Toast.LENGTH_LONG).show();
}
@Override
diff --git a/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java b/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java
index 2aa5531263..67a7e0335d 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java
+++ b/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java
@@ -160,7 +160,7 @@ public class VideoPlayer extends FrameLayout {
//noinspection ConstantConditions
this.videoView.setVideoURI(videoSource.getUri());
} else {
- Toast.makeText(getContext(), getContext().getString(R.string.VideoPlayer_error_playing_video), Toast.LENGTH_LONG).show();
+ Toast.makeText(getContext(), getContext().getString(R.string.videoErrorPlay), Toast.LENGTH_LONG).show();
return;
}
diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallMessageProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallMessageProcessor.kt
index 3d40b5f746..376cb41792 100644
--- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallMessageProcessor.kt
+++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallMessageProcessor.kt
@@ -65,7 +65,7 @@ class CallMessageProcessor(private val context: Context, private val textSecureP
val sentTimestamp = nextMessage.sentTimestamp ?: continue
if (textSecurePreferences.setShownCallNotification()) {
// first time call notification encountered
- val notification = CallNotificationBuilder.getFirstCallNotification(context)
+ val notification = CallNotificationBuilder.getFirstCallNotification(context, sender)
context.getSystemService(NotificationManager::class.java).notify(CallNotificationBuilder.WEBRTC_NOTIFICATION, notification)
insertMissedCall(sender, sentTimestamp, isFirstCall = true)
} else {
diff --git a/app/src/main/res/drawable/default_dialog_background.xml b/app/src/main/res/drawable/default_dialog_background.xml
index d2e3dfbfa7..01ae255c9f 100644
--- a/app/src/main/res/drawable/default_dialog_background.xml
+++ b/app/src/main/res/drawable/default_dialog_background.xml
@@ -4,7 +4,7 @@
android:shape="rectangle">
-
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/dialog_background.xml b/app/src/main/res/drawable/dialog_background.xml
deleted file mode 100644
index e546e1f84c..0000000000
--- a/app/src/main/res/drawable/dialog_background.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_radio_selected.xml b/app/src/main/res/drawable/ic_radio_selected.xml
new file mode 100644
index 0000000000..82021810e9
--- /dev/null
+++ b/app/src/main/res/drawable/ic_radio_selected.xml
@@ -0,0 +1,13 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_radio_unselected.xml b/app/src/main/res/drawable/ic_radio_unselected.xml
new file mode 100644
index 0000000000..285dbb276e
--- /dev/null
+++ b/app/src/main/res/drawable/ic_radio_unselected.xml
@@ -0,0 +1,11 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/padded_circle_accent_select.xml b/app/src/main/res/drawable/padded_circle_accent_select.xml
index 0d384e658f..ba8e121e16 100644
--- a/app/src/main/res/drawable/padded_circle_accent_select.xml
+++ b/app/src/main/res/drawable/padded_circle_accent_select.xml
@@ -2,10 +2,10 @@
-
-
-
+
-
diff --git a/app/src/main/res/drawable/radial_multi_select.xml b/app/src/main/res/drawable/radial_multi_select.xml
index c05af4e763..5b2144e897 100644
--- a/app/src/main/res/drawable/radial_multi_select.xml
+++ b/app/src/main/res/drawable/radial_multi_select.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/radio_states.xml b/app/src/main/res/drawable/radio_states.xml
new file mode 100644
index 0000000000..4d20610ca2
--- /dev/null
+++ b/app/src/main/res/drawable/radio_states.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_appearance_settings.xml b/app/src/main/res/layout/activity_appearance_settings.xml
index c4886708a3..140e0be611 100644
--- a/app/src/main/res/layout/activity_appearance_settings.xml
+++ b/app/src/main/res/layout/activity_appearance_settings.xml
@@ -19,7 +19,7 @@
android:paddingVertical="@dimen/small_spacing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/activity_appearance_themes_category"/>
+ android:text="@string/appearanceThemes"/>
+ android:text="@string/appearancePrimaryColor"/>
+ app:drawableLeftCompat="@drawable/quote_accent_line" />
+ android:layout_height="wrap_content" />
+ android:layout_height="wrap_content" />
@@ -312,7 +309,7 @@
android:paddingVertical="@dimen/small_spacing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/activity_appearance_follow_system_category"/>
+ android:text="@string/appearanceAutoDarkMode"/>
diff --git a/app/src/main/res/layout/activity_blocked_contacts.xml b/app/src/main/res/layout/activity_blocked_contacts.xml
index 8bc458da02..02caf4b7a8 100644
--- a/app/src/main/res/layout/activity_blocked_contacts.xml
+++ b/app/src/main/res/layout/activity_blocked_contacts.xml
@@ -35,14 +35,14 @@
android:layout_marginTop="@dimen/medium_spacing"
app:layout_constraintStart_toStartOf="@+id/cardView"
app:layout_constraintEnd_toEndOf="@+id/cardView"
- android:text="@string/blocked_contacts_empty_state"
+ android:text="@string/blockBlockedNone"
/>
-
+ android:text="@string/block"/>
@@ -327,7 +326,7 @@