Skip to content

Commit

Permalink
merge with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
plotn committed Jan 11, 2019
2 parents efb8f2b + 9e9f21f commit 00711c4
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 60 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.coolreader"
android:installLocation="auto"
android:versionName="3.2.11-1" android:versionCode="2111">
android:versionName="3.2.26-1" android:versionCode="32260">
<supports-screens
android:xlargeScreens="true"
android:largeScreens="true"
Expand Down
8 changes: 5 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
targetSdkVersion 26
// When new version released, version code must be incremented at least by 8
// for compatibility with ABI versioning of split apk (see below).
versionCode 2111
versionName "3.2.11-1"
versionCode 32250
versionName "3.2.26-1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down Expand Up @@ -53,7 +53,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
cmake {
arguments "-DCMAKE_BUILD_TYPE=Release"
arguments "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
}
}
}
Expand Down Expand Up @@ -128,6 +128,8 @@ android {
lintOptions {
disable 'MissingTranslation'
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue Apr 17 20:15:44 MSK 2018
#Thu Dec 20 17:14:24 MSK 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
68 changes: 46 additions & 22 deletions android/src/org/coolreader/CoolReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,11 @@ else if (permissions[i].compareTo(Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
log.i("read&write to storage permissions GRANTED, adding sd card mount point...");
Services.refreshServices(this);
rebaseSettings();
getDBService().setPathCorrector(Engine.getInstance(this).getPathCorrector());
getDBService().get().reopenDatabase();
waitForCRDBService(new Runnable() {
@Override
public void run() {
getDBService().setPathCorrector(Engine.getInstance(CoolReader.this).getPathCorrector());
getDB().reopenDatabase();
Services.getHistory().loadFromDB(getDB(), 200);
}
});
Expand Down Expand Up @@ -1744,13 +1744,19 @@ public void run() {
FileInfo file = Services.getScanner().findFileInTree(item);
if (file == null)
file = item;
if (file.deleteFile()) {
Services.getHistory().removeBookInfo(getDB(), file, true, true);
BackgroundThread.instance().postGUI(new Runnable() {
final FileInfo finalFile = file;
if (file.deleteFile()) {
waitForCRDBService(new Runnable() {
@Override
public void run() {
Services.getHistory().removeBookInfo(getDB(), finalFile, true, true);
BackgroundThread.instance().postGUI(new Runnable() {
@Override
public void run() {
directoryUpdated(item.parent, null);
}}, 700);
}
});
} else {
boolean bSucceed = false;
int res = 0;
Expand All @@ -1767,16 +1773,19 @@ public void run() {
startActivityForResult(intent, REQUEST_CODE_OPEN_DOCUMENT_TREE);
}
} else {
Services.getHistory().removeBookInfo(getDB(), file, true, true);
BackgroundThread.instance().postGUI(new Runnable() {
waitForCRDBService(new Runnable() {
@Override
public void run() {
directoryUpdated(item.parent, null);
}}, 700);
Services.getHistory().removeBookInfo(getDB(), finalFile, true, true);
BackgroundThread.instance().postGUI(new Runnable() {
@Override
public void run() {
directoryUpdated(item.parent, null);
}}, 700);
}
});
}
}


}
});
}
Expand Down Expand Up @@ -1825,8 +1834,13 @@ public void askDeleteRecent(final FileInfo item)
askConfirmation(R.string.win_title_confirm_history_record_delete, new Runnable() {
@Override
public void run() {
Services.getHistory().removeBookInfo(getDB(), item, true, false);
directoryUpdated(Services.getScanner().createRecentRoot());
waitForCRDBService(new Runnable() {
@Override
public void run() {
Services.getHistory().removeBookInfo(getDB(), item, true, false);
directoryUpdated(Services.getScanner().createRecentRoot());
}
});
}
});
}
Expand All @@ -1837,8 +1851,13 @@ public void askDeleteCatalog(final FileInfo item)
@Override
public void run() {
if (item != null && item.isOPDSDir()) {
getDB().removeOPDSCatalog(item.id);
directoryUpdated(Services.getScanner().createRecentRoot());
waitForCRDBService(new Runnable() {
@Override
public void run() {
getDB().removeOPDSCatalog(item.id);
directoryUpdated(Services.getScanner().createRecentRoot());
}
});
}
}
});
Expand All @@ -1850,14 +1869,19 @@ public void saveSetting(String name, String value) {
}

