Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.4.4 #103

Merged
merged 5 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

## Version 5.4.4

_2022-03-26_

* Compile with SDK 32.
* Update dependencies to stable version.
* Switch to Material3 theme.
* Replace FuzzySearch library with Levenshtein algorithm implementation.

## Version 5.4.3

_2021-12-29_
Expand All @@ -12,7 +21,7 @@ _2021-12-29_
_2021-12-24_

* Update to Kotlin 1.6.10.
* Update Corooutines to 1.6.0.
* Update Coroutines to 1.6.0.
* Update Gradle wrapper to 7.3.3.
* Refactor edit database activity to rename database dialog.

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ Then add the following dependencies in your app `build.gradle` or `build.gradle.

**Groovy**
```groovy
debugImplementation "com.infinum.dbinspector:dbinspector:5.4.3"
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.4.3"
debugImplementation "com.infinum.dbinspector:dbinspector:5.4.4"
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.4.4"
```
**KotlinDSL**
```kotlin
debugImplementation("com.infinum.dbinspector:dbinspector:5.4.3")
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.4.3")
debugImplementation("com.infinum.dbinspector:dbinspector:5.4.4")
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.4.4")
```

### Usage
Expand Down
10 changes: 5 additions & 5 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ext {
buildConfig = [
"minSdk" : 21,
"compileSdk": 31,
"targetSdk" : 31,
"buildTools": "31.0.0"
"compileSdk": 32,
"targetSdk" : 32,
"buildTools": "32.0.0"
]
releaseConfig = [
"group" : "com.infinum.dbinspector",
"version" : "5.4.3",
"versionCode": 5 * 100 * 100 + 4 * 100 + 3
"version" : "5.4.4",
"versionCode": 5 * 100 * 100 + 4 * 100 + 4
]
}
1 change: 0 additions & 1 deletion dbinspector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ dependencies {
implementation libs.protobuf.javalite
implementation libs.material
implementation libs.koin.android
implementation libs.fuzzy

testImplementation libs.bundles.test
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.infinum.dbinspector

import android.content.Intent
import com.infinum.dbinspector.data.sources.memory.logger.EmptyLogger
import com.infinum.dbinspector.data.sources.memory.logger.Logger
import com.infinum.dbinspector.ui.Presentation
import com.infinum.dbinspector.ui.databases.DatabasesActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.infinum.dbinspector.data.sources.local.proto.history.HistorySerialize
import com.infinum.dbinspector.data.sources.local.proto.settings.SettingsDataStore
import com.infinum.dbinspector.data.sources.local.proto.settings.SettingsSerializer
import com.infinum.dbinspector.data.sources.memory.connection.AndroidConnectionSource
import com.infinum.dbinspector.data.sources.memory.distance.LevenshteinDistance
import com.infinum.dbinspector.data.sources.memory.pagination.CursorPaginator
import com.infinum.dbinspector.data.sources.memory.pagination.Paginator
import com.infinum.dbinspector.data.sources.raw.AndroidDatabasesSource
Expand Down Expand Up @@ -102,7 +103,9 @@ internal object Data {

factory<Paginator>(qualifier = Qualifiers.Schema.RAW_QUERY) { CursorPaginator() }

single<Sources.Memory> { AndroidConnectionSource() }
single<Sources.Memory.Connection> { AndroidConnectionSource() }

single<Sources.Memory.Distance> { LevenshteinDistance() }
}

private fun local() = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ internal interface Sources {

interface Memory {

suspend fun openConnection(path: String): SQLiteDatabase
interface Connection {

suspend fun closeConnection(path: String)
suspend fun openConnection(path: String): SQLiteDatabase

suspend fun closeConnection(path: String)
}

interface Distance {

suspend fun calculate(query: String, options: List<String>): Int?
}
}

interface Local {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.database.sqlite.SQLiteDatabase
import androidx.annotation.VisibleForTesting
import com.infinum.dbinspector.data.Sources

internal class AndroidConnectionSource : Sources.Memory {
internal class AndroidConnectionSource : Sources.Memory.Connection {

@VisibleForTesting
internal val connectionPool: HashMap<String, SQLiteDatabase> = hashMapOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.infinum.dbinspector.data.sources.memory.distance

import com.infinum.dbinspector.data.Sources
import kotlin.math.min

/**
* Algorithm for measuring the difference between two Strings, also called a distance.
*
* It is the number of changes needed to change one String into another,
* where each change is a single character modification.
*
*/
internal class LevenshteinDistance : Sources.Memory.Distance {

/**
* Iterates over options and calculates unlimited distance between each option and query String.
* Maps a tuple of index, option, and distance, then finds minimum distance tuple and returns index.
*
* @return result index of option with minimum distance.
*/
override suspend fun calculate(query: String, options: List<String>): Int? =
options.mapIndexed { index, option ->
Triple(index, option, calculateUnlimited(query, option))
}
.minByOrNull { it.third }
?.first

/**
* Calculates Levenshtein distance between two Strings without a threshold to pass.
* A higher score indicates a greater distance.
*
* calculateUnlimited("scar", "car") = 1
* calculateUnlimited("car", "mug") = 3
*
* @return result distance.
*/
@Suppress("NestedBlockDepth", "ReturnCount")
private fun calculateUnlimited(
query: String,
other: String
): Int {
var left: String = query
var right: String = other

var leftLength = left.length
var rightLength = right.length
when {
leftLength == 0 -> return rightLength
rightLength == 0 -> return leftLength
else -> {
if (leftLength > rightLength) {
val tmp: String = left
left = right
right = tmp
leftLength = rightLength
rightLength = right.length
}
val previous = IntArray(leftLength + 1)

var i: Int
var j = 1
var upperLeft: Int
var upper: Int
var rightJ: Char
var cost: Int
i = 0
while (i <= leftLength) {
previous[i] = i
i++
}
while (j <= rightLength) {
upperLeft = previous[0]
rightJ = right[j - 1]
previous[0] = j
i = 1
while (i <= leftLength) {
upper = previous[i]
cost = if (left[i - 1] == rightJ) 0 else 1
previous[i] = min(min(previous[i - 1] + 1, previous[i] + 1), upperLeft + cost)
upperLeft = upper
i++
}
j++
}
return previous[leftLength]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ internal object Domain {
factory<Interactors.SaveExecution> { SaveExecutionInteractor(get()) }
factory<Interactors.ClearHistory> { ClearHistoryInteractor(get()) }
factory<Interactors.RemoveExecution> { RemoveExecutionInteractor(get()) }
factory<Interactors.GetExecution> { GetExecutionInteractor(get()) }
factory<Interactors.GetExecution> { GetExecutionInteractor(get(), get()) }

factory<Mappers.Execution> { ExecutionMapper() }
factory<Mappers.History> { HistoryMapper(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.domain.Interactors

internal class CloseConnectionInteractor(
private val source: Sources.Memory
private val source: Sources.Memory.Connection
) : Interactors.CloseConnection {

override suspend fun invoke(input: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.domain.Interactors

internal class OpenConnectionInteractor(
private val source: Sources.Memory
private val source: Sources.Memory.Connection
) : Interactors.OpenConnection {

override suspend fun invoke(input: String): SQLiteDatabase =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.data.models.local.proto.input.HistoryTask
import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity
import com.infinum.dbinspector.domain.Interactors
import me.xdrop.fuzzywuzzy.FuzzySearch

internal class GetExecutionInteractor(
private val dataStore: Sources.Local.History
private val dataStore: Sources.Local.History,
private val distance: Sources.Memory.Distance
) : Interactors.GetExecution {

override suspend fun invoke(input: HistoryTask): HistoryEntity =
dataStore.current()
.executionsList
.filter { it.databasePath == input.execution?.databasePath }
.takeIf { it.isNotEmpty() }
?.let { entities ->
FuzzySearch.extractOne(
?.let { entities: List<HistoryEntity.ExecutionEntity> ->
distance.calculate(
input.execution?.execution.orEmpty(),
entities.map { it.execution }
)
?.takeIf { it.score != 0 }
?.let { entities[it.index] }
entities.map { it.execution },
)?.let { index -> entities[index] }
}
?.let {
HistoryEntity.getDefaultInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/scrollView">

Expand Down Expand Up @@ -83,7 +82,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/suggestionButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
Expand All @@ -108,7 +107,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/errorView"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="12dp"
Expand All @@ -119,7 +118,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/affectedRowsView"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">

Expand Down Expand Up @@ -56,7 +55,7 @@

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/importButton"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
style="@style/Widget.Material3.ExtendedFloatingActionButton.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
Expand Down
7 changes: 3 additions & 4 deletions dbinspector/src/main/res/layout/dbinspector_activity_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/scrollView">

Expand Down Expand Up @@ -82,7 +81,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/suggestionButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
Expand All @@ -107,7 +106,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/errorView"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="12dp"
Expand All @@ -118,7 +117,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/affectedRowsView"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/scrollView">

Expand Down Expand Up @@ -44,7 +43,7 @@
android:orientation="vertical">

<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dbinspector_database_name"
Expand All @@ -53,7 +52,7 @@

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nameInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down
Loading