use of org.kiwix.kiwixmobile.database.BookmarksDao in project kiwix-android by kiwix.
the class KiwixMobileActivity method refreshBookmarkSymbol.
public void refreshBookmarkSymbol(Menu menu) {
// Checks if current webview is in bookmarks array
if (bookmarks == null || bookmarks.size() == 0) {
bookmarksDao = new BookmarksDao(KiwixDatabase.getInstance(this));
bookmarks = bookmarksDao.getBookmarks(ZimContentProvider.getId(), ZimContentProvider.getName());
}
TabLayout.Tab bookmarkTab = pageBottomTabLayout.getTabAt(4);
if (menu.findItem(R.id.menu_bookmarks) != null && getCurrentWebView().getUrl() != null && ZimContentProvider.getId() != null && !getCurrentWebView().getUrl().equals("file:///android_asset/help.html")) {
int icon = bookmarks.contains(getCurrentWebView().getUrl()) ? R.drawable.action_bookmark_active : R.drawable.action_bookmark;
menu.findItem(R.id.menu_bookmarks).setEnabled(true).setIcon(icon).getIcon().setAlpha(255);
bookmarkTab.getCustomView().findViewById(R.id.bookmark_tab_icon).setBackgroundResource(icon);
} else {
menu.findItem(R.id.menu_bookmarks).setEnabled(false).setIcon(R.drawable.action_bookmark).getIcon().setAlpha(130);
bookmarkTab.getCustomView().findViewById(R.id.bookmark_tab_icon).setBackgroundResource(R.drawable.action_bookmark);
}
}
use of org.kiwix.kiwixmobile.database.BookmarksDao in project kiwix-android by kiwix.
the class KiwixMobileActivity method openZimFile.
public boolean openZimFile(File file, boolean clearHistory) {
if (file.canRead() || Build.VERSION.SDK_INT < 19 || (BuildConfig.IS_CUSTOM_APP && Build.VERSION.SDK_INT != 23)) {
if (file.exists()) {
if (ZimContentProvider.setZimFile(file.getAbsolutePath()) != null) {
if (clearHistory) {
requestClearHistoryAfterLoad = true;
}
if (menu != null) {
initAllMenuItems();
} else {
// Menu may not be initialized yet. In this case
// signal to menu create to show
requestInitAllMenuItems = true;
}
// Bookmarks
bookmarks = new ArrayList<>();
bookmarksDao = new BookmarksDao(KiwixDatabase.getInstance(this));
bookmarks = bookmarksDao.getBookmarks(ZimContentProvider.getId(), ZimContentProvider.getName());
openMainPage();
refreshBookmarks();
return true;
} else {
Toast.makeText(this, getResources().getString(R.string.error_fileinvalid), Toast.LENGTH_LONG).show();
showHelpPage();
}
} else {
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
Toast.makeText(this, getResources().getString(R.string.error_filenotfound), Toast.LENGTH_LONG).show();
showHelpPage();
}
return false;
} else {
this.file = file;
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_STORAGE_PERMISSION);
if (BuildConfig.IS_CUSTOM_APP && Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
Toast.makeText(this, getResources().getString(R.string.request_storage_custom), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, getResources().getString(R.string.request_storage), Toast.LENGTH_LONG).show();
}
return false;
}
}
use of org.kiwix.kiwixmobile.database.BookmarksDao in project kiwix-android by kiwix.
the class KiwixMobileActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG_KIWIX, "Intent data: " + data);
switch(requestCode) {
case REQUEST_FILE_SELECT:
if (resultCode == RESULT_OK) {
// The URI of the selected file
final Uri uri = data.getData();
File file = null;
if (uri != null) {
String path = uri.getPath();
if (path != null) {
file = new File(path);
}
}
if (file == null) {
Log.i(TAG_KIWIX, "Could not find file");
return;
}
finish();
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
zimFile.setData(uri);
startActivity(zimFile);
}
break;
case REQUEST_FILE_SEARCH:
if (resultCode == RESULT_OK) {
String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
boolean isSearchInText = data.getBooleanExtra(EXTRA_SEARCH_IN_TEXT, false);
if (isSearchInText) {
// if the search is localized trigger find in page UI.
KiwixWebView webView = getCurrentWebView();
compatCallback.setActive();
compatCallback.setWebView(webView);
startSupportActionMode(compatCallback);
compatCallback.setText(title);
compatCallback.findAll();
compatCallback.showSoftInput();
} else {
searchForTitle(title);
}
} else {
// TODO: Inform the User
Log.w(TAG_KIWIX, "Unhandled search failure");
}
break;
case REQUEST_PREFERENCES:
if (resultCode == RESULT_RESTART) {
finish();
startActivity(new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class));
}
if (resultCode == RESULT_HISTORY_CLEARED) {
mWebViews.clear();
newTab();
tabDrawerAdapter.notifyDataSetChanged();
}
loadPrefs();
break;
case BOOKMARK_CHOSEN_REQUEST:
if (resultCode == RESULT_OK) {
boolean itemClicked = data.getBooleanExtra(EXTRA_BOOKMARK_CLICKED, false);
if (ZimContentProvider.getId() == null)
return;
// Bookmarks
bookmarksDao = new BookmarksDao(KiwixDatabase.getInstance(this));
bookmarks = bookmarksDao.getBookmarks(ZimContentProvider.getId(), ZimContentProvider.getName());
if (itemClicked) {
String bookmarkChosen;
if (data.getStringExtra(EXTRA_CHOSE_X_URL) != null) {
bookmarkChosen = data.getStringExtra(EXTRA_CHOSE_X_URL);
newTab();
getCurrentWebView().loadUrl(bookmarkChosen);
} else {
newTab();
bookmarkChosen = data.getStringExtra(EXTRA_CHOSE_X_TITLE);
openArticleFromBookmarkTitle(bookmarkChosen);
}
}
if (menu != null) {
refreshBookmarkSymbol(menu);
}
}
break;
default:
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
use of org.kiwix.kiwixmobile.database.BookmarksDao in project kiwix-android by kiwix.
the class BookmarksPresenter method loadBookmarks.
public void loadBookmarks(Context context) {
bookmarksDao = new BookmarksDao(KiwixDatabase.getInstance(context));
ArrayList<String> bookmarks = bookmarksDao.getBookmarkTitles(ZimContentProvider.getId(), ZimContentProvider.getName());
ArrayList<String> bookmarkUrls = bookmarksDao.getBookmarks(ZimContentProvider.getId(), ZimContentProvider.getName());
getMvpView().showBookmarks(bookmarks, bookmarkUrls);
}
Aggregations