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

Add support multi byte book title #213

Open
wants to merge 3 commits into
base: master
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Expand Up @@ -14,9 +14,10 @@ buildscript {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
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:2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
Expand Down
34 changes: 34 additions & 0 deletions folioreader/res/values-ja/strings.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">folioreader</string>
<string name="share">共有</string>
<string name="copy">コピー</string>
<string name="send_to">送信先:</string>
<string name="copied">コピーしました</string>
<string name="less_than_minute">1分未満 ·&#160;</string>
<string name="minutes_left">%1$d 分 ·&#160;</string>
<string name="minute_left">%1$d 分 ·&#160;</string>
<string name="highlight">ハイライト</string>
<string name="define">定義</string>
<string name="highlights">ハイライト</string>
<string name="style">スタイル</string>
<string name="Cancel">キャンセル</string>
<string name="loading">読み込み中</string>
<string name="please_wait">しばらくお待ちください</string>
<string name="edit_notes">編集</string>
<string name="save_note">保存</string>
<string name="please_enter_note">入力してください</string>
<string name="contents">目次</string>
<string name="dictionary">辞書</string>
<string name="cannot_access_epub_message">epubを開くことができません。ストレージアクセスが必要です !</string>
<string name="pages_left">残り %1$d ページ</string>
<string name="page_left">残り %1$d ページ</string>
<string name="change_Font">フォントの変更e</string>
<string name="change_Font_Color">フォント色</string>
<string name="changeStyle">スタイルの変更</string>
<string name="error_CannotChangeStyle">スタイルを変更できません!</string>
<string name="OK">Ok</string>
<string name="SetSizeTitle">上部パネルサイズ:</string>
<string name="LanguageChooserTitle">2つの言語を選択する:</string>
<string name="cant_open_file">このフィルは開けません。</string>
</resources>
1 change: 1 addition & 0 deletions folioreader/res/values-pt-rBR/strings.xml
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
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>
1 change: 1 addition & 0 deletions folioreader/res/values/strings.xml
Expand Up @@ -93,4 +93,5 @@
<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>
Expand Up @@ -59,6 +59,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 @@ -131,7 +134,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();
}
}

toolbar = findViewById(R.id.toolbar);
Expand All @@ -153,27 +159,52 @@ public void startContentHighlightActivity() {
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
}

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 @@ -369,15 +400,22 @@ 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) {
Log.v(TAG, "setConfig >>");

Bundle args = getIntent().getExtras();
Log.v(TAG, "setConfig args = " + args.toString());

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);
}
Log.v(TAG, "setConfig <<");
}

@Override
Expand All @@ -394,9 +432,29 @@ public void pause() {
public void onError() {
}

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
Expand Up @@ -71,6 +71,7 @@

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -209,6 +210,13 @@ public View onCreateView(LayoutInflater inflater,


private String getWebviewUrl() {
//return Constants.LOCALHOST + mBookTitle + "/" + spineItem.href;
try{
return Constants.LOCALHOST + URLEncoder.encode(mBookTitle, "UTF-8") + "/" + spineItem.href;
}
catch (Exception ex){

}
return Constants.LOCALHOST + mBookTitle + "/" + spineItem.href;
}

Expand All @@ -227,7 +235,7 @@ public void onConfigurationChanged(Configuration newConfig) {

/**
* [EVENT BUS FUNCTION]
* Function triggered from {@link FolioActivity#initAudioView()} when pause/play
* Function triggered from {@link FolioActivity} when pause/play
* button is clicked
*
* @param event of type {@link MediaOverlayPlayPauseEvent} contains if paused/played
Expand Down Expand Up @@ -368,8 +376,17 @@ private void setHtml(boolean reloaded) {
if (forwardSlashLastIndex != -1)
path = ref.substring(0, forwardSlashLastIndex + 1);

String title;
try{
title = URLEncoder.encode(mBookTitle, "UTF-8");
}
catch(Exception ex){
title = mBookTitle;
}

mWebview.loadDataWithBaseURL(
Constants.LOCALHOST + mBookTitle + "/" + path,
// Constants.LOCALHOST + mBookTitle + "/" + path,
Constants.LOCALHOST + title + "/" + path,
HtmlUtil.getHtmlContent(getActivity(), mHtmlString, mConfig),
"text/html",
"UTF-8",
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.folioreader.ui.tableofcontents.presenter.TableOfContentsPresenter;
import com.folioreader.util.AppUtil;

import java.net.URLEncoder;
import java.util.ArrayList;

import static com.folioreader.Constants.BOOK_TITLE;
Expand Down Expand Up @@ -72,7 +73,15 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mTableOfContentsRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_menu);
errorView = (TextView) view.findViewById(R.id.tv_error);
String urlString = Constants.LOCALHOST + mBookTitle + "/manifest";

String bookTitle;
try{
bookTitle = URLEncoder.encode(mBookTitle, "UTF-8");
}
catch(Exception ex){
bookTitle = mBookTitle;
}
String urlString = Constants.LOCALHOST + bookTitle + "/manifest";

configRecyclerViews();
presenter.getTOCContent(urlString);
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void onClick(View v) {
findViewById(R.id.btn_assest).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
folioReader.openBook("file:///android_asset/TheSilverChair.epub");
folioReader.openBook("file:///android_asset/jpn.epub");
}
});

Expand Down