Skip to content

Commit

Permalink
2.0-draft19 (1493) - Update Project
Browse files Browse the repository at this point in the history
- Updated dependencies to latest.
  • Loading branch information
ZoeMeow1027 committed Jul 1, 2024
1 parent eb895a0 commit 655a352
Show file tree
Hide file tree
Showing 26 changed files with 745 additions and 661 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
applicationId "io.zoemeow.dutschedule"
minSdk 21
targetSdkVersion 34
versionCode 1467
versionCode 1493
versionName "2.0-draft19"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -63,8 +63,8 @@ dependencies {
implementation platform('androidx.compose:compose-bom:2024.06.00')
implementation 'androidx.compose.ui:ui-graphics'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation platform('androidx.compose:compose-bom:2024.06.00')
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.6.8"
androidTestImplementation platform('androidx.compose:compose-bom:2024.06.00')
Expand All @@ -82,7 +82,7 @@ dependencies {
runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.2'

// https://mvnrepository.com/artifact/androidx.fragment/fragment-ktx
runtimeOnly 'androidx.fragment:fragment-ktx:1.8.0'
runtimeOnly 'androidx.fragment:fragment-ktx:1.8.1'

// https://mvnrepository.com/artifact/androidx.compose.material3/material3
implementation 'androidx.compose.material3:material3:1.2.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.os.StrictMode
import android.window.SplashScreen
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
Expand All @@ -15,18 +14,15 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.Image
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.graphics.Color
Expand All @@ -36,7 +32,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.SoftwareKeyboardController
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.compose.viewModel
Expand Down Expand Up @@ -181,9 +176,9 @@ abstract class BaseActivity: ComponentActivity() {
return mainViewModel
}

fun getControlBackgroundAlpha(): Float {
fun getBackgroundAlpha(): Float {
return when (mainViewModel.appSettings.value.backgroundImage != BackgroundImageOption.None) {
true -> mainViewModel.appSettings.value.componentOpacity
true -> mainViewModel.appSettings.value.backgroundImageOpacity
false -> 1f
// true -> return mainViewModel.appSettings.value.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class HelpActivity : BaseActivity() {
.padding(bottom = 7.dp)
.clickable { clearAllFocusAndHideKeyboard() },
color = MaterialTheme.colorScheme.secondaryContainer.copy(
alpha = getControlBackgroundAlpha()
alpha = getBackgroundAlpha()
),
shape = RoundedCornerShape(7.dp),
content = {
Expand Down Expand Up @@ -190,7 +190,7 @@ class HelpActivity : BaseActivity() {
HelpLinkClickable(
item = item,
modifier = Modifier.fillMaxWidth().padding(bottom = 7.dp),
opacity = getControlBackgroundAlpha(),
opacity = getBackgroundAlpha(),
linkClicked = {
clearAllFocusAndHideKeyboard()
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class PermissionsActivity : BaseActivity() {
bottomBar = {
BottomAppBar(
containerColor = BottomAppBarDefaults.containerColor.copy(
alpha = getControlBackgroundAlpha()
alpha = getBackgroundAlpha()
),
floatingActionButton = {
ExtendedFloatingActionButton(
Expand Down Expand Up @@ -164,7 +164,7 @@ class PermissionsActivity : BaseActivity() {
isRequired = false,
isGranted = item.isGranted,
padding = PaddingValues(bottom = 10.dp),
opacity = getControlBackgroundAlpha(),
opacity = getBackgroundAlpha(),
clicked = {
permissionRequest?.let {
if (item.isGranted) {
Expand Down
194 changes: 180 additions & 14 deletions app/src/main/java/io/zoemeow/dutschedule/activity/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package io.zoemeow.dutschedule.activity

import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import dagger.hilt.android.AndroidEntryPoint
import io.zoemeow.dutschedule.R
import io.zoemeow.dutschedule.model.settings.BackgroundImageOption
import io.zoemeow.dutschedule.ui.view.settings.ExperimentSettings
import io.zoemeow.dutschedule.ui.view.settings.LanguageSettings
import io.zoemeow.dutschedule.ui.view.settings.MainView
import io.zoemeow.dutschedule.ui.view.settings.NewsNotificationSettings
import io.zoemeow.dutschedule.ui.view.settings.ParseNewsSubjectNotification
import io.zoemeow.dutschedule.ui.view.settings.Activity_Settings
import io.zoemeow.dutschedule.ui.view.settings.Activity_Settings_AppLanguageSettings
import io.zoemeow.dutschedule.ui.view.settings.Activity_Settings_ExperimentSettings
import io.zoemeow.dutschedule.ui.view.settings.Activity_Settings_NewsNotificationSettings
import io.zoemeow.dutschedule.ui.view.settings.Activity_Settings_ParseNewsSubjectNotification
import io.zoemeow.dutschedule.utils.BackgroundImageUtil

@AndroidEntryPoint
Expand Down Expand Up @@ -65,47 +67,211 @@ class SettingsActivity : BaseActivity() {
) {
when (intent.action) {
INTENT_PARSENEWSSUBJECTNOTIFICATION -> {
ParseNewsSubjectNotification(
Activity_Settings_ParseNewsSubjectNotification(
context = context,
snackBarHostState = snackBarHostState,
containerColor = containerColor,
contentColor = contentColor
contentColor = contentColor,
activity = this,
onBack = {
setResult(RESULT_CANCELED)
finish()
}
)
}

INTENT_EXPERIMENTSETTINGS -> {
ExperimentSettings(
Activity_Settings_ExperimentSettings(
context = context,
snackBarHostState = snackBarHostState,
containerColor = containerColor,
contentColor = contentColor
contentColor = contentColor,
activity = this,
onBack = {
setResult(RESULT_CANCELED)
finish()
}
)
}

INTENT_LANGUAGESETTINGS -> {
LanguageSettings(
Activity_Settings_AppLanguageSettings(
context = context,
snackBarHostState = snackBarHostState,
containerColor = containerColor,
contentColor = contentColor
contentColor = contentColor,
onBack = {
setResult(RESULT_CANCELED)
finish()
}
)
}

INTENT_NEWSNOTIFICATIONSETTINGS -> {
NewsNotificationSettings(
Activity_Settings_NewsNotificationSettings(
context = context,
snackBarHostState = snackBarHostState,
containerColor = containerColor,
contentColor = contentColor
contentColor = contentColor,
onBack = {
setResult(RESULT_CANCELED)
finish()
},
fetchNewsInBackgroundDuration = getMainViewModel().appSettings.value.newsBackgroundDuration,
onFetchNewsStateChanged = { duration ->
if (duration > 0) {
if (PermissionsActivity.checkPermissionScheduleExactAlarm(context).isGranted && PermissionsActivity.checkPermissionNotification(context).isGranted) {
// Fetch news in background onClick
val dataTemp = getMainViewModel().appSettings.value.clone(
fetchNewsBackgroundDuration = duration
)
getMainViewModel().appSettings.value = dataTemp
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = context.getString(
R.string.settings_newsnotify_fetchnewsinbackground_enabled,
duration
),
clearPrevious = true
)
} else {
showSnackBar(
text = context.getString(R.string.settings_newsnotify_snackbar_missingpermissions),
clearPrevious = true,
actionText = context.getString(R.string.action_grant),
action = {
Intent(context, PermissionsActivity::class.java).also { intent ->
context.startActivity(intent)
}
}
)
}
} else {
val dataTemp = getMainViewModel().appSettings.value.clone(
fetchNewsBackgroundDuration = 0
)
getMainViewModel().appSettings.value = dataTemp
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = context.getString(R.string.settings_newsnotify_fetchnewsinbackground_disabled),
clearPrevious = true
)
}
},
isNewSubjectNotificationParseEnabled = getMainViewModel().appSettings.value.newsBackgroundParseNewsSubject,
onNewSubjectNotificationParseClick = {
Intent(context, SettingsActivity::class.java).apply {
action = INTENT_PARSENEWSSUBJECTNOTIFICATION
}.also { intent -> context.startActivity(intent) }
},
isNewsGlobalEnabled = getMainViewModel().appSettings.value.newsBackgroundGlobalEnabled,
onNewsGlobalStateChanged = { enabled ->
val dataTemp = getMainViewModel().appSettings.value.clone(
newsBackgroundGlobalEnabled = enabled
)
getMainViewModel().appSettings.value = dataTemp
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = when (enabled) {
true -> context.getString(R.string.settings_newsnotify_newsglobal_enabled)
false -> context.getString(R.string.settings_newsnotify_newsglobal_disabled)
},
clearPrevious = true
)
},
isNewsSubjectEnabled = getMainViewModel().appSettings.value.newsBackgroundSubjectEnabled,
onNewsSubjectStateChanged = f@ { code ->
if (code == 1) {
showSnackBar(
text = "\"Match your subject schedule\" option is in development. Check back soon.",
clearPrevious = true
)
return@f
}

val dataTemp = getMainViewModel().appSettings.value.clone(
newsBackgroundSubjectEnabled = code
)
getMainViewModel().appSettings.value = dataTemp
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = when (code) {
-1 -> context.getString(R.string.settings_newsnotify_newssubject_notify_disabled)
0 -> context.getString(R.string.settings_newsnotify_newssubject_notify_all)
1 -> context.getString(R.string.settings_newsnotify_newssubject_notify_matchsubsch)
2 -> context.getString(R.string.settings_newsnotify_newssubject_notify_matchfilter)
// TODO: No code valid
else -> "----------"
},
clearPrevious = true
)
},
subjectFilterList = getMainViewModel().appSettings.value.newsBackgroundFilterList,
onSubjectFilterAdd = { subjectCode ->
// Add a filter
try {
getMainViewModel().appSettings.value.newsBackgroundFilterList.add(subjectCode)
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = context.getString(
R.string.settings_newsnotify_newsfilter_notify_add,
subjectCode.subjectName,
subjectCode.studentYearId,
".Nh",
subjectCode.classId
),
clearPrevious = true
)
} catch (_: Exception) { }
},
onSubjectFilterDelete = { subjectCode ->
// Delete a filter
try {
val data = subjectCode.copy()
getMainViewModel().appSettings.value.newsBackgroundFilterList.remove(subjectCode)
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = context.getString(
R.string.settings_newsnotify_newsfilter_notify_delete,
data.subjectName,
data.studentYearId,
".Nh",
data.classId
),
clearPrevious = true
)
} catch (_: Exception) { }
},
onSubjectFilterClear = {
// Delete all filters
try {
getMainViewModel().appSettings.value.newsBackgroundFilterList.clear()
getMainViewModel().saveSettings(saveSettingsOnly = true)
showSnackBar(
text = context.getString(R.string.settings_newsnotify_newsfilter_notify_deleteall),
clearPrevious = true
)
} catch (_: Exception) { }
},
opacity = getBackgroundAlpha()
)
}

else -> {
MainView(
Activity_Settings(
context = context,
snackBarHostState = snackBarHostState,
containerColor = containerColor,
contentColor = contentColor,
componentBackgroundAlpha = getBackgroundAlpha(),
mainViewModel = getMainViewModel(),
onShowSnackBar = { text, clearPrevious, actionText, action ->
showSnackBar(text = text, clearPrevious = clearPrevious, actionText = actionText, action = action)
},
onBack = {
setResult(RESULT_CANCELED)
finish()
},
mediaRequest = {
pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
}
Expand Down
Loading

0 comments on commit 655a352

Please sign in to comment.