Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pending Bugs #46

Merged
merged 5 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

5 changes: 2 additions & 3 deletions .idea/gradle.xml

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

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ object AppModule {

@OptIn(
ExperimentalMaterialNavigationApi::class,
androidx.compose.animation.ExperimentalAnimationApi::class,
kotlinx.coroutines.InternalCoroutinesApi::class,
androidx.compose.ui.ExperimentalComposeUiApi::class,
androidx.compose.material.ExperimentalMaterialApi::class,
androidx.compose.foundation.ExperimentalFoundationApi::class
ExperimentalAnimationApi::class,
InternalCoroutinesApi::class,
ExperimentalComposeUiApi::class,
ExperimentalMaterialApi::class,
ExperimentalFoundationApi::class
)
@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface AudioPlayer {

class PlayerWrapper(
// val resources: Resources,
val context: Context
val context: Context,
) : AudioPlayer {
override fun setDataSource(alarmtone: Uri) {
// Fall back on the default alarm if the database does not have an
Expand Down Expand Up @@ -53,7 +53,7 @@ class PlayerWrapper(
AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_ALARM)
.build()
.build(),
)
prepare()
isLooping = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import timber.log.Timber
@InternalCoroutinesApi
@ExperimentalAnimationApi
@ExperimentalMaterialNavigationApi
internal class NotificationInteractorImpl constructor(
internal class NotificationInteractorImpl(
private val alarmNotification: MathAlarmNotification,
) : NotificationInteractor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import com.timilehinaregbesola.mathalarm.presentation.alarmsettings.components.A
import com.timilehinaregbesola.mathalarm.presentation.appsettings.AlarmPreferencesImpl
import com.timilehinaregbesola.mathalarm.presentation.appsettings.components.AppSettingsScreen
import com.timilehinaregbesola.mathalarm.presentation.appsettings.shouldUseDarkColors
import com.timilehinaregbesola.mathalarm.utils.Navigation
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_ALARM_LIST
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_ALARM_MATH
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_ALARM_MATH_ARGUMENT
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_ALARM_MATH_URI
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_APP_SETTINGS
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_SETTINGS_SHEET
import com.timilehinaregbesola.mathalarm.utils.Navigation.NAV_SETTINGS_SHEET_ARGUMENT
import kotlinx.coroutines.InternalCoroutinesApi

@ExperimentalMaterialNavigationApi
Expand All @@ -46,9 +52,9 @@ fun NavGraph(preferences: AlarmPreferencesImpl) {
bottomSheetNavigator = bottomSheetNavigator,
sheetShape = RoundedCornerShape(topStart = 40.dp, topEnd = 40.dp),
) {
AnimatedNavHost(navController = navController, startDestination = Navigation.NAV_ALARM_LIST) {
AnimatedNavHost(navController = navController, startDestination = NAV_ALARM_LIST) {
composable(
route = Navigation.NAV_ALARM_LIST,
route = NAV_ALARM_LIST,
enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Right,
Expand All @@ -68,8 +74,8 @@ fun NavGraph(preferences: AlarmPreferencesImpl) {
)
}
composable(
route = Navigation.NAV_ALARM_MATH,
deepLinks = listOf(navDeepLink { uriPattern = Navigation.NAV_ALARM_MATH_URI }),
route = NAV_ALARM_MATH,
deepLinks = listOf(navDeepLink { uriPattern = NAV_ALARM_MATH_URI }),
enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Right,
Expand All @@ -83,7 +89,7 @@ fun NavGraph(preferences: AlarmPreferencesImpl) {
)
},
) {
val alarmJson = it.arguments?.getString(Navigation.NAV_ALARM_MATH_ARGUMENT)
val alarmJson = it.arguments?.getString(NAV_ALARM_MATH_ARGUMENT)
val moshi = Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build()
val jsonAdapter = moshi.adapter(AlarmEntity::class.java).lenient()
val alarmObject = alarmJson?.let { it1 -> jsonAdapter.fromJson(it1) }
Expand All @@ -94,7 +100,7 @@ fun NavGraph(preferences: AlarmPreferencesImpl) {
)
}
composable(
route = Navigation.NAV_APP_SETTINGS,
route = NAV_APP_SETTINGS,
enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Right,
Expand All @@ -114,9 +120,9 @@ fun NavGraph(preferences: AlarmPreferencesImpl) {
)
}
bottomSheet(
route = Navigation.NAV_SETTINGS_SHEET,
route = NAV_SETTINGS_SHEET,
) { backStackEntry ->
val alarmJson = backStackEntry.arguments?.getString(Navigation.NAV_SETTINGS_SHEET_ARGUMENT)
val alarmJson = backStackEntry.arguments?.getString(NAV_SETTINGS_SHEET_ARGUMENT)
val moshi = Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build()
val jsonAdapter = moshi.adapter(AlarmEntity::class.java).lenient()
val alarmObject = alarmJson?.let { jsonAdapter.fromJson(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.timilehinaregbesola.mathalarm.notification

import android.app.PendingIntent
import android.app.PendingIntent.FLAG_MUTABLE
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.content.Context
import android.content.Intent
import android.os.Build
Expand Down Expand Up @@ -50,7 +52,7 @@ class AlarmNotificationScheduler(private val context: Context) {
passedAlarm.repeatDays = sb.toString()
}
}
(SUN..SAT).forEach { i ->
for (i in SUN..SAT) {
if (passedAlarm.repeatDays[i] == 'T') {
val daysUntilAlarm: Int
val cal = passedAlarm.initCalendar()
Expand All @@ -71,8 +73,6 @@ class AlarmNotificationScheduler(private val context: Context) {
cal.add(Calendar.DAY_OF_YEAR, daysUntilAlarm)
Timber.d("days until alarm: $daysUntilAlarm")
}
// val stringId: StringBuilder = StringBuilder().append(i)
// .append(passedAlarm.hour).append(passedAlarm.minute)
val stringId: StringBuilder = StringBuilder().append(passedAlarm.alarmId).append(i)
.append(passedAlarm.hour).append(passedAlarm.minute)
val id = stringId.toString().split("-").joinToString("")
Expand All @@ -81,24 +81,33 @@ class AlarmNotificationScheduler(private val context: Context) {
// check if a previous alarm has been set
val isSet = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.getBroadcast(
context, intentId, alarmIntent, PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_MUTABLE
context,
intentId,
alarmIntent,
PendingIntent.FLAG_NO_CREATE or FLAG_MUTABLE,
)
} else {
PendingIntent.getBroadcast(context, intentId, alarmIntent, PendingIntent.FLAG_NO_CREATE)
}
if (isSet != null) {
if (!reschedule) {
// context.showToast(R.string.alarm_duplicate_toast_text)
// context.showToast(R.string.alarm_duplicate_toast_text)
}
return false
}
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.getBroadcast(
context, intentId, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE
context,
intentId,
alarmIntent,
PendingIntent.FLAG_CANCEL_CURRENT or FLAG_MUTABLE,
)
} else {
PendingIntent.getBroadcast(
context, intentId, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT
context,
intentId,
alarmIntent,
PendingIntent.FLAG_CANCEL_CURRENT,
)
}
alarmIntentList.add(pendingIntent)
Expand Down Expand Up @@ -131,13 +140,17 @@ class AlarmNotificationScheduler(private val context: Context) {
val intentId = id.toInt()
val cancelPendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.getBroadcast(
context, intentId, receiverIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
context,
intentId,
receiverIntent,
FLAG_UPDATE_CURRENT or FLAG_MUTABLE,
)
} else {
PendingIntent.getBroadcast(
context, intentId, receiverIntent,
PendingIntent.FLAG_UPDATE_CURRENT
context,
intentId,
receiverIntent,
FLAG_UPDATE_CURRENT,
)
}
context.cancelAlarm(cancelPendingIntent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.timilehinaregbesola.mathalarm.presentation.alarmlist

import androidx.lifecycle.*
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.timilehinaregbesola.mathalarm.domain.model.Alarm
import com.timilehinaregbesola.mathalarm.framework.Usecases
import com.timilehinaregbesola.mathalarm.framework.app.permission.AlarmPermission
import com.timilehinaregbesola.mathalarm.provider.CalendarProvider
import com.timilehinaregbesola.mathalarm.utils.UiEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.* // ktlint-disable no-wildcard-imports
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.*
import javax.inject.Inject

@HiltViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
package com.timilehinaregbesola.mathalarm.presentation.alarmlist.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.size
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.timilehinaregbesola.mathalarm.R
import com.timilehinaregbesola.mathalarm.presentation.alarmlist.components.AddAlarmFab.FabBackgroundColor
import com.timilehinaregbesola.mathalarm.presentation.alarmlist.components.AddAlarmFab.FabImageSize

@ExperimentalMaterialApi
@Composable
fun AddAlarmFab(
modifier: Modifier = Modifier,
fabImage: Painter,
onClick: () -> Unit
onClick: () -> Unit,
) {
FloatingActionButton(
modifier = modifier,
onClick = onClick,
backgroundColor = Color(0x482FF7),
backgroundColor = Color(FabBackgroundColor),
) {
Image(
modifier = Modifier
.width(72.dp)
.height(75.dp),
.size(FabImageSize),
painter = fabImage,
contentDescription = null
contentDescription = null,
)
}
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
@Preview
private fun AddAlarmFabPreview() {
MaterialTheme {
AddAlarmFab(fabImage = painterResource(id = R.drawable.fabb)) {}
}
}

private object AddAlarmFab {
const val FabBackgroundColor = 0x482FF7
val FabImageSize = 72.dp
}
Loading