Skip to content

Commit

Permalink
[SHARED] Handle licenses webpage
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgurgul committed Jan 24, 2025
1 parent e9305be commit d274f16
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="#FFFFFF"
android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h4v-2L5,18L5,8h14v10h-4v2h4c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.89,-2 -2,-2zM12,10l-4,4h3v6h2v-6h3l-4,-4z" />

</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<string name="licenses_module_name">Název modulu:</string>
<string name="licenses_module_version">Verze modulu:</string>
<string name="licenses_module_license">Licence:</string>
<string name="licenses_webpage">Webová stránka</string>

</resources>

Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,6 @@
<string name="licenses_module_name">Modulname:</string>
<string name="licenses_module_version">Modulversion:</string>
<string name="licenses_module_license">Lizenz:</string>
<string name="licenses_webpage">Webseite</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@
<string name="licenses_module_name">Nazwa modułu:</string>
<string name="licenses_module_version">Wersja modułu:</string>
<string name="licenses_module_license">Licencja:</string>
<string name="licenses_webpage">Strona internetowa</string>

</resources>
1 change: 1 addition & 0 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,6 @@
<string name="licenses_module_name">Module name:</string>
<string name="licenses_module_version">Module version:</string>
<string name="licenses_module_license">License:</string>
<string name="licenses_webpage">Webpage</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand All @@ -28,20 +30,24 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.kgurgul.cpuinfo.domain.model.License
import com.kgurgul.cpuinfo.shared.Res
import com.kgurgul.cpuinfo.shared.back
import com.kgurgul.cpuinfo.shared.ic_open_in_browser
import com.kgurgul.cpuinfo.shared.licenses
import com.kgurgul.cpuinfo.shared.licenses_module_license
import com.kgurgul.cpuinfo.shared.licenses_module_name
import com.kgurgul.cpuinfo.shared.licenses_module_version
import com.kgurgul.cpuinfo.shared.licenses_webpage
import com.kgurgul.cpuinfo.ui.components.CpuDivider
import com.kgurgul.cpuinfo.ui.components.CpuPullToRefreshBox
import com.kgurgul.cpuinfo.ui.components.PrimaryTopAppBar
import com.kgurgul.cpuinfo.ui.components.VerticalScrollbar
import com.kgurgul.cpuinfo.ui.theme.spacingMedium
import com.kgurgul.cpuinfo.ui.theme.spacingSmall
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

Expand All @@ -51,10 +57,11 @@ fun LicensesScreen(
viewModel: LicensesViewModel = koinViewModel(),
) {
val uiState by viewModel.uiStateFlow.collectAsStateWithLifecycle()
val uriHandler = LocalUriHandler.current
LicensesScreen(
uiState = uiState,
onNavigateBackClicked = onNavigateBackClicked,
onLicenseUrlClicked = viewModel::onLicenseUrlClicked,
onLicenseUrlClicked = { uriHandler.openUri(uri = it) },
)
}

Expand Down Expand Up @@ -108,7 +115,6 @@ fun LicensesScreen(
onLicenseUrlClicked = onLicenseUrlClicked,
)
if (index != uiState.licenses.lastIndex) {
Spacer(modifier = Modifier.size(spacingMedium))
CpuDivider(
modifier = Modifier.padding(top = spacingSmall),
)
Expand Down Expand Up @@ -181,5 +187,19 @@ private fun LicenseItem(
color = MaterialTheme.colorScheme.onBackground,
)
}
Button(
onClick = { onLicenseUrlClicked(license.licenseUrl) },
) {
Icon(
painter = painterResource(Res.drawable.ic_open_in_browser),
contentDescription = stringResource(Res.string.licenses_webpage),
modifier = Modifier.size(ButtonDefaults.IconSize)
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(
text = stringResource(Res.string.licenses_webpage),
style = MaterialTheme.typography.bodyMedium,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class LicensesViewModel(
}
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), UiState())

fun onLicenseUrlClicked(url: String) {

}

data class UiState(
val isLoading: Boolean = false,
val isError: Boolean = false,
Expand Down

0 comments on commit d274f16

Please sign in to comment.