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

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
}