Skip to content
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

Credits screen with attribution to simplemaps.com #219

Merged
merged 2 commits into from
Jan 25, 2025
Merged
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,205 @@
package dev.hossain.weatheralert.ui.about

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withLink
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.slack.circuit.codegen.annotations.CircuitInject
import com.slack.circuit.runtime.CircuitUiEvent
import com.slack.circuit.runtime.CircuitUiState
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.presenter.Presenter
import com.slack.circuit.runtime.screen.Screen
import com.slack.circuitx.effects.LaunchedImpressionEffect
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dev.hossain.weatheralert.R
import dev.hossain.weatheralert.di.AppScope
import dev.hossain.weatheralert.ui.theme.WeatherAlertAppTheme
import dev.hossain.weatheralert.ui.theme.dimensions
import dev.hossain.weatheralert.util.Analytics
import kotlinx.parcelize.Parcelize

@Parcelize
data class AppCreditsScreen(
val requestId: String,
) : Screen {
data class State(
val eventSink: (Event) -> Unit,
) : CircuitUiState

sealed class Event : CircuitUiEvent {
data object GoBack : Event()
}
}

class AppCreditsPresenter
@AssistedInject
constructor(
@Assisted private val navigator: Navigator,
@Assisted private val screen: AppCreditsScreen,
private val analytics: Analytics,
) : Presenter<AppCreditsScreen.State> {
@Composable
override fun present(): AppCreditsScreen.State {
LaunchedImpressionEffect {
analytics.logScreenView(AppCreditsScreen::class)
}

return AppCreditsScreen.State { event ->
when (event) {
AppCreditsScreen.Event.GoBack -> {
navigator.pop()
}
}
}
}

@CircuitInject(AppCreditsScreen::class, AppScope::class)
@AssistedFactory
fun interface Factory {
fun create(
navigator: Navigator,
screen: AppCreditsScreen,
): AppCreditsPresenter
}
}

@OptIn(ExperimentalMaterial3Api::class)
@CircuitInject(AppCreditsScreen::class, AppScope::class)
@Composable
fun AppCreditsScreen(
state: AppCreditsScreen.State,
modifier: Modifier = Modifier,
) {
Scaffold(
topBar = {
TopAppBar(
title = { Text("Credits") },
navigationIcon = {
IconButton(onClick = {
state.eventSink(AppCreditsScreen.Event.GoBack)
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Go back",
)
}
},
)
},
) { contentPaddingValues ->
Column(
modifier =
modifier
.fillMaxSize()
.padding(contentPaddingValues)
.padding(horizontal = MaterialTheme.dimensions.horizontalScreenPadding)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
Image(
painter = painterResource(R.drawable.world_map),
contentDescription = "World Map",
modifier = Modifier.padding(top = 0.dp).align(Alignment.CenterHorizontally).size(100.dp),
)
Text(
text = "City Database",
style = MaterialTheme.typography.titleMedium,
)
SimpleMapsLinkedText()
Spacer(modifier = Modifier.height(8.dp))

Image(
painter = painterResource(R.drawable.alien_monster_icon),
contentDescription = "World Map",
modifier = Modifier.padding(top = 0.dp).align(Alignment.CenterHorizontally).size(100.dp),
)
Text(
text = "Icons",
style = MaterialTheme.typography.titleMedium,
)
Text(
text = "- Material Design Icons",
style = MaterialTheme.typography.bodyMedium,
)
Text(
text = "- Vector icons from various sources",
style = MaterialTheme.typography.bodyMedium,
)
}
}
}

@Composable
private fun SimpleMapsLinkedText() {
val uriHandler = LocalUriHandler.current

val annotatedLinkString =
buildAnnotatedString {
append("The world cities database is provided by ")
withLink(
LinkAnnotation.Url(
url = "https://simplemaps.com",
styles =
TextLinkStyles(
style = SpanStyle(color = MaterialTheme.colorScheme.primary),
hoveredStyle = SpanStyle(color = MaterialTheme.colorScheme.secondary),
),
linkInteractionListener = {
uriHandler.openUri("https://simplemaps.com")
},
),
) {
withStyle(style = SpanStyle(color = MaterialTheme.colorScheme.primary)) {
append("simplemaps.com")
}
}
append(".")
}
Text(text = annotatedLinkString)
}

