-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee86cf2
commit aa5e1ea
Showing
59 changed files
with
2,295 additions
and
2,125 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/d4rk/lowbrightness/helpers/AppUpdateNotificationsManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.d4rk.lowbrightness.helpers | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.core.app.NotificationCompat | ||
import com.d4rk.lowbrightness.R | ||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory | ||
import com.google.android.play.core.install.model.AppUpdateType | ||
import com.google.android.play.core.install.model.UpdateAvailability | ||
class AppUpdateNotificationsManager(private val context: Context) { | ||
private val updateChannelId = "update_channel" | ||
private val updateNotificationId = 0 | ||
fun checkAndSendUpdateNotification() { | ||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
val appUpdateInfoTask = AppUpdateManagerFactory.create(context).appUpdateInfo | ||
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> | ||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE | ||
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { | ||
val updateChannel = NotificationChannel(updateChannelId, context.getString(R.string.update_notifications), NotificationManager.IMPORTANCE_HIGH) | ||
notificationManager.createNotificationChannel(updateChannel) | ||
val updateBuilder = NotificationCompat.Builder(context, updateChannelId) | ||
.setSmallIcon(R.drawable.ic_notification_update) | ||
.setContentTitle(context.getString(R.string.notification_update_title)) | ||
.setContentText(context.getString(R.string.summary_notification_update)) | ||
.setAutoCancel(true) | ||
.setContentIntent(PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}")), PendingIntent.FLAG_IMMUTABLE)) | ||
notificationManager.notify(updateNotificationId, updateBuilder.build()) | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/d4rk/lowbrightness/helpers/AppUsageNotificationsManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.d4rk.lowbrightness.helpers | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.content.Context | ||
import androidx.core.app.NotificationCompat | ||
import com.d4rk.lowbrightness.R | ||
class AppUsageNotificationsManager(private val context: Context) { | ||
private val appUsageChannelId = "app_usage_channel" | ||
private val appUsageNotificationId = 0 | ||
fun checkAndSendAppUsageNotification() { | ||
val prefs = context.getSharedPreferences("app_usage", Context.MODE_PRIVATE) | ||
val lastUsedTimestamp = prefs.getLong("last_used", 0) | ||
val currentTimestamp = System.currentTimeMillis() | ||
val notificationThreshold = 3 * 24 * 60 * 60 * 1000 | ||
if (currentTimestamp - lastUsedTimestamp > notificationThreshold) { | ||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
val appUsageChannel = NotificationChannel(appUsageChannelId, context.getString(R.string.app_usage_notifications),NotificationManager.IMPORTANCE_HIGH) | ||
notificationManager.createNotificationChannel(appUsageChannel) | ||
val notificationBuilder = NotificationCompat.Builder(context, appUsageChannelId) | ||
.setSmallIcon(R.drawable.ic_notification_important) | ||
.setContentTitle(context.getString(R.string.notification_last_time_used_title)) | ||
.setContentText(context.getString(R.string.summary_notification_last_time_used)) | ||
.setAutoCancel(true) | ||
notificationManager.notify(appUsageNotificationId, notificationBuilder.build()) | ||
} | ||
prefs.edit().putLong("last_used", currentTimestamp).apply() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.