Browse Source

Documentation for BookmarkExporter

master
anthony restaino 7 years ago
parent
commit
64cdd016e6
  1. 18
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java
  2. 35
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkExporter.java
  3. 1
      app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkModel.java
  4. 3
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  5. 2
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java

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

@ -29,6 +29,8 @@ import acr.browser.lightning.database.HistoryItem; @@ -29,6 +29,8 @@ import acr.browser.lightning.database.HistoryItem;
/**
* The disk backed bookmark database.
* See {@link BookmarkModel} for method
* documentation.
* <p>
* Created by anthonycr on 5/6/17.
*/
@ -64,6 +66,12 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel @@ -64,6 +66,12 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
DEFAULT_BOOKMARK_TITLE = application.getString(R.string.untitled);
}
/**
* Lazily initializes the database
* field when called.
*
* @return a non null writable database.
*/
@NonNull
private SQLiteDatabase lazyDatabase() {
if (mDatabase == null) {
@ -96,12 +104,12 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel @@ -96,12 +104,12 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel
}
@NonNull
private static ContentValues bindBookmarkToContentValues(@NonNull HistoryItem historyItem) {
private static ContentValues bindBookmarkToContentValues(@NonNull HistoryItem bookmarkItem) {
ContentValues contentValues = new ContentValues(4);
contentValues.put(KEY_TITLE, historyItem.getTitle());
contentValues.put(KEY_URL, historyItem.getUrl());
contentValues.put(KEY_FOLDER, historyItem.getFolder());
contentValues.put(KEY_POSITION, historyItem.getPosition());
contentValues.put(KEY_TITLE, bookmarkItem.getTitle());
contentValues.put(KEY_URL, bookmarkItem.getUrl());
contentValues.put(KEY_FOLDER, bookmarkItem.getFolder());
contentValues.put(KEY_POSITION, bookmarkItem.getPosition());
return contentValues;
}

35
app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkExporter.java

@ -47,6 +47,13 @@ public class BookmarkExporter { @@ -47,6 +47,13 @@ public class BookmarkExporter {
private static final String KEY_FOLDER = "folder";
private static final String KEY_ORDER = "order";
/**
* Retrieves all the default bookmarks stored
* in the raw file within assets.
*
* @param context the context necessary to open assets.
* @return a non null list of the bookmarks stored in assets.
*/
@NonNull
public static List<HistoryItem> importBookmarksFromAssets(@NonNull Context context) {
List<HistoryItem> bookmarks = new ArrayList<>();
@ -82,6 +89,15 @@ public class BookmarkExporter { @@ -82,6 +89,15 @@ public class BookmarkExporter {
return bookmarks;
}
/**
* Exports the list of bookmarks to a file.
*
* @param bookmarkList the bookmarks to export.
* @param file the file to export to.
* @return an observable that emits a completion
* event when the export is complete, or an error
* event if there is a problem.
*/
@NonNull
public static Completable exportBookmarksToFile(@NonNull final List<HistoryItem> bookmarkList,
@NonNull final File file) {
@ -113,6 +129,16 @@ public class BookmarkExporter { @@ -113,6 +129,16 @@ public class BookmarkExporter {
});
}
/**
* Attempts to import bookmarks from the
* given file. If the file is not in a
* supported format, it will fail.
*
* @param file the file to import from.
* @return an observable that emits the
* imported bookmarks, or an error if the
* file cannot be imported.
*/
@NonNull
public static Single<List<HistoryItem>> importBookmarksFromFile(@NonNull final File file) {
return Single.create(new SingleAction<List<HistoryItem>>() {
@ -146,6 +172,15 @@ public class BookmarkExporter { @@ -146,6 +172,15 @@ public class BookmarkExporter {
});
}
/**
* A blocking call that creates a new export file with
* the name "BookmarkExport.txt" and an appropriate
* numerical appendage if a file already exists with
* that name.
*
* @return a non null empty file that can be used
* to export bookmarks to.
*/
@WorkerThread
@NonNull
public static File createNewExportFile() {

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

@ -7,7 +7,6 @@ import android.support.annotation.WorkerThread; @@ -7,7 +7,6 @@ import android.support.annotation.WorkerThread;
import com.anthonycr.bonsai.Completable;
import com.anthonycr.bonsai.Single;
import java.io.File;
import java.util.List;
import acr.browser.lightning.database.HistoryItem;

3
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -22,10 +22,7 @@ import android.widget.ImageView; @@ -22,10 +22,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.bonsai.SingleSubscriber;
import com.anthonycr.bonsai.Subscription;
import java.lang.ref.WeakReference;

2
app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java

@ -9,7 +9,6 @@ import android.graphics.ColorFilter; @@ -9,7 +9,6 @@ import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.AttrRes;
@ -19,7 +18,6 @@ import android.support.annotation.NonNull; @@ -19,7 +18,6 @@ import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.TypedValue;
import android.widget.ImageView;
import acr.browser.lightning.R;

Loading…
Cancel
Save