Merge remote-tracking branch 'origin/master'

This commit is contained in:
Elad Keyshawn 2017-01-15 10:43:22 +02:00
commit 66a1a99ffd
4 changed files with 67 additions and 29 deletions

View File

@ -44,7 +44,7 @@
<string name="pref_info_version">Version</string>
<string name="pref_zoom_enable">Zoom controls</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_summary">Display a button at the end of the page to scroll up to the top</string>
<string name="pref_language_title">Language</string>
@ -102,10 +102,10 @@
<string name="delete_specific_zim_toast">File deleted</string>
<string name="zim_file_downloading">Downloading</string>
<string name="zim_file_downloaded">Downloaded</string>
<string name="download_pause">pause</string>
<string name="download_play">play</string>
<string name="download_stop">stop</string>
<string name="download_close">close</string>
<string name="download_pause">Pause</string>
<string name="download_play">Play</string>
<string name="download_stop">Stop</string>
<string name="download_close">Close</string>
<string name="no_downloads_here">No downloads here</string>
<string name="no_files_here">No files here</string>
<string name="download_complete_snackbar">Download complete</string>

View File

@ -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;
@ -1007,6 +1001,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("");
@ -1211,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:

View File

@ -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));
}
}

View File

@ -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<String> 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) {