Skip to content

Commit eabcb01

Browse files
authored
Merge pull request #13 from smartmobilefactory/_master/dynamicCss
master/dynamic css
2 parents 64d448d + 595c1ea commit eabcb01

File tree

12 files changed

+90
-18
lines changed

12 files changed

+90
-18
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { zoom: 100%; } * { background: #111111 !important; color: #ABABAB !important; } :link, :link * { color: #DBDBDC !important } :visited, :visited * { color: #5B5B5B !important }

app/src/main/java/com/smartmobilefactory/epubreader/sample/MainActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.smartmobilefactory.epubreader.sample;
22

33
import android.app.Application;
4+
import android.graphics.Color;
45
import android.os.Build;
56
import android.os.Bundle;
67
import android.os.StrictMode;
@@ -161,6 +162,16 @@ public void onStopTrackingTouch(SeekBar seekBar) {
161162
binding.epubView.setScrollDirection(EpubScrollDirection.SINGLE_CHAPTER_VERTICAL);
162163
});
163164

165+
binding.nightmode.setOnCheckedChangeListener((buttonView, isChecked) -> {
166+
if (isChecked) {
167+
binding.epubView.getSettings().setCustomChapterCss(new String[]{"file:///android_asset/books/styles/night_mode.css"});
168+
binding.epubView.setBackgroundColor(Color.parseColor("#111111"));
169+
} else {
170+
binding.epubView.getSettings().setCustomChapterCss(new String[]{});
171+
binding.epubView.setBackgroundColor(Color.WHITE);
172+
}
173+
});
174+
164175
}
165176

166177
private void observeEpub() {

app/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@
141141

142142
</LinearLayout>
143143
</HorizontalScrollView>
144+
145+
<CheckBox
146+
android:id="@+id/nightmode"
147+
android:layout_marginTop="12dp"
148+
android:layout_width="wrap_content"
149+
android:layout_height="wrap_content"
150+
android:text="Nightmode"/>
151+
144152
</LinearLayout>
145153

146154
</FrameLayout>

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 16
1010
targetSdkVersion 25
1111
versionCode 1
12-
versionName "0.1.1"
12+
versionName "0.2"
1313

1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1515

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<manifest package="com.smartmobilefactory.epubreader"
2-
xmlns:android="http://schemas.android.com/apk/res/android">
3-
4-
<application android:label="@string/app_name"
5-
android:supportsRtl="true">
6-
7-
</application>
1+
<manifest package="com.smartmobilefactory.epubreader">
82

93
</manifest>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,45 @@
11
package com.smartmobilefactory.epubreader;
22

33
public enum EpubScrollDirection {
4+
5+
/**
6+
* make chapters internally vertical scrollable
7+
* but each chapter has its own page
8+
* the user can swipe horizontally through the chapters
9+
*
10+
* | chapter1 | | chapter2 | | chapter3 | | chapter4 |
11+
* | chapter1 | | chapter2 | | chapter3 | | chapter4 |
12+
* | chapter1 | | chapter2 | | chapter4 |
13+
* | chapter1 |
14+
* | chapter1 |
15+
*/
416
HORIZONTAL_WITH_VERTICAL_CONTENT,
17+
18+
/**
19+
* make all chapters vertical scrollable
20+
* WARNING: this mode is not well tested and experimental
21+
*
22+
* | chapter1 |
23+
* | chapter1 |
24+
* | chapter1 |
25+
* | chapter1 |
26+
* | chapter1 |
27+
* | chapter2 |
28+
* | chapter2 |
29+
* | chapter2 |
30+
* | chapter3 |
31+
* | chapter4 |
32+
*/
533
VERTICAL_WITH_VERTICAL_CONTENT,
34+
35+
/**
36+
* show only a single chapter which is vertically scrollable
37+
*
38+
* | chapter1 |
39+
* | chapter1 |
40+
* | chapter1 |
41+
* | chapter1 |
42+
* | chapter1 |
43+
*/
644
SINGLE_CHAPTER_VERTICAL
745
}

library/src/main/java/com/smartmobilefactory/epubreader/display/EpubDisplayHelper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.net.Uri;
44
import android.os.Build;
5+
import android.support.annotation.CheckResult;
56
import android.webkit.WebView;
67

78
import com.smartmobilefactory.epubreader.EpubViewSettings;
@@ -14,6 +15,7 @@
1415
import java.util.List;
1516
import java.util.Locale;
1617

18+
import io.reactivex.Completable;
1719
import io.reactivex.Single;
1820
import io.reactivex.android.schedulers.AndroidSchedulers;
1921
import io.reactivex.schedulers.Schedulers;
@@ -25,7 +27,8 @@ public class EpubDisplayHelper {
2527
private static String INJECT_CSS_FORMAT = "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\n";
2628
private static String INJECT_JAVASCRIPT_FORMAT = "<script src=\"%s\"></script>\n";
2729

28-
public static BaseDisposableObserver loadHtmlData(WebView webView, Epub epub, SpineReference spineReference, EpubViewSettings settings) {
30+
@CheckResult
31+
public static Completable loadHtmlData(WebView webView, Epub epub, SpineReference spineReference, EpubViewSettings settings) {
2932

3033
WeakReference<WebView> webViewWeakReference = new WeakReference<>(webView);
3134

@@ -58,7 +61,7 @@ public static BaseDisposableObserver loadHtmlData(WebView webView, Epub epub, Sp
5861
);
5962
}
6063
})
61-
.subscribeWith(new BaseDisposableObserver<>());
64+
.toCompletable();
6265
}
6366

