Skip to content

Commit

Permalink
Add a development only config for now to enable vazir
Browse files Browse the repository at this point in the history
We should see how we can integrate it into our widgets
  • Loading branch information
ebraminio committed May 6, 2024
1 parent 24ae391 commit b3dc392
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const val PREF_SYSTEM_DARK_THEME = "SystemDarkTheme"
const val PREF_SYSTEM_LIGHT_THEME = "SystemLightTheme"
const val PREF_THEME_GRADIENT = "ThemeGradient"
const val PREF_RED_HOLIDAYS = "RedHolidays"
const val PREF_VAZIR_ENABLED = "VazirEnabled"
const val PREF_HOLIDAY_TYPES = "holiday_types"
const val PREF_WEEK_START = "WeekStart"
const val PREF_WEEK_ENDS = "WeekEnds"
Expand Down Expand Up @@ -87,6 +88,7 @@ const val DEFAULT_ISLAMIC_OFFSET = "0"
const val DEFAULT_SECONDARY_CALENDAR_IN_TABLE = false
const val DEFAULT_THEME_GRADIENT = true
const val DEFAULT_RED_HOLIDAYS = false
const val DEFAULT_VAZIR_ENABLED = false
const val DEFAULT_WALLPAPER_DARK = true
const val DEFAULT_WALLPAPER_AUTOMATIC = false
const val DEFAULT_DREAM_NOISE = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.byagowi.persiancalendar.DEFAULT_PRAY_TIME_METHOD
import com.byagowi.persiancalendar.DEFAULT_RED_HOLIDAYS
import com.byagowi.persiancalendar.DEFAULT_SECONDARY_CALENDAR_IN_TABLE
import com.byagowi.persiancalendar.DEFAULT_THEME_GRADIENT
import com.byagowi.persiancalendar.DEFAULT_VAZIR_ENABLED
import com.byagowi.persiancalendar.DEFAULT_WALLPAPER_AUTOMATIC
import com.byagowi.persiancalendar.DEFAULT_WALLPAPER_DARK
import com.byagowi.persiancalendar.DEFAULT_WIDGET_CLOCK
Expand Down Expand Up @@ -66,6 +67,7 @@ import com.byagowi.persiancalendar.PREF_SYSTEM_DARK_THEME
import com.byagowi.persiancalendar.PREF_SYSTEM_LIGHT_THEME
import com.byagowi.persiancalendar.PREF_THEME
import com.byagowi.persiancalendar.PREF_THEME_GRADIENT
import com.byagowi.persiancalendar.PREF_VAZIR_ENABLED
import com.byagowi.persiancalendar.PREF_WALLPAPER_AUTOMATIC
import com.byagowi.persiancalendar.PREF_WALLPAPER_DARK
import com.byagowi.persiancalendar.PREF_WEEK_ENDS
Expand Down Expand Up @@ -182,6 +184,10 @@ val isGradient: StateFlow<Boolean> get() = isGradient_
private val isRedHolidays_ = MutableStateFlow(DEFAULT_RED_HOLIDAYS)
val isRedHolidays: StateFlow<Boolean> get() = isRedHolidays_


private val isVazirEnabled_ = MutableStateFlow(DEFAULT_VAZIR_ENABLED)
val isVazirEnabled: StateFlow<Boolean> get() = isVazirEnabled_

private var alternativeGregorianMonths = false

