Skip to content

Commit

Permalink
[optimize] Optimize the "Suggested Tags" feature below the search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Nov 11, 2023
1 parent e813ab5 commit 8a80eb1
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId "com.skyd.rays"
minSdk 24
targetSdk 34
versionCode 41
versionName "1.6-beta23"
versionCode 42
versionName "1.6-beta24"
flavorDimensions = ["versionName"]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.skyd.rays.model.bean.STICKER_TABLE_NAME
import com.skyd.rays.model.bean.StickerBean

class Migration1To2 : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE $STICKER_TABLE_NAME ADD ${StickerBean.MODIFY_TIME_COLUMN} INTEGER")
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE $STICKER_TABLE_NAME ADD ${StickerBean.MODIFY_TIME_COLUMN} INTEGER")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.skyd.rays.model.bean.STICKER_TABLE_NAME
import com.skyd.rays.model.bean.StickerBean

class Migration2To3 : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE $STICKER_TABLE_NAME ADD ${StickerBean.CLICK_COUNT_COLUMN} INTEGER NOT NULL DEFAULT 0")
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE $STICKER_TABLE_NAME ADD ${StickerBean.CLICK_COUNT_COLUMN} INTEGER NOT NULL DEFAULT 0")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.skyd.rays.model.bean.STICKER_TABLE_NAME
import com.skyd.rays.model.bean.StickerBean

class Migration3To4 : Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE $STICKER_TABLE_NAME ADD ${StickerBean.SHARE_COUNT_COLUMN} INTEGER NOT NULL DEFAULT 0")
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE $STICKER_TABLE_NAME ADD ${StickerBean.SHARE_COUNT_COLUMN} INTEGER NOT NULL DEFAULT 0")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.skyd.rays.model.bean.URI_STRING_SHARE_PACKAGE_TABLE_NAME
import com.skyd.rays.model.bean.UriStringSharePackageBean

class Migration4To5 : Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"""CREATE TABLE $URI_STRING_SHARE_PACKAGE_TABLE_NAME
(${UriStringSharePackageBean.PACKAGE_NAME_COLUMN} TEXT PRIMARY KEY NOT NULL,
${UriStringSharePackageBean.ENABLED_COLUMN} INTEGER NOT NULL)"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.skyd.rays.model.bean.API_GRANT_PACKAGE_TABLE_NAME
import com.skyd.rays.model.bean.ApiGrantPackageBean

class Migration5To6 : Migration(5, 6) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"""CREATE TABLE $API_GRANT_PACKAGE_TABLE_NAME
(${ApiGrantPackageBean.PACKAGE_NAME_COLUMN} TEXT PRIMARY KEY NOT NULL,
${ApiGrantPackageBean.ENABLED_COLUMN} INTEGER NOT NULL)"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,43 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkHorizontally
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material.icons.filled.Folder
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.RichTooltip
import androidx.compose.material3.SearchBar
import androidx.compose.material3.SuggestionChip
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TooltipBox
import androidx.compose.material3.TooltipDefaults
import androidx.compose.material3.VerticalDivider
import androidx.compose.material3.rememberTooltipState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -46,6 +57,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
Expand All @@ -59,6 +71,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.skyd.rays.R
import com.skyd.rays.config.refreshStickerData
import com.skyd.rays.ext.isCompact
import com.skyd.rays.ext.plus
import com.skyd.rays.model.bean.StickerWithTags
import com.skyd.rays.model.preference.CurrentStickerUuidPreference
import com.skyd.rays.model.preference.ExportStickerDirPreference
Expand Down Expand Up @@ -419,35 +432,93 @@ fun PopularTagsBar(
onTagClicked: (String) -> Unit,
tags: List<Pair<String, Float>>,
) {
Box {
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp),
val eachTag: @Composable (Pair<String, Float>) -> Unit = { item ->
TooltipBox(
positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
tooltip = {
RichTooltip(
title = { Text(item.first) },
text = {
Text(
text = stringResource(
R.string.home_screen_popular_tags_popular_value, item.second
)
)
}
)
},
state = rememberTooltipState(),
) {
itemsIndexed(tags) { _, item ->
TooltipBox(
positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
tooltip = {
RichTooltip(
title = { Text(item.first) },
text = {
Text(
text = stringResource(
R.string.home_screen_popular_tags_popular_value, item.second
)
)
Text(
modifier = Modifier
.clip(RoundedCornerShape(6.dp))
.clickable { onTagClicked(item.first) }
.padding(horizontal = 10.dp, vertical = 6.dp),
text = item.first
)
}
}

Box {
Row {
var expand by rememberSaveable { mutableStateOf(false) }
Box(
modifier = Modifier
.weight(1f)
.align(Alignment.CenterVertically)
) {
val lazyRowState = rememberLazyListState()
val flowRowState = rememberScrollState()
androidx.compose.animation.AnimatedVisibility(
visible = !expand,
enter = fadeIn(),
exit = fadeOut(),
) {
LazyRow(
state = lazyRowState,
contentPadding = PaddingValues(start = 16.dp) + PaddingValues(vertical = 6.dp),
verticalAlignment = Alignment.CenterVertically,
) {
itemsIndexed(tags) { index, item ->
eachTag(item)
if (index < tags.size - 1) {
VerticalDivider(modifier = Modifier.height(16.dp))
}
)
},
state = rememberTooltipState(),
}
}
}
androidx.compose.animation.AnimatedVisibility(
visible = expand,
enter = expandVertically(expandFrom = Alignment.Top) + fadeIn(),
exit = shrinkVertically(shrinkTowards = Alignment.Top) + fadeOut(),
) {
SuggestionChip(
onClick = { onTagClicked(item.first) },
label = { Text(text = item.first) }
)
FlowRow(
modifier = Modifier
.padding(start = 16.dp)
.heightIn(max = 200.dp)
.verticalScroll(flowRowState)
.padding(vertical = 6.dp),
) {
tags.forEachIndexed { index, item ->
eachTag(item)
if (index < tags.size - 1) {
VerticalDivider(
modifier = Modifier
.height(16.dp)
.align(Alignment.CenterVertically)
)
}
}
}
}
}

RaysIconButton(
imageVector = if (expand) Icons.Default.ExpandLess else Icons.Default.ExpandMore,
contentDescription = if (expand) stringResource(R.string.collapse)
else stringResource(R.string.expand),
onClick = { expand = !expand },
)
}

HorizontalDivider(
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/skyd/rays/ui/screen/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ fun MainScreen() {
}

@Composable
private fun NavigationBarOrRail(
navController: NavController
) {
private fun NavigationBarOrRail(navController: NavController) {
val items = listOf(
stringResource(R.string.home_screen_name) to HOME_SCREEN_ROUTE,
stringResource(R.string.mini_tool_screen_name) to MINI_TOOL_SCREEN_ROUTE,
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,6 @@
<string name="setting_screen_privacy_description">禁止截图等</string>
<string name="privacy_screen_disable_screenshot">禁止截图</string>
<string name="privacy_screen_disable_screenshot_description">禁止在应用内截图</string>
<string name="expand">展开</string>
<string name="collapse">收起</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,6 @@
<string name="setting_screen_privacy_description">Disable screenshot</string>
<string name="privacy_screen_disable_screenshot">Disable screenshot</string>
<string name="privacy_screen_disable_screenshot_description">Screenshot is prohibited in the app</string>
<string name="expand">Expand</string>
<string name="collapse">Collapse</string>
</resources>

0 comments on commit 8a80eb1

Please sign in to comment.