Skip to content

Commit

Permalink
MomentsPage
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Apr 8, 2023
1 parent ab539f4 commit 70088e2
Show file tree
Hide file tree
Showing 13 changed files with 593 additions and 126 deletions.
41 changes: 41 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ dependencies {
debugImplementation 'androidx.compose.ui:ui-test-manifest'

implementation("androidx.compose.runtime:runtime-livedata:1.4.1")
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.30.0'
def nav_version = "2.5.3"
implementation "androidx.navigation:navigation-compose:$nav_version"


implementation 'com.google.zxing:core:3.5.1'
Expand All @@ -77,7 +80,7 @@ dependencies {

implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.google.code.gson:gson:$gson_version"
implementation("com.github.bumptech.glide:compose:1.0.0-alpha.1")
implementation("com.github.bumptech.glide:compose:1.0.0-alpha.3")

implementation(project(":bili-api"))

Expand Down
4 changes: 3 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
-keep public class extends com.bumptech.glide.module.AppGlideModule
-keep class com.bumptech.glide.GeneratedAppGlideModuleImpl
4 changes: 3 additions & 1 deletion app/src/main/java/com/storyteller_f/bi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.storyteller_f.bi

import android.app.Application
import com.a10miaomiao.bilimiao.comm.BilimiaoCommApp
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule

class App: Application() {

Expand All @@ -24,4 +26,4 @@ class App: Application() {
commApp.onCreate()
readUserInfo()
}
}
}
145 changes: 67 additions & 78 deletions app/src/main/java/com/storyteller_f/bi/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,40 @@ import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.Button
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType
import com.google.zxing.qrcode.QRCodeWriter
import com.storyteller_f.bi.components.HistoryPage
import com.storyteller_f.bi.components.HomeTopBar
import com.storyteller_f.bi.components.MomentsPage
import com.storyteller_f.bi.components.Screen
import com.storyteller_f.bi.components.UserCenterDrawer
import com.storyteller_f.bi.ui.theme.BiTheme
import kotlinx.coroutines.launch
import java.util.Collections
Expand All @@ -52,43 +51,74 @@ class MainActivity : ComponentActivity() {
setContent {
val drawerState = rememberDrawerState(DrawerValue.Closed)
val coroutineScope = rememberCoroutineScope()
val navController = rememberNavController()

val open = {
coroutineScope.launch {
drawerState.open()
}
}
val user by userInfo.observeAsState()
val u = user
val items = listOf(
Screen.History,
Screen.Moments,
)
BiTheme {
ModalNavigationDrawer(drawerContent = {
if (u != null) {
Text(text = u.name)
} else Button(onClick = {

}) {
Text(text = "login")
}
}, drawerState = drawerState) {
ModalNavigationDrawer(
drawerContent = {
UserCenterDrawer(userInfo = u)
},
drawerState = drawerState
) {
Scaffold(topBar = {
TopAppBar(
title = {
Text(text = "Bi")
},
navigationIcon = {
IconButton(onClick = {
open()
}) {
HomeTopBar {
open()
}
}, bottomBar = {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
NavigationBar {
items.forEach { screen ->
val selected =
currentDestination?.hierarchy?.any { it.route == screen.route } == true
NavigationBarItem(selected = selected, onClick = {
navController.navigate(screen.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
}, {
Icon(Icons.Filled.Menu, contentDescription = null)
}
},
)
}, label = {
Text(text = stringResource(id = screen.resourceId))
})
}
}
}) {
Surface(
modifier = Modifier.fillMaxSize().padding(it),
modifier = Modifier
.fillMaxSize()
.padding(it),
color = MaterialTheme.colorScheme.background
) {
// LoginPage(url, loadingState, checkState)
HistoryPage()
NavHost(navController = navController, startDestination = Screen.History.route) {
composable(Screen.History.route) {
HistoryPage()
}
composable(Screen.Moments.route) {
MomentsPage()
}
}

}
}

Expand All @@ -99,39 +129,6 @@ class MainActivity : ComponentActivity() {
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
val image by remember {
derivedStateOf {
"hello".createQRImage(200, 200)
}
}
val widthDp = LocalConfiguration.current.smallestScreenWidthDp - 100

Column {
Text(
text = "Hello $name!",
modifier = modifier
)
Button(onClick = { /*TODO*/ }) {
Text(text = "request")
}
Button(onClick = { /*TODO*/ }) {
Text(text = "get")
}
Image(
bitmap = image.asImageBitmap(),
contentDescription = "test",
modifier = Modifier
.width(
widthDp.dp
)
.height(widthDp.dp)
)
}

}

fun String.createQRImage(width: Int, height: Int): Bitmap {
val bitMatrix = QRCodeWriter().encode(
this,
Expand All @@ -149,12 +146,4 @@ fun String.createQRImage(width: Int, height: Int): Bitmap {
}.toArray(),
width, height, Bitmap.Config.ARGB_8888
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
BiTheme {
Greeting("Android")
}
}
44 changes: 33 additions & 11 deletions app/src/main/java/com/storyteller_f/bi/components/History.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ import com.bumptech.glide.integration.compose.GlideImage
import com.storyteller_f.bi.LoadingState
import kotlinx.coroutines.launch

fun MutableLiveData<LoadingState>.loaded() {
value = LoadingState.Done
}

fun MutableLiveData<LoadingState>.error(e: Exception) {
value = LoadingState.Error(e)
}

fun MutableLiveData<LoadingState>.loading(message: String = "") {
value = LoadingState.Loading(message)
}

class HistoryViewModel : ViewModel() {
var list = PaginationInfo<HistoryOuterClass.CursorItem>()
val state = MutableLiveData<LoadingState>()
Expand All @@ -37,7 +49,7 @@ class HistoryViewModel : ViewModel() {

fun load() {
viewModelScope.launch {
state.value = LoadingState.Loading("")
state.loading()
try {
val req = HistoryOuterClass.CursorV2Req.newBuilder().apply {
business = "archive"
Expand All @@ -49,9 +61,9 @@ class HistoryViewModel : ViewModel() {
.request(req)
.awaitCall()
list.data.addAll(res.itemsList)
state.value = LoadingState.Done
state.loaded()
} catch (e: Exception) {
state.value = LoadingState.Error(e)
state.error(e)
}

}
Expand All @@ -70,7 +82,7 @@ fun HistoryPage() {
is LoadingState.Done -> LazyColumn {
items(list.data.size) {
val cursorItem = list.data[it]
HistoryItem(cursorItem, editMode = false)
HistoryItem(cursorItem)
}
}

Expand All @@ -87,28 +99,38 @@ class VideoItemProvider : PreviewParameterProvider<HistoryOuterClass.CursorItem>

}

@Preview
@OptIn(ExperimentalGlideComposeApi::class)
@Composable
fun HistoryItem(
@PreviewParameter(VideoItemProvider::class) item: HistoryOuterClass.CursorItem,
editMode: Boolean = true
) {
val text = item.title
val text1 = item.dt.type.name
VideoItem(item.cover(), text, text1)
}

@Preview
@Composable
@OptIn(ExperimentalGlideComposeApi::class)
fun VideoItem(
url: String? = null,
text: String = "text",
label: String = "label"
) {

Row(modifier = Modifier.padding(8.dp)) {
val coverModifier = Modifier
.width(80.dp)
.height(45.dp)
if (editMode) {
if (url == null) {
Box(coverModifier.background(Color.Blue))
} else {
val url = UrlUtil.autoHttps(item.cover())
val u = "$url@672w_378h_1c_"
val u = "${UrlUtil.autoHttps(url)}@672w_378h_1c_"
GlideImage(u, contentDescription = null, modifier = coverModifier)
}
Column(modifier = Modifier.padding(start = 8.dp)) {
Text(text = item.title)
Text(text = item.dt.type.name)
Text(text = text)
Text(text = label)
}
}
}
Expand Down
Loading

0 comments on commit 70088e2

Please sign in to comment.