Android Bookmarks can be loaded by either Title or URL #255

I may have also made a migration path but am not too sure as very
difficult to test.
This commit is contained in:
mhutti1 2016-07-29 17:45:26 +01:00
parent 6bbc6d93a9
commit ee6f214023
5 changed files with 46 additions and 7 deletions

View File

@ -5,6 +5,7 @@ NEW: Kiwix search home screen widget
NEW: Download manager
NEW: Improved ZIM management
NEW: Build against newer version of Android NDK/SDK
NEW: Bookmarks for multiple articles with the same title can be created
FIXED: Opening problem with ZIM filenames with special characters
FIXED: Useless "w820dp" language
FIXED: Failing he, id, yi locales

View File

@ -200,7 +200,11 @@ public class BookmarksActivity extends AppCompatActivity
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent();
intent.putExtra("choseX", bookmarks.get(position));
if (!bookmarkUrls.get(position).equals("null")) {
intent.putExtra("choseXURL", bookmarkUrls.get(position));
} else {
intent.putExtra("choseXTitle", bookmarks.get(position));
}
intent.putExtra("bookmarkClicked", true);
setResult(RESULT_OK, intent);
finish();

View File

@ -713,7 +713,7 @@ public class KiwixMobileActivity extends AppCompatActivity {
.setAction(ShortcutUtils.stringsGetter(R.string.undo, this), v -> {
if (mWebViews.size() == 1 && prevSize == 1) {
openArticleFromBookmark(tempForUndo.getTitle());
openArticleFromBookmarkURL(tempForUndo.getUrl());
} else {
restoreTabAtIndex(tempForUndo.getUrl(), index);
selectTab(index);
@ -1151,11 +1151,16 @@ public class KiwixMobileActivity extends AppCompatActivity {
refreshBookmarks();
}
public boolean openArticleFromBookmark(String bookmarkTitle) {
public boolean openArticleFromBookmarkTitle(String bookmarkTitle) {
// Log.d(TAG_KIWIX, "openArticleFromBookmark: " + articleSearchtextView.getText());
return openArticle(ZimContentProvider.getPageUrlFromTitle(bookmarkTitle));
}
public boolean openArticleFromBookmarkURL(String bookmarkURL) {
// Log.d(TAG_KIWIX, "openArticleFromBookmark: " + articleSearchtextView.getText());
return openArticle(bookmarkURL);
}
private void contentsDrawerHint() {
mLeftDrawerLayout.postDelayed(new Runnable() {
@Override
@ -1391,9 +1396,17 @@ public class KiwixMobileActivity extends AppCompatActivity {
bookmarks = bookmarksDao.getBookmarks();
if (itemClicked) {
String bookmarkChosen = data.getStringExtra("choseX");
newTab();
openArticleFromBookmark(bookmarkChosen);
String bookmarkChosen;
if (data.getStringExtra("choseXURL") != null) {
bookmarkChosen = data.getStringExtra("choseXURL");
newTab();
getCurrentWebView().loadUrl(bookmarkChosen);
} else {
newTab();
bookmarkChosen = data.getStringExtra("choseXTitle");
openArticleFromBookmarkTitle(bookmarkChosen);
}
}
refreshBookmarkSymbol(menu);

View File

@ -59,7 +59,11 @@ public class BookmarksDao {
* Save {@code searchString} as the most recent search.
*/
public void saveBookmark(String articleUrl, String articleTitle) {
mDb.persist(new Bookmarks().setBookmarkUrl(articleUrl).setBookmarkTitle(articleTitle));
if (articleUrl != null) {
mDb.persist(new Bookmarks().setBookmarkUrl(articleUrl).setBookmarkTitle(articleTitle));
} else {
mDb.persist(new Bookmarks().setBookmarkUrl("null").setBookmarkTitle(articleTitle));
}
}
/**

View File

@ -92,6 +92,23 @@ public class KiwixDatabase extends SquidDatabase {
db.execSQL("DROP TABLE IF EXISTS Bookmarks");
tryCreateTable(Bookmarks.TABLE);
BookmarksDao bookmarksDao = new BookmarksDao(this);
if (ZimContentProvider.getId() != null) {
try {
InputStream stream = context.openFileInput(ZimContentProvider.getId() + ".txt");
String in;
if (stream != null) {
BufferedReader read = new BufferedReader(new InputStreamReader(stream));
while ((in = read.readLine()) != null) {
bookmarksDao.saveBookmark(null,in);
}
Log.d(KiwixMobileActivity.TAG_KIWIX, "Switched to bookmarkfile " + ZimContentProvider.getId());
}
} catch (FileNotFoundException e) {
Log.e(KiwixMobileActivity.TAG_KIWIX, "File not found: " + e.toString());
} catch (IOException e) {
Log.e(KiwixMobileActivity.TAG_KIWIX, "Can not read file: " + e.toString());
}
}
}
return true;
}