Merge pull request #265 from nitta-lab-2023/filter_add_myself
Filter add myself
commit dbbcceec0d2c2bb25ea0780c63a629a62630b0a6
2 parents 83acdb8 + e28fedb
Shinnosuke Iyonaga authored on 10 Oct 2023
Showing 2 changed files
View
80
app/src/main/java/com/example/nemophila/MapsActivity.java
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;
import androidx.navigation.ui.NavigationUI;
 
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.widget.ListView;
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.CameraUpdateFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.material.navigation.NavigationView;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
 
 
public class MapsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
FriendViewModel friendViewModel;
DialogFragment filterDialog;
MapsFragment mapsFragment;
private Handler handler;
//private HashMap<String, String> NameToId;
 
 
// フィルターのリスト用
ArrayList<FilterDataModel> listData;
ListView list;
boolean isGenre;
String genreData[];
ArrayList<String> friendsData;
ArrayList<String> UsersData;
 
 
@Override
protected void onCreate(Bundle savedInstanceState) {
return false;
}
});
 
//filterDialog = new FilterDialog();
 
// サイドメニューのボタン
Button genreButton = findViewById(R.id.filter_genre_button);
Button friendButton = findViewById(R.id.filter_friends_button);
 
});
 
// サイドメニューのフィルターのリストの準備
genreData = new String[]{"中華", "和食", "イタリアン", "フレンチ", "カフェ", "バー", "居酒屋", "ラーメン", "うどん・そば", "その他 海外料理"};
friendsData = new ArrayList<>();
//NameToId = new HashMap<>();
 
// friendsData[0] = "iyo";
// friendsData[1] = "iyo2";
// friendsData[2] = "superiyo";
// friendsData[3] = "perfectiyo";
// friendsData[4] = "finaliyo";
UsersData = new ArrayList<>();
 
//自分自身をfilterにかけられるように追加しておく
UsersData.add(nemophila.getUid());
 
//フレンド一覧を取得
friendViewModel.getFriends(nemophila.getUid());
friendViewModel.getFriendsLiveData().observe(this, new Observer<Collection<AccountNameJson>>() {
@Override
public void onChanged(Collection<AccountNameJson> friends) {
for (AccountNameJson friend : friends) {
friendsData.add(friend.getUid());
//NameToId.put(friend.getName(), friend.getUid());
UsersData.add(friend.getUid());
}
}
});
 
 
return super.onOptionsItemSelected(item);
}
 
 
//ジャンルfilter設定画面になったとき
public void prepareGenreList(String s){
//sは検索欄に入力された文字列
// 現在表示されているリストがジャンルのリストかどうかを設定
));
list.deferNotifyDataSetChanged();
}
 
//ユーザーfilter設定画面になったとき
public void prepareFriendList(String s){
//sは検索欄に入力された文字列
// 現在表示されているリストがジャンルのリストかどうかを設定
isGenre = false;
 
// 一度リストのデータを取り除いてから追加する
listData.clear();
 
FilterDataModel fd = new FilterDataModel();
fd.setText(nemophila.getUid());
fd.setNameText(nemophila.getName());
listData.add(fd);
for (AccountNameJson friend : nemophila.getFriends()) {
if(s == null) {
FilterDataModel fd = new FilterDataModel();
fd.setText(friend.getUid());
fd.setNameText(friend.getName());
listData.add(fd);
FilterDataModel fd2 = new FilterDataModel();
fd2.setText(friend.getUid());
fd2.setNameText(friend.getName());
listData.add(fd2);
} else {
//検索にヒットしたフレンドのみのリストにする
if(friend.getName().contains(s)){
FilterDataModel fd = new FilterDataModel();
fd.setText(friend.getUid());
fd.setNameText(friend.getName());
listData.add(fd);
FilterDataModel fd2 = new FilterDataModel();
fd2.setText(friend.getUid());
fd2.setNameText(friend.getName());
listData.add(fd2);
}
}
}
 
 
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
 
// 画面外に行ったときにチェックがずれないようにする
// 画面外に行ったときにチェックがはずれないようにする
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CheckBox checkBox;
 
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b) {
if(isGenre) {
//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());
}
} 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());
}
}
FilterDataModel data = getItem(position);
data.isChecked = b;
//shopsViewModelのPreShoplistは、現在取得した全てのshopを持っている
Collection<Shop> shops = shopsViewModel.getPreShoplist();
 
if ( shops != null ) {
System.out.println(shops);
nemophila.getSelectGenres();
 
for (Shop shop : shops) {
Marker setMarker = shopsViewModel.getMarker(shop);
 
ArrayList<String> userIdSet = (ArrayList<String>)shop.getUserIdSet().clone();
friendsData.add(nemophila.getUid());
userIdSet.retainAll(friendsData);
UsersData.add(nemophila.getUid());
userIdSet.retainAll(UsersData);
 
//自分とそのフレンド以外の投稿は確認しない
if( userIdSet.size() > 0) {
//場合分け
 
public String getText() {
return text;
}
public String getNameText() {
return nameText;
}
 
public boolean isChecked() {
return isChecked;
}
 
public void setText(String text) {
this.text = text;
}
public void setNameText(String text) {
this.nameText = text;
}
 
public void setChecked(boolean checked) {
isChecked = checked;
}
}
 
}
View
4
app/src/main/res/layout/activity_maps.xml
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.04"
android:text="フィルター"
android:text="フィルター設定(表示投稿の絞り込み)"
android:autoSizeTextType="uniform"/>
 
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/filter_friends_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text="フレンド"
android:text="ユーザー"
android:autoSizeTextType="uniform"
android:textColor="@color/black"
android:backgroundTint="@color/white"/>
</LinearLayout>