mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 03:45:33 -04:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
66a1a99ffd
@ -44,7 +44,7 @@
|
|||||||
<string name="pref_info_version">Version</string>
|
<string name="pref_info_version">Version</string>
|
||||||
<string name="pref_zoom_enable">Zoom controls</string>
|
<string name="pref_zoom_enable">Zoom controls</string>
|
||||||
<string name="pref_nightmode">Night mode</string>
|
<string name="pref_nightmode">Night mode</string>
|
||||||
<string name="pref_nightmode_summary">Show articles with reverted colors</string>
|
<string name="pref_nightmode_summary">Show articles with inverted colors</string>
|
||||||
<string name="pref_backtotop">Back to Top</string>
|
<string name="pref_backtotop">Back to Top</string>
|
||||||
<string name="pref_backtotop_summary">Display a button at the end of the page to scroll up to the top</string>
|
<string name="pref_backtotop_summary">Display a button at the end of the page to scroll up to the top</string>
|
||||||
<string name="pref_language_title">Language</string>
|
<string name="pref_language_title">Language</string>
|
||||||
@ -102,10 +102,10 @@
|
|||||||
<string name="delete_specific_zim_toast">File deleted</string>
|
<string name="delete_specific_zim_toast">File deleted</string>
|
||||||
<string name="zim_file_downloading">Downloading</string>
|
<string name="zim_file_downloading">Downloading</string>
|
||||||
<string name="zim_file_downloaded">Downloaded</string>
|
<string name="zim_file_downloaded">Downloaded</string>
|
||||||
<string name="download_pause">pause</string>
|
<string name="download_pause">Pause</string>
|
||||||
<string name="download_play">play</string>
|
<string name="download_play">Play</string>
|
||||||
<string name="download_stop">stop</string>
|
<string name="download_stop">Stop</string>
|
||||||
<string name="download_close">close</string>
|
<string name="download_close">Close</string>
|
||||||
<string name="no_downloads_here">No downloads here</string>
|
<string name="no_downloads_here">No downloads here</string>
|
||||||
<string name="no_files_here">No files here</string>
|
<string name="no_files_here">No files here</string>
|
||||||
<string name="download_complete_snackbar">Download complete</string>
|
<string name="download_complete_snackbar">Download complete</string>
|
||||||
|
@ -37,7 +37,6 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
@ -383,15 +382,10 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal
|
|||||||
LibraryFragment.mService.cancelNotification(i.getIntExtra("notificationID", 0));
|
LibraryFragment.mService.cancelNotification(i.getIntExtra("notificationID", 0));
|
||||||
Uri uri = Uri.fromFile(file);
|
Uri uri = Uri.fromFile(file);
|
||||||
|
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
finish();
|
||||||
@Override
|
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
|
||||||
public void run() {
|
zimFile.setData(uri);
|
||||||
finish();
|
startActivity(zimFile);
|
||||||
Intent newZimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
|
|
||||||
newZimFile.setData(uri);
|
|
||||||
startActivity(newZimFile);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,8 +619,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal
|
|||||||
tabDrawerAdapter.setSelected(currentWebViewIndex);
|
tabDrawerAdapter.setSelected(currentWebViewIndex);
|
||||||
|
|
||||||
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||||
final Handler handler = new Handler();
|
new Handler().postDelayed(() -> drawerLayout.closeDrawers(), 150);
|
||||||
handler.postDelayed(() -> drawerLayout.closeDrawers(), 150);
|
|
||||||
}
|
}
|
||||||
loadPrefs();
|
loadPrefs();
|
||||||
if (menu != null) {
|
if (menu != null) {
|
||||||
@ -636,7 +629,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal
|
|||||||
}
|
}
|
||||||
|
|
||||||
public KiwixWebView getCurrentWebView() {
|
public KiwixWebView getCurrentWebView() {
|
||||||
if (mWebViews.size() == 0) { return newTab(); }
|
if (mWebViews.size() == 0) return newTab();
|
||||||
if (currentWebViewIndex < mWebViews.size()) {
|
if (currentWebViewIndex < mWebViews.size()) {
|
||||||
return mWebViews.get(currentWebViewIndex);
|
return mWebViews.get(currentWebViewIndex);
|
||||||
} else {
|
} else {
|
||||||
@ -669,6 +662,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal
|
|||||||
case R.id.menu_bookmarks_list:
|
case R.id.menu_bookmarks_list:
|
||||||
goToBookmarks();
|
goToBookmarks();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.menu_randomarticle:
|
case R.id.menu_randomarticle:
|
||||||
openRandomArticle();
|
openRandomArticle();
|
||||||
break;
|
break;
|
||||||
@ -1007,6 +1001,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
i.putExtra(Intent.EXTRA_PROCESS_TEXT, intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT));
|
i.putExtra(Intent.EXTRA_PROCESS_TEXT, intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT));
|
||||||
}
|
}
|
||||||
|
intent.setAction("");
|
||||||
startActivityForResult(i, REQUEST_FILE_SEARCH);
|
startActivityForResult(i, REQUEST_FILE_SEARCH);
|
||||||
} else if (intent.getAction().equals(KiwixSearchWidget.TEXT_CLICKED)){
|
} else if (intent.getAction().equals(KiwixSearchWidget.TEXT_CLICKED)){
|
||||||
intent.setAction("");
|
intent.setAction("");
|
||||||
@ -1211,15 +1206,10 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
finish();
|
||||||
@Override
|
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
|
||||||
public void run() {
|
zimFile.setData(uri);
|
||||||
finish();
|
startActivity(zimFile);
|
||||||
Intent newZimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
|
|
||||||
newZimFile.setData(uri);
|
|
||||||
startActivity(newZimFile);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REQUEST_FILE_SEARCH:
|
case REQUEST_FILE_SEARCH:
|
||||||
|
@ -10,6 +10,7 @@ import android.support.design.widget.CoordinatorLayout;
|
|||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -159,7 +160,10 @@ public class DownloadFragment extends Fragment {
|
|||||||
if (LibraryFragment.mService.downloadProgress.get(mKeys[position]) != 0) {
|
if (LibraryFragment.mService.downloadProgress.get(mKeys[position]) != 0) {
|
||||||
downloadProgress.setProgress(LibraryFragment.mService.downloadProgress.get(mKeys[position]));
|
downloadProgress.setProgress(LibraryFragment.mService.downloadProgress.get(mKeys[position]));
|
||||||
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PAUSE) {
|
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PAUSE) {
|
||||||
pause.setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_black_24dp));
|
pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp));
|
||||||
|
}
|
||||||
|
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY) {
|
||||||
|
pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_24dp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,9 @@ public class DownloadService extends Service {
|
|||||||
public static final int PAUSE = 2;
|
public static final int PAUSE = 2;
|
||||||
public static final int FINISH = 3;
|
public static final int FINISH = 3;
|
||||||
public static final int CANCEL = 4;
|
public static final int CANCEL = 4;
|
||||||
|
public static final String ACTION_PAUSE = "PAUSE";
|
||||||
|
public static final String ACTION_STOP = "STOP";
|
||||||
|
public static final String NOTIFICATION_ID = "NOTIFICATION_ID";
|
||||||
public static int notificationCount = 1;
|
public static int notificationCount = 1;
|
||||||
public static ArrayList<String> notifications = new ArrayList<>();
|
public static ArrayList<String> notifications = new ArrayList<>();
|
||||||
public String notificationTitle;
|
public String notificationTitle;
|
||||||
@ -89,10 +92,20 @@ public class DownloadService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
DownloadService.notificationCount++;
|
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
if (intent.hasExtra(NOTIFICATION_ID) && intent.getAction().equals(ACTION_STOP)) {
|
||||||
|
stopDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
if (intent.hasExtra(NOTIFICATION_ID) && intent.getAction().equals(ACTION_PAUSE)) {
|
||||||
|
toggleDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DownloadService.notificationCount++;
|
||||||
SD_CARD = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
|
SD_CARD = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
|
||||||
.getString(KiwixMobileActivity.PREF_STORAGE,Environment.getExternalStorageDirectory().getPath());
|
.getString(KiwixMobileActivity.PREF_STORAGE,Environment.getExternalStorageDirectory().getPath());
|
||||||
KIWIX_ROOT = SD_CARD + "/Kiwix/";
|
KIWIX_ROOT = SD_CARD + "/Kiwix/";
|
||||||
@ -110,12 +123,22 @@ public class DownloadService extends Service {
|
|||||||
(getBaseContext(), 0,
|
(getBaseContext(), 0,
|
||||||
target, PendingIntent.FLAG_CANCEL_CURRENT);
|
target, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
|
||||||
|
Intent pauseIntent = new Intent(this, this.getClass()).setAction(ACTION_PAUSE).putExtra(NOTIFICATION_ID, notificationCount);
|
||||||
|
Intent stopIntent = new Intent(this, this.getClass()).setAction(ACTION_STOP).putExtra(NOTIFICATION_ID, notificationCount);;
|
||||||
|
PendingIntent pausePending = PendingIntent.getService(getBaseContext(), 0, pauseIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
PendingIntent stopPending = PendingIntent.getService(getBaseContext(), 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
|
||||||
|
NotificationCompat.Action pause = new NotificationCompat.Action(R.drawable.ic_pause_black_24dp, getString(R.string.download_pause), pausePending);
|
||||||
|
NotificationCompat.Action stop = new NotificationCompat.Action(R.drawable.ic_stop_black_24dp, getString(R.string.download_stop), stopPending);
|
||||||
|
|
||||||
notification.put(notificationCount , new NotificationCompat.Builder(this)
|
notification.put(notificationCount , new NotificationCompat.Builder(this)
|
||||||
.setContentTitle(getResources().getString(R.string.zim_file_downloading) + " " + notificationTitle)
|
.setContentTitle(getResources().getString(R.string.zim_file_downloading) + " " + notificationTitle)
|
||||||
.setProgress(100, 0, false)
|
.setProgress(100, 0, false)
|
||||||
.setSmallIcon(R.drawable.kiwix_notification)
|
.setSmallIcon(R.drawable.kiwix_notification)
|
||||||
.setColor(Color.BLACK)
|
.setColor(Color.BLACK)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
|
.addAction(pause)
|
||||||
|
.addAction(stop)
|
||||||
.setOngoing(true));
|
.setOngoing(true));
|
||||||
|
|
||||||
downloadStatus.put(notificationCount, PLAY);
|
downloadStatus.put(notificationCount, PLAY);
|
||||||
@ -129,6 +152,9 @@ public class DownloadService extends Service {
|
|||||||
synchronized (pauseLock) {
|
synchronized (pauseLock) {
|
||||||
pauseLock.notify();
|
pauseLock.notify();
|
||||||
}
|
}
|
||||||
|
downloadFragment.mDownloads.remove(notificationID);
|
||||||
|
downloadFragment.mDownloadFiles.remove(notificationID);
|
||||||
|
downloadFragment.downloadAdapter.notifyDataSetChanged();
|
||||||
updateForeground();
|
updateForeground();
|
||||||
notificationManager.cancel(notificationID);
|
notificationManager.cancel(notificationID);
|
||||||
}
|
}
|
||||||
@ -153,8 +179,21 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleDownload (int notificationID) {
|
||||||
|
if (downloadStatus.get(notificationID) == PAUSE) {
|
||||||
|
playDownload(notificationID);
|
||||||
|
} else {
|
||||||
|
pauseDownload(notificationID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void pauseDownload(int notificationID) {
|
public void pauseDownload(int notificationID) {
|
||||||
downloadStatus.put(notificationID, PAUSE);
|
downloadStatus.put(notificationID, PAUSE);
|
||||||
|
notification.get(notificationID).mActions.get(0).title = getString(R.string.download_play);
|
||||||
|
notification.get(notificationID).mActions.get(0).icon = R.drawable.ic_play_arrow_black_24dp;
|
||||||
|
notificationManager.notify(notificationID, notification.get(notificationID).build());
|
||||||
|
downloadFragment.downloadAdapter.notifyDataSetChanged();
|
||||||
|
downloadFragment.listView.invalidateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playDownload(int notificationID) {
|
public void playDownload(int notificationID) {
|
||||||
@ -162,6 +201,11 @@ public class DownloadService extends Service {
|
|||||||
synchronized (pauseLock) {
|
synchronized (pauseLock) {
|
||||||
pauseLock.notify();
|
pauseLock.notify();
|
||||||
}
|
}
|
||||||
|
notification.get(notificationID).mActions.get(0).title = getString(R.string.download_pause);
|
||||||
|
notification.get(notificationID).mActions.get(0).icon = R.drawable.ic_pause_black_24dp;
|
||||||
|
notificationManager.notify(notificationID, notification.get(notificationID).build());
|
||||||
|
downloadFragment.downloadAdapter.notifyDataSetChanged();
|
||||||
|
downloadFragment.listView.invalidateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadBook(String url, int notificationID, LibraryNetworkEntity.Book book) {
|
private void downloadBook(String url, int notificationID, LibraryNetworkEntity.Book book) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user