Skip to content

Commit

Permalink
Add snoozing
Browse files Browse the repository at this point in the history
  • Loading branch information
yerzhant committed Dec 24, 2020
1 parent 7825c4e commit 90a122b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
12 changes: 8 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
package="kz.azan.solat">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_label">
android:label="@string/app_label"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down Expand Up @@ -65,10 +65,14 @@
android:resource="@xml/solat_widget_info" />
</receiver>

<receiver android:name=".alarm.AlarmService">
<receiver
android:name=".alarm.AlarmService"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver android:name=".alarm.Snooze" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AlarmService : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
"android.intent.action.BOOT_COMPLETED" -> init(context)
Intent.ACTION_BOOT_COMPLETED -> init(context)
actionInit -> init(context)
actionAzan -> azan(context, intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import android.content.SharedPreferences
import android.media.Ringtone
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import kz.azan.solat.MainActivity
import kz.azan.solat.R
import kz.azan.solat.repository.SETTINGS_NAME
import kz.azan.solat.repository.SolatRepository
import java.util.*

const val AZAN_CHANNEL_ID = "azan-human"

Expand All @@ -39,6 +41,10 @@ class NotificationService(private val context: Context) {
PendingIntent.getActivity(context, 0, it, 0)
}

val snoozeIntent = Intent(context, Snooze::class.java).let {
PendingIntent.getBroadcast(context, 0, it, 0)
}

val solatRepository = SolatRepository(context)
val cityName = solatRepository.getCityName()

Expand All @@ -57,11 +63,16 @@ class NotificationService(private val context: Context) {
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(mainActivityIntent)
.setDeleteIntent(mainActivityIntent)
.setDeleteIntent(snoozeIntent)
.setAutoCancel(true)
.addAction(
R.drawable.ic_baseline_snooze_24,
context.getString(R.string.snooze).toUpperCase(Locale.ROOT),
snoozeIntent
)

azanRingtone = RingtoneManager.getRingtone(context, azanUri)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
azanRingtone?.volume = solatRepository.getAzanVolume()
}
azanRingtone?.play()
Expand Down
11 changes: 11 additions & 0 deletions android/app/src/main/kotlin/kz/azan/solat/alarm/Snooze.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kz.azan.solat.alarm

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class Snooze : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
azanRingtone?.stop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SolatRepository(private val context: Context) {
val times = solatDatabase.timesDao().findByDate(date)
solatDatabase.close()
return times
// return Times("", "04:40", "07:02", "13:01", "19:11", "22:22", "23:23")
// return Times("", "04:40", "07:02", "13:01", "19:11", "23:36", "23:23")
}

fun getCityName(): String? {
Expand Down
10 changes: 10 additions & 0 deletions android/app/src/main/res/drawable/ic_baseline_snooze_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FF2F80ED">
<path
android:fillColor="@android:color/white"
android:pathData="M7.88,3.39L6.6,1.86 2,5.71l1.29,1.53 4.59,-3.85zM22,5.72l-4.6,-3.86 -1.29,1.53 4.6,3.86L22,5.72zM12,4c-4.97,0 -9,4.03 -9,9s4.02,9 9,9c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,20c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7zM9,11h3.63L9,15.2L9,17h6v-2h-3.63L15,10.8L15,9L9,9v2z"/>
</vector>
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
<string name="isha">Иша</string>

<string name="azan">Азан</string>

<string name="snooze">Отключить</string>
</resources>

0 comments on commit 90a122b

Please sign in to comment.