Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #272 from readium/fixes/debug
Browse files Browse the repository at this point in the history
wrap timber logs to only show in debug builds and source formatting
  • Loading branch information
aferditamuriqi committed Dec 28, 2019
2 parents 1f0e7cd + 61e8747 commit 233ca1c
Show file tree
Hide file tree
Showing 33 changed files with 135 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/captures
.externalNativeBuild
*.aab
r2-testapp/release
12 changes: 6 additions & 6 deletions r2-testapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ group = 'com.github.readium'
int major = 2
int minor = 1
int patch = 0
int build = 17
int build = 22
String type = ""

def version = "$major.$minor.$patch"
Expand Down Expand Up @@ -86,22 +86,22 @@ dependencies {
if (findProject(':r2-shared')) {
implementation project(':r2-shared')
} else {
implementation "com.github.readium:r2-shared-kotlin:1.1.4"
implementation "com.github.readium:r2-shared-kotlin:1.1.5"
}
if (findProject(':r2-navigator')) {
implementation project(':r2-navigator')
} else {
implementation "com.github.readium:r2-navigator-kotlin:1.1.3"
implementation "com.github.readium:r2-navigator-kotlin:1.1.4"
}
if (findProject(':r2-streamer')) {
implementation project(':r2-streamer')
} else {
implementation "com.github.readium:r2-streamer-kotlin:1.1.3"
implementation "com.github.readium:r2-streamer-kotlin:1.1.4"
}
if (findProject(':r2-opds')) {
implementation project(':r2-opds')
} else {
implementation "com.github.readium:r2-opds-kotlin:1.1.2"
implementation "com.github.readium:r2-opds-kotlin:1.1.3"
}
if (findProject(':r2-lcp')) {
implementation project(':r2-lcp')
Expand All @@ -119,7 +119,7 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.webkit:webkit:1.1.0'
implementation "com.google.android.material:material:1.2.0-alpha02"
implementation "com.google.android.material:material:1.2.0-alpha03"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation ('com.github.edrlab.nanohttpd:nanohttpd-nanolets:2.3.2') {
Expand Down
5 changes: 2 additions & 3 deletions r2-testapp/src/main/java/org/readium/r2/testapp/R2App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.content.ContentResolver
import android.content.Context
import nl.komponents.kovenant.android.startKovenant
import nl.komponents.kovenant.android.stopKovenant
import org.readium.r2.testapp.BuildConfig.DEBUG
import timber.log.Timber

class R2App : Application() {
Expand All @@ -24,9 +25,7 @@ class R2App : Application() {
// Configure Kovenant with standard dispatchers
// suitable for an Android environment.
startKovenant()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
if (DEBUG) Timber.plant(Timber.DebugTree())
}

override fun onTerminate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class AudiobookActivity : R2AudiobookActivity(), NavigatorDelegate {

override fun onDestroy() {
super.onDestroy()
activitiesLaunched.getAndDecrement();
activitiesLaunched.getAndDecrement()
}

override fun onStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ComicActivity : R2CbzActivity(), CoroutineScope, NavigatorDelegate {

override fun onDestroy() {
super.onDestroy()
activitiesLaunched.getAndDecrement();
activitiesLaunched.getAndDecrement()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.readium.r2.navigator.divina.R2DiViNaActivity
import org.readium.r2.shared.Locator
import org.readium.r2.testapp.BuildConfig.DEBUG
import org.readium.r2.testapp.R
import org.readium.r2.testapp.library.activitiesLaunched
import org.readium.r2.testapp.outline.R2OutlineActivity
Expand Down Expand Up @@ -76,7 +77,7 @@ class DiViNaActivity : R2DiViNaActivity(), CoroutineScope {
data ?: return
if (requestCode == 2 && resultCode == Activity.RESULT_OK) {
val locator = data.getSerializableExtra("locator") as Locator
Timber.d("locator href ${locator.href}")
if (DEBUG) Timber.d("locator href ${locator.href}")

// Call the player's goTo function with the considered href
divinaWebView.evaluateJavascript("if (player) { player.goTo('${locator.href}'); };", null)
Expand All @@ -85,7 +86,7 @@ class DiViNaActivity : R2DiViNaActivity(), CoroutineScope {

override fun onDestroy() {
super.onDestroy()
activitiesLaunched.getAndDecrement();
activitiesLaunched.getAndDecrement()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class BOOKMARKS(private var database: BookmarksDatabaseOpenHelper) {
return null
}

fun has(bookmark: Bookmark): List<Bookmark> {
private fun has(bookmark: Bookmark): List<Bookmark> {
return database.use {
select(BOOKMARKSTable.NAME,
BOOKMARKSTable.ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class Book(var id: Long? = null,
get() {
val url = URI(href)
if (!url.scheme.isNullOrEmpty() && url.isAbsolute) {
val uri = Uri.parse(href);
val uri = Uri.parse(href)
return uri.lastPathSegment
}
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val path = Paths.get(href)
path.fileName.toString()
} else {
val uri = Uri.parse(href);
val uri = Uri.parse(href)
uri.lastPathSegment
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class HIGHLIGHTS(private var database: HighlightsDatabaseOpenHelper) {
return null
}

fun has(highlight: Highlight): List<Highlight> {
private fun has(highlight: Highlight): List<Highlight> {
return database.use {

select(HIGHLIGHTSTable.NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.readium.r2.navigator.epub.Style
import org.readium.r2.navigator.pager.R2EpubPageFragment
import org.readium.r2.navigator.pager.R2PagerAdapter
import org.readium.r2.shared.*
import org.readium.r2.testapp.BuildConfig.DEBUG
import org.readium.r2.testapp.DRMManagementActivity
import org.readium.r2.testapp.R
import org.readium.r2.testapp.db.*
Expand Down Expand Up @@ -582,7 +583,7 @@ class EpubActivity : R2EpubActivity(), CoroutineScope, NavigatorDelegate/*, Visu

currentFragment.webView.runJavaScript("markSearch('${searchStorage.getString("term", null)}', null, '$resourceHref', '$resourceType', '$resourceTitle', '$index')") { result ->

Timber.d("###### $result")
if (DEBUG) Timber.d("###### $result")

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.readium.r2.navigator.BASE_URL
import org.readium.r2.navigator.IR2TTS
import org.readium.r2.navigator.VisualNavigator
import org.readium.r2.shared.Publication
import org.readium.r2.testapp.BuildConfig.DEBUG
import timber.log.Timber
import java.io.IOException
import java.util.*
Expand Down Expand Up @@ -64,7 +65,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
value < 0 -> 0
else -> value
}
Timber.tag(this::class.java.simpleName).d("Current utterance index: $currentUtterance")
if (DEBUG) Timber.tag(this::class.java.simpleName).d("Current utterance index: $currentUtterance")
}

private var items = publication.readingOrder
Expand Down Expand Up @@ -93,7 +94,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
textToSpeech = TextToSpeech(context,
TextToSpeech.OnInitListener { status ->
initialized = (status != TextToSpeech.ERROR)
Timber.tag(this::class.java.simpleName).d("textToSpeech initialization status: $initialized")
if (DEBUG) Timber.tag(this::class.java.simpleName).d("textToSpeech initialization status: $initialized")
})
}

Expand Down Expand Up @@ -278,12 +279,12 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
* @param utteranceId The utterance ID of the utterance.
*/
override fun onError(utteranceId: String?) {
Timber.tag(this::class.java.simpleName).e("Error saying: ${utterances[utteranceId!!.toInt()]}")
if (DEBUG) Timber.tag(this::class.java.simpleName).e("Error saying: ${utterances[utteranceId!!.toInt()]}")
}
})

if (res == TextToSpeech.ERROR) {
Timber.tag(this::class.java.simpleName).e("TTS failed to set callbacks")
if (DEBUG) Timber.tag(this::class.java.simpleName).e("TTS failed to set callbacks")
return false
}

Expand Down Expand Up @@ -317,7 +318,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
isPaused = false
if (initialized && configure()) {
if (currentUtterance >= utterances.size) {
Timber.tag(this::class.java.simpleName).e("Invalid currentUtterance value: $currentUtterance . Expected less than $utterances.size")
if (DEBUG) Timber.tag(this::class.java.simpleName).e("Invalid currentUtterance value: $currentUtterance . Expected less than $utterances.size")
currentUtterance = 0
}
val index = currentUtterance
Expand Down Expand Up @@ -406,7 +407,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
resumeReading()
}
} catch (e: Exception) {
Timber.tag(this::class.java.simpleName).e(e.toString())
if (DEBUG) Timber.tag(this::class.java.simpleName).e(e.toString())
return false
}

Expand Down Expand Up @@ -445,7 +446,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
*/
private fun addToUtterancesQueue(utterance: String, index: Int): Boolean {
if (textToSpeech.speak(utterance, TextToSpeech.QUEUE_ADD, null, index.toString()) == TextToSpeech.ERROR) {
Timber.tag(this::class.java.simpleName).e("Error while adding utterance: $utterance to the TTS queue")
if (DEBUG) Timber.tag(this::class.java.simpleName).e("Error while adding utterance: $utterance to the TTS queue")
return false
}

Expand All @@ -459,7 +460,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
*/
private fun flushUtterancesQueue(): Boolean {
if (textToSpeech.speak("", TextToSpeech.QUEUE_FLUSH, null, null) == TextToSpeech.ERROR) {
Timber.tag(this::class.java.simpleName).e("Error while flushing TTS queue.")
if (DEBUG) Timber.tag(this::class.java.simpleName).e("Error while flushing TTS queue.")
return false
}

Expand Down Expand Up @@ -516,7 +517,7 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
splitParagraphAndAddToUtterances(elements)

} catch (e: IOException) {
Timber.tag(this::class.java.simpleName).e(e.toString())
if (DEBUG) Timber.tag(this::class.java.simpleName).e(e.toString())
success = false
return@Runnable
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.readium.r2.testapp.R
import org.readium.r2.testapp.utils.color
import java.io.File

class UserSettings(var preferences: SharedPreferences, val context: Context, val UIPreset: MutableMap<ReadiumCSSName, Boolean>) {
class UserSettings(var preferences: SharedPreferences, val context: Context, private val UIPreset: MutableMap<ReadiumCSSName, Boolean>) {

lateinit var resourcePager: R2ViewPager

Expand Down Expand Up @@ -341,7 +341,7 @@ class UserSettings(var preferences: SharedPreferences, val context: Context, val

// Publisher defaults
val publisherDefaultSwitch = layout.findViewById(R.id.publisher_default) as Switch
publisherDefaultSwitch.contentDescription = "\u00A0";
publisherDefaultSwitch.contentDescription = "\u00A0"

publisherDefaultSwitch.isChecked = publisherDefault.on
publisherDefaultSwitch.setOnCheckedChangeListener { _, b ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.readium.r2.testapp.utils.singleClick
import java.io.ByteArrayInputStream


open class BooksAdapter(private val activity: Activity, private var books: MutableList<Book>, private val server: String, private var itemListener: RecyclerViewClickListener) : RecyclerView.Adapter<BooksAdapter.ViewHolder>() {
open class BooksAdapter(private val activity: Activity, private var books: MutableList<Book>, private var itemListener: RecyclerViewClickListener) : RecyclerView.Adapter<BooksAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = activity.layoutInflater
Expand All @@ -37,7 +37,7 @@ open class BooksAdapter(private val activity: Activity, private var books: Mutab
val book = books[position]

viewHolder.textView.text = book.title
viewHolder.textView.contentDescription = "\u00A0";
viewHolder.textView.contentDescription = "\u00A0"

viewHolder.imageView.setImageResource(R.drawable.cover)

Expand Down
Loading

0 comments on commit 233ca1c

Please sign in to comment.