Add send eBook through mail feature.
This commit is contained in:
parent
38c67504b2
commit
82aa5ec62a
2 changed files with 50 additions and 65 deletions
|
|
@ -1,11 +1,6 @@
|
|||
package com.pixelized.biblib.ui.composable.pages
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.core.MutableTransitionState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
|
|
@ -20,7 +15,7 @@ import androidx.compose.material.icons.filled.Send
|
|||
import androidx.compose.runtime.Composable
|
||||
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.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
|
|
@ -40,7 +35,6 @@ import com.pixelized.biblib.ui.composable.common.HtmlText
|
|||
import com.pixelized.biblib.ui.composable.common.Image
|
||||
import com.pixelized.biblib.ui.data.BookUio
|
||||
import com.pixelized.biblib.ui.data.MailUio
|
||||
import com.pixelized.biblib.ui.theme.Animation
|
||||
import com.pixelized.biblib.ui.theme.BibLibTheme
|
||||
import com.pixelized.biblib.ui.theme.Teal200
|
||||
import com.pixelized.biblib.ui.viewmodel.book.BooksViewModel
|
||||
|
|
@ -50,10 +44,11 @@ import com.pixelized.biblib.ui.viewmodel.user.UserViewModel
|
|||
import com.pixelized.biblib.utils.BitmapCache
|
||||
import com.pixelized.biblib.utils.injection.ServiceLocator
|
||||
import com.pixelized.biblib.utils.mock.BookMock
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@Composable
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@OptIn(ExperimentalMaterialApi::class, ExperimentalAnimationApi::class)
|
||||
fun DetailPage(
|
||||
booksViewModel: IBooksViewModel = viewModel<BooksViewModel>(),
|
||||
userViewModel: IUserViewModel = viewModel<UserViewModel>(),
|
||||
|
|
@ -65,11 +60,23 @@ fun DetailPage(
|
|||
.fillMaxHeight(),
|
||||
elevation = 4.dp
|
||||
) {
|
||||
val bottomSheetVisibility = remember { MutableTransitionState(false) }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
|
||||
|
||||
val book by booksViewModel.getBookDetail(bookId).observeAsState()
|
||||
val user by userViewModel.user.observeAsState()
|
||||
|
||||
ModalBottomSheetLayout(
|
||||
sheetState = sheetState,
|
||||
sheetContent = {
|
||||
SendMailBottomSheet(
|
||||
user?.amazonEmails?.map { MailUio(it) } ?: listOf(),
|
||||
onItemClick = {
|
||||
booksViewModel.send(id = bookId, mail = it.mail)
|
||||
},
|
||||
)
|
||||
},
|
||||
) {
|
||||
book?.let {
|
||||
DetailPage(
|
||||
book = it,
|
||||
|
|
@ -81,30 +88,13 @@ fun DetailPage(
|
|||
email?.let { mail -> booksViewModel.send(id = bookId, mail = mail) }
|
||||
}
|
||||
emailCount > 1 -> {
|
||||
bottomSheetVisibility.targetState = true
|
||||
coroutineScope.launch { sheetState.show() }
|
||||
}
|
||||
else -> Unit // TODO warning popup, no email.
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
AnimatedVisibility(
|
||||
visibleState = bottomSheetVisibility,
|
||||
enter = slideInVertically(
|
||||
animationSpec = tween(Animation.MEDIUM_DURATION),
|
||||
initialOffsetY = { it },
|
||||
),
|
||||
exit = slideOutVertically(
|
||||
animationSpec = tween(Animation.MEDIUM_DURATION),
|
||||
targetOffsetY = { it },
|
||||
),
|
||||
) {
|
||||
SendMailBottomSheet(
|
||||
user?.amazonEmails?.map { MailUio(it) } ?: listOf(),
|
||||
onItemClick = { booksViewModel.send(id = bookId, mail = it.mail) },
|
||||
onOutsideClick = { bottomSheetVisibility.targetState = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -250,24 +240,18 @@ private fun SendMailBottomSheet(
|
|||
MailUio("R.Daneel.Olivaw.Kindle@gmailcom"),
|
||||
),
|
||||
onItemClick: (MailUio) -> Unit = {},
|
||||
onOutsideClick: () -> Unit = {},
|
||||
) {
|
||||
val typography = MaterialTheme.typography
|
||||
|
||||
Box(
|
||||
contentAlignment = Alignment.BottomCenter,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight()
|
||||
.clickable { onOutsideClick() },
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.background(MaterialTheme.colors.background)
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier.padding(horizontal = 16.dp).padding(top = 8.dp),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.padding(top = 8.dp),
|
||||
style = typography.caption,
|
||||
text = "Send this EBook to:",
|
||||
text = "Send this eBook to:",
|
||||
)
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
|
@ -279,7 +263,6 @@ private fun SendMailBottomSheet(
|
|||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SendMailItem(
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ class BooksViewModel : ViewModel(), IBooksViewModel {
|
|||
}
|
||||
|
||||
override fun send(id: Int, mail: String) {
|
||||
// TODO()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
client.service.send(bookId = id, mail = mail)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun loadNewBooks(): Boolean {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue