diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 23617fa..a13acaf 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -7,11 +7,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4934277..806593e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,7 +5,6 @@
-
-
-
+
+
-
-
+
+
{
Log.d("debug", "currentbutton, 現在地にカメラを移動");
+ //shopsViewModel.setViewArea(currentLatlng.longitude+20, currentLatlng.latitude+20.0, currentLatlng.longitude-20.0, currentLatlng.latitude-20.0);
+ System.out.println(shopsViewModel.getShopsLiveData().getValue());
//現在地にカメラを移動
zoomMap(currentLatlng.latitude, currentLatlng.longitude);
});
@@ -105,10 +116,9 @@
mMap = googleMap;
//ViewModelへのアクセス
- ShopsViewModel shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
+ shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
//ダミーショップaとcが返される座標にしておく
- //画面スクロールに応じて以下の1行を実行するようにする
- shopsViewModel.setViewArea(20.0, 40.0, 10.0, 30.0);
+ shopsViewModel.setViewArea(40.0, 140.0, 20.0, 100.0);
// LiveDataへの購読
shopsViewModel.getShopsLiveData().observe(this, shops -> {
@@ -116,6 +126,7 @@
//対応する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(""));
@@ -138,38 +149,45 @@
testLatlng2 = new LatLng(34.74, 135.26);
//初期画面の座標(現在地をロードするまで)
-// initialLatlng = new LatLng(39,138);
+ initialLatlng = new LatLng(39,138);
//店Cの座標にカメラ移動
- initialLatlng = new LatLng(34.5,12.3);
+// initialLatlng = new LatLng(34.5,12.3);
//初期画面に移動
-// mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 5f));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 15f));
//標準のマーカー(店用のピン)
- setMarker(latitude, longitude);
+ //setMarker(latitude, longitude);
//アイコン画像をマーカーに設定
//画像関連がわかっていないのでパス
//setIcon(latitude, longitude);
+ //画面が動いたとき
+ mMap.setOnCameraIdleListener(() -> {
+ //カメラの座標とZOOM倍率を保存
+ nowCamera = mMap.getCameraPosition();
+ nowLatlng = new LatLng(nowCamera.target.latitude, nowCamera.target.longitude);
+ nowZoom = nowCamera.zoom;
+ //Shopの描画範囲を指定
+ shopsViewModel.setViewArea(nowLatlng.longitude+1, nowLatlng.latitude+1, nowLatlng.longitude-1, nowLatlng.latitude-1);
+ });
+
/*
//多分使わない
// タップした時のリスナーをセット
mMap.setOnMapClickListener(tapLocation -> {
// map(ピン以外)をtapされた位置の緯度経度
- latlng = new LatLng(tapLocation.latitude, tapLocation.longitude);
- String str = String.format(Locale.US, "%f, %f", tapLocation.latitude, tapLocation.longitude);
- mMap.addMarker(new MarkerOptions().position(location).title(str));
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 18));
+ 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);
});
- */
+ */
//長押し時に店を作成し、その座標にピンを立てる
//長押し時にその座標を保存し、投稿画面に移り、Shop作成完了時にはピンを立て、Shop画面に移行
mMap.setOnMapLongClickListener(longpushLocation -> {
- // Nemophila nemophila = (Nemophila) this.getApplication();
//長押しされた位置の緯度経度を取得
//LatLng newlocation = new LatLng(longpushLocation.latitude, longpushLocation.longitude);
//Nemophilaに座標を保存
@@ -208,6 +226,9 @@
nemophila.setCurrentShop((Shop)marker.getTag());
System.out.println(nemophila.getCurrentShop().getName());
+ //ShopActivity画面に遷移
+ Intent intent = new Intent(MainActivity.this, ShopActivity.class);
+ startActivity(intent);
return false;
}
@@ -229,9 +250,6 @@
markerOptions2.title(null);
mMap.addMarker(markerOptions2);
- // ズーム
- //zoomMap(latitude, longitude);
-
}
private void zoomMap(double latitude, double longitude){
@@ -258,7 +276,7 @@
newLatLngBounds(bounds, width, height, 0));
//ズーム処理
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15f));
+ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, nowZoom));
}
//現在地の表示
@@ -356,7 +374,7 @@
public void onLocationChanged(Location location) {
//初期画面は現在地を中心にするため...
if (currentLatlng == null){
- //zoomMap(location.getLatitude(), location.getLongitude());
+ zoomMap(location.getLatitude(), location.getLongitude());
findViewById(R.id.LL_Load).setVisibility(View.GONE);
}
@@ -365,19 +383,6 @@
//LatLng型で受け取っておく
currentLatlng = new LatLng(location.getLatitude(), location.getLongitude());
- /*
- テスト用。現在座標を画面に表示
- */
-// // 緯度の表示
-// TextView textView1 = findViewById(R.id.text_view1);
-// String str1 = "Latitude:"+location.getLatitude();
-// textView1.setText(str1);
-//
-// // 経度の表示
-// TextView textView2 = findViewById(R.id.text_view2);
-// String str2 = "Longitude:"+location.getLongitude();
-// textView2.setText(str2);
-
//現在地アイコンを表示.このsetIcon内にzoomMap処理もあるので注意
setIcon(location.getLatitude(),location.getLongitude());
}
@@ -394,4 +399,4 @@
}
-}
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/MyPageActivity.java b/app/src/main/java/com/example/nemophila/MyPageActivity.java
index 973cb52..5ebf6f5 100644
--- a/app/src/main/java/com/example/nemophila/MyPageActivity.java
+++ b/app/src/main/java/com/example/nemophila/MyPageActivity.java
@@ -82,4 +82,15 @@
id.setText(uid);
}
+ protected void onResume(Bundle savedInstanceState) {
+// super.onResume(savedInstanceState);
+
+ Nemophila nemophila = (Nemophila) getApplication();
+ String uid = nemophila.getUid();
+ String name = nemophila.getName();
+ TextView myName = (TextView) findViewById(R.id.name);
+ myName.setText(name);
+ TextView id = (TextView) findViewById(R.id.id);
+ id.setText(uid);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/Nemophila.java b/app/src/main/java/com/example/nemophila/Nemophila.java
index 6b8c2be..26e5d77 100644
--- a/app/src/main/java/com/example/nemophila/Nemophila.java
+++ b/app/src/main/java/com/example/nemophila/Nemophila.java
@@ -4,14 +4,24 @@
import android.content.SharedPreferences;
import com.example.nemophila.entities.Shop;
+import com.google.type.LatLng;
public class Nemophila extends Application {
+ //アカウントのデータ
private String name;
private String uid;
private String token;
+
+ //ショップのデータ
private Shop currentShop;
private double currentLongitude;
private double currentLatitude;
+ private Shop dummyShop;
+
+ //カメラのデータ
+ private Float cameraLatitude;
+ private Float cameraLongitude;
+ private float zoom;
//Getter
@@ -45,6 +55,30 @@
public double getCurrentLatitude() {
return currentLatitude;
}
+ public Shop getDummyShop() {
+ return dummyShop;
+ }
+ public Float getCameraLatitude() {
+ if(cameraLatitude == 0){
+ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
+ cameraLatitude = preferences.getFloat("cameraLatitude", 0);
+ }
+ return cameraLatitude;
+ }
+ public Float getCameraLongitude() {
+ if(cameraLongitude == 0){
+ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
+ cameraLongitude = preferences.getFloat("cameraLongitude", 0);
+ }
+ return cameraLongitude;
+ }
+ public float getZoom() {
+ if(zoom == 0.0){
+ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
+ zoom = preferences.getFloat("zoom", 0);
+ }
+ return zoom;
+ }
//Setter
public void setName(String name) {
@@ -77,4 +111,25 @@
public void setCurrentLatitude(double currentLatitude) {
this.currentLatitude = currentLatitude;
}
+ public void setDummyShop(Shop dummyShop) {
+ this.dummyShop = dummyShop;
+ }
+ public void setCameraLatitude(Float cameraLatitude) {
+ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.putFloat("cameraLatitude", cameraLatitude);
+ this.cameraLatitude = cameraLatitude;
+ }
+ public void setCameraLongitude(Float cameraLongitude) {
+ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.putFloat("cameraLongitude", cameraLongitude);
+ this.cameraLongitude = cameraLongitude;
+ }
+ public void setZoom(float zoom) {
+ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.putFloat("zoom", zoom);
+ this.zoom = zoom;
+ }
}
diff --git a/app/src/main/java/com/example/nemophila/ShopCreateActivity.java b/app/src/main/java/com/example/nemophila/ShopCreateActivity.java
index c1b74e3..c6d2a90 100644
--- a/app/src/main/java/com/example/nemophila/ShopCreateActivity.java
+++ b/app/src/main/java/com/example/nemophila/ShopCreateActivity.java
@@ -25,29 +25,25 @@
Nemophila nemophila = (Nemophila) this.getApplication();
- // ShopsViewModelにアクセス
- ShopsViewModel shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
-
- // LiveDataへの購読
- shopsViewModel.getCurrentLiveData().observe(this, shop -> {
- // ShopActivityでどこの店についての投稿かを管理できるように更新する
- nemophila.setCurrentShop(shop);
-
- // ShopActivityへ画面遷移する
- Intent intent = new Intent(getApplication(), ShopActivity.class);
- startActivity(intent);
- });
+ // フィールド
+ Shop dummyShop = new Shop();
// 店の名前が入力されていればsidを発行し、新しくShopを生成
- Button shopCreateButton = findViewById(R.id.buttonShopCreate);
- shopCreateButton.setOnClickListener(v -> {
+ Button transitionButton = findViewById(R.id.buttonTransitionPostActivity);
+ transitionButton.setOnClickListener(v -> {
EditText nameTextBox = findViewById(R.id.editTextShopCreate);
String name = nameTextBox.getText().toString();
// 店の名前を入力されているときのみ処理を行う
if (!name.equals("")) {
- shopsViewModel.createShop(name, nemophila.getCurrentLongitude(), nemophila.getCurrentLatitude());
- shopCreateButton.setEnabled(false);
+ dummyShop.setName(name);
+ dummyShop.setLongitude(nemophila.getCurrentLongitude());
+ dummyShop.setLatitude(nemophila.getCurrentLatitude());
+ nemophila.setDummyShop(dummyShop);
+
+ // PostActivityへ画面を遷移する
+ Intent intent = new Intent(getApplication(), PostActivity.class);
+ startActivity(intent);
// 店の名前を入力されていないときToastを発行
} else {
Toast ts = Toast.makeText(ShopCreateActivity.this, "名前を入力してください", Toast.LENGTH_SHORT);
@@ -55,5 +51,12 @@
ts.show();
}
});
+
+ Button cancelButton = findViewById(R.id.buttonCancel);
+ cancelButton.setOnClickListener(v -> {
+ cancelButton.setEnabled(false);
+ Intent intent = new Intent(getApplication(), MainActivity.class);
+ startActivity(intent);
+ });
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/TestActivity.java b/app/src/main/java/com/example/nemophila/TestActivity.java
index 7a5921f..0fe08d0 100644
--- a/app/src/main/java/com/example/nemophila/TestActivity.java
+++ b/app/src/main/java/com/example/nemophila/TestActivity.java
@@ -60,7 +60,7 @@
// shopsViewModel.start(500, nemophila);
break;
case 1:
- //accountViewModel.getAccount("1111");
+ accountViewModel.getAccountPosts("1111");
break;
case 2:
postsViewModel.createPost("1114", "dbfd3740-8dcc-4b9c-b3b0-42c908da1c65", "151347fa-2c90-44d7-ba48-f23f475b910d", 1,
diff --git a/app/src/main/java/com/example/nemophila/resources/AccountsRest.java b/app/src/main/java/com/example/nemophila/resources/AccountsRest.java
index 75354d8..20af87c 100644
--- a/app/src/main/java/com/example/nemophila/resources/AccountsRest.java
+++ b/app/src/main/java/com/example/nemophila/resources/AccountsRest.java
@@ -48,7 +48,7 @@
@FormUrlEncoded
@PUT("accounts/{uid}/pw")
- Call changePw(
+ Call changePw(
@Path("uid") String uid,
@Field("oldPw") String oldPw,
@Field("newPw") String newPw,
@@ -57,7 +57,7 @@
@FormUrlEncoded
@PUT("accounts/{uid}/name")
- Call changeName(
+ Call changeName(
@Path("uid") String uid,
@Field("name") String name,
@Field("token") String 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 6820651..b484c47 100644
--- a/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java
+++ b/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java
@@ -24,7 +24,8 @@
private final AccountsRest accountsRest;
// ライブデータ
- private final MutableLiveData accountLiveData;
+ private final MutableLiveData nameLiveData;
+ private final MutableLiveData pwLiveData;
private final MutableLiveData> accountPostsLiveData;
// コンストラクタ
@@ -34,51 +35,20 @@
.addConverterFactory(JacksonConverterFactory.create())
.build();
this.accountsRest = retrofit.create(AccountsRest.class);
- this.accountLiveData = new MutableLiveData<>();
+ this.nameLiveData = new MutableLiveData<>();
+ this.pwLiveData = new MutableLiveData<>();
this.accountPostsLiveData = new MutableLiveData<>();
}
// ライブデータの取得(ゲッター)
- public MutableLiveData getAccountLiveData() { return accountLiveData; }
+ public MutableLiveData getNameLiveData() {
+ return nameLiveData;
+ }
+ public MutableLiveData getPwLiveData() {
+ return pwLiveData;
+ }
public MutableLiveData> getAccountPostsLiveData() { return accountPostsLiveData; }
- //AccountJsonからAccountを作成し,対象のライブデータに設定する
- private void setAccountLiveDataFromJson(AccountJson accountJson) {
- Account account = new Account(accountJson);
- accountLiveData.setValue(account);
- }
-
- //PostJsonからPostを作成し,対象のライブデータに設定する
- private void setAccountPostLiveDataFromJson(Collection postJson) {
- ArrayList posts = new ArrayList<>();
- for(PostJson i: postJson) {
- Post post = new Post(i);
- posts.add(post);
- }
- accountPostsLiveData.setValue(posts);
- }
-
- // 対象のアカウント情報の取得
- public void getAccount(String uid) {
- Call call = accountsRest.getAccount(uid);
-
- call.enqueue(new Callback() {
- @Override
- public void onResponse(Call call, Response response) {
- if (response.isSuccessful()) {
- AccountJson accountJson = response.body();
- setAccountLiveDataFromJson(accountJson);
- } else {
- System.out.println("response error");
- }
- }
- @Override
- public void onFailure(Call call, Throwable t) {
- System.out.println("correspondence error");
- }
- });
- }
-
// 対象のアカウント情報の削除
public void deleteAccount(String uid) {
Call call = accountsRest.deleteAccount(uid);
@@ -87,56 +57,56 @@
@Override
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
- System.out.println("successful");
+ System.out.println("DeleteAccount Successful");
} else {
- System.out.println("response error");
+ System.out.println("DeleteAccount ResponseError");
}
}
@Override
public void onFailure(Call call, Throwable t) {
- System.out.println("correspondence error");
+ System.out.println("DeleteAccount NetworkError" + t);
}
});
}
// 対象のアカウントパスワードの変更
public void changePw(String uid, String oldPw, String newPw, String token) {
- Call call = accountsRest.changePw(uid, oldPw, newPw, token);
+ Call call = accountsRest.changePw(uid, oldPw, newPw, token);
- 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()) {
- AccountJson accountJson = response.body();
- setAccountLiveDataFromJson(accountJson);
+ pwLiveData.setValue(newPw);
+ System.out.println("Success ChangePW");
} else {
System.out.println("response error");
}
}
@Override
- public void onFailure(Call call, Throwable t) {
- System.out.println("correspondence error");
+ public void onFailure(Call call, Throwable t) {
+ System.out.println("correspondence error" + t);
}
});
}
// 対象のアカウント名の変更
public void changeName(String uid, String name, String token) {
- Call call = accountsRest.changeName(uid, name, token);
+ Call call = accountsRest.changeName(uid, name, token);
- 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()) {
- AccountJson accountJson = response.body();
- setAccountLiveDataFromJson(accountJson);
+ nameLiveData.setValue(name);
+ System.out.println("Success ChangeName");
} else {
System.out.println("response error");
}
}
@Override
- public void onFailure(Call call, Throwable t) {
- System.out.println("correspondence error");
+ public void onFailure(Call call, Throwable t) {
+ System.out.println("correspondence error" + t);
}
});
}
@@ -151,17 +121,28 @@
if (response.isSuccessful()) {
Collection postJson = response.body();
setAccountPostLiveDataFromJson(postJson);
+ System.out.println("Success" + accountPostsLiveData.getValue().toString());
} else {
System.out.println("response error");
}
}
@Override
public void onFailure(Call> call, Throwable t) {
- System.out.println("correspondence error");
+ System.out.println("correspondence error" + t);
}
});
}
+ //PostJsonからPostを作成し,対象のライブデータに設定する
+ private void setAccountPostLiveDataFromJson(Collection postJson) {
+ ArrayList posts = new ArrayList<>();
+ for(PostJson pj: postJson) {
+ Post post = new Post(pj);
+ posts.add(post);
+ }
+ accountPostsLiveData.setValue(posts);
+ }
+
// 対象のアカウントがした投稿の削除
public void deleteAccountPost(String sid, String uid, String pid, String token) {
Call call = accountsRest.deletePost(sid, uid, pid, token);
@@ -177,7 +158,7 @@
}
@Override
public void onFailure(Call call, Throwable t) {
- System.out.println("correspondence error");
+ System.out.println("correspondence error" + t);
}
});
}
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 88282c9..88ea984 100644
--- a/app/src/main/java/com/example/nemophila/viewmodels/ShopsViewModel.java
+++ b/app/src/main/java/com/example/nemophila/viewmodels/ShopsViewModel.java
@@ -60,15 +60,18 @@
ShopToMarker.put(shop, marker);
}
+ // ShopToMarkerからkeyを指定して、要素を削除する
+ public void removeShopAndMarker(Shop shop) { ShopToMarker.remove(shop); }
+
// 店に紐づいたピンを返す
public Marker getMarker(Shop shop) {
return ShopToMarker.get(shop);
}
+ // TimerViewModelを利用して、定期的にMainActivityに呼び出してもらう
@Override
public void update() {
updateShops();
- // System.out.println("hogehoge");
}
// 画面を動かす, 又はGPSが移動する度に呼び出される
@@ -119,6 +122,7 @@
});
}
+ // 新しく店を生成する
public void createShop(String name, double longitude, double latitude) {
Call call = shopsRest.createShop(name, longitude, latitude);
diff --git a/app/src/main/res/layout/activity_shop_create.xml b/app/src/main/res/layout/activity_shop_create.xml
index 15c2449..49640ec 100644
--- a/app/src/main/res/layout/activity_shop_create.xml
+++ b/app/src/main/res/layout/activity_shop_create.xml
@@ -8,16 +8,16 @@
+ app:layout_constraintVertical_bias="0.125" />
-
+ app:layout_constraintVertical_bias="0.041" />
\ No newline at end of file