Skip to content

Commit

Permalink
Version bump, detekt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaisn committed Sep 6, 2021
1 parent 1dd8f06 commit e2548f8
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 78 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "com.maltaisn.notes.sync"
minSdkVersion 21
targetSdkVersion 30
versionCode 10400
versionName "1.4.0"
versionCode 10401
versionName "1.4.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

kapt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Screenshots {
))

onView(allOf(isDescendantOfA(withId(R.id.fragment_note_layout)), withId(R.id.recycler_view)))
.perform(actionOnItemAtPosition<NoteViewHolder>(0, click()))
.perform(actionOnItemAtPosition<NoteViewHolder<*>>(0, click()))
delay(250)
onView(allOf(isDescendantOfA(withId(R.id.fragment_edit_layout)), withId(R.id.recycler_view)))
.perform(actionOnItemAtPosition<EditItemViewHolder>(3, click()))
Expand Down Expand Up @@ -180,7 +180,7 @@ class Screenshots {
))

onView(allOf(isDescendantOfA(withId(R.id.fragment_note_layout)), withId(R.id.recycler_view)))
.perform(actionOnItemAtPosition<NoteViewHolder>(1, longClick()))
.perform(actionOnItemAtPosition<NoteViewHolder<*>>(1, longClick()))
delay(250)
onView(toolbarItem(R.id.item_reminder)).perform(click())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package com.maltaisn.notes.model
* This is used to catch forward compatibility fails.
*/
class BadDataException(message: String = "", cause: Throwable? = null)
: IllegalStateException(message, cause)
: IllegalStateException(message, cause)
33 changes: 20 additions & 13 deletions app/src/main/kotlin/com/maltaisn/notes/model/DefaultJsonManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,22 @@ class DefaultJsonManager @Inject constructor(
return ImportResult.BAD_DATA
}

// Add labels
// Import all data
val newLabelsMap = importLabels(notesData)
importNotes(notesData, newLabelsMap)

// Update all reminders
reminderAlarmManager.updateAllAlarms()

return if (notesData.version > VERSION) {
// data comes from future version of app
ImportResult.FUTURE_VERSION
} else {
ImportResult.SUCCESS
}
}

private suspend fun importLabels(notesData: NotesData): Map<Long, Long> {
val existingLabels = labelsDao.getAll()
val existingLabelsIdMap = existingLabels.associateBy { it.id }
val existingLabelsNameMap = existingLabels.associateBy { it.name }
Expand Down Expand Up @@ -120,8 +135,10 @@ class DefaultJsonManager @Inject constructor(
newLabelsMap[id] = labelsDao.insert(Label(id, labelName))
}
}
return newLabelsMap
}

// Add notes
private suspend fun importNotes(notesData: NotesData, newLabelsMap: Map<Long, Long>) {
val existingNotes = notesDao.getAll().asSequence().map { it.note }.associateBy { it.id }
val labelRefs = mutableListOf<LabelRef>()
for ((id, ns) in notesData.notes) {
Expand Down Expand Up @@ -150,16 +167,6 @@ class DefaultJsonManager @Inject constructor(
}
}
labelsDao.insertRefs(labelRefs)

// Update all reminders
reminderAlarmManager.updateAllAlarms()

return if (notesData.version > VERSION) {
// data comes from future version of app
ImportResult.FUTURE_VERSION
} else {
ImportResult.SUCCESS
}
}

