Skip to content

Commit

Permalink
feat(settings/about): redesign credits & add libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog authored Jul 21, 2024
1 parent 73a321f commit d3bb609
Show file tree
Hide file tree
Showing 21 changed files with 614 additions and 289 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.parcelize")
id("com.mikepenz.aboutlibraries.plugin")
}

val composeMaterialVersion = "1.7.0-beta05"
Expand Down Expand Up @@ -92,6 +93,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycleVersion")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("com.mikepenz:aboutlibraries-core:11.2.2")
implementation("io.insert-koin:koin-androidx-compose:3.5.6")
implementation("com.github.aliernfrog:top-toast-compose:2.1.0-alpha01")
implementation("com.lazygeniouz:dfc:1.0.8")
Expand Down
34 changes: 19 additions & 15 deletions app/src/main/java/com/aliernfrog/pftool/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.os.Build
import android.os.Environment
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Translate
import com.aliernfrog.pftool.data.CreditsData
import com.aliernfrog.pftool.data.PrefEditItem
import com.aliernfrog.pftool.data.Social
import com.aliernfrog.pftool.impl.CreditData
import com.aliernfrog.pftool.util.staticutil.GeneralUtil

const val TAG = "PFToolLogs"
Expand Down Expand Up @@ -77,35 +77,39 @@ object SettingsConstant {
)