@Preview(showBackground = true, name = "Light Mode")
@Preview(showBackground = true, uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES, name = "Dark Mode")
@Composable
fun AppCreditsScreenPreview() {
val sampleState =
AppCreditsScreen.State(
eventSink = {},
)
WeatherAlertAppTheme {
AppCreditsScreen(state = sampleState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import dev.hossain.weatheralert.db.AlertDao
import dev.hossain.weatheralert.db.UserCityAlert
import dev.hossain.weatheralert.di.AppScope
import dev.hossain.weatheralert.network.NetworkMonitor
import dev.hossain.weatheralert.ui.about.AppCreditsScreen
import dev.hossain.weatheralert.ui.addalert.AddNewWeatherAlertScreen
import dev.hossain.weatheralert.ui.details.WeatherAlertDetailsScreen
import dev.hossain.weatheralert.ui.settings.UserSettingsScreen
Expand Down Expand Up @@ -124,6 +125,8 @@ data class CurrentWeatherAlertScreen(

data object AboutAppClicked : Event()

data object CreditsClicked : Event()

data class UndoDelete(
val item: AlertTileData,
) : Event()
Expand Down Expand Up @@ -271,6 +274,11 @@ class CurrentWeatherAlertPresenter
Timber.d("About app clicked.")
// TODO https://github.com/hossain-khan/android-weather-alert/issues/211
}

CurrentWeatherAlertScreen.Event.CreditsClicked -> {
Timber.d("Credits clicked.")
navigator.goTo(AppCreditsScreen("credits"))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ fun AppMenuItems(

DropdownMenuItem(
text = { Text("Send Feedback") },
leadingIcon = { Icon(painter = painterResource(R.drawable.feedback_24dp), contentDescription = null) },
trailingIcon = { Icon(painter = painterResource(R.drawable.open_in_new_24dp), contentDescription = null) },
leadingIcon = { Icon(painter = painterResource(R.drawable.github_logo), contentDescription = "Github Logo Icon") },
trailingIcon = { Icon(painter = painterResource(R.drawable.open_in_new_24dp), contentDescription = "External Link Icon") },
onClick = {
expanded = false
// Take user to GitHub issues page to report issue or provide feedback.
Expand All @@ -70,6 +70,15 @@ fun AppMenuItems(

HorizontalDivider()

DropdownMenuItem(
text = { Text("Credits") },
leadingIcon = { Icon(painter = painterResource(R.drawable.book_letter_24dp), contentDescription = null) },
onClick = {
expanded = false
eventSink(Event.CreditsClicked)
},
)

DropdownMenuItem(
text = { Text("About") },
leadingIcon = { Icon(Icons.Outlined.Info, contentDescription = null) },
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/drawable-night/alien_monster_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="36"
android:viewportHeight="36">
<!--
Source: https://www.svgrepo.com/svg/404714/alien-monster
-->

<path
android:fillColor="#866BBD"
android:pathData="M26,31h4v4h-4zM6,31h4v4L6,35zM30,10h-2L28,8h-2L26,6h-3L23,2h-2v4h-6L15,2h-2v4h-3v2L8,8v2L6,10v7L2,17v2h4v7h4v5h5v-5h6v5h5v-5h4v-7h4v-2h-4v-7zM16,21h-4v-8h4v8zM20,21v-8h4v8h-4zM34,6h2v11h-2zM0,6h2v11L0,17z" />

</vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/alien_monster_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="36"
android:viewportHeight="36">
<!--
Source: https://www.svgrepo.com/svg/404714/alien-monster
-->

<path
android:fillColor="#553986"
android:pathData="M26,31h4v4h-4zM6,31h4v4L6,35zM30,10h-2L28,8h-2L26,6h-3L23,2h-2v4h-6L15,2h-2v4h-3v2L8,8v2L6,10v7L2,17v2h4v7h4v5h5v-5h6v5h5v-5h4v-7h4v-2h-4v-7zM16,21h-4v-8h4v8zM20,21v-8h4v8h-4zM34,6h2v11h-2zM0,6h2v11L0,17z" />

</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/book_letter_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M300,880q-59,0 -99.5,-40.5T160,740v-520q0,-58 40.5,-99t99.5,-41h500v600q-26,0 -43,17.5T740,740q0,26 17,43t43,17v80L300,880ZM300,800h373q-6,-14 -9.5,-28.5T660,740q0,-16 3,-31t10,-29L300,680q-26,0 -43,17.5T240,740q0,26 17,43t43,17ZM240,613q14,-7 28.5,-10t31.5,-3h420v-440L300,160q-26,0 -43,17.5T240,220v393ZM349,520h49l25,-71h113l25,71h49L504,240h-50L349,520ZM437,408 L478,292h3l41,116h-85ZM240,613v-453,453Z"
android:fillColor="#e8eaed"/>
</vector>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/credits_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:strokeWidth="0.3"
android:strokeColor="#FF000000"
android:fillColor="#FF000000"
android:pathData="M7,15.5c0,0.049 0.006,0.096 0.007,0.145a7.3,7.3 0,1 1,8.638 -8.638c-0.049,0 -0.096,-0.007 -0.145,-0.007a8.557,8.557 0,0 0,-0.877 0.045,6.296 6.296,0 1,0 -7.578,7.578A8.557,8.557 0,0 0,7 15.5zM7.983,4.23l-0.119,-0.992A5.3,5.3 0,0 0,3.2 8.558c0.002,0.153 0.01,0.303 0.024,0.45l0.995,-0.093a4.508,4.508 0,0 1,-0.019 -0.367A4.3,4.3 0,0 1,7.983 4.23zM22.8,15.5a7.3,7.3 0,1 1,-7.3 -7.3,7.308 7.308,0 0,1 7.3,7.3zM21.8,15.5a6.3,6.3 0,1 0,-6.3 6.3,6.307 6.307,0 0,0 6.3,-6.3zM11.22,15.915a4.508,4.508 0,0 1,-0.02 -0.367,4.3 4.3,0 0,1 3.783,-4.318l-0.119,-0.992a5.3,5.3 0,0 0,-4.664 5.32c0.002,0.153 0.01,0.303 0.024,0.45zM19.248,11.752l-0.707,0.707a4.3,4.3 0,1 1,-6.082 6.082l-0.707,0.707a5.3,5.3 0,0 0,7.496 -7.496z" />

</vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/github_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="20"
android:viewportHeight="20">

<path
android:fillColor="#000000"
android:fillType="evenOdd"
android:pathData="M10,0C15.523,0 20,4.59 20,10.253C20,14.782 17.138,18.624 13.167,19.981C12.66,20.082 12.48,19.762 12.48,19.489C12.48,19.151 12.492,18.047 12.492,16.675C12.492,15.719 12.172,15.095 11.813,14.777C14.04,14.523 16.38,13.656 16.38,9.718C16.38,8.598 15.992,7.684 15.35,6.966C15.454,6.707 15.797,5.664 15.252,4.252C15.252,4.252 14.414,3.977 12.505,5.303C11.706,5.076 10.85,4.962 10,4.958C9.15,4.962 8.295,5.076 7.497,5.303C5.586,3.977 4.746,4.252 4.746,4.252C4.203,5.664 4.546,6.707 4.649,6.966C4.01,7.684 3.619,8.598 3.619,9.718C3.619,13.646 5.954,14.526 8.175,14.785C7.889,15.041 7.63,15.493 7.54,16.156C6.97,16.418 5.522,16.871 4.63,15.304C4.63,15.304 4.101,14.319 3.097,14.247C3.097,14.247 2.122,14.234 3.029,14.87C3.029,14.87 3.684,15.185 4.139,16.37C4.139,16.37 4.726,18.2 7.508,17.58C7.513,18.437 7.522,19.245 7.522,19.489C7.522,19.76 7.338,20.077 6.839,19.982C2.865,18.627 0,14.783 0,10.253C0,4.59 4.478,0 10,0"
android:strokeWidth="1"
android:strokeColor="#00000000" />

</vector>
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/github_logo_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="48"
android:viewportHeight="48">

<path
android:fillColor="#00000000"
android:fillType="evenOdd"
android:pathData="M24,2.5a21.5,21.5 0,0 0,-6.8 41.9c1.08,0.2 1.47,-0.46 1.47,-1s0,-1.86 0,-3.65c-6,1.3 -7.24,-2.88 -7.24,-2.88A5.7,5.7 0,0 0,9 33.68c-1.95,-1.33 0.15,-1.31 0.15,-1.31a4.52,4.52 0,0 1,3.29 2.22c1.92,3.29 5,2.34 6.26,1.79a4.61,4.61 0,0 1,1.37 -2.88c-4.78,-0.54 -9.8,-2.38 -9.8,-10.62a8.29,8.29 0,0 1,2.22 -5.77,7.68 7.68,0 0,1 0.21,-5.69s1.8,-0.58 5.91,2.2a20.46,20.46 0,0 1,10.76 0c4.11,-2.78 5.91,-2.2 5.91,-2.2a7.74,7.74 0,0 1,0.21 5.69,8.28 8.28,0 0,1 2.21,5.77c0,8.26 -5,10.07 -9.81,10.61a5.12,5.12 0,0 1,1.46 4c0,2.87 0,5.19 0,5.9s0.39,1.24 1.48,1A21.5,21.5 0,0 0,24 2.5"
android:strokeWidth="1"
android:strokeColor="#000000"
android:strokeLineCap="round"
android:strokeLineJoin="round" />

</vector>
Loading