From 44709579880780060d172d6a66b745c42520f9bf Mon Sep 17 00:00:00 2001 From: Ed Holloway-George Date: Tue, 24 Jun 2025 08:30:49 +0200 Subject: [PATCH] Add Gemini Style Guide --- .gemini/styleguide.md | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .gemini/styleguide.md diff --git a/.gemini/styleguide.md b/.gemini/styleguide.md new file mode 100644 index 000000000..7ad08290b --- /dev/null +++ b/.gemini/styleguide.md @@ -0,0 +1,90 @@ +# Now In Android Style Guide + +# Introduction +This style guide outlines the coding conventions for the Now In Android application. +Generally speaking, this application follows the official Kotlin coding styleguide and best practises used when writing modern Android mobile applications. + +# Key Principles +* **Security:** Code should always follow security best practises and avoid introducing vulnerbilities. +* **Readability:** Code should be easy to understand for all team members. +* **Maintainability:** Code should be easy to modify and extend. +* **Consistency:** Adhering to a consistent style across all projects improves + collaboration and reduces errors. +* **Performance:** While readability is paramount, code should be efficient especially when working with custom UI or business logic. + +# Tooling +* **Code formatter:** [Spotless] - Enforces consistent formatting automatically. +* **Linter:** [ktlint] - Identifies potential issues and style violations. + +# Example +```kotlin +package com.google.samples.apps.nowinandroid + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading +import com.google.samples.apps.nowinandroid.MainActivityUiState.Success +import com.google.samples.apps.nowinandroid.core.data.repository.UserDataRepository +import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig +import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand +import com.google.samples.apps.nowinandroid.core.model.data.UserData +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn +import javax.inject.Inject + +@HiltViewModel +class MainActivityViewModel @Inject constructor( + userDataRepository: UserDataRepository, +) : ViewModel() { + val uiState: StateFlow = userDataRepository.userData.map { + Success(it) + }.stateIn( + scope = viewModelScope, + initialValue = Loading, + started = SharingStarted.WhileSubscribed(5_000), + ) +} + +sealed interface MainActivityUiState { + data object Loading : MainActivityUiState + + data class Success(val userData: UserData) : MainActivityUiState { + override val shouldDisableDynamicTheming = !userData.useDynamicColor + + override val shouldUseAndroidTheme: Boolean = when (userData.themeBrand) { + ThemeBrand.DEFAULT -> false + ThemeBrand.ANDROID -> true + } + + override fun shouldUseDarkTheme(isSystemDarkTheme: Boolean) = + when (userData.darkThemeConfig) { + DarkThemeConfig.FOLLOW_SYSTEM -> isSystemDarkTheme + DarkThemeConfig.LIGHT -> false + DarkThemeConfig.DARK -> true + } + } + + /** + * Returns `true` if the state wasn't loaded yet and it should keep showing the splash screen. + */ + fun shouldKeepSplashScreen() = this is Loading + + /** + * Returns `true` if the dynamic color is disabled. + */ + val shouldDisableDynamicTheming: Boolean get() = true + + /** + * Returns `true` if the Android theme should be used. + */ + val shouldUseAndroidTheme: Boolean get() = false + + /** + * Returns `true` if dark theme should be used. + */ + fun shouldUseDarkTheme(isSystemDarkTheme: Boolean) = isSystemDarkTheme +} +``` \ No newline at end of file