Merge branch 'devel'

master v1.2.1
yattoz 2022-03-13 18:13:06 +09:00
commit 24edc08bbf
14 changed files with 125 additions and 57 deletions

View File

@ -7,6 +7,7 @@
<option name="testRunner" value="GRADLE" /> <option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Android Studio default JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -26,5 +26,10 @@
<option name="name" value="Google" /> <option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" /> <option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
</component> </component>
</project> </project>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -16,21 +16,21 @@ configurations.all {
} }
android { android {
compileSdkVersion 30 compileSdkVersion 32
buildToolsVersion "30.0.1"
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_11
} }
kotlinOptions { kotlinOptions {
jvmTarget = "1.8" jvmTarget = "11"
} }
defaultConfig { defaultConfig {
applicationId "fr.forum_thalie.tsumugi" applicationId "fr.forum_thalie.tsumugi"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 30 targetSdkVersion 32
versionCode 120 multiDexEnabled true
versionName "1.2.0" versionCode 121
versionName "1.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }
@ -48,6 +48,9 @@ android {
} }
dependencies { dependencies {
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
/* /*
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
@ -68,15 +71,18 @@ dependencies {
*/ */
implementation "androidx.media:media:1.1.0" implementation "androidx.media:media:1.5.0"
//noinspection GradleDependency
implementation 'com.google.android.exoplayer:exoplayer:2.11.3' implementation 'com.google.android.exoplayer:exoplayer:2.11.3'
//implementation project(':exoplayer-library') // uses local ExoPlayer clone, from dev-v2 branch (fixes ISO-8859-1 ICY metadata //implementation project(':exoplayer-library') // uses local ExoPlayer clone, from dev-v2 branch (fixes ISO-8859-1 ICY metadata
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.preference:preference-ktx:1.2.0'
// jsoup HTML parser library @ https://jsoup.org/ // jsoup HTML parser library @ https://jsoup.org/
// implementation 'org.jsoup:jsoup:1.12.1' // implementation 'org.jsoup:jsoup:1.12.1'

View File

@ -10,7 +10,8 @@
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- needed for API 28 --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- needed for API 28 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_ALARM"/> <uses-permission android:name="android.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
@ -22,8 +23,8 @@
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme.Launcher" android:theme="@style/AppTheme.Launcher"
tools:ignore="AllowBackup,GoogleAppIndexingWarning"> tools:ignore="AllowBackup,GoogleAppIndexingWarning"
android:name="androidx.multidex.MultiDexApplication">
<service <service
android:name=".RadioService" android:name=".RadioService"
android:enabled="true" android:enabled="true"
@ -35,7 +36,8 @@
<receiver android:name=".BootBroadcastReceiver" <receiver android:name=".BootBroadcastReceiver"
android:directBootAware="true" android:directBootAware="true"
tools:targetApi="n"> tools:targetApi="n"
android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="fr.forum_thalie.tsumugi.PLAY_OR_FALLBACK" /> <action android:name="fr.forum_thalie.tsumugi.PLAY_OR_FALLBACK" />
@ -47,9 +49,9 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="fullUser"> android:screenOrientation="fullUser"
android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -63,7 +65,8 @@
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:screenOrientation="fullUser" /> android:screenOrientation="fullUser" />
<receiver android:name="androidx.media.session.MediaButtonReceiver"> <receiver android:name="androidx.media.session.MediaButtonReceiver"
android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter> </intent-filter>

View File

@ -7,15 +7,33 @@
"hour_end": "7:00" "hour_end": "7:00"
}, },
{ {
"title": "Jeux Vidéos Matin", "title": "Tsumugi Rétro",
"periodicity": "1111100", "periodicity": "1000000",
"hour_begin": "09:00", "hour_begin": "09:00",
"hour_end": "10:30" "hour_end": "12:00"
}, },
{ {
"title": "Anime Matin", "title": "Tournant du Millénaire",
"periodicity": "1111100", "periodicity": "0100000",
"hour_begin": "10:30", "hour_begin": "09:00",
"hour_end": "12:00"
},
{
"title": "Tsumugi Netpop",
"periodicity": "0010000",
"hour_begin": "09:00",
"hour_end": "12:00"
},
{
"title": "Tsumugi Moderne",
"periodicity": "0001000",
"hour_begin": "09:00",
"hour_end": "12:00"
},
{
"title": "Tsumugi Très Récent",
"periodicity": "0000100",
"hour_begin": "09:00",
"hour_end": "12:00" "hour_end": "12:00"
}, },
{ {

View File

@ -50,6 +50,7 @@ abstract class BaseNotification(private val notificationChannelId: String,
notificationManager.notify(notificationId, notification) notificationManager.notify(notificationId, notification)
} }
@RequiresApi(Build.VERSION_CODES.M)
open fun create(c: Context) { open fun create(c: Context) {
notificationManager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
@ -58,7 +59,7 @@ abstract class BaseNotification(private val notificationChannelId: String,
// thanks to the launchMode specified in the Manifest : android:launchMode="singleTop" // thanks to the launchMode specified in the Manifest : android:launchMode="singleTop"
val pendingIntent = PendingIntent.getActivity( val pendingIntent = PendingIntent.getActivity(
c, 0, c, 0,
notificationIntent, 0 notificationIntent, PendingIntent.FLAG_IMMUTABLE
) )
var channelID = "" var channelID = ""

View File

@ -3,8 +3,10 @@ package fr.forum_thalie.tsumugi
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat import android.support.v4.media.session.PlaybackStateCompat
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import fr.forum_thalie.tsumugi.playerstore.PlayerStore import fr.forum_thalie.tsumugi.playerstore.PlayerStore
@ -34,7 +36,7 @@ class NowPlayingNotification(
// got it right // got it right
val delIntent = Intent(c, RadioService::class.java) val delIntent = Intent(c, RadioService::class.java)
delIntent.putExtra("action", Actions.KILL.name) delIntent.putExtra("action", Actions.KILL.name)
val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE) val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE + PendingIntent.FLAG_IMMUTABLE)
builder.setDeleteIntent(deleteIntent) builder.setDeleteIntent(deleteIntent)
mediaStyle = androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().also { mediaStyle = androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().also {
@ -46,6 +48,7 @@ class NowPlayingNotification(
update(c) update(c)
} }
@RequiresApi(Build.VERSION_CODES.M)
fun update(c: Context, isUpdatingNotificationButton: Boolean = false, isRinging: Boolean = false) { fun update(c: Context, isUpdatingNotificationButton: Boolean = false, isRinging: Boolean = false) {
if (isUpdatingNotificationButton) if (isUpdatingNotificationButton)
@ -72,17 +75,17 @@ class NowPlayingNotification(
playPauseAction = if (PlayerStore.instance.playbackState.value == PlaybackStateCompat.STATE_PLAYING) { playPauseAction = if (PlayerStore.instance.playbackState.value == PlaybackStateCompat.STATE_PLAYING) {
intent.putExtra("action", Actions.PAUSE.name) intent.putExtra("action", Actions.PAUSE.name)
val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
NotificationCompat.Action.Builder(R.drawable.ic_pause, "Pause", pendingButtonIntent).build() NotificationCompat.Action.Builder(R.drawable.ic_pause, "Pause", pendingButtonIntent).build()
} else { } else {
intent.putExtra("action", Actions.PLAY.name) intent.putExtra("action", Actions.PLAY.name)
val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
NotificationCompat.Action.Builder(R.drawable.ic_play,"Play", pendingButtonIntent).build() NotificationCompat.Action.Builder(R.drawable.ic_play,"Play", pendingButtonIntent).build()
} }
builder.addAction(playPauseAction) builder.addAction(playPauseAction)
val intent2 = Intent(c, RadioService::class.java) val intent2 = Intent(c, RadioService::class.java)
intent2.putExtra("action", Actions.KILL.name) intent2.putExtra("action", Actions.KILL.name)
val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT) val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
val stopAction = NotificationCompat.Action.Builder(R.drawable.ic_close,"Stop", pendingButtonIntent).build() val stopAction = NotificationCompat.Action.Builder(R.drawable.ic_close,"Stop", pendingButtonIntent).build()
builder.addAction(stopAction) builder.addAction(stopAction)
@ -92,7 +95,7 @@ class NowPlayingNotification(
val snoozeIntent = Intent(c, RadioService::class.java) val snoozeIntent = Intent(c, RadioService::class.java)
snoozeIntent.putExtra("action", Actions.SNOOZE.name) snoozeIntent.putExtra("action", Actions.SNOOZE.name)
val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
val snoozeAction = NotificationCompat.Action.Builder(R.drawable.ic_alarm, "Snooze ($snoozeMinutes min.)", pendingSnoozeIntent ).build() val snoozeAction = NotificationCompat.Action.Builder(R.drawable.ic_alarm, "Snooze ($snoozeMinutes min.)", pendingSnoozeIntent ).build()
if (snoozeMinutes > 0) if (snoozeMinutes > 0)
builder.addAction(snoozeAction) builder.addAction(snoozeAction)

View File

@ -193,7 +193,8 @@ class RadioService : MediaBrowserServiceCompat() {
// Define managers // Define managers
telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE) // telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
//define the audioFocusRequest //define the audioFocusRequest
@ -514,6 +515,10 @@ class RadioService : MediaBrowserServiceCompat() {
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
return return
} }
if (mediaSession.controller.playbackState.state == PlaybackStateCompat.STATE_PLAYING && !isRinging && isAlarmStopped)
{
return //nothing to do here
}
PlayerStore.instance.playbackState.value = PlaybackStateCompat.STATE_PLAYING PlayerStore.instance.playbackState.value = PlaybackStateCompat.STATE_PLAYING
@ -530,6 +535,7 @@ class RadioService : MediaBrowserServiceCompat() {
} }
// START PLAYBACK, LET'S ROCK // START PLAYBACK, LET'S ROCK
player.playWhenReady = true
nowPlayingNotification.update(this, isUpdatingNotificationButton = true, isRinging = isRinging) nowPlayingNotification.update(this, isUpdatingNotificationButton = true, isRinging = isRinging)
playbackStateBuilder.setState( playbackStateBuilder.setState(
@ -539,7 +545,6 @@ class RadioService : MediaBrowserServiceCompat() {
SystemClock.elapsedRealtime() SystemClock.elapsedRealtime()
) )
mediaSession.setPlaybackState(playbackStateBuilder.build()) mediaSession.setPlaybackState(playbackStateBuilder.build())
player.playWhenReady = true
//[REMOVE LOG CALLS]Log.d(tag, radioTag + "begin playing") //[REMOVE LOG CALLS]Log.d(tag, radioTag + "begin playing")
} }

View File

@ -4,7 +4,9 @@ import android.app.AlarmManager
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.AlarmManagerCompat import androidx.core.app.AlarmManagerCompat
import fr.forum_thalie.tsumugi.BootBroadcastReceiver import fr.forum_thalie.tsumugi.BootBroadcastReceiver
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -27,13 +29,31 @@ class RadioAlarm {
{ {
alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent -> alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}") intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
PendingIntent.getBroadcast(c, 0, intent, 0) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(
c,
0,
intent,
PendingIntent.FLAG_IMMUTABLE
)
} else {
PendingIntent.getBroadcast(
c,
0,
intent,
0
)
}
} }
showIntent = Intent(c, ParametersActivity::class.java).let { intent -> showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
intent.putExtra("action", "alarm") intent.putExtra("action", "alarm")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_IMMUTABLE)
} else {
PendingIntent.getActivity(c, 0, intent, 0) PendingIntent.getActivity(c, 0, intent, 0)
} }
} }
}
fun cancelAlarm(c: Context) fun cancelAlarm(c: Context)
@ -43,6 +63,7 @@ class RadioAlarm {
alarmManager.cancel(alarmIntent) alarmManager.cancel(alarmIntent)
} }
@RequiresApi(Build.VERSION_CODES.M)
fun setNextAlarm(c: Context, isForce: Boolean = false, forceTime: Int? = null, forceDays: Set<String>? = null) fun setNextAlarm(c: Context, isForce: Boolean = false, forceTime: Int? = null, forceDays: Set<String>? = null)
{ {
defineIntents(c) defineIntents(c)
@ -54,7 +75,7 @@ class RadioAlarm {
val showIntent = Intent(c, ParametersActivity::class.java).let { intent -> val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
intent.putExtra("action", ActionOpenParam.ALARM.name) intent.putExtra("action", ActionOpenParam.ALARM.name)
PendingIntent.getActivity(c, 0, intent, 0) PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_IMMUTABLE)
} }
val time = findNextAlarmTime(c, forceTime, forceDays) val time = findNextAlarmTime(c, forceTime, forceDays)
if (time > 0) if (time > 0)

View File

@ -4,7 +4,9 @@ import android.app.AlarmManager
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.AlarmManagerCompat import androidx.core.app.AlarmManagerCompat
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -30,18 +32,20 @@ class RadioSleeper {
private lateinit var sleepIntent: PendingIntent private lateinit var sleepIntent: PendingIntent
private lateinit var fadeOutIntent: PendingIntent private lateinit var fadeOutIntent: PendingIntent
@RequiresApi(Build.VERSION_CODES.M)
private fun defineIntents(c: Context) private fun defineIntents(c: Context)
{ {
sleepIntent = Intent(c, RadioService::class.java).let { intent -> sleepIntent = Intent(c, RadioService::class.java).let { intent ->
intent.putExtra("action", Actions.KILL.name) intent.putExtra("action", Actions.KILL.name)
PendingIntent.getService(c, 99, intent, 0) PendingIntent.getService(c, 99, intent, PendingIntent.FLAG_IMMUTABLE)
} }
fadeOutIntent = Intent(c, RadioService::class.java).let { intent -> fadeOutIntent = Intent(c, RadioService::class.java).let { intent ->
intent.putExtra("action", Actions.FADE_OUT.name) intent.putExtra("action", Actions.FADE_OUT.name)
PendingIntent.getService(c, 98, intent, 0) PendingIntent.getService(c, 98, intent, PendingIntent.FLAG_IMMUTABLE)
} }
} }
@RequiresApi(Build.VERSION_CODES.M)
fun setSleep(c: Context, isForce: Boolean = false, forceDuration: Long? = null) fun setSleep(c: Context, isForce: Boolean = false, forceDuration: Long? = null)
{ {
defineIntents(c) defineIntents(c)

View File

@ -47,7 +47,7 @@ class AlarmFragment : PreferenceFragmentCompat() {
fun updateIsWakingUpSummary(preference: SwitchPreferenceCompat?, newValue: Boolean? = true, forceTime: Int? = null, forceDays: Set<String>? = null) fun updateIsWakingUpSummary(preference: SwitchPreferenceCompat?, newValue: Boolean? = true, forceTime: Int? = null, forceDays: Set<String>? = null)
{ {
val dateLong = RadioAlarm.instance.findNextAlarmTime(context!!, forceTime, forceDays) val dateLong = RadioAlarm.instance.findNextAlarmTime(requireContext(), forceTime, forceDays)
val calendar = Calendar.getInstance() val calendar = Calendar.getInstance()
calendar.timeInMillis = dateLong calendar.timeInMillis = dateLong
if (newValue == true && calendar.timeInMillis > 0) if (newValue == true && calendar.timeInMillis > 0)
@ -65,14 +65,14 @@ class AlarmFragment : PreferenceFragmentCompat() {
val hourOfDayDefault = 7 val hourOfDayDefault = 7
val minuteDefault = 0 val minuteDefault = 0
if (!PreferenceManager.getDefaultSharedPreferences(context!!).contains("alarmTimeFromMidnight")) if (!PreferenceManager.getDefaultSharedPreferences(requireContext()).contains("alarmTimeFromMidnight"))
{ {
PreferenceManager.getDefaultSharedPreferences(context!!).edit { PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
putInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault)) putInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault))
commit() commit()
} }
} }
val time = PreferenceManager.getDefaultSharedPreferences(context!!).getInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault)) val time = PreferenceManager.getDefaultSharedPreferences(requireContext()).getInt("alarmTimeFromMidnight", (60*hourOfDayDefault+minuteDefault))
val hourOfDay = time / 60 val hourOfDay = time / 60
val minute = time % 60 val minute = time % 60
timeSet?.summary = "${if (hourOfDay < 10) "0" else ""}$hourOfDay:${if (minute < 10) "0" else ""}$minute" timeSet?.summary = "${if (hourOfDay < 10) "0" else ""}$hourOfDay:${if (minute < 10) "0" else ""}$minute"
@ -80,16 +80,16 @@ class AlarmFragment : PreferenceFragmentCompat() {
timeSet?.setOnPreferenceClickListener { timeSet?.setOnPreferenceClickListener {
val timePickerOnTimeSetListener = TimePickerDialog.OnTimeSetListener { _, hourOfDay, minute -> val timePickerOnTimeSetListener = TimePickerDialog.OnTimeSetListener { _, hourOfDay, minute ->
PreferenceManager.getDefaultSharedPreferences(context!!).edit { PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
putInt("alarmTimeFromMidnight", (60*hourOfDay+minute)) putInt("alarmTimeFromMidnight", (60*hourOfDay+minute))
commit() commit()
} }
timeSet.summary = "${if (hourOfDay < 10) "0" else ""}$hourOfDay:${if (minute < 10) "0" else ""}$minute" timeSet.summary = "${if (hourOfDay < 10) "0" else ""}$hourOfDay:${if (minute < 10) "0" else ""}$minute"
RadioAlarm.instance.cancelAlarm(context!!) RadioAlarm.instance.cancelAlarm(requireContext())
RadioAlarm.instance.setNextAlarm(context!!, isForce = true, forceTime = hourOfDay*60+minute) RadioAlarm.instance.setNextAlarm(requireContext(), isForce = true, forceTime = hourOfDay*60+minute)
updateIsWakingUpSummary(isWakingUp, isWakingUp?.isChecked, forceTime = hourOfDay*60+minute) updateIsWakingUpSummary(isWakingUp, isWakingUp?.isChecked, forceTime = hourOfDay*60+minute)
} }
val timeNew = PreferenceManager.getDefaultSharedPreferences(context!!).getInt("alarmTimeFromMidnight", 7*60) val timeNew = PreferenceManager.getDefaultSharedPreferences(requireContext()).getInt("alarmTimeFromMidnight", 7*60)
val hourOfDayNew = timeNew / 60 val hourOfDayNew = timeNew / 60
val minuteNew = timeNew % 60 val minuteNew = timeNew % 60
val timePicker = TimePickerDialog(context, timePickerOnTimeSetListener, hourOfDayNew, minuteNew, true) val timePicker = TimePickerDialog(context, timePickerOnTimeSetListener, hourOfDayNew, minuteNew, true)
@ -103,8 +103,8 @@ class AlarmFragment : PreferenceFragmentCompat() {
val fullWeek = weekdays.toSet() val fullWeek = weekdays.toSet()
val workingWeek = weekdays.toSet().minusElement(weekdays.last()).minusElement(weekdays.elementAt(weekdays.size - 2)) val workingWeek = weekdays.toSet().minusElement(weekdays.last()).minusElement(weekdays.elementAt(weekdays.size - 2))
val listOfDays = when (newValue) { val listOfDays = when (newValue) {
fullWeek -> context!!.getString(R.string.every_day) fullWeek -> requireContext().getString(R.string.every_day)
workingWeek -> context!!.getString(R.string.working_days) workingWeek -> requireContext().getString(R.string.working_days)
else -> { else -> {
// build ORDERED LIST of days... I don't know why the original one is in shambles!! // build ORDERED LIST of days... I don't know why the original one is in shambles!!
val fullWeekOrdered = weekdays val fullWeekOrdered = weekdays
@ -119,12 +119,12 @@ class AlarmFragment : PreferenceFragmentCompat() {
preference?.summary = listOfDays preference?.summary = listOfDays
} }
updateDays(alarmDays, PreferenceManager.getDefaultSharedPreferences(context).getStringSet("alarmDays", setOf())) updateDays(alarmDays, PreferenceManager.getDefaultSharedPreferences(requireContext()).getStringSet("alarmDays", setOf()))
alarmDays?.setOnPreferenceChangeListener { preference, newValue -> alarmDays?.setOnPreferenceChangeListener { preference, newValue ->
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
updateDays(preference as MultiSelectListPreference, newValue as Set<String>) updateDays(preference as MultiSelectListPreference, newValue as Set<String>)
RadioAlarm.instance.cancelAlarm(context!!) RadioAlarm.instance.cancelAlarm(requireContext())
RadioAlarm.instance.setNextAlarm(context!!, isForce = true, forceDays = newValue) RadioAlarm.instance.setNextAlarm(requireContext(), isForce = true, forceDays = newValue)
updateIsWakingUpSummary(isWakingUp, isWakingUp?.isChecked, forceDays = newValue) updateIsWakingUpSummary(isWakingUp, isWakingUp?.isChecked, forceDays = newValue)
true true
} }
@ -133,9 +133,9 @@ class AlarmFragment : PreferenceFragmentCompat() {
isWakingUp?.setOnPreferenceChangeListener { _, newValue -> isWakingUp?.setOnPreferenceChangeListener { _, newValue ->
if (newValue as Boolean) if (newValue as Boolean)
RadioAlarm.instance.setNextAlarm(context!!, isForce = true) RadioAlarm.instance.setNextAlarm(requireContext(), isForce = true)
else else
RadioAlarm.instance.cancelAlarm(context!!) RadioAlarm.instance.cancelAlarm(requireContext())
timeSet?.isEnabled = newValue timeSet?.isEnabled = newValue
alarmDays?.isEnabled = newValue alarmDays?.isEnabled = newValue
snoozeDuration?.isEnabled = newValue snoozeDuration?.isEnabled = newValue

View File

@ -1,16 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.3.72' ext.kotlin_version = '1.6.10'
repositories { repositories {
google() google()
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.1' classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
} }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip