feat: language fragment to jetpack compose

- added orders to the test rule to avoid retries error in tests.
- renamed content lambda to "navigationIcon".
- removed redundant "Experimental api" from kiwixSearchView.
- added appropriate text size for kiwixSearchView.
This commit is contained in:
jaskaran 2025-03-25 15:55:47 +05:30 committed by MohitMaliFtechiz
parent 1fc4e505a2
commit 90830da5ca
5 changed files with 26 additions and 8 deletions

View File

@ -37,6 +37,8 @@ import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER
import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER
import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.RetryRule
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
@ -46,10 +48,11 @@ import org.kiwix.kiwixmobile.utils.StandardActions
@LargeTest @LargeTest
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class LanguageFragmentTest { class LanguageFragmentTest {
@get:Rule @Rule(order = RETRY_RULE_ORDER)
val retryTestRule = RetryRule() @JvmField
val retryRule = RetryRule()
@get:Rule @get:Rule(order = COMPOSE_TEST_RULE_ORDER)
val composeTestRule = createComposeRule() val composeTestRule = createComposeRule()
private val permissions = private val permissions =

View File

@ -91,7 +91,7 @@ class LanguageFragment : BaseFragment() {
searchText = it searchText = it
languageViewModel.actions.offer(Action.Filter(it)) languageViewModel.actions.offer(Action.Filter(it))
}, },
content = { navigationIcon = {
NavigationIcon( NavigationIcon(
iconItem = if (isSearchActive) { iconItem = if (isSearchActive) {
IconItem.Vector(Icons.AutoMirrored.Filled.ArrowBack) IconItem.Vector(Icons.AutoMirrored.Filled.ArrowBack)

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.language package org.kiwix.kiwixmobile.language
import android.annotation.SuppressLint
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateEndPadding
@ -46,6 +47,7 @@ import org.kiwix.kiwixmobile.language.viewmodel.LanguageViewModel
import org.kiwix.kiwixmobile.language.viewmodel.State import org.kiwix.kiwixmobile.language.viewmodel.State
import org.kiwix.kiwixmobile.language.viewmodel.State.Content import org.kiwix.kiwixmobile.language.viewmodel.State.Content
@SuppressLint("ComposableLambdaParameterNaming")
@Composable @Composable
fun LanguageScreen( fun LanguageScreen(
searchText: String, searchText: String,
@ -54,7 +56,7 @@ fun LanguageScreen(
actionMenuItemList: List<ActionMenuItem>, actionMenuItemList: List<ActionMenuItem>,
onClearClick: () -> Unit, onClearClick: () -> Unit,
onAppBarValueChange: (String) -> Unit, onAppBarValueChange: (String) -> Unit,
content: @Composable() () -> Unit, navigationIcon: @Composable() () -> Unit = {}
) { ) {
val state by languageViewModel.state.observeAsState(State.Loading) val state by languageViewModel.state.observeAsState(State.Loading)
val listState: LazyListState = rememberLazyListState() val listState: LazyListState = rememberLazyListState()
@ -63,7 +65,7 @@ fun LanguageScreen(
Scaffold(topBar = { Scaffold(topBar = {
KiwixAppBar( KiwixAppBar(
titleId = R.string.select_languages, titleId = R.string.select_languages,
navigationIcon = content, navigationIcon = navigationIcon,
actionMenuItems = actionMenuItemList, actionMenuItems = actionMenuItemList,
searchBar = if (isSearchActive) { searchBar = if (isSearchActive) {
{ modifier -> { modifier ->

View File

@ -18,9 +18,9 @@
package org.kiwix.kiwixmobile.core.ui.components package org.kiwix.kiwixmobile.core.ui.components
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -31,9 +31,11 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.utils.ComposeDimens
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun KiwixSearchView( fun KiwixSearchView(
modifier: Modifier, modifier: Modifier,
@ -59,7 +61,17 @@ fun KiwixSearchView(
.focusRequester(focusRequester), .focusRequester(focusRequester),
singleLine = true, singleLine = true,
value = value, value = value,
placeholder = {
Text(
text = stringResource(R.string.search_label),
color = Color.LightGray,
fontSize = ComposeDimens.EIGHTEEN_SP
)
},
colors = colors, colors = colors,
textStyle = TextStyle.Default.copy(
fontSize = ComposeDimens.EIGHTEEN_SP
),
onValueChange = { onValueChange = {
onValueChange(it.replace("\n", "")) onValueChange(it.replace("\n", ""))
}, },

View File

@ -56,6 +56,7 @@ object ComposeDimens {
// Font Sizes // Font Sizes
val TWENTY_FOUR_SP = 24.sp val TWENTY_FOUR_SP = 24.sp
val FOURTEEN_SP = 14.sp val FOURTEEN_SP = 14.sp
val EIGHTEEN_SP = 18.sp
// Default letter spacing in text according to theme // Default letter spacing in text according to theme
val DEFAULT_LETTER_SPACING = 0.0333.em val DEFAULT_LETTER_SPACING = 0.0333.em