Import bookmarks from assets if the database is empty
This commit is contained in:
parent
ae30951e41
commit
c71ffda636
@ -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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -374,4 +374,9 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return DatabaseUtils.queryNumEntries(lazyDatabase(), TABLE_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 {
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user