diff --git a/app/src/main/java/com/example/nemophila/MapsActivity.java b/app/src/main/java/com/example/nemophila/MapsActivity.java index 1256256..65b1128 100644 --- a/app/src/main/java/com/example/nemophila/MapsActivity.java +++ b/app/src/main/java/com/example/nemophila/MapsActivity.java @@ -7,6 +7,8 @@ import androidx.appcompat.widget.Toolbar; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.DialogFragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; import androidx.navigation.NavController; import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.ui.AppBarConfiguration; @@ -30,28 +32,42 @@ import android.widget.TextView; import android.widget.Toast; +import com.example.nemophila.entities.Account; +import com.example.nemophila.entities.AccountNameJson; +import com.example.nemophila.entities.Shop; +import com.example.nemophila.viewmodels.FriendViewModel; +import com.example.nemophila.viewmodels.ShopsViewModel; +import com.google.android.gms.maps.model.Marker; import com.google.android.material.navigation.NavigationView; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; public class MapsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { Nemophila nemophila; + ShopsViewModel shopsViewModel; + FriendViewModel friendViewModel; DialogFragment filterDialog; private Handler handler; + private HashMap NameToId; + // フィルターのリスト用 ArrayList listData; ListView list; boolean isGenre; String genreData[]; - String friendsData[]; + ArrayList friendsData; @Override protected void onCreate(Bundle savedInstanceState) { + shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class); + friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class); super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); @@ -115,19 +131,28 @@ }); // サイドメニューのフィルターのリストの準備 - genreData = new String[5]; - friendsData = new String[5]; - genreData[0] = "和食"; - genreData[1] = "中華"; - genreData[2] = "イタリアン"; - genreData[3] = "洋食"; - genreData[4] = "ジャンクフード"; + genreData = new String[]{"中華", "和食", "イタリアン", "フレンチ", "カフェ", "バー", "居酒屋", "ラーメン", "うどん・そば", "その他 海外料理"}; + friendsData = new ArrayList<>(); + NameToId = new HashMap<>(); - friendsData[0] = "iyo"; - friendsData[1] = "iyo2"; - friendsData[2] = "superiyo"; - friendsData[3] = "perfectiyo"; - friendsData[4] = "finaliyo"; +// friendsData[0] = "iyo"; +// friendsData[1] = "iyo2"; +// friendsData[2] = "superiyo"; +// friendsData[3] = "perfectiyo"; +// friendsData[4] = "finaliyo"; + + //フレンド一覧を取得 + friendViewModel.getFriends(nemophila.getUid()); + friendViewModel.getFriendsLiveData().observe(this, new Observer>() { + @Override + public void onChanged(Collection friends) { + for (AccountNameJson friend : friends) { + friendsData.add(friend.getName()); + NameToId.put(friend.getName(), friend.getUid()); + } + } + }); + listData = new ArrayList<>(); list = findViewById(R.id.drawer_list); @@ -186,6 +211,8 @@ public void prepareGenreList(String s){ + //sは検索欄に入力された文字列 + // 現在表示されているリストがジャンルのリストかどうかを設定 isGenre = true; @@ -215,20 +242,24 @@ } public void prepareFriendList(String s){ + //sは検索欄に入力された文字列 + // 現在表示されているリストがジャンルのリストかどうかを設定 isGenre = false; // 一度リストのデータを取り除いてから追加する listData.clear(); - for(int i = 0; i < friendsData.length; i++){ + + for (AccountNameJson friend : nemophila.getFriends()) { if(s == null) { FilterDataModel fd = new FilterDataModel(); - fd.setText(friendsData[i]); + fd.setText(friend.getName()); listData.add(fd); } else { - if(friendsData[i].contains(s)){ + //検索にヒットしたフレンドのみのリストにする + if(friend.getName().contains(s)){ FilterDataModel fd = new FilterDataModel(); - fd.setText(friendsData[i]); + fd.setText(friend.getName()); listData.add(fd); } } @@ -276,7 +307,7 @@ checkBox.setChecked(nemophila.getSelectFriends().contains(item.getText())); } - // チェックボックスを押したときの処理 + // チェックボックスを押したときの処理 //bがtrueでチェック状態を指す checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { @@ -285,18 +316,44 @@ //Toast.makeText(MapsActivity.this, listData.get(position).getText(), Toast.LENGTH_SHORT).show(); nemophila.setSelectGenres(listData.get(position).getText()); } else { - nemophila.setSelectFriends(listData.get(position).getText()); + nemophila.setSelectFriends(NameToId.get(listData.get(position).getText())); } } else { if(isGenre) { //Toast.makeText(MapsActivity.this, listData.get(position).getText(), Toast.LENGTH_SHORT).show(); nemophila.removeSelectGenres(listData.get(position).getText()); + } else { - nemophila.removeSelectFriends(listData.get(position).getText()); + nemophila.removeSelectFriends(NameToId.get(listData.get(position).getText())); } } FilterDataModel data = getItem(position); data.isChecked = b; + Collection shops = shopsViewModel.getPreShoplist(); + + if ( shops != null ) { + System.out.println(shops); + nemophila.getSelectGenres(); + + for (Shop shop : shops) { + Marker setMarker = shopsViewModel.getMarker(shop); + if(nemophila.getSelectGenres().isEmpty()){ + setMarker.setVisible(true); + } else { + for(String genre : nemophila.getSelectGenres()) { + if(shop.getGenreSet().contains(genre)) { + setMarker.setVisible(true); + } else { + setMarker.setVisible(false); + } + } + } + } + +// if (!nemophila.getSelectFriends().isEmpty()) { +// setMaker.setVisible(false); +// } + } } });