mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 06:49:07 -05:00
Initial project setup (BIT-61) (#7)
This commit is contained in:
committed by
Álison Fernandes
parent
67fd9d30b6
commit
cd204b9b11
@@ -0,0 +1,10 @@
|
||||
package com.x8bit.bitwarden
|
||||
|
||||
import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
/**
|
||||
* Custom application class.
|
||||
*/
|
||||
@HiltAndroidApp
|
||||
class BitwardenApplication : Application()
|
||||
35
app/src/main/java/com/x8bit/bitwarden/MainActivity.kt
Normal file
35
app/src/main/java/com/x8bit/bitwarden/MainActivity.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.x8bit.bitwarden
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.x8bit.bitwarden.ui.theme.BitwardenTheme
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
* Primary entry point for the application.
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
BitwardenTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.app_name),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
74
app/src/main/java/com/x8bit/bitwarden/ui/theme/Theme.kt
Normal file
74
app/src/main/java/com/x8bit/bitwarden/ui/theme/Theme.kt
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.x8bit.bitwarden.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.R.color
|
||||
|
||||
/**
|
||||
* The overall application theme. This can be configured to support a [darkTheme] and
|
||||
* [dynamicColor].
|
||||
*/
|
||||
@Composable
|
||||
fun BitwardenTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
dynamicColor: Boolean = false,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
// Get the current scheme
|
||||
val context = LocalContext.current
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
darkTheme -> darkColorScheme(context)
|
||||
else -> lightColorScheme(context)
|
||||
}
|
||||
|
||||
// Update status bar according to scheme
|
||||
val view = LocalView.current
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = colorScheme.primary.toArgb()
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
|
||||
}
|
||||
}
|
||||
|
||||
// Set overall theme based on color scheme and typography settings
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
private fun darkColorScheme(context: Context): ColorScheme =
|
||||
darkColorScheme(
|
||||
primary = Color(context.getColor(color.dark_primary)),
|
||||
secondary = Color(context.getColor(R.color.dark_primary)),
|
||||
tertiary = Color(context.getColor(R.color.dark_primary)),
|
||||
)
|
||||
|
||||
private fun lightColorScheme(context: Context): ColorScheme =
|
||||
lightColorScheme(
|
||||
primary = Color(context.getColor(color.primary)),
|
||||
secondary = Color(context.getColor(R.color.primary)),
|
||||
tertiary = Color(context.getColor(R.color.primary)),
|
||||
)
|
||||
17
app/src/main/java/com/x8bit/bitwarden/ui/theme/Type.kt
Normal file
17
app/src/main/java/com/x8bit/bitwarden/ui/theme/Type.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.x8bit.bitwarden.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
val Typography: Typography = Typography(
|
||||
bodyLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp,
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user