Light theme feature intro bottom sheet.

This commit is contained in:
Anton Chekulaev 2020-08-27 15:50:35 +10:00
parent 83a36b327a
commit 9d0d2cb07e
9 changed files with 207 additions and 19 deletions

84
res/drawable/ic_sun.xml Normal file
View File

@ -0,0 +1,84 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:pathData="M6,30L2,30C0.8954,30 0,30.8955 0,32C0,33.1045 0.8954,34 2,34L6,34C7.1044,34 8,33.1046 8,32C8,30.8954 7.1044,30 6,30Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M62,30L58,30C56.8956,30 56,30.8954 56,32C56,33.1046 56.8954,34 58,34L62,34C63.1044,34 64,33.1046 64,32C64,30.8954 63.1046,30 62,30Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M32,56C30.8955,56 30,56.8954 30,58L30,62C30,63.1044 30.8954,64 32,64C33.1046,64 34,63.1046 34,62L34,58C34,56.8956 33.1045,56 32,56Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M32,0C30.8955,0 30,0.8954 30,2L30,6C30,7.1044 30.8954,8 32,8C33.1046,8 34,7.1046 34,6L34,2C34,0.8954 33.1045,0 32,0Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M47.7318,56.7846L45.7319,53.0721C45.1797,52.047 43.9567,51.6956 43.0002,52.2876C42.0438,52.8794 41.716,54.1903 42.2682,55.2155L44.2681,58.928C44.8205,59.9536 46.0439,60.3041 46.9998,59.7125C47.9562,59.1207 48.284,57.8097 47.7318,56.7846Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M21.7318,8.7845L19.7319,5.0721C19.1797,4.047 17.9567,3.6956 17.0002,4.2875C16.0438,4.8794 15.716,6.1903 16.2682,7.2155L18.2681,10.9279C18.8205,11.9536 20.0439,12.3042 20.9998,11.7125C21.9562,11.1206 22.284,9.8097 21.7318,8.7845Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M58.9279,44.2681L55.2154,42.2684C54.1902,41.7159 52.8793,42.0438 52.2875,43.0003C51.6956,43.9567 52.0469,45.1798 53.0721,45.7319L56.7846,47.7317C57.8092,48.2838 59.1204,47.9567 59.7125,46.9998C60.3044,46.0434 59.9531,44.8203 58.9279,44.2681Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M10.928,18.2681L7.2155,16.2683C6.1902,15.7159 4.8792,16.0439 4.2875,17.0003C3.6956,17.9567 4.0469,19.1798 5.0721,19.7319L8.7846,21.7317C9.8092,22.2838 11.1204,21.9567 11.7126,20.9998C12.3043,20.0433 11.9532,18.8203 10.928,18.2681Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M59.7125,17.0003C59.1207,16.0438 57.8098,15.716 56.7846,16.2683L53.0721,18.2681C52.0469,18.8203 51.6956,20.0434 52.2875,20.9998C52.8796,21.9567 54.1909,22.2837 55.2154,21.7318L58.9279,19.7319C59.9531,19.1798 60.3044,17.9567 59.7125,17.0003Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M11.7125,43.0002C11.1208,42.0438 9.8097,41.716 8.7845,42.2682L5.0721,44.2681C4.0469,44.8203 3.6956,46.0434 4.2875,46.9998C4.8796,47.9567 6.1909,48.2837 7.2154,47.7318L10.9279,45.7319C11.9532,45.1797 12.3043,43.9567 11.7125,43.0002Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M46.9998,4.2876C46.0432,3.6955 44.8203,4.047 44.2681,5.0721L42.2682,8.7846C41.716,9.8097 42.0438,11.1206 43.0002,11.7124C43.9562,12.3041 45.1795,11.9537 45.7319,10.9279L47.7318,7.2155C48.284,6.1905 47.9562,4.8796 46.9998,4.2876Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M20.9998,52.2876C20.0433,51.6955 18.8202,52.0469 18.2681,53.0722L16.2682,56.7846C15.716,57.8097 16.0438,59.1206 17.0002,59.7125C17.9562,60.3042 19.1795,59.9536 19.7319,58.9279L21.7318,55.2155C22.284,54.1904 21.9562,52.8795 20.9998,52.2876Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
<path
android:pathData="M31.5,12C20.7478,12 12,20.7478 12,31.5C12,42.2522 20.7478,51 31.5,51C42.2522,51 51,42.2522 51,31.5C51,20.7478 42.2524,12 31.5,12ZM31.5,47.643C22.5988,47.643 15.357,40.4013 15.357,31.5C15.357,22.5987 22.5988,15.357 31.5,15.357C40.4012,15.357 47.643,22.5988 47.643,31.5C47.643,40.4012 40.4013,47.643 31.5,47.643Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:padding="@dimen/large_spacing"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_sun"
android:tint="?android:textColorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/large_spacing"
android:text="Light Mode"
android:textStyle="bold"
android:textSize="@dimen/large_font_size" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/large_spacing"
android:text="Who left the lights on? bla bla bla"
android:textSize="@dimen/medium_font_size"
android:textAlignment="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_spacing"
android:text="Feeling the dark side more? Just pop into the in-app settings and tap the app mode button in the top-right to toggle dark mode again."
android:textSize="@dimen/medium_font_size"
android:textAlignment="center" />
<Button
style="@style/Widget.Session.Button.Common.UnimportantOutline"
android:id="@+id/okButton"
android:layout_width="240dp"
android:layout_height="@dimen/medium_button_height"
android:layout_marginTop="@dimen/very_large_spacing"
android:text="@string/ok" />
</LinearLayout>

