首页搜索调整
This commit is contained in:
@@ -4,11 +4,13 @@ import android.widget.Toast
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material3.Text
|
||||
@@ -23,6 +25,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -35,6 +38,10 @@ import com.aiosman.ravenow.AppStore
|
||||
import com.aiosman.ravenow.Messaging
|
||||
import com.aiosman.ravenow.R
|
||||
import com.aiosman.ravenow.data.AccountServiceImpl
|
||||
import com.aiosman.ravenow.data.ServiceException
|
||||
import com.aiosman.ravenow.data.api.ErrorCode
|
||||
import com.aiosman.ravenow.data.api.showToast
|
||||
import com.aiosman.ravenow.data.api.toErrorMessage
|
||||
import com.aiosman.ravenow.ui.NavigationRoute
|
||||
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
||||
import com.aiosman.ravenow.ui.composables.ActionButton
|
||||
@@ -46,10 +53,16 @@ fun RemoveAccountScreen() {
|
||||
val appColors = LocalAppTheme.current
|
||||
val navController = LocalNavController.current
|
||||
var inputPassword by remember { mutableStateOf("") }
|
||||
var passwordError by remember { mutableStateOf<String?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
|
||||
fun removeAccount(password: String) {
|
||||
if (password.isEmpty()) {
|
||||
passwordError = "Please enter your correct password"
|
||||
return
|
||||
}
|
||||
|
||||
scope.launch {
|
||||
try {
|
||||
val accountService = AccountServiceImpl()
|
||||
@@ -60,17 +73,21 @@ fun RemoveAccountScreen() {
|
||||
rememberMe = false
|
||||
saveData()
|
||||
}
|
||||
// 删除推送渠道
|
||||
AppState.ReloadAppState(context)
|
||||
//返回到登录页面
|
||||
navController.navigate(NavigationRoute.Login.route) {
|
||||
popUpTo(NavigationRoute.Login.route) {
|
||||
inclusive = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
//重置AppState
|
||||
AppState.ReloadAppState(context)
|
||||
Toast.makeText(context, "Account has been deleted", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: ServiceException) {
|
||||
passwordError = "Incorrect password"
|
||||
// e.errorType.showToast(context)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// show toast
|
||||
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(context, "An error occurred. Please try again.", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,17 +146,56 @@ fun RemoveAccountScreen() {
|
||||
|
||||
BasicTextField(
|
||||
value = inputPassword,
|
||||
onValueChange = { inputPassword = it },
|
||||
onValueChange = {
|
||||
inputPassword = it
|
||||
if (passwordError != null) {
|
||||
passwordError = null
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textStyle = TextStyle(color = appColors.text),
|
||||
cursorBrush = SolidColor(appColors.text)
|
||||
)
|
||||
if (inputPassword.isEmpty()) {
|
||||
Text(
|
||||
"Please enter your correct password",
|
||||
modifier = Modifier.padding(start = 5.dp),
|
||||
color = appColors.inputHint,
|
||||
fontWeight = FontWeight.W600
|
||||
)
|
||||
}
|
||||
}
|
||||
// 显示密码错误信息
|
||||
passwordError?.let {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
androidx.compose.foundation.Image(
|
||||
painter = painterResource(id = R.mipmap.rider_pro_input_error),
|
||||
contentDescription = "Error",
|
||||
modifier = Modifier.size(8.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.size(4.dp))
|
||||
|
||||
Text(
|
||||
text = it,
|
||||
color = androidx.compose.ui.graphics.Color.Red,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
ActionButton(
|
||||
text = stringResource(R.string.remove_account),
|
||||
fullWidth = true,
|
||||
enabled = inputPassword.isNotEmpty(),
|
||||
enabled = true,
|
||||
click = {
|
||||
removeAccount(inputPassword)
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -154,20 +155,24 @@ fun SearchScreen() {
|
||||
) {
|
||||
Box {
|
||||
TabItem(
|
||||
text = stringResource(R.string.users),
|
||||
text = stringResource(R.string.moment),
|
||||
isSelected = pagerState.currentPage == 0,
|
||||
onClick = {
|
||||
// TODO: 实现点击逻辑
|
||||
coroutineScope.launch {
|
||||
pagerState.animateScrollToPage(0)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
TabSpacer()
|
||||
Box {
|
||||
TabItem(
|
||||
text = stringResource(R.string.index_dynamic),
|
||||
text = stringResource(R.string.users),
|
||||
isSelected = pagerState.currentPage == 1,
|
||||
onClick = {
|
||||
// TODO: 实现点击逻辑
|
||||
coroutineScope.launch {
|
||||
pagerState.animateScrollToPage(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -304,25 +309,54 @@ fun MomentResultTab() {
|
||||
.fillMaxSize()
|
||||
.background(AppColors.background)
|
||||
) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
items(moments.itemCount) { idx ->
|
||||
val momentItem = moments[idx] ?: return@items
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color.White)
|
||||
) {
|
||||
MomentCard(
|
||||
momentEntity = momentItem,
|
||||
hideAction = true,
|
||||
onFollowClick = {
|
||||
model.momentFollowAction(momentItem)
|
||||
}
|
||||
)
|
||||
}
|
||||
if (moments.itemCount == 0 && model.showResult) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
androidx.compose.foundation.Image(
|
||||
painter = painterResource(id = R.mipmap.rider_pro_followers_empty),
|
||||
contentDescription = "No Comment",
|
||||
modifier = Modifier.size(140.dp)
|
||||
)
|
||||
Text(
|
||||
text = "咦,什么都没找到...",
|
||||
color = LocalAppTheme.current.text,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.W600
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "换个关键词试试吧,也许会有新发现!",
|
||||
color = LocalAppTheme.current.secondaryText,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
items(moments.itemCount) { idx ->
|
||||
val momentItem = moments[idx] ?: return@items
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color.White)
|
||||
) {
|
||||
MomentCard(
|
||||
momentEntity = momentItem,
|
||||
hideAction = true,
|
||||
onFollowClick = {
|
||||
model.momentFollowAction(momentItem)
|
||||
}
|
||||
)
|
||||
}
|
||||
// Spacer(modifier = Modifier.padding(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,17 +370,46 @@ fun UserResultTab() {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
items(users.itemCount) { idx ->
|
||||
val userItem = users[idx] ?: return@items
|
||||
UserItem(userItem) {
|
||||
scope.launch {
|
||||
if (userItem.isFollowing) {
|
||||
model.unfollowUser(userItem.id)
|
||||
} else {
|
||||
model.followUser(userItem.id)
|
||||
if (users.itemCount == 0 && model.showResult) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
androidx.compose.foundation.Image(
|
||||
painter = painterResource(id = R.mipmap.rider_pro_followers_empty),
|
||||
contentDescription = "No Comment",
|
||||
modifier = Modifier.size(140.dp)
|
||||
)
|
||||
Text(
|
||||
text = "咦,什么都没找到...",
|
||||
color = LocalAppTheme.current.text,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.W600
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "换个关键词试试吧,也许会有新发现!",
|
||||
color = LocalAppTheme.current.secondaryText,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
items(users.itemCount) { idx ->
|
||||
val userItem = users[idx] ?: return@items
|
||||
UserItem(userItem) {
|
||||
scope.launch {
|
||||
if (userItem.isFollowing) {
|
||||
model.unfollowUser(userItem.id)
|
||||
} else {
|
||||
model.followUser(userItem.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user