From 1c8241da72f839d03ef280f45a0cf324df21b710 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Wed, 15 Nov 2017 22:52:54 -0500 Subject: [PATCH 01/25] Initial project started --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 226 +++++++++--------- .../places/AutocompleteLauncherActivity.java | 40 ++++ .../res/layout/activity_places_launcher.xml | 33 +++ app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/strings.xml | 66 ++--- app/src/main/res/values/styles.xml | 31 ++- build.gradle | 1 + gradle/dependencies.gradle | 44 ++-- plugin-places/build.gradle | 40 ++++ plugin-places/src/main/AndroidManifest.xml | 12 + .../autocomplete/PlaceAutocomplete.java | 73 ++++++ .../autocomplete/PlacesCompleteActivity.java | 38 +++ .../main/res/drawable/color_text_cursor.xml | 5 + .../src/main/res/drawable/ic_arrow_back.xml | 9 + .../res/layout/activity_places_complete.xml | 75 ++++++ plugin-places/src/main/res/values/colors.xml | 6 + plugin-places/src/main/res/values/strings.xml | 5 + plugin-places/src/main/res/values/styles.xml | 13 + .../com/mapbox/places/ExampleUnitTest.java | 17 ++ plugin-traffic/javadoc.gradle | 38 ++- settings.gradle | 2 +- 22 files changed, 583 insertions(+), 196 deletions(-) create mode 100644 app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java create mode 100644 app/src/main/res/layout/activity_places_launcher.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 plugin-places/build.gradle create mode 100644 plugin-places/src/main/AndroidManifest.xml create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java create mode 100644 plugin-places/src/main/res/drawable/color_text_cursor.xml create mode 100644 plugin-places/src/main/res/drawable/ic_arrow_back.xml create mode 100644 plugin-places/src/main/res/layout/activity_places_complete.xml create mode 100644 plugin-places/src/main/res/values/colors.xml create mode 100644 plugin-places/src/main/res/values/strings.xml create mode 100644 plugin-places/src/main/res/values/styles.xml create mode 100644 plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java diff --git a/app/build.gradle b/app/build.gradle index 9db036c7b..613049d33 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation dependenciesList.supportConstraintLayout // Unit testing + implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation dependenciesList.junit testImplementation dependenciesList.mockito @@ -69,6 +70,7 @@ dependencies { implementation project(':plugin-building') implementation project(':plugin-geojson') implementation project(':plugin-cluster') + implementation project(':plugin-places') } sonarqube { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ca23b9b1..38bcf0833 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,116 +2,124 @@ - - + + - - - - - - - - - - - - - - - + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java new file mode 100644 index 000000000..560200046 --- /dev/null +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -0,0 +1,40 @@ +package com.mapbox.mapboxsdk.plugins.testapp.activity.places; + +import android.content.Intent; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import com.mapbox.mapboxsdk.plugins.testapp.R; +import com.mapbox.plugins.places.autocomplete.PlaceAutocomplete; + +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class AutocompleteLauncherActivity extends AppCompatActivity { + + private static final int REQUEST_CODE_AUTOCOMPLETE = 1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_places_launcher); + ButterKnife.bind(this); + } + + @OnClick(R.id.fabOverlay) + public void onOverlayFabClick(View view) { + Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.THEME_OVERLAY) + .build(AutocompleteLauncherActivity.this); + startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); + } + + @OnClick(R.id.fabFullScreen) + public void onFullscreenFabClick(View view) { + Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.THEME_FULLSCREEN) + .build(AutocompleteLauncherActivity.this); + startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); + } + +} diff --git a/app/src/main/res/layout/activity_places_launcher.xml b/app/src/main/res/layout/activity_places_launcher.xml new file mode 100644 index 000000000..7bcdf5162 --- /dev/null +++ b/app/src/main/res/layout/activity_places_launcher.xml @@ -0,0 +1,33 @@ + + + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 000000000..184ee9ba0 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,3 @@ + + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 20f4ceff1..5b126d7a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,38 +1,42 @@ - Mapbox Android Plugins + Mapbox Android Plugins - - category - Extrusions - Navigation - Location - Navigation - Annotations + + category + Extrusions + Navigation + Location + Navigation + Annotations + Places - - Traffic Plugin - Building Plugin - Location Modes - Location Layer Map Change - Toggle Manual Location Updates - Compass Listener - GeoJson Plugin - Cluster Plugin - - Add Traffic layers to any Mapbox basemap. - Add 3D Building layer to a Mapbox map. - Switch between the different location modes. - Change map styles while the location layers on the map. - Toggle the user location manual mode on and off. - Add a compass listener to know when heading changes or when the accuracy dropsx - Load GeoJson file from assets, path or url to the Mapbox. - Add marker clustering to a Mapbox map. + + Traffic Plugin + Building Plugin + Location Modes + Location Layer Map Change + Toggle Manual Location Updates + Compass Listener + GeoJson Plugin + Cluster Plugin + Places Autocomplete - - None - Tracking - Compass - Nav + + Add Traffic layers to any Mapbox basemap. + Add 3D Building layer to a Mapbox map. + Switch between the different location modes. + Change map styles while the location layers on the map. + Toggle the user location manual mode on and off. + Add a compass listener to know when heading changes or when the accuracy dropsx + Load GeoJson file from assets, path or url to the Mapbox. + Add marker clustering to a Mapbox map. + Launch the autocomplete activity. + + + None + Tracking + Compass + Nav diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index dc9edadb1..59f0dfecc 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,16 +1,25 @@ - - + + - + + + + + + + diff --git a/plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java b/plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java new file mode 100644 index 000000000..8113bfcb9 --- /dev/null +++ b/plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.mapbox.places; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/plugin-traffic/javadoc.gradle b/plugin-traffic/javadoc.gradle index efcf38191..f23257e29 100644 --- a/plugin-traffic/javadoc.gradle +++ b/plugin-traffic/javadoc.gradle @@ -1,25 +1,17 @@ - - - - - - - - android.libraryVariants.all { variant -> - def name = variant.name - task "javadoc$name"(type: Javadoc) { - description = "Generates javadoc for build $name" - failOnError = false - destinationDir = new File(destinationDir, variant.baseName) - source = files(variant.javaCompile.source) - classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath) + configurations.javadocDeps - options.windowTitle("Mapbox Android Plugins $VERSION_NAME Reference") - options.docTitle("Mapbox Android Plugins $VERSION_NAME") - options.header("Mapbox Android Plugins $VERSION_NAME Reference") - options.bottom("© 2017 Mapbox. All rights reserved.") - options.links("http://docs.oracle.com/javase/7/docs/api/") - options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference") - exclude '**/R.java', '**/BuildConfig.java' - } + def name = variant.name + task "javadoc$name"(type: Javadoc) { + description = "Generates javadoc for build $name" + failOnError = false + destinationDir = new File(destinationDir, variant.baseName) + source = files(variant.javaCompile.source) + classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath) + configurations.javadocDeps + options.windowTitle("Mapbox Android Plugins $VERSION_NAME Reference") + options.docTitle("Mapbox Android Plugins $VERSION_NAME") + options.header("Mapbox Android Plugins $VERSION_NAME Reference") + options.bottom("© 2017 Mapbox. All rights reserved.") + options.links("http://docs.oracle.com/javase/7/docs/api/") + options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference") + exclude '**/R.java', '**/BuildConfig.java' + } } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index e7b616aef..9d960a259 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':plugin-traffic', ':plugin-locationlayer', ':plugin-building', ':plugin-cluster', ':plugin-geojson' +include ':app', ':plugin-traffic', ':plugin-locationlayer', ':plugin-building', ':plugin-cluster', ':plugin-geojson', ':plugin-places' From b441f7ec7d6a0225ac26c35ffac8d77683785677 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Thu, 16 Nov 2017 16:44:25 -0500 Subject: [PATCH 02/25] Added more views --- plugin-places/build.gradle | 2 + plugin-places/src/main/AndroidManifest.xml | 2 +- .../autocomplete/PlacesCompleteActivity.java | 13 +- .../places/autocomplete/SearchBarView.java | 89 ++++++++++++++ .../autocomplete/SearchResultAdapter.java | 50 ++++++++ .../autocomplete/SearchResultModel.java | 29 +++++ .../places/autocomplete/SearchResultView.java | 77 ++++++++++++ .../src/main/res/drawable/ic_clear.xml | 9 ++ .../src/main/res/drawable/scroll_shadow.xml | 8 ++ .../res/layout/activity_places_complete.xml | 112 +++++++++--------- .../main/res/layout/item_search_result.xml | 59 +++++++++ .../res/layout/layout_cardview_search_bar.xml | 86 ++++++++++++++ .../layout/layout_cardview_search_result.xml | 40 +++++++ plugin-places/src/main/res/values/strings.xml | 1 + 14 files changed, 515 insertions(+), 62 deletions(-) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchBarView.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java create mode 100644 plugin-places/src/main/res/drawable/ic_clear.xml create mode 100644 plugin-places/src/main/res/drawable/scroll_shadow.xml create mode 100644 plugin-places/src/main/res/layout/item_search_result.xml create mode 100644 plugin-places/src/main/res/layout/layout_cardview_search_bar.xml create mode 100644 plugin-places/src/main/res/layout/layout_cardview_search_result.xml diff --git a/plugin-places/build.gradle b/plugin-places/build.gradle index 1d6fdc5ea..75747923f 100644 --- a/plugin-places/build.gradle +++ b/plugin-places/build.gradle @@ -37,4 +37,6 @@ dependencies { javadocDeps dependenciesList.mapboxMapSdk implementation 'com.android.support:cardview-v7:27.0.0' + implementation 'com.android.support:recyclerview-v7:27.0.0' + implementation 'com.android.support:support-v4:27.0.0' } \ No newline at end of file diff --git a/plugin-places/src/main/AndroidManifest.xml b/plugin-places/src/main/AndroidManifest.xml index 874c19c3d..143de17c4 100644 --- a/plugin-places/src/main/AndroidManifest.xml +++ b/plugin-places/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ package="com.mapbox.places"> - + 0 ? View.VISIBLE : INVISIBLE); + } + + @Override + public void afterTextChanged(Editable editable) { + + } + + + private void initBackground() { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { + // Hide the background + getBackground().setAlpha(0); + } else { + setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); + } + } + + +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java new file mode 100644 index 000000000..bda362cac --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java @@ -0,0 +1,50 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.mapbox.places.R; + +import java.util.List; + +public class SearchResultAdapter extends RecyclerView.Adapter { + + private List results; + + public SearchResultAdapter(List results) { + this.results = results; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + LayoutInflater inflater = LayoutInflater.from(parent.getContext()); + View view = inflater.inflate(R.layout.item_search_result, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + holder.placeNameView.setText(results.get(position).getTitle()); + holder.addressView.setText(results.get(position).getDescription()); + } + + @Override + public int getItemCount() { + return null != results ? results.size() : 0; + } + + static class ViewHolder extends RecyclerView.ViewHolder { + + final TextView placeNameView; + final TextView addressView; + + ViewHolder(View itemView) { + super(itemView); + placeNameView = itemView.findViewById(R.id.tv_place_name); + addressView = itemView.findViewById(R.id.tv_address); + } + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java new file mode 100644 index 000000000..ac66c6b1b --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java @@ -0,0 +1,29 @@ +package com.mapbox.plugins.places.autocomplete; + + +public class SearchResultModel { + + private String title; + private String description; + + public SearchResultModel(String title, String description) { + this.title = title; + this.description = description; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java new file mode 100644 index 000000000..c0639229a --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java @@ -0,0 +1,77 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.CardView; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.AttributeSet; + +import com.mapbox.places.R; + +import java.util.ArrayList; +import java.util.List; + +public class SearchResultView extends CardView { + + public SearchResultView(@NonNull Context context) { + this(context, null); + } + + public SearchResultView(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, -1); + } + + public SearchResultView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initialize(context); + } + + private void initialize(Context context) { + inflate(context, R.layout.layout_cardview_search_result, this); + initBackground(); + initializeResultList(); + } + + private void initializeResultList() { + List results = new ArrayList<>(); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + results.add(new SearchResultModel("hello", "world")); + + RecyclerView recyclerView = findViewById(R.id.rv_search_results); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(new SearchResultAdapter(results)); + + + } + + private void initBackground() { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { + // Hide the background + getBackground().setAlpha(0); + } else { + setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); + } + } +} diff --git a/plugin-places/src/main/res/drawable/ic_clear.xml b/plugin-places/src/main/res/drawable/ic_clear.xml new file mode 100644 index 000000000..ede4b7108 --- /dev/null +++ b/plugin-places/src/main/res/drawable/ic_clear.xml @@ -0,0 +1,9 @@ + + + diff --git a/plugin-places/src/main/res/drawable/scroll_shadow.xml b/plugin-places/src/main/res/drawable/scroll_shadow.xml new file mode 100644 index 000000000..65cf3d913 --- /dev/null +++ b/plugin-places/src/main/res/drawable/scroll_shadow.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/activity_places_complete.xml b/plugin-places/src/main/res/layout/activity_places_complete.xml index cf95a793a..c23ceb5b9 100644 --- a/plugin-places/src/main/res/layout/activity_places_complete.xml +++ b/plugin-places/src/main/res/layout/activity_places_complete.xml @@ -2,74 +2,76 @@ + android:layout_height="match_parent" + android:background="@android:color/transparent"> - - + - + + + + + - + app:layout_constraintTop_toTopOf="parent"> + + + + + + - - diff --git a/plugin-places/src/main/res/layout/item_search_result.xml b/plugin-places/src/main/res/layout/item_search_result.xml new file mode 100644 index 000000000..50199b4c8 --- /dev/null +++ b/plugin-places/src/main/res/layout/item_search_result.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + diff --git a/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml b/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml new file mode 100644 index 000000000..509ce207c --- /dev/null +++ b/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + diff --git a/plugin-places/src/main/res/layout/layout_cardview_search_result.xml b/plugin-places/src/main/res/layout/layout_cardview_search_result.xml new file mode 100644 index 000000000..e39cf0c35 --- /dev/null +++ b/plugin-places/src/main/res/layout/layout_cardview_search_result.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + diff --git a/plugin-places/src/main/res/values/strings.xml b/plugin-places/src/main/res/values/strings.xml index 0eb715528..29ada8a30 100644 --- a/plugin-places/src/main/res/values/strings.xml +++ b/plugin-places/src/main/res/values/strings.xml @@ -2,4 +2,5 @@ Search here Close Search + Clear Search Query From fd4b3d801fe4739de80b6b271cb7eee8e39b86fe Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Fri, 17 Nov 2017 11:21:16 -0500 Subject: [PATCH 03/25] progress --- .../places/AutocompleteLauncherActivity.java | 11 +--- gradle/sonarqube.gradle | 2 +- plugin-places/build.gradle | 2 + plugin-places/src/main/AndroidManifest.xml | 7 ++- .../autocomplete/PlaceAutocomplete.java | 36 ++++++------ .../autocomplete/PlacesCompleteActivity.java | 51 ++++++++++++++--- .../{ => views}/SearchBarView.java | 15 +++-- .../{ => views}/SearchResultView.java | 39 +++++++++++-- .../places/details/PlacesDetailsActivity.java | 15 +++++ .../res/layout/activity_places_complete.xml | 55 +++--------------- .../res/layout/activity_places_details.xml | 12 ++++ .../layout/details_bottom_sheet_layout.xml | 29 ++++++++++ .../main/res/layout/item_search_result.xml | 4 +- .../res/layout/layout_cardview_search_bar.xml | 14 +++-- .../layout/layout_cardview_search_result.xml | 57 ++++++++++--------- .../main/res/layout/view_search_results.xml | 40 +++++++++++++ 16 files changed, 262 insertions(+), 127 deletions(-) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => views}/SearchBarView.java (87%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => views}/SearchResultView.java (68%) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java create mode 100644 plugin-places/src/main/res/layout/activity_places_details.xml create mode 100644 plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml create mode 100644 plugin-places/src/main/res/layout/view_search_results.xml diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index 560200046..2fbbe3815 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -25,16 +25,9 @@ protected void onCreate(Bundle savedInstanceState) { @OnClick(R.id.fabOverlay) public void onOverlayFabClick(View view) { - Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.THEME_OVERLAY) + Intent intent = new PlaceAutocomplete.IntentBuilder() + .limit(10) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } - - @OnClick(R.id.fabFullScreen) - public void onFullscreenFabClick(View view) { - Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.THEME_FULLSCREEN) - .build(AutocompleteLauncherActivity.this); - startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); - } - } diff --git a/gradle/sonarqube.gradle b/gradle/sonarqube.gradle index a5bdd3a84..c6c34c622 100644 --- a/gradle/sonarqube.gradle +++ b/gradle/sonarqube.gradle @@ -3,7 +3,7 @@ apply plugin: 'org.sonarqube' sonarqube { properties { property "sonar.java.coveragePlugin", "jacoco" - property "sonar.host.url", "https://sonarcloud.io" + property "sonar.host.url", "https://mb-sonarqube-staging.tilestream.net" property "sonar.login", System.env.SONARQUBE_API_TOKEN property "sonar.organization", "mapbox" property "sonar.projectName", "mapbox-plugins" diff --git a/plugin-places/build.gradle b/plugin-places/build.gradle index 75747923f..030ef139e 100644 --- a/plugin-places/build.gradle +++ b/plugin-places/build.gradle @@ -23,6 +23,7 @@ android { } } + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) @@ -32,6 +33,7 @@ dependencies { implementation dependenciesList.mapboxGeocoding // Unit testing + implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation dependenciesList.junit testImplementation dependenciesList.mockito diff --git a/plugin-places/src/main/AndroidManifest.xml b/plugin-places/src/main/AndroidManifest.xml index 143de17c4..8269bc8c3 100644 --- a/plugin-places/src/main/AndroidManifest.xml +++ b/plugin-places/src/main/AndroidManifest.xml @@ -1,12 +1,17 @@ + + + + - + + \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index e88f11a9b..d9827cb56 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -2,27 +2,29 @@ import android.app.Activity; import android.content.Intent; +import android.support.annotation.ColorInt; import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.text.TextUtils; +import com.mapbox.geocoding.v5.GeocodingCriteria; +import com.mapbox.geocoding.v5.GeocodingCriteria.GeocodingTypeCriteria; import com.mapbox.geojson.Point; -public class PlaceAutocomplete { +import java.util.Locale; - public static final int THEME_FULLSCREEN = 2; - public static final int THEME_OVERLAY = 1; +public class PlaceAutocomplete { private PlaceAutocomplete() { } - public static class IntentBuilder { final Intent intent; - public IntentBuilder(@IntRange(from = 1, to = 2) int mode) { + public IntentBuilder() { intent = new Intent(); - intent.putExtra("mode", mode); } public IntentBuilder boundingBoxBias(Point southwest, Point northeast) { @@ -30,8 +32,9 @@ public IntentBuilder boundingBoxBias(Point southwest, Point northeast) { return this; } - public IntentBuilder country() { - + // TODO introduce theme object that can be passed in + public IntentBuilder backgroundColor(@ColorInt int backgroundColor) { + intent.putExtra("backgroundColor", backgroundColor); return this; } @@ -40,23 +43,24 @@ public IntentBuilder countries() { return this; } - public IntentBuilder proximity() { - + public IntentBuilder proximity(@NonNull Point proximity) { + intent.putExtra("proximity", proximity.toJson()); return this; } - public IntentBuilder types() { - + public IntentBuilder types(@NonNull @GeocodingTypeCriteria String... geocodingTypes) { + String types = TextUtils.join(",", geocodingTypes); + intent.putExtra("types", types); return this; } - public IntentBuilder language() { - + public IntentBuilder language(String languages) { + intent.putExtra("language", languages); return this; } - public IntentBuilder limit() { - + public IntentBuilder limit(@IntRange(from = 1, to = 10) int limit) { + intent.putExtra("limit", limit); return this; } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java index 3ae9de3ff..2d554cf08 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java @@ -4,6 +4,7 @@ import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; @@ -11,9 +12,20 @@ import android.widget.EditText; import android.widget.ImageButton; +import com.mapbox.geocoding.v5.MapboxGeocoding; +import com.mapbox.geocoding.v5.models.GeocodingResponse; import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.views.SearchBarView; -public class PlacesCompleteActivity extends AppCompatActivity { +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class PlacesCompleteActivity extends AppCompatActivity implements + SearchBarView.QueryListener, Callback { + + private MapboxGeocoding.Builder geocoderBuilder; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -21,19 +33,44 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_places_complete); Intent intent = getIntent(); - int mode = intent.getIntExtra("mode", PlaceAutocomplete.THEME_FULLSCREEN); - if (mode == PlaceAutocomplete.THEME_OVERLAY) { - } else { - getWindow().getDecorView().setBackgroundColor(Color.parseColor("#263D57")); - } - } + View view = findViewById(R.id.root_layout); + view.setBackgroundColor(intent.getIntExtra("backgroundColor", Color.GRAY)); + geocoderBuilder = geocoderBuilder(); + + geocoderBuilder.limit(intent.getIntExtra("limit", 5)); + + + SearchBarView searchBar = findViewById(R.id.cardview_search); + searchBar.addQueryChangeListener(this); + } + private MapboxGeocoding.Builder geocoderBuilder() { + return MapboxGeocoding.builder() + .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") + .autocomplete(true); + } + @Override + public void onQueryChange(CharSequence charSequence) { + String query = charSequence.toString(); + if (query.isEmpty()) { + return; + } + geocoderBuilder.query(query) + .build().enqueueCall(this); + } + @Override + public void onResponse(Call call, Response response) { + System.out.println(response.body().features().get(0).placeName()); + } + @Override + public void onFailure(Call call, Throwable t) { + } } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchBarView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchBarView.java similarity index 87% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchBarView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchBarView.java index 57118995d..7dfea287f 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchBarView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchBarView.java @@ -1,4 +1,4 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.views; import android.content.Context; import android.support.annotation.NonNull; @@ -17,6 +17,7 @@ public class SearchBarView extends CardView implements ImageButton.OnClickListener, TextWatcher { + QueryListener queryListener; ImageButton backButton; ImageButton clearButton; EditText searchEditText; @@ -34,6 +35,10 @@ public SearchBarView(@NonNull Context context, @Nullable AttributeSet attrs, int initialize(context); } + public void addQueryChangeListener(@NonNull QueryListener queryListener) { + this.queryListener = queryListener; + } + private void initialize(Context context) { inflate(context, R.layout.layout_cardview_search_bar, this); } @@ -62,20 +67,18 @@ public void onClick(View view) { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + queryListener.onQueryChange(charSequence); clearButton.setVisibility(charSequence.length() > 0 ? View.VISIBLE : INVISIBLE); } @Override public void afterTextChanged(Editable editable) { - } - private void initBackground() { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { // Hide the background @@ -85,5 +88,7 @@ private void initBackground() { } } - + public interface QueryListener { + void onQueryChange(CharSequence charSequence); + } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchResultView.java similarity index 68% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchResultView.java index c0639229a..ac15f187b 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchResultView.java @@ -1,20 +1,28 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.views; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; +import android.view.View; +import android.view.inputmethod.InputMethodManager; import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.SearchResultAdapter; +import com.mapbox.plugins.places.autocomplete.SearchResultModel; import java.util.ArrayList; import java.util.List; -public class SearchResultView extends CardView { +public class SearchResultView extends CardView implements NestedScrollView.OnScrollChangeListener { + + private NestedScrollView searchResultsScrollView; + private View dropShadow; public SearchResultView(@NonNull Context context) { this(context, null); @@ -29,10 +37,33 @@ public SearchResultView(@NonNull Context context, @Nullable AttributeSet attrs, initialize(context); } - private void initialize(Context context) { - inflate(context, R.layout.layout_cardview_search_result, this); + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + searchResultsScrollView = findViewById(R.id.nested_scroll_view_search_results); + dropShadow = findViewById(R.id.scroll_drop_shadow); initBackground(); initializeResultList(); + searchResultsScrollView.setOnScrollChangeListener(this); + } + + @Override + public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getWindowToken(), 0); + + if (v.canScrollVertically(-1)) { + dropShadow.setVisibility(VISIBLE); + // Show elevation + } else { + dropShadow.setVisibility(INVISIBLE); + // Remove elevation + } + } + + + private void initialize(Context context) { + inflate(context, R.layout.layout_cardview_search_result, this); } private void initializeResultList() { diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java new file mode 100644 index 000000000..90f1e01c9 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java @@ -0,0 +1,15 @@ +package com.mapbox.plugins.places.details; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +import com.mapbox.places.R; + +public class PlacesDetailsActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_places_details); + } +} diff --git a/plugin-places/src/main/res/layout/activity_places_complete.xml b/plugin-places/src/main/res/layout/activity_places_complete.xml index c23ceb5b9..86d16dc62 100644 --- a/plugin-places/src/main/res/layout/activity_places_complete.xml +++ b/plugin-places/src/main/res/layout/activity_places_complete.xml @@ -2,21 +2,17 @@ - - + - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/cardview_search"> + diff --git a/plugin-places/src/main/res/layout/activity_places_details.xml b/plugin-places/src/main/res/layout/activity_places_details.xml new file mode 100644 index 000000000..5d4be6125 --- /dev/null +++ b/plugin-places/src/main/res/layout/activity_places_details.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml b/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml new file mode 100644 index 000000000..522f4f602 --- /dev/null +++ b/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml @@ -0,0 +1,29 @@ + + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/item_search_result.xml b/plugin-places/src/main/res/layout/item_search_result.xml index 50199b4c8..d7b14a12b 100644 --- a/plugin-places/src/main/res/layout/item_search_result.xml +++ b/plugin-places/src/main/res/layout/item_search_result.xml @@ -31,7 +31,7 @@ android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:layout_marginEnd="16dp" - android:layout_marginStart="72dp" + android:layout_marginStart="64dp" android:textColor="@color/lightNavy" android:textSize="12sp" app:layout_constraintBottom_toBottomOf="parent" @@ -45,7 +45,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="16dp" - android:layout_marginStart="72dp" + android:layout_marginStart="64dp" android:layout_marginTop="8dp" android:textColor="@color/navy" android:textSize="16sp" diff --git a/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml b/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml index 509ce207c..3d45380ff 100644 --- a/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml +++ b/plugin-places/src/main/res/layout/layout_cardview_search_bar.xml @@ -5,8 +5,10 @@ android:id="@+id/cardview_search" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="4dp" android:layout_marginBottom="4dp" + android:layout_marginEnd="4dp" + android:layout_marginStart="4dp" + android:layout_marginTop="4dp" app:cardCornerRadius="8dp" app:cardElevation="2dp" app:cardPreventCornerOverlap="true" @@ -23,6 +25,7 @@ android:layout_width="24dp" android:layout_height="24dp" android:layout_marginBottom="8dp" + android:layout_marginLeft="16dp" android:layout_marginStart="16dp" android:layout_marginTop="8dp" android:background="@android:color/transparent" @@ -32,8 +35,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/ic_arrow_back" - android:layout_marginLeft="16dp"/> + app:srcCompat="@drawable/ic_arrow_back"/> + app:layout_constraintTop_toTopOf="parent"/> - + android:layout_height="match_parent"> - + android:layout_height="match_parent" + android:layout_marginEnd="4dp" + android:layout_marginStart="4dp" + android:clipToPadding="false" + android:fillViewport="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@+id/scroll_drop_shadow"> - + android:orientation="vertical"> - - + - + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/view_search_results.xml b/plugin-places/src/main/res/layout/view_search_results.xml new file mode 100644 index 000000000..7d8a43981 --- /dev/null +++ b/plugin-places/src/main/res/layout/view_search_results.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + \ No newline at end of file From 16a8d37469d28d57f9c673b940c8fd4d653ec0ec Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Sat, 18 Nov 2017 19:30:22 -0500 Subject: [PATCH 04/25] added second search style --- .../places/AutocompleteLauncherActivity.java | 60 ++++++++++++- .../res/layout/activity_places_launcher.xml | 10 ++- plugin-places/src/main/AndroidManifest.xml | 9 +- .../autocomplete/PlaceAutocomplete.java | 17 ++-- .../PlaceCompleteCardActivity.java | 89 +++++++++++++++++++ ...ty.java => PlaceCompleteFullActivity.java} | 55 +++++++----- .../autocomplete/SearchResultAdapter.java | 14 ++- .../autocomplete/SearchResultModel.java | 29 ------ ...{SearchResultView.java => ResultView.java} | 56 +++++------- .../{SearchBarView.java => SearchView.java} | 88 +++++++++--------- .../plugins/places/common/KeyboardUtils.java | 20 +++++ .../res/layout/activity_complete_card.xml | 74 +++++++++++++++ .../res/layout/activity_complete_full.xml | 57 ++++++++++++ .../res/layout/activity_places_complete.xml | 36 -------- .../layout/details_bottom_sheet_layout.xml | 6 +- .../main/res/layout/item_search_result.xml | 8 +- .../res/layout/layout_cardview_search_bar.xml | 88 ------------------ .../layout/layout_cardview_search_result.xml | 4 +- .../src/main/res/layout/view_results.xml | 26 ++++++ .../src/main/res/layout/view_search.xml | 66 ++++++++++++++ .../main/res/layout/view_search_results.xml | 40 --------- 21 files changed, 535 insertions(+), 317 deletions(-) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{PlacesCompleteActivity.java => PlaceCompleteFullActivity.java} (55%) delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/{SearchResultView.java => ResultView.java} (50%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/{SearchBarView.java => SearchView.java} (52%) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java create mode 100644 plugin-places/src/main/res/layout/activity_complete_card.xml create mode 100644 plugin-places/src/main/res/layout/activity_complete_full.xml delete mode 100644 plugin-places/src/main/res/layout/activity_places_complete.xml delete mode 100644 plugin-places/src/main/res/layout/layout_cardview_search_bar.xml create mode 100644 plugin-places/src/main/res/layout/view_results.xml create mode 100644 plugin-places/src/main/res/layout/view_search.xml delete mode 100644 plugin-places/src/main/res/layout/view_search_results.xml diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index 2fbbe3815..b6dc97929 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -2,13 +2,14 @@ import android.content.Intent; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; import android.view.View; +import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.plugins.testapp.R; import com.mapbox.plugins.places.autocomplete.PlaceAutocomplete; +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -16,6 +17,9 @@ public class AutocompleteLauncherActivity extends AppCompatActivity { private static final int REQUEST_CODE_AUTOCOMPLETE = 1; + @BindView(R.id.mapView) + MapView mapView; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -23,11 +27,61 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.bind(this); } - @OnClick(R.id.fabOverlay) + @OnClick(R.id.fabCard) public void onOverlayFabClick(View view) { - Intent intent = new PlaceAutocomplete.IntentBuilder() + Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_CARDS) .limit(10) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } + + @OnClick(R.id.fabFullScreen) + public void onFullScreenFabClick(View view) { + Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) + .limit(10) + .build(AutocompleteLauncherActivity.this); + startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } } diff --git a/app/src/main/res/layout/activity_places_launcher.xml b/app/src/main/res/layout/activity_places_launcher.xml index 7bcdf5162..497fe7002 100644 --- a/app/src/main/res/layout/activity_places_launcher.xml +++ b/app/src/main/res/layout/activity_places_launcher.xml @@ -7,8 +7,16 @@ android:layout_height="match_parent" tools:context="com.mapbox.mapboxsdk.plugins.testapp.activity.places.AutocompleteLauncherActivity"> + + + + + diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index d9827cb56..a9dc7ed95 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -7,24 +7,25 @@ import android.support.annotation.NonNull; import android.text.TextUtils; -import com.mapbox.geocoding.v5.GeocodingCriteria; import com.mapbox.geocoding.v5.GeocodingCriteria.GeocodingTypeCriteria; import com.mapbox.geojson.Point; -import java.util.Locale; - public class PlaceAutocomplete { - private PlaceAutocomplete() { + public static final int MODE_FULLSCREEN = 1; + public static final int MODE_CARDS = 2; + private PlaceAutocomplete() { } public static class IntentBuilder { + final int mode; final Intent intent; - public IntentBuilder() { + public IntentBuilder(@IntRange(from = 1, to = 2) int mode) { intent = new Intent(); + this.mode = mode; } public IntentBuilder boundingBoxBias(Point southwest, Point northeast) { @@ -70,7 +71,11 @@ public IntentBuilder injectPlaces() { } public Intent build(Activity activity) { - intent.setClass(activity, PlacesCompleteActivity.class); + if (mode == MODE_FULLSCREEN) { + intent.setClass(activity, PlaceCompleteFullActivity.class); + } else { + intent.setClass(activity, PlaceCompleteCardActivity.class); + } return intent; } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java new file mode 100644 index 000000000..d83566fe9 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java @@ -0,0 +1,89 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import com.mapbox.geocoding.v5.MapboxGeocoding; +import com.mapbox.geocoding.v5.models.GeocodingResponse; +import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.views.SearchView; +import com.mapbox.plugins.places.autocomplete.views.ResultView; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class PlaceCompleteCardActivity extends AppCompatActivity implements + SearchView.QueryListener,Callback, SearchView.BackButtonListener { + + private MapboxGeocoding.Builder geocoderBuilder; + private ResultView searchResultView; + + @Override + protected void onCreate (@Nullable Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_complete_card); + + Intent intent = getIntent(); + + View view = findViewById(R.id.root_layout); + view.setBackgroundColor(intent.getIntExtra("backgroundColor", Color.TRANSPARENT)); + + geocoderBuilder = geocoderBuilder(); + geocoderBuilder.limit(intent.getIntExtra("limit", 5)); + searchResultView = findViewById(R.id.searchResultView); + + SearchView searchView = findViewById(R.id.searchView); + searchView.setBackButtonListener(this); + searchView.setQueryListener(this); + } + + private MapboxGeocoding.Builder geocoderBuilder() { + return MapboxGeocoding.builder() + .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") + .autocomplete(true); + } + + @Override + public void onQueryChange(CharSequence charSequence) { + String query = charSequence.toString(); + if (query.isEmpty()) { + searchResultView.getResultsList().clear(); + searchResultView.notifyDataSetChanged(); + return; + } + geocoderBuilder.query(query) + .build().enqueueCall(this); + } + + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + searchResultView.getResultsList().clear(); + searchResultView.getResultsList().addAll(response.body().features()); + searchResultView.notifyDataSetChanged(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + + + @Override + protected void onDestroy() { +// searchBar.removeBackButtonListener(); +// searchBar.removeQueryListener(); + super.onDestroy(); + } + + @Override + public void onBackButtonPress() { + finish(); + } +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java similarity index 55% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java index 2d554cf08..f5f0008eb 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlacesCompleteActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java @@ -1,63 +1,53 @@ package com.mapbox.plugins.places.autocomplete; import android.content.Intent; -import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.View; -import android.widget.EditText; -import android.widget.ImageButton; import com.mapbox.geocoding.v5.MapboxGeocoding; import com.mapbox.geocoding.v5.models.GeocodingResponse; import com.mapbox.places.R; -import com.mapbox.plugins.places.autocomplete.views.SearchBarView; +import com.mapbox.plugins.places.autocomplete.views.ResultView; +import com.mapbox.plugins.places.autocomplete.views.SearchView; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -import retrofit2.Retrofit; -public class PlacesCompleteActivity extends AppCompatActivity implements - SearchBarView.QueryListener, Callback { +public class PlaceCompleteFullActivity extends AppCompatActivity implements + SearchView.QueryListener, Callback, SearchView.BackButtonListener { private MapboxGeocoding.Builder geocoderBuilder; + private ResultView searchResultView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_places_complete); + setContentView(R.layout.activity_complete_full); Intent intent = getIntent(); - - View view = findViewById(R.id.root_layout); - view.setBackgroundColor(intent.getIntExtra("backgroundColor", Color.GRAY)); - geocoderBuilder = geocoderBuilder(); - geocoderBuilder.limit(intent.getIntExtra("limit", 5)); + searchResultView = findViewById(R.id.searchResultView); - - SearchBarView searchBar = findViewById(R.id.cardview_search); - searchBar.addQueryChangeListener(this); + SearchView searchView = findViewById(R.id.searchView); + searchView.setBackButtonListener(this); + searchView.setQueryListener(this); } - private MapboxGeocoding.Builder geocoderBuilder() { return MapboxGeocoding.builder() .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") .autocomplete(true); } - @Override public void onQueryChange(CharSequence charSequence) { String query = charSequence.toString(); if (query.isEmpty()) { + searchResultView.getResultsList().clear(); + searchResultView.notifyDataSetChanged(); return; } geocoderBuilder.query(query) @@ -66,11 +56,28 @@ public void onQueryChange(CharSequence charSequence) { @Override public void onResponse(Call call, Response response) { - System.out.println(response.body().features().get(0).placeName()); + if (response.isSuccessful()) { + searchResultView.getResultsList().clear(); + searchResultView.getResultsList().addAll(response.body().features()); + searchResultView.notifyDataSetChanged(); + } } @Override public void onFailure(Call call, Throwable t) { } -} \ No newline at end of file + + + @Override + protected void onDestroy() { +// searchBar.removeBackButtonListener(); +// searchBar.removeQueryListener(); + super.onDestroy(); + } + + @Override + public void onBackButtonPress() { + finish(); + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java index bda362cac..9afe99603 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java @@ -6,15 +6,16 @@ import android.view.ViewGroup; import android.widget.TextView; +import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.places.R; import java.util.List; public class SearchResultAdapter extends RecyclerView.Adapter { - private List results; + private List results; - public SearchResultAdapter(List results) { + public SearchResultAdapter(List results) { this.results = results; } @@ -27,8 +28,13 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, int position) { - holder.placeNameView.setText(results.get(position).getTitle()); - holder.addressView.setText(results.get(position).getDescription()); + if (results.get(position).text() != null) { + holder.placeNameView.setText(results.get(position).text()); + } + + if (results.get(position).properties().has("address")) { + holder.addressView.setText(results.get(position).properties().getAsJsonPrimitive("address").getAsString()); + } } @Override diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java deleted file mode 100644 index ac66c6b1b..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultModel.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - - -public class SearchResultModel { - - private String title; - private String description; - - public SearchResultModel(String title, String description) { - this.title = title; - this.description = description; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java similarity index 50% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchResultView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java index ac15f187b..499532dae 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java @@ -5,35 +5,39 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v4.widget.NestedScrollView; -import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.View; -import android.view.inputmethod.InputMethodManager; +import android.widget.LinearLayout; +import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.places.R; import com.mapbox.plugins.places.autocomplete.SearchResultAdapter; -import com.mapbox.plugins.places.autocomplete.SearchResultModel; +import com.mapbox.plugins.places.common.KeyboardUtils; import java.util.ArrayList; import java.util.List; -public class SearchResultView extends CardView implements NestedScrollView.OnScrollChangeListener { +public class ResultView extends LinearLayout implements NestedScrollView.OnScrollChangeListener { private NestedScrollView searchResultsScrollView; + private final List results; + private SearchResultAdapter adapter; private View dropShadow; - public SearchResultView(@NonNull Context context) { + public ResultView(@NonNull Context context) { this(context, null); } - public SearchResultView(@NonNull Context context, @Nullable AttributeSet attrs) { + public ResultView(@NonNull Context context, @Nullable AttributeSet attrs) { this(context, attrs, -1); } - public SearchResultView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + public ResultView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + + results = new ArrayList<>(); initialize(context); } @@ -49,8 +53,7 @@ protected void onFinishInflate() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(getWindowToken(), 0); + KeyboardUtils.hideKeyboard(searchResultsScrollView); if (v.canScrollVertically(-1)) { dropShadow.setVisibility(VISIBLE); @@ -61,40 +64,23 @@ public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int old } } + public List getResultsList() { + return results; + } + + public void notifyDataSetChanged() { + adapter.notifyDataSetChanged(); + } private void initialize(Context context) { inflate(context, R.layout.layout_cardview_search_result, this); + adapter = new SearchResultAdapter(results); } private void initializeResultList() { - List results = new ArrayList<>(); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - results.add(new SearchResultModel("hello", "world")); - RecyclerView recyclerView = findViewById(R.id.rv_search_results); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.setAdapter(new SearchResultAdapter(results)); - - + recyclerView.setAdapter(adapter); } private void initBackground() { diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchBarView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchView.java similarity index 52% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchBarView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchView.java index 7dfea287f..81db8a300 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchBarView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchView.java @@ -3,54 +3,45 @@ import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.CardView; import android.text.Editable; import android.text.TextWatcher; import android.util.AttributeSet; import android.view.View; import android.widget.EditText; import android.widget.ImageButton; -import android.widget.Toast; +import android.widget.LinearLayout; import com.mapbox.places.R; -public class SearchBarView extends CardView implements ImageButton.OnClickListener, TextWatcher { +public class SearchView extends LinearLayout implements ImageButton.OnClickListener, TextWatcher { - QueryListener queryListener; - ImageButton backButton; - ImageButton clearButton; - EditText searchEditText; + @Nullable + private BackButtonListener backButtonListener; + @Nullable + private QueryListener queryListener; - public SearchBarView(@NonNull Context context) { + private final ImageButton backButton; + private final ImageButton clearButton; + private final EditText searchEditText; + + public SearchView(@NonNull Context context) { this(context, null); } - public SearchBarView(@NonNull Context context, @Nullable AttributeSet attrs) { + public SearchView(@NonNull Context context, @Nullable AttributeSet attrs) { this(context, attrs, -1); } - public SearchBarView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + public SearchView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - initialize(context); - } - - public void addQueryChangeListener(@NonNull QueryListener queryListener) { - this.queryListener = queryListener; - } - - private void initialize(Context context) { - inflate(context, R.layout.layout_cardview_search_bar, this); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); + inflate(context, R.layout.view_search, this); backButton = findViewById(R.id.button_search_back); - searchEditText = findViewById(R.id.edittext_search); clearButton = findViewById(R.id.button_search_clear); - initBackground(); + searchEditText = findViewById(R.id.edittext_search); + initialize(); + } + private void initialize() { backButton.setOnClickListener(this); clearButton.setOnClickListener(this); searchEditText.addTextChangedListener(this); @@ -59,36 +50,53 @@ protected void onFinishInflate() { @Override public void onClick(View view) { if (view.getId() == R.id.button_search_back) { - Toast.makeText(getContext(), "hello", Toast.LENGTH_LONG).show(); + if (backButtonListener != null) { + backButtonListener.onBackButtonPress(); + } } else { searchEditText.getText().clear(); } } @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + if (queryListener != null) { + queryListener.onQueryChange(charSequence); + } + clearButton.setVisibility(charSequence.length() > 0 ? View.VISIBLE : INVISIBLE); } @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - queryListener.onQueryChange(charSequence); - clearButton.setVisibility(charSequence.length() > 0 ? View.VISIBLE : INVISIBLE); + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // Not used } @Override public void afterTextChanged(Editable editable) { + // Not used } - private void initBackground() { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { - // Hide the background - getBackground().setAlpha(0); - } else { - setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); - } + public void setBackButtonListener(@Nullable BackButtonListener backButtonListener) { + this.backButtonListener = backButtonListener; + } + + public void removeBackButtonListener() { + backButtonListener = null; + } + + public void setQueryListener(@Nullable QueryListener queryListener) { + this.queryListener = queryListener; + } + + public void removeQueryListener() { + queryListener = null; } public interface QueryListener { void onQueryChange(CharSequence charSequence); } -} + + public interface BackButtonListener { + void onBackButtonPress(); + } +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java b/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java new file mode 100644 index 000000000..3bf8c82f2 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java @@ -0,0 +1,20 @@ +package com.mapbox.plugins.places.common; + +import android.content.Context; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +public class KeyboardUtils { + + private KeyboardUtils() { + } + + public static void hideKeyboard(View view) { + InputMethodManager inputMethodManager + = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); + } +} + + + diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml new file mode 100644 index 000000000..a4c74c21b --- /dev/null +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + diff --git a/plugin-places/src/main/res/layout/activity_complete_full.xml b/plugin-places/src/main/res/layout/activity_complete_full.xml new file mode 100644 index 000000000..b96ad267f --- /dev/null +++ b/plugin-places/src/main/res/layout/activity_complete_full.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/activity_places_complete.xml b/plugin-places/src/main/res/layout/activity_places_complete.xml deleted file mode 100644 index 86d16dc62..000000000 --- a/plugin-places/src/main/res/layout/activity_places_complete.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - diff --git a/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml b/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml index 522f4f602..e25acbf3f 100644 --- a/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml +++ b/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml @@ -2,14 +2,10 @@ + android:orientation="vertical"> - - - - - - - - - - - - - diff --git a/plugin-places/src/main/res/layout/layout_cardview_search_result.xml b/plugin-places/src/main/res/layout/layout_cardview_search_result.xml index cbfc3a63e..7cbf06fd9 100644 --- a/plugin-places/src/main/res/layout/layout_cardview_search_result.xml +++ b/plugin-places/src/main/res/layout/layout_cardview_search_result.xml @@ -9,8 +9,6 @@ android:id="@+id/nested_scroll_view_search_results" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginEnd="4dp" - android:layout_marginStart="4dp" android:clipToPadding="false" android:fillViewport="true" app:layout_constraintBottom_toBottomOf="parent" @@ -26,7 +24,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + diff --git a/plugin-places/src/main/res/layout/view_results.xml b/plugin-places/src/main/res/layout/view_results.xml new file mode 100644 index 000000000..42c60a9fe --- /dev/null +++ b/plugin-places/src/main/res/layout/view_results.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/plugin-places/src/main/res/layout/view_search.xml b/plugin-places/src/main/res/layout/view_search.xml new file mode 100644 index 000000000..a8d8a71b9 --- /dev/null +++ b/plugin-places/src/main/res/layout/view_search.xml @@ -0,0 +1,66 @@ + + + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/view_search_results.xml b/plugin-places/src/main/res/layout/view_search_results.xml deleted file mode 100644 index 7d8a43981..000000000 --- a/plugin-places/src/main/res/layout/view_search_results.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From 5ca81dd42d96d4ed2f7027d56e85cbffe48ac6c7 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Sat, 18 Nov 2017 22:02:58 -0500 Subject: [PATCH 05/25] Finished results card view --- .../places/AutocompleteLauncherActivity.java | 7 +- plugin-places/src/main/AndroidManifest.xml | 4 +- .../places/autocomplete/views/ResultView.java | 14 ++-- .../autocomplete/views/StarredView.java | 75 +++++++++++++++++++ .../places/details/PlacesDetailsActivity.java | 15 ---- .../res/layout/activity_complete_card.xml | 59 +++++++-------- .../res/layout/activity_complete_full.xml | 54 +++++++------ .../res/layout/activity_places_details.xml | 12 --- .../layout/details_bottom_sheet_layout.xml | 25 ------- .../src/main/res/layout/item_user_picked.xml | 61 +++++++++++++++ .../main/res/layout/layout_card_results.xml | 43 +++++++++++ .../layout/layout_cardview_search_result.xml | 39 ---------- plugin-places/src/main/res/values/colors.xml | 2 + 13 files changed, 251 insertions(+), 159 deletions(-) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java delete mode 100644 plugin-places/src/main/res/layout/activity_places_details.xml delete mode 100644 plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml create mode 100644 plugin-places/src/main/res/layout/item_user_picked.xml create mode 100644 plugin-places/src/main/res/layout/layout_card_results.xml delete mode 100644 plugin-places/src/main/res/layout/layout_cardview_search_result.xml diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index b6dc97929..a3dba4e6a 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -1,7 +1,10 @@ package com.mapbox.mapboxsdk.plugins.testapp.activity.places; import android.content.Intent; +import android.graphics.Color; import android.os.Bundle; +import android.support.annotation.ColorInt; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; @@ -31,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) { public void onOverlayFabClick(View view) { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_CARDS) .limit(10) + .backgroundColor(Color.parseColor("#EEEEEE")) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } @@ -38,7 +42,8 @@ public void onOverlayFabClick(View view) { @OnClick(R.id.fabFullScreen) public void onFullScreenFabClick(View view) { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) - .limit(10) + .limit(2) + .backgroundColor(Color.parseColor("#757575")) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } diff --git a/plugin-places/src/main/AndroidManifest.xml b/plugin-places/src/main/AndroidManifest.xml index 48ea74730..903c31ad1 100644 --- a/plugin-places/src/main/AndroidManifest.xml +++ b/plugin-places/src/main/AndroidManifest.xml @@ -14,11 +14,9 @@ - - \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java index 499532dae..9e66f1d06 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java @@ -10,6 +10,7 @@ import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; +import android.widget.ScrollView; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.places.R; @@ -21,7 +22,7 @@ public class ResultView extends LinearLayout implements NestedScrollView.OnScrollChangeListener { - private NestedScrollView searchResultsScrollView; + private ScrollView searchResultsScrollView; private final List results; private SearchResultAdapter adapter; private View dropShadow; @@ -44,11 +45,11 @@ public ResultView(@NonNull Context context, @Nullable AttributeSet attrs, int de @Override protected void onFinishInflate() { super.onFinishInflate(); - searchResultsScrollView = findViewById(R.id.nested_scroll_view_search_results); + searchResultsScrollView = findViewById(R.id.scroll_view_results); dropShadow = findViewById(R.id.scroll_drop_shadow); initBackground(); initializeResultList(); - searchResultsScrollView.setOnScrollChangeListener(this); +// searchResultsScrollView.setOnScrollChangeListener(this); } @Override @@ -73,13 +74,16 @@ public void notifyDataSetChanged() { } private void initialize(Context context) { - inflate(context, R.layout.layout_cardview_search_result, this); + inflate(context, R.layout.layout_card_results, this); adapter = new SearchResultAdapter(results); } private void initializeResultList() { RecyclerView recyclerView = findViewById(R.id.rv_search_results); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); + layoutManager.setAutoMeasureEnabled(true); + recyclerView.setLayoutManager(layoutManager); + recyclerView.setNestedScrollingEnabled(false); recyclerView.setAdapter(adapter); } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java new file mode 100644 index 000000000..0ff5427c1 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java @@ -0,0 +1,75 @@ +package com.mapbox.plugins.places.autocomplete.views; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.CardView; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.AttributeSet; + +import com.mapbox.geocoding.v5.models.CarmenFeature; +import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.SearchResultAdapter; + +import java.util.ArrayList; +import java.util.List; + +public class StarredView extends CardView { + + private final List results; + private SearchResultAdapter adapter; + + public StarredView(@NonNull Context context) { + this(context, null); + } + + public StarredView(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, -1); + } + + public StarredView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + results = new ArrayList<>(); + initialize(context); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + initBackground(); + initializeResultList(); + } + + public List getResultsList() { + return results; + } + + public void notifyDataSetChanged() { + adapter.notifyDataSetChanged(); + } + + private void initializeResultList() { + RecyclerView recyclerView = findViewById(R.id.rv_search_results); + RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); + layoutManager.setAutoMeasureEnabled(true); + recyclerView.setLayoutManager(layoutManager); + recyclerView.setNestedScrollingEnabled(false); + recyclerView.setAdapter(adapter); + } + + private void initialize(Context context) { + inflate(context, R.layout.layout_card_results, this); + adapter = new SearchResultAdapter(results); + } + + private void initBackground() { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { + // Hide the background + getBackground().setAlpha(0); + } else { + setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); + } + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java deleted file mode 100644 index 90f1e01c9..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/details/PlacesDetailsActivity.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mapbox.plugins.places.details; - -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; - -import com.mapbox.places.R; - -public class PlacesDetailsActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_places_details); - } -} diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index a4c74c21b..00c1bdc0b 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -2,7 +2,6 @@ - + + + app:layout_constraintTop_toTopOf="@+id/scroll_drop_shadow"> + app:layout_constraintTop_toTopOf="@+id/scroll_drop_shadow"/> + + + + - - diff --git a/plugin-places/src/main/res/layout/activity_complete_full.xml b/plugin-places/src/main/res/layout/activity_complete_full.xml index b96ad267f..ab540b49f 100644 --- a/plugin-places/src/main/res/layout/activity_complete_full.xml +++ b/plugin-places/src/main/res/layout/activity_complete_full.xml @@ -7,50 +7,48 @@ android:layout_height="match_parent"> + android:layout_height="56dp" + android:background="#ffffff" + android:elevation="4dp" + android:minHeight="?attr/actionBarSize" + android:theme="?attr/actionBarTheme" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" + local:popupTheme="@style/ThemeOverlay.AppCompat.Light" + local:theme="@style/ThemeOverlay.AppCompat.Light"> - - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"/> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/constraintLayout"> diff --git a/plugin-places/src/main/res/layout/activity_places_details.xml b/plugin-places/src/main/res/layout/activity_places_details.xml deleted file mode 100644 index 5d4be6125..000000000 --- a/plugin-places/src/main/res/layout/activity_places_details.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml b/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml deleted file mode 100644 index e25acbf3f..000000000 --- a/plugin-places/src/main/res/layout/details_bottom_sheet_layout.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/item_user_picked.xml b/plugin-places/src/main/res/layout/item_user_picked.xml new file mode 100644 index 000000000..df0df2169 --- /dev/null +++ b/plugin-places/src/main/res/layout/item_user_picked.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + diff --git a/plugin-places/src/main/res/layout/layout_card_results.xml b/plugin-places/src/main/res/layout/layout_card_results.xml new file mode 100644 index 000000000..1902484dd --- /dev/null +++ b/plugin-places/src/main/res/layout/layout_card_results.xml @@ -0,0 +1,43 @@ + + + + + + + + + diff --git a/plugin-places/src/main/res/layout/layout_cardview_search_result.xml b/plugin-places/src/main/res/layout/layout_cardview_search_result.xml deleted file mode 100644 index 7cbf06fd9..000000000 --- a/plugin-places/src/main/res/layout/layout_cardview_search_result.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugin-places/src/main/res/values/colors.xml b/plugin-places/src/main/res/values/colors.xml index d6951b754..3621ad41c 100644 --- a/plugin-places/src/main/res/values/colors.xml +++ b/plugin-places/src/main/res/values/colors.xml @@ -3,4 +3,6 @@ #263d57 #949fac + + #4a90e2 From 04ccf56f2fb53ced3adfd2ea4b881e11d940b072 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Sun, 19 Nov 2017 13:28:55 -0500 Subject: [PATCH 06/25] Added ability to add cards --- plugin-places/src/main/AndroidManifest.xml | 2 +- .../autocomplete/PlaceAutocomplete.java | 11 ++- .../PlaceCompleteCardActivity.java | 84 ++++++++++++++++--- .../autocomplete/SearchResultAdapter.java | 7 ++ .../autocomplete/views/StarredView.java | 75 ----------------- .../plugins/places/common/KeyboardUtils.java | 6 ++ .../res/layout/activity_complete_card.xml | 29 +++++-- .../src/main/res/layout/item_user_picked.xml | 2 +- .../main/res/layout/layout_card_results.xml | 5 +- .../src/main/res/layout/view_search.xml | 4 + 10 files changed, 126 insertions(+), 99 deletions(-) delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java diff --git a/plugin-places/src/main/AndroidManifest.xml b/plugin-places/src/main/AndroidManifest.xml index 903c31ad1..5c7a8f406 100644 --- a/plugin-places/src/main/AndroidManifest.xml +++ b/plugin-places/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:name="com.mapbox.plugins.places.autocomplete.PlaceCompleteCardActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@style/Theme.AppCompat.Translucent" - android:windowSoftInputMode="stateVisible"/> + android:windowSoftInputMode="stateVisible|adjustPan"/> carmenFeatures) { + Bundle bundle = new Bundle(); + // TODO https://github.com/mapbox/mapbox-java/pull/646 needs to be merged first +// bundle.putSerializable("injectPlaces", carmenFeatures); + intent.putExtras(bundle); return this; } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java index d83566fe9..735725988 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java @@ -6,25 +6,37 @@ import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.View; +import android.view.ViewTreeObserver; +import android.widget.ScrollView; +import android.widget.Toast; +import com.google.gson.JsonObject; import com.mapbox.geocoding.v5.MapboxGeocoding; +import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.geocoding.v5.models.GeocodingResponse; import com.mapbox.places.R; import com.mapbox.plugins.places.autocomplete.views.SearchView; import com.mapbox.plugins.places.autocomplete.views.ResultView; +import com.mapbox.plugins.places.common.KeyboardUtils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; public class PlaceCompleteCardActivity extends AppCompatActivity implements - SearchView.QueryListener,Callback, SearchView.BackButtonListener { + SearchView.QueryListener, Callback, SearchView.BackButtonListener, + ViewTreeObserver.OnScrollChangedListener { - private MapboxGeocoding.Builder geocoderBuilder; - private ResultView searchResultView; + private MapboxGeocoding.Builder geocoderBuilder; + private ResultView searchResultView; + private ResultView starredView; + private ResultView recentSearchResults; + private ScrollView resultScrollView; + private SearchView searchView; + private CarmenFeature carmenFeature; - @Override - protected void onCreate (@Nullable Bundle savedInstanceState){ + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_complete_card); @@ -35,11 +47,56 @@ protected void onCreate (@Nullable Bundle savedInstanceState){ geocoderBuilder = geocoderBuilder(); geocoderBuilder.limit(intent.getIntExtra("limit", 5)); + searchResultView = findViewById(R.id.searchResultView); + resultScrollView = findViewById(R.id.scroll_view_results); + recentSearchResults = findViewById(R.id.recentSearchResults); + starredView = findViewById(R.id.starredView); + searchView = findViewById(R.id.searchView); + + carmenFeature = CarmenFeature.builder().text("Directions to Home") + .placeName("300 Massachusetts Ave NW") + .properties(new JsonObject()) + .build(); + starredView.getResultsList().add(carmenFeature); + + carmenFeature = CarmenFeature.builder().text("Directions to Work") + .placeName("1509 16th St NW") + .properties(new JsonObject()) + .build(); + starredView.getResultsList().add(carmenFeature); + + for (int i = 0; i < 10; i++) { + carmenFeature = CarmenFeature.builder().text("My Recent Search") + .placeName("1234 John St NW") + .properties(new JsonObject()) + .build(); + recentSearchResults.getResultsList().add(carmenFeature); + } + + + + + + + + - SearchView searchView = findViewById(R.id.searchView); + + + starredView.getResultsList().add(carmenFeature); searchView.setBackButtonListener(this); - searchView.setQueryListener(this); + searchView.setQueryListener(this); + + + resultScrollView.getViewTreeObserver().addOnScrollChangedListener(this); + } + + @Override + public void onScrollChanged() { + if (resultScrollView != null && resultScrollView.getScrollY() != 0) { + KeyboardUtils.hideKeyboard(resultScrollView); + } } private MapboxGeocoding.Builder geocoderBuilder() { @@ -53,6 +110,7 @@ public void onQueryChange(CharSequence charSequence) { String query = charSequence.toString(); if (query.isEmpty()) { searchResultView.getResultsList().clear(); + searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE); searchResultView.notifyDataSetChanged(); return; } @@ -65,6 +123,7 @@ public void onResponse(Call call, Response if (response.isSuccessful()) { searchResultView.getResultsList().clear(); searchResultView.getResultsList().addAll(response.body().features()); + searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE); searchResultView.notifyDataSetChanged(); } } @@ -77,13 +136,18 @@ public void onFailure(Call call, Throwable t) { @Override protected void onDestroy() { -// searchBar.removeBackButtonListener(); -// searchBar.removeQueryListener(); + if (searchView != null) { + searchView.removeBackButtonListener(); + searchView.removeQueryListener(); + } + if (resultScrollView != null) { + resultScrollView.getViewTreeObserver().removeOnScrollChangedListener(this); + } super.onDestroy(); } @Override public void onBackButtonPress() { - finish(); + finish(); } } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java index 9afe99603..ff518ee01 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java @@ -1,5 +1,6 @@ package com.mapbox.plugins.places.autocomplete; +import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -30,10 +31,16 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public void onBindViewHolder(ViewHolder holder, int position) { if (results.get(position).text() != null) { holder.placeNameView.setText(results.get(position).text()); + if (results.get(position).text().contains("Direction")) + holder.placeNameView.setTextColor(Color.parseColor("#4a90e2")); } + + if (results.get(position).properties().has("address")) { holder.addressView.setText(results.get(position).properties().getAsJsonPrimitive("address").getAsString()); + } else { + holder.addressView.setText(results.get(position).placeName()); } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java deleted file mode 100644 index 0ff5427c1..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/StarredView.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mapbox.plugins.places.autocomplete.views; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.CardView; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.util.AttributeSet; - -import com.mapbox.geocoding.v5.models.CarmenFeature; -import com.mapbox.places.R; -import com.mapbox.plugins.places.autocomplete.SearchResultAdapter; - -import java.util.ArrayList; -import java.util.List; - -public class StarredView extends CardView { - - private final List results; - private SearchResultAdapter adapter; - - public StarredView(@NonNull Context context) { - this(context, null); - } - - public StarredView(@NonNull Context context, @Nullable AttributeSet attrs) { - this(context, attrs, -1); - } - - public StarredView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - results = new ArrayList<>(); - initialize(context); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - initBackground(); - initializeResultList(); - } - - public List getResultsList() { - return results; - } - - public void notifyDataSetChanged() { - adapter.notifyDataSetChanged(); - } - - private void initializeResultList() { - RecyclerView recyclerView = findViewById(R.id.rv_search_results); - RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); - layoutManager.setAutoMeasureEnabled(true); - recyclerView.setLayoutManager(layoutManager); - recyclerView.setNestedScrollingEnabled(false); - recyclerView.setAdapter(adapter); - } - - private void initialize(Context context) { - inflate(context, R.layout.layout_card_results, this); - adapter = new SearchResultAdapter(results); - } - - private void initBackground() { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { - // Hide the background - getBackground().setAlpha(0); - } else { - setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); - } - } -} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java b/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java index 3bf8c82f2..b51f21e3e 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java @@ -14,6 +14,12 @@ public static void hideKeyboard(View view) { = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } + + public static void showKeyboard(View view) { + InputMethodManager inputMethodManager + = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.showSoftInput(view, 0); + } } diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index 00c1bdc0b..bf3738821 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -54,16 +54,33 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/scroll_drop_shadow"> - + android:orientation="vertical" + android:paddingBottom="8dp" + android:paddingTop="8dp"> + + + + + + diff --git a/plugin-places/src/main/res/layout/item_user_picked.xml b/plugin-places/src/main/res/layout/item_user_picked.xml index df0df2169..0e4a0512b 100644 --- a/plugin-places/src/main/res/layout/item_user_picked.xml +++ b/plugin-places/src/main/res/layout/item_user_picked.xml @@ -55,7 +55,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - tools:text="Home"/> + tools:text="Directions to Home"/> diff --git a/plugin-places/src/main/res/layout/layout_card_results.xml b/plugin-places/src/main/res/layout/layout_card_results.xml index 1902484dd..90c5e9d48 100644 --- a/plugin-places/src/main/res/layout/layout_card_results.xml +++ b/plugin-places/src/main/res/layout/layout_card_results.xml @@ -6,17 +6,14 @@ android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical" - android:paddingTop="8dp"> + android:orientation="vertical"> Date: Mon, 27 Nov 2017 16:44:40 -0500 Subject: [PATCH 07/25] initial work completed --- app/build.gradle | 2 + .../places/AutocompleteLauncherActivity.java | 46 +++- gradle/dependencies.gradle | 5 +- plugin-places/build.gradle | 10 +- .../autocomplete/OnCardItemClickListener.java | 7 + .../autocomplete/PlaceAutocomplete.java | 224 ++++++++++++++++-- .../PlaceCompleteCardActivity.java | 132 ++++++----- .../PlaceCompleteFullActivity.java | 19 ++ .../places/autocomplete/PlaceConstants.java | 32 +++ .../places/autocomplete/RecentSearch.java | 39 +++ .../autocomplete/RecentSearchAsyncTask.java | 72 ++++++ .../autocomplete/RecentSearchesDao.java | 26 ++ .../autocomplete/SearchHistoryDatabase.java | 14 ++ .../autocomplete/SearchResultAdapter.java | 31 ++- .../plugins/places/autocomplete/Utils.java | 52 ++++ .../autocomplete/views/ResultCardView.java | 28 +++ .../places/autocomplete/views/ResultView.java | 55 ++--- .../src/main/res/drawable/line_divider.xml | 20 ++ .../res/layout/activity_complete_card.xml | 30 +-- .../res/layout/activity_complete_full.xml | 1 + ...card_results.xml => view_card_results.xml} | 1 - plugin-places/src/main/res/values/colors.xml | 3 +- 22 files changed, 704 insertions(+), 145 deletions(-) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java create mode 100644 plugin-places/src/main/res/drawable/line_divider.xml rename plugin-places/src/main/res/layout/{layout_card_results.xml => view_card_results.xml} (97%) diff --git a/app/build.gradle b/app/build.gradle index 613049d33..651686b2a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,8 @@ dependencies { implementation dependenciesList.supportRecyclerView implementation dependenciesList.supportConstraintLayout + implementation dependenciesList.mapboxGeocoding + // Unit testing implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation dependenciesList.junit diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index a3dba4e6a..9ddd5381c 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -1,20 +1,26 @@ package com.mapbox.mapboxsdk.plugins.testapp.activity.places; +import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; -import android.support.annotation.ColorInt; -import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; +import android.widget.Toast; +import com.google.gson.JsonObject; +import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.plugins.testapp.R; import com.mapbox.plugins.places.autocomplete.PlaceAutocomplete; +import java.util.ArrayList; +import java.util.List; + import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.OnLongClick; public class AutocompleteLauncherActivity extends AppCompatActivity { @@ -23,31 +29,65 @@ public class AutocompleteLauncherActivity extends AppCompatActivity { @BindView(R.id.mapView) MapView mapView; + private List carmenFeatures; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_places_launcher); ButterKnife.bind(this); + carmenFeatures = new ArrayList<>(); + addUserLocations(); + } + + private void addUserLocations() { + carmenFeatures.add(CarmenFeature.builder().text("Directions to Home") + .address("300 Massachusetts Ave NW") + .properties(new JsonObject()) + .build()); + + carmenFeatures.add(CarmenFeature.builder().text("Directions to Work") + .address("1509 16th St NW") + .properties(new JsonObject()) + .build()); } @OnClick(R.id.fabCard) public void onOverlayFabClick(View view) { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_CARDS) + .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") .limit(10) .backgroundColor(Color.parseColor("#EEEEEE")) + .injectPlaces(carmenFeatures) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } + @OnLongClick(R.id.fabCard) + public boolean onOverlayFabLongClick(View view) { + PlaceAutocomplete.clearRecentHistory(this); + Toast.makeText(this, "database cleared", Toast.LENGTH_LONG).show(); + return true; + } + @OnClick(R.id.fabFullScreen) public void onFullScreenFabClick(View view) { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) .limit(2) - .backgroundColor(Color.parseColor("#757575")) + .backgroundColor(Color.WHITE) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_AUTOCOMPLETE) { + CarmenFeature feature = PlaceAutocomplete.getPlace(data); + Toast.makeText(this, feature.text(), Toast.LENGTH_LONG).show(); + } + } + @Override public void onResume() { super.onResume(); diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index dc15bc203..16359fcad 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -29,7 +29,8 @@ ext { commonsIO : '2.5', robolectric : '3.4.2', lifecycleCompiler: '1.0.0', - lifecycleRuntime : '1.0.3' + lifecycleRuntime : '1.0.3', + room : '1.0.0' ] pluginVersion = [ @@ -70,6 +71,8 @@ ext { // architecture lifecycleExtensions : "android.arch.lifecycle:extensions:${version.lifecycleRuntime}", lifecycleCompiler : "android.arch.lifecycle:compiler:${version.lifecycleCompiler}", + roomRuntime : "android.arch.persistence.room:runtime:${version.room}", + roomCompiler : "android.arch.persistence.room:compiler:${version.room}", // square crew timber : "com.jakewharton.timber:timber:${version.timber}", diff --git a/plugin-places/build.gradle b/plugin-places/build.gradle index 030ef139e..b123e02e0 100644 --- a/plugin-places/build.gradle +++ b/plugin-places/build.gradle @@ -29,16 +29,18 @@ dependencies { implementation dependenciesList.supportAppcompatV7 implementation dependenciesList.supportConstraintLayout + implementation dependenciesList.supportCardView + implementation dependenciesList.supportRecyclerView + implementation dependenciesList.supportV4 + + implementation dependenciesList.roomRuntime + annotationProcessor dependenciesList.roomCompiler implementation dependenciesList.mapboxGeocoding // Unit testing - implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation dependenciesList.junit testImplementation dependenciesList.mockito javadocDeps dependenciesList.mapboxMapSdk - implementation 'com.android.support:cardview-v7:27.0.0' - implementation 'com.android.support:recyclerview-v7:27.0.0' - implementation 'com.android.support:support-v4:27.0.0' } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java new file mode 100644 index 000000000..de83274ac --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java @@ -0,0 +1,7 @@ +package com.mapbox.plugins.places.autocomplete; + +import com.mapbox.geocoding.v5.models.CarmenFeature; + +public interface OnCardItemClickListener { + void onItemClick(CarmenFeature carmenFeature); +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index 5ab9e82cd..ec588e946 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -1,8 +1,9 @@ package com.mapbox.plugins.places.autocomplete; import android.app.Activity; +import android.arch.persistence.room.Room; +import android.content.Context; import android.content.Intent; -import android.os.Bundle; import android.support.annotation.ColorInt; import android.support.annotation.IntRange; import android.support.annotation.NonNull; @@ -12,72 +13,261 @@ import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.geojson.Point; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Locale; +/** + * PlaceAutocomplete provides an activity that allows a user to start typing a place name or an + * address and see place predictions appear as they type. The activity can also display recent + * search history, injected places (as a separate list), and more. + *

