package com.example.nemophila; import android.app.Application; import android.content.SharedPreferences; import com.example.nemophila.entities.Account; import com.example.nemophila.entities.AccountNameJson; import com.example.nemophila.entities.Shop; import com.google.type.LatLng; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; public class Nemophila extends Application { //アカウントのデータ private String name; private String uid; private String token; private Collection<AccountNameJson> friends; //ショップのデータ private Shop currentShop; private double currentLongitude; private double currentLatitude; private Shop dummyShop; //カメラのデータ private double cameraLatitude; private double cameraLongitude; private float zoom; //フィルターのデータ private HashSet<String> selectGenres = new HashSet<>(); private HashSet<String> selectFriends = new HashSet<>(); private HashSet<String> favoriteFriends; //Account関連のGetter public String getName() { if(name == null){ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); name = preferences.getString("name", null); } return name; } public String getUid() { if(uid == null){ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); uid = preferences.getString("uid", null); } return uid; } public String getToken() { if(token == null){ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); token = preferences.getString("token", null); } return token; } public Collection<AccountNameJson> getFriends() { return friends; } //Shop関連のGetter public Shop getCurrentShop() { return currentShop; } public double getCurrentLongitude() { return currentLongitude; } public double getCurrentLatitude() { return currentLatitude; } public Shop getDummyShop() { return dummyShop; } //Camera関連のGetter public double getCameraLatitude() { if(cameraLatitude == 0){ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); cameraLatitude = preferences.getFloat("cameraLatitude", 0); } return cameraLatitude; } public double 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", 10); } return zoom; } //フィルター関連のGetter public HashSet<String> getSelectGenres() { return selectGenres; } public HashSet<String> getSelectFriends() { return selectFriends; } public HashSet<String> getFavoriteFriends() { if(favoriteFriends == null){ SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); favoriteFriends = new HashSet<>(preferences.getStringSet("favoriteFriends", new HashSet<>())); } return favoriteFriends; } //Setter public void setName(String name) { SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("name", name); this.name = name; editor.commit(); } public void setUid(String uid) { SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("uid", uid); this.uid = uid; editor.commit(); } public void setToken(String token) { SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("token", token); this.token = token; editor.commit(); } public void setFriends(Collection<AccountNameJson> friends) { this.friends = friends; } public void setCurrentShop(Shop currentShop) { this.currentShop = currentShop; } public void setCurrentLongitude(double currentLongitude) { this.currentLongitude = currentLongitude; } public void setCurrentLatitude(double currentLatitude) { this.currentLatitude = currentLatitude; } public void setDummyShop(Shop dummyShop) { this.dummyShop = dummyShop; } public void setCameraLatitude(double cameraLatitude) { SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); 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 public void setSelectGenres(String selectGenre) { this.selectGenres.add(selectGenre); } public void setSelectFriends(String selectFriend) { this.selectFriends.add(selectFriend); } public void setFavoriteFriends(String favoriteFriend) { SharedPreferences preferences = getSharedPreferences("prefData", MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); this.favoriteFriends.add(favoriteFriend); editor.putStringSet("favoriteFriends", favoriteFriends); editor.commit(); } //フィルターを取り除く public void removeSelectGenres(String selectGenre){ this.selectGenres.remove(selectGenre); } public void removeSelectFriends(String selectFriend) { this.selectFriends.remove(selectFriend); } public void removeFavoriteFriends(String favoriteFriend){ this.favoriteFriends.remove(favoriteFriend); } }