Skip to content

Commit

Permalink
refactor: organize string resources (#109)
Browse files Browse the repository at this point in the history
Replace strings with string resources in active session, goals, library, metronome, permissions, recorder, sessions, settings and statistics feature.

Add a new htmlResource composable for displaying html annotated strings in compose.

Fix some of minor bugs around the refactoring.

Remove legacy strings.
  • Loading branch information
matthiasemde authored Sep 7, 2024
1 parent fbfad42 commit 3085e42
Show file tree
Hide file tree
Showing 94 changed files with 1,881 additions and 1,204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2023 Matthias Emde
* Copyright (c) 2023-2024 Matthias Emde
*/

package app.musikus.library.presentation
Expand Down Expand Up @@ -33,9 +33,7 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.test.core.app.ApplicationProvider
import app.musikus.R
import app.musikus.core.domain.LibraryFolderSortMode
import app.musikus.core.domain.LibraryItemSortMode
import app.musikus.core.domain.SortMode
import app.musikus.core.domain.FakeTimeProvider
import app.musikus.core.presentation.HomeViewModel
import app.musikus.core.presentation.MainActivity
import app.musikus.core.presentation.MainViewModel
Expand All @@ -44,7 +42,6 @@ import app.musikus.core.presentation.theme.MusikusTheme
import app.musikus.core.presentation.utils.TestTags
import app.musikus.settings.domain.ColorSchemeSelections
import app.musikus.settings.domain.ThemeSelections
import app.musikus.core.domain.FakeTimeProvider
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
Expand Down Expand Up @@ -97,69 +94,69 @@ class LibraryScreenTest {

@Test
fun clickFab_multiFabMenuIsShown() {
composeRule.onNodeWithContentDescription("Folder").assertDoesNotExist()
composeRule.onNodeWithContentDescription("Item").assertDoesNotExist()
composeRule.onNodeWithContentDescription("Add folder").assertDoesNotExist()
composeRule.onNodeWithContentDescription("Add item").assertDoesNotExist()

composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()

composeRule.onNodeWithContentDescription("Folder").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Item").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Add folder").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Add item").assertIsDisplayed()
}

@Test
fun addFolderOrItem_hintDisappears() {
val context = ApplicationProvider.getApplicationContext<Context>()

// Check if hint is displayed initially
composeRule.onNodeWithText(context.getString(R.string.libraryHint)).assertIsDisplayed()
composeRule.onNodeWithText(context.getString(R.string.library_screen_hint)).assertIsDisplayed()

// Add a folder
composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Folder").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()
composeRule.onNodeWithContentDescription("Add folder").performClick()
composeRule.onNodeWithTag(TestTags.FOLDER_DIALOG_NAME_INPUT).performTextInput("Test")
composeRule.onNodeWithContentDescription("Create").performClick()

// Check if hint is not displayed anymore
composeRule.onNodeWithText(context.getString(R.string.libraryHint)).assertDoesNotExist()
composeRule.onNodeWithText(context.getString(R.string.library_screen_hint)).assertDoesNotExist()

// Remove the folder
composeRule.onNodeWithText("Test").performTouchInput { longClick() }
composeRule.onNodeWithContentDescription("Delete").performClick()
composeRule.onNodeWithContentDescription("Delete forever (1)").performClick()

// Check if hint is displayed again
composeRule.onNodeWithText(context.getString(R.string.libraryHint)).assertIsDisplayed()
composeRule.onNodeWithText(context.getString(R.string.library_screen_hint)).assertIsDisplayed()

// Add an item
composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Item").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()
composeRule.onNodeWithContentDescription("Add item").performClick()
composeRule.onNodeWithTag(TestTags.ITEM_DIALOG_NAME_INPUT).performTextInput("Test")
composeRule.onNodeWithContentDescription("Create").performClick()

// Check if hint is not displayed anymore
composeRule.onNodeWithText(context.getString(R.string.libraryHint)).assertDoesNotExist()
composeRule.onNodeWithText(context.getString(R.string.library_screen_hint)).assertDoesNotExist()

// Remove the item
composeRule.onNodeWithText("Test").performTouchInput { longClick() }
composeRule.onNodeWithContentDescription("Delete").performClick()
composeRule.onNodeWithContentDescription("Delete forever (1)").performClick()

// Check if hint is displayed again
composeRule.onNodeWithText(context.getString(R.string.libraryHint)).assertIsDisplayed()
composeRule.onNodeWithText(context.getString(R.string.library_screen_hint)).assertIsDisplayed()
}

@Test
fun addItemToFolderFromInsideAndOutside() {

// Add a folder
composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Folder").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()
composeRule.onNodeWithContentDescription("Add folder").performClick()
composeRule.onNodeWithTag(TestTags.FOLDER_DIALOG_NAME_INPUT).performTextInput("TestFolder")
composeRule.onNodeWithContentDescription("Create").performClick()

// Add an item from outside the folder
composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Item").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()
composeRule.onNodeWithContentDescription("Add item").performClick()
composeRule.onNodeWithTag(TestTags.ITEM_DIALOG_NAME_INPUT).performTextInput("TestItem1")
composeRule.onNodeWithContentDescription("Select folder").performClick()

Expand All @@ -185,18 +182,16 @@ class LibraryScreenTest {
composeRule.onNodeWithText("TestItem2").assertIsDisplayed()
}

private fun clickSortMode(sortMode: SortMode<*>) {
val sortModeType = when(sortMode) {
is LibraryItemSortMode -> "items"
is LibraryFolderSortMode -> "folders"
else -> throw Exception("Unknown sort mode type")
}
private fun clickSortMode(
sortModeType: String,
sortMode: String
) {
composeRule.onNodeWithContentDescription("Select sort mode and direction for $sortModeType").performClick()
// Select name as sorting mode
composeRule.onNode(
matcher = hasAnyAncestor(hasContentDescription("List of sort modes for $sortModeType"))
and
hasText(sortMode.label)
hasText(sortMode)
).performClick()
}

Expand All @@ -210,8 +205,8 @@ class LibraryScreenTest {
)

namesAndColors.forEach { (name, color) ->
composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Item").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()
composeRule.onNodeWithContentDescription("Add item").performClick()
composeRule.onNodeWithTag(TestTags.ITEM_DIALOG_NAME_INPUT).performTextInput(name)
composeRule.onNodeWithContentDescription("Color $color").performClick()
composeRule.onNodeWithContentDescription("Create").performClick()
Expand All @@ -229,7 +224,7 @@ class LibraryScreenTest {
}

// Change sorting mode to name descending
clickSortMode(LibraryItemSortMode.NAME)
clickSortMode("items", "Name")

// Check if items are displayed in correct order
itemNodes = composeRule.onAllNodes(hasText("TestItem", substring = true))
Expand All @@ -241,7 +236,7 @@ class LibraryScreenTest {
}

// Change sorting mode to name ascending
clickSortMode(LibraryItemSortMode.NAME)
clickSortMode("items", "Name")

// Check if items are displayed in correct order
itemNodes = composeRule.onAllNodes(hasText("TestItem", substring = true))
Expand All @@ -262,8 +257,8 @@ class LibraryScreenTest {
)

names.forEach { name ->
composeRule.onNodeWithContentDescription("Add").performClick()
composeRule.onNodeWithContentDescription("Folder").performClick()
composeRule.onNodeWithContentDescription("Add folder or item").performClick()
composeRule.onNodeWithContentDescription("Add folder").performClick()
composeRule.onNodeWithTag(TestTags.FOLDER_DIALOG_NAME_INPUT).performTextInput(name)
composeRule.onNodeWithContentDescription("Create").performClick()

Expand All @@ -280,7 +275,7 @@ class LibraryScreenTest {
}

// Change sorting mode to name descending
clickSortMode(LibraryFolderSortMode.NAME)
clickSortMode("folders", "Name")

// Check if items are displayed in correct order
itemNodes = composeRule.onAllNodes(hasText("TestFolder", substring = true))
Expand All @@ -292,7 +287,7 @@ class LibraryScreenTest {
}

// Change sorting mode to name ascending
clickSortMode(LibraryFolderSortMode.NAME)
clickSortMode("folders", "Name")

// Check if items are displayed in correct order
itemNodes = composeRule.onAllNodes(hasText("TestFolder", substring = true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2023 Matthias Emde
* Copyright (c) 2023-2024 Matthias Emde
*/

package app.musikus.repository

import app.musikus.core.domain.GoalSortInfo
import app.musikus.core.domain.GoalsSortMode
import app.musikus.core.domain.LibraryFolderSortMode
import app.musikus.core.domain.LibraryItemSortMode
import app.musikus.core.domain.SortDirection
import app.musikus.core.domain.SortInfo
import app.musikus.goals.data.GoalSortInfo
import app.musikus.goals.data.GoalsSortMode
import app.musikus.library.data.LibraryFolderSortMode
import app.musikus.library.data.LibraryItemSortMode
import app.musikus.library.data.daos.LibraryFolder
import app.musikus.library.data.daos.LibraryItem
import app.musikus.metronome.presentation.MetronomeSettings
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
android:name="app.musikus.core.presentation.Musikus"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="@string/core_app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Musikus"
Expand Down
Loading

0 comments on commit 3085e42

Please sign in to comment.