Browse Source

Import bookmarks from assets if the database is empty

master
anthony restaino 8 years ago
parent
commit
c71ffda636
  1. 6
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  2. 5
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java
  3. 11
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java
  4. 2
      app/src/main/java/acr/browser/lightning/database/bookmark/legacy/LegacyBookmarkManager.java

6
app/src/main/java/acr/browser/lightning/app/BrowserApp.java

@ -23,6 +23,7 @@ import javax.inject.Inject; @@ -23,6 +23,7 @@ import javax.inject.Inject;
import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.database.bookmark.BookmarkExporter;
import acr.browser.lightning.database.bookmark.legacy.LegacyBookmarkManager;
import acr.browser.lightning.database.bookmark.BookmarkModel;
import acr.browser.lightning.preference.PreferenceManager;
@ -88,7 +89,10 @@ public class BrowserApp extends Application { @@ -88,7 +89,10 @@ public class BrowserApp extends Application {
if (!oldBookmarks.isEmpty()) {
mBookmarkModel.addBookmarkList(oldBookmarks).subscribeOn(Schedulers.io()).subscribe();
} else {
// TODO: 5/7/17 Import bookmarks from assets if not empty
if (mBookmarkModel.count() == 0) {
List<HistoryItem> assetsBookmarks = BookmarkExporter.importBookmarksFromAssets(BrowserApp.this);
mBookmarkModel.addBookmarkList(assetsBookmarks).subscribeOn(Schedulers.io()).subscribe();
}
}
}
});

5
app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java

@ -374,4 +374,9 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel @@ -374,4 +374,9 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
});
}
@Override
public long count() {
return DatabaseUtils.queryNumEntries(lazyDatabase(), TABLE_BOOKMARK);
}
}

11
app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java

@ -2,6 +2,7 @@ package acr.browser.lightning.database.bookmark; @@ -2,6 +2,7 @@ package acr.browser.lightning.database.bookmark;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.Single;
@ -151,4 +152,14 @@ public interface BookmarkModel { @@ -151,4 +152,14 @@ public interface BookmarkModel {
*/
@NonNull
Single<List<String>> getFolderNames();
/**
* A synchronous call to the model
* that returns the number of bookmarks.
* Should be called from a background thread.
*
* @return the number of bookmarks in the database.
*/
@WorkerThread
long count();
}

2
app/src/main/java/acr/browser/lightning/database/bookmark/legacy/LegacyBookmarkManager.java

@ -27,7 +27,7 @@ import acr.browser.lightning.utils.Utils; @@ -27,7 +27,7 @@ import acr.browser.lightning.utils.Utils;
@Deprecated
public class LegacyBookmarkManager {
private static final String TAG = "BookmarkManager";
private static final String TAG = "LegacyBookmarkManager";
private static final String TITLE = "title";
private static final String URL = "url";

Loading…
Cancel
Save