View File

@ -27,7 +27,7 @@
<item name="actionBarStyle">@style/Widget.Session.ActionBar</item>
<item name="alertDialogTheme">@style/Session.AlertDialog</item>
<item name="bottomSheetStyle">@style/Widget.Session.BottomSheetDialog</item>
<item name="bottomSheetDialogTheme">@style/Theme.Session.BottomSheet</item>
<item name="preferenceTheme">@style/Session.SettingsTheme</item>
<item name="statusBarBackground">@color/accent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
@ -99,6 +99,12 @@
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.Session.BottomSheet" parent="@style/Theme.AppCompat.DayNight.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@style/Animation.MaterialComponents.BottomSheetDialog</item>
<item name="bottomSheetStyle">@style/Widget.Session.BottomSheetDialog</item>
</style>
<!-- Session -->
<style name="TextSecure.LightNoActionBar" parent="@style/TextSecure.LightTheme">

View File

@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.database.model.ThreadRecord
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob
import org.thoughtcrime.securesms.loki.dialogs.ConversationOptionsBottomSheet
import org.thoughtcrime.securesms.loki.dialogs.LightThemeFeatureIntroBottomSheet
import org.thoughtcrime.securesms.loki.dialogs.MultiDeviceRemovalBottomSheet
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
import org.thoughtcrime.securesms.loki.protocol.SessionResetImplementation
@ -200,8 +201,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
if (hasViewedSeed || !isMasterDevice) {
seedReminderView.visibility = View.GONE
}
val hasSeenMultiDeviceRemovalSheet = TextSecurePreferences.getHasSeenMultiDeviceRemovalSheet(this)
if (!hasSeenMultiDeviceRemovalSheet) {
// Multiple device removal notification
if (!TextSecurePreferences.getHasSeenMultiDeviceRemovalSheet(this)) {
TextSecurePreferences.setHasSeenMultiDeviceRemovalSheet(this)
val userPublicKey = TextSecurePreferences.getLocalNumber(this)
val deviceLinks = DatabaseFactory.getLokiAPIDatabase(this).getDeviceLinks(userPublicKey)
@ -217,8 +219,18 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
startActivity(intent)
}
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
return
}
}
// Light theme introduction
if (!TextSecurePreferences.hasSeenLightThemeIntroSheet(this) &&
UiModeUtilities.isDayUiMode(this)) {
TextSecurePreferences.setHasSeenLightThemeIntroSheet(this)
val bottomSheet = LightThemeFeatureIntroBottomSheet()
bottomSheet.show(supportFragmentManager, bottomSheet.tag)
return
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

View File

@ -116,6 +116,7 @@ class PNModeActivity : BaseActionBarActivity() {
TextSecurePreferences.setPromptedPushRegistration(this, true)
TextSecurePreferences.setIsUsingFCM(this, (selectedOptionView == fcmOptionView))
TextSecurePreferences.setHasSeenMultiDeviceRemovalSheet(this)
TextSecurePreferences.setHasSeenLightThemeIntroSheet(this)
val application = ApplicationContext.getInstance(this)
application.setUpStorageAPIIfNeeded()
application.setUpP2PAPIIfNeeded()

View File

@ -30,6 +30,5 @@ class ChangeUiModeDialog : DialogFragment() {
.setTitle("Application theme")
.setNegativeButton("Cancel") { _, _ -> dismiss() }
.create()
}
}

View File

@ -0,0 +1,26 @@
package org.thoughtcrime.securesms.loki.dialogs
import android.os.Bundle
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_light_theme_feature_intro_bottom_sheet.*
import kotlinx.android.synthetic.main.fragment_open_group_suggestion_bottom_sheet.*
import network.loki.messenger.R
class LightThemeFeatureIntroBottomSheet : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(
R.layout.fragment_light_theme_feature_intro_bottom_sheet,
container,
false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
okButton.setOnClickListener { dismiss() }
}
}

