diff --git a/folioreader/build.gradle b/folioreader/build.gradle index f41712cc4..bb6b67706 100644 --- a/folioreader/build.gradle +++ b/folioreader/build.gradle @@ -68,7 +68,6 @@ android { lintOptions { abortOnError false - lintConfig file("lint.xml") } checkstyle { diff --git a/folioreader/lint.xml b/folioreader/lint.xml deleted file mode 100644 index 45028b5fc..000000000 --- a/folioreader/lint.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/folioreader/src/main/java/com/folioreader/Config.java b/folioreader/src/main/java/com/folioreader/Config.java index c947b69b9..36a3e7a09 100644 --- a/folioreader/src/main/java/com/folioreader/Config.java +++ b/folioreader/src/main/java/com/folioreader/Config.java @@ -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"; @@ -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() { @@ -100,29 +99,28 @@ 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": @@ -130,9 +128,8 @@ public static AllowedDirection getAllowedDirectionFromString(final String LOG_TA 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; } } @@ -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; @@ -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; } @@ -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; @@ -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; diff --git a/folioreader/src/main/java/com/folioreader/model/locators/ReadLocator.kt b/folioreader/src/main/java/com/folioreader/model/locators/ReadLocator.kt index 97ce9bb45..76951f8d2 100644 --- a/folioreader/src/main/java/com/folioreader/model/locators/ReadLocator.kt +++ b/folioreader/src/main/java/com/folioreader/model/locators/ReadLocator.kt @@ -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 @@ -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) @@ -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 { @@ -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 } } @@ -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 } } diff --git a/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt b/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt index 8df26fbe8..def42cc92 100644 --- a/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt +++ b/folioreader/src/main/java/com/folioreader/ui/activity/FolioActivity.kt @@ -31,7 +31,6 @@ import android.os.Bundle import android.os.Handler import android.text.TextUtils import android.util.DisplayMetrics -import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View @@ -72,6 +71,7 @@ import org.readium.r2.streamer.parser.CbzParser import org.readium.r2.streamer.parser.EpubParser import org.readium.r2.streamer.parser.PubBox import org.readium.r2.streamer.server.Server +import timber.log.Timber import java.lang.ref.WeakReference class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControllerCallback, @@ -117,10 +117,6 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle private var taskImportance: Int = 0 companion object { - - @JvmField - val LOG_TAG: String = FolioActivity::class.java.simpleName - const val INTENT_EPUB_SOURCE_PATH = "com.folioreader.epub_asset_path" const val INTENT_EPUB_SOURCE_TYPE = "epub_source_type" const val EXTRA_READ_LOCATOR = "com.folioreader.extra.READ_LOCATOR" @@ -133,7 +129,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle private val closeBroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - Log.v(LOG_TAG, "-> closeBroadcastReceiver -> onReceive -> " + intent.action!!) + Timber.v("-> closeBroadcastReceiver -> onReceive -> %s", intent.action) val action = intent.action if (action != null && action == FolioReader.ACTION_CLOSE_FOLIOREADER) { @@ -143,7 +139,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle val tasks = activityManager.runningAppProcesses taskImportance = tasks[0].importance } catch (e: Exception) { - Log.e(LOG_TAG, "-> ", e) + Timber.e(e) } val closeIntent = Intent(applicationContext, FolioActivity::class.java) @@ -165,7 +161,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle private val searchReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - Log.v(LOG_TAG, "-> searchReceiver -> onReceive -> " + intent.action!!) + Timber.v("-> searchReceiver -> onReceive -> %s", intent.action) val action = intent.action ?: return when (action) { @@ -196,7 +192,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) setIntent(intent) - Log.v(LOG_TAG, "-> onNewIntent") + Timber.v("-> onNewIntent") val action = getIntent().action if (action != null && action == FolioReader.ACTION_CLOSE_FOLIOREADER) { @@ -223,7 +219,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle override fun onResume() { super.onResume() - Log.v(LOG_TAG, "-> onResume") + Timber.v("-> onResume") topActivity = true val action = intent.action @@ -235,7 +231,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle override fun onStop() { super.onStop() - Log.v(LOG_TAG, "-> onStop") + Timber.v("-> onStop") topActivity = false } @@ -335,7 +331,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } override fun setDayMode() { - Log.v(LOG_TAG, "-> setDayMode") + Timber.v("-> setDayMode") actionBar!!.setBackgroundDrawable( ColorDrawable(ContextCompat.getColor(this, R.color.white)) @@ -344,7 +340,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } override fun setNightMode() { - Log.v(LOG_TAG, "-> setNightMode") + Timber.v("-> setNightMode") actionBar!!.setBackgroundDrawable( ColorDrawable(ContextCompat.getColor(this, R.color.black)) @@ -353,7 +349,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } private fun initMediaController() { - Log.v(LOG_TAG, "-> initMediaController") + Timber.v("-> initMediaController") mediaControllerFragment = MediaControllerFragment.getInstance(supportFragmentManager, this) } @@ -373,17 +369,17 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } override fun onOptionsItemSelected(item: MenuItem): Boolean { - //Log.d(LOG_TAG, "-> onOptionsItemSelected -> " + item.getItemId()); + //Timber.d("-> onOptionsItemSelected -> " + item.getItemId()); val itemId = item.itemId if (itemId == android.R.id.home) { - Log.v(LOG_TAG, "-> onOptionsItemSelected -> drawer") + Timber.v("-> onOptionsItemSelected -> drawer") startContentHighlightActivity() return true } else if (itemId == R.id.itemSearch) { - Log.v(LOG_TAG, "-> onOptionsItemSelected -> " + item.title) + Timber.v("-> onOptionsItemSelected -> %s", item.title) if (searchUri == null) return true val intent = Intent(this, SearchActivity::class.java) @@ -395,12 +391,12 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle return true } else if (itemId == R.id.itemConfig) { - Log.v(LOG_TAG, "-> onOptionsItemSelected -> " + item.title) + Timber.v("-> onOptionsItemSelected -> %s", item.title) showConfigBottomSheetDialogFragment() return true } else if (itemId == R.id.itemTts) { - Log.v(LOG_TAG, "-> onOptionsItemSelected -> " + item.title) + Timber.v("-> onOptionsItemSelected -> %s", item.title) showMediaController() return true } @@ -416,10 +412,10 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle try { intent.putExtra(CHAPTER_SELECTED, spine!![currentChapterIndex].href) } catch (e: NullPointerException) { - Log.w(LOG_TAG, "-> ", e) + Timber.w(e) intent.putExtra(CHAPTER_SELECTED, "") } catch (e: IndexOutOfBoundsException) { - Log.w(LOG_TAG, "-> ", e) + Timber.w(e) intent.putExtra(CHAPTER_SELECTED, "") } @@ -442,12 +438,12 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } private fun setupBook() { - Log.v(LOG_TAG, "-> setupBook") + Timber.v("-> setupBook") try { initBook() onBookInitSuccess() } catch (e: Exception) { - Log.e(LOG_TAG, "-> Failed to initialize book", e) + Timber.e(e, "-> Failed to initialize book") onBookInitFailure() } @@ -455,7 +451,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle @Throws(Exception::class) private fun initBook() { - Log.v(LOG_TAG, "-> initBook") + Timber.v("-> initBook") bookFileName = FileUtil.getEpubFilename(this, mEpubSourceType!!, mEpubFilePath, mEpubRawId) val path = FileUtil.saveEpubFileAndLoadLazyBook( @@ -544,7 +540,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } override fun onDirectionChange(newDirection: Config.Direction) { - Log.v(LOG_TAG, "-> onDirectionChange") + Timber.v("-> onDirectionChange") var folioPageFragment: FolioPageFragment? = currentFragment ?: return entryReadLocator = folioPageFragment!!.getLastReadLocator() @@ -567,7 +563,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } private fun initDistractionFreeMode(savedInstanceState: Bundle?) { - Log.v(LOG_TAG, "-> initDistractionFreeMode") + Timber.v("-> initDistractionFreeMode") window.decorView.setOnSystemUiVisibilityChangeListener(this) @@ -580,7 +576,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) - Log.v(LOG_TAG, "-> onPostCreate") + Timber.v("-> onPostCreate") if (distractionFreeMode) { handler!!.post { hideSystemUI() } @@ -644,7 +640,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle * 3. In tablets, navigation bar is always placed at bottom of the screen. */ private fun computeViewportRect(): Rect { - //Log.v(LOG_TAG, "-> computeViewportRect"); + //Timber.v("-> computeViewportRect"); val viewportRect = Rect(appBarLayout!!.insets) if (distractionFreeMode) @@ -691,10 +687,10 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } override fun onSystemUiVisibilityChange(visibility: Int) { - Log.v(LOG_TAG, "-> onSystemUiVisibilityChange -> visibility = $visibility") + Timber.v("-> onSystemUiVisibilityChange -> visibility = $visibility") distractionFreeMode = visibility != View.SYSTEM_UI_FLAG_VISIBLE - Log.v(LOG_TAG, "-> distractionFreeMode = $distractionFreeMode") + Timber.v("-> distractionFreeMode = $distractionFreeMode") if (actionBar != null) { if (distractionFreeMode) { @@ -715,7 +711,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } private fun showSystemUI() { - Log.v(LOG_TAG, "-> showSystemUI") + Timber.v("-> showSystemUI") if (Build.VERSION.SDK_INT >= 16) { val decorView = window.decorView @@ -731,7 +727,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } private fun hideSystemUI() { - Log.v(LOG_TAG, "-> hideSystemUI") + Timber.v("-> hideSystemUI") if (Build.VERSION.SDK_INT >= 16) { val decorView = window.decorView @@ -787,7 +783,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == RequestCode.SEARCH.value) { - Log.v(LOG_TAG, "-> onActivityResult -> " + RequestCode.SEARCH) + Timber.v("-> onActivityResult -> %s", RequestCode.SEARCH) if (resultCode == Activity.RESULT_CANCELED) return @@ -859,7 +855,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} override fun onPageSelected(position: Int) { - Log.v(LOG_TAG, "-> onPageSelected -> DirectionalViewpager -> position = $position") + Timber.v("-> onPageSelected -> DirectionalViewpager -> position = $position") EventBus.getDefault().post( MediaOverlayPlayPauseEvent( @@ -874,9 +870,9 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle if (state == DirectionalViewpager.SCROLL_STATE_IDLE) { val position = mFolioPageViewPager!!.currentItem - Log.v( - LOG_TAG, "-> onPageScrollStateChanged -> DirectionalViewpager -> " + - "position = " + position + Timber.v( + "-> onPageScrollStateChanged -> DirectionalViewpager -> position = %d", + position ) var folioPageFragment = mFolioPageFragmentAdapter!!.getItem(position - 1) as FolioPageFragment? @@ -964,7 +960,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle */ override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - Log.v(LOG_TAG, "-> onSaveInstanceState") + Timber.v("-> onSaveInstanceState") this.outState = outState outState.putBoolean(BUNDLE_DISTRACTION_FREE_MODE, distractionFreeMode) @@ -973,7 +969,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } override fun storeLastReadLocator(lastReadLocator: ReadLocator) { - Log.v(LOG_TAG, "-> storeLastReadLocator") + Timber.v("-> storeLastReadLocator") this.lastReadLocator = lastReadLocator } @@ -1043,7 +1039,7 @@ class FolioActivity : AppCompatActivity(), FolioActivityCallback, MediaControlle } private fun clearSearchLocator() { - Log.v(LOG_TAG, "-> clearSearchLocator") + Timber.v("-> clearSearchLocator") val fragments = mFolioPageFragmentAdapter!!.fragments for (i in fragments.indices) { diff --git a/folioreader/src/main/java/com/folioreader/ui/activity/SearchActivity.kt b/folioreader/src/main/java/com/folioreader/ui/activity/SearchActivity.kt index 01cf904a5..a1043bc54 100644 --- a/folioreader/src/main/java/com/folioreader/ui/activity/SearchActivity.kt +++ b/folioreader/src/main/java/com/folioreader/ui/activity/SearchActivity.kt @@ -7,7 +7,6 @@ import android.net.Uri import android.os.Bundle import android.os.Parcelable import android.text.TextUtils -import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View @@ -32,13 +31,12 @@ import com.folioreader.util.AppUtil import com.folioreader.util.UiUtil import com.folioreader.viewmodels.SearchViewModel import kotlinx.android.synthetic.main.activity_search.* +import timber.log.Timber import java.lang.reflect.Field class SearchActivity : AppCompatActivity(), OnItemClickListener { companion object { - @JvmField - val LOG_TAG: String = SearchActivity::class.java.simpleName const val BUNDLE_SPINE_SIZE = "BUNDLE_SPINE_SIZE" const val BUNDLE_SEARCH_URI = "BUNDLE_SEARCH_URI" const val BUNDLE_SAVE_SEARCH_QUERY = "BUNDLE_SAVE_SEARCH_QUERY" @@ -78,11 +76,11 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { continue if (contentDescription == "Collapse") { - Log.v(LOG_TAG, "-> initActionBar -> mCollapseButtonView found") + Timber.v("-> initActionBar -> mCollapseButtonView found") collapseButtonView = view as ImageButton collapseButtonView?.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> collapseButtonView") + Timber.v("-> onClick -> collapseButtonView") navigateBack() } @@ -95,7 +93,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Log.v(LOG_TAG, "-> onCreate") + Timber.v("-> onCreate") val config: Config = AppUtil.getSavedConfig(this)!! if (config.isNightMode) { @@ -109,7 +107,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { } private fun init(config: Config) { - Log.v(LOG_TAG, "-> init") + Timber.v("-> init") setSupportActionBar(toolbar) toolbar.addOnLayoutChangeListener(toolbarOnLayoutChangeListener) @@ -123,7 +121,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { val collapseIcon: Drawable = fieldCollapseIcon.get(toolbar) as Drawable UiUtil.setColorIntToDrawable(config.themeColor, collapseIcon) } catch (e: Exception) { - Log.e(LOG_TAG, "-> ", e) + Timber.e(e) } spineSize = intent.getIntExtra(BUNDLE_SPINE_SIZE, 0) @@ -144,7 +142,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { searchAdapterDataBundle = bundleFromFolioActivity searchAdapter.changeDataBundle(bundleFromFolioActivity) val position = bundleFromFolioActivity.getInt(BUNDLE_FIRST_VISIBLE_ITEM_INDEX) - Log.d(LOG_TAG, "-> onCreate -> scroll to previous position $position") + Timber.d("-> onCreate -> scroll to previous position $position") recyclerView.scrollToPosition(position) } @@ -155,7 +153,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { } override fun onNewIntent(intent: Intent) { - Log.v(LOG_TAG, "-> onNewIntent") + Timber.v("-> onNewIntent") if (intent.hasExtra(BUNDLE_SEARCH_URI)) { searchUri = intent.getParcelableExtra(BUNDLE_SEARCH_URI) @@ -171,7 +169,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { } private fun handleSearch() { - Log.v(LOG_TAG, "-> handleSearch") + Timber.v("-> handleSearch") val query: String = intent.getStringExtra(SearchManager.QUERY) val newDataBundle = Bundle() @@ -184,7 +182,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - Log.v(LOG_TAG, "-> onSaveInstanceState") + Timber.v("-> onSaveInstanceState") outState.putCharSequence(BUNDLE_SAVE_SEARCH_QUERY, searchView.query) outState.putBoolean(BUNDLE_IS_SOFT_KEYBOARD_VISIBLE, softKeyboardVisible) @@ -192,13 +190,13 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState) - Log.v(LOG_TAG, "-> onRestoreInstanceState") + Timber.v("-> onRestoreInstanceState") this.savedInstanceState = savedInstanceState } private fun navigateBack() { - Log.v(LOG_TAG, "-> navigateBack") + Timber.v("-> navigateBack") val intent = Intent() searchAdapterDataBundle.putInt( @@ -212,11 +210,11 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { } override fun onBackPressed() { - Log.v(LOG_TAG, "-> onBackPressed") + Timber.v("-> onBackPressed") } override fun onCreateOptionsMenu(menu: Menu?): Boolean { - Log.v(LOG_TAG, "-> onCreateOptionsMenu") + Timber.v("-> onCreateOptionsMenu") menuInflater.inflate(R.menu.menu_search, menu!!) val config: Config = AppUtil.getSavedConfig(applicationContext)!! @@ -256,7 +254,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { override fun onQueryTextChange(newText: String?): Boolean { if (TextUtils.isEmpty(newText)) { - Log.v(LOG_TAG, "-> onQueryTextChange -> Empty Query") + Timber.v("-> onQueryTextChange -> Empty Query") //supportLoaderManager.restartLoader(SEARCH_LOADER, null, this@SearchActivity) searchViewModel.cancelAllSearchCalls() searchViewModel.init() @@ -275,7 +273,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { } override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { - Log.v(LOG_TAG, "-> onMenuItemActionCollapse") + Timber.v("-> onMenuItemActionCollapse") navigateBack() return false } @@ -293,7 +291,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { val itemId = item?.itemId if (itemId == R.id.itemSearch) { - Log.v(LOG_TAG, "-> onOptionsItemSelected -> ${item.title}") + Timber.v("-> onOptionsItemSelected -> %s", item.title) //onSearchRequested() return true } @@ -308,7 +306,7 @@ class SearchActivity : AppCompatActivity(), OnItemClickListener { if (adapter is SearchAdapter) { if (viewHolder is SearchAdapter.NormalViewHolder) { - Log.v(LOG_TAG, "-> onItemClick -> " + viewHolder.searchLocator) + Timber.v("-> onItemClick -> %s", viewHolder.searchLocator) val intent = Intent() searchAdapterDataBundle.putInt( diff --git a/folioreader/src/main/java/com/folioreader/ui/adapter/FolioPageFragmentAdapter.java b/folioreader/src/main/java/com/folioreader/ui/adapter/FolioPageFragmentAdapter.java index ba4caa8ca..f1094e2f0 100644 --- a/folioreader/src/main/java/com/folioreader/ui/adapter/FolioPageFragmentAdapter.java +++ b/folioreader/src/main/java/com/folioreader/ui/adapter/FolioPageFragmentAdapter.java @@ -1,13 +1,13 @@ package com.folioreader.ui.adapter; import android.os.Bundle; -import android.util.Log; import android.view.ViewGroup; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; import com.folioreader.ui.fragment.FolioPageFragment; import org.readium.r2.shared.Link; +import timber.log.Timber; import java.lang.reflect.Field; import java.util.ArrayList; @@ -18,8 +18,6 @@ * @author mahavir on 4/2/16. */ public class FolioPageFragmentAdapter extends FragmentStatePagerAdapter { - - private static final String LOG_TAG = FolioPageFragmentAdapter.class.getSimpleName(); private List mSpineReferences; private String mEpubFileName; private String mBookId; @@ -76,7 +74,7 @@ public ArrayList getSavedStateList() { field.setAccessible(true); savedStateList = (ArrayList) field.get(this); } catch (Exception e) { - Log.e(LOG_TAG, "-> ", e); + Timber.e(e); } } @@ -91,7 +89,7 @@ public static Bundle getBundleFromSavedState(Fragment.SavedState savedState) { field.setAccessible(true); bundle = (Bundle) field.get(savedState); } catch (Exception e) { - Log.v(LOG_TAG, "-> " + e); + Timber.v(e); } return bundle; } diff --git a/folioreader/src/main/java/com/folioreader/ui/adapter/HighlightAdapter.java b/folioreader/src/main/java/com/folioreader/ui/adapter/HighlightAdapter.java index 4ffdc2ae2..9ad37fd15 100644 --- a/folioreader/src/main/java/com/folioreader/ui/adapter/HighlightAdapter.java +++ b/folioreader/src/main/java/com/folioreader/ui/adapter/HighlightAdapter.java @@ -6,6 +6,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.*; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; @@ -35,14 +36,15 @@ public HighlightAdapter(Context context, List highlights, HighLig this.config = config; } + @NonNull @Override - public HighlightHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public HighlightHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return new HighlightHolder(LayoutInflater.from(parent.getContext()) .inflate(R.layout.row_highlight, parent, false)); } @Override - public void onBindViewHolder(final HighlightHolder holder, final int position) { + public void onBindViewHolder(@NonNull final HighlightHolder holder, final int position) { holder.container.postDelayed(new Runnable() { @Override @@ -151,13 +153,13 @@ static class HighlightHolder extends RecyclerView.ViewHolder { HighlightHolder(View itemView) { super(itemView); - container = (RelativeLayout) itemView.findViewById(R.id.container); - swipeLinearLayout = (LinearLayout) itemView.findViewById(R.id.swipe_linear_layout); - content = (UnderlinedTextView) itemView.findViewById(R.id.utv_highlight_content); - delete = (ImageView) itemView.findViewById(R.id.iv_delete); - editNote = (ImageView) itemView.findViewById(R.id.iv_edit_note); - date = (TextView) itemView.findViewById(R.id.tv_highlight_date); - note = (TextView) itemView.findViewById(R.id.tv_note); + container = itemView.findViewById(R.id.container); + swipeLinearLayout = itemView.findViewById(R.id.swipe_linear_layout); + content = itemView.findViewById(R.id.utv_highlight_content); + delete = itemView.findViewById(R.id.iv_delete); + editNote = itemView.findViewById(R.id.iv_edit_note); + date = itemView.findViewById(R.id.tv_highlight_date); + note = itemView.findViewById(R.id.tv_note); } } diff --git a/folioreader/src/main/java/com/folioreader/ui/adapter/SearchAdapter.kt b/folioreader/src/main/java/com/folioreader/ui/adapter/SearchAdapter.kt index f84bd4661..27ffa6197 100644 --- a/folioreader/src/main/java/com/folioreader/ui/adapter/SearchAdapter.kt +++ b/folioreader/src/main/java/com/folioreader/ui/adapter/SearchAdapter.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.text.SpannableString import android.text.style.StyleSpan import android.text.style.UnderlineSpan -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -15,12 +14,11 @@ import androidx.recyclerview.widget.RecyclerView import com.folioreader.R import com.folioreader.model.locators.SearchItemType import com.folioreader.model.locators.SearchLocator +import timber.log.Timber class SearchAdapter : RecyclerView.Adapter { companion object { - @JvmField - val LOG_TAG: String? = SearchAdapter::class.java.simpleName const val DATA_BUNDLE = "DATA_BUNDLE" } @@ -30,13 +28,13 @@ class SearchAdapter : RecyclerView.Adapter { var onItemClickListener: OnItemClickListener? = null constructor(context: Context) : super() { - Log.v(LOG_TAG, "-> constructor") + Timber.v("-> constructor") this.context = context } constructor(context: Context, dataBundle: Bundle) : super() { - Log.v(LOG_TAG, "-> constructor") + Timber.v("-> constructor") this.context = context listViewType = ListViewType.fromString(dataBundle.getString(ListViewType.KEY)) diff --git a/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt b/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt index 801f0e6a1..cb36eee4a 100644 --- a/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt +++ b/folioreader/src/main/java/com/folioreader/ui/fragment/FolioPageFragment.kt @@ -49,6 +49,7 @@ import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.readium.r2.shared.Link import org.readium.r2.shared.Locations +import timber.log.Timber import java.util.* import java.util.regex.Pattern @@ -59,10 +60,6 @@ class FolioPageFragment : Fragment(), HtmlTaskCallback, MediaControllerCallbacks, FolioWebView.SeekBarListener { companion object { - - @JvmField - val LOG_TAG: String = FolioPageFragment::class.java.simpleName - private const val BUNDLE_SPINE_INDEX = "BUNDLE_SPINE_INDEX" private const val BUNDLE_BOOK_TITLE = "BUNDLE_BOOK_TITLE" private const val BUNDLE_SPINE_ITEM = "BUNDLE_SPINE_ITEM" @@ -330,7 +327,7 @@ class FolioPageFragment : Fragment(), fun scrollToLast() { val isPageLoading = loadingView == null || loadingView!!.visibility == View.VISIBLE - Log.v(LOG_TAG, "-> scrollToLast -> isPageLoading = $isPageLoading") + Timber.v("-> scrollToLast -> isPageLoading = $isPageLoading") if (!isPageLoading) { loadingView!!.show() @@ -341,7 +338,7 @@ class FolioPageFragment : Fragment(), fun scrollToFirst() { val isPageLoading = loadingView == null || loadingView!!.visibility == View.VISIBLE - Log.v(LOG_TAG, "-> scrollToFirst -> isPageLoading = $isPageLoading") + Timber.v("-> scrollToFirst -> isPageLoading = $isPageLoading") if (!isPageLoading) { loadingView!!.show() @@ -462,17 +459,17 @@ class FolioPageFragment : Fragment(), val readLocator: ReadLocator? if (savedInstanceState == null) { - Log.v(LOG_TAG, "-> onPageFinished -> took from getEntryReadLocator") + Timber.v("-> onPageFinished -> took from getEntryReadLocator") readLocator = mActivityCallback!!.entryReadLocator } else { - Log.v(LOG_TAG, "-> onPageFinished -> took from bundle") + Timber.v("-> onPageFinished -> took from bundle") readLocator = savedInstanceState!!.getParcelable(BUNDLE_READ_LOCATOR_CONFIG_CHANGE) savedInstanceState!!.remove(BUNDLE_READ_LOCATOR_CONFIG_CHANGE) } if (readLocator != null) { val cfi = readLocator.locations.cfi - Log.v(LOG_TAG, "-> onPageFinished -> readLocator -> " + cfi!!) + Timber.v("-> onPageFinished -> readLocator -> %s", cfi) mWebview!!.loadUrl(String.format(getString(R.string.callScrollToCfi), cfi)) } else { loadingView!!.hide() @@ -511,7 +508,7 @@ class FolioPageFragment : Fragment(), try { return WebResourceResponse("image/png", null, null) } catch (e: Exception) { - Log.e(LOG_TAG, "shouldInterceptRequest failed", e) + Timber.e(e, "shouldInterceptRequest failed") } } @@ -528,7 +525,7 @@ class FolioPageFragment : Fragment(), try { return WebResourceResponse("image/png", null, null) } catch (e: Exception) { - Log.e(LOG_TAG, "shouldInterceptRequest failed", e) + Timber.e(e, "shouldInterceptRequest failed") } } @@ -574,7 +571,7 @@ class FolioPageFragment : Fragment(), override fun onStop() { super.onStop() - Log.v(LOG_TAG, "-> onStop -> " + spineItem.href + " -> " + isCurrentFragment) + Timber.v("-> onStop -> %s -> %b", spineItem.href, isCurrentFragment) mediaController!!.stop() //TODO save last media overlay item @@ -584,14 +581,14 @@ class FolioPageFragment : Fragment(), } fun getLastReadLocator(): ReadLocator? { - Log.v(LOG_TAG, "-> getLastReadLocator -> " + spineItem.href!!) + Timber.v("-> getLastReadLocator -> %s", spineItem.href) try { synchronized(this) { mWebview!!.loadUrl(getString(R.string.callComputeLastReadCfi)) (this as java.lang.Object).wait(5000) } } catch (e: InterruptedException) { - Log.e(LOG_TAG, "-> ", e) + Timber.e(e) } return lastReadLocator @@ -618,11 +615,7 @@ class FolioPageFragment : Fragment(), @JavascriptInterface fun setHorizontalPageCount(horizontalPageCount: Int) { - Log.v( - LOG_TAG, "-> setHorizontalPageCount = " + horizontalPageCount - + " -> " + spineItem.href - ) - + Timber.v("-> setHorizontalPageCount = %d -> %s", horizontalPageCount, spineItem.href) mWebview!!.setHorizontalPageCount(horizontalPageCount) } @@ -763,7 +756,7 @@ class FolioPageFragment : Fragment(), */ override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - Log.v(LOG_TAG, "-> onSaveInstanceState -> ${spineItem.href}") + Timber.v("-> onSaveInstanceState -> %s", spineItem.href) this.outState = outState outState.putParcelable(BUNDLE_SEARCH_LOCATOR, searchLocatorVisible) @@ -857,7 +850,7 @@ class FolioPageFragment : Fragment(), } fun highlightSearchLocator(searchLocator: SearchLocator) { - Log.v(LOG_TAG, "-> highlightSearchLocator") + Timber.v("-> highlightSearchLocator") this.searchLocatorVisible = searchLocator if (loadingView != null && loadingView!!.visibility != View.VISIBLE) { @@ -871,7 +864,7 @@ class FolioPageFragment : Fragment(), } fun clearSearchLocator() { - Log.v(LOG_TAG, "-> clearSearchLocator -> " + spineItem.href!!) + Timber.v("-> clearSearchLocator -> %s", spineItem.href) mWebview!!.loadUrl(getString(R.string.callClearSelection)) searchLocatorVisible = null } diff --git a/folioreader/src/main/java/com/folioreader/ui/fragment/MediaControllerFragment.kt b/folioreader/src/main/java/com/folioreader/ui/fragment/MediaControllerFragment.kt index b73430221..779456654 100644 --- a/folioreader/src/main/java/com/folioreader/ui/fragment/MediaControllerFragment.kt +++ b/folioreader/src/main/java/com/folioreader/ui/fragment/MediaControllerFragment.kt @@ -4,7 +4,6 @@ import android.app.Dialog import android.os.Build import android.os.Bundle import android.text.Html -import android.util.Log import android.view.KeyEvent import android.view.MotionEvent import android.view.View @@ -25,6 +24,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import org.greenrobot.eventbus.EventBus +import timber.log.Timber class MediaControllerFragment : BottomSheetDialogFragment() { @@ -70,7 +70,7 @@ class MediaControllerFragment : BottomSheetDialogFragment() { private var btnTextColorStyle: StyleableTextView? = null override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - Log.v(LOG_TAG, "-> onCreateDialog") + Timber.v("-> onCreateDialog") bottomSheetDialog = BottomSheetDialog(context!!) val view = View.inflate(context, R.layout.view_audio_player, null) @@ -82,8 +82,8 @@ class MediaControllerFragment : BottomSheetDialogFragment() { mTouchOutsideView.setOnTouchListener { _, event -> if (event.action == MotionEvent.ACTION_DOWN) { - Log.v(LOG_TAG, "-> onTouch -> touch_outside -> ${getView()}") - dialog.hide() + Timber.v("-> onTouch -> touch_outside -> %s", getView()) + dialog?.hide() visible = false return@setOnTouchListener true } @@ -113,12 +113,12 @@ class MediaControllerFragment : BottomSheetDialogFragment() { override fun onStart() { super.onStart() - Log.v(LOG_TAG, "-> onStart") + Timber.v("-> onStart") - dialog.setOnKeyListener { _, keyCode, event -> + dialog?.setOnKeyListener { _, keyCode, event -> if (event.action == MotionEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { - Log.v(LOG_TAG, "-> Back button pressed") - dialog.hide() + Timber.v("-> Back button pressed") + dialog?.hide() visible = false return@setOnKeyListener true } @@ -129,42 +129,42 @@ class MediaControllerFragment : BottomSheetDialogFragment() { bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED if (!visible) - dialog.hide() + dialog?.hide() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - Log.v(LOG_TAG, "-> onSaveInstanceState -> $visible") + Timber.v("-> onSaveInstanceState -> $visible") outState.putBoolean(BUNDLE_IS_VISIBLE, visible) } override fun onViewStateRestored(savedInstanceState: Bundle?) { super.onViewStateRestored(savedInstanceState) - Log.v(LOG_TAG, "-> onViewStateRestored") + Timber.v("-> onViewStateRestored") if (savedInstanceState == null) return visible = savedInstanceState.getBoolean(BUNDLE_IS_VISIBLE) - //Log.v(LOG_TAG, "-> onViewStateRestored -> $visible") + //Timber.v("-> onViewStateRestored -> $visible") } fun show(fragmentManager: FragmentManager) { - Log.v(LOG_TAG, "-> show") + Timber.v("-> show") visible = true if (isAdded) { - //Log.v(LOG_TAG, "-> Is already added") - dialog.show() + //Timber.v("-> Is already added") + dialog?.show() } else { - //Log.v(LOG_TAG, "-> Not added") + //Timber.v("-> Not added") show(fragmentManager, MediaControllerFragment.LOG_TAG) } } override fun onDestroyView() { super.onDestroyView() - Log.v(LOG_TAG, "-> onDestroyView") + Timber.v("-> onDestroyView") } private fun initViewStates() { diff --git a/folioreader/src/main/java/com/folioreader/ui/view/FolioAppBarLayout.kt b/folioreader/src/main/java/com/folioreader/ui/view/FolioAppBarLayout.kt index d9c17483d..b056f3cee 100644 --- a/folioreader/src/main/java/com/folioreader/ui/view/FolioAppBarLayout.kt +++ b/folioreader/src/main/java/com/folioreader/ui/view/FolioAppBarLayout.kt @@ -3,17 +3,11 @@ package com.folioreader.ui.view import android.content.Context import android.graphics.Rect import android.util.AttributeSet -import android.util.Log import androidx.core.view.ViewCompat import com.google.android.material.appbar.AppBarLayout +import timber.log.Timber class FolioAppBarLayout : AppBarLayout { - - companion object { - @JvmField - val LOG_TAG: String = FolioAppBarLayout::class.java.simpleName - } - var navigationBarHeight: Int = 0 var insets: Rect? = null @@ -21,7 +15,7 @@ class FolioAppBarLayout : AppBarLayout { constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets -> - Log.v(LOG_TAG, "-> onApplyWindowInsets") + Timber.v("-> onApplyWindowInsets") // For API level 20 and above this.insets = Rect( @@ -40,7 +34,7 @@ class FolioAppBarLayout : AppBarLayout { } override fun fitSystemWindows(insets: Rect?): Boolean { - Log.v(LOG_TAG, "-> fitSystemWindows") + Timber.v("-> fitSystemWindows") // For API level 19 and below this.insets = Rect(insets) diff --git a/folioreader/src/main/java/com/folioreader/ui/view/FolioSearchView.kt b/folioreader/src/main/java/com/folioreader/ui/view/FolioSearchView.kt index 706502956..0ff99f07b 100644 --- a/folioreader/src/main/java/com/folioreader/ui/view/FolioSearchView.kt +++ b/folioreader/src/main/java/com/folioreader/ui/view/FolioSearchView.kt @@ -4,7 +4,6 @@ import android.app.SearchManager import android.content.ComponentName import android.content.Context import android.util.AttributeSet -import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.ImageView @@ -15,14 +14,9 @@ import androidx.core.graphics.ColorUtils import com.folioreader.Config import com.folioreader.R import com.folioreader.util.UiUtil +import timber.log.Timber class FolioSearchView : SearchView { - - companion object { - @JvmField - val LOG_TAG: String = FolioSearchView::class.java.simpleName - } - private lateinit var searchAutoComplete: SearchView.SearchAutoComplete constructor(context: Context?) : super(context) @@ -30,7 +24,7 @@ class FolioSearchView : SearchView { constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) fun init(componentName: ComponentName, config: Config) { - Log.v(LOG_TAG, "-> init") + Timber.v("-> init") val searchManager: SearchManager = context.getSystemService(Context.SEARCH_SERVICE) as SearchManager setSearchableInfo(searchManager.getSearchableInfo(componentName)) @@ -41,7 +35,7 @@ class FolioSearchView : SearchView { } private fun adjustLayout() { - Log.v(LOG_TAG, "-> adjustLayout") + Timber.v("-> adjustLayout") // Hide searchHintIcon val searchMagIcon: View = findViewById(R.id.search_mag_icon) @@ -53,7 +47,7 @@ class FolioSearchView : SearchView { } private fun applyTheme(config: Config) { - Log.v(LOG_TAG, "-> applyTheme") + Timber.v("-> applyTheme") val searchCloseButton: ImageView = findViewById(R.id.search_close_btn) UiUtil.setColorIntToDrawable(config.themeColor, searchCloseButton.drawable) diff --git a/folioreader/src/main/java/com/folioreader/ui/view/FolioWebView.kt b/folioreader/src/main/java/com/folioreader/ui/view/FolioWebView.kt index 7ee774e56..24a04a684 100644 --- a/folioreader/src/main/java/com/folioreader/ui/view/FolioWebView.kt +++ b/folioreader/src/main/java/com/folioreader/ui/view/FolioWebView.kt @@ -10,7 +10,6 @@ import android.os.Handler import android.os.Looper import android.util.AttributeSet import android.util.DisplayMetrics -import android.util.Log import android.view.* import android.view.ActionMode.Callback import android.view.ViewGroup.LayoutParams.WRAP_CONTENT @@ -40,6 +39,7 @@ import dalvik.system.PathClassLoader import kotlinx.android.synthetic.main.text_selection.view.* import org.json.JSONObject import org.springframework.util.ReflectionUtils +import timber.log.Timber import java.lang.ref.WeakReference /** @@ -48,8 +48,6 @@ import java.lang.ref.WeakReference class FolioWebView : WebView { companion object { - - val LOG_TAG: String = FolioWebView::class.java.simpleName private const val IS_SCROLLING_CHECK_TIMER = 100 private const val IS_SCROLLING_CHECK_MAX_DURATION = 10000 @@ -57,19 +55,19 @@ class FolioWebView : WebView { fun onWebViewConsoleMessage(cm: ConsoleMessage, LOG_TAG: String, msg: String): Boolean { when (cm.messageLevel()) { ConsoleMessage.MessageLevel.LOG -> { - Log.v(LOG_TAG, msg) + Timber.tag(LOG_TAG).v(msg) return true } ConsoleMessage.MessageLevel.DEBUG, ConsoleMessage.MessageLevel.TIP -> { - Log.d(LOG_TAG, msg) + Timber.tag(LOG_TAG).d(msg) return true } ConsoleMessage.MessageLevel.WARNING -> { - Log.w(LOG_TAG, msg) + Timber.tag(LOG_TAG).w(msg) return true } ConsoleMessage.MessageLevel.ERROR -> { - Log.e(LOG_TAG, msg) + Timber.tag(LOG_TAG).e(msg) return true } else -> return false @@ -157,18 +155,18 @@ class FolioWebView : WebView { private inner class HorizontalGestureListener : GestureDetector.SimpleOnGestureListener() { override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean { - //Log.d(LOG_TAG, "-> onScroll -> e1 = " + e1 + ", e2 = " + e2 + ", distanceX = " + distanceX + ", distanceY = " + distanceY); + //Timber.d("-> onScroll -> e1 = " + e1 + ", e2 = " + e2 + ", distanceX = " + distanceX + ", distanceY = " + distanceY); lastScrollType = LastScrollType.USER return false } override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean { - //Log.d(LOG_TAG, "-> onFling -> e1 = " + e1 + ", e2 = " + e2 + ", velocityX = " + velocityX + ", velocityY = " + velocityY); + //Timber.d("-> onFling -> e1 = " + e1 + ", e2 = " + e2 + ", velocityX = " + velocityX + ", velocityY = " + velocityY); if (!webViewPager.isScrolling) { // Need to complete the scroll as ViewPager thinks these touch events should not // scroll it's pages. - //Log.d(LOG_TAG, "-> onFling -> completing scroll"); + //Timber.d("-> onFling -> completing scroll"); uiHandler.postDelayed({ // Delayed to avoid inconsistency of scrolling in WebView scrollTo(getScrollXPixelsForPage(webViewPager!!.currentItem), 0) @@ -180,7 +178,7 @@ class FolioWebView : WebView { } override fun onDown(event: MotionEvent?): Boolean { - //Log.v(LOG_TAG, "-> onDown -> " + event.toString()); + //Timber.v("-> onDown -> " + event.toString()); eventActionDown = MotionEvent.obtain(event) super@FolioWebView.onTouchEvent(event) @@ -190,7 +188,7 @@ class FolioWebView : WebView { @JavascriptInterface fun dismissPopupWindow(): Boolean { - Log.d(LOG_TAG, "-> dismissPopupWindow -> " + parentFragment.spineItem?.href) + Timber.d("-> dismissPopupWindow -> %s", parentFragment.spineItem?.href) val wasShowing = popupWindow.isShowing if (Looper.getMainLooper().thread == Thread.currentThread()) { popupWindow.dismiss() @@ -205,7 +203,7 @@ class FolioWebView : WebView { override fun destroy() { super.destroy() - Log.d(LOG_TAG, "-> destroy") + Timber.d("-> destroy") dismissPopupWindow() destroyed = true } @@ -213,13 +211,13 @@ class FolioWebView : WebView { private inner class VerticalGestureListener : GestureDetector.SimpleOnGestureListener() { override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean { - //Log.v(LOG_TAG, "-> onScroll -> e1 = " + e1 + ", e2 = " + e2 + ", distanceX = " + distanceX + ", distanceY = " + distanceY); + //Timber.v("-> onScroll -> e1 = " + e1 + ", e2 = " + e2 + ", distanceX = " + distanceX + ", distanceY = " + distanceY); lastScrollType = LastScrollType.USER return false } override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean { - //Log.v(LOG_TAG, "-> onFling -> e1 = " + e1 + ", e2 = " + e2 + ", velocityX = " + velocityX + ", velocityY = " + velocityY); + //Timber.v("-> onFling -> e1 = " + e1 + ", e2 = " + e2 + ", velocityX = " + velocityX + ", velocityY = " + velocityY); lastScrollType = LastScrollType.USER return false } @@ -230,7 +228,7 @@ class FolioWebView : WebView { constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) private fun init() { - Log.v(LOG_TAG, "-> init") + Timber.v("-> init") uiHandler = Handler() displayMetrics = resources.displayMetrics @@ -246,7 +244,7 @@ class FolioWebView : WebView { } fun initViewTextSelection() { - Log.v(LOG_TAG, "-> initViewTextSelection") + Timber.v("-> initViewTextSelection") val textSelectionMiddleDrawable = ContextCompat.getDrawable( context, @@ -265,28 +263,28 @@ class FolioWebView : WebView { viewTextSelection.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) viewTextSelection.yellowHighlight.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> yellowHighlight") + Timber.v("-> onClick -> yellowHighlight") onHighlightColorItemsClicked(HighlightStyle.Yellow, false) } viewTextSelection.greenHighlight.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> greenHighlight") + Timber.v("-> onClick -> greenHighlight") onHighlightColorItemsClicked(HighlightStyle.Green, false) } viewTextSelection.blueHighlight.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> blueHighlight") + Timber.v("-> onClick -> blueHighlight") onHighlightColorItemsClicked(HighlightStyle.Blue, false) } viewTextSelection.pinkHighlight.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> pinkHighlight") + Timber.v("-> onClick -> pinkHighlight") onHighlightColorItemsClicked(HighlightStyle.Pink, false) } viewTextSelection.underlineHighlight.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> underlineHighlight") + Timber.v("-> onClick -> underlineHighlight") onHighlightColorItemsClicked(HighlightStyle.Underline, false) } viewTextSelection.deleteHighlight.setOnClickListener { - Log.v(LOG_TAG, "-> onClick -> deleteHighlight") + Timber.v("-> onClick -> deleteHighlight") dismissPopupWindow() loadUrl("javascript:clearSelection()") loadUrl("javascript:deleteThisHighlight()") @@ -313,20 +311,20 @@ class FolioWebView : WebView { when (id) { R.id.copySelection -> { - Log.v(LOG_TAG, "-> onTextSelectionItemClicked -> copySelection -> $selectedText") + Timber.v("-> onTextSelectionItemClicked -> copySelection -> $selectedText") UiUtil.copyToClipboard(context, selectedText) Toast.makeText(context, context.getString(R.string.copied), Toast.LENGTH_SHORT).show() } R.id.shareSelection -> { - Log.v(LOG_TAG, "-> onTextSelectionItemClicked -> shareSelection -> $selectedText") + Timber.v("-> onTextSelectionItemClicked -> shareSelection -> $selectedText") UiUtil.share(context, selectedText) } R.id.defineSelection -> { - Log.v(LOG_TAG, "-> onTextSelectionItemClicked -> defineSelection -> $selectedText") + Timber.v("-> onTextSelectionItemClicked -> defineSelection -> $selectedText") uiHandler.post { showDictDialog(selectedText) } } else -> { - Log.w(LOG_TAG, "-> onTextSelectionItemClicked -> unknown id = $id") + Timber.w("-> onTextSelectionItemClicked -> unknown id = $id") } } } @@ -346,7 +344,7 @@ class FolioWebView : WebView { @JavascriptInterface fun deleteThisHighlight(id: String?) { - Log.d(LOG_TAG, "-> deleteThisHighlight") + Timber.d("-> deleteThisHighlight") if (id.isNullOrEmpty()) return @@ -389,7 +387,7 @@ class FolioWebView : WebView { } override fun onTouchEvent(event: MotionEvent?): Boolean { - //Log.v(LOG_TAG, "-> onTouchEvent -> " + AppUtil.actionToString(event.getAction())); + //Timber.v("-> onTouchEvent -> " + AppUtil.actionToString(event.getAction())); if (event == null) return false @@ -410,7 +408,7 @@ class FolioWebView : WebView { } private fun computeHorizontalScroll(event: MotionEvent): Boolean { - //Log.v(LOG_TAG, "-> computeHorizontalScroll"); + //Timber.v("-> computeHorizontalScroll"); // Rare condition in fast scrolling if (!::webViewPager.isInitialized) @@ -422,12 +420,12 @@ class FolioWebView : WebView { } fun getScrollXDpForPage(page: Int): Int { - //Log.v(LOG_TAG, "-> getScrollXDpForPage -> page = " + page); + //Timber.v("-> getScrollXDpForPage -> page = " + page); return page * pageWidthCssDp } fun getScrollXPixelsForPage(page: Int): Int { - //Log.v(LOG_TAG, "-> getScrollXPixelsForPage -> page = " + page); + //Timber.v("-> getScrollXPixelsForPage -> page = " + page); return Math.ceil((page * pageWidthCssPixels).toDouble()).toInt() } @@ -442,7 +440,7 @@ class FolioWebView : WebView { override fun scrollTo(x: Int, y: Int) { super.scrollTo(x, y) - //Log.d(LOG_TAG, "-> scrollTo -> x = " + x); + //Timber.d("-> scrollTo -> x = " + x); lastScrollType = LastScrollType.PROGRAMMATIC } @@ -451,7 +449,7 @@ class FolioWebView : WebView { super.onScrollChanged(l, t, oldl, oldt) if (lastScrollType == LastScrollType.USER) { - //Log.d(LOG_TAG, "-> onScrollChanged -> scroll initiated by user"); + //Timber.d("-> onScrollChanged -> scroll initiated by user"); parentFragment.searchLocatorVisible = null } @@ -469,12 +467,12 @@ class FolioWebView : WebView { private inner class TextSelectionCb : ActionMode.Callback { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - Log.d(LOG_TAG, "-> onCreateActionMode") + Timber.d("-> onCreateActionMode") return true } override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - Log.d(LOG_TAG, "-> onPrepareActionMode") + Timber.d("-> onPrepareActionMode") evaluateJavascript("javascript:getSelectionRect()") { value -> val rectJson = JSONObject(value) @@ -487,12 +485,12 @@ class FolioWebView : WebView { } override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - Log.d(LOG_TAG, "-> onActionItemClicked") + Timber.d("-> onActionItemClicked") return false } override fun onDestroyActionMode(mode: ActionMode) { - Log.d(LOG_TAG, "-> onDestroyActionMode") + Timber.d("-> onDestroyActionMode") dismissPopupWindow() } } @@ -501,28 +499,28 @@ class FolioWebView : WebView { private inner class TextSelectionCb2 : ActionMode.Callback2() { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - Log.d(LOG_TAG, "-> onCreateActionMode") + Timber.d("-> onCreateActionMode") menu.clear() return true } override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - Log.d(LOG_TAG, "-> onPrepareActionMode") + Timber.d("-> onPrepareActionMode") return false } override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - Log.d(LOG_TAG, "-> onActionItemClicked") + Timber.d("-> onActionItemClicked") return false } override fun onDestroyActionMode(mode: ActionMode) { - Log.d(LOG_TAG, "-> onDestroyActionMode") + Timber.d("-> onDestroyActionMode") dismissPopupWindow() } override fun onGetContentRect(mode: ActionMode, view: View, outRect: Rect) { - Log.d(LOG_TAG, "-> onGetContentRect") + Timber.d("-> onGetContentRect") evaluateJavascript("javascript:getSelectionRect()") { value -> val rectJson = JSONObject(value) @@ -535,7 +533,7 @@ class FolioWebView : WebView { } override fun startActionMode(callback: Callback): ActionMode { - Log.d(LOG_TAG, "-> startActionMode") + Timber.d("-> startActionMode") textSelectionCb = TextSelectionCb() actionMode = super.startActionMode(textSelectionCb) @@ -544,8 +542,7 @@ class FolioWebView : WebView { /*try { applyThemeColorToHandles() } catch (e: Exception) { - Log.w(LOG_TAG, "-> startActionMode -> Failed to apply theme colors to selection " + - "handles", e) + Timber.w(e, "-> startActionMode -> Failed to apply theme colors to selection handles") }*/ return actionMode as ActionMode @@ -556,7 +553,7 @@ class FolioWebView : WebView { @RequiresApi(api = Build.VERSION_CODES.M) override fun startActionMode(callback: Callback, type: Int): ActionMode { - Log.d(LOG_TAG, "-> startActionMode") + Timber.d("-> startActionMode") textSelectionCb2 = TextSelectionCb2() actionMode = super.startActionMode(textSelectionCb2, type) @@ -565,8 +562,7 @@ class FolioWebView : WebView { /*try { applyThemeColorToHandles() } catch (e: Exception) { - Log.w(LOG_TAG, "-> startActionMode -> Failed to apply theme colors to selection " + - "handles", e) + Timber.w(e, "-> startActionMode -> Failed to apply theme colors to selection handles") }*/ return actionMode as ActionMode @@ -576,7 +572,7 @@ class FolioWebView : WebView { } private fun applyThemeColorToHandles() { - Log.v(LOG_TAG, "-> applyThemeColorToHandles") + Timber.v("-> applyThemeColorToHandles") if (Build.VERSION.SDK_INT < 23) { val folioActivityRef: WeakReference = folioActivityCallback.activity @@ -662,38 +658,35 @@ class FolioWebView : WebView { currentSelectionRect.top = (top * density).toInt() currentSelectionRect.right = (right * density).toInt() currentSelectionRect.bottom = (bottom * density).toInt() - Log.d(LOG_TAG, "-> setSelectionRect -> $currentSelectionRect") + Timber.d("-> setSelectionRect -> $currentSelectionRect") computeTextSelectionRect(currentSelectionRect) uiHandler.post { showTextSelectionPopup() } } private fun computeTextSelectionRect(currentSelectionRect: Rect) { - Log.v(LOG_TAG, "-> computeTextSelectionRect") + Timber.v("-> computeTextSelectionRect") val viewportRect = folioActivityCallback.getViewportRect(DisplayUnit.PX) - Log.d(LOG_TAG, "-> viewportRect -> $viewportRect") + Timber.d("-> viewportRect -> $viewportRect") if (!Rect.intersects(viewportRect, currentSelectionRect)) { - Log.i(LOG_TAG, "-> currentSelectionRect doesn't intersects viewportRect") + Timber.i("-> currentSelectionRect doesn't intersects viewportRect") uiHandler.post { popupWindow.dismiss() uiHandler.removeCallbacks(isScrollingRunnable) } return } - Log.i(LOG_TAG, "-> currentSelectionRect intersects viewportRect") + Timber.i("-> currentSelectionRect intersects viewportRect") if (selectionRect == currentSelectionRect) { - Log.i( - LOG_TAG, "-> setSelectionRect -> currentSelectionRect is equal to previous " + - "selectionRect so no need to computeTextSelectionRect and show popupWindow again" - ) + Timber.i("-> setSelectionRect -> currentSelectionRect is equal to previous " + + "selectionRect so no need to computeTextSelectionRect and show popupWindow again") return } - Log.i( - LOG_TAG, "-> setSelectionRect -> currentSelectionRect is not equal to previous " + + Timber.i("-> setSelectionRect -> currentSelectionRect is not equal to previous " + "selectionRect so computeTextSelectionRect and show popupWindow" ) selectionRect = currentSelectionRect @@ -703,8 +696,8 @@ class FolioWebView : WebView { val belowSelectionRect = Rect(viewportRect) belowSelectionRect.top = selectionRect.bottom + handleHeight - //Log.d(LOG_TAG, "-> aboveSelectionRect -> " + aboveSelectionRect); - //Log.d(LOG_TAG, "-> belowSelectionRect -> " + belowSelectionRect); + //Timber.d("-> aboveSelectionRect -> " + aboveSelectionRect); + //Timber.d("-> belowSelectionRect -> " + belowSelectionRect); // Priority to show popupWindow will be as following - // 1. Show popupWindow below selectionRect, if space available @@ -716,11 +709,11 @@ class FolioWebView : WebView { popupRect.top = belowSelectionRect.top popupRect.right = popupRect.left + viewTextSelection.measuredWidth popupRect.bottom = popupRect.top + viewTextSelection.measuredHeight - //Log.d(LOG_TAG, "-> Pre decision popupRect -> " + popupRect); + //Timber.d("-> Pre decision popupRect -> " + popupRect); val popupY: Int if (belowSelectionRect.contains(popupRect)) { - Log.i(LOG_TAG, "-> show below") + Timber.i("-> show below") popupY = belowSelectionRect.top } else { @@ -730,12 +723,12 @@ class FolioWebView : WebView { popupRect.bottom = popupRect.top + viewTextSelection.measuredHeight if (aboveSelectionRect.contains(popupRect)) { - Log.i(LOG_TAG, "-> show above") + Timber.i("-> show above") popupY = aboveSelectionRect.bottom - popupRect.height() } else { - Log.i(LOG_TAG, "-> show in middle") + Timber.i("-> show in middle") val popupYDiff = (viewTextSelection.measuredHeight - selectionRect.height()) / 2 popupY = selectionRect.top - popupYDiff } @@ -745,7 +738,7 @@ class FolioWebView : WebView { val popupX = selectionRect.left - popupXDiff popupRect.offsetTo(popupX, popupY) - //Log.d(LOG_TAG, "-> Post decision popupRect -> " + popupRect); + //Timber.d("-> Post decision popupRect -> " + popupRect); // Check if popupRect left side is going outside of the viewportRect if (popupRect.left < viewportRect.left) { @@ -762,8 +755,8 @@ class FolioWebView : WebView { } private fun showTextSelectionPopup() { - Log.v(LOG_TAG, "-> showTextSelectionPopup") - Log.d(LOG_TAG, "-> showTextSelectionPopup -> To be laid out popupRect -> $popupRect") + Timber.v("-> showTextSelectionPopup") + Timber.d("-> showTextSelectionPopup -> To be laid out popupRect -> %s", popupRect) popupWindow.dismiss() oldScrollX = scrollX @@ -777,7 +770,7 @@ class FolioWebView : WebView { lastTouchAction == MotionEvent.ACTION_MOVE if (oldScrollX == currentScrollX && oldScrollY == currentScrollY && !inTouchMode) { - Log.i(LOG_TAG, "-> Stopped scrolling, show Popup") + Timber.i("-> Stopped scrolling, show Popup") popupWindow.dismiss() popupWindow = PopupWindow(viewTextSelection, WRAP_CONTENT, WRAP_CONTENT) popupWindow.isClippingEnabled = false @@ -786,7 +779,7 @@ class FolioWebView : WebView { popupRect.left, popupRect.top ) } else { - Log.i(LOG_TAG, "-> Still scrolling, don't show Popup") + Timber.i("-> Still scrolling, don't show Popup") oldScrollX = currentScrollX oldScrollY = currentScrollY isScrollingCheckDuration += IS_SCROLLING_CHECK_TIMER diff --git a/folioreader/src/main/java/com/folioreader/ui/view/LoadingView.java b/folioreader/src/main/java/com/folioreader/ui/view/LoadingView.java index ae650d968..efaff5682 100644 --- a/folioreader/src/main/java/com/folioreader/ui/view/LoadingView.java +++ b/folioreader/src/main/java/com/folioreader/ui/view/LoadingView.java @@ -28,8 +28,6 @@ public void run() { } }; - private static final String LOG_TAG = LoadingView.class.getSimpleName(); - public LoadingView(Context context) { super(context); init(context, null, 0); @@ -86,7 +84,7 @@ public void updateTheme() { @SuppressWarnings("unused") @JavascriptInterface public void show() { - //Log.d(LOG_TAG, "-> show"); + //Timber.d("-> show"); handler.removeCallbacks(hideRunnable); handler.post(new Runnable() { @@ -103,7 +101,7 @@ public void run() { @SuppressWarnings("unused") @JavascriptInterface public void hide() { - //Log.d(LOG_TAG, "-> hide"); + //Timber.d("-> hide"); handler.removeCallbacks(hideRunnable); handler.post(new Runnable() { @@ -117,7 +115,7 @@ public void run() { @SuppressWarnings("unused") @JavascriptInterface public void visible() { - //Log.d(LOG_TAG, "-> visible"); + //Timber.d("-> visible"); handler.post(new Runnable() { @Override public void run() { @@ -129,7 +127,7 @@ public void run() { @SuppressWarnings("unused") @JavascriptInterface public void invisible() { - //Log.d(LOG_TAG, "-> invisible"); + //Timber.d("-> invisible"); handler.post(new Runnable() { @Override public void run() { diff --git a/folioreader/src/main/java/com/folioreader/ui/view/WebViewPager.kt b/folioreader/src/main/java/com/folioreader/ui/view/WebViewPager.kt index e81f1a692..37925e560 100644 --- a/folioreader/src/main/java/com/folioreader/ui/view/WebViewPager.kt +++ b/folioreader/src/main/java/com/folioreader/ui/view/WebViewPager.kt @@ -3,21 +3,15 @@ package com.folioreader.ui.view import android.content.Context import android.os.Handler import android.util.AttributeSet -import android.util.Log import android.view.* import android.webkit.JavascriptInterface import androidx.core.view.GestureDetectorCompat import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.ViewPager import com.folioreader.R +import timber.log.Timber class WebViewPager : ViewPager { - - companion object { - @JvmField - val LOG_TAG: String = WebViewPager::class.java.simpleName - } - private var horizontalPageCount: Int = 0 private var folioWebView: FolioWebView? = null private var takeOverScrolling: Boolean = false @@ -44,26 +38,26 @@ class WebViewPager : ViewPager { addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { - // Log.d(LOG_TAG, "-> onPageScrolled -> position = " + position + + // Timber.d("-> onPageScrolled -> position = " + position + // ", positionOffset = " + positionOffset + ", positionOffsetPixels = " + positionOffsetPixels); isScrolling = true if (takeOverScrolling && folioWebView != null) { val scrollX = folioWebView!!.getScrollXPixelsForPage(position) + positionOffsetPixels - //Log.d(LOG_TAG, "-> onPageScrolled -> scrollX = " + scrollX); + //Timber.d("-> onPageScrolled -> scrollX = " + scrollX); folioWebView!!.scrollTo(scrollX, 0) } if (positionOffsetPixels == 0) { - //Log.d(LOG_TAG, "-> onPageScrolled -> takeOverScrolling = false"); + //Timber.d("-> onPageScrolled -> takeOverScrolling = false"); takeOverScrolling = false isScrolling = false } } override fun onPageSelected(position: Int) { - Log.v(LOG_TAG, "-> onPageSelected -> $position") + Timber.v("-> onPageSelected -> $position") } override fun onPageScrollStateChanged(state: Int) {} @@ -80,7 +74,7 @@ class WebViewPager : ViewPager { } fun setHorizontalPageCount(horizontalPageCount: Int) { - //Log.d(LOG_TAG, "-> horizontalPageCount = " + horizontalPageCount); + //Timber.d("-> horizontalPageCount = " + horizontalPageCount); this.horizontalPageCount = horizontalPageCount adapter = WebViewPagerAdapter() @@ -92,7 +86,7 @@ class WebViewPager : ViewPager { @JavascriptInterface fun setCurrentPage(pageIndex: Int) { - Log.v(LOG_TAG, "-> setCurrentItem -> pageIndex = $pageIndex") + Timber.v("-> setCurrentItem -> pageIndex = $pageIndex") uiHandler!!.post { setCurrentItem(pageIndex, false) } } @@ -117,32 +111,32 @@ class WebViewPager : ViewPager { } override fun onSingleTapUp(e: MotionEvent?): Boolean { - //Log.d(LOG_TAG, "-> onSingleTapUp"); + //Timber.d("-> onSingleTapUp"); lastGestureType = LastGestureType.OnSingleTapUp return false } override fun onLongPress(e: MotionEvent?) { super.onLongPress(e) - //Log.d(LOG_TAG, "-> onLongPress -> " + e); + //Timber.d("-> onLongPress -> " + e); lastGestureType = LastGestureType.OnLongPress } override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean { - //Log.v(LOG_TAG, "-> onScroll -> e1 = " + e1 + ", e2 = " + e2 + ", distanceX = " + distanceX + ", distanceY = " + distanceY); + //Timber.v("-> onScroll -> e1 = " + e1 + ", e2 = " + e2 + ", distanceX = " + distanceX + ", distanceY = " + distanceY); lastGestureType = LastGestureType.OnScroll return false } override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean { - //Log.d(LOG_TAG, "-> onFling -> e1 = " + e1 + ", e2 = " + e2 + ", velocityX = " + velocityX + ", velocityY = " + velocityY); + //Timber.d("-> onFling -> e1 = " + e1 + ", e2 = " + e2 + ", velocityX = " + velocityX + ", velocityY = " + velocityY); lastGestureType = LastGestureType.OnFling return false } } override fun onTouchEvent(event: MotionEvent?): Boolean { - //Log.d(LOG_TAG, "-> onTouchEvent -> " + AppUtil.actionToString(event.getAction())); + //Timber.d("-> onTouchEvent -> " + AppUtil.actionToString(event.getAction())); if (event == null) return false @@ -159,7 +153,7 @@ class WebViewPager : ViewPager { if (event.action == MotionEvent.ACTION_UP) { if (lastGestureType == LastGestureType.OnScroll || lastGestureType == LastGestureType.OnFling) { - //Log.d(LOG_TAG, "-> onTouchEvent -> takeOverScrolling = true, " + "lastGestureType = " + lastGestureType); + //Timber.d("-> onTouchEvent -> takeOverScrolling = true, " + "lastGestureType = " + lastGestureType); takeOverScrolling = true } lastGestureType = null diff --git a/folioreader/src/main/java/com/folioreader/util/AppUtil.kt b/folioreader/src/main/java/com/folioreader/util/AppUtil.kt index 9b7958f44..2ec5e21c6 100644 --- a/folioreader/src/main/java/com/folioreader/util/AppUtil.kt +++ b/folioreader/src/main/java/com/folioreader/util/AppUtil.kt @@ -3,7 +3,6 @@ package com.folioreader.util import android.app.Activity import android.content.Context import android.os.Build -import android.util.Log import android.view.MotionEvent import android.view.View import android.view.inputmethod.InputMethodManager @@ -13,6 +12,7 @@ import com.folioreader.util.SharedPreferenceUtil.getSharedPreferencesString import org.json.JSONArray import org.json.JSONException import org.json.JSONObject +import timber.log.Timber import java.net.ServerSocket import java.net.URLConnection import java.text.SimpleDateFormat @@ -26,7 +26,6 @@ class AppUtil { companion object { private val SMIL_ELEMENTS = "smil_elements" - private val LOG_TAG = AppUtil::class.java.simpleName private val FOLIO_READER_ROOT = "folioreader" private enum class FileType { @@ -52,7 +51,7 @@ class AppUtil { map[key] = value!!.toString() } } catch (e: JSONException) { - Log.e(LOG_TAG, "toMap failed", e) + Timber.e(e, "toMap failed") } return map @@ -102,7 +101,7 @@ class AppUtil { obj.toString() ) } catch (e: JSONException) { - Log.e(LOG_TAG, e.message) + Timber.e(e) } } @@ -115,7 +114,7 @@ class AppUtil { val jsonObject = JSONObject(json) return Config(jsonObject) } catch (e: JSONException) { - Log.e(LOG_TAG, e.message) + Timber.e(e) return null } @@ -170,14 +169,14 @@ class AppUtil { try { serverSocket = ServerSocket(portNumber) - Log.d(LOG_TAG, "-> getAvailablePortNumber -> portNumber $portNumber available") + Timber.d("-> getAvailablePortNumber -> portNumber $portNumber available") portNumberAvailable = portNumber } catch (e: Exception) { serverSocket = ServerSocket(0) portNumberAvailable = serverSocket.localPort - Log.w( - LOG_TAG, "-> getAvailablePortNumber -> portNumber $portNumber not available, " + - "$portNumberAvailable is available" + Timber.w( + "-> getAvailablePortNumber -> portNumber %d not available, %d is available", + portNumber, portNumberAvailable ) } finally { serverSocket?.close() diff --git a/folioreader/src/main/java/com/folioreader/util/UiUtil.java b/folioreader/src/main/java/com/folioreader/util/UiUtil.java index 8bdb3cb80..84e774b62 100644 --- a/folioreader/src/main/java/com/folioreader/util/UiUtil.java +++ b/folioreader/src/main/java/com/folioreader/util/UiUtil.java @@ -18,7 +18,6 @@ import android.os.Build; import android.text.TextUtils; import android.util.AttributeSet; -import android.util.Log; import android.util.StateSet; import android.view.View; import android.view.Window; @@ -34,6 +33,7 @@ import com.folioreader.ui.view.UnderlinedTextView; import org.json.JSONException; import org.json.JSONObject; +import timber.log.Timber; import java.lang.ref.SoftReference; import java.lang.reflect.Field; @@ -43,9 +43,6 @@ * Created by mahavir on 3/30/16. */ public class UiUtil { - - private static final String LOG_TAG = UiUtil.class.getSimpleName(); - public static void setCustomFont(View view, Context ctx, AttributeSet attrs, int[] attributeSet, int fontId) { TypedArray a = ctx.obtainStyledAttributes(attrs, attributeSet); @@ -66,7 +63,7 @@ public static boolean setCustomFont(View view, Context ctx, String asset) { ((Button) view).setTypeface(tf); } } catch (Exception e) { - Log.e("AppUtil", "Could not get typface " + asset); + Timber.e("Could not get typface %s", asset); return false; } @@ -168,7 +165,7 @@ public static void setColorResToDrawable(@ColorRes int colorResId, Drawable draw int color = ContextCompat.getColor(AppContext.get(), colorResId); drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); } catch (Resources.NotFoundException e) { - Log.e(LOG_TAG, "-> Exception in setColorResToDrawable -> ", e); + Timber.e(e, "-> Exception in setColorResToDrawable -> "); } } @@ -215,7 +212,7 @@ public static void setEditTextCursorColor(EditText editText, @ColorInt int color } } catch (Exception e) { - Log.e(LOG_TAG, "-> ", e); + Timber.e(e); } } @@ -281,7 +278,7 @@ public static void setEditTextHandleColor(EditText editText, @ColorInt int color fieldCenter.set(editor, drawableCenter); } } catch (Exception e) { - Log.e(LOG_TAG, "-> ", e); + Timber.e(e); } } @@ -328,7 +325,7 @@ public static String rectToDOMRectJson(Rect rect) { jsonObject.put("height", rect.height()); return jsonObject.toString(); } catch (JSONException e) { - Log.e(LOG_TAG, "-> ", e); + Timber.e(e); } return null; } diff --git a/folioreader/src/main/java/com/folioreader/viewmodels/SearchViewModel.kt b/folioreader/src/main/java/com/folioreader/viewmodels/SearchViewModel.kt index 446077cb8..b02312f5f 100644 --- a/folioreader/src/main/java/com/folioreader/viewmodels/SearchViewModel.kt +++ b/folioreader/src/main/java/com/folioreader/viewmodels/SearchViewModel.kt @@ -1,7 +1,6 @@ package com.folioreader.viewmodels import android.os.Bundle -import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.folioreader.FolioReader @@ -13,13 +12,9 @@ import org.readium.r2.shared.Locator import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import timber.log.Timber class SearchViewModel : ViewModel() { - - companion object { - val LOG_TAG: String = SearchViewModel::class.java.simpleName - } - var liveAdapterDataBundle: MutableLiveData = MutableLiveData() private var r2StreamerApi: R2StreamerApi? = FolioReader.get().r2StreamerApi private var searchCallCount: Int = 0 @@ -32,7 +27,7 @@ class SearchViewModel : ViewModel() { } fun init() { - Log.v(LOG_TAG, "-> init") + Timber.v("-> init") val bundle = Bundle() bundle.putString(ListViewType.KEY, ListViewType.INIT_VIEW.toString()) @@ -41,8 +36,8 @@ class SearchViewModel : ViewModel() { } fun search(spineSize: Int, query: String) { - //Log.v(LOG_TAG, "-> search") - Log.d(LOG_TAG, "-> search -> spineSize = $spineSize, query = $query") + //Timber.v("-> search") + Timber.d("-> search -> spineSize = $spineSize, query = $query") cancelAllSearchCalls() @@ -60,7 +55,7 @@ class SearchViewModel : ViewModel() { } fun cancelAllSearchCalls() { - Log.v(LOG_TAG, "-> cancelAllSearchCalls") + Timber.v("-> cancelAllSearchCalls") searchCallList.forEach { it.cancel() } searchCallList.clear() @@ -68,14 +63,14 @@ class SearchViewModel : ViewModel() { inner class SearchApiCallback : Callback> { override fun onFailure(call: Call>, t: Throwable) { - Log.e(LOG_TAG, "-> search -> onFailure", t) + Timber.e(t, "-> search -> onFailure") val bundle = processSingleSearchResponse(call, null, t) mergeSearchResponse(bundle, call) } override fun onResponse(call: Call>, response: Response>) { - Log.d(LOG_TAG, "-> search -> onResponse") + Timber.d("-> search -> onResponse") val bundle = processSingleSearchResponse(call, response, null) mergeSearchResponse(bundle, call) @@ -83,7 +78,7 @@ class SearchViewModel : ViewModel() { } private fun mergeSearchResponse(bundle: Bundle, call: Call>) { - Log.v(LOG_TAG, "-> mergeSearchResponse") + Timber.v("-> mergeSearchResponse") if (call.isCanceled) return @@ -146,7 +141,7 @@ class SearchViewModel : ViewModel() { response: Response>?, t: Throwable? ): Bundle { - Log.d(LOG_TAG, "-> processSingleSearchResponse") + Timber.d("-> processSingleSearchResponse") val locatorList = response?.body() return when { @@ -169,7 +164,7 @@ class SearchViewModel : ViewModel() { } private fun initSearchLocatorList(locatorList: MutableList): Bundle { - Log.v(LOG_TAG, "-> initSearchLocatorList") + Timber.v("-> initSearchLocatorList") val searchLocatorList: MutableList = mutableListOf() diff --git a/sample/src/main/java/com/folioreader/android/sample/HomeActivity.java b/sample/src/main/java/com/folioreader/android/sample/HomeActivity.java index 25c63427d..91916e12b 100644 --- a/sample/src/main/java/com/folioreader/android/sample/HomeActivity.java +++ b/sample/src/main/java/com/folioreader/android/sample/HomeActivity.java @@ -16,7 +16,6 @@ package com.folioreader.android.sample; import android.os.Bundle; -import android.util.Log; import android.view.View; import android.widget.Toast; import androidx.annotation.Nullable; @@ -31,6 +30,7 @@ import com.folioreader.util.AppUtil; import com.folioreader.util.OnHighlightListener; import com.folioreader.util.ReadLocatorListener; +import timber.log.Timber; import java.io.BufferedReader; import java.io.IOException; @@ -42,7 +42,6 @@ public class HomeActivity extends AppCompatActivity implements OnHighlightListener, ReadLocatorListener, FolioReader.OnClosedListener { - private static final String LOG_TAG = HomeActivity.class.getSimpleName(); private FolioReader folioReader; @Override @@ -97,7 +96,7 @@ private ReadLocator getLastReadLocator() { @Override public void saveReadLocator(ReadLocator readLocator) { - Log.i(LOG_TAG, "-> saveReadLocator -> " + readLocator.toJson()); + Timber.i("-> saveReadLocator -> %s", readLocator.toJson()); } /* @@ -149,13 +148,13 @@ private String loadAssetTextAsString(String name) { } return buf.toString(); } catch (IOException e) { - Log.e("HomeActivity", "Error opening asset " + name); + Timber.e("Error opening asset %s", name); } finally { if (in != null) { try { in.close(); } catch (IOException e) { - Log.e("HomeActivity", "Error closing asset " + name); + Timber.e("Error closing asset %s", name); } } } @@ -177,6 +176,6 @@ public void onHighlight(HighLight highlight, HighLight.HighLightAction type) { @Override public void onFolioReaderClosed() { - Log.v(LOG_TAG, "-> onFolioReaderClosed"); + Timber.v("-> onFolioReaderClosed"); } } \ No newline at end of file