Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix/first page position of vertical string books, App can't open multibytes title book #217

Open
wants to merge 2 commits into
base: feature/horizontal_scroll
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ buildscript {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
Expand Down
6 changes: 3 additions & 3 deletions folioreader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ext {

android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
versionCode 1
Expand Down Expand Up @@ -82,7 +82,7 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':webViewMarker')

final ANDROID_LIB_VERSION = '26.0.2'
final ANDROID_LIB_VERSION = '27.+'

//noinspection GradleDependency
compile "com.android.support:appcompat-v7:$ANDROID_LIB_VERSION"
Expand Down
1 change: 1 addition & 0 deletions folioreader/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
<string name="OK">Ok</string>
<string name="SetSizeTitle">Painel superior</string>
<string name="LanguageChooserTitle">Escolha 2 linguagens</string>
<string name="cant_open_file">Can\'t open file</string>
</resources>
1 change: 1 addition & 0 deletions folioreader/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
<string name="save_note">Сохранить заметку</string>
<string name="please_enter_note">пожалуйста введите заметку</string>
<string name="contents">Содержание</string>
<string name="cant_open_file">Can\'t open file</string>

</resources>
3 changes: 3 additions & 0 deletions folioreader/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@
<string name="dictionary">Dictionary</string>
<string name="wikipedia">Wikipedia</string>
<string name="cannot_access_epub_message">Cannot open epub it needs storage access !</string>
<string name="orientation_horizontal">horizontal</string>
<string name="orientation_vertical">vertical</string>
<string name="cant_open_file">Can\'t open file</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.folioreader.ui.folio.presenter.MainPresenter;
import com.folioreader.util.AppUtil;
import com.folioreader.util.FileUtil;

import com.folioreader.util.UiUtil;
import com.folioreader.view.ConfigBottomSheetDialogFragment;
import com.folioreader.view.DirectionalViewpager;
Expand All @@ -74,6 +73,9 @@
import org.readium.r2_streamer.server.EpubServerSingleton;

import java.io.IOException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -162,7 +164,10 @@ protected void onCreate(Bundle savedInstanceState) {
if (ContextCompat.checkSelfPermission(FolioActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(FolioActivity.this, Constants.getWriteExternalStoragePerms(), Constants.WRITE_EXTERNAL_STORAGE_REQUEST);
} else {
setupBook();
if(setupBook() == false){
Toast.makeText(this, R.string.cant_open_file, Toast.LENGTH_LONG);
finish();
}
}

initAudioView();
Expand Down Expand Up @@ -205,27 +210,52 @@ public void onClick(View v) {
}
}

private void initBook(String mEpubFileName, int mEpubRawId, String mEpubFilePath, EpubSourceType mEpubSourceType) {
private Boolean initBook(String mEpubFileName, int mEpubRawId, String mEpubFilePath, EpubSourceType mEpubSourceType) {
Log.v(TAG, "initBook >>");
Boolean result = false;
try {
int portNumber = getIntent().getIntExtra(Config.INTENT_PORT, Constants.PORT_NUMBER);
mEpubServer = EpubServerSingleton.getEpubServerInstance(portNumber);
mEpubServer.start();
String path = FileUtil.saveEpubFileAndLoadLazyBook(FolioActivity.this, mEpubSourceType, mEpubFilePath,
mEpubRawId, mEpubFileName);
addEpub(path);

String urlString = Constants.LOCALHOST + bookFileName + "/manifest";
new MainPresenter(this).parseManifest(urlString);
if(addEpub(path)){

String urlString = Constants.LOCALHOST + URLEncoder.encode(bookFileName, "UTF-8") + "/manifest";
Log.v(TAG, "initBook urlString = " + urlString);
new MainPresenter(this).parseManifest(urlString);

result = true;
}
} catch (IOException e) {
Log.e(TAG, "initBook failed", e);
}
Log.v(TAG, "initBook <<");

return result;
}

private void addEpub(String path) throws IOException {
private Boolean addEpub(String path) throws IOException {
Log.v(TAG, "addEpub >>");
Log.v(TAG, "addEpub path = " + path);
Log.v(TAG, "addEpub bookFileName = " + bookFileName);

Boolean result = true;

Container epubContainer = new EpubContainer(path);
mEpubServer.addEpub(epubContainer, "/" + bookFileName);
try{
mEpubServer.addEpub(epubContainer, "/" + URLEncoder.encode(bookFileName));
}
catch(Exception ex){
Log.e(TAG, "addEpub error = " + ex.getMessage());
result = false;
}
getEpubResource();

Log.v(TAG, "addEpub <<");

return result;
}

private void getEpubResource() {
Expand Down Expand Up @@ -488,11 +518,12 @@ public void onLoadPublication(EpubPublication publication) {
}

private void setConfig() {
if (AppUtil.getSavedConfig(this) != null) {
mConfig = AppUtil.getSavedConfig(this);
} else if (getIntent().getParcelableExtra(Config.INTENT_CONFIG) != null) {
if (getIntent().getParcelableExtra(Config.INTENT_CONFIG) != null) {
mConfig = getIntent().getParcelableExtra(Config.INTENT_CONFIG);
AppUtil.saveConfig(this, mConfig);
Log.v(TAG, "setConfig (2) isShowTts = " + mConfig.isShowTts());
} else if (AppUtil.getSavedConfig(this) != null) {
mConfig = AppUtil.getSavedConfig(this);
} else {
mConfig = new Config.ConfigBuilder().build();
AppUtil.saveConfig(this, mConfig);
Expand Down Expand Up @@ -673,9 +704,29 @@ public void initColors() {
UiUtil.setColorToImage(this, mConfig.getThemeColor(), ((ImageView) findViewById(R.id.btn_speaker)).getDrawable());
}

private void setupBook() {
bookFileName = FileUtil.getEpubFilename(this, mEpubSourceType, mEpubFilePath, mEpubRawId);
initBook(bookFileName, mEpubRawId, mEpubFilePath, mEpubSourceType);
public String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();

// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
hexString.append(String.format("%02x", messageDigest[i] & 0xff));
return hexString.toString();

} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}

private Boolean setupBook() {
//bookFileName = FileUtil.getEpubFilename(this, mEpubSourceType, mEpubFilePath, mEpubRawId);
bookFileName = md5(mEpubFilePath);
return initBook(bookFileName, mEpubRawId, mEpubFilePath, mEpubSourceType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void onProgressChanged(WebView view, int progress) {
@Override
public void run() {
Log.d("scroll y", "Scrolly" + mScrollY);
mWebview.scrollTo(0, mScrollY);
mWebview.scrollTo(mWebview.getScrollX(), mScrollY);
}
}, 100);
}
Expand Down Expand Up @@ -1037,7 +1037,7 @@ public void setWebViewPosition(final int position) {
@Override
public void run() {
if (isAdded()) {
mWebview.scrollTo(0, position);
mWebview.scrollTo(mWebview.getScrollX(), position);
}
}
});
Expand Down
17 changes: 8 additions & 9 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#Sat Jun 10 11:42:12 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

org.gradle.daemon=true
org.gradle.parallel=true
#Fri Jun 15 20:59:41 JST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.daemon=true
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
org.gradle.parallel=true
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
javaMaxHeapSize "4G"
}

compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "com.folioreader.android.sample"
Expand Down Expand Up @@ -57,5 +57,5 @@ android {

dependencies {
compile project(':folioreader')
compile 'com.android.support:appcompat-v7:26.0.2'
compile "com.android.support:appcompat-v7:27.+"
}
2 changes: 1 addition & 1 deletion webViewMarker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {

android {
compileSdkVersion 19
buildToolsVersion '26.0.2'
buildToolsVersion '27.0.3'

defaultConfig {
versionCode Integer.parseInt(project.VERSION_CODE)
Expand Down