forked from LawnchairLauncher/lawnicons
-
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.
Merge branch 'LawnchairLauncher:develop' into test-2
- Loading branch information
Showing
9 changed files
with
482 additions
and
129 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
110 changes: 110 additions & 0 deletions
110
app/src/main/kotlin/app/lawnchair/lawnicons/ui/components/home/HomeBottomBar.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,110 @@ | ||
package app.lawnchair.lawnicons.ui.components.home | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.compose.foundation.layout.requiredSize | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.Search | ||
import androidx.compose.material3.BottomAppBar | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.FloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.PlainTooltip | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TooltipBox | ||
import androidx.compose.material3.TooltipDefaults | ||
import androidx.compose.material3.rememberTooltipState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import app.lawnchair.lawnicons.R | ||
import app.lawnchair.lawnicons.model.IconRequestModel | ||
import app.lawnchair.lawnicons.ui.util.Constants | ||
|
||
@Composable | ||
fun HomeBottomBar( | ||
context: Context, | ||
iconRequestModel: IconRequestModel?, | ||
snackbarHostState: SnackbarHostState, | ||
onNavigate: () -> Unit, | ||
onExpandSearch: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
BottomAppBar( | ||
actions = { | ||
SimpleTooltipBox( | ||
label = stringResource(id = R.string.github), | ||
) { | ||
IconButton( | ||
onClick = { | ||
val webpage = Uri.parse(Constants.GITHUB) | ||
val intent = Intent(Intent.ACTION_VIEW, webpage) | ||
if (intent.resolveActivity(context.packageManager) != null) { | ||
context.startActivity(intent) | ||
} | ||
}, | ||
) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.github_foreground), | ||
contentDescription = stringResource(id = R.string.github), | ||
modifier = Modifier.requiredSize(24.dp), | ||
) | ||
} | ||
} | ||
IconRequestIconButton( | ||
iconRequestModel = iconRequestModel, | ||
snackbarHostState = snackbarHostState, | ||
) | ||
SimpleTooltipBox( | ||
label = stringResource(id = R.string.about), | ||
) { | ||
IconButton(onClick = onNavigate) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.contacts_foreground), | ||
contentDescription = stringResource(id = R.string.about), | ||
modifier = Modifier.requiredSize(24.dp), | ||
) | ||
} | ||
} | ||
}, | ||
floatingActionButton = { | ||
SimpleTooltipBox( | ||
label = stringResource(id = R.string.search), | ||
) { | ||
FloatingActionButton(onClick = onExpandSearch) { | ||
Icon( | ||
imageVector = Icons.Rounded.Search, | ||
contentDescription = stringResource(id = R.string.search), | ||
) | ||
} | ||
} | ||
}, | ||
modifier = modifier, | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun SimpleTooltipBox( | ||
label: String, | ||
modifier: Modifier = Modifier, | ||
content: @Composable (() -> Unit), | ||
) { | ||
TooltipBox( | ||
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), | ||
tooltip = { | ||
PlainTooltip { | ||
Text(label) | ||
} | ||
}, | ||
state = rememberTooltipState(), | ||
modifier = modifier, | ||
) { | ||
content() | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
app/src/main/kotlin/app/lawnchair/lawnicons/ui/components/home/HomeTopBar.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,143 @@ | ||
package app.lawnchair.lawnicons.ui.components.home | ||
|
||
import androidx.compose.animation.AnimatedContent | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.CenterAlignedTopAppBar | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBarScrollBehavior | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.focus.focusRequester | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import app.lawnchair.lawnicons.R | ||
import app.lawnchair.lawnicons.model.IconInfo | ||
import app.lawnchair.lawnicons.model.IconInfoModel | ||
import app.lawnchair.lawnicons.model.SearchMode | ||
import app.lawnchair.lawnicons.ui.components.home.search.LawniconsSearchBar | ||
import app.lawnchair.lawnicons.ui.components.home.search.SearchContents | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
fun HomeTopBar( | ||
isSearchExpanded: Boolean, | ||
onFocusChange: () -> Unit, | ||
isExpandedScreen: Boolean, | ||
onClearSearch: () -> Unit, | ||
onChangeMode: (SearchMode) -> Unit, | ||
onSearchIcons: (String) -> Unit, | ||
searchedIconInfoModel: IconInfoModel?, | ||
onNavigate: () -> Unit, | ||
isIconPicker: Boolean, | ||
searchTerm: String, | ||
searchMode: SearchMode, | ||
onSendResult: (IconInfo) -> Unit, | ||
focusRequester: FocusRequester, | ||
scrollBehavior: TopAppBarScrollBehavior, | ||
appIcon: ImageBitmap, | ||
modifier: Modifier = Modifier, | ||
) { | ||
AnimatedContent(targetState = isSearchExpanded || isExpandedScreen, label = "TopAppBar to SearchBar", modifier = modifier) { targetState -> | ||
if (targetState) { | ||
searchedIconInfoModel?.let { | ||
SearchBar( | ||
searchTerm = searchTerm, | ||
onClearSearch = onClearSearch, | ||
onChangeMode = onChangeMode, | ||
onSearchIcons = onSearchIcons, | ||
iconInfoModel = it, | ||
onNavigate = onNavigate, | ||
isExpandedScreen = isExpandedScreen, | ||
isIconPicker = isIconPicker, | ||
searchMode = searchMode, | ||
onSendResult = onSendResult, | ||
onFocusChange = onFocusChange, | ||
inputFieldModifier = Modifier.focusRequester(focusRequester), | ||
) | ||
} | ||
} else { | ||
CenterAlignedTopAppBar( | ||
scrollBehavior = scrollBehavior, | ||
title = { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Image( | ||
bitmap = appIcon, | ||
contentDescription = stringResource(id = R.string.app_name), | ||
modifier = Modifier.size(36.dp), | ||
) | ||
Spacer(modifier = Modifier.width(8.dp)) | ||
Text( | ||
stringResource(id = R.string.app_name), | ||
) | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SearchBar( | ||
onClearSearch: () -> Unit, | ||
onChangeMode: (SearchMode) -> Unit, | ||
onSearchIcons: (String) -> Unit, | ||
searchTerm: String, | ||
iconInfoModel: IconInfoModel, | ||
onNavigate: () -> Unit, | ||
isExpandedScreen: Boolean, | ||
isIconPicker: Boolean, | ||
searchMode: SearchMode, | ||
onSendResult: (IconInfo) -> Unit, | ||
onFocusChange: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
inputFieldModifier: Modifier = Modifier, | ||
) { | ||
Column( | ||
modifier = modifier.fillMaxWidth(), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
LawniconsSearchBar( | ||
query = searchTerm, | ||
isQueryEmpty = searchTerm == "", | ||
onClearAndBackClick = { | ||
onClearSearch() | ||
onFocusChange() | ||
}, | ||
onQueryChange = { newValue -> | ||
onSearchIcons(newValue) | ||
}, | ||
iconInfoModel = iconInfoModel, | ||
onNavigate = onNavigate, | ||
isExpandedScreen = isExpandedScreen, | ||
isIconPicker = isIconPicker, | ||
content = { | ||
SearchContents( | ||
searchTerm = searchTerm, | ||
searchMode = searchMode, | ||
onModeChange = { mode -> | ||
onChangeMode(mode) | ||
}, | ||
iconInfo = iconInfoModel.iconInfo, | ||
onSendResult = { | ||
onSendResult(it) | ||
}, | ||
) | ||
}, | ||
inputFieldModifier = inputFieldModifier, | ||
) | ||
} | ||
} |
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
Oops, something went wrong.