Skip to content

Commit

Permalink
chore: update colors and clean up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudmathieu committed Mar 25, 2024
1 parent 1252cde commit 5df14ea
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 464 deletions.
6 changes: 3 additions & 3 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name=".AndroidMakersApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".AndroidMakersApplication"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/PreviewTheme.AndroidMakers"
Expand All @@ -32,12 +32,12 @@
android:resource="@color/white" />

<activity
android:name=".ui.MainActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:launchMode="singleTask"
android:name=".ui.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AndroidMakers.NoActionBar"
android:launchMode="singleTask"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -46,9 +46,9 @@
</activity>

<service
android:name=".messaging.AndroidMakersMessagingService"
android:directBootAware="true"
android:exported="false">
android:exported="false"
android:name=".messaging.AndroidMakersMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ import io.openfeedback.android.OpenFeedback

class AndroidMakersApplication : Application() {

lateinit var openFeedback: OpenFeedback
private lateinit var openFeedback: OpenFeedback

override fun onCreate() {
super.onCreate()

DependenciesBuilder(this).inject(
listOf(androidViewModelModule, viewModelModule)
listOf(
androidViewModelModule,
viewModelModule
)
)

openFeedback = OpenFeedback(
context = this,
openFeedbackProjectId = "am2023",
firebaseConfig = OpenFeedback.FirebaseConfig(
projectId = "open-feedback-42",
applicationId = "1:635903227116:web:31de912f8bf29befb1e1c9",
apiKey = "AIzaSyB3ELJsaiItrln0uDGSuuHE1CfOJO67Hb4",
databaseUrl = "https://open-feedback-42.firebaseio.com"
)
context = this,
openFeedbackProjectId = "am2023",
firebaseConfig = OpenFeedback.FirebaseConfig(
projectId = "open-feedback-42",
applicationId = "1:635903227116:web:31de912f8bf29befb1e1c9",
apiKey = "AIzaSyB3ELJsaiItrln0uDGSuuHE1CfOJO67Hb4",
databaseUrl = "https://open-feedback-42.firebaseio.com"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,30 @@ class AndroidMakersMessagingService : FirebaseMessagingService() {
private fun sendNotification(messageBody: String) {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_IMMUTABLE)
val pendingIntent = PendingIntent.getActivity(
this, 0 /* Request code */, intent,
PendingIntent.FLAG_IMMUTABLE
)

val channelId = "fcm_default_channel"
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setSmallIcon(R.drawable.notification)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setSmallIcon(R.drawable.notification)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)

val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT)
val channel = NotificationChannel(
channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT
)
notificationManager.createNotificationChannel(channel)
}

Expand Down
37 changes: 18 additions & 19 deletions androidApp/src/main/java/fr/paug/androidmakers/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.runtime.staticCompositionLocalOf
import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope
import com.androidmakers.ui.MainLayout
import com.androidmakers.ui.theme.AndroidMakersTheme
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
Expand All @@ -30,7 +31,6 @@ import dev.gitlive.firebase.auth.auth
import fr.androidmakers.store.firebase.toUser
import fr.paug.androidmakers.BuildConfig
import fr.paug.androidmakers.R
import fr.paug.androidmakers.ui.theme.AndroidMakersTheme
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -46,7 +46,6 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)
enableEdgeToEdge()

logFCMToken()

Expand All @@ -57,28 +56,28 @@ class MainActivity : AppCompatActivity() {
val darkTheme = isSystemInDarkTheme()

CompositionLocalProvider(
LocalActivity provides rememberedActivity,
LocalActivity provides rememberedActivity,
) {
KoinContext {
AndroidMakersTheme {
DisposableEffect(darkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
) { darkTheme },
statusBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT,
) { darkTheme },
)
onDispose { }
}

MainLayout(
user = userState.value,
versionName = BuildConfig.VERSION_NAME,
versionCode = BuildConfig.VERSION_CODE.toString(),
user = userState.value,
versionName = BuildConfig.VERSION_NAME,
versionCode = BuildConfig.VERSION_CODE.toString(),
)
}
}
Expand All @@ -103,7 +102,7 @@ class MainActivity : AppCompatActivity() {
when (requestCode) {
REQ_SIGNIN -> {
val task: Task<GoogleSignInAccount> =
GoogleSignIn.getSignedInAccountFromIntent(data)
GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account: GoogleSignInAccount = task.getResult(ApiException::class.java)
val idToken = account.idToken
Expand Down Expand Up @@ -138,8 +137,8 @@ class MainActivity : AppCompatActivity() {
fun signout() {
val activity = this
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(activity.getString(R.string.default_web_client_id))
.build()
.requestIdToken(activity.getString(R.string.default_web_client_id))
.build()
val googleSignInClient = GoogleSignIn.getClient(activity, gso)

lifecycleScope.launch {
Expand All @@ -153,8 +152,8 @@ class MainActivity : AppCompatActivity() {
fun signin() {
val activity = this
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(activity.getString(R.string.default_web_client_id))
.build()
.requestIdToken(activity.getString(R.string.default_web_client_id))
.build()
val googleSignInClient = GoogleSignIn.getClient(activity, gso)

activity.startActivityForResult(googleSignInClient.signInIntent, REQ_SIGNIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MainActivityViewModel(
private val userRepository: UserRepository,
val syncBookmarksUseCase: SyncBookmarksUseCase

): ViewModel() {
) : ViewModel() {
private val _user = MutableStateFlow<User?>(null)
val user: Flow<User?> = _user

Expand All @@ -23,9 +23,9 @@ class MainActivityViewModel(

val currentUser = _user.value
if (currentUser != null) {
// fire & forget
// This is racy but oh well...
syncBookmarksUseCase(currentUser.id)
// fire & forget
// This is racy but oh well...
syncBookmarksUseCase(currentUser.id)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,41 @@ package fr.paug.androidmakers.ui.components
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import fr.paug.androidmakers.R

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ShowRationalPermissionDialog(
packageName: String,
openDialog: MutableState<Boolean>,
onclick: () -> Unit,
packageName: String,
openDialog: MutableState<Boolean>,
onclick: () -> Unit,
) {
if (openDialog.value) {
val context = LocalContext.current
AlertDialog(
onDismissRequest = { openDialog.value = false },
title = { Text(text = stringResource(id = R.string.permission_notifications_rationale_title)) },
text = { Text(text = stringResource(id = R.string.permission_notifications_rationale_text)) },
confirmButton = {
TextButton(
onClick = {
openDialog.value = false
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:$packageName")
context.startActivity(intent)
}
) {
Text(stringResource(id = R.string.permission_notifications_rationale_positive))
onDismissRequest = { openDialog.value = false },
title = { Text(text = stringResource(id = R.string.permission_notifications_rationale_title)) },
text = { Text(text = stringResource(id = R.string.permission_notifications_rationale_text)) },
confirmButton = {
TextButton(
onClick = {
openDialog.value = false
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:$packageName")
context.startActivity(intent)
}
) {
Text(stringResource(id = R.string.permission_notifications_rationale_positive))
}
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,49 @@ fun SigninButton(user: User?) {
val expandedState = remember { mutableStateOf(false) }

IconButton(
onClick = {
expandedState.value = true
}
onClick = {
expandedState.value = true
}
) {
if (user == null) {
Icon(
imageVector = Icons.Rounded.AccountCircle,
contentDescription = stringResource(MR.strings.signin)
imageVector = Icons.Rounded.AccountCircle,
contentDescription = stringResource(MR.strings.signin)
)
} else {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(user.photoUrl)
.build(),
modifier = Modifier.clip(CircleShape),
contentDescription = stringResource(MR.strings.signout)
model = ImageRequest.Builder(LocalContext.current)
.data(user.photoUrl)
.build(),
modifier = Modifier.clip(CircleShape),
contentDescription = stringResource(MR.strings.signout)
)
}
}

DropdownMenu(
expanded = expandedState.value,
onDismissRequest = { expandedState.value = false }
expanded = expandedState.value,
onDismissRequest = { expandedState.value = false }
) {
if (user == null) {
DropdownMenuItem(
text = {
Text(stringResource(MR.strings.signin))
},
onClick = {
expandedState.value = false
activity.signin()
}
text = {
Text(stringResource(MR.strings.signin))
},
onClick = {
expandedState.value = false
activity.signin()
}
)
} else {
DropdownMenuItem(
text = {
Text(stringResource(MR.strings.signout))
},
onClick = {
expandedState.value = false
activity.signout()
}
text = {
Text(stringResource(MR.strings.signout))
},
onClick = {
expandedState.value = false
activity.signout()
}
)
}
}
Expand Down
Loading

0 comments on commit 5df14ea

Please sign in to comment.