From d0c79b4ee228ef868c454c51a38845f5a9bacaed Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Mon, 9 Jan 2017 20:09:11 +0000 Subject: [PATCH 1/4] Readd deleted code --- src/org/kiwix/kiwixmobile/KiwixMobileActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 29dafd83e..e556738ca 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -1007,6 +1007,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { i.putExtra(Intent.EXTRA_PROCESS_TEXT, intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)); } + intent.setAction(""); startActivityForResult(i, REQUEST_FILE_SEARCH); } else if (intent.getAction().equals(KiwixSearchWidget.TEXT_CLICKED)){ intent.setAction(""); From 565050f321110ffaa711fcca5a11a3a118c76b80 Mon Sep 17 00:00:00 2001 From: Rashiq Date: Thu, 12 Jan 2017 22:19:06 +0100 Subject: [PATCH 2/4] Remove unnecessary handlers --- .../kiwixmobile/KiwixMobileActivity.java | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index e556738ca..69e2dc76f 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -37,7 +37,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.os.Looper; import android.preference.PreferenceManager; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; @@ -383,15 +382,10 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal LibraryFragment.mService.cancelNotification(i.getIntExtra("notificationID", 0)); Uri uri = Uri.fromFile(file); - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - finish(); - Intent newZimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class); - newZimFile.setData(uri); - startActivity(newZimFile); - } - }); + finish(); + Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class); + zimFile.setData(uri); + startActivity(zimFile); } } @@ -625,8 +619,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal tabDrawerAdapter.setSelected(currentWebViewIndex); if (drawerLayout.isDrawerOpen(GravityCompat.START)) { - final Handler handler = new Handler(); - handler.postDelayed(() -> drawerLayout.closeDrawers(), 150); + new Handler().postDelayed(() -> drawerLayout.closeDrawers(), 150); } loadPrefs(); if (menu != null) { @@ -636,7 +629,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal } public KiwixWebView getCurrentWebView() { - if (mWebViews.size() == 0) { return newTab(); } + if (mWebViews.size() == 0) return newTab(); if (currentWebViewIndex < mWebViews.size()) { return mWebViews.get(currentWebViewIndex); } else { @@ -669,6 +662,7 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal case R.id.menu_bookmarks_list: goToBookmarks(); break; + case R.id.menu_randomarticle: openRandomArticle(); break; @@ -1212,15 +1206,10 @@ public class KiwixMobileActivity extends AppCompatActivity implements WebViewCal return; } - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - finish(); - Intent newZimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class); - newZimFile.setData(uri); - startActivity(newZimFile); - } - }); + finish(); + Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class); + zimFile.setData(uri); + startActivity(zimFile); } break; case REQUEST_FILE_SEARCH: From 9915755297abb573583e2b1b4a6660bfb6b315bd Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Fri, 13 Jan 2017 22:31:42 +0000 Subject: [PATCH 3/4] Update night mode description --- res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index d88aa87e7..b62f660b8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -44,7 +44,7 @@ Version Zoom controls Night mode - Show articles with reverted colors + Show articles with inverted colors Back to Top Display a button at the end of the page to scroll up to the top Language From 3f7e0fddaab6f4acca3fbbea77f754478137e082 Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Sat, 14 Jan 2017 23:33:57 +0000 Subject: [PATCH 4/4] Add play/pause stop buttons to Android download notifications #435 --- res/values/strings.xml | 8 ++-- .../downloader/DownloadFragment.java | 6 ++- .../downloader/DownloadService.java | 46 ++++++++++++++++++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index b62f660b8..da5839c9c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -102,10 +102,10 @@ File deleted Downloading Downloaded - pause - play - stop - close + Pause + Play + Stop + Close No downloads here No files here Download complete diff --git a/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java b/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java index d37315c78..588223c17 100644 --- a/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java +++ b/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java @@ -10,6 +10,7 @@ import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; +import android.support.v4.content.ContextCompat; import android.util.Base64; import android.view.LayoutInflater; import android.view.View; @@ -159,7 +160,10 @@ public class DownloadFragment extends Fragment { if (LibraryFragment.mService.downloadProgress.get(mKeys[position]) != 0) { downloadProgress.setProgress(LibraryFragment.mService.downloadProgress.get(mKeys[position])); 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)); } } diff --git a/src/org/kiwix/kiwixmobile/downloader/DownloadService.java b/src/org/kiwix/kiwixmobile/downloader/DownloadService.java index db73e1bc5..0547f4acb 100644 --- a/src/org/kiwix/kiwixmobile/downloader/DownloadService.java +++ b/src/org/kiwix/kiwixmobile/downloader/DownloadService.java @@ -53,6 +53,9 @@ public class DownloadService extends Service { public static final int PAUSE = 2; public static final int FINISH = 3; 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 ArrayList notifications = new ArrayList<>(); public String notificationTitle; @@ -89,10 +92,20 @@ public class DownloadService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - DownloadService.notificationCount++; if (intent == null) { 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()) .getString(KiwixMobileActivity.PREF_STORAGE,Environment.getExternalStorageDirectory().getPath()); KIWIX_ROOT = SD_CARD + "/Kiwix/"; @@ -110,12 +123,22 @@ public class DownloadService extends Service { (getBaseContext(), 0, 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) .setContentTitle(getResources().getString(R.string.zim_file_downloading) + " " + notificationTitle) .setProgress(100, 0, false) .setSmallIcon(R.drawable.kiwix_notification) .setColor(Color.BLACK) .setContentIntent(pendingIntent) + .addAction(pause) + .addAction(stop) .setOngoing(true)); downloadStatus.put(notificationCount, PLAY); @@ -129,6 +152,9 @@ public class DownloadService extends Service { synchronized (pauseLock) { pauseLock.notify(); } + downloadFragment.mDownloads.remove(notificationID); + downloadFragment.mDownloadFiles.remove(notificationID); + downloadFragment.downloadAdapter.notifyDataSetChanged(); updateForeground(); 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) { 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) { @@ -162,6 +201,11 @@ public class DownloadService extends Service { synchronized (pauseLock) { 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) {