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); } }