Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
feat: 历史记录新 UI
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Jan 8, 2023
1 parent 53df456 commit 0c75052
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import com.huanchengfly.tieba.post.arch.pageViewModel
import com.huanchengfly.tieba.post.dataStore
import com.huanchengfly.tieba.post.getInt
import com.huanchengfly.tieba.post.goToActivity
import com.huanchengfly.tieba.post.models.database.History
import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme
import com.huanchengfly.tieba.post.ui.page.ProvideNavigator
import com.huanchengfly.tieba.post.ui.page.forum.threadlist.ForumThreadListPage
Expand All @@ -102,6 +103,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.picker.ListSinglePicker
import com.huanchengfly.tieba.post.ui.widgets.compose.rememberDialogState
import com.huanchengfly.tieba.post.ui.widgets.compose.rememberMenuState
import com.huanchengfly.tieba.post.utils.AccountUtil.LocalAccount
import com.huanchengfly.tieba.post.utils.HistoryUtil
import com.huanchengfly.tieba.post.utils.StringUtil.getShortNumString
import com.huanchengfly.tieba.post.utils.TiebaUtil
import com.huanchengfly.tieba.post.utils.appPreferences
Expand Down Expand Up @@ -365,6 +367,20 @@ fun ForumPage(

val unlikeDialogState = rememberDialogState()

if (forum != null) {
LaunchedEffect(forum) {
HistoryUtil.writeHistory(
History()
.setTitle(context.getString(R.string.title_forum, forumName))
.setTimestamp(System.currentTimeMillis())
.setAvatar(forum.avatar)
.setType(HistoryUtil.TYPE_FORUM)
.setData(forumName),
true
)
}
}

if (account != null && forum != null) {
ConfirmDialog(
dialogState = unlikeDialogState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.huanchengfly.tieba.post.ui.page.history

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.width
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Tab
import androidx.compose.material.TabRow
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.rememberPagerState
import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme
import com.huanchengfly.tieba.post.ui.page.history.list.HistoryListPage
import com.huanchengfly.tieba.post.ui.widgets.compose.BackNavigationIcon
import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold
import com.huanchengfly.tieba.post.ui.widgets.compose.PagerTabIndicator
import com.huanchengfly.tieba.post.ui.widgets.compose.TitleCentredToolbar
import com.huanchengfly.tieba.post.utils.HistoryUtil
import com.ramcosta.composedestinations.annotation.DeepLink
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import kotlinx.coroutines.launch

@OptIn(ExperimentalPagerApi::class)
@Destination(
deepLinks = [
DeepLink(uriPattern = "tblite://history")
]
)
@Composable
fun HistoryPage(
navigator: DestinationsNavigator
) {
val pagerState = rememberPagerState()
val coroutineScope = rememberCoroutineScope()

MyScaffold(
topBar = {
TitleCentredToolbar(
title = stringResource(id = R.string.title_history),
navigationIcon = {
BackNavigationIcon(onBackPressed = { navigator.navigateUp() })
},
actions = {
IconButton(onClick = { /*TODO*/ }) {
Icon(
imageVector = Icons.Outlined.Delete,
contentDescription = stringResource(id = R.string.title_history_delete),
tint = ExtendedTheme.colors.onTopBar
)
}
}
) {
TabRow(
selectedTabIndex = pagerState.currentPage,
indicator = { tabPositions ->
PagerTabIndicator(
pagerState = pagerState,
tabPositions = tabPositions
)
},
divider = {},
backgroundColor = ExtendedTheme.colors.topBar,
contentColor = ExtendedTheme.colors.accent,
modifier = Modifier
.width(100.dp * 2)
.align(Alignment.CenterHorizontally)
) {
Tab(
text = {
Text(
text = stringResource(id = R.string.title_history_thread),
fontSize = 13.sp
)
},
selected = pagerState.currentPage == 0,
onClick = {
coroutineScope.launch {
pagerState.animateScrollToPage(0)
}
},
selectedContentColor = ExtendedTheme.colors.accent,
unselectedContentColor = ExtendedTheme.colors.onTopBarSecondary
)
Tab(
text = {
Text(
text = stringResource(id = R.string.title_history_forum),
fontSize = 13.sp
)
},
selected = pagerState.currentPage == 1,
onClick = {
coroutineScope.launch {
pagerState.animateScrollToPage(1)
}
},
selectedContentColor = ExtendedTheme.colors.accent,
unselectedContentColor = ExtendedTheme.colors.onTopBarSecondary
)
}
}
}
) {
HorizontalPager(
count = 2,
state = pagerState,
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.Top,
userScrollEnabled = true,
) {
if (it == 0) {
HistoryListPage(type = HistoryUtil.TYPE_THREAD)
} else {
HistoryListPage(type = HistoryUtil.TYPE_FORUM)
}
}
}
}
Loading

0 comments on commit 0c75052

Please sign in to comment.