Add swipe refresh to inbox page
This commit is contained in:
parent
a0a8a27626
commit
0a6252c051
|
@ -61,7 +61,8 @@ dependencies {
|
|||
implementation 'androidx.activity:activity-compose:1.6.1'
|
||||
implementation "androidx.compose.ui:ui:$compose_version"
|
||||
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
|
||||
implementation 'androidx.compose.material3:material3:1.1.0-alpha01'
|
||||
implementation 'androidx.compose.material3:material3:1.1.0-alpha02'
|
||||
implementation 'androidx.compose.material:material:1.4.0-alpha01'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
|
@ -91,4 +92,7 @@ dependencies {
|
|||
implementation "io.insert-koin:koin-androidx-workmanager:$koin_android_version"
|
||||
implementation "io.insert-koin:koin-androidx-navigation:$koin_android_version"
|
||||
implementation "io.insert-koin:koin-androidx-compose:$koin_android_compose_version"
|
||||
|
||||
// Accompanist
|
||||
implementation "com.google.accompanist:accompanist-swiperefresh:0.27.0"
|
||||
}
|
|
@ -4,9 +4,7 @@ import android.app.Application
|
|||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
|
@ -22,9 +20,13 @@ import com.hnu.nanamail.ui.component.MailItemComponent
|
|||
import com.hnu.nanamail.ui.component.MainTopBarComponent
|
||||
import com.hnu.nanamail.viewmodel.InboxViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
||||
import androidx.compose.material.pullrefresh.pullRefresh
|
||||
import androidx.compose.material.pullrefresh.rememberPullRefreshState
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
fun InboxScreen(
|
||||
viewModel: InboxViewModel,
|
||||
|
@ -33,6 +35,16 @@ fun InboxScreen(
|
|||
val login = remember { mutableStateOf(true) }
|
||||
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
||||
val scope = rememberCoroutineScope()
|
||||
val refreshScope = rememberCoroutineScope()
|
||||
var refreshing by remember { mutableStateOf(false) }
|
||||
fun refresh() = refreshScope.launch {
|
||||
refreshing = true
|
||||
// viewModel.fetchMails()
|
||||
delay(5000)
|
||||
refreshing = false
|
||||
}
|
||||
|
||||
val refreshState = rememberPullRefreshState(refreshing, ::refresh)
|
||||
// if (!viewModel.checkLogin()) {
|
||||
// login.value = false
|
||||
// }
|
||||
|
@ -66,6 +78,7 @@ fun InboxScreen(
|
|||
selectedItem = NavItem.Inbox
|
||||
)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
drawerState = drawerState,
|
||||
gesturesEnabled = false
|
||||
) {
|
||||
|
@ -81,28 +94,42 @@ fun InboxScreen(
|
|||
text = stringResource(id = R.string.inbox)
|
||||
)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
Column(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 20.dp)
|
||||
.padding(it)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
.pullRefresh(refreshState)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
TrashEntryComponent(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 10.dp)
|
||||
.padding(horizontal = 20.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.heightIn(min = 300.dp)
|
||||
) {
|
||||
navController.navigate("trash")
|
||||
}
|
||||
for (mail in viewModel.mailList) {
|
||||
MailItemComponent(mail = mail) {
|
||||
navController.navigate("mail/${mail.uuid}")
|
||||
TrashEntryComponent(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 10.dp)
|
||||
) {
|
||||
navController.navigate("trash")
|
||||
}
|
||||
for (mail in viewModel.mailList) {
|
||||
MailItemComponent(mail = mail) {
|
||||
navController.navigate("mail/${mail.uuid}")
|
||||
}
|
||||
}
|
||||
}
|
||||
PullRefreshIndicator(
|
||||
refreshing = refreshing,
|
||||
state = refreshState,
|
||||
modifier = Modifier.align(Alignment.TopCenter),
|
||||
contentColor = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
buildscript {
|
||||
ext {
|
||||
compose_version = '1.3.0'
|
||||
compose_version = '1.3.1'
|
||||
ksp_version = "1.6.21-1.0.6"
|
||||
}
|
||||
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
|
Loading…
Reference in New Issue