Skip to content

Commit

Permalink
Solved an issue with activity minimum time preference (Int casted to …
Browse files Browse the repository at this point in the history
…String and viceversa)
  • Loading branch information
Javinator9889 committed Jul 1, 2020
1 parent 645d94d commit a8ab1f8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -50,9 +50,9 @@
android:name=".gms.activity.ActivityReceiver"
android:enabled="true"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="com.javinator9889.handwashingreminder.TRANSITIONS_RECEIVER_ACTION" />-->
<!-- </intent-filter>-->
<intent-filter>
<action android:name="com.javinator9889.handwashingreminder.TRANSITIONS_RECEIVER_ACTION" />
</intent-filter>
</receiver>

<receiver
Expand Down
Expand Up @@ -31,8 +31,8 @@ import com.google.android.gms.tasks.Task
import timber.log.Timber

internal const val ACTIVITY_REQUEST_CODE = 64
//internal const val TRANSITIONS_RECEIVER_ACTION =
// "${BuildConfig.APPLICATION_ID}.TRANSITIONS_RECEIVER_ACTION"
internal const val TRANSITIONS_RECEIVER_ACTION =
"com.javinator9889.handwashingreminder.TRANSITIONS_RECEIVER_ACTION"
internal val TRANSITIONS = listOf<ActivityTransition>(
ActivityTransition.Builder()
.setActivityType(DetectedActivity.IN_VEHICLE)
Expand All @@ -53,7 +53,8 @@ internal val TRANSITIONS = listOf<ActivityTransition>(
)

class ActivityHandler private constructor(private val context: Context) {
private var pendingIntent: PendingIntent = createPendingIntent()
private val pendingIntent: PendingIntent
get() = createPendingIntent()
private var activityRegistered = false

companion object {
Expand Down Expand Up @@ -95,7 +96,7 @@ class ActivityHandler private constructor(private val context: Context) {

private fun createPendingIntent(): PendingIntent =
with(Intent(context, ActivityReceiver::class.java)) {
// action = TRANSITIONS_RECEIVER_ACTION
action = TRANSITIONS_RECEIVER_ACTION
PendingIntent.getBroadcast(
context,
ACTIVITY_REQUEST_CODE,
Expand Down
Expand Up @@ -88,9 +88,9 @@ class ActivityReceiver : BroadcastReceiver() {
detectedActivity: Int,
context: Context
) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val timeInBetweenNotifications =
preferences.getInt(Preferences.ACTIVITY_MINIMUM_TIME, 15)
prefs.getString(Preferences.ACTIVITY_MINIMUM_TIME, "15")!!.toInt()
val timeFile = File(context.cacheDir, "activity.time")
var latestNotificationTime = 0L
withContext(Dispatchers.IO) {
Expand All @@ -104,6 +104,7 @@ class ActivityReceiver : BroadcastReceiver() {
TimeUnit.MINUTES,
latestNotificationTime
)
Timber.d("$timeDifference - $timeInBetweenNotifications")
if (timeDifference <= timeInBetweenNotifications)
return
val notificationContent = when (detectedActivity) {
Expand Down
Expand Up @@ -36,8 +36,11 @@ class LogReportTree : Timber.Tree() {
t: Throwable?
) {
when (priority) {
Log.DEBUG, Log.VERBOSE -> return
Log.WARN -> crashlytics.log("W: $tag: $message")
Log.DEBUG, Log.VERBOSE, Log.INFO -> return
Log.WARN -> {
crashlytics.log("W: $tag: $message")
t?.let { crashlytics.recordException(it) }
}
Log.ERROR -> {
crashlytics.log("E/$tag: $message")
t?.let { crashlytics.recordException(t) }
Expand Down
Expand Up @@ -47,7 +47,7 @@ object CalendarUtils {
unit: TimeUnit,
to: Long,
from: Long = Calendar.getInstance().timeInMillis
): Long = unit.convert(timeBetween(from, to), TimeUnit.MILLISECONDS)
): Long = unit.convert(timeBetween(to, from), TimeUnit.MILLISECONDS)

fun timeBetween(
to: Long,
Expand Down

0 comments on commit a8ab1f8

Please sign in to comment.