-
-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Contributors page - https://github.com/revanced/revanced-manager-compose/issues/34 * feat: adding ContributorScreen as clickable icons like the website * feat: adding ContributorScreen - Made changes that were asked for in prev PR - Currently just waiting on a git merge to get ArrowButton in * feat: adding ContributorScreen - Made changes that were asked for in prev PR - ArrowButton is also in use * feat: adding ContributorScreen - Made changes that were asked for in prev PR - ArrowButton is also in use - Fixed other PR comment changes * Apply suggestions from code review * Remove unused string resources --------- Co-authored-by: Ax333l <[email protected]>
- Loading branch information
Showing
6 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
app/src/main/java/app/revanced/manager/ui/screen/settings/ContributorScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package app.revanced.manager.ui.screen.settings | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.ArrowDropDown | ||
import androidx.compose.material.icons.outlined.ArrowDropUp | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import app.revanced.manager.R | ||
import app.revanced.manager.network.dto.ReVancedContributor | ||
import app.revanced.manager.ui.component.AppTopBar | ||
import app.revanced.manager.ui.component.ArrowButton | ||
import app.revanced.manager.ui.component.LoadingIndicator | ||
import app.revanced.manager.ui.viewmodel.ContributorViewModel | ||
import coil.compose.AsyncImage | ||
import org.koin.androidx.compose.getViewModel | ||
|
||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun ContributorScreen( | ||
onBackClick: () -> Unit, | ||
viewModel: ContributorViewModel = getViewModel() | ||
) { | ||
val repositories = viewModel.repositories | ||
Scaffold( | ||
topBar = { | ||
AppTopBar( | ||
title = stringResource(R.string.contributors), | ||
onBackClick = onBackClick | ||
) | ||
}, | ||
) { paddingValues -> | ||
Column( | ||
modifier = Modifier | ||
.fillMaxHeight() | ||
.padding(paddingValues) | ||
.fillMaxWidth() | ||
.verticalScroll(rememberScrollState()) | ||
) { | ||
if(repositories.isEmpty()) { | ||
LoadingIndicator() | ||
} | ||
repositories.forEach { | ||
ExpandableListCard( | ||
title = it.name, | ||
contributors = it.contributors | ||
) | ||
} | ||
} | ||
} | ||
} | ||
@OptIn(ExperimentalLayoutApi::class) | ||
@Composable | ||
fun ExpandableListCard( | ||
title: String, | ||
contributors: List<ReVancedContributor> | ||
) { | ||
var expanded by remember { mutableStateOf(false) } | ||
Card( | ||
shape = RoundedCornerShape(30.dp), | ||
elevation = CardDefaults.outlinedCardElevation(), | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(16.dp) | ||
.border( | ||
width = 2.dp, | ||
color = MaterialTheme.colorScheme.outline, | ||
shape = MaterialTheme.shapes.medium | ||
), | ||
colors = CardDefaults.outlinedCardColors(), | ||
) { | ||
Column() { | ||
Row() { | ||
ListItem( | ||
headlineContent = { | ||
Text( | ||
text = processHeadlineText(title), | ||
style = MaterialTheme.typography.titleMedium | ||
) | ||
}, | ||
trailingContent = { | ||
if (contributors.isNotEmpty()) { | ||
ArrowButton( | ||
expanded = expanded, | ||
onClick = { expanded = !expanded } | ||
) | ||
} | ||
}, | ||
) | ||
} | ||
if (expanded) { | ||
FlowRow( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.wrapContentHeight() | ||
.padding(8.dp), | ||
) { | ||
contributors.forEach { | ||
AsyncImage( | ||
model = it.avatarUrl, | ||
contentDescription = it.avatarUrl, | ||
contentScale = ContentScale.Crop, | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.size(45.dp) | ||
.clip(CircleShape) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
fun processHeadlineText(repositoryName: String): String { | ||
return "Revanced " + repositoryName.replace("revanced/revanced-", "") | ||
.replace("-", " ") | ||
.split(" ") | ||
.map { if (it.length > 3) it else it.uppercase() } | ||
.joinToString(" ") | ||
.replaceFirstChar { it.uppercase() } | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/app/revanced/manager/ui/viewmodel/ContributorViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app.revanced.manager.ui.viewmodel | ||
|
||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import app.revanced.manager.domain.repository.ReVancedRepository | ||
import app.revanced.manager.network.utils.getOrNull | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
class ContributorViewModel(private val repository: ReVancedRepository): ViewModel() { | ||
val repositories = mutableStateListOf<app.revanced.manager.network.dto.ReVancedRepository>() | ||
init { | ||
viewModelScope.launch { | ||
withContext(Dispatchers.IO) { | ||
val repos = repository.getContributors().getOrNull()?.repositories | ||
withContext(Dispatchers.Main) { | ||
if (repos != null) { repositories.addAll(repos) } | ||
} | ||
} | ||
} | ||
} | ||
} |