Skip to content

Commit

Permalink
Merge pull request #271 from virxkane/int-fileman-background
Browse files Browse the repository at this point in the history
Internal file manager background operations
  • Loading branch information
buggins committed Mar 21, 2021
2 parents c051af1 + c37e704 commit af6c46c
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 137 deletions.
52 changes: 28 additions & 24 deletions android/res/layout/browser_status_bar.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/title"
style="@style/TextAppearance.Medium"
android:text="@null"
android:singleLine="true"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:paddingTop="3dip"
android:paddingBottom="3dip"

android:ellipsize="start"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/title"
style="@style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_weight="10"
android:ellipsize="start"
android:paddingTop="3dip"

android:paddingBottom="3dip"
android:singleLine="true"
android:text="@null" />

<ProgressBar
android:id="@+id/progress"
style="@android:style/Widget.ProgressBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:visibility="gone" />

</LinearLayout>
<!-- /LinearLayout-->
1 change: 1 addition & 0 deletions android/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,5 @@
<string name="inconsistent_options">Обнаружены противоречивые настройки: в разделе "Сенсорный экран" отключено меню чтения, в разделе "кнопки" меню чтения не связано ни с одной кнопкой, кроме того выключена панель инструментов. Чтобы не потерять функционал программы выберите один вариант: либо включить отображение панели инструментов либо добавить действие для вывода меню чтения на сенсорный экран</string>
<string name="inconsistent_options_toolbar">Включить панель инструментов</string>
<string name="inconsistent_options_tap_reading_menu">Добавить меню чтения на сенсорный экран</string>
<string name="options_hide_empty_dirs_slowdown">(Может замедлить вывод содержимого каталога)</string>
</resources>
1 change: 1 addition & 0 deletions android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,5 @@
<string name="inconsistent_options">Inconsistent options were found: the reading menu was disabled in the "Tap zone actions" section, the reading menu was not associated with any buttons in the "Keys actions" section, and the toolbar was also disabled. In order not to lose the functionality of the program, choose variant: enable the display of the toolbar, or add an action to display the reading menu on the touch screen</string>
<string name="inconsistent_options_toolbar">enable toolbar</string>
<string name="inconsistent_options_tap_reading_menu">add reading menu on the touch screen</string>
<string name="options_hide_empty_dirs_slowdown">(May slow down the listing of directory contents)</string>
</resources>
25 changes: 25 additions & 0 deletions android/src/org/coolreader/CoolReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ public void applyAppSetting(String key, String value) {
} else if (key.equals(PROP_APP_CLOUDSYNC_DATA_KEEPALIVE)) {
mCloudSyncBookmarksKeepAlive = Utils.parseInt(value, 14, 0, 365);
updateGoogleDriveSynchronizer();
} else if (key.equals(PROP_APP_FILE_BROWSER_HIDE_EMPTY_FOLDERS)) {
// already in super method:
// Services.getScanner().setHideEmptyDirs(flg);
// Here only refresh the file browser
if (null != mBrowser) {
mBrowser.showLastDirectory();
}
} else if (key.equals(PROP_APP_FILE_BROWSER_HIDE_EMPTY_GENRES)) {
if (null != mBrowser) {
mBrowser.setHideEmptyGenres(flg);
Expand Down Expand Up @@ -765,6 +772,9 @@ protected void onPause() {
if (mReaderView != null) {
mReaderView.onAppPause();
}
if (mBrowser != null) {
mBrowser.stopCurrentScan();
}
Services.getCoverpageManager().removeCoverpageReadyListener(mHomeFrame);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (mSyncGoogleDriveEnabled && mGoogleDriveSync != null && !mGoogleDriveSync.isBusy()) {
Expand Down Expand Up @@ -1155,6 +1165,9 @@ private void setCurrentFrame(ViewGroup newFrame) {
if (mCurrentFrame == mBrowserFrame) {
// update recent books directory
mBrowser.refreshDirectory(Services.getScanner().getRecentDir(), null);
} else {
if (null != mBrowser)
mBrowser.stopCurrentScan();
}
onUserActivity();
}
Expand All @@ -1167,6 +1180,8 @@ public void showReader() {
}

public void showRootWindow() {
if (null != mBrowser)
mBrowser.stopCurrentScan();
setCurrentFrame(mHomeFrame);
if (activityIsRunning) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Expand All @@ -1179,6 +1194,8 @@ public void showRootWindow() {
}

private void runInReader(final Runnable task) {
if (null != mBrowser)
mBrowser.stopCurrentScan();
waitForCRDBService(() -> {
if (mReaderFrame != null) {
task.run();
Expand Down Expand Up @@ -1404,6 +1421,14 @@ public void setBrowserTitle(String title) {
mBrowserFrame.setBrowserTitle(title);
}

public void setBrowserProgressStatus(boolean enable) {
if (!enable) {
log.e("setBrowserProgressStatus(false)");
}
if (mBrowserFrame != null)
mBrowserFrame.setBrowserProgressStatus(enable);
}


// Dictionary support

Expand Down
8 changes: 7 additions & 1 deletion android/src/org/coolreader/crengine/BrowserViewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.coolreader.R;
Expand Down Expand Up @@ -42,7 +43,12 @@ public void setBrowserTitle(String title) {
this.browserTitle = title;
((TextView)titleView.findViewById(R.id.title)).setText(title);
}


public void setBrowserProgressStatus(boolean enable) {
ProgressBar progressBar = titleView.findViewById(R.id.progress);
progressBar.setVisibility(enable ? View.VISIBLE : View.GONE);
}

public void onThemeChanged(InterfaceTheme theme) {
//titleView.setBackgroundResource(theme.getBrowserStatusBackground());
//toolbarView.setButtonAlpha(theme.getToolbarButtonAlpha());
Expand Down
58 changes: 49 additions & 9 deletions android/src/org/coolreader/crengine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,17 @@ public void fatalError(String msg) {
// });
// }
// }

public void showProgress(final int mainProgress, final int resourceId) {
showProgress(mainProgress,
mActivity.getResources().getString(resourceId));
}

public void showProgress(final int mainProgress, final int resourceId, Scanner.ScanControl scanControl) {
showProgress(mainProgress,
mActivity.getResources().getString(resourceId), scanControl);
}

private String mProgressMessage = null;
private int mProgressPos = 0;

Expand Down Expand Up @@ -369,6 +375,18 @@ public DelayedProgress showProgressDelayed(final int mainProgress, final String
* @param msg is progress message
*/
public void showProgress(final int mainProgress, final String msg) {
showProgress(mainProgress, msg, null);
}

/**
* Show progress dialog.
* (thread-safe)
*
* @param mainProgress is percent*100
* @param msg is progress message
* @param scanControl control to interrupt process, can be null.
*/
public void showProgress(final int mainProgress, final String msg, Scanner.ScanControl scanControl) {
final int progressId = ++nextProgressId;
mProgressMessage = msg;
mProgressPos = mainProgress;
Expand All @@ -392,21 +410,25 @@ public void showProgress(final int mainProgress, final String msg) {
try {
if (mActivity != null && mActivity.isStarted()) {
mProgress = new ProgressDialog(mActivity);
mProgress
.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
if (progressIcon != null)
mProgress.setIcon(progressIcon);
else
mProgress.setIcon(R.mipmap.cr3_logo);
mProgress.setMax(10000);
mProgress.setCancelable(false);
mProgress.setCancelable(null != scanControl);
mProgress.setProgress(mainProgress);
mProgress
.setTitle(mActivity
mProgress.setTitle(mActivity
.getResources()
.getString(
R.string.progress_please_wait));
mProgress.setMessage(msg);
mProgress.setOnCancelListener(dialog -> {
if (null != scanControl) {
log.e("scanControl.stop()");
scanControl.stop();
}
});
mProgress.show();
progressShown = true;
}
Expand All @@ -420,6 +442,13 @@ public void showProgress(final int mainProgress, final String msg) {
} else {
mProgress.setProgress(mainProgress);
mProgress.setMessage(msg);
mProgress.setCancelable(null != scanControl);
mProgress.setOnCancelListener(dialog -> {
if (null != scanControl) {
log.e("scanControl.stop()");
scanControl.stop();
}
});
if (!mProgress.isShowing()) {
mProgress.show();
progressShown = true;
Expand Down Expand Up @@ -1944,17 +1973,28 @@ public ProgressControl createProgress(int resourceId) {
return new ProgressControl(resourceId);
}

private static final int PROGRESS_UPDATE_INTERVAL = DeviceInfo.EINK_SCREEN ? 4000 : 500;
private static final int PROGRESS_SHOW_INTERVAL = DeviceInfo.EINK_SCREEN ? 4000 : 1500;
public ProgressControl createProgress(int resourceId, Scanner.ScanControl scanControl) {
return new ProgressControl(resourceId, scanControl);
}

private static final int PROGRESS_UPDATE_INTERVAL = DeviceInfo.EINK_SCREEN ? 1000 : 500;
private static final int PROGRESS_SHOW_INTERVAL = DeviceInfo.EINK_SCREEN ? 1000 : 500;

public class ProgressControl {
private final int resourceId;
private long createTime = Utils.timeStamp();
private final long createTime = Utils.timeStamp();
private final Scanner.ScanControl scanControl;
private long lastUpdateTime;
private boolean shown;

private ProgressControl(int resourceId) {
this.resourceId = resourceId;
this.scanControl = null;
}

private ProgressControl(int resourceId, Scanner.ScanControl scanControl) {
this.resourceId = resourceId;
this.scanControl = scanControl;
}

public void hide() {
Expand All @@ -1974,7 +2014,7 @@ public void setProgress(int percent) {
return;
shown = true;
lastUpdateTime = Utils.timeStamp();
showProgress(percent, resourceId);
showProgress(percent, resourceId, scanControl);
}
}

Expand Down
Loading

0 comments on commit af6c46c

Please sign in to comment.