public void editBookInfo(final FileInfo currDirectory, final FileInfo item) {
Services.getHistory().getOrCreateBookInfo(getDB(), item, new BookInfoLoadedCallack() {
waitForCRDBService(new Runnable() {
@Override
public void onBookInfoLoaded(BookInfo bookInfo) {
if (bookInfo == null)
bookInfo = new BookInfo(item);
BookInfoEditDialog dlg = new BookInfoEditDialog(CoolReader.this, currDirectory, bookInfo,
currDirectory.isRecentDir());
dlg.show();
public void run() {
Services.getHistory().getOrCreateBookInfo(getDB(), item, new BookInfoLoadedCallack() {
@Override
public void onBookInfoLoaded(BookInfo bookInfo) {
if (bookInfo == null)
bookInfo = new BookInfo(item);
BookInfoEditDialog dlg = new BookInfoEditDialog(CoolReader.this, currDirectory, bookInfo,
currDirectory.isRecentDir());
dlg.show();
}
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion android/src/org/coolreader/crengine/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected void bindCRDBService() {
* Wait until database is bound.
* @param readyCallback to be called after DB is ready
*/
public void waitForCRDBService(Runnable readyCallback) {
public synchronized void waitForCRDBService(Runnable readyCallback) {
if (mCRDBService == null) {
mCRDBService = new CRDBServiceAccessor(this, Engine.getInstance(this).getPathCorrector());
}
Expand Down
22 changes: 13 additions & 9 deletions android/src/org/coolreader/crengine/CRRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,19 @@ public void refreshRecentBooks() {
BackgroundThread.instance().postGUI(new Runnable() {
@Override
public void run() {
if (Services.getHistory() != null && mActivity.getDB() != null) {
Services.getHistory().getOrLoadRecentBooks(mActivity.getDB(), new CRDBService.RecentBooksLoadingCallback() {
@Override
public void onRecentBooksListLoaded(ArrayList<BookInfo> bookList) {
updateCurrentBook(bookList != null && bookList.size() > 0 ? bookList.get(0) : null);
updateRecentBooks(bookList);
}
});
}
mActivity.waitForCRDBService(new Runnable() {
@Override
public void run() {
if (Services.getHistory() != null && mActivity.getDB() != null)
Services.getHistory().getOrLoadRecentBooks(mActivity.getDB(), new CRDBService.RecentBooksLoadingCallback() {
@Override
public void onRecentBooksListLoaded(ArrayList<BookInfo> bookList) {
updateCurrentBook(bookList != null && bookList.size() > 0 ? bookList.get(0) : null);
updateRecentBooks(bookList);
}
});
}
});
}
});
}
Expand Down
3 changes: 0 additions & 3 deletions android/src/org/coolreader/crengine/OptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3746,9 +3746,6 @@ private void setupBrowserOptions(String filter)

mOptionsBrowser = new OptionsListView(getContext(), null);

final Properties properties = new Properties();
Properties sett = mActivity.settings();
properties.setProperty(ReaderView.PROP_APP_BOOK_SORT_ORDER, sett.getProperty(ReaderView.PROP_APP_BOOK_SORT_ORDER));
int[] sortOrderLabels = {
FileInfo.SortOrder.FILENAME.resourceId,
FileInfo.SortOrder.FILENAME_DESC.resourceId,
Expand Down
11 changes: 9 additions & 2 deletions android/src/org/coolreader/crengine/Properties.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.coolreader.crengine;

import android.util.Log;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("serial")
public class Properties extends java.util.Properties {
public static final Logger elog = L.create("props", Log.ERROR);

public Properties() {
super();
}
Expand Down Expand Up @@ -130,9 +134,12 @@ synchronized public String getProperty(String name) {

@Override
synchronized public Object setProperty(String name, String value) {
if (!StrUtils.isEmptyStr(name))
try {
return super.setProperty(name, value);
else return null;
} catch (NullPointerException e) {
elog.e("Properties.setProperty(): value can't be null, name=" + name);
return null;
}
}

@Override
Expand Down
59 changes: 53 additions & 6 deletions android/src/org/coolreader/crengine/TTSToolbarDlg.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class TTSToolbarDlg implements TTS.OnUtteranceCompletedListener {
TTS mTTS;
private static NotificationChannel channel;
ImageButton playPauseButton;
ImageButton playPauseButtonEll;
ImageView ivVolDown;
ImageView ivVolUp;
ImageView ivFreqDown;
Expand Down Expand Up @@ -92,12 +93,12 @@ public void onReceive(Context context, Intent intent) {
break;
case ACTION_TTS_PLAY:
if (!isSpeaking) {
toggleStartStop();
toggleStartStopExt(false);
}
break;
case ACTION_TTS_PAUSE:
if (isSpeaking) {
toggleStartStop();
toggleStartStopExt(false);
}
break;
case ACTION_TTS_NEXT:
Expand Down Expand Up @@ -351,7 +352,7 @@ public void onNewSelection(Selection selection) {
}
currentSelection = selection;
if ( isSpeaking ) {
mTTS.stop(); //plotn - experiments
if (isAlwaysStop) mTTS.stop();
say(currentSelection);
}
}
Expand Down Expand Up @@ -397,6 +398,7 @@ private void startMotionWatchdog(){
}

private boolean isSpeaking;
private boolean isAlwaysStop;
private long curTime = System.currentTimeMillis();
private long lastSaveCurPosTime = System.currentTimeMillis();

Expand All @@ -412,27 +414,53 @@ private void stop() {

public void pause() {
if (isSpeaking)
toggleStartStop();
toggleStartStopExt(false);
}


private void toggleStartStopExt(boolean b) {
isAlwaysStop = b;
toggleStartStop();
}

private void toggleStartStop() {
int colorGrayC;
TypedArray a = mCoolReader.getTheme().obtainStyledAttributes(new int[]
{R.attr.colorThemeGray2Contrast, R.attr.colorThemeGray2});
colorGrayC = a.getColor(0, Color.GRAY);
a.recycle();

ColorDrawable c = new ColorDrawable(colorGrayC);
c.setAlpha(130);

if ( isSpeaking ) {
playPauseButton.setImageResource(
Utils.resolveResourceIdByAttr(mCoolReader, R.attr.attr_ic_media_play, R.drawable.ic_media_play)
//R.drawable.ic_media_play
);
playPauseButtonEll.setImageResource(
Utils.resolveResourceIdByAttr(mCoolReader, R.attr.attr_ic_media_play_ell, R.drawable.icons8_play_ell)
//R.drawable.ic_media_play
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setMediaSessionPlaybackState(PlaybackState.STATE_STOPPED);
}
playPauseButton.setBackgroundDrawable(c);
playPauseButtonEll.setBackgroundDrawable(c);
stop();
} else {
playPauseButton.setImageResource(
Utils.resolveResourceIdByAttr(mCoolReader, R.attr.attr_ic_media_pause, R.drawable.ic_media_pause)
//R.drawable.ic_media_pause
);
playPauseButtonEll.setImageResource(
Utils.resolveResourceIdByAttr(mCoolReader, R.attr.attr_ic_media_pause, R.drawable.ic_media_pause)
//R.drawable.ic_media_pause
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setMediaSessionPlaybackState(PlaybackState.STATE_PLAYING);
}
playPauseButton.setBackgroundDrawable(c);
playPauseButtonEll.setBackgroundDrawable(c);
start();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -480,6 +508,12 @@ public TTSToolbarDlg( CoolReader coolReader, ReaderView readerView, TTS tts )
//R.drawable.ic_media_play
);
playPauseButton.setBackgroundDrawable(c);
playPauseButtonEll = (ImageButton)panel.findViewById(R.id.tts_play_pause_ell);
playPauseButtonEll.setImageResource(
Utils.resolveResourceIdByAttr(mCoolReader, R.attr.attr_ic_media_play_ell, R.drawable.icons8_play_ell)
//R.drawable.ic_media_play
);
playPauseButtonEll.setBackgroundDrawable(c);
//panel.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
panel.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

Expand All @@ -505,7 +539,12 @@ public TTSToolbarDlg( CoolReader coolReader, ReaderView readerView, TTS tts )
mPanel.findViewById(R.id.tts_play_pause).setBackgroundDrawable(c);
mPanel.findViewById(R.id.tts_play_pause).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
toggleStartStop();
toggleStartStopExt(false);
}
});
mPanel.findViewById(R.id.tts_play_pause_ell).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
toggleStartStopExt(true);
}
});
mPanel.findViewById(R.id.tts_play_pause).setOnLongClickListener(new View.OnLongClickListener() {
Expand All @@ -516,6 +555,14 @@ public boolean onLongClick(View v) {
return true;
}
});
mPanel.findViewById(R.id.tts_play_pause_ell).setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
mCoolReader.tts = null;
mCoolReader.ttsInitialized = false;
mCoolReader.showToast("Re-initializing TTS");
return true;
}
});
mPanel.findViewById(R.id.tts_back).setBackgroundDrawable(c);
mPanel.findViewById(R.id.tts_back).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Expand Down
Loading

0 comments on commit 00711c4

Please sign in to comment.