Android Clicking notifications now does the intuitive action

This commit is contained in:
mhutti1 2016-08-12 22:14:51 +01:00
parent a31a7d4c98
commit d18efe8d9a
2 changed files with 33 additions and 20 deletions

View File

@ -84,6 +84,7 @@ import android.widget.Toast;
import org.json.JSONArray; import org.json.JSONArray;
import org.kiwix.kiwixmobile.database.BookmarksDao; import org.kiwix.kiwixmobile.database.BookmarksDao;
import org.kiwix.kiwixmobile.database.KiwixDatabase; import org.kiwix.kiwixmobile.database.KiwixDatabase;
import org.kiwix.kiwixmobile.downloader.DownloadService;
import org.kiwix.kiwixmobile.settings.Constants; import org.kiwix.kiwixmobile.settings.Constants;
import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity; import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity;
import org.kiwix.kiwixmobile.utils.HTMLUtils; import org.kiwix.kiwixmobile.utils.HTMLUtils;
@ -461,12 +462,29 @@ public class KiwixMobileActivity extends AppCompatActivity {
} else if (IS_WIDGET_VOICE_SEARCH && ZimContentProvider.getId() != null) { } else if (IS_WIDGET_VOICE_SEARCH && ZimContentProvider.getId() != null) {
goToSearch(true); goToSearch(true);
} else if (IS_WIDGET_STAR || IS_WIDGET_SEARCH_INTENT || IS_WIDGET_VOICE_SEARCH) { } else if (IS_WIDGET_STAR || IS_WIDGET_SEARCH_INTENT || IS_WIDGET_VOICE_SEARCH) {
manageZimFiles(); manageZimFiles(0);
} }
Intent i = getIntent(); Intent i = getIntent();
if (i.getBooleanExtra("library",false)){ if (i.getBooleanExtra("library",false)){
manageZimFiles(); manageZimFiles(2);
}
if (i.hasExtra("zimFile")){
File file = new File(i.getStringExtra("zimFile"));
Uri uri = Uri.fromFile(file);
if (file == null) {
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);
}
});
} }
} }
@ -778,7 +796,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
break; break;
case R.id.menu_openfile: case R.id.menu_openfile:
manageZimFiles(); manageZimFiles(0);
break; break;
case R.id.menu_settings: case R.id.menu_settings:
@ -1079,7 +1097,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
} else if (IS_WIDGET_VOICE_SEARCH && ZimContentProvider.getId() != null) { } else if (IS_WIDGET_VOICE_SEARCH && ZimContentProvider.getId() != null) {
goToSearch(true); goToSearch(true);
} else if (IS_WIDGET_STAR || IS_WIDGET_SEARCH_INTENT || IS_WIDGET_VOICE_SEARCH) { } else if (IS_WIDGET_STAR || IS_WIDGET_SEARCH_INTENT || IS_WIDGET_VOICE_SEARCH) {
manageZimFiles(); manageZimFiles(0);
} }
} }
@ -1477,12 +1495,13 @@ public class KiwixMobileActivity extends AppCompatActivity {
} }
} }
public void manageZimFiles() { public void manageZimFiles(int tab) {
refreshBookmarks(); refreshBookmarks();
final Intent target = new Intent(this, ZimManageActivity.class); final Intent target = new Intent(this, ZimManageActivity.class);
target.setAction(Intent.ACTION_GET_CONTENT); target.setAction(Intent.ACTION_GET_CONTENT);
// The MIME data type filter // The MIME data type filter
target.setType("//"); target.setType("//");
target.putExtra(ZimManageActivity.TAB_EXTRA,tab);
// Only return URIs that can be opened with ContentResolver // Only return URIs that can be opened with ContentResolver
target.addCategory(Intent.CATEGORY_OPENABLE); target.addCategory(Intent.CATEGORY_OPENABLE);
// Force use of our file selection component. // Force use of our file selection component.
@ -1491,20 +1510,6 @@ public class KiwixMobileActivity extends AppCompatActivity {
startActivityForResult(target, REQUEST_FILE_SELECT); startActivityForResult(target, REQUEST_FILE_SELECT);
} }
public void downloadZimFiles() {
refreshBookmarks();
final Intent target = new Intent(this, ZimManageActivity.class);
target.setAction(Intent.ACTION_GET_CONTENT);
target.putExtra(ZimManageActivity.TAB_EXTRA,1);
// The MIME data type filter
target.setType("//");
// Only return URIs that can be opened with ContentResolver
target.addCategory(Intent.CATEGORY_OPENABLE);
// Force use of our file selection component.
// (Note may make sense to just define a custom intent instead)
startActivityForResult(target, REQUEST_FILE_SELECT);
}
public void selectSettings() { public void selectSettings() {
@ -1728,7 +1733,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
} else if (url.startsWith(ZimContentProvider.UI_URI.toString())) { } else if (url.startsWith(ZimContentProvider.UI_URI.toString())) {
// To handle links which access user interface (i.p. used in help page) // To handle links which access user interface (i.p. used in help page)
if (url.equals(ZimContentProvider.UI_URI.toString() + "selectzimfile")) { if (url.equals(ZimContentProvider.UI_URI.toString() + "selectzimfile")) {
downloadZimFiles(); manageZimFiles(1);
} else { } else {
Log.e(TAG_KIWIX, "UI Url " + url + " not supported."); Log.e(TAG_KIWIX, "UI Url " + url + " not supported.");
} }

View File

@ -118,6 +118,8 @@ public class DownloadService extends Service {
updateForeground(); updateForeground();
} }
public void pauseDownload(int notificationID) { public void pauseDownload(int notificationID) {
downloadStatus.put(notificationID, 1); downloadStatus.put(notificationID, 1);
} }
@ -141,7 +143,13 @@ public class DownloadService extends Service {
if (progress == 100) { if (progress == 100) {
notification.get(notificationID).setOngoing(false); notification.get(notificationID).setOngoing(false);
notification.get(notificationID).setContentTitle(notificationTitle + " " + getResources().getString(R.string.zim_file_downloaded)); notification.get(notificationID).setContentTitle(notificationTitle + " " + getResources().getString(R.string.zim_file_downloaded));
final Intent target = new Intent(this, KiwixMobileActivity.class);
target.putExtra("zimFile", KIWIX_ROOT + StorageUtils.getFileNameFromUrl(book.getUrl()));
PendingIntent pendingIntent = PendingIntent.getActivity
(getBaseContext(), 0,
target, PendingIntent.FLAG_CANCEL_CURRENT);
book.downloaded = true; book.downloaded = true;
notification.get(notificationID).setContentIntent(pendingIntent);
bookDao.saveBook(book); bookDao.saveBook(book);
updateForeground(); updateForeground();
} else if (progress == 0) { } else if (progress == 0) {