Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Timber for logging #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion folioreader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ android {

lintOptions {
abortOnError false
lintConfig file("lint.xml")
}

checkstyle {
Expand Down
5 changes: 0 additions & 5 deletions folioreader/lint.xml

This file was deleted.

64 changes: 30 additions & 34 deletions folioreader/src/main/java/com/folioreader/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import org.json.JSONObject;
import timber.log.Timber;

/**
* Configuration class for FolioReader.
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class Config implements Parcelable {

private static final String LOG_TAG = Config.class.getSimpleName();
public static final String INTENT_CONFIG = "config";
public static final String EXTRA_OVERRIDE_CONFIG = "com.folioreader.extra.OVERRIDE_CONFIG";
public static final String CONFIG_FONT = "font";
Expand Down Expand Up @@ -87,8 +86,8 @@ protected Config(Parcel in) {
nightMode = in.readByte() != 0;
themeColor = in.readInt();
showTts = in.readByte() != 0;
allowedDirection = getAllowedDirectionFromString(LOG_TAG, in.readString());
direction = getDirectionFromString(LOG_TAG, in.readString());
allowedDirection = getAllowedDirectionFromString(in.readString());
direction = getDirectionFromString(in.readString());
}

public Config() {
Expand All @@ -100,39 +99,37 @@ public Config(JSONObject jsonObject) {
nightMode = jsonObject.optBoolean(CONFIG_IS_NIGHT_MODE);
themeColor = getValidColorInt(jsonObject.optInt(CONFIG_THEME_COLOR_INT));
showTts = jsonObject.optBoolean(CONFIG_IS_TTS);
allowedDirection = getAllowedDirectionFromString(LOG_TAG,
allowedDirection = getAllowedDirectionFromString(
jsonObject.optString(CONFIG_ALLOWED_DIRECTION));
direction = getDirectionFromString(LOG_TAG, jsonObject.optString(CONFIG_DIRECTION));
direction = getDirectionFromString(jsonObject.optString(CONFIG_DIRECTION));
}

public static Direction getDirectionFromString(final String LOG_TAG, String directionString) {
public static Direction getDirectionFromString(@Nullable String directionString) {

switch (directionString) {
switch (directionString == null? "null" : directionString) {
case "VERTICAL":
return Direction.VERTICAL;
case "HORIZONTAL":
return Direction.HORIZONTAL;
default:
Log.w(LOG_TAG, "-> Illegal argument directionString = `" + directionString
+ "`, defaulting direction to " + DEFAULT_DIRECTION);
Timber.w("-> Illegal argument directionString = `%s`, defaulting direction to %s",
directionString, DEFAULT_DIRECTION);
return DEFAULT_DIRECTION;
}
}

public static AllowedDirection getAllowedDirectionFromString(final String LOG_TAG,
String allowedDirectionString) {
public static AllowedDirection getAllowedDirectionFromString(@Nullable String allowedDirectionString) {

switch (allowedDirectionString) {
switch (allowedDirectionString == null? "null" : allowedDirectionString) {
case "ONLY_VERTICAL":
return AllowedDirection.ONLY_VERTICAL;
case "ONLY_HORIZONTAL":
return AllowedDirection.ONLY_HORIZONTAL;
case "VERTICAL_AND_HORIZONTAL":
return AllowedDirection.VERTICAL_AND_HORIZONTAL;
default:
Log.w(LOG_TAG, "-> Illegal argument allowedDirectionString = `"
+ allowedDirectionString + "`, defaulting allowedDirection to "
+ DEFAULT_ALLOWED_DIRECTION);
Timber.w("-> Illegal argument allowedDirectionString = `%s`, defaulting allowedDirection to %s",
allowedDirectionString, DEFAULT_ALLOWED_DIRECTION);
return DEFAULT_ALLOWED_DIRECTION;
}
}
Expand Down Expand Up @@ -167,8 +164,8 @@ public Config setNightMode(boolean nightMode) {
@ColorInt
private int getValidColorInt(@ColorInt int colorInt) {
if (colorInt >= 0) {
Log.w(LOG_TAG, "-> getValidColorInt -> Invalid argument colorInt = " + colorInt +
", Returning DEFAULT_THEME_COLOR_INT = " + DEFAULT_THEME_COLOR_INT);
Timber.w("-> getValidColorInt -> Invalid argument colorInt = %d, Returning DEFAULT_THEME_COLOR_INT = %d",
colorInt, DEFAULT_THEME_COLOR_INT);
return DEFAULT_THEME_COLOR_INT;
}
return colorInt;
Expand All @@ -183,8 +180,8 @@ public Config setThemeColorRes(@ColorRes int colorResId) {
try {
this.themeColor = ContextCompat.getColor(AppContext.get(), colorResId);
} catch (Resources.NotFoundException e) {
Log.w(LOG_TAG, "-> setThemeColorRes -> " + e);
Log.w(LOG_TAG, "-> setThemeColorRes -> Defaulting themeColor to " +
Timber.w(e, "-> setThemeColorRes -> ");
Timber.w("-> setThemeColorRes -> Defaulting themeColor to %d",
DEFAULT_THEME_COLOR_INT);
this.themeColor = DEFAULT_THEME_COLOR_INT;
}
Expand Down Expand Up @@ -224,21 +221,20 @@ public Config setAllowedDirection(AllowedDirection allowedDirection) {
if (allowedDirection == null) {
this.allowedDirection = DEFAULT_ALLOWED_DIRECTION;
direction = DEFAULT_DIRECTION;
Log.w(LOG_TAG, "-> allowedDirection cannot be null, defaulting " +
"allowedDirection to " + DEFAULT_ALLOWED_DIRECTION + " and direction to " +
DEFAULT_DIRECTION);
Timber.w("-> allowedDirection cannot be null, defaulting allowedDirection to %s and direction to %s",
DEFAULT_ALLOWED_DIRECTION, DEFAULT_DIRECTION);

} else if (allowedDirection == AllowedDirection.ONLY_VERTICAL &&
direction != Direction.VERTICAL) {
direction = Direction.VERTICAL;
Log.w(LOG_TAG, "-> allowedDirection is " + allowedDirection +
", defaulting direction to " + direction);
Timber.w("-> allowedDirection is %s, defaulting direction to %s",
allowedDirection, direction);

} else if (allowedDirection == AllowedDirection.ONLY_HORIZONTAL &&
direction != Direction.HORIZONTAL) {
direction = Direction.HORIZONTAL;
Log.w(LOG_TAG, "-> allowedDirection is " + allowedDirection
+ ", defaulting direction to " + direction);
Timber.w("-> allowedDirection is %s, defaulting direction to %s",
allowedDirection, direction);
}

return this;
Expand All @@ -258,20 +254,20 @@ public Config setDirection(Direction direction) {

if (allowedDirection == AllowedDirection.VERTICAL_AND_HORIZONTAL && direction == null) {
this.direction = DEFAULT_DIRECTION;
Log.w(LOG_TAG, "-> direction cannot be `null` when allowedDirection is " +
allowedDirection + ", defaulting direction to " + this.direction);
Timber.w("-> direction cannot be `null` when allowedDirection is %s, defaulting direction to %s",
allowedDirection, this.direction);

} else if (allowedDirection == AllowedDirection.ONLY_VERTICAL &&
direction != Direction.VERTICAL) {
this.direction = Direction.VERTICAL;
Log.w(LOG_TAG, "-> direction cannot be `" + direction + "` when allowedDirection is " +
allowedDirection + ", defaulting direction to " + this.direction);
Timber.w("-> direction cannot be `%s` when allowedDirection is %s, defaulting direction to %s",
direction, allowedDirection, this.direction);

} else if (allowedDirection == AllowedDirection.ONLY_HORIZONTAL &&
direction != Direction.HORIZONTAL) {
this.direction = Direction.HORIZONTAL;
Log.w(LOG_TAG, "-> direction cannot be `" + direction + "` when allowedDirection is " +
allowedDirection + ", defaulting direction to " + this.direction);
Timber.w("-> direction cannot be `%s` when allowedDirection is %s, defaulting direction to %s",
direction, allowedDirection, this.direction);

} else {
this.direction = direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.folioreader.model.locators

import android.os.Parcel
import android.os.Parcelable
import android.util.Log
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonPropertyOrder
Expand All @@ -11,6 +10,7 @@ import com.folioreader.util.ObjectMapperSingleton
import org.readium.r2.shared.Locations
import org.readium.r2.shared.Locator
import org.readium.r2.shared.LocatorText
import timber.log.Timber

@JsonPropertyOrder("bookId", "href", "created", "locations")
@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down Expand Up @@ -50,10 +50,6 @@ open class ReadLocator : Locator, Parcelable {
}

companion object {

@JvmField
val LOG_TAG: String = ReadLocator::class.java.simpleName

@JvmStatic
fun fromJson(json: String?): ReadLocator? {
return try {
Expand All @@ -62,7 +58,7 @@ open class ReadLocator : Locator, Parcelable {
.forType(ReadLocator::class.java)
.readValue(json)
} catch (e: Exception) {
Log.e(LOG_TAG, "-> ", e)
Timber.e(e)
null
}
}
Expand Down Expand Up @@ -90,7 +86,7 @@ open class ReadLocator : Locator, Parcelable {
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
objectMapper.writeValueAsString(this)
} catch (e: Exception) {
Log.e(LOG_TAG, "-> ", e)
Timber.e(e)
null
}
}
Expand Down
Loading