private val coordinates_ = MutableStateFlow<Coordinates?>(null)
Expand Down Expand Up @@ -358,6 +364,7 @@ fun updateStoredPreference(context: Context) {
} ?: Theme.LIGHT
isGradient_.value = preferences.getBoolean(PREF_THEME_GRADIENT, DEFAULT_THEME_GRADIENT)
isRedHolidays_.value = preferences.getBoolean(PREF_RED_HOLIDAYS, DEFAULT_RED_HOLIDAYS)
isVazirEnabled_.value = preferences.getBoolean(PREF_VAZIR_ENABLED, DEFAULT_VAZIR_ENABLED)
alternativeGregorianMonths = when {
language.isPersian -> preferences.getBoolean(
PREF_ENGLISH_GREGORIAN_PERSIAN_MONTHS, DEFAULT_ENGLISH_GREGORIAN_PERSIAN_MONTHS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ import androidx.compose.ui.semantics.invisibleToUser
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.core.content.edit
import com.byagowi.persiancalendar.BuildConfig
import com.byagowi.persiancalendar.PREF_RED_HOLIDAYS
import com.byagowi.persiancalendar.PREF_SYSTEM_DARK_THEME
import com.byagowi.persiancalendar.PREF_SYSTEM_LIGHT_THEME
import com.byagowi.persiancalendar.PREF_THEME
import com.byagowi.persiancalendar.PREF_THEME_GRADIENT
import com.byagowi.persiancalendar.PREF_VAZIR_ENABLED
import com.byagowi.persiancalendar.R
import com.byagowi.persiancalendar.global.isGradient
import com.byagowi.persiancalendar.global.isRedHolidays
import com.byagowi.persiancalendar.global.isVazirEnabled
import com.byagowi.persiancalendar.global.language
import com.byagowi.persiancalendar.global.systemDarkTheme
import com.byagowi.persiancalendar.global.systemLightTheme
import com.byagowi.persiancalendar.global.theme
Expand Down Expand Up @@ -152,5 +156,16 @@ fun ThemeDialog(onDismissRequest: () -> Unit) {
checked = isRedHolidays,
) { context.preferences.edit { putBoolean(PREF_RED_HOLIDAYS, !isRedHolidays) } }
}
val language by language.collectAsState()
AnimatedVisibility(
visible = showMore && BuildConfig.DEVELOPMENT && language.isArabicScript,
modifier = Modifier.padding(horizontal = 24.dp),
) {
val isVazirEnabled by isVazirEnabled.collectAsState()
SwitchWithLabel(
label = "وزیر",
checked = isVazirEnabled,
) { context.preferences.edit { putBoolean(PREF_VAZIR_ENABLED, !isVazirEnabled) } }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.TopAppBarColors
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.Typography
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable
Expand All @@ -39,12 +40,16 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.LayoutDirection
import androidx.core.content.ContextCompat
import androidx.core.text.layoutDirection
import com.byagowi.persiancalendar.BuildConfig
import com.byagowi.persiancalendar.R
import com.byagowi.persiancalendar.global.isGradient
import com.byagowi.persiancalendar.global.isRedHolidays
import com.byagowi.persiancalendar.global.isVazirEnabled
import com.byagowi.persiancalendar.global.language
import com.byagowi.persiancalendar.global.systemDarkTheme
import com.byagowi.persiancalendar.global.systemLightTheme
Expand All @@ -58,14 +63,39 @@ import com.byagowi.persiancalendar.variants.debugAssertNotNull

@Composable
fun AppTheme(content: @Composable () -> Unit) {
MaterialTheme(colorScheme = appColorScheme()) {
val isVazirEnabled by isVazirEnabled.collectAsState()
val language by language.collectAsState()
val typography = if (isVazirEnabled && BuildConfig.DEVELOPMENT && language.isArabicScript) {
val font = FontFamily(Font(R.font.vazirmatn))
Typography(
displayLarge = MaterialTheme.typography.displayLarge.copy(fontFamily = font),
displayMedium = MaterialTheme.typography.displayMedium.copy(fontFamily = font),
displaySmall = MaterialTheme.typography.displaySmall.copy(fontFamily = font),

headlineLarge = MaterialTheme.typography.headlineLarge.copy(fontFamily = font),
headlineMedium = MaterialTheme.typography.headlineMedium.copy(fontFamily = font),
headlineSmall = MaterialTheme.typography.headlineSmall.copy(fontFamily = font),

titleLarge = MaterialTheme.typography.titleLarge.copy(fontFamily = font),
titleMedium = MaterialTheme.typography.titleMedium.copy(fontFamily = font),
titleSmall = MaterialTheme.typography.titleSmall.copy(fontFamily = font),

bodyLarge = MaterialTheme.typography.bodyLarge.copy(fontFamily = font),
bodyMedium = MaterialTheme.typography.bodyMedium.copy(fontFamily = font),
bodySmall = MaterialTheme.typography.bodySmall.copy(fontFamily = font),

labelLarge = MaterialTheme.typography.labelLarge.copy(fontFamily = font),
labelMedium = MaterialTheme.typography.labelMedium.copy(fontFamily = font),
labelSmall = MaterialTheme.typography.labelSmall.copy(fontFamily = font)
)
} else MaterialTheme.typography
MaterialTheme(colorScheme = appColorScheme(), typography = typography) {
val contentColor by animateColorAsState(
MaterialTheme.colorScheme.onBackground,
animationSpec = appColorAnimationSpec,
label = "content color"
)

val language by language.collectAsState()
val isRtl =
language.isLessKnownRtl || language.asSystemLocale().layoutDirection == View.LAYOUT_DIRECTION_RTL
CompositionLocalProvider(
Expand Down
Binary file added PersianCalendar/src/main/res/font/vazirmatn.ttf
Binary file not shown.

0 comments on commit b3dc392

Please sign in to comment.