Skip to content

Commit

Permalink
Introduce more android arch component
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Mace committed Nov 30, 2017
1 parent 6a9c916 commit c2058f5
Show file tree
Hide file tree
Showing 31 changed files with 711 additions and 454 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies {
implementation dependenciesList.mapboxMapSdk
implementation dependenciesList.mapboxServices

implementation dependenciesList.lifecycleExtensions

// Support libraries
implementation dependenciesList.supportAnnotation
implementation dependenciesList.supportAppcompatV7
Expand Down
6 changes: 4 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ ext {
commonsIO : '2.5',
robolectric : '3.4.2',
lifecycleCompiler : '1.0.0',
lifecycleRuntime : '1.0.3',
lifecycleExtensions: '1.0.0',
room : '1.0.0',
androidArchCore : '1.0.0',
okhttp : '3.9.0'
]

Expand Down Expand Up @@ -71,7 +72,7 @@ ext {
supportConstraintLayout: "com.android.support.constraint:constraint-layout:${version.constraintLayout}",

// architecture
lifecycleExtensions : "android.arch.lifecycle:extensions:${version.lifecycleRuntime}",
lifecycleExtensions : "android.arch.lifecycle:extensions:${version.lifecycleExtensions}",
lifecycleCompiler : "android.arch.lifecycle:compiler:${version.lifecycleCompiler}",
roomRuntime : "android.arch.persistence.room:runtime:${version.room}",
roomCompiler : "android.arch.persistence.room:compiler:${version.room}",
Expand All @@ -95,6 +96,7 @@ ext {
hamcrest : "org.hamcrest:hamcrest-junit:${version.hamcrest}",
commonsIO : "commons-io:commons-io:${version.commonsIO}",
robolectric : "org.robolectric:robolectric:${version.robolectric}",
androidArchCore : "android.arch.core:core-testing:${version.androidArchCore}",

// okhttp
okhttp : "com.squareup.okhttp3:okhttp:${version.okhttp}",
Expand Down
2 changes: 2 additions & 0 deletions plugin-places/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation dependenciesList.supportRecyclerView
implementation dependenciesList.supportV4

implementation dependenciesList.lifecycleExtensions
implementation dependenciesList.roomRuntime
annotationProcessor dependenciesList.roomCompiler

Expand All @@ -48,6 +49,7 @@ dependencies {
// Unit testing
testImplementation dependenciesList.junit
testImplementation dependenciesList.mockito
testImplementation dependenciesList.androidArchCore

javadocDeps dependenciesList.mapboxMapSdk
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "6785f3a8f4d6195ea76771bea75e1fd5",
"entities": [
{
"tableName": "searchhistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`placeId` TEXT NOT NULL, `carmen_feature` TEXT, PRIMARY KEY(`placeId`))",
"fields": [
{
"fieldPath": "placeId",
"columnName": "placeId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "carmenFeature",
"columnName": "carmen_feature",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"placeId"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"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, \"6785f3a8f4d6195ea76771bea75e1fd5\")"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "6785f3a8f4d6195ea76771bea75e1fd5",
"entities": [
{
"tableName": "searchhistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`placeId` TEXT NOT NULL, `carmen_feature` TEXT, PRIMARY KEY(`placeId`))",
"fields": [
{
"fieldPath": "placeId",
"columnName": "placeId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "carmenFeature",
"columnName": "carmen_feature",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"placeId"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"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, \"6785f3a8f4d6195ea76771bea75e1fd5\")"
]
}
}
7 changes: 1 addition & 6 deletions plugin-places/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

<application>
<activity
android:name="com.mapbox.plugins.places.autocomplete.PlaceCompleteCardActivity"
android:name="com.mapbox.plugins.places.autocomplete.ui.PlaceAutocompleteActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@style/Theme.AppCompat.Translucent"
android:windowSoftInputMode="stateVisible|adjustPan"/>

<activity
android:name="com.mapbox.plugins.places.autocomplete.PlaceCompleteFullActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@style/Theme.AppCompat.Translucent"
android:windowSoftInputMode="stateVisible"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.mapbox.plugins.places.autocomplete;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MediatorLiveData;
import android.arch.lifecycle.Observer;
import android.support.annotation.Nullable;

import com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase;
import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity;

import java.util.List;

public class DataRepository {

private static DataRepository instance;

private final SearchHistoryDatabase database;
private MediatorLiveData<List<SearchHistoryEntity>> observableSearchHistory;

private DataRepository(final SearchHistoryDatabase database) {
this.database = database;
observableSearchHistory = new MediatorLiveData<>();

observableSearchHistory.addSource(database.searchHistoryDao().getAll(),
new Observer<List<SearchHistoryEntity>>() {
@Override
public void onChanged(@Nullable List<SearchHistoryEntity> searchHistoryEntities) {
if (database.getDatabaseCreated().getValue() != null) {
observableSearchHistory.postValue(searchHistoryEntities);
}
}
});
}

public static DataRepository getInstance(final SearchHistoryDatabase database) {
if (instance == null) {
instance = new DataRepository(database);
}
return instance;
}

public LiveData<List<SearchHistoryEntity>> getSearchHistory() {
return observableSearchHistory;
}

public void addSearchHistoryEntity(SearchHistoryEntity searchHistory) {
SearchHistoryDatabase.insertData(database, searchHistory);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.mapbox.geocoding.v5.GeocodingCriteria.GeocodingTypeCriteria;
import com.mapbox.geocoding.v5.models.CarmenFeature;
import com.mapbox.geojson.Point;
import com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase;
import com.mapbox.plugins.places.autocomplete.ui.PlaceAutocompleteActivity;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -69,9 +71,9 @@ public static CarmenFeature getPlace(Intent data) {
* @since 0.1.0
*/
public static void clearRecentHistory(Context context) {
SearchHistoryDatabase database = Room.databaseBuilder(context,
SearchHistoryDatabase.class, PlaceConstants.SEARCH_HISTORY_DATABASE_NAME).build();
new RecentSearchAsyncTask(database).execute();
// SearchHistoryDatabase database = Room.databaseBuilder(context,
// SearchHistoryDatabase.class, PlaceConstants.SEARCH_HISTORY_DATABASE_NAME).build();
// new RecentSearchAsyncTask(database).execute();
}

/**
Expand Down Expand Up @@ -268,12 +270,8 @@ public IntentBuilder backgroundColor(@ColorInt int backgroundColor) {
*/
public Intent build(Activity activity) {
intent.putStringArrayListExtra(PlaceConstants.COUNTRIES, countries);

if (mode == MODE_FULLSCREEN) {
intent.setClass(activity, PlaceCompleteFullActivity.class);
} else {
intent.setClass(activity, PlaceCompleteCardActivity.class);
}
intent.putExtra(PlaceConstants.MODE, mode);
intent.setClass(activity, PlaceAutocompleteActivity.class);
return intent;
}
}
Expand Down
Loading

0 comments on commit c2058f5

Please sign in to comment.