Skip to content

Commit

Permalink
Update 2.0_r1.
Browse files Browse the repository at this point in the history
  • Loading branch information
D4rK7355608 committed Dec 14, 2022
1 parent 2e33c92 commit 5e00611
Show file tree
Hide file tree
Showing 24 changed files with 150 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Version 2.0_r1:
- Added Store Archive compatibility;
- Added Romanian language support;
- Added Russian language support;
- Added Italian language support;
- Added Indonesian language support;
- Added Hindi language support;
- Added Japanese language support;
- Added French language support;
- Added Turkish language support;
- Added German language support;
- Added Spanish language support;
- Fixed crashes;
- Fixed app doesn't start;
- Fixed notification not appear on (Android 13+);
- Under the hood improvements.

# Version 1.0_r9:
- Fixed crashes;
- Under the hood improvements.
Expand Down
26 changes: 18 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ plugins {
}
android {
compileSdk 33
namespace 'com.d4rk.musicsleeptimer.plus'
defaultConfig {
applicationId "com.d4rk.musicsleeptimer.plus"
applicationId 'com.d4rk.musicsleeptimer.plus'
minSdk 26
targetSdk 33
versionCode 14
versionName "1.0_r9"
versionCode 16
versionName '2.0_r1'
archivesBaseName = "com.d4rk.musicsleeptimer.plus-v${versionName}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
multiDexEnabled true
minifyEnabled true
shrinkResources true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
multiDexEnabled true
minifyEnabled true
shrinkResources true
debuggable true
Expand All @@ -35,12 +39,18 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
bundle {
storeArchive {
enable = false
}
}
}
dependencies {
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.12'
implementation 'com.google.firebase:firebase-analytics-ktx:21.1.0'
implementation 'com.google.firebase:firebase-perf:20.1.0'
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.3.2'
implementation 'com.google.firebase:firebase-analytics-ktx:21.2.0'
implementation 'com.google.firebase:firebase-perf:20.3.0'
implementation 'androidx.multidex:multidex:2.0.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
14 changes: 10 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.d4rk.musicsleeptimer.plus">
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:logo="@drawable/ic_launcher_foreground"
android:label="@string/app_name"
android:appCategory="audio"
android:supportsRtl="true"
android:description="@string/app_description"
android:theme="@android:style/Theme.DeviceDefault">
android:theme="@android:style/Theme.DeviceDefault"
android:appCategory="audio"
android:localeConfig="@xml/config_locales"
tools:targetApi="33">
<service
android:name=".services.SleepTileService"
android:icon="@drawable/ic_music_off"
Expand All @@ -24,6 +27,9 @@
<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true"/>
<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true"/>
</service>
<service android:name=".services.SleepAudioService"/>
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.d4rk.musicsleeptimer.plus.notifications
import android.app.Notification
import android.app.Notification.CATEGORY_EVENT
import android.app.Notification.VISIBILITY_PUBLIC
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.Action.CANCEL
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.Action.DECREMENT
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.Action.INCREMENT
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_LOW
Expand All @@ -25,7 +28,7 @@ object SleepNotification {
private val TIMEOUT_DECREMENT_MILLIS = MINUTES.toMillis(10)
private enum class Action(private val value: String) {
CANCEL("com.d4rk.musicsleeptimer.plus.action.CANCEL") {
override fun title(context: Context) = context.getText(R.string.notification_action_cancel)
override fun title(context: Context) = context.getText(android.R.string.cancel)
},
INCREMENT("com.d4rk.musicsleeptimer.plus.action.INCREMENT") {
override fun title(context: Context) = context.getString(R.string.notification_action_increment, MILLISECONDS.toMinutes(TIMEOUT_INCREMENT_MILLIS))
Expand All @@ -41,21 +44,28 @@ object SleepNotification {
fun action(context: Context, cancel: Boolean = false): Notification.Action.Builder = Notification.Action.Builder(Icon.createWithResource(context, 0), title(context), pendingIntent(context, cancel))
abstract fun title(context: Context): CharSequence?
}
private fun Context.notificationManager() = getSystemService(NotificationManager::class.java)
fun Context.notificationManager(): NotificationManager? = getSystemService(NotificationManager::class.java)
fun Context.find() = notificationManager()?.activeNotifications?.firstOrNull { it.id == R.id.notification_id }?.notification
fun Context.handle(intent: Intent?) = when (Action.parse(intent?.action)) {
Action.INCREMENT -> update(TIMEOUT_INCREMENT_MILLIS)
Action.DECREMENT -> update(-TIMEOUT_DECREMENT_MILLIS)
Action.CANCEL -> cancel()
INCREMENT -> update(TIMEOUT_INCREMENT_MILLIS)
DECREMENT -> update(-TIMEOUT_DECREMENT_MILLIS)
CANCEL -> cancel()
null -> Unit
}
fun Context.toggle() = if (find() == null) show() else cancel()
private fun Context.cancel() = notificationManager()?.cancel(R.id.notification_id) ?: Unit
private fun Context.update(timeout: Long) = find()?.let { it.`when` - currentTimeMillis() }?.let { if (it > -timeout) it + timeout else it }?.let { show(it) }
private fun Context.update(timeout: Long) = find()?.let {
it.`when` - currentTimeMillis()
}
?.let {
if (it > -timeout) it + timeout else it
}
?.let { show(it)
}
private fun Context.show(timeout: Long = TIMEOUT_INITIAL_MILLIS) {
require(timeout > 0)
val eta = currentTimeMillis() + timeout
val notification = Notification.Builder(this, getString(R.string.notification_channel_id)).setCategory(CATEGORY_EVENT).setVisibility(VISIBILITY_PUBLIC).setOnlyAlertOnce(true).setOngoing(true).setSmallIcon(R.drawable.ic_music_off).setSubText(DateFormat.getTimeInstance(SHORT).format(Date(eta))).setShowWhen(true).setWhen(eta).setUsesChronometer(true).setChronometerCountDown(true).setTimeoutAfter(timeout).setDeleteIntent(SleepAudioService.pendingIntent(this)).addAction(Action.INCREMENT.action(this).build()).addAction(Action.DECREMENT.action(this, cancel = timeout <= TIMEOUT_DECREMENT_MILLIS).build()).addAction(Action.CANCEL.action(this).build()).build()
val notification = Notification.Builder(this, getString(R.string.notification_channel_id)).setCategory(CATEGORY_EVENT).setVisibility(VISIBILITY_PUBLIC).setOnlyAlertOnce(true).setOngoing(true).setSmallIcon(R.drawable.ic_music_off).setSubText(DateFormat.getTimeInstance(SHORT).format(Date(eta))).setShowWhen(true).setWhen(eta).setUsesChronometer(true).setChronometerCountDown(true).setTimeoutAfter(timeout).setDeleteIntent(SleepAudioService.pendingIntent(this)).addAction(INCREMENT.action(this).build()).addAction(DECREMENT.action(this, cancel = timeout <= TIMEOUT_DECREMENT_MILLIS).build()).addAction(CANCEL.action(this).build()).build()
createNotificationChannel()
notificationManager()?.notify(R.id.notification_id, notification)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit.SECONDS
class SleepAudioService : android.app.IntentService("SleepAudioService") {
companion object {
private val FADE_STEP_MILLIS = SECONDS.toMillis(1)
private val RESTORE_VOLUME_MILLIS = SECONDS.toMillis(2)
private fun intent(context: Context) = Intent(context, SleepAudioService::class.java)
fun pendingIntent(context: Context): PendingIntent? = PendingIntent.getService(context, 0, intent(context), FLAG_IMMUTABLE)
}
Expand All @@ -30,7 +31,7 @@ class SleepAudioService : android.app.IntentService("SleepAudioService") {
val attributes = AudioAttributes.Builder().setUsage(USAGE_MEDIA).setContentType(CONTENT_TYPE_MUSIC).build()
val focusRequest = AudioFocusRequest.Builder(AUDIOFOCUS_GAIN).setAudioAttributes(attributes).setOnAudioFocusChangeListener {}.build()
requestAudioFocus(focusRequest)
Thread.sleep(FADE_STEP_MILLIS)
Thread.sleep(RESTORE_VOLUME_MILLIS)
setStreamVolume(STREAM_MUSIC, volumeIndex, 0)
abandonAudioFocusRequest(focusRequest)
requestTileUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import android.content.Context
import android.content.Intent
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.Q
import android.provider.Settings
import android.service.quicksettings.Tile.STATE_ACTIVE
import android.service.quicksettings.Tile.STATE_INACTIVE
import android.service.quicksettings.TileService
import com.d4rk.musicsleeptimer.plus.R
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.notificationManager
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.find
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.handle
import com.d4rk.musicsleeptimer.plus.notifications.SleepNotification.toggle
Expand All @@ -19,7 +21,10 @@ class SleepTileService : TileService() {
fun Context.requestTileUpdate() = requestListeningState(this, ComponentName(this, SleepTileService::class.java))
}
override fun onStartListening() = refreshTile()
override fun onClick() = toggle().also { refreshTile() }
override fun onClick() = when (notificationManager()?.areNotificationsEnabled()) {
true -> toggle().also { refreshTile() }
else -> requestNotificationsPermission()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
handle(intent)
requestTileUpdate()
Expand All @@ -39,4 +44,8 @@ class SleepTileService : TileService() {
}
updateTile()
} ?: Unit
private fun requestNotificationsPermission() = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
}.let(::startActivityAndCollapse)
}
6 changes: 0 additions & 6 deletions app/src/main/res/mipmap-night-anydpi/ic_launcher.xml

This file was deleted.

4 changes: 4 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Tippe, um zu starten</string>
<string name="app_description">Stellen Sie Ihre Musik so ein, dass sie nach dem Einschlafen stoppt.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Toca para empezar</string>
<string name="app_description">Configure su música para que se detenga después de quedarse dormido.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Appuyez pour commencer</string>
<string name="app_description">Réglez votre musique pour qu\'elle s\'arrête après vous être endormi.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">शरू करने के लिए टैप करें</string>
<string name="app_description">सो जाने के बाद अपना संगीत बंद करने के लिए सेट करें।</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Ketuk untuk memulai</string>
<string name="app_description">Atur musik Anda agar berhenti setelah Anda tertidur.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Tocca per iniziare</string>
<string name="app_description">Imposta la tua musica in modo che si fermi dopo che ti addormenti.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">タップして開始</string>
<string name="app_description">眠りについたら音楽を停止するように設定します。</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Atingeți pentru a începe</string>
<string name="app_description">Setează-ți muzica să se oprească după ce adormi.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Нажмите, чтобы начать</string>
<string name="app_description">Настройте музыку так, чтобы она останавливалась после того, как вы заснете.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="tile_subtitle">Başlamak için dokun</string>
<string name="app_description">Müziğinizi uykuya daldıktan sonra duracak şekilde ayarlayın.</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<color name="ic_launcher_background">@android:color/white</color>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>
<string name="app_name" translatable="false">Music Sleep Timer</string>
<string name="app_description">Set your music to stop after you fall asleep.</string>
<string name="tile_subtitle">Tap to start</string>
<string name="notification_channel_id" translatable="false">sleep_timer</string>
<string name="notification_action_increment" translatable="false">+%d</string>
<string name="notification_action_decrement" translatable="false">-%d</string>
</resources>
9 changes: 0 additions & 9 deletions app/src/main/res/values/values.xml

This file was deleted.

14 changes: 14 additions & 0 deletions app/src/main/res/xml/config_locales.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<locale-config
xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en"/>
<locale android:name="ro"/>
<locale android:name="ru"/>
<locale android:name="in"/>
<locale android:name="fr"/>
<locale android:name="it"/>
<locale android:name="ja"/>
<locale android:name="hi"/>
<locale android:name="es"/>
<locale android:name="tr"/>
<locale android:name="de"/>
</locale-config>
14 changes: 5 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
buildscript {
dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
id "com.google.gms.google-services" version "4.3.10" apply false
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.22' apply false
id 'com.google.gms.google-services' version '4.3.14' apply false
id 'com.google.firebase.crashlytics' version '2.9.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Aug 08 16:50:02 EEST 2022
#Fri Dec 02 01:41:33 EET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 5e00611

Please sign in to comment.