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 #26 from readium/develop
Browse files Browse the repository at this point in the history
1.0.3
  • Loading branch information
aferditamuriqi authored Aug 25, 2018
2 parents 1a2e3ed + bd49de2 commit 76117fe
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 343 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.41'
ext.kotlin_version = '1.2.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
51 changes: 35 additions & 16 deletions r2-navigator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.readium'

android {
flavorDimensions "testapp"

compileSdkVersion 27
buildToolsVersion "27.0.3"


defaultConfig {
minSdkVersion 21
targetSdkVersion 27
Expand All @@ -31,49 +32,67 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
intTestapp {
dimension "testapp"
}
intTestappWithLcp {
dimension "testapp"
}
devTestapp {
dimension "testapp"
}
devTestappWithLcp {
dimension "testapp"
}
}

// default build flavour
defaultPublishConfig "intTestappDebug"
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'com.jakewharton.timber:timber:4.7.0'

// uncomment this line to use with jitpack
implementation 'com.github.readium:r2-shared-kotlin:master-SNAPSHOT'
intTestappImplementation 'com.github.readium:r2-shared-kotlin:develop-SNAPSHOT'
intTestappWithLcpImplementation 'com.github.readium:r2-shared-kotlin:develop-SNAPSHOT'

// uncomment this line to use with GitHu submodules and Android Studio Modules
// implementation project(':r2-shared')
if (findProject(':r2-shared')) {
devTestappImplementation project(':r2-shared')
devTestappWithLcpImplementation project(':r2-shared')
}
intTestappImplementation 'com.github.readium:r2-shared-kotlin:develop-SNAPSHOT'
intTestappWithLcpImplementation 'com.github.readium:r2-shared-kotlin:develop-SNAPSHOT'

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation "org.jetbrains.anko:anko-design:0.10.4" // For SnackBars
implementation "org.jetbrains.anko:anko-design:0.10.5" // For SnackBars

implementation "org.jetbrains.anko:anko-commons:0.10.4"
implementation "org.jetbrains.anko:anko-commons:0.10.5"

// Anko Layouts
implementation "org.jetbrains.anko:anko-sdk25:0.10.4"
implementation "org.jetbrains.anko:anko-sdk25:0.10.5"
// sdk15, sdk19, sdk21, sdk23 are also available
implementation "org.jetbrains.anko:anko-appcompat-v7:0.10.4"
implementation "org.jetbrains.anko:anko-recyclerview-v7:0.10.4"
implementation "org.jetbrains.anko:anko-appcompat-v7:0.10.5"
implementation "org.jetbrains.anko:anko-recyclerview-v7:0.10.5"

// Coroutine listeners for Anko Layouts
implementation "org.jetbrains.anko:anko-sdk25-coroutines:0.10.4"
implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:0.10.4"
implementation "org.jetbrains.anko:anko-sdk25-coroutines:0.10.5"
implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:0.10.5"

// Anko SQLite
implementation "org.jetbrains.anko:anko-sqlite:0.10.4"
implementation "org.jetbrains.anko:anko-sqlite:0.10.5"
implementation 'joda-time:joda-time:2.9.9'


implementation 'com.android.support:support-core-ui:27.1.1'
implementation 'com.duolingo.open:rtl-viewpager:1.0.3'

implementation 'org.zeroturnaround:zt-zip:1.12'
// JSON parser
// implementation 'com.beust:klaxon:3.0.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
182 changes: 118 additions & 64 deletions r2-navigator/r2-navigator.iml

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions r2-navigator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<activity
android:name=".R2CbzActivity"
android:theme="@style/AppTheme" />
<activity
android:name=".R2OutlineActivity"
android:label="Table of Contents"
android:theme="@style/AppTheme" />
<activity
android:name=".DRMManagementActivity"
android:label="DRM Management"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import android.widget.LinearLayout
import org.jetbrains.anko.*
import org.jetbrains.anko.design.coordinatorLayout
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.readium.r2.shared.drm.DRMMModel
import org.readium.r2.shared.drm.DRMModel


class DRMManagementActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val drmModel: DRMMModel = intent.getSerializableExtra("drmModel") as DRMMModel
val drmModel: DRMModel = intent.getSerializableExtra("drmModel") as DRMModel


coordinatorLayout {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Module: r2-navigator-kotlin
* Developers: Aferdita Muriqi, Clément Baumann
* Developers: Aferdita Muriqi, Mostapha Idoubihi
*
* Copyright (c) 2018. Readium Foundation. All rights reserved.
* Use of this source code is governed by a BSD-style license which is detailed in the
Expand Down
104 changes: 52 additions & 52 deletions r2-navigator/src/main/java/org/readium/r2/navigator/R2EpubActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ import android.os.Bundle
import android.os.Handler
import android.support.v4.view.ViewCompat
import android.support.v7.app.AppCompatActivity
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import kotlinx.android.synthetic.main.fragment_page_epub.view.*
import org.jetbrains.anko.contentView
import org.jetbrains.anko.intentFor
import org.readium.r2.navigator.pager.R2PagerAdapter
import org.readium.r2.navigator.pager.R2ViewPager
import org.readium.r2.shared.Publication
import org.readium.r2.shared.drm.DRMMModel
import org.readium.r2.shared.drm.DRMModel


class R2EpubActivity : AppCompatActivity() {
open class R2EpubActivity : AppCompatActivity() {

lateinit var preferences: SharedPreferences
lateinit var resourcePager: R2ViewPager
lateinit var resources: ArrayList<String>

private lateinit var publicationPath: String
private lateinit var publication: Publication
private lateinit var epubName: String
protected lateinit var publicationPath: String
protected lateinit var publication: Publication
protected lateinit var epubName: String
lateinit var publicationIdentifier: String

lateinit var userSettings: UserSettings
private var drmModel: DRMMModel? = null
private var menuDrm: MenuItem? = null
private var menuToc: MenuItem? = null
protected var drmModel: DRMModel? = null
protected var menuDrm: MenuItem? = null
protected var menuToc: MenuItem? = null

var pagerPosition = 0
var reloadPagerPositions = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -58,7 +58,7 @@ class R2EpubActivity : AppCompatActivity() {

Handler().postDelayed({
if (intent.getSerializableExtra("drmModel") != null) {
drmModel = intent.getSerializableExtra("drmModel") as DRMMModel
drmModel = intent.getSerializableExtra("drmModel") as DRMModel
drmModel?.let {
runOnUiThread {
menuDrm?.isVisible = true
Expand Down Expand Up @@ -88,7 +88,7 @@ class R2EpubActivity : AppCompatActivity() {
val index = preferences.getInt("$publicationIdentifier-document", 0)

val adapter = R2PagerAdapter(supportFragmentManager, resources, publication.metadata.title, Publication.TYPE.EPUB, publicationPath)

reloadPagerPositions = true
resourcePager.adapter = adapter

userSettings = UserSettings(preferences, this)
Expand All @@ -104,6 +104,7 @@ class R2EpubActivity : AppCompatActivity() {
} else {
resourcePager.currentItem = index
}
storeDocumentIndex()

val appearancePref = preferences.getInt("appearance", 0)
val backgroundsColors = mutableListOf("#ffffff", "#faf4e8", "#000000")
Expand All @@ -113,53 +114,47 @@ class R2EpubActivity : AppCompatActivity() {
toggleActionBar()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_toc, menu)
menuDrm = menu?.findItem(R.id.drm)
menuToc = menu?.findItem(R.id.toc)
menuDrm?.isVisible = false
return true
override fun onPause() {
super.onPause()
storeProgression(resourcePager.webView.progression)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {

R.id.toc -> {
val intent = Intent(this, R2OutlineActivity::class.java)
intent.putExtra("publicationPath", publicationPath)
intent.putExtra("publication", publication)
intent.putExtra("epubName", epubName)
startActivityForResult(intent, 2)
return false
}
R.id.settings -> {
userSettings.userSettingsPopUp().showAsDropDown(this.findViewById(R.id.toc), 0, 0, Gravity.END)
return false
}
R.id.drm -> {
startActivity(intentFor<DRMManagementActivity>("drmModel" to drmModel))
return false
}

else -> return super.onOptionsItemSelected(item)
}

/**
* storeProgression() : save in the preference the last progression in the spine item
*/
fun storeProgression(progression:Double) {
storeDocumentIndex()
val publicationIdentifier = publication.metadata.identifier
preferences.edit().putString("$publicationIdentifier-documentProgression", progression.toString()).apply()
}

override fun onPause() {
super.onPause()
val publicationIdentifier = publication.metadata.identifier
/**
* storeDocumentIndex() : save in the preference the last spine item
*/
fun storeDocumentIndex() {
val documentIndex = resourcePager.currentItem
val progression = resourcePager.webView.progression
preferences.edit().putInt("$publicationIdentifier-document", documentIndex).apply()
preferences.edit().putString("$publicationIdentifier-documentProgression", progression.toString()).apply()
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == 2 && resultCode == Activity.RESULT_OK) {
if (data != null) {
var href: String = data.getStringExtra("toc_item_uri")

pagerPosition = 0
reloadPagerPositions = true

val adapter = R2PagerAdapter(supportFragmentManager, resources, publication.metadata.title, Publication.TYPE.EPUB, publicationPath)
resourcePager.adapter = adapter

// href is the link to the page in the toc
var href: String = data.getStringExtra("toc_item_uri")

// Fetching the last progression saved ( default : 0.0 )
val progression = data.getDoubleExtra("item_progression", 0.0)

// Set the progression fetched
storeProgression(progression)

if (href.indexOf("#") > 0) {
href = href.substring(0, href.indexOf("#"))
Expand All @@ -168,9 +163,9 @@ class R2EpubActivity : AppCompatActivity() {
for (i in 0 until publication.spine.size) {
if (publication.spine[i].href == href) {
resourcePager.currentItem = i
storeDocumentIndex()
}
}
preferences.edit().putString("$publicationIdentifier-documentProgression", 0.0.toString()).apply()
if (supportActionBar!!.isShowing) {
resourcePager.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Expand All @@ -186,28 +181,33 @@ class R2EpubActivity : AppCompatActivity() {

fun nextResource() {
runOnUiThread {
preferences.edit().putString("$publicationIdentifier-documentProgression", 0.0.toString()).apply()
pagerPosition = 0
resourcePager.webView.progression = 0.0

if (ViewCompat.getLayoutDirection(this.contentView) == ViewCompat.LAYOUT_DIRECTION_RTL) {
// The view has RTL layout
resourcePager.currentItem = resourcePager.currentItem - 1
} else {
// The view has LTR layout
resourcePager.currentItem = resourcePager.currentItem + 1
}
storeDocumentIndex()
}
}

fun previousResource() {
runOnUiThread {
preferences.edit().putString("$publicationIdentifier-documentProgression", 1.0.toString()).apply()
pagerPosition = 0
resourcePager.webView.progression = 1.0

if (ViewCompat.getLayoutDirection(this.contentView) == ViewCompat.LAYOUT_DIRECTION_RTL) {
// The view has RTL layout
resourcePager.currentItem = resourcePager.currentItem + 1
} else {
// The view has LTR layout
resourcePager.currentItem = resourcePager.currentItem - 1
}

storeDocumentIndex()
}
}

Expand Down
Loading

0 comments on commit 76117fe

Please sign in to comment.