Issue
I'm trying to make an app with Clean Architecture. I want to press button from my activity and start scheduler to check if week have passed.
So I have AlarmScheduler interface (which i want to pass in Domain layer) that contain only one function
interface AlarmScheduler {
fun schedule(someString: String)
}
And also I have implementation (which I want to pass in Data layer) AndroidAlarmSchedulerImpl Code looks like this:
class AndroidAlarmScheduler(
private val context: Context,
): AlarmScheduler {
private val alarmManager = context.getSystemService(AlarmManager::class.java)
@SuppressLint("ScheduleExactAlarm")
override fun schedule(someString: String) {
val intent = Intent(context, AlarmReceiver::class.java).apply {
this.putExtra(ALARM_INTENT_STRING_EXTRA, someString)
}
val calendar = Calendar.getInstance()
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
calendar.set(Calendar.HOUR_OF_DAY, 7)
calendar.set(Calendar.MINUTE, 0)
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
PendingIntent.getBroadcast(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
)
}
}
The problem is could I pass android framework logic outside presentation layer? If you know any solutions please describe it.
Solution
It's hard to give a good answer to my question and as I managed to understand you are free to do whatever you want. But I found a good example of how you can manage your project structure and also this project contain an example where you can pass your Alarm manager logic in project. Here is a link: https://github.com/tolgaprm/Mova-MovieApp/tree/main. Enjoy! If somebody will give better answer I will change the answer of question.
Answered By - RubyFlash
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.