-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added composable for search bar to the android app (#12)
re #10
- Loading branch information
Showing
27 changed files
with
602 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/androidApp/src/main/java/io/github/tscholze/kennzeichner/android/MainApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.github.tscholze.kennzeichner.android | ||
|
||
import android.app.Application | ||
import io.github.tscholze.kennzeichner.android.di.appModule | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.android.ext.koin.androidLogger | ||
import org.koin.core.context.startKoin | ||
|
||
class MainApplication : Application(){ | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
// Setup koin | ||
startKoin{ | ||
androidContext(this@MainApplication) | ||
androidLogger() | ||
modules(appModule) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...src/main/java/io/github/tscholze/kennzeichner/android/composables/components/SearchBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.github.tscholze.kennzeichner.android.composables.components | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextField | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Close | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusDirection | ||
import androidx.compose.ui.platform.LocalFocusManager | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.input.ImeAction | ||
import io.github.tscholze.kennzeichner.android.R | ||
|
||
/** | ||
* Represents a search bar. | ||
* If the user types or clears the search bar text the state | ||
* property will be updated. | ||
* | ||
* @param state: Observable state of the search query. | ||
*/ | ||
@Composable | ||
fun SearchBar(state: MutableState<String>) { | ||
// MARK: - Properties - | ||
|
||
val focusManager = LocalFocusManager.current | ||
|
||
// MARK: - UI - | ||
|
||
TextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = state.value, | ||
onValueChange = { state.value = it }, | ||
singleLine = true, | ||
placeholder = { Text(stringResource(R.string.searchbar_text_placeholder)) | ||
}, | ||
leadingIcon = { | ||
Icon( | ||
Icons.Default.Search, | ||
contentDescription = "Search icon", | ||
) | ||
}, | ||
trailingIcon = { | ||
if (state.value.isNotEmpty()) { | ||
IconButton( | ||
onClick = { | ||
state.value = "" | ||
focusManager.moveFocus(FocusDirection.Next) | ||
} | ||
) { | ||
Icon( | ||
Icons.Default.Close, | ||
contentDescription = "Clear icon", | ||
) | ||
} | ||
} | ||
}, | ||
keyboardActions = KeyboardActions( | ||
onAny = { focusManager.clearFocus() } | ||
), | ||
keyboardOptions = KeyboardOptions( | ||
autoCorrect = false, | ||
imeAction = ImeAction.Search | ||
) | ||
) | ||
} |
Oops, something went wrong.