fix: 看图页面底栏内容颜色

This commit is contained in:
HuanCheng65 2023-05-05 22:56:45 +08:00
parent c347420dee
commit 7d8c7ed3e6
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
1 changed files with 70 additions and 67 deletions

View File

@ -5,6 +5,7 @@ import android.net.Uri
import android.os.Build import android.os.Build
import android.view.MotionEvent import android.view.MotionEvent
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -13,6 +14,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.IconButton import androidx.compose.material.IconButton
@ -40,9 +43,6 @@ import com.github.panpf.sketch.displayImage
import com.github.panpf.sketch.zoom.Edge import com.github.panpf.sketch.zoom.Edge
import com.github.panpf.sketch.zoom.ReadModeDecider import com.github.panpf.sketch.zoom.ReadModeDecider
import com.github.panpf.sketch.zoom.SketchZoomImageView import com.github.panpf.sketch.zoom.SketchZoomImageView
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.rememberPagerState
import com.huanchengfly.tieba.post.R import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.arch.BaseComposeActivityWithParcelable import com.huanchengfly.tieba.post.arch.BaseComposeActivityWithParcelable
import com.huanchengfly.tieba.post.arch.collectPartialAsState import com.huanchengfly.tieba.post.arch.collectPartialAsState
@ -50,6 +50,7 @@ import com.huanchengfly.tieba.post.models.protos.PhotoViewData
import com.huanchengfly.tieba.post.toastShort import com.huanchengfly.tieba.post.toastShort
import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.ProvideContentColor
import com.huanchengfly.tieba.post.utils.ImageUtil import com.huanchengfly.tieba.post.utils.ImageUtil
import com.huanchengfly.tieba.post.utils.download import com.huanchengfly.tieba.post.utils.download
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -137,7 +138,7 @@ class PhotoViewActivity : BaseComposeActivityWithParcelable<PhotoViewData>() {
override val dataExtraKey: String = EXTRA_PHOTO_VIEW_DATA override val dataExtraKey: String = EXTRA_PHOTO_VIEW_DATA
@OptIn(ExperimentalPagerApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
override fun createContent(data: PhotoViewData) { override fun createContent(data: PhotoViewData) {
LazyLoad(loaded = viewModel.initialized) { LazyLoad(loaded = viewModel.initialized) {
@ -174,7 +175,7 @@ class PhotoViewActivity : BaseComposeActivityWithParcelable<PhotoViewData>() {
} }
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
HorizontalPager( HorizontalPager(
count = pageCount, pageCount = pageCount,
state = pagerState, state = pagerState,
key = { key = {
"${items[it].originUrl}_${items[it].overallIndex}" "${items[it].originUrl}_${items[it].overallIndex}"
@ -207,71 +208,73 @@ class PhotoViewActivity : BaseComposeActivityWithParcelable<PhotoViewData>() {
.fillMaxWidth() .fillMaxWidth()
.align(Alignment.BottomCenter) .align(Alignment.BottomCenter)
) { ) {
Row( ProvideContentColor(color = Color.White) {
modifier = Modifier Row(
.fillMaxWidth() modifier = Modifier
.background( .fillMaxWidth()
Brush.verticalGradient( .background(
listOf( Brush.verticalGradient(
Color.Black.copy(alpha = 0.0f), listOf(
Color.Black.copy(alpha = 0.5f) Color.Black.copy(alpha = 0.0f),
Color.Black.copy(alpha = 0.5f)
)
) )
) )
) .padding(horizontal = 16.dp),
.padding(horizontal = 16.dp), verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically ) {
) { val index = pagerState.currentPage
val index = pagerState.currentPage if (totalAmount > 1) {
if (totalAmount > 1) { val picIndex = items[index].overallIndex ?: (index + 1)
val picIndex = items[index].overallIndex ?: (index + 1) Text(
Text( text = "$picIndex / $totalAmount",
text = "$picIndex / $totalAmount", modifier = Modifier.weight(1f)
modifier = Modifier.weight(1f) )
) } else {
} else { Spacer(modifier = Modifier.weight(1f))
Spacer(modifier = Modifier.weight(1f)) }
} IconButton(onClick = {
IconButton(onClick = { toastShort(R.string.toast_preparing_share_pic)
toastShort(R.string.toast_preparing_share_pic) ImageUtil.download(
ImageUtil.download( this@PhotoViewActivity,
this@PhotoViewActivity, items[index].originUrl,
items[index].originUrl, true
true ) { uri: Uri ->
) { uri: Uri -> val chooser = Intent(Intent.ACTION_SEND).apply {
val chooser = Intent(Intent.ACTION_SEND).apply { type = Intent.normalizeMimeType("image/jpeg")
type = Intent.normalizeMimeType("image/jpeg") if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { putExtra(Intent.EXTRA_STREAM, uri)
putExtra(Intent.EXTRA_STREAM, uri) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } else {
} else { putExtra(Intent.EXTRA_STREAM, uri)
putExtra(Intent.EXTRA_STREAM, uri) }
} }.let {
}.let { Intent.createChooser(
Intent.createChooser( it,
it, getString(R.string.title_share_pic)
getString(R.string.title_share_pic) )
) }
} runCatching {
runCatching { startActivity(chooser)
startActivity(chooser) }
} }
}) {
Icon(
imageVector = Icons.Rounded.Share,
contentDescription = stringResource(id = R.string.title_share_pic)
)
}
IconButton(onClick = {
ImageUtil.download(
this@PhotoViewActivity,
items[index].originUrl
)
}) {
Icon(
imageVector = Icons.Rounded.Download,
contentDescription = stringResource(id = R.string.desc_download_pic)
)
} }
}) {
Icon(
imageVector = Icons.Rounded.Share,
contentDescription = stringResource(id = R.string.title_share_pic)
)
}
IconButton(onClick = {
ImageUtil.download(
this@PhotoViewActivity,
items[index].originUrl
)
}) {
Icon(
imageVector = Icons.Rounded.Download,
contentDescription = stringResource(id = R.string.desc_download_pic)
)
} }
} }
} }