+ * If the user exits the autocomplete activity without choosing a place, the calling activity will + * receive {@link Activity#RESULT_CANCELED}. + * + * @since 0.1.0 + */ public class PlaceAutocomplete { + /** + * Mode for launching the autocomplete activity in fullscreen. + * + * @since 0.1.0 + */ public static final int MODE_FULLSCREEN = 1; + + /** + * Mode for launching the autocomplete activity using Android card views for the layouts. + * + * @since 0.1.0 + */ public static final int MODE_CARDS = 2; private PlaceAutocomplete() { + // Class should never be initialized. + } + + /** + * Returns the {@link CarmenFeature} selected by the user. + * + * @param data the result Intent that was provided in + * {@link Activity#onActivityResult(int, int, Intent)} + * @return the users selected {@link CarmenFeature} + */ + public static CarmenFeature getPlace(Intent data) { + String json = data.getStringExtra(PlaceConstants.RETURNING_CARMEN_FEATURE); + return CarmenFeature.fromJson(json); } + /** + * If the search history is being displayed in the search results section you should provide a + * setting for the user to clear their search history. Calling this method will remove all entries + * from the database. + * + * @param context your application's context + * @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(); + } + + /** + * Builder for the Place Autocomplete launch intent. + *

+ * After setting the required and optional parameters, call {@link IntentBuilder#build(Activity)} + * and pass the intent to {@link Activity#startActivityForResult(Intent, int)}. + *

+ * + * @since 0.1.0 + */ public static class IntentBuilder { - final int mode; - final Intent intent; + private final ArrayList countries; + private final Intent intent; + private final int mode; + /** + * Creates a new builder that creates an intent to launch the autocomplete activity. + * + * @param mode Either {@link PlaceAutocomplete#MODE_FULLSCREEN} or + * {@link PlaceAutocomplete#MODE_CARDS} + * @since 0.1.0 + */ public IntentBuilder(@IntRange(from = 1, to = 2) int mode) { + countries = new ArrayList<>(); intent = new Intent(); this.mode = mode; } - public IntentBuilder boundingBoxBias(Point southwest, Point northeast) { -// intent.putExtra() + /** + * Required to call when this is being built. If no access token provided, + * {@link com.mapbox.services.exceptions.ServicesException} will be thrown. + * + * @param accessToken Mapbox access token, You must have a Mapbox account inorder to use the + * Geocoding API + * @return this builder for chaining options together + * @since 0.1.0 + */ + public IntentBuilder accessToken(@NonNull String accessToken) { + intent.putExtra(PlaceConstants.ACCESS_TOKEN, accessToken); return this; } - // TODO introduce theme object that can be passed in - public IntentBuilder backgroundColor(@ColorInt int backgroundColor) { - intent.putExtra("backgroundColor", backgroundColor); + /** + * Limit the results to a defined bounding box. Unlike {@link #proximity(Point)}, this will + * strictly limit results to within the bounding box only. If simple biasing is desired rather + * than a strict region, use proximity instead. + * + * @param northeast the northeast corner of the bounding box as a {@link Point} + * @param southwest the southwest corner of the bounding box as a {@link Point} + * @return this builder for chaining options together + * @since 0.1.0 + */ + public IntentBuilder boundingBoxBias(@NonNull Point northeast, @NonNull Point southwest) { + intent.putExtra(PlaceConstants.BBOX_SOUTHWEST_POINT, southwest.toJson()); + intent.putExtra(PlaceConstants.BBOX_NORTHEAST_POINT, northeast.toJson()); return this; } - public IntentBuilder countries() { + /** + * Add a single country locale to restrict the results. This method can be called as many times + * as needed inorder to add multiple countries. + * + * @param country limit geocoding results to one + * @return this builder for chaining options together + * @since 0.1.0 + */ + public IntentBuilder country(Locale country) { + countries.add(country.getCountry()); + return this; + } + /** + * Limit results to one or more countries. Options are ISO 3166 alpha 2 country codes separated + * by commas. + * + * @param country limit geocoding results to one + * @return this builder for chaining options together + * @since 0.1.0 + */ + public IntentBuilder country(String... country) { + countries.addAll(Arrays.asList(country)); return this; } + /** + * Bias local results based on a provided {@link Point}. This oftentimes increases accuracy in + * the returned results. + * + * @param proximity a point defining the proximity you'd like to bias the results around + * @return this builder for chaining options together + * @since 0.1.0 + */ public IntentBuilder proximity(@NonNull Point proximity) { - intent.putExtra("proximity", proximity.toJson()); + intent.putExtra(PlaceConstants.PROXIMITY, proximity.toJson()); return this; } + /** + * This optionally can be set to filter the results returned back after making the geocoding + * request. A null value can't be passed in and only values defined in + * {@link GeocodingTypeCriteria} are allowed. + *

+ * Note that {@link GeocodingTypeCriteria#TYPE_POI_LANDMARK} returns a subset of the results + * returned by {@link GeocodingTypeCriteria#TYPE_POI}. More than one type can be specified. + *

+ * + * @param geocodingTypes optionally filter the result types by one or more defined types inside + * the {@link GeocodingTypeCriteria} + * @return this builder for chaining options together + * @since 0.1.0 + */ public IntentBuilder types(@NonNull @GeocodingTypeCriteria String... geocodingTypes) { String types = TextUtils.join(",", geocodingTypes); - intent.putExtra("types", types); + intent.putExtra(PlaceConstants.TYPE, types); return this; } + /** + * This optionally specifies the desired response language for user queries. Results that match + * the requested language are favored over results in other languages. If more than one language + * tag is supplied separating them by a comma, text in all requested languages will be returned. + *

+ * Any valid IETF language tag can be submitted, and a best effort will be made to return + * results in the requested language or languages, falling back first to similar and then to + * common languages in the event that text is not available in the requested language. In the + * event a fallback language is used, the language field will have a different value than the + * one requested. + *

+ * Translation availability varies by language and region, for a full list of supported regions, + * see the link provided below. + * + * @param languages a String specifying the language or languages you'd like results to support + * @return this builder for chaining options together + * @see Supported languages + * @since 0.1.0 + */ public IntentBuilder language(String languages) { - intent.putExtra("language", languages); + intent.putExtra(PlaceConstants.LANGUAGE, languages); return this; } + /** + * This optionally specifies the maximum number of results to return. the default is 5 and the + * maximum is 10. + * + * @param limit the number of returned results + * @return this builder for chaining options together + * @since 0.1.0 + */ public IntentBuilder limit(@IntRange(from = 1, to = 10) int limit) { - intent.putExtra("limit", limit); + intent.putExtra(PlaceConstants.LIMIT, limit); return this; } + /** + * Insert a list of {@link CarmenFeature}s which you'd like to highlight without the user + * performing a query. These will show up in a different list view. + * + * @param carmenFeatures a list of {@link CarmenFeature}s which you'd like to highlight in the + * results view + * @return this builder for chaining options together + * @since 0.1.0 + */ public IntentBuilder injectPlaces(List carmenFeatures) { - Bundle bundle = new Bundle(); - // TODO https://github.com/mapbox/mapbox-java/pull/646 needs to be merged first -// bundle.putSerializable("injectPlaces", carmenFeatures); - intent.putExtras(bundle); + ArrayList serialized = new ArrayList<>(carmenFeatures.size()); + for (CarmenFeature carmenFeature : carmenFeatures) { + serialized.add(carmenFeature.toJson()); + } + intent.putStringArrayListExtra(PlaceConstants.INJECTED_PLACES, serialized); return this; } + /** + * Set the background color of the activity. + * + * @param backgroundColor the color you'd like the background to show as + * @return this builder for chaining options together + * @since 0.1.0 + */ + public IntentBuilder backgroundColor(@ColorInt int backgroundColor) { + intent.putExtra(PlaceConstants.BACKGROUND, backgroundColor); + return this; + } + + /** + * Retrieves the current Intent as configured by the Builder. + * + * @param activity the current activity which you are launching the autocomplete activity from + * @return the current Intent configured by this builder + * @since 0.1.0 + */ public Intent build(Activity activity) { + intent.putStringArrayListExtra(PlaceConstants.COUNTRIES, countries); + if (mode == MODE_FULLSCREEN) { intent.setClass(activity, PlaceCompleteFullActivity.class); } else { diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java index 735725988..e8ef64baf 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java @@ -1,31 +1,37 @@ package com.mapbox.plugins.places.autocomplete; +import android.arch.persistence.room.Room; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewTreeObserver; import android.widget.ScrollView; -import android.widget.Toast; -import com.google.gson.JsonObject; import com.mapbox.geocoding.v5.MapboxGeocoding; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.geocoding.v5.models.GeocodingResponse; import com.mapbox.places.R; -import com.mapbox.plugins.places.autocomplete.views.SearchView; import com.mapbox.plugins.places.autocomplete.views.ResultView; +import com.mapbox.plugins.places.autocomplete.views.SearchView; import com.mapbox.plugins.places.common.KeyboardUtils; +import java.util.ArrayList; +import java.util.List; + import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import static android.view.View.INVISIBLE; +import static android.view.View.VISIBLE; + public class PlaceCompleteCardActivity extends AppCompatActivity implements SearchView.QueryListener, Callback, SearchView.BackButtonListener, - ViewTreeObserver.OnScrollChangedListener { + ViewTreeObserver.OnScrollChangedListener, OnCardItemClickListener { private MapboxGeocoding.Builder geocoderBuilder; private ResultView searchResultView; @@ -33,84 +39,85 @@ public class PlaceCompleteCardActivity extends AppCompatActivity implements private ResultView recentSearchResults; private ScrollView resultScrollView; private SearchView searchView; - private CarmenFeature carmenFeature; + private SearchHistoryDatabase database; + private View rootView; + private View dropShadow; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_complete_card); + bindViews(); + bindClickListeners(); Intent intent = getIntent(); - View view = findViewById(R.id.root_layout); - view.setBackgroundColor(intent.getIntExtra("backgroundColor", Color.TRANSPARENT)); - - geocoderBuilder = geocoderBuilder(); - geocoderBuilder.limit(intent.getIntExtra("limit", 5)); - - searchResultView = findViewById(R.id.searchResultView); - resultScrollView = findViewById(R.id.scroll_view_results); - recentSearchResults = findViewById(R.id.recentSearchResults); - starredView = findViewById(R.id.starredView); - searchView = findViewById(R.id.searchView); - - carmenFeature = CarmenFeature.builder().text("Directions to Home") - .placeName("300 Massachusetts Ave NW") - .properties(new JsonObject()) - .build(); - starredView.getResultsList().add(carmenFeature); - - carmenFeature = CarmenFeature.builder().text("Directions to Work") - .placeName("1509 16th St NW") - .properties(new JsonObject()) - .build(); - starredView.getResultsList().add(carmenFeature); - - for (int i = 0; i < 10; i++) { - carmenFeature = CarmenFeature.builder().text("My Recent Search") - .placeName("1234 John St NW") - .properties(new JsonObject()) - .build(); - recentSearchResults.getResultsList().add(carmenFeature); - } - - - - - - + // Theme settings + rootView.setBackgroundColor(intent.getIntExtra(PlaceConstants.BACKGROUND, Color.TRANSPARENT)); + fillFavoritePlacesList(intent); + geocoderBuilder = Utils.initiateSearchQuery(intent); + // Get and populate the recent history list + database = Room.databaseBuilder(getApplicationContext(), + SearchHistoryDatabase.class, PlaceConstants.SEARCH_HISTORY_DATABASE_NAME).build(); + new RecentSearchAsyncTask(database, recentSearchResults).execute(); + resultScrollView.getViewTreeObserver().addOnScrollChangedListener(this); + } + private void fillFavoritePlacesList(@NonNull Intent intent) { + List serialized = intent.getStringArrayListExtra(PlaceConstants.INJECTED_PLACES); + if (serialized == null || serialized.isEmpty()) { + return; + } + List starredFeatures = new ArrayList<>(); + for (String serializedCarmenFeature: serialized) { + starredFeatures.add(CarmenFeature.fromJson(serializedCarmenFeature)); + } + starredView.getResultsList().addAll(starredFeatures); + } - starredView.getResultsList().add(carmenFeature); + private void bindClickListeners() { + recentSearchResults.setOnItemClickListener(this); + searchResultView.setOnItemClickListener(this); + starredView.setOnItemClickListener(this); searchView.setBackButtonListener(this); searchView.setQueryListener(this); + } - - resultScrollView.getViewTreeObserver().addOnScrollChangedListener(this); + private void bindViews() { + rootView = findViewById(R.id.root_layout); + searchResultView = findViewById(R.id.searchResultView); + resultScrollView = findViewById(R.id.scroll_view_results); + recentSearchResults = findViewById(R.id.recentSearchResults); + starredView = findViewById(R.id.starredView); + searchView = findViewById(R.id.searchView); + dropShadow = findViewById(R.id.scroll_drop_shadow); } @Override public void onScrollChanged() { - if (resultScrollView != null && resultScrollView.getScrollY() != 0) { - KeyboardUtils.hideKeyboard(resultScrollView); + if (resultScrollView != null) { + if (resultScrollView.getScrollY() != 0) { + KeyboardUtils.hideKeyboard(resultScrollView); + } + if (resultScrollView.canScrollVertically(-1)) { + dropShadow.setVisibility(VISIBLE); + // Show elevation + } else { + dropShadow.setVisibility(INVISIBLE); + // Remove elevation + } } } - private MapboxGeocoding.Builder geocoderBuilder() { - return MapboxGeocoding.builder() - .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") - .autocomplete(true); - } - @Override public void onQueryChange(CharSequence charSequence) { String query = charSequence.toString(); if (query.isEmpty()) { searchResultView.getResultsList().clear(); - searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE); + searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : VISIBLE); searchResultView.notifyDataSetChanged(); return; } @@ -123,16 +130,28 @@ public void onResponse(Call call, Response if (response.isSuccessful()) { searchResultView.getResultsList().clear(); searchResultView.getResultsList().addAll(response.body().features()); - searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE); + searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : VISIBLE); searchResultView.notifyDataSetChanged(); } } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable throwable) { } + @Override + public void onItemClick(CarmenFeature carmenFeature) { + String json = carmenFeature.toJson(); + RecentSearch recentSearch = new RecentSearch(carmenFeature.id(), json); + + new RecentSearchAsyncTask(database, recentSearch).execute(); + + Intent intent = new Intent(); + intent.putExtra(PlaceConstants.RETURNING_CARMEN_FEATURE, json); + setResult(AppCompatActivity.RESULT_OK, intent); + finish(); + } @Override protected void onDestroy() { @@ -148,6 +167,7 @@ protected void onDestroy() { @Override public void onBackButtonPress() { + setResult(AppCompatActivity.RESULT_CANCELED); finish(); } } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java index f5f0008eb..8d255a330 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java @@ -1,9 +1,11 @@ package com.mapbox.plugins.places.autocomplete; import android.content.Intent; +import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; +import android.view.View; import com.mapbox.geocoding.v5.MapboxGeocoding; import com.mapbox.geocoding.v5.models.GeocodingResponse; @@ -20,13 +22,19 @@ public class PlaceCompleteFullActivity extends AppCompatActivity implements private MapboxGeocoding.Builder geocoderBuilder; private ResultView searchResultView; + private View rootView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_complete_full); + bindViews(); Intent intent = getIntent(); + + // TODO Theming occurs here + rootView.setBackgroundColor(intent.getIntExtra("backgroundColor", Color.TRANSPARENT)); + geocoderBuilder = geocoderBuilder(); geocoderBuilder.limit(intent.getIntExtra("limit", 5)); searchResultView = findViewById(R.id.searchResultView); @@ -54,6 +62,17 @@ public void onQueryChange(CharSequence charSequence) { .build().enqueueCall(this); } + private void bindViews() { + rootView = findViewById(R.id.root_layout); + searchResultView = findViewById(R.id.searchResultView); + + +// resultScrollView = findViewById(R.id.scroll_view_results); +// recentSearchResults = findViewById(R.id.recentSearchResults); +// starredView = findViewById(R.id.starredView); +// searchView = findViewById(R.id.searchView); + } + @Override public void onResponse(Call call, Response response) { if (response.isSuccessful()) { diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java new file mode 100644 index 000000000..21d577630 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java @@ -0,0 +1,32 @@ +package com.mapbox.plugins.places.autocomplete; + +final class PlaceConstants { + + private PlaceConstants() { + } + + static final String RETURNING_CARMEN_FEATURE = "carmenFeature"; + + static final String SEARCH_HISTORY_DATABASE_NAME = "mb-places-search-history-db"; + + static final String ACCESS_TOKEN = "mb-places-accessToken"; + + static final String BBOX_SOUTHWEST_POINT = "mb-places-bbox-southwestPoint"; + + static final String BBOX_NORTHEAST_POINT = "mb-places-bbox-northeastPoint"; + + static final String COUNTRIES = "mb-places-countries"; + + static final String PROXIMITY = "mb-places-proximity"; + + static final String TYPE = "mb-places-types"; + + static final String LANGUAGE = "mb-places-language"; + + static final String LIMIT = "mb-places-limit"; + + static final String INJECTED_PLACES = "mb-places-injectPlaces"; + + static final String BACKGROUND = "mb-places-backgroundColor"; + +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java new file mode 100644 index 000000000..fb89ac835 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java @@ -0,0 +1,39 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; + +@Entity +public class RecentSearch { + + public RecentSearch(@NonNull String placeId, String carmenFeature) { + this.placeId = placeId; + this.carmenFeature = carmenFeature; + } + + @NonNull + @PrimaryKey + private String placeId; + + @ColumnInfo(name = "carmen_feature") + private String carmenFeature; + + @NonNull + public String getPlaceId() { + return placeId; + } + + public void setPlaceId(@NonNull String placeId) { + this.placeId = placeId; + } + + public String getCarmenFeature() { + return carmenFeature; + } + + public void setCarmenFeature(String carmenFeature) { + this.carmenFeature = carmenFeature; + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java new file mode 100644 index 000000000..61f46471a --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java @@ -0,0 +1,72 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; + +import com.mapbox.geocoding.v5.models.CarmenFeature; +import com.mapbox.plugins.places.autocomplete.views.ResultView; + +import java.util.ArrayList; +import java.util.List; + +class RecentSearchAsyncTask extends AsyncTask { + + private final SearchHistoryDatabase database; + private List carmenFeatures = new ArrayList<>(); + private ResultView recentSearchResults; + private RecentSearch recentSearch; + + RecentSearchAsyncTask(@NonNull SearchHistoryDatabase database) { + this.database = database; + } + + RecentSearchAsyncTask(@NonNull SearchHistoryDatabase database, + @Nullable ResultView recentSearchResults) { + this.database = database; + this.recentSearchResults = recentSearchResults; + } + + RecentSearchAsyncTask(@NonNull SearchHistoryDatabase database, + @Nullable RecentSearch recentSearch) { + this.database = database; + this.recentSearch = recentSearch; + } + + @Override + protected Void doInBackground(Void... voids) { + + if (recentSearchResults != null) { + for (RecentSearch recentSearch : database.recentSearchesDao().getAll()) { + CarmenFeature carmenFeature = CarmenFeature.fromJson(recentSearch.getCarmenFeature()); + carmenFeatures.add(carmenFeature); + } + } else if (recentSearch != null) { + RecentSearch sameRecentSearch = database.recentSearchesDao() + .findByCarmenFeature(recentSearch.getPlaceId()); + if (sameRecentSearch != null) { + return null; + } + + database.recentSearchesDao().insertAll(recentSearch); + } else { + for (RecentSearch recentSearch : database.recentSearchesDao().getAll()) { + database.recentSearchesDao().delete(recentSearch); + } + } + + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (recentSearchResults != null) { + recentSearchResults.getResultsList().addAll(carmenFeatures); + if (!carmenFeatures.isEmpty()) { + recentSearchResults.setVisibility(View.VISIBLE); + } + } + } +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java new file mode 100644 index 000000000..fa3875d69 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java @@ -0,0 +1,26 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Delete; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.Query; + +import java.util.List; + +@Dao +public interface RecentSearchesDao { + @Query("SELECT * FROM recentsearch") + List getAll(); + + @Query("SELECT * FROM recentsearch WHERE placeId IN (:placeIds)") + List loadAllByIds(String[] placeIds); + + @Query("SELECT * FROM recentsearch WHERE placeId IN (:placeId)") + RecentSearch findByCarmenFeature(String placeId); + + @Insert + void insertAll(RecentSearch... recentSearch); + + @Delete + void delete(RecentSearch recentSearch); +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java new file mode 100644 index 000000000..12c3df2a1 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java @@ -0,0 +1,14 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.arch.persistence.room.Database; +import android.arch.persistence.room.RoomDatabase; + +@Database(entities = {RecentSearch.class}, version = 1) +public abstract class SearchHistoryDatabase extends RoomDatabase { + public abstract RecentSearchesDao recentSearchesDao(); +} + + + + + diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java index ff518ee01..37cf04239 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java @@ -1,6 +1,5 @@ package com.mapbox.plugins.places.autocomplete; -import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -14,7 +13,8 @@ public class SearchResultAdapter extends RecyclerView.Adapter { - private List results; + private final List results; + private OnCardItemClickListener onItemClickListener; public SearchResultAdapter(List results) { this.results = results; @@ -23,24 +23,30 @@ public SearchResultAdapter(List results) { @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - View view = inflater.inflate(R.layout.item_search_result, parent, false); + View view = inflater.inflate( R.layout.item_search_result, parent, false); return new ViewHolder(view); } + public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) { + this.onItemClickListener = onItemClickListener; + } + @Override public void onBindViewHolder(ViewHolder holder, int position) { + if (onItemClickListener != null) { + holder.bind(results.get(position), onItemClickListener); + } + if (results.get(position).text() != null) { holder.placeNameView.setText(results.get(position).text()); - if (results.get(position).text().contains("Direction")) - holder.placeNameView.setTextColor(Color.parseColor("#4a90e2")); } - - if (results.get(position).properties().has("address")) { holder.addressView.setText(results.get(position).properties().getAsJsonPrimitive("address").getAsString()); - } else { + } else if (results.get(position).placeName() != null) { holder.addressView.setText(results.get(position).placeName()); + } else { + holder.addressView.setHeight(0); } } @@ -59,5 +65,14 @@ static class ViewHolder extends RecyclerView.ViewHolder { placeNameView = itemView.findViewById(R.id.tv_place_name); addressView = itemView.findViewById(R.id.tv_address); } + + public void bind(final CarmenFeature carmenFeature, final OnCardItemClickListener listener) { + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.onItemClick(carmenFeature); + } + }); + } } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java new file mode 100644 index 000000000..9f7801b79 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java @@ -0,0 +1,52 @@ +package com.mapbox.plugins.places.autocomplete; + +import android.content.Intent; + +import com.mapbox.geocoding.v5.MapboxGeocoding; +import com.mapbox.geojson.Point; + +public class Utils { + + private Utils() { + } + + static MapboxGeocoding.Builder initiateSearchQuery(Intent intent) { + MapboxGeocoding.Builder geocoderBuilder = MapboxGeocoding.builder().autocomplete(true); + geocoderBuilder.accessToken(intent.getStringExtra(PlaceConstants.ACCESS_TOKEN)); + geocoderBuilder.limit(intent.getIntExtra(PlaceConstants.LIMIT, 5)); + + // Proximity + String proximityPointJson = intent.getStringExtra(PlaceConstants.PROXIMITY); + if (proximityPointJson != null) { + geocoderBuilder.proximity(Point.fromJson(proximityPointJson)); + } + + // Language + String languageJson = intent.getStringExtra(PlaceConstants.LANGUAGE); + if (languageJson != null) { + geocoderBuilder.languages(languageJson); + } + + // Type + String typeJson = intent.getStringExtra(PlaceConstants.TYPE); + if (typeJson != null) { + geocoderBuilder.geocodingTypes(typeJson); + } + + // Countries + String countriesJson = intent.getStringExtra(PlaceConstants.COUNTRIES); + if (countriesJson != null) { + geocoderBuilder.geocodingTypes(countriesJson); + } + + // Bounding box + String southwest = intent.getStringExtra(PlaceConstants.BBOX_SOUTHWEST_POINT); + String northeast = intent.getStringExtra(PlaceConstants.BBOX_NORTHEAST_POINT); + if (southwest != null && northeast != null) { + Point southwestPoint = Point.fromJson(southwest); + Point northeastPoint = Point.fromJson(northeast); + geocoderBuilder.bbox(southwestPoint, northeastPoint); + } + return geocoderBuilder; + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java new file mode 100644 index 000000000..5035886e1 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java @@ -0,0 +1,28 @@ +package com.mapbox.plugins.places.autocomplete.views; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; + +import com.mapbox.places.R; + +public class ResultCardView extends ResultView { + + public ResultCardView(@NonNull Context context) { + this(context, null); + } + + public ResultCardView(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, -1); + } + + public ResultCardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + void inflateView(Context context) { + inflate(context, R.layout.view_card_results, this); + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java index 9e66f1d06..91c171660 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java @@ -1,31 +1,28 @@ package com.mapbox.plugins.places.autocomplete.views; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.support.v4.widget.NestedScrollView; +import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; -import android.view.View; import android.widget.LinearLayout; -import android.widget.ScrollView; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.OnCardItemClickListener; import com.mapbox.plugins.places.autocomplete.SearchResultAdapter; -import com.mapbox.plugins.places.common.KeyboardUtils; import java.util.ArrayList; import java.util.List; -public class ResultView extends LinearLayout implements NestedScrollView.OnScrollChangeListener { +public class ResultView extends LinearLayout { - private ScrollView searchResultsScrollView; private final List results; private SearchResultAdapter adapter; - private View dropShadow; public ResultView(@NonNull Context context) { this(context, null); @@ -37,7 +34,6 @@ public ResultView(@NonNull Context context, @Nullable AttributeSet attrs) { public ResultView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - results = new ArrayList<>(); initialize(context); } @@ -45,24 +41,7 @@ public ResultView(@NonNull Context context, @Nullable AttributeSet attrs, int de @Override protected void onFinishInflate() { super.onFinishInflate(); - searchResultsScrollView = findViewById(R.id.scroll_view_results); - dropShadow = findViewById(R.id.scroll_drop_shadow); - initBackground(); initializeResultList(); -// searchResultsScrollView.setOnScrollChangeListener(this); - } - - @Override - public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { - KeyboardUtils.hideKeyboard(searchResultsScrollView); - - if (v.canScrollVertically(-1)) { - dropShadow.setVisibility(VISIBLE); - // Show elevation - } else { - dropShadow.setVisibility(INVISIBLE); - // Remove elevation - } } public List getResultsList() { @@ -74,25 +53,31 @@ public void notifyDataSetChanged() { } private void initialize(Context context) { - inflate(context, R.layout.layout_card_results, this); + inflateView(context); adapter = new SearchResultAdapter(results); } + void inflateView(Context context) { + inflate(context, R.layout.view_results, this); + } + + public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) { + if (adapter != null) { + adapter.setOnItemClickListener(onItemClickListener); + } + } + private void initializeResultList() { +// Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.line_divider); +// DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), VERTICAL); +// dividerItemDecoration.setDrawable(drawable); + RecyclerView recyclerView = findViewById(R.id.rv_search_results); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setAutoMeasureEnabled(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setNestedScrollingEnabled(false); +// recyclerView.addItemDecoration(dividerItemDecoration); recyclerView.setAdapter(adapter); } - - private void initBackground() { - if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { - // Hide the background - getBackground().setAlpha(0); - } else { - setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); - } - } } diff --git a/plugin-places/src/main/res/drawable/line_divider.xml b/plugin-places/src/main/res/drawable/line_divider.xml new file mode 100644 index 000000000..89f31069c --- /dev/null +++ b/plugin-places/src/main/res/drawable/line_divider.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index bf3738821..4db753d65 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -24,8 +24,6 @@ android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="42dp" - android:layout_marginEnd="8dp" - android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> @@ -34,11 +32,9 @@ + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@+id/scroll_drop_shadow"> - + android:visibility="gone"/> - + android:layout_height="wrap_content" + android:visibility="gone"/> - - - - - diff --git a/plugin-places/src/main/res/layout/activity_complete_full.xml b/plugin-places/src/main/res/layout/activity_complete_full.xml index ab540b49f..171e2ef0c 100644 --- a/plugin-places/src/main/res/layout/activity_complete_full.xml +++ b/plugin-places/src/main/res/layout/activity_complete_full.xml @@ -3,6 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:local="http://schemas.android.com/tools" + android:id="@+id/root_layout" android:layout_width="match_parent" android:layout_height="match_parent"> diff --git a/plugin-places/src/main/res/layout/layout_card_results.xml b/plugin-places/src/main/res/layout/view_card_results.xml similarity index 97% rename from plugin-places/src/main/res/layout/layout_card_results.xml rename to plugin-places/src/main/res/layout/view_card_results.xml index 90c5e9d48..79fc7499a 100644 --- a/plugin-places/src/main/res/layout/layout_card_results.xml +++ b/plugin-places/src/main/res/layout/view_card_results.xml @@ -9,7 +9,6 @@ android:orientation="vertical"> #263d57 #949fac - #4a90e2 + + #EEEEEE From 23e8dabdde8c9c551996e6c929484dbb9e05871e Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 17:40:31 -0500 Subject: [PATCH 08/25] fixed dependency issue --- .../places/AutocompleteLauncherActivity.java | 12 ++++++++++-- gradle/dependencies.gradle | 1 + .../plugins/geojson/GeoJsonPluginBuilder.java | 4 ++-- .../geojson/listener/OnLoadingGeoJsonListener.java | 2 +- .../places/autocomplete/PlaceAutocomplete.java | 1 + .../autocomplete/PlaceCompleteCardActivity.java | 9 +++++---- .../plugins/places/autocomplete/PlaceConstants.java | 1 + .../places/autocomplete/SearchResultAdapter.java | 12 ++++++++++-- .../places/autocomplete/views/ResultView.java | 2 +- 9 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index 9ddd5381c..09de06eb4 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -9,6 +9,7 @@ import android.widget.Toast; import com.google.gson.JsonObject; +import com.mapbox.geocoding.v5.models.CarmenContext; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.plugins.testapp.R; @@ -41,13 +42,20 @@ protected void onCreate(Bundle savedInstanceState) { } private void addUserLocations() { + CarmenContext context = CarmenContext.builder().text("300 Massachusetts Ave NW").build(); + List contextList = new ArrayList<>(); + contextList.add(context); + carmenFeatures.add(CarmenFeature.builder().text("Directions to Home") - .address("300 Massachusetts Ave NW") + .placeName("300 Massachusetts Ave NW") + .id("directions-home") + .context(contextList) .properties(new JsonObject()) .build()); carmenFeatures.add(CarmenFeature.builder().text("Directions to Work") - .address("1509 16th St NW") + .placeName("1509 16th St NW") + .id("directions-work") .properties(new JsonObject()) .build()); } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 05edf3d75..a81172e72 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -10,6 +10,7 @@ ext { version = [ mapboxMapSdk : '5.2.0', mapboxServices : '2.2.9', + mapboxGeocoding : '3.0.0-SNAPSHOT', autoValue : '1.4.1', autoValueParcel : '0.2.5', junit : '4.12', diff --git a/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/GeoJsonPluginBuilder.java b/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/GeoJsonPluginBuilder.java index 3187e1eae..8075edd40 100644 --- a/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/GeoJsonPluginBuilder.java +++ b/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/GeoJsonPluginBuilder.java @@ -120,7 +120,7 @@ public GeoJsonPluginBuilder withPolygonFillColor(@ColorInt int fillColor) { } /** - * @param stockColor the stock color of polyline & polygon. default value is Color.argb(80, 250, 0, 0); + * @param stockColor the stock color of polyline and polygon. default value is Color.argb(80, 250, 0, 0); * @return instance of GeoJsonPluginBuilder class */ @@ -130,7 +130,7 @@ public GeoJsonPluginBuilder withStockColor(@ColorInt int stockColor) { } /** - * @param width the stock width of polyline & polygon. default value is 3 + * @param width the stock width of polyline and polygon. default value is 3 * @return instance of GeoJsonPluginBuilder class */ diff --git a/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/listener/OnLoadingGeoJsonListener.java b/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/listener/OnLoadingGeoJsonListener.java index 61ce5b597..d63737d6d 100644 --- a/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/listener/OnLoadingGeoJsonListener.java +++ b/plugin-geojson/src/main/java/com/mapbox/mapboxsdk/plugins/geojson/listener/OnLoadingGeoJsonListener.java @@ -12,7 +12,7 @@ public interface OnLoadingGeoJsonListener { void onLoaded(); /** - * @param e the Exception occur during load & parse GeoJson file + * @param e the Exception occur during load and parse GeoJson file */ void onLoadFailed(Exception e); } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index ec588e946..1112a9e0f 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -240,6 +240,7 @@ public IntentBuilder limit(@IntRange(from = 1, to = 10) int limit) { public IntentBuilder injectPlaces(List carmenFeatures) { ArrayList serialized = new ArrayList<>(carmenFeatures.size()); for (CarmenFeature carmenFeature : carmenFeatures) { + carmenFeature.properties().addProperty(PlaceConstants.SAVED_PLACE, true); serialized.add(carmenFeature.toJson()); } intent.putStringArrayListExtra(PlaceConstants.INJECTED_PLACES, serialized); diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java index e8ef64baf..08750272f 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java @@ -72,7 +72,7 @@ private void fillFavoritePlacesList(@NonNull Intent intent) { return; } List starredFeatures = new ArrayList<>(); - for (String serializedCarmenFeature: serialized) { + for (String serializedCarmenFeature : serialized) { starredFeatures.add(CarmenFeature.fromJson(serializedCarmenFeature)); } starredView.getResultsList().addAll(starredFeatures); @@ -143,9 +143,10 @@ public void onFailure(Call call, Throwable throwable) { @Override public void onItemClick(CarmenFeature carmenFeature) { String json = carmenFeature.toJson(); - RecentSearch recentSearch = new RecentSearch(carmenFeature.id(), json); - - new RecentSearchAsyncTask(database, recentSearch).execute(); + if (!carmenFeature.properties().has(PlaceConstants.SAVED_PLACE)) { + RecentSearch recentSearch = new RecentSearch(carmenFeature.id(), json); + new RecentSearchAsyncTask(database, recentSearch).execute(); + } Intent intent = new Intent(); intent.putExtra(PlaceConstants.RETURNING_CARMEN_FEATURE, json); diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java index 21d577630..d5180031f 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java @@ -29,4 +29,5 @@ private PlaceConstants() { static final String BACKGROUND = "mb-places-backgroundColor"; + static final String SAVED_PLACE = "saved-carmen-feature"; } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java index 37cf04239..70665f5d8 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java @@ -1,5 +1,7 @@ package com.mapbox.plugins.places.autocomplete; +import android.content.Context; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -14,16 +16,18 @@ public class SearchResultAdapter extends RecyclerView.Adapter { private final List results; + private final Context context; private OnCardItemClickListener onItemClickListener; - public SearchResultAdapter(List results) { + public SearchResultAdapter(Context context, List results) { this.results = results; + this.context = context; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - View view = inflater.inflate( R.layout.item_search_result, parent, false); + View view = inflater.inflate(R.layout.item_search_result, parent, false); return new ViewHolder(view); } @@ -37,6 +41,10 @@ public void onBindViewHolder(ViewHolder holder, int position) { holder.bind(results.get(position), onItemClickListener); } + if (results.get(position).properties().has(PlaceConstants.SAVED_PLACE)) { + holder.placeNameView.setTextColor(ContextCompat.getColor(context, R.color.brightBlue)); + } + if (results.get(position).text() != null) { holder.placeNameView.setText(results.get(position).text()); } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java index 91c171660..38836c6bb 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java @@ -54,7 +54,7 @@ public void notifyDataSetChanged() { private void initialize(Context context) { inflateView(context); - adapter = new SearchResultAdapter(results); + adapter = new SearchResultAdapter(getContext(), results); } void inflateView(Context context) { From b6cae517b4dbbf4322921e8dfca935ba8922c55c Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 17:51:18 -0500 Subject: [PATCH 09/25] initial coded cleanup started --- app/build.gradle | 1 - app/src/main/AndroidManifest.xml | 235 +++++++++--------- .../autocomplete/SearchResultAdapter.java | 21 +- 3 files changed, 129 insertions(+), 128 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 65eb0c8f1..b098b26e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,7 +43,6 @@ dependencies { implementation dependenciesList.mapboxGeocoding // Unit testing - implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation dependenciesList.junit testImplementation dependenciesList.mockito diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 38bcf0833..f8c3fc987 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,124 +2,123 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java index 70665f5d8..37745a1df 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java @@ -13,11 +13,13 @@ import java.util.List; -public class SearchResultAdapter extends RecyclerView.Adapter { +public class SearchResultAdapter extends RecyclerView.Adapter { + private static final String ADDRESS = "address"; + + private OnCardItemClickListener onItemClickListener; private final List results; private final Context context; - private OnCardItemClickListener onItemClickListener; public SearchResultAdapter(Context context, List results) { this.results = results; @@ -25,10 +27,10 @@ public SearchResultAdapter(Context context, List results) { } @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); View view = inflater.inflate(R.layout.item_search_result, parent, false); - return new ViewHolder(view); + return new SearchViewHolder(view); } public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) { @@ -36,7 +38,7 @@ public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) } @Override - public void onBindViewHolder(ViewHolder holder, int position) { + public void onBindViewHolder(SearchViewHolder holder, int position) { if (onItemClickListener != null) { holder.bind(results.get(position), onItemClickListener); } @@ -49,8 +51,9 @@ public void onBindViewHolder(ViewHolder holder, int position) { holder.placeNameView.setText(results.get(position).text()); } - if (results.get(position).properties().has("address")) { - holder.addressView.setText(results.get(position).properties().getAsJsonPrimitive("address").getAsString()); + if (results.get(position).properties().has(ADDRESS)) { + holder.addressView.setText(results.get(position).properties() + .getAsJsonPrimitive(ADDRESS).getAsString()); } else if (results.get(position).placeName() != null) { holder.addressView.setText(results.get(position).placeName()); } else { @@ -63,12 +66,12 @@ public int getItemCount() { return null != results ? results.size() : 0; } - static class ViewHolder extends RecyclerView.ViewHolder { + static class SearchViewHolder extends RecyclerView.ViewHolder { final TextView placeNameView; final TextView addressView; - ViewHolder(View itemView) { + SearchViewHolder(View itemView) { super(itemView); placeNameView = itemView.findViewById(R.id.tv_place_name); addressView = itemView.findViewById(R.id.tv_address); From cae63dfe6de2b66bfe0b08c787f53d2635b62373 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 17:54:02 -0500 Subject: [PATCH 10/25] removed access token --- .../activity/places/AutocompleteLauncherActivity.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index 09de06eb4..738407dbe 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -11,6 +11,7 @@ import com.google.gson.JsonObject; import com.mapbox.geocoding.v5.models.CarmenContext; import com.mapbox.geocoding.v5.models.CarmenFeature; +import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.plugins.testapp.R; import com.mapbox.plugins.places.autocomplete.PlaceAutocomplete; @@ -42,14 +43,9 @@ protected void onCreate(Bundle savedInstanceState) { } private void addUserLocations() { - CarmenContext context = CarmenContext.builder().text("300 Massachusetts Ave NW").build(); - List contextList = new ArrayList<>(); - contextList.add(context); - carmenFeatures.add(CarmenFeature.builder().text("Directions to Home") .placeName("300 Massachusetts Ave NW") .id("directions-home") - .context(contextList) .properties(new JsonObject()) .build()); @@ -63,7 +59,7 @@ private void addUserLocations() { @OnClick(R.id.fabCard) public void onOverlayFabClick(View view) { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_CARDS) - .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") + .accessToken(Mapbox.getAccessToken()) .limit(10) .backgroundColor(Color.parseColor("#EEEEEE")) .injectPlaces(carmenFeatures) From 68f92426c7621a0802c06f3d8f618b7caf01e763 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 17:57:59 -0500 Subject: [PATCH 11/25] cleaned up manifest file --- .../res/layout/activity_places_launcher.xml | 62 +++++++++---------- plugin-places/src/main/AndroidManifest.xml | 20 +++--- 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/app/src/main/res/layout/activity_places_launcher.xml b/app/src/main/res/layout/activity_places_launcher.xml index 497fe7002..51791ce11 100644 --- a/app/src/main/res/layout/activity_places_launcher.xml +++ b/app/src/main/res/layout/activity_places_launcher.xml @@ -1,41 +1,41 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="com.mapbox.mapboxsdk.plugins.testapp.activity.places.AutocompleteLauncherActivity"> + android:id="@+id/mapView" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:mapbox_cameraTargetLat="40.73581" + app:mapbox_cameraTargetLng="-73.99155" + app:mapbox_cameraZoom="11"/> + android:id="@+id/fabCard" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="end|bottom" + android:layout_marginBottom="82dp" + android:layout_marginEnd="16dp" + android:layout_marginRight="16dp" + android:src="@drawable/ic_layers" + android:tint="@android:color/white" + app:backgroundTint="@color/colorAccent" + app:layout_anchorGravity="top"/> + android:id="@+id/fabFullScreen" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="end|bottom" + android:layout_margin="16dp" + android:tint="@android:color/white" + app:backgroundTint="@color/colorPrimary" + app:srcCompat="@android:drawable/ic_search_category_default"/> diff --git a/plugin-places/src/main/AndroidManifest.xml b/plugin-places/src/main/AndroidManifest.xml index 5c7a8f406..e6a4a9999 100644 --- a/plugin-places/src/main/AndroidManifest.xml +++ b/plugin-places/src/main/AndroidManifest.xml @@ -3,20 +3,16 @@ package="com.mapbox.places"> - - + android:name="com.mapbox.plugins.places.autocomplete.PlaceCompleteCardActivity" + android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" + android:theme="@style/Theme.AppCompat.Translucent" + android:windowSoftInputMode="stateVisible|adjustPan"/> - + 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"/> - \ No newline at end of file From 5be43fe7489274b743b4df45803f2176b7db7385 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 18:40:57 -0500 Subject: [PATCH 12/25] added room schema to VCS --- plugin-places/build.gradle | 7 ++++ .../1.json | 39 +++++++++++++++++++ .../autocomplete/OnCardItemClickListener.java | 7 +++- .../PlaceCompleteCardActivity.java | 2 - .../PlaceCompleteFullActivity.java | 2 - .../autocomplete/RecentSearchAsyncTask.java | 1 - .../{views => }/ResultCardView.java | 2 +- .../autocomplete/{views => }/ResultView.java | 12 +----- .../autocomplete/SearchHistoryDatabase.java | 5 --- .../autocomplete/{views => }/SearchView.java | 2 +- .../res/layout/activity_complete_card.xml | 8 ++-- .../res/layout/activity_complete_full.xml | 4 +- 12 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{views => }/ResultCardView.java (92%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{views => }/ResultView.java (75%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{views => }/SearchView.java (98%) diff --git a/plugin-places/build.gradle b/plugin-places/build.gradle index b123e02e0..c7237bf66 100644 --- a/plugin-places/build.gradle +++ b/plugin-places/build.gradle @@ -10,6 +10,13 @@ android { targetSdkVersion androidVersions.targetSdkVersion testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true + + // Write out the current schema of Room + javaCompileOptions { + annotationProcessorOptions { + arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] + } + } } buildTypes { diff --git a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json new file mode 100644 index 000000000..de98e0659 --- /dev/null +++ b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json @@ -0,0 +1,39 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "8c7c23e0876029678043b33f10b9d681", + "entities": [ + { + "tableName": "RecentSearch", + "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, \"8c7c23e0876029678043b33f10b9d681\")" + ] + } +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java index de83274ac..3c827598e 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java @@ -2,6 +2,11 @@ import com.mapbox.geocoding.v5.models.CarmenFeature; -public interface OnCardItemClickListener { +/** + * Used internally to detect when a user has selected an item from one of the results list. + * + * @since 0.1.0 + */ +interface OnCardItemClickListener { void onItemClick(CarmenFeature carmenFeature); } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java index 08750272f..614ac217d 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java @@ -15,8 +15,6 @@ import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.geocoding.v5.models.GeocodingResponse; import com.mapbox.places.R; -import com.mapbox.plugins.places.autocomplete.views.ResultView; -import com.mapbox.plugins.places.autocomplete.views.SearchView; import com.mapbox.plugins.places.common.KeyboardUtils; import java.util.ArrayList; diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java index 8d255a330..fc8f112d1 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java @@ -10,8 +10,6 @@ import com.mapbox.geocoding.v5.MapboxGeocoding; import com.mapbox.geocoding.v5.models.GeocodingResponse; import com.mapbox.places.R; -import com.mapbox.plugins.places.autocomplete.views.ResultView; -import com.mapbox.plugins.places.autocomplete.views.SearchView; import retrofit2.Call; import retrofit2.Callback; diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java index 61f46471a..38a3c03c8 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java @@ -6,7 +6,6 @@ import android.view.View; import com.mapbox.geocoding.v5.models.CarmenFeature; -import com.mapbox.plugins.places.autocomplete.views.ResultView; import java.util.ArrayList; import java.util.List; diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultCardView.java similarity index 92% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultCardView.java index 5035886e1..2d8f8f434 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultCardView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultCardView.java @@ -1,4 +1,4 @@ -package com.mapbox.plugins.places.autocomplete.views; +package com.mapbox.plugins.places.autocomplete; import android.content.Context; import android.support.annotation.NonNull; diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultView.java similarity index 75% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultView.java index 38836c6bb..1502177b3 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/ResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultView.java @@ -1,11 +1,8 @@ -package com.mapbox.plugins.places.autocomplete.views; +package com.mapbox.plugins.places.autocomplete; import android.content.Context; -import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; @@ -13,8 +10,6 @@ import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.places.R; -import com.mapbox.plugins.places.autocomplete.OnCardItemClickListener; -import com.mapbox.plugins.places.autocomplete.SearchResultAdapter; import java.util.ArrayList; import java.util.List; @@ -68,16 +63,11 @@ public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) } private void initializeResultList() { -// Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.line_divider); -// DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), VERTICAL); -// dividerItemDecoration.setDrawable(drawable); - RecyclerView recyclerView = findViewById(R.id.rv_search_results); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setAutoMeasureEnabled(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setNestedScrollingEnabled(false); -// recyclerView.addItemDecoration(dividerItemDecoration); recyclerView.setAdapter(adapter); } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java index 12c3df2a1..76d0dfcd5 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java @@ -7,8 +7,3 @@ public abstract class SearchHistoryDatabase extends RoomDatabase { public abstract RecentSearchesDao recentSearchesDao(); } - - - - - diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchView.java similarity index 98% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchView.java index 81db8a300..b77306186 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/views/SearchView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchView.java @@ -1,4 +1,4 @@ -package com.mapbox.plugins.places.autocomplete.views; +package com.mapbox.plugins.places.autocomplete; import android.content.Context; import android.support.annotation.NonNull; diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index 4db753d65..83829cc58 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -20,7 +20,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - - - diff --git a/plugin-places/src/main/res/layout/activity_complete_full.xml b/plugin-places/src/main/res/layout/activity_complete_full.xml index 171e2ef0c..c383b6eeb 100644 --- a/plugin-places/src/main/res/layout/activity_complete_full.xml +++ b/plugin-places/src/main/res/layout/activity_complete_full.xml @@ -21,7 +21,7 @@ local:popupTheme="@style/ThemeOverlay.AppCompat.Light" local:theme="@style/ThemeOverlay.AppCompat.Light"> - - Date: Mon, 27 Nov 2017 19:51:19 -0500 Subject: [PATCH 13/25] code clean up --- .../places/AutocompleteLauncherActivity.java | 3 +- .../PlaceCompleteCardActivity.java | 11 +- .../PlaceCompleteFullActivity.java | 18 +-- .../places/autocomplete/PlaceConstants.java | 12 -- .../src/main/res/drawable/ic_place.xml | 9 ++ .../res/layout/activity_complete_card.xml | 112 ++++++++-------- .../res/layout/activity_complete_full.xml | 80 ++++++------ .../main/res/layout/item_search_result.xml | 102 +++++++-------- .../src/main/res/layout/item_user_picked.xml | 61 --------- .../src/main/res/layout/view_card_results.xml | 60 ++++----- .../src/main/res/layout/view_results.xml | 38 +++--- .../src/main/res/layout/view_search.xml | 122 +++++++++--------- .../com/mapbox/places/ExampleUnitTest.java | 17 --- 13 files changed, 273 insertions(+), 372 deletions(-) create mode 100644 plugin-places/src/main/res/drawable/ic_place.xml delete mode 100644 plugin-places/src/main/res/layout/item_user_picked.xml delete mode 100644 plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index 738407dbe..b513cb7d8 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -77,7 +77,8 @@ public boolean onOverlayFabLongClick(View view) { @OnClick(R.id.fabFullScreen) public void onFullScreenFabClick(View view) { Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) - .limit(2) + .accessToken(Mapbox.getAccessToken()) + .injectPlaces(carmenFeatures) .backgroundColor(Color.WHITE) .build(AutocompleteLauncherActivity.this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java index 614ac217d..a8e142921 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java @@ -27,6 +27,7 @@ import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; + public class PlaceCompleteCardActivity extends AppCompatActivity implements SearchView.QueryListener, Callback, SearchView.BackButtonListener, ViewTreeObserver.OnScrollChangedListener, OnCardItemClickListener { @@ -100,13 +101,9 @@ public void onScrollChanged() { if (resultScrollView.getScrollY() != 0) { KeyboardUtils.hideKeyboard(resultScrollView); } - if (resultScrollView.canScrollVertically(-1)) { - dropShadow.setVisibility(VISIBLE); - // Show elevation - } else { - dropShadow.setVisibility(INVISIBLE); - // Remove elevation - } + dropShadow.setVisibility( + resultScrollView.canScrollVertically(-1) ? VISIBLE : INVISIBLE + ); } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java index fc8f112d1..f96b49b46 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java @@ -30,11 +30,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { Intent intent = getIntent(); - // TODO Theming occurs here - rootView.setBackgroundColor(intent.getIntExtra("backgroundColor", Color.TRANSPARENT)); + rootView.setBackgroundColor(intent.getIntExtra(PlaceConstants.BACKGROUND, Color.TRANSPARENT)); - geocoderBuilder = geocoderBuilder(); - geocoderBuilder.limit(intent.getIntExtra("limit", 5)); + geocoderBuilder = Utils.initiateSearchQuery(intent); searchResultView = findViewById(R.id.searchResultView); SearchView searchView = findViewById(R.id.searchView); @@ -42,12 +40,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { searchView.setQueryListener(this); } - private MapboxGeocoding.Builder geocoderBuilder() { - return MapboxGeocoding.builder() - .accessToken("pk.eyJ1IjoiY2FtbWFjZSIsImEiOiI5OGQxZjRmZGQ2YjU3Mzk1YjJmZTQ5ZDY2MTg1NDJiOCJ9.hIFoCKGAGOwQkKyVPvrxvQ") - .autocomplete(true); - } - @Override public void onQueryChange(CharSequence charSequence) { String query = charSequence.toString(); @@ -63,12 +55,6 @@ public void onQueryChange(CharSequence charSequence) { private void bindViews() { rootView = findViewById(R.id.root_layout); searchResultView = findViewById(R.id.searchResultView); - - -// resultScrollView = findViewById(R.id.scroll_view_results); -// recentSearchResults = findViewById(R.id.recentSearchResults); -// starredView = findViewById(R.id.starredView); -// searchView = findViewById(R.id.searchView); } @Override diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java index d5180031f..648ffae9b 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java @@ -6,28 +6,16 @@ private PlaceConstants() { } static final String RETURNING_CARMEN_FEATURE = "carmenFeature"; - static final String SEARCH_HISTORY_DATABASE_NAME = "mb-places-search-history-db"; - static final String ACCESS_TOKEN = "mb-places-accessToken"; - static final String BBOX_SOUTHWEST_POINT = "mb-places-bbox-southwestPoint"; - static final String BBOX_NORTHEAST_POINT = "mb-places-bbox-northeastPoint"; - static final String COUNTRIES = "mb-places-countries"; - static final String PROXIMITY = "mb-places-proximity"; - static final String TYPE = "mb-places-types"; - static final String LANGUAGE = "mb-places-language"; - static final String LIMIT = "mb-places-limit"; - static final String INJECTED_PLACES = "mb-places-injectPlaces"; - static final String BACKGROUND = "mb-places-backgroundColor"; - static final String SAVED_PLACE = "saved-carmen-feature"; } diff --git a/plugin-places/src/main/res/drawable/ic_place.xml b/plugin-places/src/main/res/drawable/ic_place.xml new file mode 100644 index 000000000..e3291a943 --- /dev/null +++ b/plugin-places/src/main/res/drawable/ic_place.xml @@ -0,0 +1,9 @@ + + + diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index 83829cc58..3d99d8409 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -1,80 +1,80 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/root_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/transparent"> + android:id="@+id/cardView" + android:layout_width="0dp" + android:layout_height="56dp" + android:layout_margin="8dp" + app:cardBackgroundColor="@color/cardview_light_background" + app:cardCornerRadius="8dp" + app:cardElevation="2dp" + app:cardUseCompatPadding="true" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:id="@+id/searchView" + android:layout_width="match_parent" + android:layout_height="42dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"/> + android:id="@+id/scroll_drop_shadow" + android:layout_width="match_parent" + android:layout_height="2dp" + android:background="@drawable/scroll_shadow" + android:visibility="invisible" + app:layout_constraintTop_toBottomOf="@+id/cardView"/> + + - + android:visibility="gone"/> - - + android:id="@+id/recentSearchResults" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone"/> + android:id="@+id/starredView" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> diff --git a/plugin-places/src/main/res/layout/activity_complete_full.xml b/plugin-places/src/main/res/layout/activity_complete_full.xml index c383b6eeb..4a74042ed 100644 --- a/plugin-places/src/main/res/layout/activity_complete_full.xml +++ b/plugin-places/src/main/res/layout/activity_complete_full.xml @@ -1,56 +1,56 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:local="http://schemas.android.com/tools" + android:id="@+id/root_layout" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"/> + + - - + app:layout_constraintTop_toTopOf="parent"/> \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/item_search_result.xml b/plugin-places/src/main/res/layout/item_search_result.xml index 894d7ac57..f01c0d62a 100644 --- a/plugin-places/src/main/res/layout/item_search_result.xml +++ b/plugin-places/src/main/res/layout/item_search_result.xml @@ -1,63 +1,61 @@ - + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="60dp" + android:background="@color/cardview_light_background"> - + android:layout_width="24dp" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp" + android:layout_marginLeft="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="8dp" + android:tint="@color/lightNavy" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_place"/> + android:id="@+id/tv_address" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginBottom="4dp" + android:layout_marginEnd="16dp" + android:layout_marginLeft="64dp" + android:layout_marginRight="16dp" + android:layout_marginStart="64dp" + android:maxLines="1" + android:textColor="@color/lightNavy" + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/tv_place_name" + tools:text="1600 Pennsylvania Ave NW, Washington, DC 20500"/> + android:id="@+id/tv_place_name" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="16dp" + android:layout_marginLeft="64dp" + android:layout_marginRight="16dp" + android:layout_marginStart="64dp" + android:layout_marginTop="8dp" + android:maxLines="1" + android:textColor="@color/navy" + android:textSize="16sp" + app:layout_constraintBottom_toTopOf="@+id/tv_address" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="The White House"/> diff --git a/plugin-places/src/main/res/layout/item_user_picked.xml b/plugin-places/src/main/res/layout/item_user_picked.xml deleted file mode 100644 index 0e4a0512b..000000000 --- a/plugin-places/src/main/res/layout/item_user_picked.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - diff --git a/plugin-places/src/main/res/layout/view_card_results.xml b/plugin-places/src/main/res/layout/view_card_results.xml index 79fc7499a..fa2b26f3c 100644 --- a/plugin-places/src/main/res/layout/view_card_results.xml +++ b/plugin-places/src/main/res/layout/view_card_results.xml @@ -1,39 +1,39 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/linearLayout" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + app:cardBackgroundColor="@color/cardview_light_background" + app:cardCornerRadius="8dp" + app:cardElevation="2dp" + app:cardPreventCornerOverlap="true" + app:cardUseCompatPadding="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.5" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintVertical_bias="0.0" + tools:layout_conversion_absoluteHeight="551dp" + tools:layout_conversion_absoluteWidth="108dp"> + layout="@layout/view_results" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:layout_conversion_absoluteHeight="540dp" + tools:layout_conversion_absoluteWidth="99dp" + tools:layout_editor_absoluteX="5dp" + tools:layout_editor_absoluteY="6dp"/> diff --git a/plugin-places/src/main/res/layout/view_results.xml b/plugin-places/src/main/res/layout/view_results.xml index 42c60a9fe..ae24a6f68 100644 --- a/plugin-places/src/main/res/layout/view_results.xml +++ b/plugin-places/src/main/res/layout/view_results.xml @@ -1,26 +1,26 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + android:id="@+id/rv_search_results" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/cardview_light_background" + android:clipChildren="true" + android:clipToPadding="true" + android:overScrollMode="never" + android:scrollbars="none" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintStart_toStartOf="parent" + tools:listitem="@layout/item_search_result"> diff --git a/plugin-places/src/main/res/layout/view_search.xml b/plugin-places/src/main/res/layout/view_search.xml index 5d7bc8a18..377b0c193 100644 --- a/plugin-places/src/main/res/layout/view_search.xml +++ b/plugin-places/src/main/res/layout/view_search.xml @@ -1,70 +1,70 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + android:id="@+id/button_search_clear" + android:layout_width="24dp" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="8dp" + android:background="@android:color/transparent" + android:contentDescription="@string/cd_search_clear_button" + android:visibility="invisible" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_clear"/> + android:id="@+id/edittext_search" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp" + android:layout_marginEnd="8dp" + android:layout_marginLeft="62dp" + android:layout_marginRight="8dp" + android:layout_marginStart="62dp" + android:layout_marginTop="8dp" + android:background="@null" + android:cursorVisible="true" + android:ems="10" + android:focusable="true" + android:focusableInTouchMode="true" + android:hint="@string/autocomplete_search_hint" + android:imeOptions="actionSearch|flagNoExtractUi" + android:inputType="textNoSuggestions" + android:singleLine="true" + android:textColor="@color/navy" + android:textColorHint="@color/lightNavy" + android:textColorLink="@color/navy" + android:textCursorDrawable="@drawable/color_text_cursor" + android:textSize="16sp" + android:typeface="sans" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/button_search_clear" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"/> + android:id="@+id/button_search_back" + android:layout_width="24dp" + android:layout_height="24dp" + android:layout_marginBottom="8dp" + android:layout_marginLeft="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="8dp" + android:background="@android:color/transparent" + android:contentDescription="@string/cd_search_back_button" + android:focusable="true" + android:tint="@color/navy" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_arrow_back"/> \ No newline at end of file diff --git a/plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java b/plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java deleted file mode 100644 index 8113bfcb9..000000000 --- a/plugin-places/src/test/java/com/mapbox/places/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.mapbox.places; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file From b0843b4e3a6d21848e38a546700439ddcb8c8430 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 22:20:51 -0500 Subject: [PATCH 14/25] Added missing files --- Makefile | 5 ++++ plugin-places/CHANGELOG.md | 6 ++++ plugin-places/gradle.properties | 5 ++++ plugin-places/javadoc.gradle | 17 +++++++++++ .../places/autocomplete/PlaceConstants.java | 28 ++++++++++--------- 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 plugin-places/CHANGELOG.md create mode 100644 plugin-places/gradle.properties create mode 100644 plugin-places/javadoc.gradle diff --git a/Makefile b/Makefile index 1e7d931ac..65a1c667c 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ test: ./gradlew :plugin-locationlayer:test ./gradlew :plugin-building:test ./gradlew :plugin-cluster:test + ./gradlew :plugin-places:test build-release: ./gradlew :plugin-geojson:assembleRelease @@ -14,6 +15,7 @@ build-release: ./gradlew :plugin-locationlayer:assembleRelease ./gradlew :plugin-building:assembleRelease ./gradlew :plugin-cluster:assembleRelease + ./gradlew :plugin-places:assembleRelease javadoc: # Android modules @@ -23,6 +25,7 @@ javadoc: ./gradlew :plugin-locationlayer:javadocrelease ./gradlew :plugin-building:javadocrelease ./gradlew :plugin-cluster:javadocrelease + ./gradlew :plugin-places:javadocrelease publish: export IS_LOCAL_DEVELOPMENT=false; ./gradlew :plugin-geojson:uploadArchives @@ -30,6 +33,7 @@ publish: export IS_LOCAL_DEVELOPMENT=false; ./gradlew :plugin-locationlayer:uploadArchives export IS_LOCAL_DEVELOPMENT=false; ./gradlew :plugin-building:uploadArchives export IS_LOCAL_DEVELOPMENT=false; ./gradlew :plugin-cluster:uploadArchives + export IS_LOCAL_DEVELOPMENT=false; ./gradlew :plugin-places:uploadArchives publish-local: # This publishes to ~/.m2/repository/com/mapbox/mapboxsdk @@ -38,3 +42,4 @@ publish-local: export IS_LOCAL_DEVELOPMENT=true; ./gradlew :plugin-locationlayer:uploadArchives export IS_LOCAL_DEVELOPMENT=true; ./gradlew :plugin-building:uploadArchives export IS_LOCAL_DEVELOPMENT=true; ./gradlew :plugin-cluster:uploadArchives + export IS_LOCAL_DEVELOPMENT=true; ./gradlew :plugin-places:uploadArchives diff --git a/plugin-places/CHANGELOG.md b/plugin-places/CHANGELOG.md new file mode 100644 index 000000000..a2dc57110 --- /dev/null +++ b/plugin-places/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog for the Mapbox Places Plugin + +Mapbox welcomes participation and contributions from everyone. + +### 0.1.0 - TBD +- Initial release as a standalone package. \ No newline at end of file diff --git a/plugin-places/gradle.properties b/plugin-places/gradle.properties new file mode 100644 index 000000000..655394649 --- /dev/null +++ b/plugin-places/gradle.properties @@ -0,0 +1,5 @@ +VERSION_NAME=0.1.0-SNAPSHOT +POM_ARTIFACT_ID=mapbox-android-plugin-places +POM_NAME=Mapbox Android Places Plugin +POM_DESCRIPTION=Mapbox Android Places Plugin +POM_PACKAGING=aar \ No newline at end of file diff --git a/plugin-places/javadoc.gradle b/plugin-places/javadoc.gradle new file mode 100644 index 000000000..2f1f1e721 --- /dev/null +++ b/plugin-places/javadoc.gradle @@ -0,0 +1,17 @@ +android.libraryVariants.all { variant -> + def name = variant.name + task "javadoc$name"(type: Javadoc) { + description = "Generates javadoc for build $name" + failOnError = false + destinationDir = new File(destinationDir, variant.baseName) + source = files(variant.javaCompile.source) + classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath) + configurations.javadocDeps + options.windowTitle("Mapbox Android Places Plugin $VERSION_NAME Reference") + options.docTitle("Mapbox Android Places Plugin $VERSION_NAME") + options.header("Mapbox Android Places Plugin $VERSION_NAME Reference") + options.bottom("© 2017 Mapbox. All rights reserved.") + options.links("http://docs.oracle.com/javase/7/docs/api/") + options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference") + exclude '**/R.java', '**/BuildConfig.java' + } +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java index 648ffae9b..066964aa5 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java @@ -5,17 +5,19 @@ final class PlaceConstants { private PlaceConstants() { } - static final String RETURNING_CARMEN_FEATURE = "carmenFeature"; - static final String SEARCH_HISTORY_DATABASE_NAME = "mb-places-search-history-db"; - static final String ACCESS_TOKEN = "mb-places-accessToken"; - static final String BBOX_SOUTHWEST_POINT = "mb-places-bbox-southwestPoint"; - static final String BBOX_NORTHEAST_POINT = "mb-places-bbox-northeastPoint"; - static final String COUNTRIES = "mb-places-countries"; - static final String PROXIMITY = "mb-places-proximity"; - static final String TYPE = "mb-places-types"; - static final String LANGUAGE = "mb-places-language"; - static final String LIMIT = "mb-places-limit"; - static final String INJECTED_PLACES = "mb-places-injectPlaces"; - static final String BACKGROUND = "mb-places-backgroundColor"; - static final String SAVED_PLACE = "saved-carmen-feature"; + static final String RETURNING_CARMEN_FEATURE = "com.mapbox.mapboxsdk.plugins.places.carmenfeat"; + static final String SEARCH_HISTORY_DATABASE_NAME = "com.mapbox.mapboxsdk.plugins.places.database"; + static final String ACCESS_TOKEN = "com.mapbox.mapboxsdk.plugins.places.accessToken"; + static final String BBOX_SOUTHWEST_POINT + = "com.mapbox.mapboxsdk.plugins.places.bbox.southwestPoint"; + static final String BBOX_NORTHEAST_POINT + = "com.mapbox.mapboxsdk.plugins.places.bbox.northeastPoint"; + static final String COUNTRIES = "com.mapbox.mapboxsdk.plugins.places.countries"; + static final String PROXIMITY = "com.mapbox.mapboxsdk.plugins.places.proximity"; + static final String TYPE = "com.mapbox.mapboxsdk.plugins.places.types"; + static final String LANGUAGE = "com.mapbox.mapboxsdk.plugins.places.language"; + static final String LIMIT = "com.mapbox.mapboxsdk.plugins.places.limit"; + static final String INJECTED_PLACES = "com.mapbox.mapboxsdk.plugins.places.injectPlaces"; + static final String BACKGROUND = "com.mapbox.mapboxsdk.plugins.places.backgroundColor"; + static final String SAVED_PLACE = "com.mapbox.mapboxsdk.plugins.places.savedcarmenfeat"; } From 6a9c9160103a677768fc8ea01472e24c5de18d4b Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 27 Nov 2017 22:58:58 -0500 Subject: [PATCH 15/25] Fixed search view margins --- .../src/main/res/layout/activity_complete_card.xml | 7 ++++--- plugin-places/src/main/res/layout/view_card_results.xml | 3 --- plugin-places/src/main/res/layout/view_search.xml | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index 3d99d8409..f82f6c6f2 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -10,8 +10,7 @@ diff --git a/plugin-places/src/main/res/layout/view_card_results.xml b/plugin-places/src/main/res/layout/view_card_results.xml index fa2b26f3c..10585aac7 100644 --- a/plugin-places/src/main/res/layout/view_card_results.xml +++ b/plugin-places/src/main/res/layout/view_card_results.xml @@ -11,8 +11,6 @@ diff --git a/plugin-places/src/main/res/layout/view_search.xml b/plugin-places/src/main/res/layout/view_search.xml index 377b0c193..de8826917 100644 --- a/plugin-places/src/main/res/layout/view_search.xml +++ b/plugin-places/src/main/res/layout/view_search.xml @@ -10,8 +10,7 @@ android:layout_width="24dp" android:layout_height="wrap_content" android:layout_marginBottom="8dp" - android:layout_marginEnd="8dp" - android:layout_marginRight="8dp" + android:layout_marginEnd="16dp" android:layout_marginTop="8dp" android:background="@android:color/transparent" android:contentDescription="@string/cd_search_clear_button" From 9a528d208bd3b644c640f6b641ad5a36e23ce92b Mon Sep 17 00:00:00 2001 From: Langston Smith Date: Tue, 28 Nov 2017 16:51:59 -0800 Subject: [PATCH 16/25] checkstyle --- .../testapp/activity/places/AutocompleteLauncherActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index b513cb7d8..d8f0d528f 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -9,7 +9,6 @@ import android.widget.Toast; import com.google.gson.JsonObject; -import com.mapbox.geocoding.v5.models.CarmenContext; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.maps.MapView; From c2058f5e3dbacd3e94f59ce78efeed392b6a2007 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Wed, 29 Nov 2017 19:41:00 -0500 Subject: [PATCH 17/25] Introduce more android arch component --- app/build.gradle | 2 + gradle/dependencies.gradle | 6 +- plugin-places/build.gradle | 2 + .../1.json | 39 ++++ .../2.json | 39 ++++ plugin-places/src/main/AndroidManifest.xml | 7 +- .../places/autocomplete/DataRepository.java | 49 +++++ .../autocomplete/OnCardItemClickListener.java | 12 -- .../autocomplete/PlaceAutocomplete.java | 16 +- .../PlaceCompleteCardActivity.java | 169 ----------------- .../PlaceCompleteFullActivity.java | 86 --------- .../places/autocomplete/PlaceConstants.java | 28 +-- .../autocomplete/RecentSearchAsyncTask.java | 71 ------- .../autocomplete/RecentSearchesDao.java | 26 --- .../autocomplete/SearchHistoryDatabase.java | 9 - .../data/SearchHistoryDatabase.java | 89 +++++++++ .../converter/CarmenFeatureConverter.java | 19 ++ .../data/dao/SearchHistoryDao.java | 34 ++++ .../entity/SearchHistoryEntity.java} | 19 +- .../autocomplete/model/SearchHistory.java | 9 + .../ui/PlaceAutocompleteActivity.java | 175 ++++++++++++++++++ .../autocomplete/{ => ui}/ResultCardView.java | 2 +- .../autocomplete/ui/ResultClickCallback.java | 7 + .../autocomplete/{ => ui}/ResultView.java | 4 +- .../{ => ui}/SearchResultAdapter.java | 21 ++- .../autocomplete/{ => ui}/SearchView.java | 28 +-- .../autocomplete/{ => utils}/Utils.java | 6 +- .../viewmodel/PlaceAutocompleteViewModel.java | 117 ++++++++++++ .../res/layout/activity_complete_card.xml | 12 +- .../res/layout/activity_complete_full.xml | 58 ++++-- .../main/res/layout/item_search_result.xml | 4 +- 31 files changed, 711 insertions(+), 454 deletions(-) create mode 100644 plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/1.json create mode 100644 plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{RecentSearch.java => data/entity/SearchHistoryEntity.java} (52%) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/SearchHistory.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => ui}/ResultCardView.java (93%) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultClickCallback.java rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => ui}/ResultView.java (93%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => ui}/SearchResultAdapter.java (79%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => ui}/SearchView.java (83%) rename plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/{ => utils}/Utils.java (87%) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java diff --git a/app/build.gradle b/app/build.gradle index b098b26e9..1211138a7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,8 @@ dependencies { implementation dependenciesList.mapboxMapSdk implementation dependenciesList.mapboxServices + implementation dependenciesList.lifecycleExtensions + // Support libraries implementation dependenciesList.supportAnnotation implementation dependenciesList.supportAppcompatV7 diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index a81172e72..ddc54b6f7 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -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' ] @@ -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}", @@ -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}", diff --git a/plugin-places/build.gradle b/plugin-places/build.gradle index c7237bf66..66845dc8c 100644 --- a/plugin-places/build.gradle +++ b/plugin-places/build.gradle @@ -40,6 +40,7 @@ dependencies { implementation dependenciesList.supportRecyclerView implementation dependenciesList.supportV4 + implementation dependenciesList.lifecycleExtensions implementation dependenciesList.roomRuntime annotationProcessor dependenciesList.roomCompiler @@ -48,6 +49,7 @@ dependencies { // Unit testing testImplementation dependenciesList.junit testImplementation dependenciesList.mockito + testImplementation dependenciesList.androidArchCore javadocDeps dependenciesList.mapboxMapSdk } \ No newline at end of file diff --git a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/1.json b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/1.json new file mode 100644 index 000000000..7339fcd5c --- /dev/null +++ b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/1.json @@ -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\")" + ] + } +} \ No newline at end of file diff --git a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json new file mode 100644 index 000000000..995743fee --- /dev/null +++ b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json @@ -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\")" + ] + } +} \ No newline at end of file diff --git a/plugin-places/src/main/AndroidManifest.xml b/plugin-places/src/main/AndroidManifest.xml index e6a4a9999..3b5fffaf2 100644 --- a/plugin-places/src/main/AndroidManifest.xml +++ b/plugin-places/src/main/AndroidManifest.xml @@ -4,15 +4,10 @@ - \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java new file mode 100644 index 000000000..8f9ed4cc4 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java @@ -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> observableSearchHistory; + + private DataRepository(final SearchHistoryDatabase database) { + this.database = database; + observableSearchHistory = new MediatorLiveData<>(); + + observableSearchHistory.addSource(database.searchHistoryDao().getAll(), + new Observer>() { + @Override + public void onChanged(@Nullable List 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> getSearchHistory() { + return observableSearchHistory; + } + + public void addSearchHistoryEntity(SearchHistoryEntity searchHistory) { + SearchHistoryDatabase.insertData(database, searchHistory); + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java deleted file mode 100644 index 3c827598e..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/OnCardItemClickListener.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - -import com.mapbox.geocoding.v5.models.CarmenFeature; - -/** - * Used internally to detect when a user has selected an item from one of the results list. - * - * @since 0.1.0 - */ -interface OnCardItemClickListener { - void onItemClick(CarmenFeature carmenFeature); -} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index 1112a9e0f..fcf81d0fe 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -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; @@ -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(); } /** @@ -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; } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java deleted file mode 100644 index a8e142921..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteCardActivity.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - -import android.arch.persistence.room.Room; -import android.content.Intent; -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.view.ViewTreeObserver; -import android.widget.ScrollView; - -import com.mapbox.geocoding.v5.MapboxGeocoding; -import com.mapbox.geocoding.v5.models.CarmenFeature; -import com.mapbox.geocoding.v5.models.GeocodingResponse; -import com.mapbox.places.R; -import com.mapbox.plugins.places.common.KeyboardUtils; - -import java.util.ArrayList; -import java.util.List; - -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; - -import static android.view.View.INVISIBLE; -import static android.view.View.VISIBLE; - - -public class PlaceCompleteCardActivity extends AppCompatActivity implements - SearchView.QueryListener, Callback, SearchView.BackButtonListener, - ViewTreeObserver.OnScrollChangedListener, OnCardItemClickListener { - - private MapboxGeocoding.Builder geocoderBuilder; - private ResultView searchResultView; - private ResultView starredView; - private ResultView recentSearchResults; - private ScrollView resultScrollView; - private SearchView searchView; - private SearchHistoryDatabase database; - private View rootView; - private View dropShadow; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_complete_card); - bindViews(); - bindClickListeners(); - - Intent intent = getIntent(); - - // Theme settings - rootView.setBackgroundColor(intent.getIntExtra(PlaceConstants.BACKGROUND, Color.TRANSPARENT)); - - fillFavoritePlacesList(intent); - geocoderBuilder = Utils.initiateSearchQuery(intent); - - // Get and populate the recent history list - database = Room.databaseBuilder(getApplicationContext(), - SearchHistoryDatabase.class, PlaceConstants.SEARCH_HISTORY_DATABASE_NAME).build(); - new RecentSearchAsyncTask(database, recentSearchResults).execute(); - - resultScrollView.getViewTreeObserver().addOnScrollChangedListener(this); - } - - private void fillFavoritePlacesList(@NonNull Intent intent) { - List serialized = intent.getStringArrayListExtra(PlaceConstants.INJECTED_PLACES); - if (serialized == null || serialized.isEmpty()) { - return; - } - List starredFeatures = new ArrayList<>(); - for (String serializedCarmenFeature : serialized) { - starredFeatures.add(CarmenFeature.fromJson(serializedCarmenFeature)); - } - starredView.getResultsList().addAll(starredFeatures); - } - - private void bindClickListeners() { - recentSearchResults.setOnItemClickListener(this); - searchResultView.setOnItemClickListener(this); - starredView.setOnItemClickListener(this); - searchView.setBackButtonListener(this); - searchView.setQueryListener(this); - } - - private void bindViews() { - rootView = findViewById(R.id.root_layout); - searchResultView = findViewById(R.id.searchResultView); - resultScrollView = findViewById(R.id.scroll_view_results); - recentSearchResults = findViewById(R.id.recentSearchResults); - starredView = findViewById(R.id.starredView); - searchView = findViewById(R.id.searchView); - dropShadow = findViewById(R.id.scroll_drop_shadow); - } - - @Override - public void onScrollChanged() { - if (resultScrollView != null) { - if (resultScrollView.getScrollY() != 0) { - KeyboardUtils.hideKeyboard(resultScrollView); - } - dropShadow.setVisibility( - resultScrollView.canScrollVertically(-1) ? VISIBLE : INVISIBLE - ); - } - } - - @Override - public void onQueryChange(CharSequence charSequence) { - String query = charSequence.toString(); - if (query.isEmpty()) { - searchResultView.getResultsList().clear(); - searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : VISIBLE); - searchResultView.notifyDataSetChanged(); - return; - } - geocoderBuilder.query(query) - .build().enqueueCall(this); - } - - @Override - public void onResponse(Call call, Response response) { - if (response.isSuccessful()) { - searchResultView.getResultsList().clear(); - searchResultView.getResultsList().addAll(response.body().features()); - searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? View.GONE : VISIBLE); - searchResultView.notifyDataSetChanged(); - } - } - - @Override - public void onFailure(Call call, Throwable throwable) { - - } - - @Override - public void onItemClick(CarmenFeature carmenFeature) { - String json = carmenFeature.toJson(); - if (!carmenFeature.properties().has(PlaceConstants.SAVED_PLACE)) { - RecentSearch recentSearch = new RecentSearch(carmenFeature.id(), json); - new RecentSearchAsyncTask(database, recentSearch).execute(); - } - - Intent intent = new Intent(); - intent.putExtra(PlaceConstants.RETURNING_CARMEN_FEATURE, json); - setResult(AppCompatActivity.RESULT_OK, intent); - finish(); - } - - @Override - protected void onDestroy() { - if (searchView != null) { - searchView.removeBackButtonListener(); - searchView.removeQueryListener(); - } - if (resultScrollView != null) { - resultScrollView.getViewTreeObserver().removeOnScrollChangedListener(this); - } - super.onDestroy(); - } - - @Override - public void onBackButtonPress() { - setResult(AppCompatActivity.RESULT_CANCELED); - finish(); - } -} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java deleted file mode 100644 index f96b49b46..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceCompleteFullActivity.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - -import android.content.Intent; -import android.graphics.Color; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.view.View; - -import com.mapbox.geocoding.v5.MapboxGeocoding; -import com.mapbox.geocoding.v5.models.GeocodingResponse; -import com.mapbox.places.R; - -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; - -public class PlaceCompleteFullActivity extends AppCompatActivity implements - SearchView.QueryListener, Callback, SearchView.BackButtonListener { - - private MapboxGeocoding.Builder geocoderBuilder; - private ResultView searchResultView; - private View rootView; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_complete_full); - bindViews(); - - Intent intent = getIntent(); - - rootView.setBackgroundColor(intent.getIntExtra(PlaceConstants.BACKGROUND, Color.TRANSPARENT)); - - geocoderBuilder = Utils.initiateSearchQuery(intent); - searchResultView = findViewById(R.id.searchResultView); - - SearchView searchView = findViewById(R.id.searchView); - searchView.setBackButtonListener(this); - searchView.setQueryListener(this); - } - - @Override - public void onQueryChange(CharSequence charSequence) { - String query = charSequence.toString(); - if (query.isEmpty()) { - searchResultView.getResultsList().clear(); - searchResultView.notifyDataSetChanged(); - return; - } - geocoderBuilder.query(query) - .build().enqueueCall(this); - } - - private void bindViews() { - rootView = findViewById(R.id.root_layout); - searchResultView = findViewById(R.id.searchResultView); - } - - @Override - public void onResponse(Call call, Response response) { - if (response.isSuccessful()) { - searchResultView.getResultsList().clear(); - searchResultView.getResultsList().addAll(response.body().features()); - searchResultView.notifyDataSetChanged(); - } - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - - - @Override - protected void onDestroy() { -// searchBar.removeBackButtonListener(); -// searchBar.removeQueryListener(); - super.onDestroy(); - } - - @Override - public void onBackButtonPress() { - finish(); - } -} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java index 066964aa5..3ec847fb6 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java @@ -1,23 +1,23 @@ package com.mapbox.plugins.places.autocomplete; -final class PlaceConstants { +public final class PlaceConstants { private PlaceConstants() { } - static final String RETURNING_CARMEN_FEATURE = "com.mapbox.mapboxsdk.plugins.places.carmenfeat"; - static final String SEARCH_HISTORY_DATABASE_NAME = "com.mapbox.mapboxsdk.plugins.places.database"; - static final String ACCESS_TOKEN = "com.mapbox.mapboxsdk.plugins.places.accessToken"; - static final String BBOX_SOUTHWEST_POINT + public static final String RETURNING_CARMEN_FEATURE = "com.mapbox.mapboxsdk.plugins.places.carmenfeat"; + public static final String ACCESS_TOKEN = "com.mapbox.mapboxsdk.plugins.places.accessToken"; + public static final String BBOX_SOUTHWEST_POINT = "com.mapbox.mapboxsdk.plugins.places.bbox.southwestPoint"; - static final String BBOX_NORTHEAST_POINT + public static final String BBOX_NORTHEAST_POINT = "com.mapbox.mapboxsdk.plugins.places.bbox.northeastPoint"; - static final String COUNTRIES = "com.mapbox.mapboxsdk.plugins.places.countries"; - static final String PROXIMITY = "com.mapbox.mapboxsdk.plugins.places.proximity"; - static final String TYPE = "com.mapbox.mapboxsdk.plugins.places.types"; - static final String LANGUAGE = "com.mapbox.mapboxsdk.plugins.places.language"; - static final String LIMIT = "com.mapbox.mapboxsdk.plugins.places.limit"; - static final String INJECTED_PLACES = "com.mapbox.mapboxsdk.plugins.places.injectPlaces"; - static final String BACKGROUND = "com.mapbox.mapboxsdk.plugins.places.backgroundColor"; - static final String SAVED_PLACE = "com.mapbox.mapboxsdk.plugins.places.savedcarmenfeat"; + public static final String COUNTRIES = "com.mapbox.mapboxsdk.plugins.places.countries"; + public static final String PROXIMITY = "com.mapbox.mapboxsdk.plugins.places.proximity"; + public static final String TYPE = "com.mapbox.mapboxsdk.plugins.places.types"; + public static final String LANGUAGE = "com.mapbox.mapboxsdk.plugins.places.language"; + public static final String LIMIT = "com.mapbox.mapboxsdk.plugins.places.limit"; + public static final String INJECTED_PLACES = "com.mapbox.mapboxsdk.plugins.places.injectPlaces"; + public static final String BACKGROUND = "com.mapbox.mapboxsdk.plugins.places.backgroundColor"; + public static final String SAVED_PLACE = "com.mapbox.mapboxsdk.plugins.places.savedcarmenfeat"; + public static final String MODE = "com.mapbox.mapboxsdk.plugins.places.mode"; } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java deleted file mode 100644 index 38a3c03c8..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchAsyncTask.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - -import android.os.AsyncTask; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.View; - -import com.mapbox.geocoding.v5.models.CarmenFeature; - -import java.util.ArrayList; -import java.util.List; - -class RecentSearchAsyncTask extends AsyncTask { - - private final SearchHistoryDatabase database; - private List carmenFeatures = new ArrayList<>(); - private ResultView recentSearchResults; - private RecentSearch recentSearch; - - RecentSearchAsyncTask(@NonNull SearchHistoryDatabase database) { - this.database = database; - } - - RecentSearchAsyncTask(@NonNull SearchHistoryDatabase database, - @Nullable ResultView recentSearchResults) { - this.database = database; - this.recentSearchResults = recentSearchResults; - } - - RecentSearchAsyncTask(@NonNull SearchHistoryDatabase database, - @Nullable RecentSearch recentSearch) { - this.database = database; - this.recentSearch = recentSearch; - } - - @Override - protected Void doInBackground(Void... voids) { - - if (recentSearchResults != null) { - for (RecentSearch recentSearch : database.recentSearchesDao().getAll()) { - CarmenFeature carmenFeature = CarmenFeature.fromJson(recentSearch.getCarmenFeature()); - carmenFeatures.add(carmenFeature); - } - } else if (recentSearch != null) { - RecentSearch sameRecentSearch = database.recentSearchesDao() - .findByCarmenFeature(recentSearch.getPlaceId()); - if (sameRecentSearch != null) { - return null; - } - - database.recentSearchesDao().insertAll(recentSearch); - } else { - for (RecentSearch recentSearch : database.recentSearchesDao().getAll()) { - database.recentSearchesDao().delete(recentSearch); - } - } - - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (recentSearchResults != null) { - recentSearchResults.getResultsList().addAll(carmenFeatures); - if (!carmenFeatures.isEmpty()) { - recentSearchResults.setVisibility(View.VISIBLE); - } - } - } -} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java deleted file mode 100644 index fa3875d69..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearchesDao.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - -import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Delete; -import android.arch.persistence.room.Insert; -import android.arch.persistence.room.Query; - -import java.util.List; - -@Dao -public interface RecentSearchesDao { - @Query("SELECT * FROM recentsearch") - List getAll(); - - @Query("SELECT * FROM recentsearch WHERE placeId IN (:placeIds)") - List loadAllByIds(String[] placeIds); - - @Query("SELECT * FROM recentsearch WHERE placeId IN (:placeId)") - RecentSearch findByCarmenFeature(String placeId); - - @Insert - void insertAll(RecentSearch... recentSearch); - - @Delete - void delete(RecentSearch recentSearch); -} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java deleted file mode 100644 index 76d0dfcd5..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchHistoryDatabase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mapbox.plugins.places.autocomplete; - -import android.arch.persistence.room.Database; -import android.arch.persistence.room.RoomDatabase; - -@Database(entities = {RecentSearch.class}, version = 1) -public abstract class SearchHistoryDatabase extends RoomDatabase { - public abstract RecentSearchesDao recentSearchesDao(); -} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java new file mode 100644 index 000000000..97b3b3515 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java @@ -0,0 +1,89 @@ +package com.mapbox.plugins.places.autocomplete.data; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.MutableLiveData; +import android.arch.persistence.db.SupportSQLiteDatabase; +import android.arch.persistence.room.Database; +import android.arch.persistence.room.Room; +import android.arch.persistence.room.RoomDatabase; +import android.arch.persistence.room.TypeConverters; +import android.content.Context; +import android.os.AsyncTask; +import android.support.annotation.NonNull; + +import com.mapbox.plugins.places.autocomplete.data.converter.CarmenFeatureConverter; +import com.mapbox.plugins.places.autocomplete.data.dao.SearchHistoryDao; +import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity; + +@Database(entities = {SearchHistoryEntity.class}, version = 2) +@TypeConverters(CarmenFeatureConverter.class) +public abstract class SearchHistoryDatabase extends RoomDatabase { + + private static final String DATABASE_NAME = "com.mapbox.mapboxsdk.plugins.places.database"; + private static SearchHistoryDatabase instance; + + public abstract SearchHistoryDao searchHistoryDao(); + + private final MutableLiveData isDatabaseCreated = new MutableLiveData<>(); + + public static SearchHistoryDatabase getInstance(final Context context) { + if (instance == null) { + instance = buildDatabase(context.getApplicationContext()); + instance.updateDatabaseCreated(context.getApplicationContext()); + } + return instance; + } + + private static SearchHistoryDatabase buildDatabase(final Context appContext) { + return Room.databaseBuilder(appContext, + SearchHistoryDatabase.class, DATABASE_NAME).addCallback(new Callback() { + @Override + public void onCreate(@NonNull SupportSQLiteDatabase db) { + super.onCreate(db); + SearchHistoryDatabase database = SearchHistoryDatabase.getInstance(appContext); + database.setDatabaseCreated(); + } + }).fallbackToDestructiveMigration().build(); + // TODO remove fallbackToDestructiveMigration + } + + /** + * Check whether the database already exists and expose it via {@link #getDatabaseCreated()} + */ + private void updateDatabaseCreated(final Context context) { + if (context.getDatabasePath(DATABASE_NAME).exists()) { + setDatabaseCreated(); + } + } + + private void setDatabaseCreated() { + isDatabaseCreated.postValue(true); + } + + public static void insertData(final SearchHistoryDatabase database, + final SearchHistoryEntity searchHistory) { + new InsertSearchEntity(database, searchHistory).execute(); + } + + public LiveData getDatabaseCreated() { + return isDatabaseCreated; + } + + + private static class InsertSearchEntity extends AsyncTask { + + private final SearchHistoryDatabase database; + private final SearchHistoryEntity searchHistory; + + InsertSearchEntity(SearchHistoryDatabase database, SearchHistoryEntity searchHistory) { + this.searchHistory = searchHistory; + this.database = database; + } + + @Override + protected Void doInBackground(Void... voids) { + database.searchHistoryDao().insert(searchHistory); + return null; + } + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java new file mode 100644 index 000000000..d83b25e60 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java @@ -0,0 +1,19 @@ +package com.mapbox.plugins.places.autocomplete.data.converter; + +import android.arch.persistence.room.TypeConverter; +import android.support.annotation.NonNull; + +import com.mapbox.geocoding.v5.models.CarmenFeature; + +public class CarmenFeatureConverter { + + @TypeConverter + public static CarmenFeature toCarmenFeature(String serializedCarmenFeature) { + return serializedCarmenFeature == null ? null : CarmenFeature.fromJson(serializedCarmenFeature); + } + + @TypeConverter + public static String fromCarmenFeature(@NonNull CarmenFeature carmenFeature) { + return carmenFeature.toJson(); + } +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java new file mode 100644 index 000000000..8934fe0b3 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java @@ -0,0 +1,34 @@ +package com.mapbox.plugins.places.autocomplete.data.dao; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Delete; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity; + +import java.util.List; + +@Dao +public interface SearchHistoryDao { + + @Query("SELECT * FROM searchhistory") + LiveData> getAll(); + + @Query("SELECT * FROM searchhistory WHERE placeId IN (:placeIds)") + LiveData> loadAllByIds(String[] placeIds); + + @Query("SELECT * FROM searchhistory WHERE placeId IN (:placeId)") + LiveData findByCarmenFeature(String placeId); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insertAll(List searchHistory); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(SearchHistoryEntity searchHistory); + + @Delete + void delete(SearchHistoryEntity searchHistory); +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/SearchHistoryEntity.java similarity index 52% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/SearchHistoryEntity.java index fb89ac835..4d34b5e74 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/RecentSearch.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/SearchHistoryEntity.java @@ -1,14 +1,17 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.data.entity; import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.Entity; import android.arch.persistence.room.PrimaryKey; import android.support.annotation.NonNull; -@Entity -public class RecentSearch { +import com.mapbox.geocoding.v5.models.CarmenFeature; +import com.mapbox.plugins.places.autocomplete.model.SearchHistory; - public RecentSearch(@NonNull String placeId, String carmenFeature) { +@Entity(tableName = "searchhistory") +public class SearchHistoryEntity implements SearchHistory { + + public SearchHistoryEntity(@NonNull String placeId, CarmenFeature carmenFeature) { this.placeId = placeId; this.carmenFeature = carmenFeature; } @@ -18,8 +21,9 @@ public RecentSearch(@NonNull String placeId, String carmenFeature) { private String placeId; @ColumnInfo(name = "carmen_feature") - private String carmenFeature; + private CarmenFeature carmenFeature; + @Override @NonNull public String getPlaceId() { return placeId; @@ -29,11 +33,12 @@ public void setPlaceId(@NonNull String placeId) { this.placeId = placeId; } - public String getCarmenFeature() { + @Override + public CarmenFeature getCarmenFeature() { return carmenFeature; } - public void setCarmenFeature(String carmenFeature) { + public void setCarmenFeature(CarmenFeature carmenFeature) { this.carmenFeature = carmenFeature; } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/SearchHistory.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/SearchHistory.java new file mode 100644 index 000000000..02a73d3b6 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/SearchHistory.java @@ -0,0 +1,9 @@ +package com.mapbox.plugins.places.autocomplete.model; + +import com.mapbox.geocoding.v5.models.CarmenFeature; + +public interface SearchHistory { + String getPlaceId(); + + CarmenFeature getCarmenFeature(); +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java new file mode 100644 index 000000000..c9c7323c4 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java @@ -0,0 +1,175 @@ +package com.mapbox.plugins.places.autocomplete.ui; + +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.ViewTreeObserver; +import android.widget.ScrollView; + +import com.mapbox.geocoding.v5.models.CarmenFeature; +import com.mapbox.geocoding.v5.models.GeocodingResponse; +import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.DataRepository; +import com.mapbox.plugins.places.autocomplete.PlaceConstants; +import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity; +import com.mapbox.plugins.places.autocomplete.viewmodel.PlaceAutocompleteViewModel; +import com.mapbox.plugins.places.common.KeyboardUtils; + +import java.util.List; + +import static android.view.View.GONE; +import static android.view.View.INVISIBLE; +import static android.view.View.VISIBLE; + +public class PlaceAutocompleteActivity extends AppCompatActivity implements ResultClickCallback, + SearchView.QueryListener, SearchView.BackButtonListener, + ViewTreeObserver.OnScrollChangedListener { + + private PlaceAutocompleteViewModel viewModel; + private ResultView searchHistoryView; + private ResultView searchResultView; + private ScrollView resultScrollView; + private ResultView starredView; + private SearchView searchView; + private View dropShadowView; + private View rootView; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent intent = getIntent(); + setActivityContentView(intent); + bindViews(); + bindClickListeners(); + + // View model + PlaceAutocompleteViewModel.Factory factory = new PlaceAutocompleteViewModel.Factory( + getApplication(), intent); + viewModel = ViewModelProviders.of(this, factory).get(PlaceAutocompleteViewModel.class); + viewModel.buildGeocodingRequest(); + + // Theme settings + rootView.setBackgroundColor(intent.getIntExtra(PlaceConstants.BACKGROUND, Color.TRANSPARENT)); + resultScrollView.getViewTreeObserver().addOnScrollChangedListener(this); + + updateFavoritePlacesView(); + subscribe(); + } + + @Override + public void onScrollChanged() { + if (resultScrollView != null) { + if (resultScrollView.getScrollY() != 0) { + KeyboardUtils.hideKeyboard(resultScrollView); + } + dropShadowView.setVisibility( + resultScrollView.canScrollVertically(-1) ? VISIBLE : INVISIBLE + ); + } + } + + @Override + public void onQueryChange(CharSequence charSequence) { + viewModel.onQueryChange(charSequence); + if (charSequence.length() <= 0) { + searchResultView.getResultsList().clear(); + searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? GONE : VISIBLE); + searchResultView.notifyDataSetChanged(); + } + } + + @Override + public void onClick(CarmenFeature carmenFeature) { + Intent intent = viewModel.onItemClicked(carmenFeature); + setResult(AppCompatActivity.RESULT_OK, intent); + finish(); + } + + @Override + protected void onDestroy() { + if (resultScrollView != null) { + resultScrollView.getViewTreeObserver().removeOnScrollChangedListener(this); + } + super.onDestroy(); + } + + @Override + public void onBackButtonPress() { + setResult(AppCompatActivity.RESULT_CANCELED); + finish(); + } + + private void setActivityContentView(Intent intent) { + if (intent.getIntExtra(PlaceConstants.MODE, 1) == 2) { + setContentView(R.layout.activity_complete_card); + } else { + setContentView(R.layout.activity_complete_full); + } + } + + private void bindClickListeners() { + searchHistoryView.setOnItemClickListener(this); + searchResultView.setOnItemClickListener(this); + starredView.setOnItemClickListener(this); + searchView.setBackButtonListener(this); + searchView.setQueryListener(this); + } + + private void bindViews() { + searchHistoryView = findViewById(R.id.searchHistoryResultsView); + resultScrollView = findViewById(R.id.scroll_view_results); + searchResultView = findViewById(R.id.searchResultView); + dropShadowView = findViewById(R.id.scroll_drop_shadow); + starredView = findViewById(R.id.favoriteResultView); + searchView = findViewById(R.id.searchView); + rootView = findViewById(R.id.root_layout); + } + + private void updateSearchHistoryView(@Nullable List searchHistoryEntities) { + searchHistoryView.getResultsList().clear(); + if (searchHistoryEntities != null) { + for (SearchHistoryEntity entity : searchHistoryEntities) { + searchHistoryView.getResultsList().add(entity.getCarmenFeature()); + } + } + searchHistoryView.notifyDataSetChanged(); + searchHistoryView.setVisibility( + searchHistoryView.getResultsList().isEmpty() ? GONE : VISIBLE + ); + } + + private void updateSearchResultView(@Nullable GeocodingResponse response) { + searchResultView.getResultsList().clear(); + searchResultView.getResultsList().addAll(response.features()); + searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? GONE : VISIBLE); + searchResultView.notifyDataSetChanged(); + } + + private void updateFavoritePlacesView() { + List favoriteFeatures = viewModel.getFavoritePlaces(); + starredView.getResultsList().addAll(favoriteFeatures); + } + + private void subscribe() { + viewModel.geocodingLiveData.observe(this, new Observer() { + @Override + public void onChanged(@Nullable GeocodingResponse geocodingResponse) { + updateSearchResultView(geocodingResponse); + } + }); + + // Subscribe to the search history database + DataRepository.getInstance(viewModel.getDatabase()).getSearchHistory().observe(this, + new Observer>() { + @Override + public void onChanged(@Nullable List searchHistoryEntities) { + updateSearchHistoryView(searchHistoryEntities); + } + }); + } +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultCardView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultCardView.java similarity index 93% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultCardView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultCardView.java index 2d8f8f434..923636cb5 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultCardView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultCardView.java @@ -1,4 +1,4 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.ui; import android.content.Context; import android.support.annotation.NonNull; diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultClickCallback.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultClickCallback.java new file mode 100644 index 000000000..9c0758855 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultClickCallback.java @@ -0,0 +1,7 @@ +package com.mapbox.plugins.places.autocomplete.ui; + +import com.mapbox.geocoding.v5.models.CarmenFeature; + +interface ResultClickCallback { + void onClick(CarmenFeature carmenFeature); +} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultView.java similarity index 93% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultView.java index 1502177b3..2e91e45e1 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ResultView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/ResultView.java @@ -1,4 +1,4 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.ui; import android.content.Context; import android.support.annotation.NonNull; @@ -56,7 +56,7 @@ void inflateView(Context context) { inflate(context, R.layout.view_results, this); } - public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) { + public void setOnItemClickListener(ResultClickCallback onItemClickListener) { if (adapter != null) { adapter.setOnItemClickListener(onItemClickListener); } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java similarity index 79% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java index 37745a1df..f4185de4d 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java @@ -1,6 +1,7 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.ui; import android.content.Context; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -10,6 +11,7 @@ import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.places.R; +import com.mapbox.plugins.places.autocomplete.PlaceConstants; import java.util.List; @@ -17,7 +19,10 @@ public class SearchResultAdapter extends RecyclerView.Adapter results; private final Context context; @@ -33,14 +38,14 @@ public SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new SearchViewHolder(view); } - public void setOnItemClickListener(OnCardItemClickListener onItemClickListener) { - this.onItemClickListener = onItemClickListener; + public void setOnItemClickListener(ResultClickCallback resultClickCallback) { + this.resultClickCallback = resultClickCallback; } @Override public void onBindViewHolder(SearchViewHolder holder, int position) { - if (onItemClickListener != null) { - holder.bind(results.get(position), onItemClickListener); + if (resultClickCallback != null) { + holder.bind(results.get(position), resultClickCallback); } if (results.get(position).properties().has(PlaceConstants.SAVED_PLACE)) { @@ -77,11 +82,11 @@ static class SearchViewHolder extends RecyclerView.ViewHolder { addressView = itemView.findViewById(R.id.tv_address); } - public void bind(final CarmenFeature carmenFeature, final OnCardItemClickListener listener) { + public void bind(final CarmenFeature carmenFeature, final ResultClickCallback listener) { itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - listener.onItemClick(carmenFeature); + listener.onClick(carmenFeature); } }); } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchView.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchView.java similarity index 83% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchView.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchView.java index b77306186..ca902bfbe 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/SearchView.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchView.java @@ -1,5 +1,9 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.ui; +import android.arch.lifecycle.Lifecycle; +import android.arch.lifecycle.LifecycleObserver; +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.OnLifecycleEvent; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -13,7 +17,8 @@ import com.mapbox.places.R; -public class SearchView extends LinearLayout implements ImageButton.OnClickListener, TextWatcher { +public class SearchView extends LinearLayout implements ImageButton.OnClickListener, TextWatcher, + LifecycleObserver { @Nullable private BackButtonListener backButtonListener; @@ -45,6 +50,7 @@ private void initialize() { backButton.setOnClickListener(this); clearButton.setOnClickListener(this); searchEditText.addTextChangedListener(this); + ((LifecycleOwner) getContext()).getLifecycle().addObserver(this); } @Override @@ -58,6 +64,12 @@ public void onClick(View view) { } } + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + public void onDestroy() { + backButtonListener = null; + queryListener = null; + } + @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (queryListener != null) { @@ -80,23 +92,15 @@ public void setBackButtonListener(@Nullable BackButtonListener backButtonListene this.backButtonListener = backButtonListener; } - public void removeBackButtonListener() { - backButtonListener = null; - } - public void setQueryListener(@Nullable QueryListener queryListener) { this.queryListener = queryListener; } - public void removeQueryListener() { - queryListener = null; - } - - public interface QueryListener { + interface QueryListener { void onQueryChange(CharSequence charSequence); } - public interface BackButtonListener { + interface BackButtonListener { void onBackButtonPress(); } } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java similarity index 87% rename from plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java rename to plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java index 9f7801b79..60dffb0a7 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/Utils.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java @@ -1,16 +1,18 @@ -package com.mapbox.plugins.places.autocomplete; +package com.mapbox.plugins.places.autocomplete.utils; import android.content.Intent; import com.mapbox.geocoding.v5.MapboxGeocoding; import com.mapbox.geojson.Point; +import com.mapbox.plugins.places.autocomplete.PlaceConstants; public class Utils { private Utils() { } - static MapboxGeocoding.Builder initiateSearchQuery(Intent intent) { + // TODO move to viewmodel and delete class + public static MapboxGeocoding.Builder initiateSearchQuery(Intent intent) { MapboxGeocoding.Builder geocoderBuilder = MapboxGeocoding.builder().autocomplete(true); geocoderBuilder.accessToken(intent.getStringExtra(PlaceConstants.ACCESS_TOKEN)); geocoderBuilder.limit(intent.getIntExtra(PlaceConstants.LIMIT, 5)); diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java new file mode 100644 index 000000000..40d9b3761 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java @@ -0,0 +1,117 @@ +package com.mapbox.plugins.places.autocomplete.viewmodel; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.MutableLiveData; +import android.arch.lifecycle.ViewModel; +import android.arch.lifecycle.ViewModelProvider; +import android.content.Intent; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.mapbox.geocoding.v5.MapboxGeocoding; +import com.mapbox.geocoding.v5.models.CarmenFeature; +import com.mapbox.geocoding.v5.models.GeocodingResponse; +import com.mapbox.plugins.places.autocomplete.DataRepository; +import com.mapbox.plugins.places.autocomplete.PlaceConstants; +import com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase; +import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity; +import com.mapbox.plugins.places.autocomplete.utils.Utils; + +import java.util.ArrayList; +import java.util.List; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class PlaceAutocompleteViewModel extends AndroidViewModel + implements Callback { + + public final MutableLiveData geocodingLiveData = new MutableLiveData<>(); + private MapboxGeocoding.Builder geocoderBuilder; + private final Intent intent; + + PlaceAutocompleteViewModel(@NonNull Application application, @NonNull Intent intent) { + super(application); + this.intent = intent; + } + + public void buildGeocodingRequest() { + geocoderBuilder = Utils.initiateSearchQuery(intent); + } + + public void onQueryChange(CharSequence sequence) { + String query = sequence.toString(); + if (query.isEmpty()) { + return; + } + geocoderBuilder.query(query).build().enqueueCall(this); + } + + public Intent onItemClicked(CarmenFeature carmenFeature) { + saveCarmenFeatureToDatabase(carmenFeature); + + String json = carmenFeature.toJson(); + Intent returningIntent = new Intent(); + returningIntent.putExtra(PlaceConstants.RETURNING_CARMEN_FEATURE, json); + return returningIntent; + } + + public List getFavoritePlaces() { + List serialized = intent.getStringArrayListExtra(PlaceConstants.INJECTED_PLACES); + List favoriteFeatures = new ArrayList<>(); + if (serialized == null || serialized.isEmpty()) { + return favoriteFeatures; + } + for (String serializedCarmenFeature : serialized) { + favoriteFeatures.add(CarmenFeature.fromJson(serializedCarmenFeature)); + } + return favoriteFeatures; + } + + @Override + public void onResponse(@NonNull Call call, + @NonNull Response response) { + if (response.isSuccessful()) { + geocodingLiveData.setValue(response.body()); + } + } + + @Override + public void onFailure(@NonNull Call call, + @NonNull Throwable throwable) { + + } + + public SearchHistoryDatabase getDatabase() { + return SearchHistoryDatabase.getInstance(this.getApplication().getApplicationContext()); + } + + private void saveCarmenFeatureToDatabase(CarmenFeature carmenFeature) { + // Check that the carmenFeature hasn't already been added + if (carmenFeature.properties().has(PlaceConstants.SAVED_PLACE)) { + return; + } + SearchHistoryEntity searchHistory = new SearchHistoryEntity(carmenFeature.id(), carmenFeature); + DataRepository.getInstance(getDatabase()).addSearchHistoryEntity(searchHistory); + } + + public static class Factory extends ViewModelProvider.NewInstanceFactory { + + private final Application application; + private final Intent intent; + + public Factory(@NonNull Application application, @NonNull Intent intent) { + this.application = application; + this.intent = intent; + } + + @Override + @NonNull + public T create(@Nullable Class modelClass) { + //noinspection unchecked + return (T) new PlaceAutocompleteViewModel(application, intent); + } + } +} diff --git a/plugin-places/src/main/res/layout/activity_complete_card.xml b/plugin-places/src/main/res/layout/activity_complete_card.xml index f82f6c6f2..be7a2fb77 100644 --- a/plugin-places/src/main/res/layout/activity_complete_card.xml +++ b/plugin-places/src/main/res/layout/activity_complete_card.xml @@ -19,7 +19,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - - - diff --git a/plugin-places/src/main/res/layout/activity_complete_full.xml b/plugin-places/src/main/res/layout/activity_complete_full.xml index 4a74042ed..b7351e48f 100644 --- a/plugin-places/src/main/res/layout/activity_complete_full.xml +++ b/plugin-places/src/main/res/layout/activity_complete_full.xml @@ -8,25 +8,21 @@ android:layout_height="match_parent"> - + app:layout_constraintTop_toBottomOf="@+id/toolbar"> - + + + app:layout_constraintTop_toTopOf="@+id/scroll_drop_shadow"> + + + + + + + + + + + \ No newline at end of file diff --git a/plugin-places/src/main/res/layout/item_search_result.xml b/plugin-places/src/main/res/layout/item_search_result.xml index f01c0d62a..d01e1e0f8 100644 --- a/plugin-places/src/main/res/layout/item_search_result.xml +++ b/plugin-places/src/main/res/layout/item_search_result.xml @@ -5,7 +5,9 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="60dp" - android:background="@color/cardview_light_background"> + android:background="@color/cardview_light_background" + android:clickable="true" + android:focusable="true"> Date: Wed, 29 Nov 2017 21:33:49 -0500 Subject: [PATCH 18/25] added package-info and fixed deleting entire search history db --- Makefile | 3 ++ gradle/sonarqube.gradle | 1 - .../places/autocomplete/DataRepository.java | 39 +++++++++++-------- .../autocomplete/PlaceAutocomplete.java | 6 +-- .../data/SearchHistoryDatabase.java | 26 +++++++++---- .../data/converter/package-info.java | 7 ++++ .../data/dao/SearchHistoryDao.java | 3 ++ .../autocomplete/data/dao/package-info.java | 6 +++ .../data/entity/package-info.java | 6 +++ .../autocomplete/data/package-info.java | 6 +++ .../autocomplete/model/package-info.java | 6 +++ .../places/autocomplete/package-info.java | 6 +++ .../places/autocomplete/ui/package-info.java | 6 +++ .../autocomplete/viewmodel/package-info.java | 6 +++ .../plugins/places/common/package-info.java | 6 +++ 15 files changed, 105 insertions(+), 28 deletions(-) create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/package-info.java create mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/common/package-info.java diff --git a/Makefile b/Makefile index 65a1c667c..3cf28b486 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +sonarqube: + ./gradlew sonarqube + checkstyle: ./gradlew checkstyle diff --git a/gradle/sonarqube.gradle b/gradle/sonarqube.gradle index 065f4cc61..9208f63c9 100644 --- a/gradle/sonarqube.gradle +++ b/gradle/sonarqube.gradle @@ -11,7 +11,6 @@ sonarqube { // Test reports property "sonar.java.coveragePlugin", "jacoco" - property "sonar.jacoco.reportPaths", "${project.buildDir}/jacoco/test.exec" // Authentication diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java index 8f9ed4cc4..aea89824a 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java @@ -10,28 +10,20 @@ import java.util.List; -public class DataRepository { +/** + * Used internally for the autocomplete view + *

+ * Singleton class used for exchanging information between the data classes and the views. + * + * @since 0.1.0 + */ +public final class DataRepository { private static DataRepository instance; private final SearchHistoryDatabase database; private MediatorLiveData> observableSearchHistory; - private DataRepository(final SearchHistoryDatabase database) { - this.database = database; - observableSearchHistory = new MediatorLiveData<>(); - - observableSearchHistory.addSource(database.searchHistoryDao().getAll(), - new Observer>() { - @Override - public void onChanged(@Nullable List searchHistoryEntities) { - if (database.getDatabaseCreated().getValue() != null) { - observableSearchHistory.postValue(searchHistoryEntities); - } - } - }); - } - public static DataRepository getInstance(final SearchHistoryDatabase database) { if (instance == null) { instance = new DataRepository(database); @@ -46,4 +38,19 @@ public LiveData> getSearchHistory() { public void addSearchHistoryEntity(SearchHistoryEntity searchHistory) { SearchHistoryDatabase.insertData(database, searchHistory); } + + private DataRepository(final SearchHistoryDatabase database) { + this.database = database; + observableSearchHistory = new MediatorLiveData<>(); + + observableSearchHistory.addSource(database.searchHistoryDao().getAll(), + new Observer>() { + @Override + public void onChanged(@Nullable List searchHistoryEntities) { + if (database.getDatabaseCreated().getValue() != null) { + observableSearchHistory.postValue(searchHistoryEntities); + } + } + }); + } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index fcf81d0fe..3c6cfd88c 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -1,7 +1,6 @@ package com.mapbox.plugins.places.autocomplete; import android.app.Activity; -import android.arch.persistence.room.Room; import android.content.Context; import android.content.Intent; import android.support.annotation.ColorInt; @@ -71,9 +70,8 @@ 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 = SearchHistoryDatabase.getInstance(context); + SearchHistoryDatabase.deleteAllData(database); } /** diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java index 97b3b3515..8d4f4616c 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java @@ -43,8 +43,7 @@ public void onCreate(@NonNull SupportSQLiteDatabase db) { SearchHistoryDatabase database = SearchHistoryDatabase.getInstance(appContext); database.setDatabaseCreated(); } - }).fallbackToDestructiveMigration().build(); - // TODO remove fallbackToDestructiveMigration + }).build(); } /** @@ -62,26 +61,39 @@ private void setDatabaseCreated() { public static void insertData(final SearchHistoryDatabase database, final SearchHistoryEntity searchHistory) { - new InsertSearchEntity(database, searchHistory).execute(); + new DatabaseTask(database, searchHistory).execute(); + } + + public static void deleteAllData(final SearchHistoryDatabase database) { + new DatabaseTask(database, true).execute(); } public LiveData getDatabaseCreated() { return isDatabaseCreated; } - - private static class InsertSearchEntity extends AsyncTask { + private static class DatabaseTask extends AsyncTask { private final SearchHistoryDatabase database; - private final SearchHistoryEntity searchHistory; + private SearchHistoryEntity searchHistory; + private boolean delete; - InsertSearchEntity(SearchHistoryDatabase database, SearchHistoryEntity searchHistory) { + DatabaseTask(SearchHistoryDatabase database, boolean delete) { + this.delete = delete; + this.database = database; + } + + DatabaseTask(SearchHistoryDatabase database, SearchHistoryEntity searchHistory) { this.searchHistory = searchHistory; this.database = database; } @Override protected Void doInBackground(Void... voids) { + if (delete) { + database.searchHistoryDao().deleteAllEntries(); + return null; + } database.searchHistoryDao().insert(searchHistory); return null; } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/package-info.java new file mode 100644 index 000000000..82a1192c3 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains type converters specific to Room to convert java objects into primitive types for easier + * database storing. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.data.converter; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java index 8934fe0b3..bb9a44d97 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java @@ -31,4 +31,7 @@ public interface SearchHistoryDao { @Delete void delete(SearchHistoryEntity searchHistory); + + @Query("DELETE FROM searchhistory") + void deleteAllEntries(); } \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/package-info.java new file mode 100644 index 000000000..d7d3f99e0 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains the Data Access Objects where we define the search history database interactions. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.data.dao; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/package-info.java new file mode 100644 index 000000000..1bc4a7262 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/entity/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains classes specifying a single item entity that reflects the structure of the database. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.data.entity; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/package-info.java new file mode 100644 index 000000000..bdbe966d0 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains classes directly related to the SQLite database for search history. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.data; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/package-info.java new file mode 100644 index 000000000..23eebc7c9 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/model/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains interfaces which model a classes object methods. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.model; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/package-info.java new file mode 100644 index 000000000..54a186ade --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains all the classes which can be useful between all other packages. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/package-info.java new file mode 100644 index 000000000..affacf9bd --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains classes directly related to the user interface. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.ui; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/package-info.java new file mode 100644 index 000000000..e5890c8c7 --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains context aware view models for preparing and managing the data that place activities use. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.autocomplete.viewmodel; \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/common/package-info.java b/plugin-places/src/main/java/com/mapbox/plugins/places/common/package-info.java new file mode 100644 index 000000000..4aeaa60fa --- /dev/null +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/common/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains context aware view models for preparing and managing the data that place activities use. + * + * @since 0.1.0 + */ +package com.mapbox.plugins.places.common; \ No newline at end of file From f15a1dd2a7b1cef760a3b76b7ef419837cc169f0 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Wed, 29 Nov 2017 21:52:41 -0500 Subject: [PATCH 19/25] cleaned up code a bit --- .../places/autocomplete/PlaceAutocomplete.java | 2 +- .../places/autocomplete/PlaceConstants.java | 10 ++++++---- .../autocomplete/data/SearchHistoryDatabase.java | 6 +++--- .../data/converter/CarmenFeatureConverter.java | 4 ++++ .../autocomplete/data/dao/SearchHistoryDao.java | 7 ++++++- .../ui/PlaceAutocompleteActivity.java | 16 ++++++++-------- .../autocomplete/ui/SearchResultAdapter.java | 7 ++++--- 7 files changed, 32 insertions(+), 20 deletions(-) diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java index 3c6cfd88c..3a8d072ad 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceAutocomplete.java @@ -29,7 +29,7 @@ * * @since 0.1.0 */ -public class PlaceAutocomplete { +public final class PlaceAutocomplete { /** * Mode for launching the autocomplete activity in fullscreen. diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java index 3ec847fb6..43bb7a8b1 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/PlaceConstants.java @@ -2,10 +2,8 @@ public final class PlaceConstants { - private PlaceConstants() { - } - - public static final String RETURNING_CARMEN_FEATURE = "com.mapbox.mapboxsdk.plugins.places.carmenfeat"; + public static final String RETURNING_CARMEN_FEATURE + = "com.mapbox.mapboxsdk.plugins.places.carmenfeat"; public static final String ACCESS_TOKEN = "com.mapbox.mapboxsdk.plugins.places.accessToken"; public static final String BBOX_SOUTHWEST_POINT = "com.mapbox.mapboxsdk.plugins.places.bbox.southwestPoint"; @@ -20,4 +18,8 @@ private PlaceConstants() { public static final String BACKGROUND = "com.mapbox.mapboxsdk.plugins.places.backgroundColor"; public static final String SAVED_PLACE = "com.mapbox.mapboxsdk.plugins.places.savedcarmenfeat"; public static final String MODE = "com.mapbox.mapboxsdk.plugins.places.mode"; + + private PlaceConstants() { + } + } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java index 8d4f4616c..fa4521d4a 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java @@ -68,7 +68,7 @@ public static void deleteAllData(final SearchHistoryDatabase database) { new DatabaseTask(database, true).execute(); } - public LiveData getDatabaseCreated() { + public final LiveData getDatabaseCreated() { return isDatabaseCreated; } @@ -92,9 +92,9 @@ private static class DatabaseTask extends AsyncTask { protected Void doInBackground(Void... voids) { if (delete) { database.searchHistoryDao().deleteAllEntries(); - return null; + } else { + database.searchHistoryDao().insert(searchHistory); } - database.searchHistoryDao().insert(searchHistory); return null; } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java index d83b25e60..cfee45f4e 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/converter/CarmenFeatureConverter.java @@ -7,6 +7,10 @@ public class CarmenFeatureConverter { + private CarmenFeatureConverter() { + // class shouldn't be initialized + } + @TypeConverter public static CarmenFeature toCarmenFeature(String serializedCarmenFeature) { return serializedCarmenFeature == null ? null : CarmenFeature.fromJson(serializedCarmenFeature); diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java index bb9a44d97..357c7075b 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/dao/SearchHistoryDao.java @@ -11,6 +11,11 @@ import java.util.List; +/** + * The Data Access Objects specifically for the search history database + * + * @since 0.1.0 + */ @Dao public interface SearchHistoryDao { @@ -34,4 +39,4 @@ public interface SearchHistoryDao { @Query("DELETE FROM searchhistory") void deleteAllEntries(); -} \ No newline at end of file +} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java index c9c7323c4..f6f844556 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/PlaceAutocompleteActivity.java @@ -22,10 +22,6 @@ import java.util.List; -import static android.view.View.GONE; -import static android.view.View.INVISIBLE; -import static android.view.View.VISIBLE; - public class PlaceAutocompleteActivity extends AppCompatActivity implements ResultClickCallback, SearchView.QueryListener, SearchView.BackButtonListener, ViewTreeObserver.OnScrollChangedListener { @@ -68,7 +64,7 @@ public void onScrollChanged() { KeyboardUtils.hideKeyboard(resultScrollView); } dropShadowView.setVisibility( - resultScrollView.canScrollVertically(-1) ? VISIBLE : INVISIBLE + resultScrollView.canScrollVertically(-1) ? View.VISIBLE : View.INVISIBLE ); } } @@ -78,7 +74,9 @@ public void onQueryChange(CharSequence charSequence) { viewModel.onQueryChange(charSequence); if (charSequence.length() <= 0) { searchResultView.getResultsList().clear(); - searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? GONE : VISIBLE); + searchResultView.setVisibility( + searchResultView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE + ); searchResultView.notifyDataSetChanged(); } } @@ -139,14 +137,16 @@ private void updateSearchHistoryView(@Nullable List searchH } searchHistoryView.notifyDataSetChanged(); searchHistoryView.setVisibility( - searchHistoryView.getResultsList().isEmpty() ? GONE : VISIBLE + searchHistoryView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE ); } private void updateSearchResultView(@Nullable GeocodingResponse response) { searchResultView.getResultsList().clear(); searchResultView.getResultsList().addAll(response.features()); - searchResultView.setVisibility(searchResultView.getResultsList().isEmpty() ? GONE : VISIBLE); + searchResultView.setVisibility( + searchResultView.getResultsList().isEmpty() ? View.GONE : View.VISIBLE + ); searchResultView.notifyDataSetChanged(); } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java index f4185de4d..039682bca 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/ui/SearchResultAdapter.java @@ -15,7 +15,8 @@ import java.util.List; -public class SearchResultAdapter extends RecyclerView.Adapter { +public class SearchResultAdapter + extends RecyclerView.Adapter { private static final String ADDRESS = "address"; @@ -73,8 +74,8 @@ public int getItemCount() { static class SearchViewHolder extends RecyclerView.ViewHolder { - final TextView placeNameView; - final TextView addressView; + private final TextView placeNameView; + private final TextView addressView; SearchViewHolder(View itemView) { super(itemView); From 8bee62d65db6aafffdc85d7a62e1df2ec731283c Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Wed, 29 Nov 2017 22:01:19 -0500 Subject: [PATCH 20/25] sonarqube fixes --- .../places/autocomplete/DataRepository.java | 30 +++++++++---------- .../data/SearchHistoryDatabase.java | 17 ++++++----- .../plugins/places/common/KeyboardUtils.java | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java index aea89824a..55181750f 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/DataRepository.java @@ -24,21 +24,6 @@ public final class DataRepository { private final SearchHistoryDatabase database; private MediatorLiveData> observableSearchHistory; - public static DataRepository getInstance(final SearchHistoryDatabase database) { - if (instance == null) { - instance = new DataRepository(database); - } - return instance; - } - - public LiveData> getSearchHistory() { - return observableSearchHistory; - } - - public void addSearchHistoryEntity(SearchHistoryEntity searchHistory) { - SearchHistoryDatabase.insertData(database, searchHistory); - } - private DataRepository(final SearchHistoryDatabase database) { this.database = database; observableSearchHistory = new MediatorLiveData<>(); @@ -53,4 +38,19 @@ public void onChanged(@Nullable List searchHistoryEntities) } }); } + + public static DataRepository getInstance(final SearchHistoryDatabase database) { + if (instance == null) { + instance = new DataRepository(database); + } + return instance; + } + + public LiveData> getSearchHistory() { + return observableSearchHistory; + } + + public void addSearchHistoryEntity(SearchHistoryEntity searchHistory) { + SearchHistoryDatabase.insertData(database, searchHistory); + } } diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java index fa4521d4a..2a43f7ae0 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java @@ -36,14 +36,15 @@ public static SearchHistoryDatabase getInstance(final Context context) { private static SearchHistoryDatabase buildDatabase(final Context appContext) { return Room.databaseBuilder(appContext, - SearchHistoryDatabase.class, DATABASE_NAME).addCallback(new Callback() { - @Override - public void onCreate(@NonNull SupportSQLiteDatabase db) { - super.onCreate(db); - SearchHistoryDatabase database = SearchHistoryDatabase.getInstance(appContext); - database.setDatabaseCreated(); - } - }).build(); + SearchHistoryDatabase.class, DATABASE_NAME).addCallback( + new Callback() { + @Override + public void onCreate(@NonNull SupportSQLiteDatabase db) { + super.onCreate(db); + SearchHistoryDatabase database = SearchHistoryDatabase.getInstance(appContext); + database.setDatabaseCreated(); + } + }).build(); } /** diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java b/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java index b51f21e3e..c283c742f 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/common/KeyboardUtils.java @@ -4,7 +4,7 @@ import android.view.View; import android.view.inputmethod.InputMethodManager; -public class KeyboardUtils { +public final class KeyboardUtils { private KeyboardUtils() { } From c38c40ee456c5f49f98485dda368560d21dc68a5 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Thu, 30 Nov 2017 10:48:43 -0500 Subject: [PATCH 21/25] remove mapboxGeocoding dependency in test app --- app/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1211138a7..6980d6d3b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,8 +42,6 @@ dependencies { implementation dependenciesList.supportRecyclerView implementation dependenciesList.supportConstraintLayout - implementation dependenciesList.mapboxGeocoding - // Unit testing testImplementation dependenciesList.junit testImplementation dependenciesList.mockito From 55ddbf7c3dd5a7bea3c98a0117cda86e50c347bf Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Thu, 30 Nov 2017 11:06:41 -0500 Subject: [PATCH 22/25] final fixes before initial review --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 1 - .../1.json | 39 -------------- .../2.json | 39 -------------- .../data/SearchHistoryDatabase.java | 2 +- .../places/autocomplete/utils/Utils.java | 54 ------------------- .../viewmodel/PlaceAutocompleteViewModel.java | 41 ++++++++++++-- 7 files changed, 40 insertions(+), 137 deletions(-) delete mode 100644 plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json delete mode 100644 plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json delete mode 100644 plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java diff --git a/app/build.gradle b/app/build.gradle index 6980d6d3b..a6e65b40e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,6 +32,7 @@ dependencies { // Mapbox implementation dependenciesList.mapboxMapSdk implementation dependenciesList.mapboxServices + implementation dependenciesList.mapboxGeocoding implementation dependenciesList.lifecycleExtensions diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f8c3fc987..405c5f767 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,7 +16,6 @@ - diff --git a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json deleted file mode 100644 index de98e0659..000000000 --- a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.SearchHistoryDatabase/1.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "formatVersion": 1, - "database": { - "version": 1, - "identityHash": "8c7c23e0876029678043b33f10b9d681", - "entities": [ - { - "tableName": "RecentSearch", - "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, \"8c7c23e0876029678043b33f10b9d681\")" - ] - } -} \ No newline at end of file diff --git a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json b/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json deleted file mode 100644 index 995743fee..000000000 --- a/plugin-places/schemas/com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase/2.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "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\")" - ] - } -} \ No newline at end of file diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java index 2a43f7ae0..de12b8597 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/data/SearchHistoryDatabase.java @@ -15,7 +15,7 @@ import com.mapbox.plugins.places.autocomplete.data.dao.SearchHistoryDao; import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity; -@Database(entities = {SearchHistoryEntity.class}, version = 2) +@Database(entities = {SearchHistoryEntity.class}, version = 1) @TypeConverters(CarmenFeatureConverter.class) public abstract class SearchHistoryDatabase extends RoomDatabase { diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java deleted file mode 100644 index 60dffb0a7..000000000 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/utils/Utils.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.mapbox.plugins.places.autocomplete.utils; - -import android.content.Intent; - -import com.mapbox.geocoding.v5.MapboxGeocoding; -import com.mapbox.geojson.Point; -import com.mapbox.plugins.places.autocomplete.PlaceConstants; - -public class Utils { - - private Utils() { - } - - // TODO move to viewmodel and delete class - public static MapboxGeocoding.Builder initiateSearchQuery(Intent intent) { - MapboxGeocoding.Builder geocoderBuilder = MapboxGeocoding.builder().autocomplete(true); - geocoderBuilder.accessToken(intent.getStringExtra(PlaceConstants.ACCESS_TOKEN)); - geocoderBuilder.limit(intent.getIntExtra(PlaceConstants.LIMIT, 5)); - - // Proximity - String proximityPointJson = intent.getStringExtra(PlaceConstants.PROXIMITY); - if (proximityPointJson != null) { - geocoderBuilder.proximity(Point.fromJson(proximityPointJson)); - } - - // Language - String languageJson = intent.getStringExtra(PlaceConstants.LANGUAGE); - if (languageJson != null) { - geocoderBuilder.languages(languageJson); - } - - // Type - String typeJson = intent.getStringExtra(PlaceConstants.TYPE); - if (typeJson != null) { - geocoderBuilder.geocodingTypes(typeJson); - } - - // Countries - String countriesJson = intent.getStringExtra(PlaceConstants.COUNTRIES); - if (countriesJson != null) { - geocoderBuilder.geocodingTypes(countriesJson); - } - - // Bounding box - String southwest = intent.getStringExtra(PlaceConstants.BBOX_SOUTHWEST_POINT); - String northeast = intent.getStringExtra(PlaceConstants.BBOX_NORTHEAST_POINT); - if (southwest != null && northeast != null) { - Point southwestPoint = Point.fromJson(southwest); - Point northeastPoint = Point.fromJson(northeast); - geocoderBuilder.bbox(southwestPoint, northeastPoint); - } - return geocoderBuilder; - } -} diff --git a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java index 40d9b3761..41d79a714 100644 --- a/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java +++ b/plugin-places/src/main/java/com/mapbox/plugins/places/autocomplete/viewmodel/PlaceAutocompleteViewModel.java @@ -12,11 +12,11 @@ import com.mapbox.geocoding.v5.MapboxGeocoding; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.geocoding.v5.models.GeocodingResponse; +import com.mapbox.geojson.Point; import com.mapbox.plugins.places.autocomplete.DataRepository; import com.mapbox.plugins.places.autocomplete.PlaceConstants; import com.mapbox.plugins.places.autocomplete.data.SearchHistoryDatabase; import com.mapbox.plugins.places.autocomplete.data.entity.SearchHistoryEntity; -import com.mapbox.plugins.places.autocomplete.utils.Utils; import java.util.ArrayList; import java.util.List; @@ -38,7 +38,42 @@ public class PlaceAutocompleteViewModel extends AndroidViewModel } public void buildGeocodingRequest() { - geocoderBuilder = Utils.initiateSearchQuery(intent); + geocoderBuilder = MapboxGeocoding.builder().autocomplete(true); + geocoderBuilder.accessToken(intent.getStringExtra(PlaceConstants.ACCESS_TOKEN)); + geocoderBuilder.limit(intent.getIntExtra(PlaceConstants.LIMIT, 5)); + + // Proximity + String proximityPointJson = intent.getStringExtra(PlaceConstants.PROXIMITY); + if (proximityPointJson != null) { + geocoderBuilder.proximity(Point.fromJson(proximityPointJson)); + } + + // Language + String languageJson = intent.getStringExtra(PlaceConstants.LANGUAGE); + if (languageJson != null) { + geocoderBuilder.languages(languageJson); + } + + // Type + String typeJson = intent.getStringExtra(PlaceConstants.TYPE); + if (typeJson != null) { + geocoderBuilder.geocodingTypes(typeJson); + } + + // Countries + String countriesJson = intent.getStringExtra(PlaceConstants.COUNTRIES); + if (countriesJson != null) { + geocoderBuilder.geocodingTypes(countriesJson); + } + + // Bounding box + String southwest = intent.getStringExtra(PlaceConstants.BBOX_SOUTHWEST_POINT); + String northeast = intent.getStringExtra(PlaceConstants.BBOX_NORTHEAST_POINT); + if (southwest != null && northeast != null) { + Point southwestPoint = Point.fromJson(southwest); + Point northeastPoint = Point.fromJson(northeast); + geocoderBuilder.bbox(southwestPoint, northeastPoint); + } } public void onQueryChange(CharSequence sequence) { @@ -81,7 +116,7 @@ public void onResponse(@NonNull Call call, @Override public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { - + throw new RuntimeException("Request failed with following message: ", throwable); } public SearchHistoryDatabase getDatabase() { From eec268b404223c782cc2a050b6d9bbaa3c99d5f1 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Thu, 30 Nov 2017 11:11:34 -0500 Subject: [PATCH 23/25] fixed checkstyle issue --- .../testapp/activity/places/AutocompleteLauncherActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java index b513cb7d8..d8f0d528f 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/places/AutocompleteLauncherActivity.java @@ -9,7 +9,6 @@ import android.widget.Toast; import com.google.gson.JsonObject; -import com.mapbox.geocoding.v5.models.CarmenContext; import com.mapbox.geocoding.v5.models.CarmenFeature; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.maps.MapView; From d7bba35312aa4c2c9e08e899f1b0dcd92272ba6f Mon Sep 17 00:00:00 2001 From: Langston Smith Date: Thu, 30 Nov 2017 12:28:28 -0800 Subject: [PATCH 24/25] Adding places plugin docs (#173) * Adds README to places plugin folder * adding places plugin line to repo readme * tweaks * fixed a few typos * nit line --- README.md | 3 +- plugin-places/README.md | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 plugin-places/README.md diff --git a/README.md b/README.md index d1c2798ee..78720b9eb 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Plugins are single-purpose libraries built on top of the [Mapbox Maps SDK for An * [**GeoJSON:** Load GeoJSON data from a URL, an asset file, or path.](https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-geojson) +* [**Places:** Add location search to your app with beautiful UI.](https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-places) + ## Installing a plugin By using a plugin, you also include the Android Map SDK which means that you'll need to setup your project to use the Map SDK if you haven't already. Head over to the [overview page for the Mapbox Maps SDK](https://www.mapbox.com/android-docs/map-sdk/overview/) to learn more. @@ -35,7 +37,6 @@ dependencies { ``` 5. Click the Sync Project with Gradle Files near the toolbar in Studio. - ## Help and Usage This repository includes an app that shows how to use each plugins in this repository. [Check out its code](https://github.com/mapbox/mapbox-plugins-android/tree/master/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp) for ready-to-use snippets. diff --git a/plugin-places/README.md b/plugin-places/README.md new file mode 100644 index 000000000..e00fd9022 --- /dev/null +++ b/plugin-places/README.md @@ -0,0 +1,65 @@ +# Mapbox places plugin + +The places plugin is the easiest and most powerful way to take advantage of [Mapbox's location search ("geocoding") capabilities](https://www.mapbox.com/geocoding/). The plugin automatically makes geocoding requests, has built-in saved locations, includes location picker functionality, and adds beautiful UI into your Android project. + +![ezgif com-crop](https://user-images.githubusercontent.com/5652865/32994007-045b6230-cd2f-11e7-8902-d7ee6da3ab47.gif) + +## Getting Started + +To use the places plugin, you include it in your `build.gradle` file. + +``` +// In the root build.gradle file +repositories { + mavenCentral() +} + +... + +// In the app build.gradle file +dependencies { + compile 'com.mapbox.mapboxsdk:mapbox-android-plugin-places:0.1.0' +} +``` + +The places plugin is published to Maven Central and nightly SNAPSHOTs are available on Sonatype: + +``` +// In the root build.gradle file +repositories { + mavenCentral() + maven { url "http://oss.sonatype.org/content/repositories/snapshots/" } +} + +... + +// In the app build.gradle file +dependencies { + compile 'com.mapbox.mapboxsdk:mapbox-android-plugin-places:0.2.0-SNAPSHOT' +} +``` + +## Places plugin examples + +- [In this repo's test app](https://github.com/mapbox/mapbox-plugins-android/blob/master/plugins/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/AutocompleteLauncherActivity.java) + +## Help and Usage + +This repository includes an app that shows how to use each plugins in this repository. [Check out its code](https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp) for ready-to-use snippets. + +Plugins are easy to use. A plugin is simply a library module built on top of the Mapbox Maps SDK for Android. Currently, we are not requiring plugins to register themselves or to implement any specific interfaces so that they're simple to consume. + +We'd love to [hear your feedback](https://github.com/mapbox/mapbox-plugins-android/issues) as we build more plugins and learn how you use them. + +## Why Plugins + +Splitting specific functionality into plugins makes our Maps SDK lighter and nimble for you to use, and it also lets us iterate faster. We can release plugins more often than the SDK, which requires a slower pace due to its larger codebase. + +The Mapbox Android team creates plugins but this plugins repository is an open-source project similar to the various Mapbox SDKs for Android. +Plugins' lightweight nature makes them much easier for you and anyone else to contribute rather than trying to add the same feature to the more robust Maps SDK. The Mapbox team can also more easily accept contributed plugins and keep the plugin list growing. + +## Contributing + +We welcome contributions to this plugin repository! + +If you're interested in building and sharing your own plugin, please read [the contribution guide](https://github.com/mapbox/mapbox-plugins-android/blob/master/CONTRIBUTING.md) to learn how to get started. From b263aee7ff8c153141ec7af8c63b683774e011a0 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Fri, 1 Dec 2017 18:19:59 -0500 Subject: [PATCH 25/25] fixed string id --- app/src/main/AndroidManifest.xml | 304 +++++++++++++++---------------- 1 file changed, 152 insertions(+), 152 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4b51b2670..1644765bc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,167 +2,167 @@ - - + + - + - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - + - - - - - + + + + + - + \ No newline at end of file