Skip to content

Commit

Permalink
Fix download-related crash, use Timber for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Oct 3, 2017
1 parent 50ac246 commit 0a90567
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 19 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Expand Up @@ -26,8 +26,8 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 19
targetSdkVersion 26
versionCode 126
versionName '4.2'
versionCode 128
versionName '4.2.1'
multiDexEnabled true
}
buildTypes {
Expand Down Expand Up @@ -82,6 +82,7 @@ dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'commons-io:commons-io:2.5'
compile 'net.danlew:android.joda:2.9.9'
compile 'io.reactivex.rxjava2:rxjava:2.1.4'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/stevenschoen/putionew/Analytics.kt
Expand Up @@ -86,7 +86,7 @@ class Analytics(context: Context) {

private fun Bundle.addIdAndName(file: PutioFile) {
putLong(FirebaseAnalytics.Param.ITEM_ID, file.id)
putString(FirebaseAnalytics.Param.ITEM_NAME, file.name)
putString(FirebaseAnalytics.Param.ITEM_NAME, file.name.take(100))
}

private fun Bundle.logEvent(event: String) = putioApp.firebaseAnalytics.logEvent(event, this)
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/stevenschoen/putionew/CrashlyticsTree.java
@@ -0,0 +1,31 @@
package com.stevenschoen.putionew;

import android.support.annotation.Nullable;
import android.util.Log;

import com.crashlytics.android.Crashlytics;

import timber.log.Timber;

public class CrashlyticsTree extends Timber.Tree {
private static final String CRASHLYTICS_KEY_PRIORITY = "priority";
private static final String CRASHLYTICS_KEY_TAG = "tag";
private static final String CRASHLYTICS_KEY_MESSAGE = "message";

@Override
protected void log(int priority, @Nullable String tag, @Nullable String message, @Nullable Throwable t) {
if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
return;
}

Crashlytics.setInt(CRASHLYTICS_KEY_PRIORITY, priority);
Crashlytics.setString(CRASHLYTICS_KEY_TAG, tag);
Crashlytics.setString(CRASHLYTICS_KEY_MESSAGE, message);

if (t == null) {
Crashlytics.logException(new Exception(message));
} else {
Crashlytics.logException(t);
}
}
}
7 changes: 0 additions & 7 deletions app/src/main/java/com/stevenschoen/putionew/Log.kt

This file was deleted.

Expand Up @@ -12,6 +12,7 @@ import com.stevenschoen.putionew.files.FileDownloadDatabase
import com.stevenschoen.putionew.model.files.PutioFile
import io.fabric.sdk.android.Fabric
import net.danlew.android.joda.JodaTimeAndroid
import timber.log.Timber

class PutioApplication : MultiDexApplication() {

Expand Down Expand Up @@ -41,6 +42,12 @@ class PutioApplication : MultiDexApplication() {
.build())
.build())

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
} else {
Timber.plant(CrashlyticsTree())
}

JodaTimeAndroid.init(this)

if (Build.VERSION.SDK_INT >= 26) {
Expand Down
Expand Up @@ -9,6 +9,7 @@ import android.support.v4.app.JobIntentService
import com.stevenschoen.putionew.PutioUtils
import com.stevenschoen.putionew.analytics
import com.stevenschoen.putionew.putioApp
import timber.log.Timber

class DownloadFinishedService : JobIntentService() {

Expand All @@ -32,10 +33,15 @@ class DownloadFinishedService : JobIntentService() {
val downloadStatus = query.getInt(query.getColumnIndex(DownloadManager.COLUMN_STATUS))
if (downloadStatus == DownloadManager.STATUS_SUCCESSFUL) {
val fileDownloads = putioApp.fileDownloadDatabase.fileDownloadsDao()
fileDownloads.update(fileDownloads.getByDownloadIdSynchronous(downloadId)!!.apply {
status = FileDownload.Status.Downloaded
uri = downloadManager.getUriForDownloadedFile(downloadId).toString()
})
val fileDownload = fileDownloads.getByDownloadIdSynchronous(downloadId)
if (fileDownload != null) {
fileDownloads.update(fileDownload.apply {
status = FileDownload.Status.Downloaded
uri = downloadManager.getUriForDownloadedFile(downloadId).toString()
})
} else {
Timber.w("Got a finished download (ID $downloadId), but no matching FileDownload")
}

putioApp.fileDownloadDatabase.fileDownloadsDao()
.getByDownloadIdOnce(downloadId)
Expand Down
Expand Up @@ -7,9 +7,9 @@ import android.support.v4.app.LoaderManager
import android.support.v4.content.Loader
import com.stevenschoen.putionew.PutioBaseLoader
import com.stevenschoen.putionew.getUniqueLoaderId
import com.stevenschoen.putionew.log
import com.stevenschoen.putionew.model.files.PutioFile
import com.stevenschoen.putionew.putioApp
import timber.log.Timber

class FileDetailsLoader(context: Context, private val file: PutioFile) : PutioBaseLoader(context) {

Expand All @@ -19,10 +19,10 @@ class FileDetailsLoader(context: Context, private val file: PutioFile) : PutioBa
val isDownloaded = it.status == FileDownload.Status.Downloaded
val isDownloading = it.status == FileDownload.Status.InProgress
if ((isDownloaded || isDownloading) && !isFileDownloadedOrDownloading(context, it)) {
log("${file.name} appears to not be downloaded, marking NotDownloaded")
Timber.d("${file.name} appears to not be downloaded, marking NotDownloaded")
markFileNotDownloaded(context, it)
} else if (isDownloading && isFileDownloaded(context, it)) {
log("${file.name} appears to be downloaded, marking Downloaded")
Timber.d("${file.name} appears to be downloaded, marking Downloaded")
markFileDownloaded(context, it)
}
/*
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/file_putio.xml
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="?attr/listChoiceBackgroundIndicator"
android:background="?listChoiceBackgroundIndicator"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -9,7 +9,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
Expand Down

0 comments on commit 0a90567

Please sign in to comment.