Skip to content

Commit adc3723

Browse files
committed
Db to markdown migration
1 parent 1628198 commit adc3723

34 files changed

Lines changed: 408 additions & 1047 deletions

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ local.properties
1212
*.key
1313
*.aab
1414
*.jar
15-
/html
15+
/html
16+
/assets/tldr
17+
.claude
18+
/data/intructions.md
19+
/data/processed.txt

android/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ dependencies {
2727
androidTestImplementation(libs.androidx.ui.test.junit4)
2828
debugImplementation(libs.androidx.ui.test.manifest)
2929
debugImplementation(libs.androidx.ui.tooling)
30+
implementation(libs.multiplatform.markdown.renderer.android)
31+
implementation(libs.multiplatform.markdown.renderer.m2)
32+
implementation(libs.multiplatform.markdown.renderer.code)
3033
}
3134

3235
android {

android/src/androidTest/java/com/inspiredandroid/linuxcommandbibliotheca/ComposeDeeplinkTests.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.preference.PreferenceManager
1111
import androidx.test.core.app.ActivityScenario
1212
import androidx.test.core.app.ApplicationProvider
1313
import androidx.test.ext.junit.runners.AndroidJUnit4
14-
import com.linuxcommandlibrary.shared.initDatabase
1514
import org.junit.Before
1615
import org.junit.Rule
1716
import org.junit.Test
@@ -33,7 +32,6 @@ class ComposeDeeplinkTests {
3332
@Before
3433
fun setUp() {
3534
val context: Context = ApplicationProvider.getApplicationContext()
36-
initDatabase(context)
3735

3836
// Clear bookmarks
3937
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

android/src/androidTest/java/com/inspiredandroid/linuxcommandbibliotheca/ComposeScreenshots.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ import androidx.test.core.app.ActivityScenario
1313
import androidx.test.core.app.ApplicationProvider
1414
import androidx.test.ext.junit.runners.AndroidJUnit4
1515
import androidx.test.platform.app.InstrumentationRegistry
16-
import com.linuxcommandlibrary.shared.copyDatabase
17-
import com.linuxcommandlibrary.shared.initDatabase
1816
import kotlinx.coroutines.delay
1917
import kotlinx.coroutines.runBlocking
2018
import org.junit.Before
2119
import org.junit.Rule
2220
import org.junit.Test
2321
import org.junit.runner.RunWith
24-
import org.koin.java.KoinJavaComponent.inject
2522
import java.io.FileOutputStream
2623

2724
/**
@@ -43,11 +40,6 @@ class ComposeScreenshots {
4340
@Before
4441
fun setUp() {
4542
val context: Context = ApplicationProvider.getApplicationContext()
46-
copyDatabase(context)
47-
initDatabase(context)
48-
49-
val dataManager: com.inspiredandroid.linuxcommandbibliotheca.DataManager by inject(com.inspiredandroid.linuxcommandbibliotheca.DataManager::class.java)
50-
dataManager.updateDatabaseVersion()
5143

5244
// Clear bookmarks
5345
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

android/src/androidTest/java/com/inspiredandroid/linuxcommandbibliotheca/ComposeTests.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import androidx.compose.ui.test.junit4.createComposeRule
66
import androidx.preference.PreferenceManager
77
import androidx.test.core.app.ApplicationProvider
88
import androidx.test.ext.junit.runners.AndroidJUnit4
9-
import com.linuxcommandlibrary.shared.copyDatabase
10-
import com.linuxcommandlibrary.shared.databaseHelper
11-
import com.linuxcommandlibrary.shared.initDatabase
9+
import com.inspiredandroid.linuxcommandbibliotheca.data.BasicsRepository
10+
import com.inspiredandroid.linuxcommandbibliotheca.data.CommandsRepository
1211
import org.junit.Before
1312
import org.junit.Rule
1413
import org.junit.Test
1514
import org.junit.runner.RunWith
16-
import org.koin.java.KoinJavaComponent.inject
1715

1816
/**
1917
* Test for navigation, search and booksmarks. More tests to come
@@ -24,14 +22,15 @@ class ComposeTests {
2422
@get:Rule
2523
val composeTestRule = createComposeRule()
2624

25+
private lateinit var commandsRepository: CommandsRepository
26+
private lateinit var basicsRepository: BasicsRepository
27+
2728
@Before
2829
fun setUp() {
2930
val context: Context = ApplicationProvider.getApplicationContext()
30-
copyDatabase(context)
31-
initDatabase(context)
3231

33-
val dataManager: com.inspiredandroid.linuxcommandbibliotheca.DataManager by inject(com.inspiredandroid.linuxcommandbibliotheca.DataManager::class.java)
34-
dataManager.updateDatabaseVersion()
32+
commandsRepository = CommandsRepository(context)
33+
basicsRepository = BasicsRepository(context)
3534

3635
// Clear bookmarks
3736
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
@@ -71,18 +70,19 @@ class ComposeTests {
7170
composeTestRule.onNodeWithContentDescription("SearchField").performTextClearance()
7271

7372
// Search for an existing command
74-
val firstCommand = databaseHelper.getCommands().last()
73+
val firstCommand = commandsRepository.getCommands().last()
7574
composeTestRule.onNodeWithContentDescription("SearchField")
7675
.performTextInput(firstCommand.name)
77-
composeTestRule.onNodeWithText(firstCommand.description).assertIsDisplayed()
76+
// Verify the command appears in results
77+
composeTestRule.onNodeWithText(firstCommand.name).assertIsDisplayed()
7878
}
7979

8080
/**
8181
* Test if bookmarks in command detail and command list are shown correctly
8282
*/
8383
@Test
8484
fun testBookmarks() {
85-
val firstCommand = databaseHelper.getCommands().first()
85+
val firstCommand = commandsRepository.getCommands().first()
8686

8787
composeTestRule.onNodeWithText("Commands").performClick()
8888

@@ -91,7 +91,7 @@ class ComposeTests {
9191
// Search for first command and go to command detail screen
9292
composeTestRule.onNodeWithContentDescription("SearchField")
9393
.performTextInput(firstCommand.name)
94-
composeTestRule.onNodeWithText(firstCommand.description).performClick()
94+
composeTestRule.onNodeWithText(firstCommand.name).performClick()
9595

9696
// Click bookmark icon and check if icon/contentDescription changed
9797
composeTestRule.onNodeWithContentDescription("Add bookmark").performClick()
@@ -106,14 +106,15 @@ class ComposeTests {
106106

107107
@Test
108108
fun testBasicsScreen() {
109-
val firstBasicCategory = databaseHelper.getBasics().first()
109+
val firstBasicCategory = basicsRepository.getCategories().first()
110110

111111
// Click on first category
112112
composeTestRule.onNodeWithText(firstBasicCategory.title).performClick()
113113
composeTestRule.onNodeWithContentDescription("TopAppBarTitle")
114114
.assertTextEquals(firstBasicCategory.title)
115115

116-
val basicGroup = databaseHelper.getBasicGroupsByQuery(firstBasicCategory.id).first()
116+
val (groups, _) = basicsRepository.getGroupsAndCommands(firstBasicCategory.id)
117+
val basicGroup = groups.first()
117118

118119
// Click on first group
119120
composeTestRule.onNodeWithText(basicGroup.description).performClick()

android/src/main/AndroidManifest.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,5 @@
5656
android:scheme="https" />
5757
</intent-filter>
5858
</activity>
59-
<activity
60-
android:name=".InitializeDatabaseActivity"
61-
android:exported="true">
62-
<intent-filter android:autoVerify="true">
63-
<action android:name="android.intent.action.VIEW" />
64-
</intent-filter>
65-
</activity>
6659
</application>
6760
</manifest>

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/DataManager.kt

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,29 @@ class DataManager(context: Context) {
99

1010
val prefs: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
1111

12-
private val bookmarksIds = getBookmarkIds()
12+
private val bookmarkNames = getBookmarkNames()
1313

14-
private fun getBookmarkIds(): MutableList<Long> {
15-
val bookmarksChain = prefs.getString(KEY_BOOKMARKS, "") ?: ""
16-
return bookmarksChain.split(",").mapNotNull { it.trim().toLongOrNull() }.toMutableList()
14+
private fun getBookmarkNames(): MutableSet<String> {
15+
val bookmarksChain = prefs.getString(KEY_BOOKMARKS_V2, "") ?: ""
16+
return bookmarksChain.split(",").filter { it.isNotBlank() }.toMutableSet()
1717
}
1818

19-
private fun saveBookmarkIds() {
20-
val bookmarksChain = bookmarksIds.joinToString(separator = ",")
21-
prefs.edit { putString(KEY_BOOKMARKS, bookmarksChain) }
19+
private fun saveBookmarkNames() {
20+
val bookmarksChain = bookmarkNames.joinToString(separator = ",")
21+
prefs.edit { putString(KEY_BOOKMARKS_V2, bookmarksChain) }
2222
}
2323

24-
fun addBookmark(id: Long) {
25-
bookmarksIds.add(id)
26-
saveBookmarkIds()
24+
fun addBookmark(name: String) {
25+
bookmarkNames.add(name)
26+
saveBookmarkNames()
2727
}
2828

29-
fun removeBookmark(id: Long) {
30-
bookmarksIds.remove(id)
31-
saveBookmarkIds()
29+
fun removeBookmark(name: String) {
30+
bookmarkNames.remove(name)
31+
saveBookmarkNames()
3232
}
3333

34-
fun hasBookmark(id: Long): Boolean = bookmarksIds.contains(id)
35-
36-
fun isDatabaseUpToDate(): Boolean {
37-
val databaseVersion = prefs.getInt(KEY_DATABASE_VERSION, 0)
38-
return databaseVersion == CURRENT_DATABASE_VERSION
39-
}
40-
41-
fun updateDatabaseVersion() {
42-
prefs.edit { putInt(KEY_DATABASE_VERSION, CURRENT_DATABASE_VERSION) }
43-
}
34+
fun hasBookmark(name: String): Boolean = bookmarkNames.contains(name)
4435

4536
fun setAutoExpandSections(autoExpand: Boolean) {
4637
prefs.edit { putBoolean(KEY_AUTO_EXPAND_SECTIONS, autoExpand) }
@@ -49,9 +40,7 @@ class DataManager(context: Context) {
4940
fun isAutoExpandSections(): Boolean = prefs.getBoolean(KEY_AUTO_EXPAND_SECTIONS, false)
5041

5142
companion object {
52-
const val KEY_BOOKMARKS = "KEY_BOOKMARKS"
53-
const val KEY_DATABASE_VERSION = "DATABASE_VERSION"
43+
const val KEY_BOOKMARKS_V2 = "KEY_BOOKMARKS_V2"
5444
const val KEY_AUTO_EXPAND_SECTIONS = "auto_expand_sections"
55-
const val CURRENT_DATABASE_VERSION = 34
5645
}
5746
}
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
package com.inspiredandroid.linuxcommandbibliotheca
22

33
import androidx.navigation.NavBackStackEntry
4-
import com.linuxcommandlibrary.shared.databaseHelper
5-
import com.linuxcommandlibrary.shared.getHtmlFileName
64

7-
fun NavBackStackEntry.getCommandId(): Long? {
8-
var commandId =
9-
arguments?.getString("commandId")?.toLongOrNull()
10-
if (commandId == null) {
11-
// get id by command name when opened via deeplink
12-
val commandName = arguments?.getString("commandName") ?: ""
13-
val command = databaseHelper.getCommand(commandName)
14-
commandId = command?.id
15-
}
16-
return commandId
17-
}
18-
19-
fun NavBackStackEntry.getCategoryId(): Long? {
20-
var categoryId =
21-
arguments?.getString("categoryId")?.toLongOrNull()
22-
if (categoryId == null) {
23-
// get id by category name when opened via deeplink
24-
val categoryName =
25-
arguments?.getString("deepLinkCategoryName") ?: ""
26-
val categories = databaseHelper.getBasics()
27-
categoryId = categories.firstOrNull { it.getHtmlFileName() == categoryName }?.id
28-
}
29-
return categoryId
5+
fun NavBackStackEntry.getCategoryId(): String? {
6+
return arguments?.getString("categoryId")?.takeIf { it.isNotEmpty() }
7+
?: arguments?.getString("categoryName") // For deep links
308
}

0 commit comments

Comments
 (0)