View File

@ -13,7 +13,7 @@ object UiModeUtilities {
private const val PREF_KEY_SELECTED_UI_MODE = "SELECTED_UI_MODE"
@JvmStatic
public fun setUserSelectedUiMode(context: Context, uiMode: UiMode) {
fun setUserSelectedUiMode(context: Context, uiMode: UiMode) {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit()
.putString(PREF_KEY_SELECTED_UI_MODE, uiMode.name)
@ -22,7 +22,7 @@ object UiModeUtilities {
}
@JvmStatic
public fun getUserSelectedUiMode(context: Context): UiMode {
fun getUserSelectedUiMode(context: Context): UiMode {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val selectedUiModeName = prefs.getString(PREF_KEY_SELECTED_UI_MODE, UiMode.SYSTEM_DEFAULT.name)!!
var selectedUiMode: UiMode
@ -36,27 +36,28 @@ object UiModeUtilities {
}
@JvmStatic
public fun setupUiModeToUserSelected(context: Context) {
fun setupUiModeToUserSelected(context: Context) {
val selectedUiMode = getUserSelectedUiMode(context)
setUserSelectedUiMode(context, selectedUiMode)
}
/**
* Whether the application UI is in the light mode
* (do not confuse with the user selected UiMode).
*/
@JvmStatic
fun isDayUiMode(context: Context): Boolean {
val uiModeNightBit = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return uiModeNightBit == Configuration.UI_MODE_NIGHT_NO
}
}
//TODO Use localized string resources.
enum class UiMode(
val displayName: String,
val uiModeNightFlag: Int,
val nightModeValue: Int) {
DAY ("Day",
Configuration.UI_MODE_NIGHT_NO,
AppCompatDelegate.MODE_NIGHT_NO),
NIGHT ("Night",
Configuration.UI_MODE_NIGHT_YES,
AppCompatDelegate.MODE_NIGHT_YES),
SYSTEM_DEFAULT ("System default",
Configuration.UI_MODE_NIGHT_UNDEFINED,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
DAY("Day", AppCompatDelegate.MODE_NIGHT_NO),
NIGHT("Night", AppCompatDelegate.MODE_NIGHT_YES),
SYSTEM_DEFAULT("System default", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}

View File

@ -1316,5 +1316,13 @@ public class TextSecurePreferences {
public static void setHasSeenMultiDeviceRemovalSheet(Context context) {
setBooleanPreference(context, "has_seen_multi_device_removal_sheet", true);
}
public static boolean hasSeenLightThemeIntroSheet(Context context) {
return getBooleanPreference(context, "has_seen_light_theme_intro_sheet", false);
}
public static void setHasSeenLightThemeIntroSheet(Context context) {
setBooleanPreference(context, "has_seen_light_theme_intro_sheet", true);
}
// endregion
}