From 5cb00ccf0ecff781894d97f5de33c4fa276e362c Mon Sep 17 00:00:00 2001 From: Bijoy Singh Kochar Date: Sun, 17 Jun 2018 21:21:54 +0100 Subject: [PATCH] Adding ability to not export locked notes. Adding more upsells --- .../com/maubis/scarlet/base/MainActivity.kt | 2 + .../sheet/BackupSettingsOptionsBottomSheet.kt | 14 +++++++ .../base/export/support/NoteExporter.kt | 9 ++++- .../main/recycler/InformationRecyclerItem.kt | 38 +++++++++++++++++++ base/src/main/res/values/strings.xml | 2 + 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/base/src/main/java/com/maubis/scarlet/base/MainActivity.kt b/base/src/main/java/com/maubis/scarlet/base/MainActivity.kt index 6d49bd57..20d98c57 100644 --- a/base/src/main/java/com/maubis/scarlet/base/MainActivity.kt +++ b/base/src/main/java/com/maubis/scarlet/base/MainActivity.kt @@ -276,6 +276,8 @@ class MainActivity : ThemedActivity(), ITutorialActivity, INoteOptionSheetActivi shouldShowAppUpdateInformationItem() -> getAppUpdateInformationItem(this) shouldShowReviewInformationItem() -> getReviewInformationItem(this) shouldShowInstallProInformationItem() -> getInstallProInformationItem(this) + shouldShowThemeInformationItem() -> getThemeInformationItem(this) + shouldShowBackupInformationItem() -> getBackupInformationItem(this) else -> null } if (informationItem === null) { diff --git a/base/src/main/java/com/maubis/scarlet/base/export/sheet/BackupSettingsOptionsBottomSheet.kt b/base/src/main/java/com/maubis/scarlet/base/export/sheet/BackupSettingsOptionsBottomSheet.kt index 153c6bc8..ef909171 100644 --- a/base/src/main/java/com/maubis/scarlet/base/export/sheet/BackupSettingsOptionsBottomSheet.kt +++ b/base/src/main/java/com/maubis/scarlet/base/export/sheet/BackupSettingsOptionsBottomSheet.kt @@ -82,6 +82,16 @@ class BackupSettingsOptionsBottomSheet : OptionItemBottomSheetBase() { }, enabled = exportAsMarkdown )) + options.add(OptionsItem( + title = R.string.import_export_locked, + subtitle = R.string.import_export_locked_details, + icon = R.drawable.ic_action_lock, + listener = View.OnClickListener { + exportLockedNotes = !exportLockedNotes + reset(dialog) + }, + enabled = exportLockedNotes + )) val autoBackupEnabled = CoreConfig.instance.store().get(KEY_AUTO_BACKUP_MODE, false) options.add(OptionsItem( title = R.string.home_option_auto_export, @@ -152,5 +162,9 @@ class BackupSettingsOptionsBottomSheet : OptionItemBottomSheetBase() { sheet.show(activity.supportFragmentManager, sheet.tag) } + + var exportLockedNotes: Boolean + get() = CoreConfig.instance.store().get(KEY_BACKUP_LOCKED, true) + set(value) = CoreConfig.instance.store().put(KEY_BACKUP_LOCKED, value) } } \ No newline at end of file diff --git a/base/src/main/java/com/maubis/scarlet/base/export/support/NoteExporter.kt b/base/src/main/java/com/maubis/scarlet/base/export/support/NoteExporter.kt index 89e204e5..098d8de8 100644 --- a/base/src/main/java/com/maubis/scarlet/base/export/support/NoteExporter.kt +++ b/base/src/main/java/com/maubis/scarlet/base/export/support/NoteExporter.kt @@ -9,6 +9,7 @@ import com.maubis.scarlet.base.config.CoreConfig import com.maubis.scarlet.base.export.data.ExportableFileFormat import com.maubis.scarlet.base.export.data.ExportableNote import com.maubis.scarlet.base.export.data.ExportableTag +import com.maubis.scarlet.base.export.sheet.BackupSettingsOptionsBottomSheet import com.maubis.scarlet.base.export.sheet.ExportNotesBottomSheet import com.maubis.scarlet.base.note.getFullText import com.maubis.scarlet.base.support.database.notesDB @@ -17,6 +18,7 @@ import java.io.File import java.util.* const val KEY_NOTE_VERSION = "KEY_NOTE_VERSION" +const val KEY_BACKUP_LOCKED = "KEY_BACKUP_LOCKED" const val KEY_BACKUP_MARKDOWN = "KEY_BACKUP_MARKDOWN" const val KEY_BACKUP_LOCATION = "KEY_BACKUP_LOCATION" const val KEY_AUTO_BACKUP_MODE = "KEY_AUTO_BACKUP_MODE" @@ -35,7 +37,12 @@ class NoteExporter() { return getMarkdownExportContent() } - val notes = notesDB.getAll().map { ExportableNote(it) } + val exportLocked = BackupSettingsOptionsBottomSheet.exportLockedNotes + + val notes = notesDB + .getAll() + .filter { exportLocked || !it.locked } + .map { ExportableNote(it) } val tags = tagsDB.getAll().map { ExportableTag(it) } val fileContent = ExportableFileFormat(EXPORT_VERSION, notes, tags) return Gson().toJson(fileContent) diff --git a/base/src/main/java/com/maubis/scarlet/base/main/recycler/InformationRecyclerItem.kt b/base/src/main/java/com/maubis/scarlet/base/main/recycler/InformationRecyclerItem.kt index 79b4fbbc..d1e37bc0 100644 --- a/base/src/main/java/com/maubis/scarlet/base/main/recycler/InformationRecyclerItem.kt +++ b/base/src/main/java/com/maubis/scarlet/base/main/recycler/InformationRecyclerItem.kt @@ -2,8 +2,11 @@ package com.maubis.scarlet.base.main.recycler import android.content.Context import com.github.bijoysingh.starter.util.IntentUtils +import com.maubis.scarlet.base.MainActivity import com.maubis.scarlet.base.R import com.maubis.scarlet.base.config.CoreConfig +import com.maubis.scarlet.base.export.sheet.BackupSettingsOptionsBottomSheet +import com.maubis.scarlet.base.settings.sheet.UISettingsOptionsBottomSheet import com.maubis.scarlet.base.support.Flavor import com.maubis.scarlet.base.support.recycler.RecyclerItem import java.util.* @@ -12,6 +15,8 @@ const val KEY_INFO_RATE_AND_REVIEW = "KEY_RATE_AND_REVIEW_INFO" const val KEY_INFO_INSTALL_PRO_v2 = "KEY_INFO_INSTALL_PRO_v2" const val KEY_INFO_SIGN_IN = "KEY_INFO_SIGN_IN" const val KEY_FORCE_SHOW_SIGN_IN = "KEY_FORCE_SHOW_SIGN_IN" +const val KEY_THEME_OPTIONS = "KEY_THEME_OPTIONS" +const val KEY_BACKUP_OPTIONS = "KEY_BACKUP_OPTIONS" const val KEY_INFO_INSTALL_PRO_MAX_COUNT = 10 @@ -49,6 +54,39 @@ fun getReviewInformationItem(context: Context): InformationRecyclerItem { }) } +fun shouldShowThemeInformationItem(): Boolean { + return probability(0.01f) + && !CoreConfig.instance.store().get(KEY_THEME_OPTIONS, false) +} + +fun getThemeInformationItem(activity: MainActivity): InformationRecyclerItem { + return InformationRecyclerItem( + R.drawable.ic_action_grid, + R.string.home_option_ui_experience, + R.string.home_option_ui_experience_subtitle, + { + CoreConfig.instance.store().put(KEY_THEME_OPTIONS, true) + UISettingsOptionsBottomSheet.openSheet(activity) + }) +} + +fun shouldShowBackupInformationItem(): Boolean { + return probability(0.01f) + && !CoreConfig.instance.store().get(KEY_BACKUP_OPTIONS, false) +} + +fun getBackupInformationItem(activity: MainActivity): InformationRecyclerItem { + return InformationRecyclerItem( + R.drawable.ic_export, + R.string.home_option_backup_options, + R.string.home_option_backup_options_subtitle, + { + CoreConfig.instance.store().put(KEY_BACKUP_OPTIONS, true) + BackupSettingsOptionsBottomSheet.openSheet(activity) + }) +} + + fun shouldShowInstallProInformationItem(): Boolean { return probability(0.01f) && CoreConfig.instance.store().get(KEY_INFO_INSTALL_PRO_v2, 0) < KEY_INFO_INSTALL_PRO_MAX_COUNT diff --git a/base/src/main/res/values/strings.xml b/base/src/main/res/values/strings.xml index 91a2b0fa..69cdf494 100644 --- a/base/src/main/res/values/strings.xml +++ b/base/src/main/res/values/strings.xml @@ -187,6 +187,8 @@ Done Share MaterialNotes/BACKUP.txt + Export locked notes + Also backup the notes which are locked %s KB %s MB