Import bookmarks from assets if the database is empty

This commit is contained in:
anthony restaino 2017-05-07 20:58:07 -04:00
parent ae30951e41
commit c71ffda636
4 changed files with 22 additions and 2 deletions

View File

@ -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();
}
}
}
});

View File

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

View File

@ -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();
}

View File

@ -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";