mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
build: initialize project structure
Set up Android project configuration, Gradle build scripts, typography, and default resource assets.
This commit is contained in:
1 parent
0a595f619a
commit
f13d46f778
65 files changed
+6056
-11
No files matched your search
@@ -0,0 +1,119 @@
|
||||
package com.example.notification
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.example.MainActivity
|
||||
import com.example.R
|
||||
import com.example.data.model.MealType
|
||||
import com.example.receiver.MealReminderReceiver
|
||||
import java.util.Calendar
|
||||
|
||||
object MealNotificationManager {
|
||||
|
||||
const val CHANNEL_ID = "meal_reminders_channel"
|
||||
const val CHANNEL_NAME = "Rappels de Repas"
|
||||
const val EXTRA_MEAL_TYPE = "extra_meal_type"
|
||||
const val ACTION_LOG_MEAL = "com.example.action.LOG_MEAL"
|
||||
|
||||
fun createNotificationChannel(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val importance = NotificationManager.IMPORTANCE_DEFAULT
|
||||
val channel = NotificationChannel(
|
||||
CHANNEL_ID,
|
||||
CHANNEL_NAME,
|
||||
importance
|
||||
).apply {
|
||||
description = "Rappels personnalisés pour noter vos sensations de faim et satiété à table."
|
||||
enableVibration(true)
|
||||
}
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
|
||||
fun showMealNotification(context: Context, mealType: MealType) {
|
||||
createNotificationChannel(context)
|
||||
|
||||
val intent = Intent(context, MainActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
action = ACTION_LOG_MEAL
|
||||
putExtra(EXTRA_MEAL_TYPE, mealType.name)
|
||||
}
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
mealType.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||
)
|
||||
|
||||
val (title, body) = when (mealType) {
|
||||
MealType.BREAKFAST -> Pair("C'est l'heure du petit-déjeuner ☀️", "Prenez 15 secondes pour évaluer votre faim et immortaliser votre assiette.")
|
||||
MealType.LUNCH -> Pair("Pause déjeuner bien méritée 🥗", "Comment est votre faim ? Prenez le temps de savourer et notez vos sensations.")
|
||||
MealType.SNACK -> Pair("Moment de la collation 🍎", "Envie gourmande ou vrai besoin énergétique ? Notez votre ressenti sur Satiéa.")
|
||||
MealType.DINNER -> Pair("C'est l'heure du dîner 🌙", "Terminez votre journée en douceur en notant votre niveau de faim et votre assiette.")
|
||||
}
|
||||
|
||||
val notification = NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentTitle(title)
|
||||
.setContentText(body)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(body))
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent)
|
||||
.addAction(
|
||||
R.mipmap.ic_launcher,
|
||||
"Noter mon repas",
|
||||
pendingIntent
|
||||
)
|
||||
.build()
|
||||
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(mealType.ordinal + 100, notification)
|
||||
}
|
||||
|
||||
fun scheduleDailyReminder(context: Context, mealType: MealType, hour: Int, minute: Int, enabled: Boolean) {
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager ?: return
|
||||
|
||||
val intent = Intent(context, MealReminderReceiver::class.java).apply {
|
||||
putExtra(EXTRA_MEAL_TYPE, mealType.name)
|
||||
}
|
||||
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
mealType.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0)
|
||||
)
|
||||
|
||||
if (!enabled) {
|
||||
alarmManager.cancel(pendingIntent)
|
||||
return
|
||||
}
|
||||
|
||||
val calendar = Calendar.getInstance().apply {
|
||||
timeInMillis = System.currentTimeMillis()
|
||||
set(Calendar.HOUR_OF_DAY, hour)
|
||||
set(Calendar.MINUTE, minute)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
if (timeInMillis <= System.currentTimeMillis()) {
|
||||
add(Calendar.DAY_OF_YEAR, 1)
|
||||
}
|
||||
}
|
||||
|
||||
alarmManager.setInexactRepeating(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
calendar.timeInMillis,
|
||||
AlarmManager.INTERVAL_DAY,
|
||||
pendingIntent
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user