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/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4f46913..b19b47f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -104,10 +104,10 @@ android:exported="true" android:label="@string/title_activity_requesting" android:windowSoftInputMode="adjustPan"> - - - - + + + + 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); }); // ピンをクリックした場合 diff --git a/app/src/main/java/com/example/nemophila/RequestedActivity.java b/app/src/main/java/com/example/nemophila/RequestedActivity.java index 6a1ef91..724535d 100644 --- a/app/src/main/java/com/example/nemophila/RequestedActivity.java +++ b/app/src/main/java/com/example/nemophila/RequestedActivity.java @@ -96,6 +96,7 @@ rv.setLayoutManager(llm); friendViewModel.getRequested(uid); + friendViewModel.getFriends(uid); friendViewModel.getRequestedLiveData().observe(this, new Observer>() { @Override public void onChanged(Collection accountNameJson) { diff --git a/app/src/main/java/com/example/nemophila/RequestingActivity.java b/app/src/main/java/com/example/nemophila/RequestingActivity.java index e8a6639..12f8900 100644 --- a/app/src/main/java/com/example/nemophila/RequestingActivity.java +++ b/app/src/main/java/com/example/nemophila/RequestingActivity.java @@ -79,23 +79,31 @@ //ViewModelからアカウントが返ってくれば(データ変更があれば)実行 @Override public void onChanged(Account user) { - requestingName = (user.getName()); + if(user == null){ + new AlertDialog.Builder(RequestingActivity.this) + .setTitle("IDが間違っています") + .setPositiveButton("OK", null) + .create() + .show(); + }else { + requestingName = (user.getName()); - //申請を送るダイアログ - RequestingDialogFragment dialog = new RequestingDialogFragment(RequestingActivity.this); - //名前を渡す - Bundle args = new Bundle(); - args.putString("message", requestingName); - dialog.setArguments(args); + //申請を送るダイアログ + RequestingDialogFragment dialog = new RequestingDialogFragment(RequestingActivity.this); + //名前を渡す + Bundle args = new Bundle(); + args.putString("message", requestingName); + dialog.setArguments(args); - //ダイアログの表示 - dialog.show(getSupportFragmentManager(), "Requesting_dialog"); - //OK押したら申請するメソッドにuid、requestingId、tokenを渡す + //ダイアログの表示 + dialog.show(getSupportFragmentManager(), "Requesting_dialog"); + //OK押したら申請するメソッドにuid、requestingId、tokenを渡す + } } - - }); } + + }); diff --git a/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java b/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java index 199c3e4..601c705 100644 --- a/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java +++ b/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java @@ -171,10 +171,16 @@ @Override public void onResponse(Call call, Response response) { if (response.isSuccessful()) { - Account ac = new Account(response.body()); - accountLiveData.setValue(ac); - System.out.println("success"); + if(response.body() == null){ + accountLiveData.setValue(null); + System.out.println("response error"); + }else { + Account ac = new Account(response.body()); + accountLiveData.setValue(ac); + System.out.println("success"); + } } else { + accountLiveData.setValue(null); System.out.println("response error"); } } diff --git a/app/src/main/java/com/example/nemophila/viewmodels/ShopsViewModel.java b/app/src/main/java/com/example/nemophila/viewmodels/ShopsViewModel.java index 88ea984..e0a8dc9 100644 --- a/app/src/main/java/com/example/nemophila/viewmodels/ShopsViewModel.java +++ b/app/src/main/java/com/example/nemophila/viewmodels/ShopsViewModel.java @@ -35,11 +35,13 @@ // ライブデータ final private MutableLiveData> shopsLiveData; + final private MutableLiveData> nearShopsLiveData; final private MutableLiveData currentShopLiveData; // コンストラクタ public ShopsViewModel() { this.shopsLiveData = new MutableLiveData<>(); + this.nearShopsLiveData = new MutableLiveData<>(); this.currentShopLiveData = new MutableLiveData<>(); this.retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/nemophila/") @@ -53,7 +55,10 @@ public LiveData> getShopsLiveData() { return this.shopsLiveData; } - public LiveData getCurrentLiveData() { return this.currentShopLiveData; } + public LiveData> getNearShopsLiveData() { return this.nearShopsLiveData; } + public LiveData getCurrentLiveData() { + return this.currentShopLiveData; + } // ShopToMarkerに新しく店と地図上のピンを紐づける public void setShopAndMarker(Shop shop, Marker marker) { @@ -61,7 +66,9 @@ } // ShopToMarkerからkeyを指定して、要素を削除する - public void removeShopAndMarker(Shop shop) { ShopToMarker.remove(shop); } + public void removeShopAndMarker(Shop shop) { + ShopToMarker.remove(shop); + } // 店に紐づいたピンを返す public Marker getMarker(Shop shop) { @@ -122,23 +129,48 @@ }); } - // 新しく店を生成する - public void createShop(String name, double longitude, double latitude) { - Call call = shopsRest.createShop(name, longitude, latitude); + public void longClickViewArea(double ux, double uy, double lx, double ly) { + // 画面内に収まる範囲の店舗を取得する + Call> call = shopsRest.getShops(ux, uy, lx, ly); - call.enqueue(new Callback() { + call.enqueue(new Callback>() { + // 通信が成功 @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call> call, Response> response) { + // 通信が正常に動作 if (response.isSuccessful()) { - currentShopLiveData.setValue(response.body()); + nearShopsLiveData.setValue(response.body()); + } else { + System.out.println("ShopsViewModel : 通信失敗"); } } + // 通信が失敗 @Override - public void onFailure(Call call, Throwable t) { - System.out.println("通信失敗 : createShop"); - System.out.println(t); - } + public void onFailure(Call> call, Throwable t) { + System.out.println("setViewModel : 通信失敗"); + System.out.println(t); + } }); } -} + + // 新しく店を生成する + public void createShop (String name,double longitude, double latitude){ + Call call = shopsRest.createShop(name, longitude, latitude); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + currentShopLiveData.setValue(response.body()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("通信失敗 : createShop"); + System.out.println(t); + } + }); + } + } diff --git a/app/src/main/res/drawable/ic_baseline_replay_24.xml b/app/src/main/res/drawable/ic_baseline_replay_24.xml new file mode 100644 index 0000000..effe564 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_replay_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_my_page_editor.xml b/app/src/main/res/layout/activity_my_page_editor.xml index 3b45611..e187d18 100644 --- a/app/src/main/res/layout/activity_my_page_editor.xml +++ b/app/src/main/res/layout/activity_my_page_editor.xml @@ -126,7 +126,7 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.023" android:background="@drawable/circle_button" - android:src="@drawable/ic_mypage" + android:src="@drawable/ic_baseline_replay_24" android:scaleType="fitCenter" android:padding="7dp" />