6467
private static String getHtml(Epub epub, SpineReference reference, EpubViewSettings settings) throws IOException {

library/src/main/java/com/smartmobilefactory/epubreader/display/vertical_content/SingleChapterVerticalEpubDisplayStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void displayEpub(final Epub epub, EpubLocation location) {
3434
if (location instanceof EpubLocation.ChapterLocation) {
3535
int chapter = ((EpubLocation.ChapterLocation) location).chapter();
3636
SpineReference spineReference = epub.getBook().getSpine().getSpineReferences().get(chapter);
37-
EpubDisplayHelper.loadHtmlData(binding.webview, epub, spineReference, settings);
37+
binding.webview.loadEpubPage(epub, spineReference, epubView.getSettings());
3838
setCurrentChapter(chapter);
3939
}
4040

library/src/main/java/com/smartmobilefactory/epubreader/display/vertical_content/horizontal_chapters/PagerAdapter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public View getView(int position, ViewGroup parent) {
6060
binding.webview.setUrlInterceptor(strategy.urlInterceptor);
6161

6262
SpineReference spineReference = epub.getBook().getSpine().getSpineReferences().get(position);
63-
EpubDisplayHelper.loadHtmlData(binding.webview, epub, spineReference, epubView.getSettings())
64-
.addTo(compositeDisposable);
63+
binding.webview.loadEpubPage(epub, spineReference, epubView.getSettings());
6564

6665
handleLocation(position, binding.webview);
6766

library/src/main/java/com/smartmobilefactory/epubreader/display/vertical_content/vertical_chapters/ChapterAdapter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public void onBindViewHolder(ChapterViewHolder holder, int position) {
6161
holder.binding.webview.setUrlInterceptor(strategy.urlInterceptor);
6262

6363
SpineReference spineReference = epub.getBook().getSpine().getSpineReferences().get(position);
64-
EpubDisplayHelper.loadHtmlData(holder.binding.webview, epub, spineReference, epubView.getSettings())
65-
.addTo(compositeDisposable);
64+
holder.binding.webview.loadEpubPage(epub, spineReference, epubView.getSettings());
6665

6766
Bridge bridge = new Bridge();
6867
holder.binding.webview.setInternalBridge(bridge);

0 commit comments

Comments
 (0)