diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 498ac9e..d6fdd9e 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -12,6 +12,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 743778d..4343ab5 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,10 +12,15 @@
+
+
+
+
+
@@ -34,8 +39,6 @@
-
-
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 53f8b18..0407368 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -82,9 +82,16 @@
+
+ android:exported="true"
+ android:label="@string/title_activity_requested">
+
+
+
+
+
diff --git a/app/src/main/java/com/example/nemophila/FriendActivity.java b/app/src/main/java/com/example/nemophila/FriendActivity.java
index d611634..dbca5a6 100644
--- a/app/src/main/java/com/example/nemophila/FriendActivity.java
+++ b/app/src/main/java/com/example/nemophila/FriendActivity.java
@@ -11,11 +11,14 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.graphics.Color;
+import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -28,6 +31,7 @@
import java.util.List;
public class FriendActivity extends AppCompatActivity {
+ private Nemophila nemophila;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -37,7 +41,7 @@
List friendsDataset = new ArrayList<>(); // 1行分の情報を持つDataModelを格納するリスト
RecyclerView rv = findViewById(R.id.friendsList); // recyclerViewを取得
FriendViewModel friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class); // ViewModelを取得
- Nemophila nemophila = (Nemophila) this.getApplication();
+ nemophila = (Nemophila) this.getApplication();
//一行ずつを縦に(LinearLayout)表示するLayoutManagerを宣言
@@ -69,6 +73,18 @@
.create()
.show();
}
+
+ @Override
+ void onFavoriteClick(View view, int position, FriendDataModel friend, ImageView favorite) {
+ if (favorite.getVisibility() == View.INVISIBLE) {
+ favorite.setVisibility(View.VISIBLE);
+ nemophila.setFavoriteFriends(friend.getId());
+ } else {
+ favorite.setVisibility(View.INVISIBLE);
+ nemophila.removeFavoriteFriends(friend.getId());
+ System.out.println(nemophila.getFavoriteFriends());
+ }
+ }
};
friendViewModel.getFriends(myUid); // 自身のフレンドの一覧を取得するメソッドを呼び出す
@@ -102,14 +118,14 @@
// ----------- RecyclerView用の内部クラス ------------//
// Adapter
abstract public class FriendActivityAdapter extends RecyclerView.Adapter {
- private List friendDatas;
+ private List friendData;
- public FriendActivityAdapter(List friendDatas) {
- this.friendDatas = friendDatas;
+ public FriendActivityAdapter(List friendData) {
+ this.friendData = friendData;
}
- public void setList(List friendDatas) {
- this.friendDatas = friendDatas;
+ public void setList(List friendData) {
+ this.friendData = friendData;
}
@NonNull
@@ -120,13 +136,23 @@
// ViewHolderを生成
FriendsViewHolder vh = new FriendsViewHolder(inflate);
- // クリックイベントを登録
+ // 削除ボタンを押したときのイベントを登録
vh.deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = vh.getBindingAdapterPosition();
- // 処理はonItemClick()に丸投げ
- onDeleteClick(v, position, friendDatas.get(position));
+ // 処理はonDeleteClick()に丸投げ
+ onDeleteClick(v, position, friendData.get(position));
+ }
+ });
+
+ // お気に入りに追加したときのイベントを登録
+ vh.favoriteOutline.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ int position = vh.getBindingAdapterPosition();
+ // 処理はonFavoriteClick()に丸投げ
+ onFavoriteClick(v, position, friendData.get(position), vh.favorite);
}
});
@@ -136,25 +162,33 @@
@Override
public void onBindViewHolder(@NonNull FriendsViewHolder holder, int position) {
// 後からアイコンの登録をできるようにする
- holder.nameView.setText(friendDatas.get(position).getName());
+ holder.nameView.setText(friendData.get(position).getName());
+ if (nemophila.getFavoriteFriends().contains(friendData.get(position).getId())) {
+ holder.favorite.setVisibility(View.VISIBLE);
+ }
}
@Override
public int getItemCount() {
- return friendDatas.size();
+ return friendData.size();
}
abstract void onDeleteClick(View view, int position, FriendDataModel friend);
+ abstract void onFavoriteClick(View view, int position, FriendDataModel friend, ImageView favorite);
}
// ViewHolder
public class FriendsViewHolder extends RecyclerView.ViewHolder {
+ public ImageView favorite;
+ public ImageButton favoriteOutline;
public ImageView iconView;
public TextView nameView;
public Button deleteButton;
public FriendsViewHolder(@NonNull View itemView) {
super(itemView);
+ favorite = itemView.findViewById(R.id.favorite);
+ favoriteOutline = itemView.findViewById(R.id.favorite_outline);
iconView = itemView.findViewById(R.id.friendIcon);
nameView = itemView.findViewById(R.id.friendName);
deleteButton = itemView.findViewById(R.id.friendDelete);
diff --git a/app/src/main/java/com/example/nemophila/LoginActivity.java b/app/src/main/java/com/example/nemophila/LoginActivity.java
index 033fa07..7e63aa1 100644
--- a/app/src/main/java/com/example/nemophila/LoginActivity.java
+++ b/app/src/main/java/com/example/nemophila/LoginActivity.java
@@ -26,6 +26,11 @@
private AccountsRest AccountsRest;
private Nemophila nemophila;
+ //座標指定
+ private double defaultLat = 34.74;
+ private double defaultLong = 135.26;
+ private float defaultZoom = 15f;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -35,6 +40,11 @@
nemophila = (Nemophila) this.getApplication();
//Nemophilaにtokenとuidがある場合ログイン画面をスキップ
if ((nemophila.getUid() != null) && (nemophila.getToken() != null)){
+ //座標指定(仮)
+ nemophila.setCameraLatitude(defaultLat);
+ nemophila.setCameraLongitude(defaultLong);
+ nemophila.setZoom(defaultZoom);
+
Intent intent = new Intent(LoginActivity.this,MapsActivity.class);
startActivity(intent);
return;
@@ -71,6 +81,11 @@
nemophila.setUid(response.body().getId());
nemophila.setToken(response.body().getToken());
+ //座標指定(仮)
+ nemophila.setCameraLatitude(defaultLat);
+ nemophila.setCameraLongitude(defaultLong);
+ nemophila.setZoom(defaultZoom);
+
//mainに画面遷移
Intent intent = new Intent(LoginActivity.this,MapsActivity.class);
startActivity(intent);
diff --git a/app/src/main/java/com/example/nemophila/MainActivity.java b/app/src/main/java/com/example/nemophila/MainActivity.java
index 595597b..57930f1 100644
--- a/app/src/main/java/com/example/nemophila/MainActivity.java
+++ b/app/src/main/java/com/example/nemophila/MainActivity.java
@@ -1,388 +1,388 @@
-package com.example.nemophila;
-
-import androidx.fragment.app.FragmentActivity;
-
-import androidx.activity.result.ActivityResultLauncher;
-import androidx.activity.result.contract.ActivityResultContracts;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
-import androidx.lifecycle.ViewModelProvider;
-
-import android.app.ProgressDialog;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.ImageButton;
-import android.widget.Toast;
-import android.annotation.SuppressLint;
-import android.content.pm.PackageManager;
-import android.location.Location;
-import android.location.LocationListener;
-import android.location.LocationManager;
-import android.content.Intent;
-import android.provider.Settings;
-import android.util.Log;
-import android.Manifest;
-
-import com.example.nemophila.entities.Shop;
-import com.example.nemophila.viewmodels.ShopsViewModel;
-import com.google.android.gms.maps.CameraUpdateFactory;
-import com.google.android.gms.maps.GoogleMap;
-import com.google.android.gms.maps.OnMapReadyCallback;
-import com.google.android.gms.maps.SupportMapFragment;
-import com.google.android.gms.maps.model.BitmapDescriptor;
-import com.google.android.gms.maps.model.BitmapDescriptorFactory;
-import com.google.android.gms.maps.model.CameraPosition;
-import com.google.android.gms.maps.model.GroundOverlay;
-import com.google.android.gms.maps.model.GroundOverlayOptions;
-import com.google.android.gms.maps.model.LatLng;
-import com.google.android.gms.maps.model.LatLngBounds;
-import com.google.android.gms.maps.model.Marker;
-import com.google.android.gms.maps.model.MarkerOptions;
-import com.example.nemophila.databinding.ActivityMainBinding;
-
-import java.util.Locale;
-
-public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
- ShopsViewModel shopsViewModel;
-
- Nemophila nemophila;
- private GoogleMap mMap;
- private ActivityMainBinding binding;
- private LatLng currentLatlng = null;
- private LatLng initialLatlng;
- private LatLng shopLatlng;
- private LatLng testLatlng;
- private LatLng testLatlng2;
- private LatLng tapLatlng;
- private CameraPosition nowCamera;
- private LatLng nowLatlng;
-
- private GroundOverlay currentOverlay;
- LocationManager locationManager;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
-
- binding = ActivityMainBinding.inflate(getLayoutInflater());
- setContentView(binding.getRoot());
+//package com.example.nemophila;
//
-// nemophila = (Nemophila) this.getApplication();
+//import androidx.fragment.app.FragmentActivity;
//
-// ImageButton myPageButton = findViewById(R.id.myPageButton);
-// // lambda式
-// myPageButton.setOnClickListener( v -> {
-// Log.d("debug", "myPageButton, マイページに画面遷移");
-// Intent intent = new Intent(MainActivity.this, MyPageActivity.class);
+//import androidx.activity.result.ActivityResultLauncher;
+//import androidx.activity.result.contract.ActivityResultContracts;
+//import androidx.core.app.ActivityCompat;
+//import androidx.core.content.ContextCompat;
+//import androidx.lifecycle.ViewModelProvider;
+//
+//import android.app.ProgressDialog;
+//import android.os.Bundle;
+//import android.view.View;
+//import android.widget.ImageButton;
+//import android.widget.Toast;
+//import android.annotation.SuppressLint;
+//import android.content.pm.PackageManager;
+//import android.location.Location;
+//import android.location.LocationListener;
+//import android.location.LocationManager;
+//import android.content.Intent;
+//import android.provider.Settings;
+//import android.util.Log;
+//import android.Manifest;
+//
+//import com.example.nemophila.entities.Shop;
+//import com.example.nemophila.viewmodels.ShopsViewModel;
+//import com.google.android.gms.maps.CameraUpdateFactory;
+//import com.google.android.gms.maps.GoogleMap;
+//import com.google.android.gms.maps.OnMapReadyCallback;
+//import com.google.android.gms.maps.SupportMapFragment;
+//import com.google.android.gms.maps.model.BitmapDescriptor;
+//import com.google.android.gms.maps.model.BitmapDescriptorFactory;
+//import com.google.android.gms.maps.model.CameraPosition;
+//import com.google.android.gms.maps.model.GroundOverlay;
+//import com.google.android.gms.maps.model.GroundOverlayOptions;
+//import com.google.android.gms.maps.model.LatLng;
+//import com.google.android.gms.maps.model.LatLngBounds;
+//import com.google.android.gms.maps.model.Marker;
+//import com.google.android.gms.maps.model.MarkerOptions;
+//import com.example.nemophila.databinding.ActivityMainBinding;
+//
+//import java.util.Locale;
+//
+//public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
+// ShopsViewModel shopsViewModel;
+//
+// Nemophila nemophila;
+// private GoogleMap mMap;
+// private ActivityMainBinding binding;
+// private LatLng currentLatlng = null;
+// private LatLng initialLatlng;
+// private LatLng shopLatlng;
+// private LatLng testLatlng;
+// private LatLng testLatlng2;
+// private LatLng tapLatlng;
+// private CameraPosition nowCamera;
+// private LatLng nowLatlng;
+//
+// private GroundOverlay currentOverlay;
+// LocationManager locationManager;
+//
+//
+// @Override
+// protected void onCreate(Bundle savedInstanceState) {
+// super.onCreate(savedInstanceState);
+// shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
+//
+// binding = ActivityMainBinding.inflate(getLayoutInflater());
+// setContentView(binding.getRoot());
+////
+//// nemophila = (Nemophila) this.getApplication();
+////
+//// ImageButton myPageButton = findViewById(R.id.myPageButton);
+//// // lambda式
+//// myPageButton.setOnClickListener( v -> {
+//// Log.d("debug", "myPageButton, マイページに画面遷移");
+//// Intent intent = new Intent(MainActivity.this, MyPageActivity.class);
+//// startActivity(intent);
+//// });
+//
+//
+// if (ActivityCompat.checkSelfPermission(this,
+// Manifest.permission.ACCESS_FINE_LOCATION)
+// != PackageManager.PERMISSION_GRANTED) {
+//
+// requestPermissionLauncher.launch(
+// Manifest.permission.ACCESS_FINE_LOCATION);
+// }
+// else{
+// locationStart();
+// }
+//
+// // Obtain the SupportMapFragment and get notified when the map is ready to be used.
+// SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
+// .findFragmentById(R.id.map);
+// assert mapFragment != null;
+// mapFragment.getMapAsync(this);
+//
+// }
+//
+// @Override
+// public void onMapReady(GoogleMap googleMap) {
+// mMap = googleMap;
+//
+// //ViewModelへのアクセス
+// shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
+//
+// // LiveDataへの購読
+// shopsViewModel.getShopsLiveData().observe(this, 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);
+// }
+// }
+//
+// });
+//
+///*
+// //研究室周辺の緯度経度
+// double latitude = 34.7308032;
+// double longitude = 135.2630272;
+//
+// //テスト用,仮ピン立て
+// testLatlng = new LatLng(latitude, longitude);
+// testLatlng2 = new LatLng(34.74, 135.26);
+//
+// //店Cの座標にカメラ移動
+// //initialLatlng = new LatLng(34.5,12.3);
+//
+// //標準のマーカー(店用のピン)
+// //setMarker(latitude, longitude);
+//
+// //アイコン画像をマーカーに設定
+// //画像関連がわかっていないのでパス
+// //setIcon(latitude, longitude);
+// */
+//
+// //初期画面の座標(現在地をロードするまで表示)
+// //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(() -> {
+// //カメラの座標と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);
+// });
+//
+// /*
+// //多分使わない
+// // タップした時のリスナーをセット
+// 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);
+// });
+// */
+//
+// //長押し時に店を作成し、その座標にピンを立てる
+// //長押し時にその座標を保存し、投稿画面に移り、Shop作成完了時にはピンを立て、Shop画面に移行
+// mMap.setOnMapLongClickListener(longpushLocation -> {
+// //長押しされた位置の緯度経度を取得
+// //LatLng newlocation = new LatLng(longpushLocation.latitude, longpushLocation.longitude);
+// //Nemophilaに座標を保存
+// nemophila.setCurrentLatitude(longpushLocation.latitude);
+// nemophila.setCurrentLongitude(longpushLocation.longitude);
+// //長押しした場合は今からShopを作成するので、CurrentShopをnullで登録しておく
+// nemophila.setCurrentShop(null);
+// //ShopCreate画面に遷移
+// Intent intent = new Intent(MainActivity.this, ShopCreateActivity.class);
// startActivity(intent);
// });
-
-
- if (ActivityCompat.checkSelfPermission(this,
- Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
-
- requestPermissionLauncher.launch(
- Manifest.permission.ACCESS_FINE_LOCATION);
- }
- else{
- locationStart();
- }
-
- // Obtain the SupportMapFragment and get notified when the map is ready to be used.
- SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
- .findFragmentById(R.id.map);
- assert mapFragment != null;
- mapFragment.getMapAsync(this);
-
- }
-
- @Override
- public void onMapReady(GoogleMap googleMap) {
- mMap = googleMap;
-
- //ViewModelへのアクセス
- shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
-
- // LiveDataへの購読
- shopsViewModel.getShopsLiveData().observe(this, 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);
- }
- }
-
- });
-
-/*
- //研究室周辺の緯度経度
- double latitude = 34.7308032;
- double longitude = 135.2630272;
-
- //テスト用,仮ピン立て
- testLatlng = new LatLng(latitude, longitude);
- testLatlng2 = new LatLng(34.74, 135.26);
-
- //店Cの座標にカメラ移動
- //initialLatlng = new LatLng(34.5,12.3);
-
- //標準のマーカー(店用のピン)
- //setMarker(latitude, longitude);
-
- //アイコン画像をマーカーに設定
- //画像関連がわかっていないのでパス
- //setIcon(latitude, longitude);
- */
-
- //初期画面の座標(現在地をロードするまで表示)
- //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(() -> {
- //カメラの座標と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);
- });
-
- /*
- //多分使わない
- // タップした時のリスナーをセット
- 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);
- });
- */
-
- //長押し時に店を作成し、その座標にピンを立てる
- //長押し時にその座標を保存し、投稿画面に移り、Shop作成完了時にはピンを立て、Shop画面に移行
- mMap.setOnMapLongClickListener(longpushLocation -> {
- //長押しされた位置の緯度経度を取得
- //LatLng newlocation = new LatLng(longpushLocation.latitude, longpushLocation.longitude);
- //Nemophilaに座標を保存
- nemophila.setCurrentLatitude(longpushLocation.latitude);
- nemophila.setCurrentLongitude(longpushLocation.longitude);
- //長押しした場合は今からShopを作成するので、CurrentShopをnullで登録しておく
- nemophila.setCurrentShop(null);
- //ShopCreate画面に遷移
- Intent intent = new Intent(MainActivity.this, ShopCreateActivity.class);
- startActivity(intent);
- });
-
- // ピンをクリックした場合
- mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
- @Override
- public boolean onMarkerClick(Marker marker) {
- //店の詳細と投稿一覧を表示
- //ここでshopActivityを呼び出す
-
- //下からクリックしたことを通知
- Toast.makeText(MainActivity.this, "ピンクリック", Toast.LENGTH_SHORT).show();
- //選んだ店をsetする(現状はnullになっているが後で直す)
- nemophila.setCurrentShop((Shop)marker.getTag());
- System.out.println(nemophila.getCurrentShop().getName());
-
- //ShopActivity画面に遷移
- Intent intent = new Intent(MainActivity.this, ShopActivity.class);
- startActivity(intent);
-
- return false;
- }
- });
-
- }
-
- //起動時から立っているピンの設定。完成時不要
- private void setMarker(double latitude, double longitude){
- MarkerOptions markerOptions = new MarkerOptions();
- MarkerOptions markerOptions2 = new MarkerOptions();
-
- markerOptions.position(testLatlng);
- markerOptions.title("ntlab");
- mMap.addMarker(markerOptions);
-
- //テスト用
- markerOptions2.position(testLatlng2);
- markerOptions2.title(null);
- mMap.addMarker(markerOptions2);
-
- }
-
- private void zoomMap(double latitude, double longitude){
- // 表示する東西南北の緯度経度を設定
- double south = latitude * (1-0.00005);
- double west = longitude * (1-0.00005);
- double north = latitude * (1+0.00005);
- double east = longitude * (1+0.00005);
-
- LatLng latlng = new LatLng(latitude,longitude);
-
- // LatLngBounds (LatLng southwest, LatLng northeast)
- //左下、右上
- LatLngBounds bounds = LatLngBounds.builder()
- .include(new LatLng(south , west))
- .include(new LatLng(north, east))
- .build();
-
- int width = getResources().getDisplayMetrics().widthPixels;
- int height = getResources().getDisplayMetrics().heightPixels;
-
- // static CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int height, int padding)
- mMap.moveCamera(CameraUpdateFactory.
- newLatLngBounds(bounds, width, height, 0));
-
- //ズーム処理
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, nemophila.getZoom()));
- }
-
- //現在地の表示
- private void setIcon(double latitude, double longitude){
- //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.icon_current,null);
- //更新前の現在地アイコンを消去
- if(currentOverlay != null) {
- currentOverlay.remove();
- }
-
- LatLng current_location = new LatLng(latitude,longitude);
-
- // マップに貼り付ける BitmapDescriptor生成
- BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(R.drawable.icon_current);
- //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_current_location,null);
-
- // 貼り付設定
- GroundOverlayOptions overlayOptions = new GroundOverlayOptions();
- overlayOptions.image(descriptor);
-
- //public GroundOverlayOptions anchor (float u, float v)
- // (0,0):top-left, (0,1):bottom-left, (1,0):top-right, (1,1):bottom-right
- overlayOptions.anchor(0.5f, 0.5f);
-
- // 張り付け画像の大きさ メートル単位
- // public GroundOverlayOptions position(LatLng location, float width, float height)
- overlayOptions.position(current_location, 200f, 200f);
-
- // マップに貼り付け・アルファを設定
- currentOverlay = mMap.addGroundOverlay(overlayOptions);
-
- // 透明度
- assert currentOverlay != null;
- currentOverlay.setTransparency(0.8F);
- }
-
-
- private final ActivityResultLauncher
- requestPermissionLauncher = registerForActivityResult(
- new ActivityResultContracts.RequestPermission(),
- isGranted -> {
- if (isGranted) {
- locationStart();
- }
- else {
- Toast toast = Toast.makeText(this,
- "これ以上なにもできません", Toast.LENGTH_SHORT);
- toast.show();
- }
- });
-
- //現在地の取得
- @SuppressLint("MissingPermission")
- private void locationStart(){
- Log.d("debug","locationStart()");
-
- // LocationManager インスタンス生成
- locationManager =
- (LocationManager) getSystemService(LOCATION_SERVICE);
-
- if (locationManager != null && locationManager.isProviderEnabled(
- LocationManager.GPS_PROVIDER)) {
-
- Log.d("debug", "location manager Enabled");
- } else {
- // GPSを設定するように促す
- Intent settingsIntent =
- new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
- startActivity(settingsIntent);
- Log.d("debug", "not gpsEnable, startActivity");
- }
-
- if (ContextCompat.checkSelfPermission(this,
- Manifest.permission.ACCESS_FINE_LOCATION) !=
- PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
-
- Log.d("debug", "checkSelfPermission false");
- return;
- }
-
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
- 1000, 50, this);
-
- }
-
- @Override
- public void onLocationChanged(Location location) {
- //初期画面は現在地を中心にするため...
- if (currentLatlng == null){
- //↓現在地ロード後画面中心を現在地にする場合
- //zoomMap(location.getLatitude(), location.getLongitude());
- //ロード画面の終了
- findViewById(R.id.LL_Load).setVisibility(View.GONE);
-
- //現在地ボタンを表示
- findViewById(R.id.currentButton).setVisibility(View.VISIBLE);
- ImageButton button1 = findViewById(R.id.currentButton);
-
- button1.setOnClickListener( v -> {
- Log.d("debug", "currentbutton, 現在地にカメラを移動");
- System.out.println(shopsViewModel.getShopsLiveData().getValue());
- //現在地にカメラを移動
- zoomMap(currentLatlng.latitude, currentLatlng.longitude);
- });
- }
-
- //現在地が変更されるたびに現在地アイコンを移動
- //LatLng型で受け取っておく
- currentLatlng = new LatLng(location.getLatitude(), location.getLongitude());
-
- //現在地アイコンを表示.このsetIcon内にzoomMap処理もあるので注意
- setIcon(location.getLatitude(),location.getLongitude());
- }
-
-
-
- @Override
- public void onProviderEnabled(String provider) {
-
- }
-
- @Override
- public void onProviderDisabled(String provider) {
-
- }
-
-}
\ No newline at end of file
+//
+// // ピンをクリックした場合
+// mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
+// @Override
+// public boolean onMarkerClick(Marker marker) {
+// //店の詳細と投稿一覧を表示
+// //ここでshopActivityを呼び出す
+//
+// //下からクリックしたことを通知
+// Toast.makeText(MainActivity.this, "ピンクリック", Toast.LENGTH_SHORT).show();
+// //選んだ店をsetする(現状はnullになっているが後で直す)
+// nemophila.setCurrentShop((Shop)marker.getTag());
+// System.out.println(nemophila.getCurrentShop().getName());
+//
+// //ShopActivity画面に遷移
+// Intent intent = new Intent(MainActivity.this, ShopActivity.class);
+// startActivity(intent);
+//
+// return false;
+// }
+// });
+//
+// }
+//
+// //起動時から立っているピンの設定。完成時不要
+// private void setMarker(double latitude, double longitude){
+// MarkerOptions markerOptions = new MarkerOptions();
+// MarkerOptions markerOptions2 = new MarkerOptions();
+//
+// markerOptions.position(testLatlng);
+// markerOptions.title("ntlab");
+// mMap.addMarker(markerOptions);
+//
+// //テスト用
+// markerOptions2.position(testLatlng2);
+// markerOptions2.title(null);
+// mMap.addMarker(markerOptions2);
+//
+// }
+//
+// private void zoomMap(double latitude, double longitude){
+// // 表示する東西南北の緯度経度を設定
+// double south = latitude * (1-0.00005);
+// double west = longitude * (1-0.00005);
+// double north = latitude * (1+0.00005);
+// double east = longitude * (1+0.00005);
+//
+// LatLng latlng = new LatLng(latitude,longitude);
+//
+// // LatLngBounds (LatLng southwest, LatLng northeast)
+// //左下、右上
+// LatLngBounds bounds = LatLngBounds.builder()
+// .include(new LatLng(south , west))
+// .include(new LatLng(north, east))
+// .build();
+//
+// int width = getResources().getDisplayMetrics().widthPixels;
+// int height = getResources().getDisplayMetrics().heightPixels;
+//
+// // static CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int height, int padding)
+// mMap.moveCamera(CameraUpdateFactory.
+// newLatLngBounds(bounds, width, height, 0));
+//
+// //ズーム処理
+// mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, nemophila.getZoom()));
+// }
+//
+// //現在地の表示
+// private void setIcon(double latitude, double longitude){
+// //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.icon_current,null);
+// //更新前の現在地アイコンを消去
+// if(currentOverlay != null) {
+// currentOverlay.remove();
+// }
+//
+// LatLng current_location = new LatLng(latitude,longitude);
+//
+// // マップに貼り付ける BitmapDescriptor生成
+// BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(R.drawable.icon_current);
+// //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_current_location,null);
+//
+// // 貼り付設定
+// GroundOverlayOptions overlayOptions = new GroundOverlayOptions();
+// overlayOptions.image(descriptor);
+//
+// //public GroundOverlayOptions anchor (float u, float v)
+// // (0,0):top-left, (0,1):bottom-left, (1,0):top-right, (1,1):bottom-right
+// overlayOptions.anchor(0.5f, 0.5f);
+//
+// // 張り付け画像の大きさ メートル単位
+// // public GroundOverlayOptions position(LatLng location, float width, float height)
+// overlayOptions.position(current_location, 200f, 200f);
+//
+// // マップに貼り付け・アルファを設定
+// currentOverlay = mMap.addGroundOverlay(overlayOptions);
+//
+// // 透明度
+// assert currentOverlay != null;
+// currentOverlay.setTransparency(0.8F);
+// }
+//
+//
+// private final ActivityResultLauncher
+// requestPermissionLauncher = registerForActivityResult(
+// new ActivityResultContracts.RequestPermission(),
+// isGranted -> {
+// if (isGranted) {
+// locationStart();
+// }
+// else {
+// Toast toast = Toast.makeText(this,
+// "これ以上なにもできません", Toast.LENGTH_SHORT);
+// toast.show();
+// }
+// });
+//
+// //現在地の取得
+// @SuppressLint("MissingPermission")
+// private void locationStart(){
+// Log.d("debug","locationStart()");
+//
+// // LocationManager インスタンス生成
+// locationManager =
+// (LocationManager) getSystemService(LOCATION_SERVICE);
+//
+// if (locationManager != null && locationManager.isProviderEnabled(
+// LocationManager.GPS_PROVIDER)) {
+//
+// Log.d("debug", "location manager Enabled");
+// } else {
+// // GPSを設定するように促す
+// Intent settingsIntent =
+// new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+// startActivity(settingsIntent);
+// Log.d("debug", "not gpsEnable, startActivity");
+// }
+//
+// if (ContextCompat.checkSelfPermission(this,
+// Manifest.permission.ACCESS_FINE_LOCATION) !=
+// PackageManager.PERMISSION_GRANTED) {
+// ActivityCompat.requestPermissions(this,
+// new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
+//
+// Log.d("debug", "checkSelfPermission false");
+// return;
+// }
+//
+// locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
+// 1000, 50, this);
+//
+// }
+//
+// @Override
+// public void onLocationChanged(Location location) {
+// //初期画面は現在地を中心にするため...
+// if (currentLatlng == null){
+// //↓現在地ロード後画面中心を現在地にする場合
+// //zoomMap(location.getLatitude(), location.getLongitude());
+// //ロード画面の終了
+// findViewById(R.id.LL_Load).setVisibility(View.GONE);
+//
+// //現在地ボタンを表示
+// findViewById(R.id.currentButton).setVisibility(View.VISIBLE);
+// ImageButton button1 = findViewById(R.id.currentButton);
+//
+// button1.setOnClickListener( v -> {
+// Log.d("debug", "currentbutton, 現在地にカメラを移動");
+// System.out.println(shopsViewModel.getShopsLiveData().getValue());
+// //現在地にカメラを移動
+// zoomMap(currentLatlng.latitude, currentLatlng.longitude);
+// });
+// }
+//
+// //現在地が変更されるたびに現在地アイコンを移動
+// //LatLng型で受け取っておく
+// currentLatlng = new LatLng(location.getLatitude(), location.getLongitude());
+//
+// //現在地アイコンを表示.このsetIcon内にzoomMap処理もあるので注意
+// setIcon(location.getLatitude(),location.getLongitude());
+// }
+//
+//
+//
+// @Override
+// public void onProviderEnabled(String provider) {
+//
+// }
+//
+// @Override
+// public void onProviderDisabled(String provider) {
+//
+// }
+//
+//}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/MapsFragment.java b/app/src/main/java/com/example/nemophila/MapsFragment.java
index c9db8c8..a1c429c 100644
--- a/app/src/main/java/com/example/nemophila/MapsFragment.java
+++ b/app/src/main/java/com/example/nemophila/MapsFragment.java
@@ -6,6 +6,7 @@
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
@@ -13,6 +14,10 @@
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@@ -43,6 +48,8 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.common.collect.Maps;
+import java.util.Map;
+
public class MapsFragment extends Fragment implements LocationListener {
ShopsViewModel shopsViewModel;
@@ -52,13 +59,15 @@
private LatLng currentLatlng = null;
private LatLng initialLatlng;
private LatLng shopLatlng;
- private LatLng testLatlng;
- private LatLng testLatlng2;
- private LatLng tapLatlng;
- private CameraPosition nowCamera;
- private LatLng nowLatlng;
+// private LatLng testLatlng;
+// private LatLng testLatlng2;
+// private LatLng tapLatlng;
+// private CameraPosition nowCamera;
+// private LatLng nowLatlng;
+ private Marker currentMarker;
+ private BitmapDescriptor bd;
- private GroundOverlay currentOverlay;
+
LocationManager locationManager;
private OnMapReadyCallback callback = new OnMapReadyCallback() {
@@ -89,29 +98,8 @@
shopsViewModel.setShopAndMarker(shop, createMaker);
}
}
-
});
-// binding = ActivityMainBinding.inflate(getLayoutInflater());
-// getActivity().setContentView(binding.getRoot());
-//
-// if (ActivityCompat.checkSelfPermission(getContext(),
-// Manifest.permission.ACCESS_FINE_LOCATION)
-// != PackageManager.PERMISSION_GRANTED) {
-//
-// requestPermissionLauncher.launch(
-// Manifest.permission.ACCESS_FINE_LOCATION);
-// }
-// else{
-// locationStart();
-// }
-
- // Obtain the SupportMapFragment and get notified when the map is ready to be used.
-// SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager()
-// .findFragmentById(R.id.map);
-// assert mapFragment != null;
-// mapFragment.getMapAsync(this);
-
//初期画面の座標(現在地をロードするまで表示)
//initialLatlng = new LatLng(39,138);
initialLatlng = new LatLng(nemophila.getCameraLatitude(), nemophila.getCameraLongitude());
@@ -168,8 +156,15 @@
//ここでshopActivityを呼び出す
//下からクリックしたことを通知
- Toast.makeText(getActivity(), "ピンクリック", Toast.LENGTH_SHORT).show();
- //選んだ店をsetする(現状はnullになっているが後で直す)
+ //Toast.makeText(getActivity(), "ピンクリック", Toast.LENGTH_SHORT).show();
+
+ //現在地マーカーをクリックしたときのみ例外
+ if(marker.getTag() == null) {
+ //以下の処理をストップ
+ return false;
+ }
+
+ //選んだ店をsetする
nemophila.setCurrentShop((Shop) marker.getTag());
System.out.println(nemophila.getCurrentShop().getName());
@@ -218,12 +213,16 @@
// assert mapFragment != null;
// mapFragment.getMapAsync(this);
-
SupportMapFragment mapFragment =
(SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
if (mapFragment != null) {
mapFragment.getMapAsync(callback);
}
+
+ //現在地アイコン用の準備
+ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_current);
+ Bitmap afterBitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
+ bd = BitmapDescriptorFactory.fromBitmap(afterBitmap);
}
@@ -256,36 +255,39 @@
//現在地の表示
private void setIcon(double latitude, double longitude) {
- //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.icon_current,null);
- //更新前の現在地アイコンを消去
- if (currentOverlay != null) {
- currentOverlay.remove();
- }
-
+ //現在地をLatLng型で取得
LatLng current_location = new LatLng(latitude, longitude);
- // マップに貼り付ける BitmapDescriptor生成
- BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(R.drawable.icon_current);
- //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_current_location,null);
-
- // 貼り付設定
- GroundOverlayOptions overlayOptions = new GroundOverlayOptions();
- overlayOptions.image(descriptor);
-
- //public GroundOverlayOptions anchor (float u, float v)
- // (0,0):top-left, (0,1):bottom-left, (1,0):top-right, (1,1):bottom-right
- overlayOptions.anchor(0.5f, 0.5f);
-
- // 張り付け画像の大きさ メートル単位
- // public GroundOverlayOptions position(LatLng location, float width, float height)
- overlayOptions.position(current_location, 200f, 200f);
-
- // マップに貼り付け・アルファを設定
- currentOverlay = mMap.addGroundOverlay(overlayOptions);
-
- // 透明度
- assert currentOverlay != null;
- currentOverlay.setTransparency(0.8F);
+ //初回現在地取得時
+ if (currentMarker == null) {
+ currentMarker=mMap.addMarker(new MarkerOptions().position(current_location).title("現在地").icon(bd));
+ } else {
+ //2回目移行
+ currentMarker.setPosition(current_location);
+ }
+//
+// // マップに貼り付ける BitmapDescriptor生成
+// BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(R.drawable.icon_current);
+// //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_current_location,null);
+//
+// // 貼り付設定
+// GroundOverlayOptions overlayOptions = new GroundOverlayOptions();
+// overlayOptions.image(descriptor);
+//
+// //public GroundOverlayOptions anchor (float u, float v)
+// // (0,0):top-left, (0,1):bottom-left, (1,0):top-right, (1,1):bottom-right
+// overlayOptions.anchor(0.5f, 0.5f);
+//
+// // 張り付け画像の大きさ メートル単位
+// // public GroundOverlayOptions position(LatLng location, float width, float height)
+// overlayOptions.position(current_location, 200f, 200f);
+//
+// // マップに貼り付け・アルファを設定
+// currentOverlay = mMap.addGroundOverlay(overlayOptions);
+//
+// // 透明度
+// assert currentOverlay != null;
+// currentOverlay.setTransparency(0.8F);
}
diff --git a/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java b/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java
index 6301b5d..4ff7896 100644
--- a/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java
+++ b/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java
@@ -10,6 +10,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
@@ -31,7 +32,7 @@
myName.setText(name);
//MyPageに戻るボタン
- Button backButton = (Button) findViewById(R.id.backMyPage);
+ ImageButton backButton = (ImageButton) findViewById(R.id.backMyPage);
backButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MyPageEditorActivity.this, MyPageActivity.class);
diff --git a/app/src/main/java/com/example/nemophila/Nemophila.java b/app/src/main/java/com/example/nemophila/Nemophila.java
index 37d9e2b..14f1aed 100644
--- a/app/src/main/java/com/example/nemophila/Nemophila.java
+++ b/app/src/main/java/com/example/nemophila/Nemophila.java
@@ -30,7 +30,7 @@
//フィルターのデータ
private HashSet selectGenres = new HashSet<>();
private HashSet selectFriends = new HashSet<>();
- private HashSet favoriteFriends = new HashSet<>();
+ private HashSet favoriteFriends;
//Account関連のGetter
public String getName() {
@@ -100,11 +100,11 @@
return selectFriends;
}
public HashSet getFavoriteFriends() {
- if(favoriteFriends.isEmpty()){
+ if(favoriteFriends == null){
SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
- favoriteFriends = (HashSet) preferences.getStringSet("favoriteFriends", new HashSet<>());
+ favoriteFriends = new HashSet<>(preferences.getStringSet("favoriteFriends", new HashSet<>()));
}
- return new HashSet<>(favoriteFriends);
+ return favoriteFriends;
}
//Setter
@@ -146,18 +146,21 @@
SharedPreferences.Editor editor = preferences.edit();
editor.putFloat("cameraLatitude", (float) cameraLatitude);
this.cameraLatitude = cameraLatitude;
+ editor.commit();
}
public void setCameraLongitude(double cameraLongitude) {
SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putFloat("cameraLongitude", (float) cameraLongitude);
this.cameraLongitude = cameraLongitude;
+ editor.commit();
}
public void setZoom(float zoom) {
SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putFloat("zoom", zoom);
this.zoom = zoom;
+ editor.commit();
}
//フィルター関連のSetter
@@ -170,8 +173,9 @@
public void setFavoriteFriends(String favoriteFriend) {
SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
- editor.putStringSet("favoriteFriends", favoriteFriends);
this.favoriteFriends.add(favoriteFriend);
+ editor.putStringSet("favoriteFriends", favoriteFriends);
+ editor.commit();
}
//フィルターを取り除く
@@ -182,6 +186,6 @@
this.selectFriends.remove(selectFriend);
}
public void removeFavoriteFriends(String favoriteFriend){
- this.selectFriends.remove(favoriteFriend);
+ this.favoriteFriends.remove(favoriteFriend);
}
}
diff --git a/app/src/main/java/com/example/nemophila/PostActivity.java b/app/src/main/java/com/example/nemophila/PostActivity.java
index fb9ed9b..6fbe3ce 100644
--- a/app/src/main/java/com/example/nemophila/PostActivity.java
+++ b/app/src/main/java/com/example/nemophila/PostActivity.java
@@ -1,10 +1,17 @@
package com.example.nemophila;
+import androidx.activity.result.ActivityResultCallback;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContract;
+import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
+import android.app.Activity;
import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
@@ -24,6 +31,7 @@
import com.example.nemophila.viewmodels.ShopsViewModel;
import com.google.android.material.snackbar.Snackbar;
+import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -51,6 +59,14 @@
private Retrofit retrofit;
private Nemophila nemophila;
+ private ActivityResultLauncher launcher = registerForActivityResult(new ActivityResultContracts.GetContent(),
+ new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Uri result) {
+
+ }
+ });
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -161,51 +177,15 @@
//製作途中
-//
-// Intent intent = new Intent(MediaStore.AC);
-// intent.setType("image/*");
-//
-// Button selectPictureButton = (Button)findViewById(R.id.selectpicturebutton);
-// selectPictureButton.setOnClickListener(new View.OnClickListener(){
-// public void onClick(View v) {
-//// 画像選択(3枚)
-//
-// intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
-// intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
-// String title = "Select multiple images";
-// Intent chooser = Intent.createChooser(intent, title);
-// startActivityForResult(chooser, REQ_CODE_CHOOSE_FILES_URI);
-// }
-// });
-//
-// public void onActivityResult(int requestCode, int resultCode, final Intent data) {
-// super.onActivityResult(requestCode, resultCode, intent);
-//
-// if (resultCode != Activity.RESULT_OK) {
-// // Handle error
-// return;
-// }
-//
-// switch(requestCode) {
-// case REQUEST_PHOTO_PICKER_SINGLE_SELECT:
-// // Get photo picker response for single select.
-// Uri currentUri = data.getData();
-//
-// // Do stuff with the photo/video URI.
-// return;
-// case REQUEST_PHOTO_PICKER_MULTI_SELECT:
-// // Get photo picker response for multi select
-// for (int i = 0; i < data.getClipData().getItemCount(); i++) {
-// Uri currentUri = data.getClipData().getItemAt(i).getUri();
-//
-// // Do stuff with each photo/video URI.
-// }
-// return;
-// }
-// }
-//
-//
-//
+
+ Button selectPictureButton = (Button)findViewById(R.id.selectpicturebutton);
+ selectPictureButton.setOnClickListener(new View.OnClickListener(){
+ public void onClick(View v) {
+// 画像選択(3枚)
+ launcher.launch("image/*");
+ }
+ });
+
diff --git a/app/src/main/java/com/example/nemophila/RequestedActivity.java b/app/src/main/java/com/example/nemophila/RequestedActivity.java
index 0462074..8b4b2ad 100644
--- a/app/src/main/java/com/example/nemophila/RequestedActivity.java
+++ b/app/src/main/java/com/example/nemophila/RequestedActivity.java
@@ -4,9 +4,12 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -14,6 +17,7 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
+import android.widget.Toast;
import com.example.nemophila.entities.Account;
import com.example.nemophila.entities.AccountNameJson;
@@ -24,20 +28,19 @@
import java.util.List;
public class RequestedActivity extends AppCompatActivity {
-
- //初期化
- FriendViewModel friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class);
- Nemophila nemophila = (Nemophila) this.getApplication();
- List requestedDataSet = new ArrayList<>();
- LinearLayoutManager llm = new LinearLayoutManager(this);
- String uid = nemophila.getUid();
- String token = nemophila.getToken();
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_requested);
+ //初期化
+ FriendViewModel friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class);
+ Nemophila nemophila = (Nemophila) this.getApplication();
+ List requestedDataSet = new ArrayList<>();
+ LinearLayoutManager llm = new LinearLayoutManager(this);
+ String uid = nemophila.getUid();
+ String token = nemophila.getToken();
+
Button returnButton = (Button)findViewById(R.id.CancelButton);
returnButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
@@ -47,18 +50,57 @@
});
RecyclerView rv = findViewById(R.id.requestedList);
- RequestedAdapter adapter = new RequestedAdapter(requestedDataSet);
+ RequestedAdapter adapter = new RequestedAdapter(requestedDataSet) {
+ @Override
+ void onOkButtonClick(View view, int position, RequestedUserModel userModel) {
+ new AlertDialog.Builder(RequestedActivity.this)
+ .setTitle("確認")
+ .setMessage("フレンド申請を承諾します")
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ Toast.makeText(RequestedActivity.this, userModel.getName(), Toast.LENGTH_SHORT).show();
+ System.out.println("承諾ボタンが押されました: " + userModel.getName());
+// friendViewModel.putFriend(uid, userModel.getId(), token);
+ }
+ })
+ .setNegativeButton("Cancel", null)
+ .create()
+ .show();
+ }
+ @Override
+ void onNoButtonClick(View view, int position, RequestedUserModel userModel) {
+ new AlertDialog.Builder(RequestedActivity.this)
+ .setTitle("警告")
+ .setMessage("フレンド申請を拒否します")
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ Toast.makeText(RequestedActivity.this, userModel.getName(), Toast.LENGTH_SHORT).show();
+ System.out.println("拒否ボタンが押されました: " + userModel.getName());
+// friendViewModel.deleteRequested(uid, userModel.getId(), token);
+ }
+ })
+ .setNegativeButton("Cancel", null)
+ .create()
+ .show();
+ }
+ };
+
+ RecyclerView.ItemDecoration itemDecoration =
+ new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
+
+ rv.addItemDecoration(itemDecoration);
rv.setHasFixedSize(true);
rv.setLayoutManager(llm);
- rv.setAdapter(adapter);
friendViewModel.getRequested(uid);
friendViewModel.getRequestedLiveData().observe(this, new Observer>() {
@Override
- public void onChanged(Collection accountNameJsons) {
+ public void onChanged(Collection accountNameJson) {
requestedDataSet.clear();
- for (AccountNameJson acj: accountNameJsons) {
+ for (AccountNameJson acj: accountNameJson) {
RequestedUserModel data = new RequestedUserModel();
data.setId(acj.getUid());
data.setName(acj.getName());
@@ -71,7 +113,7 @@
}
//Adapter
- public class RequestedAdapter extends RecyclerView.Adapter {
+ abstract public class RequestedAdapter extends RecyclerView.Adapter {
private List list;
public RequestedAdapter(List list) {
this.list = list;
@@ -85,6 +127,23 @@
public RequestedViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_requested_activity, parent,false);
RequestedViewHolder vh = new RequestedViewHolder(inflate);
+
+ vh.okButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int position = vh.getBindingAdapterPosition();
+ onOkButtonClick(view, position, list.get(position));
+ }
+ });
+
+ vh.noButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int position = vh.getBindingAdapterPosition();
+ onNoButtonClick(view, position, list.get(position));
+ }
+ });
+
return vh;
}
@@ -97,15 +156,22 @@
public int getItemCount() {
return list.size();
}
+
+ abstract void onOkButtonClick(View view, int position, RequestedUserModel userModel);
+ abstract void onNoButtonClick(View view, int position, RequestedUserModel userModel);
}
//ViewHolder
public class RequestedViewHolder extends RecyclerView.ViewHolder {
public TextView nameView;
+ public Button okButton;
+ public Button noButton;
public RequestedViewHolder(@NonNull View view) {
super(view);
nameView = (TextView) view.findViewById(R.id.textView3);
+ okButton = view.findViewById(R.id.okButton);
+ noButton = view.findViewById(R.id.noButton);
}
}
diff --git a/app/src/main/java/com/example/nemophila/RequestingActivity.java b/app/src/main/java/com/example/nemophila/RequestingActivity.java
index 6adf436..692dd76 100644
--- a/app/src/main/java/com/example/nemophila/RequestingActivity.java
+++ b/app/src/main/java/com/example/nemophila/RequestingActivity.java
@@ -2,6 +2,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
@@ -14,11 +15,16 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.ImageView;
import android.widget.TextView;
+import com.example.nemophila.entities.AccountNameJson;
+import com.example.nemophila.entities.Post;
+import com.example.nemophila.viewmodels.FriendViewModel;
import com.example.nemophila.viewmodels.PostsViewModel;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
public class RequestingActivity extends AppCompatActivity {
@@ -59,16 +65,15 @@
});
//RecyclerView(表示の設定、直接表示するところはLivedataを購読しているonChanged内にしたい)
- List requestingDataSet = new ArrayList<>();
- List RequestingDataList = new ArrayList<>();
+ List requestingDataList = new ArrayList<>();
//xmlからrvにRecyclerViewを取得、アダプターを宣言
RecyclerView rv = (RecyclerView) findViewById(R.id.requestingList);
- RequestingActivity.RequestingAdapter adapter = new RequestingActivity.RequestingAdapter(RequestingDataList);
+ RequestingAdapter adapter = new RequestingAdapter(requestingDataList);
//一行ずつを縦に(LinearLayout)表示するLayoutManagerを宣言
LinearLayoutManager llm = new LinearLayoutManager(this);
- //
+ //データごとの区切り線を入れる
RecyclerView.ItemDecoration itemDecoration =
new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
rv.addItemDecoration(itemDecoration);
@@ -76,50 +81,91 @@
rv.setHasFixedSize(true);
rv.setLayoutManager(llm);
+ //ViewModelを宣言し、申請先のデータをロードしておく
+ FriendViewModel friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class);
+ friendViewModel.getRequesting(uid);
- //表示テスト用に仮データ
- List testDataSet = new ArrayList<>();
- for (int i = 0; i < 15; i++) {
- RequestingDataModel data = new RequestingDataModel();
- data.setName("ネモフィラ太郎"+ i + "号(テスト)");
+ //申請先の一覧のLiveDataへの購読
- testDataSet.add(data);
- }
- //onChange内に書くべき表示部分
- adapter.setList(testDataSet);
- rv.setAdapter(adapter);
+ friendViewModel.getRequestingLiveData().observe(this, new Observer>() {
+ //データに変更があった時実行
+ @Override
+ public void onChanged(Collection requestingUsers) {
+
+ //表示用のDataListを一旦クリアし、LiveDataから受け取ったデータを一つずつセット(重複しないように)
+ requestingDataList.clear();
+ //受け取ったLivedataの要素分繰り返し、セット
+ for (AccountNameJson user: requestingUsers) {
+ //dataを宣言 dataに投稿の必要なデータをセットし、それをpostsDatasetに追加してリストを作る
+ RequestingDataModel data = new RequestingDataModel();
+ data.setName(user.getName());
+ data.setId(user.getUid());
+
+ //投稿一つの情報がdataに全部セットされたらDatasetに追加
+ requestingDataList.add(data);
+ }
+
+ //onChange内に書くべき表示部分
+ adapter.setList(requestingDataList);
+ rv.setAdapter(adapter);
+ }
+ });
+
+
+// //表示テスト用に仮データ
+// List testDataSet = new ArrayList<>();
+// for (int i = 0; i < 15; i++) {
+// RequestingDataModel data = new RequestingDataModel();
+// data.setName("ネモフィラ太郎"+ i + "号(テスト)");
+//
+// testDataSet.add(data);
+// }
+// //onChange内に書くべき表示部分
+// adapter.setList(testDataSet);
+// rv.setAdapter(adapter);
+
}
//RecyclerViewのための内部クラス
- //とりあえずnameのみで作成
//Adapter
- public class RequestingAdapter extends RecyclerView.Adapter {
+ public class RequestingAdapter extends RecyclerView.Adapter {
- private List list;
+ private List list;
- public RequestingAdapter(List list) {
+ public RequestingAdapter(List list) {
this.list =list;
}
- public void setList(List list) {
+ public void setList(List list) {
this.list = list;
}
@NonNull
@Override
- public RequestingActivity.RequestingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-
+ public RequestingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ //1データあたりのレイアウトを読み込み、ビューホルダーを宣言
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_requesting_activity, parent,false);
- RequestingActivity.RequestingViewHolder vh = new RequestingActivity.RequestingViewHolder(inflate);
+ RequestingViewHolder vh = new RequestingViewHolder(inflate);
+
+ // リスト内のボタンを押した時の処理
+ vh.deleteButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ int position = vh.getBindingAdapterPosition();
+ // 処理はonItemClickに
+ onItemClick(v, position, list.get(position));
+ }
+ });
+
return vh;
}
@Override
- public void onBindViewHolder(@NonNull RequestingActivity.RequestingViewHolder holder, int position) {
+ public void onBindViewHolder(@NonNull RequestingViewHolder holder, int position) {
holder.nameView.setText(list.get(position).getName());
}
@@ -127,28 +173,44 @@
public int getItemCount() {
return list.size();
}
+
+ void onItemClick(View view, int position, RequestingDataModel requesting) {
+ // このメソッドをActivity内でオーバーライドして、クリックイベントの処理を設定する
+ }
}
//ViewHolder
public class RequestingViewHolder extends RecyclerView.ViewHolder {
public TextView nameView;
+ public ImageView iconView;
+ public Button deleteButton;
public RequestingViewHolder(@NonNull View itemView) {
super(itemView);
nameView = (TextView) itemView.findViewById(R.id.requestingName);
+ iconView = itemView.findViewById(R.id.requestingIcon);
+ deleteButton = itemView.findViewById(R.id.requestingDeleteButton);
}
}
//DataModel
public static class RequestingDataModel {
private String name;
+ private String id;
public String getName() {
return name;
}
+ public String getId() {
+ return id;
+ }
+
public void setName(String name) {
this.name = name;
}
+ public void setId(String id){
+ this.id = id;
+ }
}
diff --git a/app/src/main/java/com/example/nemophila/SignUpActivity.java b/app/src/main/java/com/example/nemophila/SignUpActivity.java
index e561fe7..4296898 100644
--- a/app/src/main/java/com/example/nemophila/SignUpActivity.java
+++ b/app/src/main/java/com/example/nemophila/SignUpActivity.java
@@ -26,6 +26,11 @@
private AccountsRest AccountsRest;
private Nemophila nemophila;
+ //座標指定
+ private double defaultLat = 34.74;
+ private double defaultLong = 135.26;
+ private float defaultZoom = 15f;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -36,6 +41,11 @@
//Nemophilaにtokenとuidがある場合サインアップ画面をスキップ
if ((nemophila.getUid() != null) && (nemophila.getToken() != null)){
+ //座標指定(仮)
+ nemophila.setCameraLatitude(defaultLat);
+ nemophila.setCameraLongitude(defaultLong);
+ nemophila.setZoom(defaultZoom);
+
Intent intent = new Intent(SignUpActivity.this,MapsActivity.class);
startActivity(intent);
System.out.println("サインアップ処理をスキップ");
@@ -74,6 +84,11 @@
nemophila.setUid(response.body().getId());
nemophila.setToken(response.body().getToken());
+ //座標指定(仮)
+ nemophila.setCameraLatitude(defaultLat);
+ nemophila.setCameraLongitude(defaultLong);
+ nemophila.setZoom(defaultZoom);
+
//mainに画面遷移
Intent intent = new Intent(SignUpActivity.this, MapsActivity.class);
startActivity(intent);
diff --git a/app/src/main/java/com/example/nemophila/resources/FriendsRest.java b/app/src/main/java/com/example/nemophila/resources/FriendsRest.java
index d590f56..03cc094 100644
--- a/app/src/main/java/com/example/nemophila/resources/FriendsRest.java
+++ b/app/src/main/java/com/example/nemophila/resources/FriendsRest.java
@@ -34,7 +34,7 @@
@Field("token") String token
);
- @GET("/accounts/{uid}/requesting")
+ @GET("accounts/{uid}/requesting")
Call> getRequesting(
@Path("uid") String uid
);
diff --git a/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java b/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java
index 4749334..3676d3f 100644
--- a/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java
+++ b/app/src/main/java/com/example/nemophila/viewmodels/FriendViewModel.java
@@ -69,7 +69,7 @@
}
});
}
-//
+
public void putFriend(String uid,String fid, String token) {
Call call = friendsRest.putFriend(uid,fid,token);
call.enqueue(new Callback() {
@@ -113,8 +113,10 @@
public void onResponse(Call> call, Response> response) {
if (response.isSuccessful()) {
System.out.println("Successful");
+ Collection accountNameJson = response.body();
+ requestingLiveData.setValue(accountNameJson);
} else {
- System.out.println("ResponseError");
+ System.out.println("ResponseError" + response.code());
}
}
@Override
@@ -167,6 +169,8 @@
public void onResponse(Call> call, Response> response) {
if (response.isSuccessful()) {
System.out.println("Successful");
+ Collection accountNameJson = response.body();
+ requestedLiveData.setValue(accountNameJson);
} else {
System.out.println("ResponseError");
}
diff --git a/app/src/main/res/drawable-v24/ic_current.png b/app/src/main/res/drawable-v24/ic_current.png
new file mode 100644
index 0000000..1bdc797
--- /dev/null
+++ b/app/src/main/res/drawable-v24/ic_current.png
Binary files differ
diff --git a/app/src/main/res/drawable/ic_star.xml b/app/src/main/res/drawable/ic_star.xml
new file mode 100644
index 0000000..f4b4d6a
--- /dev/null
+++ b/app/src/main/res/drawable/ic_star.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_star_outline.xml b/app/src/main/res/drawable/ic_star_outline.xml
new file mode 100644
index 0000000..59aef55
--- /dev/null
+++ b/app/src/main/res/drawable/ic_star_outline.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/icon_current.jpg b/app/src/main/res/drawable/icon_current.jpg
deleted file mode 100644
index 6f2e35a..0000000
--- a/app/src/main/res/drawable/icon_current.jpg
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml
index 500e992..7636d4b 100644
--- a/app/src/main/res/layout/activity_maps.xml
+++ b/app/src/main/res/layout/activity_maps.xml
@@ -21,15 +21,6 @@
app:defaultNavHost="true"
app:navGraph="@navigation/navigation" />
-
-
-
-
-
-
-
-
-
+ app:layout_constraintVertical_bias="0.149"/>
-
+ app:layout_constraintVertical_bias="0.023"
+ android:background="@drawable/circle_button"
+ android:src="@drawable/ic_mypage"
+ android:scaleType="fitCenter"
+ android:padding="7dp"
+ />
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_mypage.xml b/app/src/main/res/layout/activity_mypage.xml
index c338201..5ba4e04 100644
--- a/app/src/main/res/layout/activity_mypage.xml
+++ b/app/src/main/res/layout/activity_mypage.xml
@@ -127,10 +127,10 @@
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.5"
+ app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/myPageEdit"
- app:layout_constraintVertical_bias="0">
+ app:layout_constraintVertical_bias="1.0">
+ tools:textSize="14sp" />
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/textView5"
+ app:layout_constraintVertical_bias="0.0" />
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/layout_friends_activity.xml b/app/src/main/res/layout/layout_friends_activity.xml
index 7635bd4..a0353d9 100644
--- a/app/src/main/res/layout/layout_friends_activity.xml
+++ b/app/src/main/res/layout/layout_friends_activity.xml
@@ -3,27 +3,57 @@
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">
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/layout_requested_activity.xml b/app/src/main/res/layout/layout_requested_activity.xml
index 2738b1b..e7ea1b0 100644
--- a/app/src/main/res/layout/layout_requested_activity.xml
+++ b/app/src/main/res/layout/layout_requested_activity.xml
@@ -3,7 +3,9 @@
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">
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ >
GpsActivity
ShopCreateActivity
+ RequestedActivity
RequestingActivity
UserName
Make a new Account