Skip to content

Commit

Permalink
新增历史记录
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa1115910 committed Jan 21, 2025
1 parent df636b8 commit 004f593
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@
android:exported="false"
android:label="@string/title_mobile_activity_following_user"
android:theme="@style/Theme.BVMobile" />
<activity
android:name=".mobile.activities.HistoryActivity"
android:exported="false"
android:label="@string/title_mobile_activity_history"
android:theme="@style/Theme.BVMobile" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.aaa1115910.bv.mobile.activities

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import dev.aaa1115910.bv.mobile.screen.HistoryScreen
import dev.aaa1115910.bv.mobile.theme.BVMobileTheme

class HistoryActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val windowSize = calculateWindowSizeClass(this)
BVMobileTheme {
HistoryScreen(
windowSize = windowSize
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package dev.aaa1115910.bv.mobile.screen

import android.app.Activity
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import dev.aaa1115910.bv.R
import dev.aaa1115910.bv.mobile.activities.VideoPlayerActivity
import dev.aaa1115910.bv.mobile.component.videocard.SmallVideoCard
import dev.aaa1115910.bv.util.OnBottomReached
import dev.aaa1115910.bv.util.fInfo
import dev.aaa1115910.bv.viewmodel.user.HistoryViewModel
import io.github.oshai.kotlinlogging.KotlinLogging
import org.koin.androidx.compose.koinViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HistoryScreen(
modifier: Modifier = Modifier,
windowSize: WindowSizeClass,
historyViewModel: HistoryViewModel = koinViewModel()
) {
val context = LocalContext.current
val logger = KotlinLogging.logger("HistoryScreen")
val listState = rememberLazyGridState()
val scrollBehavior =
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())

listState.OnBottomReached(
loading = historyViewModel.updating
) {
logger.fInfo { "on reached rcmd page bottom" }
historyViewModel.update()
}

Scaffold(
modifier = modifier
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
LargeTopAppBar(
title = { Text(text = stringResource(R.string.title_mobile_activity_history)) },
navigationIcon = {
IconButton(
onClick = { (context as Activity).finish() }
) {
Icon(
imageVector = Icons.AutoMirrored.Default.ArrowBack,
contentDescription = null
)
}
},
scrollBehavior = scrollBehavior
)
}
) { innerPadding ->
LazyVerticalGrid(
modifier = Modifier.padding(top = innerPadding.calculateTopPadding()),
columns = GridCells.Adaptive(if (windowSize.widthSizeClass == WindowWidthSizeClass.Compact) 180.dp else 220.dp),
state = listState,
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(8.dp)
) {
items(historyViewModel.histories) { history ->
SmallVideoCard(
data = history,
onClick = {
VideoPlayerActivity.actionStart(
context = context,
aid = history.avid
)
}
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import com.origeek.imageViewer.previewer.rememberPreviewerState
import dev.aaa1115910.biliapi.entity.Picture
import dev.aaa1115910.bv.component.DevelopingTipContent
import dev.aaa1115910.bv.mobile.activities.FollowingUserActivity
import dev.aaa1115910.bv.mobile.activities.HistoryActivity
import dev.aaa1115910.bv.mobile.activities.LoginActivity
import dev.aaa1115910.bv.mobile.activities.SettingsActivity
import dev.aaa1115910.bv.mobile.component.home.UserDialog
Expand Down Expand Up @@ -304,7 +305,11 @@ fun MobileMainScreen(
Intent(context, FollowingUserActivity::class.java)
)
},
onOpenHistory = {},
onOpenHistory = {
context.startActivity(
Intent(context, HistoryActivity::class.java)
)
},
onOpenFavorite = {},
onOpenFollowingPgc = {},
onOpenToView = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HistoryViewModel(
var noMore by mutableStateOf(false)

private var cursor = 0L
private var updating = false
var updating by mutableStateOf(false)

fun update() {
viewModelScope.launch(Dispatchers.IO) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
<string name="title_activity_video_player_v3">视频播放</string>
<string name="title_mobile_activity_dynamic_detail">动态详情</string>
<string name="title_mobile_activity_following_user">我的关注</string>
<string name="title_mobile_activity_history">历史记录</string>
<string name="title_mobile_activity_login">用户登录</string>
<string name="title_mobile_activity_settings">设置</string>
<string name="title_mobile_activity_user_space">用户空间</string>
Expand Down

0 comments on commit 004f593

Please sign in to comment.