diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 28ac697..e69de29 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/MapsDialogFragment.java b/app/src/main/java/com/example/nemophila/MapsDialogFragment.java
new file mode 100644
index 0000000..391b4db
--- /dev/null
+++ b/app/src/main/java/com/example/nemophila/MapsDialogFragment.java
@@ -0,0 +1,62 @@
+package com.example.nemophila;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.DialogFragment;
+
+import com.example.nemophila.entities.Shop;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+public class MapsDialogFragment extends DialogFragment {
+
+ private Collection shops;
+ public MapsDialogFragment(Collection shops) {
+ this.shops = shops;
+ }
+
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
+ String[] choices = new String[shops.size()];
+ //ArrayList choices = new ArrayList<>();
+
+ int j = 0;
+ for (Iterator i = shops.iterator(); i.hasNext(); j++) {
+ Shop tmp = (Shop)i.next();
+ choices[j] = tmp.getName();
+ }
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle("投稿したいお店はこの中にありますか?")
+ .setPositiveButton("該当する店がありません(新規作成)", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ //このボタンを押した時の処理を書きます。
+ //新規投稿画面へ遷移
+ }
+ })
+ .setNeutralButton("キャンセル", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ // このボタンを押した時の処理を書きます。
+ }
+ })
+ .setItems(choices, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(getActivity(),
+ String.format("「%s」を選択しました。", choices[which]),
+ Toast.LENGTH_SHORT)
+ .show();
+ }
+ });
+ return builder.create();
+ }
+}
diff --git a/app/src/main/java/com/example/nemophila/MapsFragment.java b/app/src/main/java/com/example/nemophila/MapsFragment.java
index 0ed3186..c0837f2 100644
--- a/app/src/main/java/com/example/nemophila/MapsFragment.java
+++ b/app/src/main/java/com/example/nemophila/MapsFragment.java
@@ -7,6 +7,7 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
+import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
@@ -61,12 +62,12 @@
private LatLng shopLatlng;
// private LatLng testLatlng;
// private LatLng testLatlng2;
-// private LatLng tapLatlng;
+ private LatLng tapLatlng;
// private CameraPosition nowCamera;
// private LatLng nowLatlng;
private Marker currentMarker;
private BitmapDescriptor bd;
-
+ private boolean isLongClick;
LocationManager locationManager;
@@ -78,75 +79,115 @@
nemophila = (Nemophila) getActivity().getApplication();
mMap = googleMap;
-
-
//ViewModelへのアクセス
shopsViewModel = new ViewModelProvider(getActivity()).get(ShopsViewModel.class);
// LiveDataへの購読
shopsViewModel.getShopsLiveData().observe(getActivity(), shops -> {
- //受け取ったshopsに対してMarkerが立っているかを確認
- //対応するMarkerがなければMarkerを立てる
- for (Shop shop : shops) {
- if (shopsViewModel.getMarker(shop) == null) {
-
- shopLatlng = new LatLng(shop.getLatitude(), shop.getLongitude());
- System.out.println(shopLatlng);
- Marker createMaker = mMap.addMarker(new MarkerOptions().position(shopLatlng).title(""));
- //マーカーに店情報を持たせる
- createMaker.setTag(shop);
- //ShopToMarkerに紐づけ
- shopsViewModel.setShopAndMarker(shop, createMaker);
+ Toast.makeText(getActivity(),
+ String.format("店確認しました"),
+ Toast.LENGTH_SHORT)
+ .show();
+//
+// if(isLongClick == true) {
+// Toast.makeText(getActivity(),
+// String.format("長押しは受け取れてるよ"),
+// Toast.LENGTH_SHORT)
+// .show();
+// //長押し時は周辺のピンを全て取得し、ダイアログに表示する
+// DialogFragment dialogFragment = new MapsDialogFragment(shops);
+// dialogFragment.show(getActivity().getSupportFragmentManager(),"mapsdialog");
+//
+// }
+ //受け取ったshopsに対してMarkerが立っているかを確認
+ //各shopに対応するMarkerがなければMarkerを立てる
+ for (Shop shop : shops) {
+ if (shopsViewModel.getMarker(shop) == null) {
+ shopLatlng = new LatLng(shop.getLatitude(), shop.getLongitude());
+ System.out.println(shopLatlng);
+ Marker createMaker = mMap.addMarker(new MarkerOptions().position(shopLatlng).title(""));
+ //マーカーに店情報を持たせる
+ createMaker.setTag(shop);
+ //ShopToMarkerに紐づけ
+ shopsViewModel.setShopAndMarker(shop, createMaker);
+ }
}
- }
+ });
+
+ // LiveDataへの購読
+ shopsViewModel.getNearShopsLiveData().observe(getActivity(), shops -> {
+ Toast.makeText(getActivity(),
+ String.format("店確認しました、ダイアログを表示します"),
+ Toast.LENGTH_SHORT)
+ .show();
+
+ //if(isLongClick == true) {
+ //長押し時は周辺のピンを全て取得し、ダイアログに表示する
+ DialogFragment dialogFragment = new MapsDialogFragment(shops);
+ dialogFragment.show(getActivity().getSupportFragmentManager(),"mapsdialog");
+
+ //}
});
//初期画面の座標(現在地をロードするまで表示)
//initialLatlng = new LatLng(39,138);
initialLatlng = new LatLng(nemophila.getCameraLatitude(), nemophila.getCameraLongitude());
//初期画面に移動
- //mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 15f));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, nemophila.getZoom()));
//画面が動いたとき
mMap.setOnCameraIdleListener(() -> {
+ //長押し状態を解除
+ //isLongClick = false;
//カメラの座標とZOOM倍率を保存
//nowCamera = mMap.getCameraPosition();
nemophila.setCameraLatitude(mMap.getCameraPosition().target.latitude);
nemophila.setCameraLongitude(mMap.getCameraPosition().target.longitude);
nemophila.setZoom(mMap.getCameraPosition().zoom);
-
- //nowLatlng = new LatLng(nowCamera.target.latitude, nowCamera.target.longitude);
- //nowZoom = nowCamera.zoom;
//Shopの描画範囲を指定
shopsViewModel.setViewArea(nemophila.getCameraLongitude() + 1, nemophila.getCameraLatitude() + 1, nemophila.getCameraLongitude() - 1, nemophila.getCameraLatitude() - 1);
});
- /*
- //多分使わない
+
+ // test用 座標を確認するため
// タップした時のリスナーをセット
mMap.setOnMapClickListener(tapLocation -> {
// map(ピン以外)をtapされた位置の緯度経度
tapLatlng = new LatLng(tapLocation.latitude, tapLocation.longitude);
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tapLatlng, nowZoom));
- shopsViewModel.setViewArea(tapLatlng.longitude+1, tapLatlng.latitude+1, tapLatlng.longitude-1, tapLatlng.latitude-1);
+ Toast.makeText(getActivity(),
+ String.format("%s", tapLatlng),
+ Toast.LENGTH_SHORT)
+ .show();
});
- */
+
//長押し時に店を作成し、その座標にピンを立てる
//長押し時にその座標を保存し、投稿画面に移り、Shop作成完了時にはピンを立て、Shop画面に移行
mMap.setOnMapLongClickListener(longpushLocation -> {
//長押しされた位置の緯度経度を取得
//LatLng newlocation = new LatLng(longpushLocation.latitude, longpushLocation.longitude);
+
+ //長押し座標を画面中心にしておく
+ //zoomMap(longpushLocation.latitude, longpushLocation.longitude);
//Nemophilaに座標を保存
nemophila.setCurrentLatitude(longpushLocation.latitude);
nemophila.setCurrentLongitude(longpushLocation.longitude);
//長押しした場合は今からShopを作成するので、CurrentShopをnullで登録しておく
nemophila.setCurrentShop(null);
//ShopCreate画面に遷移
- Intent intent = new Intent(getActivity(), ShopCreateActivity.class);
- startActivity(intent);
+// Intent intent = new Intent(getActivity(), ShopCreateActivity.class);
+// startActivity(intent);
+
+ //長押しでダイアログを表示
+ //isLongClick = true; //長押ししたかどうかで動作を判定するため
+ Toast.makeText(getActivity(),
+ String.format("長押しを受け取れてるよ"),
+ Toast.LENGTH_SHORT)
+ .show();
+ shopsViewModel.longClickViewArea(longpushLocation.longitude+1, longpushLocation.latitude+1, longpushLocation.longitude-1, longpushLocation.latitude-1);
+ //本番環境は↓の範囲で
+ //shopsViewModel.setViewArea(longpushLocation.longitude+0.0007, longpushLocation.latitude+0.0007, longpushLocation.longitude-0.0007, longpushLocation.latitude-0.0007);
});
// ピンをクリックした場合