val credits = listOf(
CreditsData(
CreditData(
name = "Mohammad Alizadeh",
githubUsername = "Alizadev",
description = R.string.settings_about_credits_pfDev,
url = "https://discord.gg/X6WzGpCgDJ"
link = "https://discord.gg/X6WzGpCgDJ"
),
CreditsData(
CreditData(
name = "alieRN",
description = R.string.settings_about_credits_pfToolDev,
url = "https://github.com/aliernfrog"
githubUsername = "aliernfrog",
description = R.string.settings_about_credits_pfToolDev
),
CreditsData(
CreditData(
name = "infini0083",
description = R.string.settings_about_credits_ui,
url = "https://github.com/infini0083"
githubUsername = "infini0083",
description = R.string.settings_about_credits_ui
),
CreditsData(
CreditData(
name = R.string.settings_about_credits_crowdin,
githubUsername = "crowdin",
description = R.string.settings_about_credits_translations,
url = "https://crowdin.com/project/pf-tool"
link = "https://crowdin.com/project/pf-tool"
),
CreditsData(
CreditData(
name = "Vendetta Manager",
githubUsername = "vendetta-mod",
description = R.string.settings_about_credits_inspiration,
url = "https://github.com/vendetta-mod/VendettaManager"
link = "https://github.com/vendetta-mod/VendettaManager"
),
CreditsData(
CreditData(
name = "ReVanced Manager",
githubUsername = "ReVanced",
description = R.string.settings_about_credits_inspiration,
url = "https://github.com/ReVanced/revanced-manager"
link = "https://github.com/ReVanced/revanced-manager"
)
)

Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/com/aliernfrog/pftool/data/CreditsData.kt

This file was deleted.

36 changes: 36 additions & 0 deletions app/src/main/java/com/aliernfrog/pftool/impl/CreditData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.aliernfrog.pftool.impl

import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.aliernfrog.pftool.TAG
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.json.JSONObject
import java.net.URL

class CreditData(
val name: Any,
val githubUsername: String? = null,
val description: Any,
val link: String? = githubUsername?.let { "https://github.com/$githubUsername" }
) {
private var fetchedAvatar = false
var avatarURL by mutableStateOf<String?>(null)

suspend fun fetchAvatar() {
if (fetchedAvatar) return
fetchedAvatar = true
if (githubUsername == null) return
withContext(Dispatchers.IO) {
try {
val res = URL("https://api.github.com/users/$githubUsername").readText()
val json = JSONObject(res)
avatarURL = json.getString("avatar_url")
} catch (e: Exception) {
Log.e(TAG, "CreditData/fetchAvatar: ", e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package com.aliernfrog.pftool.ui.component

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aliernfrog.pftool.imeSupportsSyncAppContent
import com.aliernfrog.pftool.ui.viewmodel.InsetsViewModel
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel

/*@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppModalBottomSheet(
title: String? = null,
Expand All @@ -34,7 +42,6 @@ fun AppModalBottomSheet(
Column(
modifier = Modifier
.fillMaxWidth()
.clip(AppBottomSheetShape)
.verticalScroll(sheetScrollState)
.padding(bottom = bottomPadding)
) {
Expand All @@ -48,7 +55,7 @@ fun AppModalBottomSheet(
sheetContent()
}
}
}*/
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ package com.aliernfrog.pftool.ui.component
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.dp
import com.aliernfrog.pftool.ui.theme.AppComponentShape
import com.aliernfrog.pftool.ui.theme.AppSmallComponentShape

@Composable
fun VerticalSegmentedButtons(
fun VerticalSegmentor(
vararg components: (@Composable () -> Unit),
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
shape: Shape = AppComponentShape
) {
val visibleItemIndexes = remember { mutableStateListOf<Int>() }
val firstVisibleItemIndex = visibleItemIndexes.minOfOrNull { it }
Column(
modifier = modifier
.clip(AppComponentShape)
modifier = modifier.clip(shape)
) {
components.forEachIndexed { index, component ->
val isStart = firstVisibleItemIndex == index
Expand All @@ -37,7 +39,7 @@ fun VerticalSegmentedButtons(
.padding(
top = topPadding
)
.clip(RoundedCornerShape(5.dp))
.clip(AppSmallComponentShape)
.onSizeChanged {
val isVisible = it.height > 0
if (isVisible && !visibleItemIndexes.contains(index)) visibleItemIndexes.add(index)
Expand All @@ -48,4 +50,40 @@ fun VerticalSegmentedButtons(
}
}
}
}

@Composable
fun HorizontalSegmentor(
vararg components: (@Composable () -> Unit),
modifier: Modifier = Modifier,
shape: Shape = AppComponentShape
) {
val visibleItemIndexes = remember { mutableStateListOf<Int>() }
val firstVisibleItemIndex = visibleItemIndexes.minOfOrNull { it }
Row(
modifier = modifier.clip(shape)
) {
components.forEachIndexed { index, component ->
val isStart = firstVisibleItemIndex == index
val visible = visibleItemIndexes.contains(index)
val startPadding by animateDpAsState(
if (visible && !isStart) 2.dp else 0.dp
)
Box(
modifier = Modifier
.weight(1f)
.padding(
start = startPadding
)
.clip(AppSmallComponentShape)
.onSizeChanged {
val isVisible = it.width > 0
if (isVisible && !visibleItemIndexes.contains(index)) visibleItemIndexes.add(index)
else if (!isVisible && visibleItemIndexes.contains(index)) visibleItemIndexes.remove(index)
}
) {
component()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -24,13 +25,15 @@ import com.aliernfrog.pftool.ui.viewmodel.MainViewModel
import com.aliernfrog.pftool.util.Destination
import com.aliernfrog.pftool.util.NavigationConstant
import com.aliernfrog.pftool.util.extension.popBackStackSafe
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainScreen(
mainViewModel: MainViewModel = koinViewModel()
) {
val scope = rememberCoroutineScope()
val navController = rememberNavController()
BaseScaffold(
navController = navController
Expand Down Expand Up @@ -82,7 +85,11 @@ fun MainScreen(

UpdateSheet(
sheetState = mainViewModel.updateSheetState,
latestVersionInfo = mainViewModel.latestVersionInfo
latestVersionInfo = mainViewModel.latestVersionInfo,
updateAvailable = mainViewModel.updateAvailable,
onCheckUpdatesRequest = { scope.launch {
mainViewModel.checkUpdates(manuallyTriggered = true)
} }
)

mainViewModel.progressState.currentProgress?.let {
Expand Down
Loading

0 comments on commit d3bb609

Please sign in to comment.