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 b6fad9e081..895c1641ab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -10,25 +10,41 @@ import android.content.Intent import android.content.IntentFilter import android.os.Build import android.os.Bundle -import android.text.SpannableString import android.widget.Toast import androidx.activity.viewModels -import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.requiredWidth +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.windowInsetsEndWidth +import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.foundation.layout.wrapContentSize +import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.material.Divider import androidx.compose.material.Icon import androidx.compose.material.MaterialTheme import androidx.compose.material.Text +import androidx.compose.material.primarySurface 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.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 androidx.core.os.bundleOf +import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -36,7 +52,6 @@ import androidx.lifecycle.repeatOnLifecycle import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.google.accompanist.themeadapter.appcompat.AppCompatTheme import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.collect @@ -85,14 +100,18 @@ import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.notifications.PushRegistry -import org.thoughtcrime.securesms.onboarding.SeedActivity -import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate +import org.thoughtcrime.securesms.onboarding.startSeedActivity import org.thoughtcrime.securesms.permissions.Permissions import org.thoughtcrime.securesms.preferences.SettingsActivity import org.thoughtcrime.securesms.showMuteDialog import org.thoughtcrime.securesms.showSessionDialog import org.thoughtcrime.securesms.ui.AppTheme +import org.thoughtcrime.securesms.ui.OutlineButton +import org.thoughtcrime.securesms.ui.PreviewTheme +import org.thoughtcrime.securesms.ui.ThemeResPreviewParameterProvider +import org.thoughtcrime.securesms.ui.classicDarkColors import org.thoughtcrime.securesms.ui.h8 +import org.thoughtcrime.securesms.ui.small import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import org.thoughtcrime.securesms.util.DateUtils import org.thoughtcrime.securesms.util.IP2Country @@ -107,7 +126,6 @@ import javax.inject.Inject @AndroidEntryPoint class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickListener, - SeedReminderViewDelegate, GlobalSearchInputLayout.GlobalSearchInputLayoutListener { companion object { @@ -196,15 +214,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), binding.sessionToolbar.disableClipping() // Set up seed reminder view lifecycleScope.launchWhenStarted { - val hasViewedSeed = textSecurePreferences.getHasViewedSeed() - if (!hasViewedSeed) { - binding.seedReminderView.isVisible = true - binding.seedReminderView.title = SpannableString("You're almost finished! 80%") // Intentionally not yet translated - binding.seedReminderView.subtitle = resources.getString(R.string.view_seed_reminder_subtitle_1) - binding.seedReminderView.setProgress(80, false) - binding.seedReminderView.delegate = this@HomeActivity - } else { - binding.seedReminderView.isVisible = false + binding.seedReminderView.setContent { + if (!textSecurePreferences.getHasViewedSeed()) SeedReminder() } } setupMessageRequestsBanner() @@ -334,6 +345,53 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), } } + @Preview + @Composable + fun PreviewMessageDetails( + @PreviewParameter(ThemeResPreviewParameterProvider::class) themeResId: Int + ) { + PreviewTheme(themeResId) { + SeedReminder() + } + } + + @Composable + private fun SeedReminder() { + AppTheme { + Column { + Box( + Modifier + .fillMaxWidth() + .height(4.dp) + .background(MaterialTheme.colors.secondary)) + Row( + Modifier + .background(MaterialTheme.colors.surface) + .padding(horizontal = 24.dp, vertical = 16.dp) + ) { + Column(Modifier.weight(1f)) { + Row { + Text("Save your recovery password", style = MaterialTheme.typography.h8) + Spacer(Modifier.requiredWidth(8.dp)) + Icon( + painter = painterResource(R.drawable.session_shield), + contentDescription = null, + modifier = Modifier.align(Alignment.CenterVertically) + .wrapContentSize(unbounded = true) + ) + } + Text("Save your recovery password to make sure you don't lose access to your account.", style = MaterialTheme.typography.small) + } + Spacer(Modifier.width(12.dp)) + OutlineButton( + stringResource(R.string.continue_2), + Modifier.align(Alignment.CenterVertically) + ) { startSeedActivity() } + } + } + } + } + @Composable private fun EmptyView() { AppTheme { @@ -510,11 +568,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), super.onBackPressed() } - override fun handleSeedReminderViewContinueButtonTapped() { - val intent = Intent(this, SeedActivity::class.java) - show(intent) - } - override fun onConversationClick(thread: ThreadRecord) { val intent = Intent(this, ConversationActivityV2::class.java) intent.putExtra(ConversationActivityV2.THREAD_ID, thread.threadId) @@ -538,7 +591,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), bottomSheet.dismiss() if (!thread.recipient.isGroupRecipient && !thread.recipient.isLocalNumber) { val clip = ClipData.newPlainText("Session ID", thread.recipient.address.toString()) - val manager = getSystemService(PassphraseRequiredActionBarActivity.CLIPBOARD_SERVICE) as ClipboardManager + val manager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager manager.setPrimaryClip(clip) Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() } @@ -547,7 +600,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), val openGroup = DatabaseComponent.get(this@HomeActivity).lokiThreadDatabase().getOpenGroupChat(threadId) ?: return@onCopyConversationId Unit val clip = ClipData.newPlainText("Community URL", openGroup.joinURL) - val manager = getSystemService(PassphraseRequiredActionBarActivity.CLIPBOARD_SERVICE) as ClipboardManager + val manager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager manager.setPrimaryClip(clip) Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedActivity.kt index 0eab58fa0c..92a05952de 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedActivity.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.onboarding import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.content.Intent import android.os.Bundle import android.text.Spannable import android.text.SpannableString @@ -19,6 +20,7 @@ import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.thoughtcrime.securesms.crypto.MnemonicUtilities import org.thoughtcrime.securesms.util.getAccentColor +import org.thoughtcrime.securesms.util.show class SeedActivity : BaseActionBarActivity() { @@ -44,10 +46,6 @@ class SeedActivity : BaseActionBarActivity() { val seedReminderViewTitle = SpannableString("You're almost finished! 90%") // Intentionally not yet translated seedReminderViewTitle.setSpan(ForegroundColorSpan(getAccentColor()), 24, 27, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) with(binding) { - seedReminderView.title = seedReminderViewTitle - seedReminderView.subtitle = resources.getString(R.string.view_seed_reminder_subtitle_2) - seedReminderView.setProgress(90, false) - seedReminderView.hideContinueButton() var redactedSeed = seed var index = 0 for (character in seed) { @@ -70,9 +68,6 @@ class SeedActivity : BaseActionBarActivity() { val seedReminderViewTitle = SpannableString("Account secured! 100%") // Intentionally not yet translated seedReminderViewTitle.setSpan(ForegroundColorSpan(getAccentColor()), 17, 21, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) with(binding) { - seedReminderView.title = seedReminderViewTitle - seedReminderView.subtitle = resources.getString(R.string.view_seed_reminder_subtitle_3) - seedReminderView.setProgress(100, true) val seedTextViewLayoutParams = seedTextView.layoutParams as LinearLayout.LayoutParams seedTextViewLayoutParams.height = seedTextView.height seedTextView.layoutParams = seedTextViewLayoutParams @@ -92,4 +87,8 @@ class SeedActivity : BaseActionBarActivity() { Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() } // endregion -} \ No newline at end of file +} + +fun Context.startSeedActivity() { + Intent(this, SeedActivity::class.java).also(::startActivity) +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedReminderView.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedReminderView.kt deleted file mode 100644 index 28611985fa..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/SeedReminderView.kt +++ /dev/null @@ -1,59 +0,0 @@ -package org.thoughtcrime.securesms.onboarding - -import android.content.Context -import android.os.Build -import android.util.AttributeSet -import android.view.LayoutInflater -import android.view.View -import android.widget.FrameLayout -import network.loki.messenger.databinding.ViewSeedReminderBinding - -class SeedReminderView : FrameLayout { - private lateinit var binding: ViewSeedReminderBinding - - var title: CharSequence - get() = binding.titleTextView.text - set(value) { binding.titleTextView.text = value } - var subtitle: CharSequence - get() = binding.subtitleTextView.text - set(value) { binding.subtitleTextView.text = value } - var delegate: SeedReminderViewDelegate? = null - - constructor(context: Context) : super(context) { - setUpViewHierarchy() - } - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - setUpViewHierarchy() - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - setUpViewHierarchy() - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { - setUpViewHierarchy() - } - - private fun setUpViewHierarchy() { - binding = ViewSeedReminderBinding.inflate(LayoutInflater.from(context), this, true) - binding.button.setOnClickListener { delegate?.handleSeedReminderViewContinueButtonTapped() } - } - - fun setProgress(progress: Int, isAnimated: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - binding.progressBar.setProgress(progress, isAnimated) - } else { - binding.progressBar.progress = progress - } - } - - fun hideContinueButton() { - binding.button.visibility = View.GONE - } -} - -interface SeedReminderViewDelegate { - - fun handleSeedReminderViewContinueButtonTapped() -} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Colors.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Colors.kt index 32c375e54d..ca7d3de7b4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Colors.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Colors.kt @@ -1,10 +1,21 @@ package org.thoughtcrime.securesms.ui +import android.content.Context +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Card import androidx.compose.material.Colors import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.material.primarySurface import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp val colorDestructive = Color(0xffFF453A) @@ -62,3 +73,45 @@ fun transparentButtonColors() = ButtonDefaults.buttonColors(backgroundColor = Co @Composable fun destructiveButtonColors() = ButtonDefaults.buttonColors(backgroundColor = Color.Transparent, contentColor = colorDestructive) + +@Preview +@Composable +fun Context.PreviewMessageDetails( + @PreviewParameter(ThemeResPreviewParameterProvider::class) themeResId: Int +) { + PreviewTheme(themeResId) { + Colors() + } +} + +@Composable +private fun Colors() { + AppTheme { + Column { + Box(Modifier.background(MaterialTheme.colors.primary)) { + Text("primary") + } + Box(Modifier.background(MaterialTheme.colors.primaryVariant)) { + Text("primaryVariant") + } + Box(Modifier.background(MaterialTheme.colors.secondary)) { + Text("secondary") + } + Box(Modifier.background(MaterialTheme.colors.secondaryVariant)) { + Text("secondaryVariant") + } + Box(Modifier.background(MaterialTheme.colors.surface)) { + Text("surface") + } + Box(Modifier.background(MaterialTheme.colors.primarySurface)) { + Text("primarySurface") + } + Box(Modifier.background(MaterialTheme.colors.background)) { + Text("background") + } + Box(Modifier.background(MaterialTheme.colors.error)) { + Text("error") + } + } + } +} 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 e3f75fa355..3c540a4107 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt @@ -58,7 +58,7 @@ fun OutlineButton(text: String, modifier: Modifier = Modifier, onClick: () -> Un shape = RoundedCornerShape(50), // = 50% percent colors = ButtonDefaults.outlinedButtonColors( contentColor = LocalExtraColors.current.prominentButtonColor, - backgroundColor = MaterialTheme.colors.background + backgroundColor = Color.Unspecified ) ) { Text(text = text) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt index 51610cd460..95953ecff9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt @@ -40,15 +40,19 @@ data class ExtraColors( fun AppTheme( content: @Composable () -> Unit ) { - val extraColors = LocalContext.current.run { + val context = LocalContext.current + + val extraColors = context.run { ExtraColors( settingsBackground = getColorFromTheme(R.attr.colorSettingsBackground), prominentButtonColor = getColorFromTheme(R.attr.prominentButtonColor), ) } + val surface = context.getColorFromTheme(R.attr.colorSettingsBackground) + CompositionLocalProvider(LocalExtraColors provides extraColors) { - AppCompatTheme { + AppCompatTheme(surface = surface) { content() } } @@ -60,6 +64,7 @@ fun AppCompatTheme( readColors: Boolean = true, typography: Typography = sessionTypography, shapes: Shapes = MaterialTheme.shapes, + surface: Color? = null, content: @Composable () -> Unit ) { val themeParams = remember(context.theme) { @@ -69,8 +74,12 @@ fun AppCompatTheme( ) } + val colors = themeParams.colors ?: MaterialTheme.colors + MaterialTheme( - colors = themeParams.colors ?: MaterialTheme.colors, + colors = colors.copy( + surface = surface ?: colors.surface + ), typography = typography, shapes = shapes, ) { diff --git a/app/src/main/res/drawable/session_shield.xml b/app/src/main/res/drawable/session_shield.xml new file mode 100644 index 0000000000..a7c6d1a24a --- /dev/null +++ b/app/src/main/res/drawable/session_shield.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout-sw400dp/activity_seed.xml b/app/src/main/res/layout-sw400dp/activity_seed.xml index 97b63ede5e..886d317b29 100644 --- a/app/src/main/res/layout-sw400dp/activity_seed.xml +++ b/app/src/main/res/layout-sw400dp/activity_seed.xml @@ -6,7 +6,7 @@ android:gravity="center_horizontal" android:orientation="vertical"> - diff --git a/app/src/main/res/layout-sw400dp/view_seed_reminder.xml b/app/src/main/res/layout-sw400dp/view_seed_reminder.xml deleted file mode 100644 index 5be50ebe6c..0000000000 --- a/app/src/main/res/layout-sw400dp/view_seed_reminder.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - -