Skip to content

workaround for twitter user image #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Mask-Android
*
* Copyright (C) 2022 DimensionDev and Contributors
*
* This file is part of Mask-Android.
*
* Mask-Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Mask-Android is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Mask-Android. If not, see <http://www.gnu.org/licenses/>.
*/
package com.dimension.maskbook.persona.ui

import androidx.compose.foundation.Image
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import coil.compose.rememberImagePainter
import com.dimension.maskbook.common.ui.widget.NameImage
import com.dimension.maskbook.persona.export.model.Network

@Composable
fun AvatarImage(
modifier: Modifier = Modifier,
avatar: String,
name: String,
network: Network,
) {
if (avatar.isNotEmpty()) {
val source = when (network) {
Network.Twitter -> "https://unavatar.io/$name"
else -> avatar
}
Image(
painter = rememberImagePainter(source),
contentDescription = null,
modifier = modifier
.clip(CircleShape),
alpha = LocalContentAlpha.current,
)
} else {
NameImage(
name = name,
style = MaterialTheme.typography.h4,
modifier = modifier,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.rememberImagePainter
import com.dimension.maskbook.common.ui.widget.HorizontalScenePadding
import com.dimension.maskbook.common.ui.widget.MaskAnimatedVisibility
import com.dimension.maskbook.common.ui.widget.MaskListItem
import com.dimension.maskbook.common.ui.widget.MaskSearchInput
import com.dimension.maskbook.common.ui.widget.NameImage
import com.dimension.maskbook.common.ui.widget.SinglelineText
import com.dimension.maskbook.common.ui.widget.button.MaskButton
import com.dimension.maskbook.common.ui.widget.button.PrimaryButton
import com.dimension.maskbook.persona.R
import com.dimension.maskbook.persona.model.ContactData
import com.dimension.maskbook.persona.model.icon
import com.dimension.maskbook.persona.ui.AvatarImage

@OptIn(ExperimentalFoundationApi::class)
@Composable
Expand Down Expand Up @@ -182,18 +181,12 @@ fun LazyListScope.ContactsScene(
MaskListItem(
icon = {
Box(contentAlignment = Alignment.BottomEnd) {
if (item.avatar.isEmpty()) {
NameImage(
name = item.name,
modifier = Modifier.size(38.dp),
)
} else {
Image(
painter = rememberImagePainter(item.avatar),
contentDescription = null,
modifier = Modifier.size(38.dp).clip(shape = CircleShape),
)
}
AvatarImage(
modifier = Modifier.size(38.dp),
avatar = item.avatar,
name = item.name,
network = item.network
)
Image(
painter = painterResource(item.network.icon),
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.rememberImagePainter
import com.dimension.maskbook.common.ui.widget.HorizontalScenePadding
import com.dimension.maskbook.common.ui.widget.NameImage
import com.dimension.maskbook.common.ui.widget.button.MaskGridButton
import com.dimension.maskbook.common.ui.widget.itemsGridIndexed
import com.dimension.maskbook.persona.R
import com.dimension.maskbook.persona.export.model.Network
import com.dimension.maskbook.persona.export.model.SocialData
import com.dimension.maskbook.persona.model.icon
import com.dimension.maskbook.persona.ui.AvatarImage

@Composable
fun SocialScene(
Expand Down Expand Up @@ -169,7 +168,12 @@ private fun SocialItem(
),
icon = {
Box {
AvatarImage(item.avatar, item.name)
AvatarImage(
modifier = Modifier.size(SocialScreenDefaults.itemIconSize),
avatar = item.avatar,
name = item.name,
network = item.network,
)
Image(
painter = painterResource(item.network.icon),
contentDescription = null,
Expand Down Expand Up @@ -204,26 +208,6 @@ private fun SocialItem(
)
}

@Composable
private fun AvatarImage(avatar: String, name: String) {
if (avatar.isNotEmpty()) {
Image(
painter = rememberImagePainter(avatar),
contentDescription = null,
modifier = Modifier
.size(SocialScreenDefaults.itemIconSize)
.clip(CircleShape),
alpha = LocalContentAlpha.current,
)
} else {
NameImage(
name = name,
style = MaterialTheme.typography.h4,
modifier = Modifier.size(SocialScreenDefaults.itemIconSize),
)
}
}

@Preview(showBackground = true)
@Composable
private fun AddIconPreview() {
Expand Down