Skip to content

Commit 68a6699

Browse files
committed
[CLEANUP] Timber all the way 🌳
1 parent 55171b1 commit 68a6699

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

app/src/main/java/dev/hossain/keepalive/util/AppChecker.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.SortedMap;
1313
import java.util.TreeMap;
1414

15+
import timber.log.Timber;
16+
1517
public class AppChecker {
1618

1719
public static boolean isGooglePhotosRunning(Context context) {
@@ -46,7 +48,7 @@ private static boolean isAppRunning(Context context, String packageName) {
4648
return true;
4749
}
4850
} else {
49-
Log.d("AppChecker", "appList is null or empty. " + appList);
51+
Timber.d("appList is null or empty. %s", appList);
5052
}
5153
}
5254
return false;
@@ -55,7 +57,7 @@ private static boolean isAppRunning(Context context, String packageName) {
5557
private static void printSortedMap(SortedMap<Long, UsageStats> sortedMap) {
5658
for (Long key : sortedMap.keySet()) {
5759
UsageStats usageStats = sortedMap.get(key);
58-
Log.d("AppChecker", "UsageStats: " + usageStats.getPackageName() + " | " + usageStats.getLastTimeUsed());
60+
Timber.d("UsageStats: " + usageStats.getPackageName() + " | " + usageStats.getLastTimeUsed());
5961
}
6062
}
6163
}

app/src/main/java/dev/hossain/keepalive/util/AppLauncher.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ import android.content.ActivityNotFoundException
44
import android.content.ComponentName
55
import android.content.Context
66
import android.content.Intent
7-
import android.util.Log
87
import dev.hossain.keepalive.util.AppConfig.PHOTOS_APP_LAUNCH_ACTIVITY
98
import dev.hossain.keepalive.util.AppConfig.PHOTOS_APP_PACKAGE_NAME
109
import dev.hossain.keepalive.util.AppConfig.SYNC_APP_LAUNCH_ACTIVITY
1110
import dev.hossain.keepalive.util.AppConfig.SYNC_APP_PACKAGE_NAME
11+
import timber.log.Timber
1212

1313
object AppLauncher {
14-
private const val TAG = "AppLauncher"
15-
1614
fun openGooglePhotos(context: Context) {
17-
Log.i(TAG, "openGooglePhotos")
15+
Timber.i("openGooglePhotos")
1816
startApplication(context, PHOTOS_APP_PACKAGE_NAME, PHOTOS_APP_LAUNCH_ACTIVITY)
1917
}
2018

2119
fun openSyncthing(context: Context) {
22-
Log.i(TAG, "openSyncthing")
20+
Timber.i("openSyncthing")
2321
startApplication(context, SYNC_APP_PACKAGE_NAME, SYNC_APP_LAUNCH_ACTIVITY)
2422
}
2523

@@ -41,7 +39,7 @@ object AppLauncher {
4139
context.startActivity(launchIntent)
4240
} catch (e: ActivityNotFoundException) {
4341
e.printStackTrace()
44-
Log.e(TAG, "Unable to find activity: $launchIntent", e)
42+
Timber.e(e, "Unable to find activity: $launchIntent")
4543
}
4644
}
4745
}

app/src/main/java/dev/hossain/keepalive/util/HttpPingSender.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
package dev.hossain.keepalive.util
22

33
import android.content.Context
4-
import android.util.Log
54
import okhttp3.OkHttpClient
65
import okhttp3.Request
76
import okio.IOException
7+
import timber.log.Timber
88

99
/**
1010
* Sends HTTP ping to a given URL.
1111
*/
1212
class HttpPingSender(private val context: Context) {
13-
companion object {
14-
private const val TAG = "HttpPingSender"
15-
}
16-
1713
private val client = OkHttpClient()
1814

1915
fun sendPingToDevice() {
2016
val deviceModel = android.os.Build.MODEL
2117
AppConfig.phoneToUrlMap[deviceModel]?.let { pingUrl ->
22-
Log.d(TAG, "sendPingToDevice: Pinging device $deviceModel with URL $pingUrl")
18+
Timber.d("sendPingToDevice: Pinging device $deviceModel with URL $pingUrl")
2319
sendHttpPing(pingUrl)
2420
} ?: run {
25-
Log.e(TAG, "sendPingToDevice: No URL found for device $deviceModel - Not supported.")
21+
Timber.e("sendPingToDevice: No URL found for device $deviceModel - Not supported.")
2622
}
2723
}
2824

@@ -44,9 +40,9 @@ class HttpPingSender(private val context: Context) {
4440
.build()
4541
client.newCall(request).execute().use { response ->
4642
if (!response.isSuccessful) {
47-
Log.e(TAG, "Unexpected code $response", IOException("Unexpected code $response"))
43+
Timber.e(IOException("Unexpected code $response"), "Unexpected code $response")
4844
} else {
49-
Log.d(TAG, "Heartbeat Ping Sent: Response: ${response.body?.string()}")
45+
Timber.d("Heartbeat Ping Sent: Response: " + response.body?.string())
5046
}
5147
}
5248
}

app/src/main/java/dev/hossain/keepalive/util/NotificationHelper.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ import android.app.NotificationManager
66
import android.app.PendingIntent
77
import android.content.Context
88
import android.content.Intent
9-
import android.util.Log
109
import androidx.core.app.NotificationCompat
1110
import dev.hossain.keepalive.MainActivity
1211
import dev.hossain.keepalive.R
12+
import timber.log.Timber
1313

1414
/**
1515
* Helper class to create notification channel and build notification.
1616
*/
1717
class NotificationHelper(private val context: Context) {
1818
companion object {
19-
private const val TAG = "NotificationHelper"
2019
private const val CHANNEL_ID = "WatchdogServiceChannel"
2120
}
2221

2322
fun createNotificationChannel() {
24-
Log.d(TAG, "createNotificationChannel() called")
23+
Timber.d("createNotificationChannel() called")
2524

2625
val channel =
2726
NotificationChannel(
@@ -35,7 +34,7 @@ class NotificationHelper(private val context: Context) {
3534
}
3635

3736
fun buildNotification(): Notification {
38-
Log.d(TAG, "buildNotification() called")
37+
Timber.d("buildNotification() called")
3938

4039
val notificationIntent = Intent(context, MainActivity::class.java)
4140
val pendingIntent =

0 commit comments

Comments
 (0)