enum class ImportResult {
Expand All @@ -180,7 +187,7 @@ class DefaultJsonManager @Inject constructor(
* adding [labels] to store label references.
*/
@Serializable
private class NoteSurrogate(
private data class NoteSurrogate(
@SerialName("type")
val type: NoteType,
@SerialName("title")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ enum class SortField(override val value: String) : ValueEnum<String> {
enum class SortDirection(override val value: String) : ValueEnum<String> {
ASCENDING("ascending"),
DESCENDING("descending"),
}
}
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/maltaisn/notes/model/ValueEnum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package com.maltaisn.notes.model
*/
interface ValueEnum<T> {
val value: T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class LabelEditViewModel @AssistedInject constructor(
}

companion object {
private val KEY_NAME = "name"
private val KEY_HIDDEN = "hidden"
private const val KEY_NAME = "name"
private const val KEY_HIDDEN = "hidden"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ class LabelViewModel @AssistedInject constructor(

/** Set the selected state of all notes to [selected]. */
private fun setAllSelected(selected: Boolean) {
if (!selected && selectedLabels.isEmpty() ||
selected && selectedLabels.size == listItems.size
) {
// Already all unselected or all selected.
val allSelected = selected && selectedLabels.size == listItems.size
val allUnselected = !selected && selectedLabels.isEmpty()
if (allSelected || allUnselected) {
// No changes needed.
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package com.maltaisn.notes.ui.note
data class Highlighted(
val content: String,
val highlights: List<IntRange> = emptyList()
)
)
84 changes: 46 additions & 38 deletions app/src/main/kotlin/com/maltaisn/notes/ui/note/NoteItemFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.maltaisn.notes.ui.note

import com.maltaisn.notes.model.PrefsManager
import com.maltaisn.notes.model.entity.Label
import com.maltaisn.notes.model.entity.ListNoteItem
import com.maltaisn.notes.model.entity.Note
import com.maltaisn.notes.model.entity.NoteType
import com.maltaisn.notes.ui.note.adapter.NoteItemList
Expand Down Expand Up @@ -94,43 +95,8 @@ class NoteItemFactory @Inject constructor(
items.sortBy { it.checked }
}

val highlights = if (query == null) {
mutableListOf()
} else {
var maxHighlights = MAX_HIGHLIGHTS_IN_LIST
items.mapTo(mutableListOf()) {
val ranges = HighlightHelper.findHighlightsInString(it.content, query!!,
minOf(maxHighlights, MAX_HIGHLIGHTS_IN_LIST_ITEM))
maxHighlights -= ranges.size
ranges
}
}

val maxItemsCount = prefs.getMaximumPreviewLines(NoteType.LIST)
val itemsCount = minOf(maxItemsCount, if (prefs.moveCheckedToBottom) {
var count = items.indexOfFirst { it.checked }
if (count == -1) {
count = items.size
}
if (query != null) {
// Show checked items with highlights as well
val checkedHighlighed = items.foldIndexed(0) { i, c, item ->
if (highlights[i].isNotEmpty() && item.checked) {
c + 1
} else {
c
}
}
count += checkedHighlighed
}
if (MINIMUM_LIST_NOTE_ITEMS in count until maxItemsCount) {
// Less than minimum unchecked items, add checked items.
count = minOf(items.size, MINIMUM_LIST_NOTE_ITEMS)
}
count
} else {
items.size
})
val highlights = getListItemHighlights(items)
val itemsCount = getListItemCount(items, highlights)

var onlyCheckedInOverflow = true
if (query != null) {
Expand Down Expand Up @@ -176,6 +142,48 @@ class NoteItemFactory @Inject constructor(
itemsChecked, overflowCount, onlyCheckedInOverflow, showMarkAsDone)
}

private fun getListItemCount(items: List<ListNoteItem>, highlights: List<List<IntRange>>): Int {
val maxItemsCount = prefs.getMaximumPreviewLines(NoteType.LIST)
return minOf(maxItemsCount, if (prefs.moveCheckedToBottom) {
var count = items.indexOfFirst { it.checked }
if (count == -1) {
count = items.size
}
if (query != null) {
// Show checked items with highlights as well
val checkedHighlighed = items.foldIndexed(0) { i, c, item ->
if (highlights[i].isNotEmpty() && item.checked) {
c + 1
} else {
c
}
}
count += checkedHighlighed
}
if (MINIMUM_LIST_NOTE_ITEMS in count until maxItemsCount) {
// Less than minimum unchecked items, add checked items.
count = minOf(items.size, MINIMUM_LIST_NOTE_ITEMS)
}
count
} else {
items.size
})
}

private fun getListItemHighlights(items: List<ListNoteItem>): MutableList<MutableList<IntRange>> {
return if (query == null) {
mutableListOf()
} else {
var maxHighlights = MAX_HIGHLIGHTS_IN_LIST
items.mapTo(mutableListOf()) {
val ranges = HighlightHelper.findHighlightsInString(it.content, query!!,
minOf(maxHighlights, MAX_HIGHLIGHTS_IN_LIST_ITEM))
maxHighlights -= ranges.size
ranges
}
}
}

private fun createTitle(note: Note): Highlighted {
var title = note.title.trim()
if (appendIdToTitle) {
Expand Down Expand Up @@ -219,4 +227,4 @@ class NoteItemFactory @Inject constructor(
private const val START_ELLIPSIS_THRESHOLD_CONTENT_FIRST = 5 // for first line of preview
private const val START_ELLIPSIS_DISTANCE_CONTENT = 20
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class NotificationViewModel @AssistedInject constructor(
// Open time dialog next
viewModelScope.launch {
// TODO thats ugly
delay(250)
delay(INTER_DIALOG_DELAY)
_showTimeDialogEvent.send(postponeTime)
}
}
Expand Down Expand Up @@ -139,6 +139,8 @@ class NotificationViewModel @AssistedInject constructor(
}

companion object {
private const val INTER_DIALOG_DELAY = 250L

private const val KEY_NOTE_ID = "note_id"
private const val KEY_POSTPONE_TIME = "postpone_time"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ReminderViewModel @AssistedInject constructor(
val currHour = calendar[Calendar.HOUR_OF_DAY]
val todayReminderHour = DEFAULT_REMINDER_HOURS.find { it > currHour + REMINDER_HOUR_MIN_DISTANCE }
calendar[Calendar.HOUR_OF_DAY] = todayReminderHour ?:
DEFAULT_REMINDER_HOURS.first { it > currHour + REMINDER_HOUR_MIN_DISTANCE - 24 }
DEFAULT_REMINDER_HOURS.first { it > currHour + REMINDER_HOUR_MIN_DISTANCE - HOURS_IN_DAY }
calendar[Calendar.MINUTE] = 0
calendar[Calendar.SECOND] = 0
calendar[Calendar.MILLISECOND] = 0
Expand Down Expand Up @@ -336,6 +336,8 @@ class ReminderViewModel @AssistedInject constructor(
private val DEFAULT_REMINDER_HOURS = listOf(8, 13, 18, 20)
private const val REMINDER_HOUR_MIN_DISTANCE = 3

private const val HOURS_IN_DAY = 24

private const val KEY_DATE = "date"
private const val KEY_RECURRENCE = "recurrence"
private const val KEY_NOTE_IDS = "note_ids"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/play/release-notes/en-US/production.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
- Added ability to hide all notes with a particular label.
- Added clickable links to edit screen.
- New Spanish translation.
- Added sorting options.
- Show more highlights in search screen.
- Many bug fixes.
5 changes: 2 additions & 3 deletions app/src/main/play/release-notes/fr-CA/production.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
- Ajout d'une fonctionnalité pour cacher les notes ayant une étiquette en particulier.
- Ajout de liens cliquables lors de l'édition.
- Nouvelle traduction en espagnol.
- Ajout d'options de tri.
- Plus de résultats surlignés dans la recherche.
- Plusieurs bugs corrigés.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class MockAlarmCallback : ReminderAlarmCallback {
alarms -= noteId
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ class RelativeDateFormatterTest {
))
}

}
}
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath "com.android.tools.build:gradle:$androidGradlePluginVersion"
Expand All @@ -16,7 +18,7 @@ buildscript {

plugins {
id "base"
id "io.gitlab.arturbosch.detekt" version "1.16.0"
id "io.gitlab.arturbosch.detekt" version "1.18.1"
}


Expand Down
1 change: 1 addition & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ complexity:
LargeClass:
active: true
threshold: 600
excludes: ['**/test/**', '**/androidTest/**', '**/sharedTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
LongMethod:
active: true
threshold: 60
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# App version
# Must be updated manually in app/build.gradle!
# (F-Droid only supports raw literals for auto update detection)
appVersion=1.4.0
appVersionCode=10400
appVersion=1.4.1
appVersionCode=10401

# Kotlin
kotlinVersion=1.5.30
Expand Down

0 comments on commit e2548f8

Please sign in to comment.