This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2fbe10a
commit 7dde4b0
Showing
102 changed files
with
2,796 additions
and
1,130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "efac8565bb9c43ba921d01e849c1c284", | ||
"entities": [ | ||
{ | ||
"tableName": "bookmarks", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `url` TEXT, `added` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "added", | ||
"columnName": "added", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"id" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "index_bookmarks_url", | ||
"unique": true, | ||
"columnNames": [ | ||
"url" | ||
], | ||
"createSql": "CREATE UNIQUE INDEX `index_bookmarks_url` ON `${TABLE_NAME}` (`url`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"efac8565bb9c43ba921d01e849c1c284\")" | ||
] | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/schemas/org.mozilla.vrbrowser.db.BookmarkDatabase/1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "73fd28ddd217ef5521de7dd6874b45ce", | ||
"entities": [ | ||
{ | ||
"tableName": "bookmarks", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `url` TEXT, `timestamp` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "timestamp", | ||
"columnName": "timestamp", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"id" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "index_bookmarks_url", | ||
"unique": true, | ||
"columnNames": [ | ||
"url" | ||
], | ||
"createSql": "CREATE UNIQUE INDEX `index_bookmarks_url` ON `${TABLE_NAME}` (`url`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"73fd28ddd217ef5521de7dd6874b45ce\")" | ||
] | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/common/shared/org/mozilla/vrbrowser/AppExecutors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.mozilla.vrbrowser; | ||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class AppExecutors { | ||
|
||
private final Executor mDiskIO; | ||
|
||
private final Executor mNetworkIO; | ||
|
||
private final Executor mMainThread; | ||
|
||
private AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) { | ||
this.mDiskIO = diskIO; | ||
this.mNetworkIO = networkIO; | ||
this.mMainThread = mainThread; | ||
} | ||
|
||
public AppExecutors() { | ||
this(Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(3), | ||
new MainThreadExecutor()); | ||
} | ||
|
||
public Executor diskIO() { | ||
return mDiskIO; | ||
} | ||
|
||
public Executor networkIO() { | ||
return mNetworkIO; | ||
} | ||
|
||
public Executor mainThread() { | ||
return mMainThread; | ||
} | ||
|
||
private static class MainThreadExecutor implements Executor { | ||
private Handler mainThreadHandler = new Handler(Looper.getMainLooper()); | ||
|
||
@Override | ||
public void execute(@NonNull Runnable command) { | ||
mainThreadHandler.post(command); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/common/shared/org/mozilla/vrbrowser/DataRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.mozilla.vrbrowser; | ||
|
||
import org.mozilla.vrbrowser.db.AppDatabase; | ||
import org.mozilla.vrbrowser.db.entity.BookmarkEntity; | ||
import org.mozilla.vrbrowser.model.Bookmark; | ||
|
||
import java.util.List; | ||
|
||
import androidx.lifecycle.LiveData; | ||
import androidx.lifecycle.MediatorLiveData; | ||
|
||
public class DataRepository { | ||
|
||
private static DataRepository sInstance; | ||
|
||
private final AppExecutors mExecutors; | ||
private final AppDatabase mDatabase; | ||
private MediatorLiveData<List<BookmarkEntity>> mObservableBookmark; | ||
|
||
private DataRepository(final AppDatabase database, final AppExecutors executors) { | ||
mDatabase = database; | ||
mExecutors = executors; | ||
mObservableBookmark = new MediatorLiveData<>(); | ||
|
||
mObservableBookmark.addSource(mDatabase.bookmarkDao().loadAllBookmarks(), | ||
bookmarkEntities -> { | ||
if (mDatabase.getDatabaseCreated().getValue() != null) { | ||
mObservableBookmark.postValue(bookmarkEntities); | ||
} | ||
}); | ||
} | ||
|
||
public static DataRepository getInstance(final AppDatabase database, final AppExecutors executors) { | ||
if (sInstance == null) { | ||
synchronized (DataRepository.class) { | ||
if (sInstance == null) { | ||
sInstance = new DataRepository(database, executors); | ||
} | ||
} | ||
} | ||
return sInstance; | ||
} | ||
|
||
public LiveData<List<BookmarkEntity>> getBookmarks() { | ||
return mObservableBookmark; | ||
} | ||
|
||
public LiveData<BookmarkEntity> getBookmarkByUrl(final String url) { | ||
return mDatabase.bookmarkDao().getBookmarkByUrlAsync(url); | ||
} | ||
|
||
public void insertBookmark(BookmarkEntity bookmark) { | ||
mExecutors.diskIO().execute(() -> mDatabase.bookmarkDao().insertBookmark(bookmark)); | ||
} | ||
|
||
public void deleteBookmark(Bookmark bookmark) { | ||
mExecutors.diskIO().execute(() -> mDatabase.bookmarkDao().deleteById(bookmark.getId())); | ||
} | ||
|
||
public void deleteBookmarkByUrl(String url) { | ||
mExecutors.diskIO().execute(() -> mDatabase.bookmarkDao().deleteByUrl(url)); | ||
} | ||
} |
Oops, something went wrong.