Skip to content

Commit

Permalink
Adding undo/redo
Browse files Browse the repository at this point in the history
  • Loading branch information
BijoySingh committed Jun 19, 2018
1 parent 5cb00cc commit cb02171
Show file tree
Hide file tree
Showing 33 changed files with 104 additions and 48 deletions.
Binary file modified base/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ class WhatsNewItemsBottomSheet : ThemedBottomSheetFragment() {
optionsTitle.setTextColor(CoreConfig.instance.themeController().get(ThemeColorType.SECONDARY_TEXT))
val whatsNew = "> A lot has changed in this update, here is a summary of those changes.\n" +
"### New Features\n" +
"- **History:** Adding undo / redo options for notes\n" +
"- **Merge Notes:** Adding option to merge multiple notes into one\n" +
"- **Search Tags:** Choose multiple tags to filter notes\n" +
"- **Search Colors:** Choose colors to filter notes by color of the note\n" +
"- **Sorting Mode:** Sort the notes in alphabetical order\n" +
"- **Markdown Export:** Export in Markdown format\n" +
"- **Markdown Export:** Export in Markdown format, Optionally not export locked notes \n" +
"- **Multiple Exports:** Export files now contain time, date information, allowing multiple backups\n" +
"- **Note Background Color:** Set the note viewer background as the note color (Pro Only)\n" +
"### Bugs Fix\n" +
Expand Down Expand Up @@ -74,7 +76,7 @@ class WhatsNewItemsBottomSheet : ThemedBottomSheetFragment() {
override fun getBackgroundCardViewIds(): Array<Int> = arrayOf(R.id.whats_new_card)

companion object {
val WHATS_NEW_UID = 5
val WHATS_NEW_UID = 6
val GOOGLE_TRANSLATE_URL = "https://translate.google.com/#auto/"

fun openSheet(activity: ThemedActivity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ import java.util.*
open class CreateNoteActivity : ViewAdvancedNoteActivity() {

private var active = false
private var lastNoteInstance: Note? = null
private var maxUid = 0
private var toolbarMode: ToolbarMode = ToolbarMode.FORMAT

private var historyIndex = 0
private var historySize = 0L

val text: ImageView by bind(R.id.format_text)
val heading: ImageView by bind(R.id.format_heading)
val subHeading: ImageView by bind(R.id.format_sub_heading)
Expand All @@ -59,13 +61,16 @@ open class CreateNoteActivity : ViewAdvancedNoteActivity() {
val chevronLeft: ImageView by bind(R.id.toolbar_chevron_left)
val chevronRight: ImageView by bind(R.id.toolbar_chevron_right)

val history: MutableList<Note> = emptyList<Note>().toMutableList()

override val editModeValue: Boolean get() = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTouchListener()
startHandler()
lastNoteInstance = NoteBuilder().copy(note!!)
history.add(NoteBuilder().copy(note!!))
notifyHistoryIcons()
}

override fun setEditMode() {
Expand Down Expand Up @@ -144,6 +149,19 @@ open class CreateNoteActivity : ViewAdvancedNoteActivity() {
}

override fun setTopToolbar() {
actionUndo.setOnClickListener {
historyIndex = if (historyIndex == 0) 0 else (historyIndex - 1)
note = NoteBuilder().copy(history.get(historyIndex))
notifyHistoryIcons()
setNote()
}
actionRedo.setOnClickListener {
val maxHistoryIndex = history.size - 1
historyIndex = if (historyIndex == maxHistoryIndex) maxHistoryIndex else (historyIndex + 1)
note = NoteBuilder().copy(history.get(historyIndex))
notifyHistoryIcons()
setNote()
}
actionDelete.visibility = GONE
actionShare.visibility = GONE
actionCopy.visibility = GONE
Expand Down Expand Up @@ -257,7 +275,7 @@ open class CreateNoteActivity : ViewAdvancedNoteActivity() {

protected fun maybeUpdateNoteWithoutSync() {
val vNote = note!!
val vLastNoteInstance = lastNoteInstance ?: note!!
val vLastNoteInstance = history.getOrNull(historyIndex) ?: note!!

vNote.description = FormatBuilder().getDescription(formats)

Expand All @@ -266,9 +284,39 @@ open class CreateNoteActivity : ViewAdvancedNoteActivity() {
return
}

addNoteToHistory(NoteBuilder().copy(vNote))
vNote.updateTimestamp = Calendar.getInstance().timeInMillis
maybeSaveNote(false)
lastNoteInstance = NoteBuilder().copy(vNote)
}

@Synchronized
private fun addNoteToHistory(note: Note) {
while (historyIndex != history.size - 1) {
history.removeAt(historyIndex)
}

history.add(note)
historySize += note.description.length
historyIndex += 1

// 0.5MB limit on history
if (historySize >= 1024 * 512 || history.size >= 15) {
val item = history.removeAt(0)
historySize -= item.description.length
historyIndex -= 1
}
notifyHistoryIcons()
}

private fun notifyHistoryIcons() {
actionRedo.alpha = when (historyIndex != history.size - 1) {
true -> 1.0f
false -> 0.4f
}
actionUndo.alpha = when (historyIndex == 0) {
true -> 0.4f
false -> 1.0f
}
}

private fun startHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ open class ViewAdvancedNoteActivity : ThemedActivity(), INoteOptionSheetActivity

val rootView: View by bind(R.id.root_layout)
val backButton: ImageView by bind(R.id.back_button)
val actionUndo: ImageView by bind(R.id.undo_button)
val actionRedo: ImageView by bind(R.id.redo_button)
val actionCopy: ImageView by bind(R.id.copy_button)
val actionDelete: ImageView by bind(R.id.delete_button)
val actionShare: ImageView by bind(R.id.share_button)
Expand Down Expand Up @@ -122,10 +124,15 @@ open class ViewAdvancedNoteActivity : ThemedActivity(), INoteOptionSheetActivity
resetBundle()
setNote()

actionDone.visibility = if (mode) VISIBLE else GONE
toolbar.visibility = if (mode) VISIBLE else GONE
primaryFab.visibility = if (mode || isDistractionFree) GONE else VISIBLE
secondaryFab.visibility = if (mode || isDistractionFree) GONE else VISIBLE
val visibleInEditMode = if (mode) VISIBLE else GONE
actionDone.visibility = visibleInEditMode
actionUndo.visibility = visibleInEditMode
actionRedo.visibility = visibleInEditMode
toolbar.visibility = visibleInEditMode

val visibleInNormalMode = if (mode || isDistractionFree) GONE else VISIBLE
primaryFab.visibility = visibleInNormalMode
secondaryFab.visibility = visibleInNormalMode
markdownToolbar.visibility = GONE
}

Expand Down Expand Up @@ -295,6 +302,8 @@ open class ViewAdvancedNoteActivity : ThemedActivity(), INoteOptionSheetActivity
}

backButton.setColorFilter(toolbarIconColor)
actionRedo.setColorFilter(toolbarIconColor)
actionUndo.setColorFilter(toolbarIconColor)
actionCopy.setColorFilter(toolbarIconColor)
actionDelete.setColorFilter(toolbarIconColor)
actionShare.setColorFilter(toolbarIconColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NoteSettingsOptionsBottomSheet : OptionItemBottomSheetBase() {
object : ColorPickerBottomSheet.ColorPickerDefaultController {
override fun getSheetTitle(): Int = R.string.choose_note_color

override fun getColorList(): IntArray = resources.getIntArray(R.array.bright_colors)
override fun getColorList(): IntArray = activity.resources.getIntArray(R.array.bright_colors)

override fun onColorSelected(color: Int) {
CoreConfig.instance.store().put(KEY_NOTE_DEFAULT_COLOR, color)
Expand Down
Binary file added base/src/main/res/drawable-hdpi/ic_redo_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/src/main/res/drawable-hdpi/ic_undo_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/src/main/res/drawable-mdpi/ic_redo_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/src/main/res/drawable-mdpi/ic_undo_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/src/main/res/drawable-xhdpi/ic_redo_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/src/main/res/drawable-xhdpi/ic_undo_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/drawable/ic_scarlet_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 22 additions & 31 deletions base/src/main/res/layout/toolbar_advanced_note.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/top_toolbar_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
Expand All @@ -13,44 +12,40 @@

<ImageView
android:id="@+id/back_button"
style="@style/BorderlessBackgroundView"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large"
android:padding="@dimen/spacing_xsmall"
android:src="@drawable/ic_close_white_48dp"
android:tint="@color/material_grey_600" />
style="@style/NoteCreatorToolbarIcon"
android:src="@drawable/ic_close_white_48dp" />

<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />


<ImageView
android:id="@+id/undo_button"
style="@style/NoteCreatorToolbarIcon"
android:src="@drawable/ic_undo_history" />

<ImageView
android:id="@+id/redo_button"
style="@style/NoteCreatorToolbarIcon"
android:src="@drawable/ic_redo_history" />

<ImageView
android:id="@+id/delete_button"
style="@style/BorderlessBackgroundView"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large"
android:padding="@dimen/spacing_xsmall"
android:src="@drawable/ic_delete_white_48dp"
android:tint="@color/material_grey_600" />
style="@style/NoteCreatorToolbarIcon"
android:src="@drawable/ic_delete_white_48dp" />

<ImageView
android:id="@+id/copy_button"
style="@style/BorderlessBackgroundView"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large"
style="@style/NoteCreatorToolbarIcon"
android:padding="9dp"
android:src="@drawable/ic_content_copy_white_48dp"
android:tint="@color/material_grey_600" />
android:src="@drawable/ic_content_copy_white_48dp" />

<ImageView
android:id="@+id/share_button"
style="@style/BorderlessBackgroundView"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large"
android:padding="@dimen/spacing_xsmall"
android:src="@drawable/ic_share_white_48dp"
android:tint="@color/material_grey_600" />
style="@style/NoteCreatorToolbarIcon"
android:src="@drawable/ic_share_white_48dp" />

<LinearLayout
android:id="@+id/color_button_clicker"
Expand All @@ -69,10 +64,6 @@

<ImageView
android:id="@+id/done_button"
style="@style/BorderlessBackgroundView"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large"
android:padding="@dimen/spacing_xsmall"
android:src="@drawable/ic_done_white_48dp"
android:tint="@color/material_grey_600" />
style="@style/NoteCreatorToolbarIcon"
android:src="@drawable/ic_done_white_48dp" />
</LinearLayout>
2 changes: 1 addition & 1 deletion base/src/main/res/layout/toolbar_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:id="@+id/home_button"
android:layout_width="@dimen/icon_size_large"
android:layout_height="@dimen/icon_size_large"
android:padding="@dimen/spacing_xsmall"
android:padding="@dimen/spacing_xxsmall"
android:layout_marginEnd="@dimen/spacing_xsmall"
android:src="@drawable/ic_scarlet_logo"
android:tint="@color/colorAccent" />
Expand Down
Binary file modified base/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified base/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion base/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<item name="android:layout_height">@dimen/icon_size_large</item>
<item name="android:tint">@color/light_hint_text</item>
<item name="android:padding">@dimen/spacing_xsmall</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
<item name="android:layout_gravity">center_vertical|end</item>
</style>

Expand Down Expand Up @@ -138,4 +137,11 @@
<item name="android:layout_margin">@dimen/spacing_xxsmall</item>
<item name="cardCornerRadius">@dimen/spacing_xxsmall</item>
</style>

<style name="NoteCreatorToolbarIcon" parent="BorderlessBackgroundView">
<item name="android:layout_width">@dimen/icon_size_large</item>
<item name="android:layout_height">@dimen/icon_size_large</item>
<item name="android:padding">@dimen/spacing_xsmall</item>
<item name="android:tint">@color/material_grey_600</item>
</style>
</resources>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.41'
ext.kotlin_version = '1.2.50'
ext.android_basics = '4.4.1'
ext.room_version = '1.0.0'
ext.ui_basics = '0.6.1'
ext.android_support_version = '27.1.1'
ext.firebase_version = '15.0.0'

ext.appconfig_version_code = 92
ext.appconfig_version = '5.8.2'
ext.appconfig_version_code = 95
ext.appconfig_version = '5.9.7'
ext.appconfig_min_os_version = 17
ext.appconfig_target_os_version = 27
ext.appconfig_build_tool_version = '27.0.3'
Expand All @@ -20,7 +20,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.zellius:android-shortcut-gradle-plugin:0.1.2'
Expand Down

0 comments on commit cb02171

Please sign in to comment.