Skip to content

Commit

Permalink
feat: main page hint.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Dec 1, 2023
1 parent 1151c40 commit 80e1e24
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
58 changes: 49 additions & 9 deletions features/main/src/main/java/com/m3u/features/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,39 @@ package com.m3u.features.main
import android.content.res.Configuration
import android.view.KeyEvent
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.TipsAndUpdates
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.m3u.core.util.basic.title
import com.m3u.data.database.entity.Feed
import com.m3u.features.main.components.FeedGallery
import com.m3u.features.main.components.MainDialog
import com.m3u.features.main.components.OnRename
import com.m3u.features.main.components.OnUnsubscribe
import com.m3u.features.main.model.FeedDetailHolder
import com.m3u.i18n.R
import com.m3u.material.components.Background
import com.m3u.material.ktx.interceptVolumeEvent
import com.m3u.material.model.LocalSpacing
import com.m3u.ui.EventHandler
import com.m3u.ui.LocalHelper
import com.m3u.ui.MessageEventHandler
Expand Down Expand Up @@ -91,21 +105,29 @@ private fun MainScreen(
var dialog: MainDialog by remember { mutableStateOf(MainDialog.Idle) }
val configuration = LocalConfiguration.current

val details = feedDetailHolder.details

val actualRowCount = remember(rowCount, configuration.orientation) {
when (configuration.orientation) {
Configuration.ORIENTATION_PORTRAIT -> rowCount
else -> rowCount + 2
}
}
Background {
FeedGallery(
rowCount = actualRowCount,
feedDetailHolder = feedDetailHolder,
navigateToFeed = navigateToFeed,
onMenu = { dialog = MainDialog.Selections(it) },
contentPadding = contentPadding,
modifier = modifier
)
Background(modifier) {
if (details.isNotEmpty()) {
FeedGallery(
rowCount = actualRowCount,
feedDetailHolder = feedDetailHolder,
navigateToFeed = navigateToFeed,
onMenu = { dialog = MainDialog.Selections(it) },
contentPadding = contentPadding,
modifier = Modifier.fillMaxSize()
)
} else {
FeedGalleryPlaceholder(
modifier = Modifier.fillMaxSize()
)
}
MainDialog(
status = dialog,
update = { dialog = it },
Expand All @@ -118,3 +140,21 @@ private fun MainScreen(
dialog = MainDialog.Idle
}
}

@Composable
private fun FeedGalleryPlaceholder(modifier: Modifier = Modifier) {
val spacing = LocalSpacing.current
Row(
modifier.semantics(mergeDescendants = true) { },
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Icon(
imageVector = Icons.Rounded.TipsAndUpdates,
contentDescription = null
)
Spacer(modifier = Modifier.size(spacing.medium))
val text = stringResource(R.string.feat_feed_prompt_add_playlist).title()
Text(remember(text) { text })
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.m3u.features.main.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
Expand Down Expand Up @@ -59,22 +56,11 @@ internal fun FeedGallery(
}
}

@Composable
private fun FeedGalleryPlaceholder(modifier: Modifier = Modifier) {
Box(modifier, contentAlignment = Alignment.Center) {
Text(
text = stringResource(string.feat_feed_prompt_add_playlist)
)
}
}

@Composable
private fun Feed.calculateUiTitle(): AnnotatedString {
val actual = title.ifEmpty {
if (local) stringResource(string.feat_main_imported_feed_title)
else ""
}
return AnnotatedString(
text = actual.uppercase()
)
return AnnotatedString(actual.uppercase())
}
1 change: 1 addition & 0 deletions i18n/src/main/res/values-zh-rCN/feat_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<string name="feat_feed_error_live_cover_not_found">封面不存在</string>
<string name="feat_feed_error_live_not_found">频道不存在</string>
<string name="feat_feed_success_save_cover">保存到了(%s)</string>
<string name="feat_feed_prompt_add_playlist">到“设置-订阅管理”中添加你的第一个播放列表</string>
</resources>
2 changes: 1 addition & 1 deletion i18n/src/main/res/values-zh-rCN/feat_setting.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="feat_setting_not_implementation">此功能当前版本不可用</string>
<string name="feat_setting_placeholder_url">订阅链接</string>
<string name="feat_setting_app_version">应用版本</string>
<string name="feat_setting_label_subscribe">订阅</string>
Expand Down Expand Up @@ -58,4 +57,5 @@
<string name="feat_setting_error_blank_url">目标地址为空</string>
<string name="feat_setting_use_dynamic_colors">动态配色</string>
<string name="feat_setting_use_dynamic_colors_unavailable">仅在 Android 12 及更高版本可用</string>
<string name="feat_setting_not_implementation">此功能当前版本不可用</string>
</resources>
1 change: 1 addition & 0 deletions i18n/src/main/res/values/feat_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
<string name="feat_feed_error_live_cover_not_found">cover is not existed</string>
<string name="feat_feed_error_live_not_found">live is not existed</string>
<string name="feat_feed_success_save_cover">saved to (%s)</string>
<string name="feat_feed_prompt_add_playlist">go \"Settings - Playlist Management\" to add your first playlist</string>
</resources>
2 changes: 1 addition & 1 deletion i18n/src/main/res/values/feat_setting.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="feat_setting_not_implementation">this feature is not available for current version</string>
<string name="feat_setting_placeholder_url">playlist link</string>
<string name="feat_setting_app_version">app version</string>
<string name="feat_setting_label_subscribe">subscribe</string>
Expand Down Expand Up @@ -54,4 +53,5 @@
<string name="feat_setting_error_blank_url">blank url</string>
<string name="feat_setting_use_dynamic_colors">dynamic colors</string>
<string name="feat_setting_use_dynamic_colors_unavailable">it is available on Android 12 and above</string>
<string name="feat_setting_not_implementation">this feature is not available for current version</string>
</resources>

0 comments on commit 80e1e24

Please sign in to comment.