-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: test notify ์ฑ๊ณต * add: notify ์์ ํ์ผ ์คํ ์ด์ง * feat: workManager๋ก ๊ตฌํ * chore: modify workManager * modify: change workManager to AlarmManager it working on api 28, but not working on api 33 * chore: notify on 11 am * feat: save notification statue in datastore * modify: change mypage design * chore: modify layout * chore: modify code * chore: modify code * delete: work manager * chore: change alarm logo file to vector * chore: move code loading app version * chore: change padding * chore: separate setting alarm code at UI * chore: at 11
- Loading branch information
Showing
24 changed files
with
624 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/eatssu/android/data/repository/PreferencesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// PreferencesRepository.kt | ||
package com.eatssu.android.data.repository | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class PreferencesRepository(private val context: Context) { | ||
|
||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings") | ||
|
||
companion object { | ||
private val DAILY_NOTIFICATION_KEY = booleanPreferencesKey("daily_notification") | ||
} | ||
|
||
val dailyNotificationStatus: Flow<Boolean> = context.dataStore.data | ||
.map { preferences -> | ||
preferences[DAILY_NOTIFICATION_KEY] ?: false // Default value is false | ||
} | ||
|
||
suspend fun setDailyNotificationStatus(status: Boolean) { | ||
context.dataStore.edit { preferences -> | ||
preferences[DAILY_NOTIFICATION_KEY] = status | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/eatssu/android/data/usecase/AlarmUsecase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.eatssu.android.data.usecase | ||
|
||
import android.app.AlarmManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.eatssu.android.util.NotificationReceiver | ||
import java.util.Calendar | ||
import javax.inject.Inject | ||
|
||
class AlarmUseCase @Inject constructor(private val context: Context) { | ||
|
||
fun scheduleAlarm() { | ||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager | ||
val intent = Intent(context, NotificationReceiver::class.java) | ||
val pendingIntent = PendingIntent.getBroadcast( | ||
context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
|
||
val calendar = Calendar.getInstance().apply { | ||
set(Calendar.HOUR_OF_DAY, 11) | ||
set(Calendar.MINUTE, 0) | ||
set(Calendar.SECOND, 0) | ||
set(Calendar.MILLISECOND, 0) | ||
} | ||
|
||
if (calendar.timeInMillis <= System.currentTimeMillis()) { | ||
calendar.add(Calendar.DAY_OF_YEAR, 1) | ||
} | ||
|
||
alarmManager.setRepeating( | ||
AlarmManager.RTC_WAKEUP, calendar.timeInMillis, AlarmManager.INTERVAL_DAY, pendingIntent | ||
) | ||
} | ||
|
||
fun cancelAlarm() { | ||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager | ||
val intent = Intent(context, NotificationReceiver::class.java) | ||
val pendingIntent = PendingIntent.getBroadcast( | ||
context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
alarmManager.cancel(pendingIntent) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/eatssu/android/data/usecase/GetDailyNotificationStatusUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.eatssu.android.data.usecase | ||
|
||
import com.eatssu.android.data.repository.PreferencesRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class GetDailyNotificationStatusUseCase @Inject constructor( | ||
private val preferencesRepository: PreferencesRepository | ||
) { | ||
operator fun invoke(): Flow<Boolean> { | ||
return preferencesRepository.dailyNotificationStatus | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/eatssu/android/data/usecase/SetDailyNotificationStatusUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.eatssu.android.data.usecase | ||
|
||
import com.eatssu.android.data.repository.PreferencesRepository | ||
import javax.inject.Inject | ||
|
||
|
||
class SetDailyNotificationStatusUseCase @Inject constructor( | ||
private val preferencesRepository: PreferencesRepository | ||
) { | ||
suspend operator fun invoke(status: Boolean) { | ||
preferencesRepository.setDailyNotificationStatus(status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.eatssu.android.di | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import com.eatssu.android.data.repository.PreferencesRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideContext(application: Application): Context { | ||
return application.applicationContext | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providePreferencesRepository(@ApplicationContext context: Context): PreferencesRepository { | ||
return PreferencesRepository(context) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.