Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fixes #347: Bookmarks support (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and MortimerGoro committed Nov 22, 2018
1 parent 2fbe10a commit 7dde4b0
Show file tree
Hide file tree
Showing 102 changed files with 2,796 additions and 1,130 deletions.
78 changes: 39 additions & 39 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def getCrashRestartDisabled = { ->
}

android {
compileSdkVersion 27
compileSdkVersion build_versions.target_sdk
defaultConfig {
applicationId "org.mozilla.vrbrowser"
minSdkVersion 24
targetSdkVersion 27
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionCode 1
versionName "1.1"
buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\""
buildConfigField "Boolean", "DISABLE_CRASH_RESTART", getCrashRestartDisabled()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++14 -fexceptions -frtti -Werror" +
Expand All @@ -36,6 +36,12 @@ android {
arguments "-DANDROID_STL=c++_shared"
}
}

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}

if (gradle.hasProperty('taskclusterBuild')) {
Expand All @@ -44,22 +50,29 @@ android {
} else {
project.archivesBaseName = "FirefoxReality"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}

dataBinding {
enabled = true
}

lintOptions {
disable "LogUsage", "ExtraTranslation"
}
Expand All @@ -83,17 +96,6 @@ android {
}
}

googlevrFlat {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/gvr-android-sdk/libraries/headers").absolutePath +
" -DVRBROWSER_GOOGLEVR"
arguments "-DVR_SDK_LIB=googlevr-lib", "-DGOOGLEVR=ON"
}
}
}

oculusvr {
dimension "platform"
externalNativeBuild {
Expand Down Expand Up @@ -185,13 +187,6 @@ android {
]
}

googlevrFlat {
java.srcDirs = [
'src/googlevr/java',
'src/googlevrFlat/java'
]
}

oculusvr {
java.srcDirs = [
'src/oculusvr/java'
Expand Down Expand Up @@ -232,27 +227,32 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

// Common
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.vr:sdk-audio:1.170.0'
implementation deps.google_vr.sdk_audio
implementation deps.room.runtime
annotationProcessor deps.room.compiler
implementation deps.lifecycle.runtime
implementation deps.lifecycle.extensions
implementation deps.support.cardview
implementation deps.support.app_compat
implementation deps.support.annotations
implementation deps.constraint_layout

// Android Components
implementation "com.github.mozilla:mozillaspeechlibrary:1.0.6"
implementation "org.mozilla.components:service-telemetry:${rootProject.ext.androidComponents['version']}"
implementation "org.mozilla.components:browser-errorpages:${rootProject.ext.androidComponents['version']}"
implementation "org.mozilla.components:browser-search:${rootProject.ext.androidComponents['version']}"
implementation "org.mozilla.components:browser-domains:${rootProject.ext.androidComponents['version']}"
implementation "org.mozilla.components:ui-autocomplete:${rootProject.ext.androidComponents['version']}"
implementation deps.mozilla_speech
implementation deps.android_components.telemetry
implementation deps.android_components.browser_errorpages
implementation deps.android_components.browser_search
implementation deps.android_components.browser_domains
implementation deps.android_components.ui_autocomplete

// Testing
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation deps.junit
androidTestImplementation deps.atsl.runner
androidTestImplementation deps.espresso.core
testImplementation deps.room.testing

// Daydream
googlevrImplementation 'com.google.vr:sdk-base:1.170.0'
googlevrFlatImplementation 'com.google.vr:sdk-base:1.170.0'
googlevrImplementation deps.google_vr.sdk_base

// ODG
svrImplementation fileTree(dir: "${project.rootDir}/third_party/svr/", include: ['*.jar'])
Expand All @@ -279,8 +279,8 @@ if (findProject(':geckoview-local')) {
dependencies {
// To see what the latest geckoview-nightly version is go here:
// https://maven.mozilla.org/?prefix=maven2/org/mozilla/geckoview/geckoview-nightly-armeabi-v7a/
armImplementation "org.mozilla.geckoview:geckoview-nightly-armeabi-v7a:${rootProject.ext.geckoNightly['version']}"
x86Implementation "org.mozilla.geckoview:geckoview-nightly-x86:${rootProject.ext.geckoNightly['version']}"
armImplementation deps.gecko_view.nightly_armv7a
x86Implementation deps.gecko_view.nightly_x86
}
}

Expand Down
61 changes: 61 additions & 0 deletions app/schemas/org.mozilla.vrbrowser.db.AppDatabase/1.json
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 app/schemas/org.mozilla.vrbrowser.db.BookmarkDatabase/1.json
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 app/src/common/shared/org/mozilla/vrbrowser/AppExecutors.java
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 app/src/common/shared/org/mozilla/vrbrowser/DataRepository.java
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));
}
}
Loading

0 comments on commit 7dde4b0

Please sign in to comment.