diff --git a/app/src/main/java/com/example/nemophila/MapsActivity.java b/app/src/main/java/com/example/nemophila/MapsActivity.java index 4ab2951..7b397b5 100644 --- a/app/src/main/java/com/example/nemophila/MapsActivity.java +++ b/app/src/main/java/com/example/nemophila/MapsActivity.java @@ -12,6 +12,8 @@ import android.content.Context; import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; @@ -24,6 +26,7 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; +import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -35,20 +38,26 @@ import com.google.android.gms.maps.model.Marker; import com.google.android.material.navigation.NavigationView; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class MapsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { + private final ExecutorService executor = Executors.newSingleThreadExecutor(); + private final Handler handler = new Handler(); + Nemophila nemophila; ShopsViewModel shopsViewModel; FriendViewModel friendViewModel; DialogFragment filterDialog; MapsFragment mapsFragment; - private Handler handler; - // フィルターのリスト用 ArrayList listData; @@ -86,9 +95,6 @@ NavigationView navigationView = (NavigationView) findViewById(R.id.navView); navigationView.setNavigationItemSelectedListener(this); - // geocode Test - handler = new Handler(); - // 検索バーの処理 SearchView searchView = findViewById(R.id.tool_search); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @@ -240,7 +246,6 @@ R.layout.filter_layout, listData )); - list.deferNotifyDataSetChanged(); } //ユーザーfilter設定画面になったとき @@ -250,12 +255,37 @@ // 現在表示されているリストがジャンルのリストかどうかを設定 isGenre = false; + //アイコン仮セット + String iconUrlString = "http://nitta-lab-www.is.konan-u.ac.jp/nemophila-data/test01.jpg"; + //本来はuidからurl作る +// String iconUrlString = "http://nitta-lab-www.is.konan-u.ac.jp/nemophila-data/icon" + myUid + ".jpg"; + // 一度リストのデータを取り除いてから追加する listData.clear(); FilterDataModel fd = new FilterDataModel(); fd.setText(nemophila.getUid()); fd.setNameText(nemophila.getName()); + executor.execute(() -> { + try{ + URL iconUrl = new URL(iconUrlString); + HttpURLConnection con = (HttpURLConnection) iconUrl.openConnection(); + con.connect(); + + InputStream is = con.getInputStream(); + + Bitmap bitmap = BitmapFactory.decodeStream(is); + handler.post(() -> { + fd.setImage(bitmap); + MyAdapter adapter = (MyAdapter) list.getAdapter(); + adapter.notifyDataSetChanged(); + }); + is.close(); + con.disconnect(); + }catch (Exception e){ + e.printStackTrace(); + } + }); listData.add(fd); for (AccountNameJson friend : nemophila.getFriends()) { @@ -263,13 +293,58 @@ FilterDataModel fd2 = new FilterDataModel(); fd2.setText(friend.getUid()); fd2.setNameText(friend.getName()); + + executor.execute(() -> { + try{ + URL iconUrl = new URL(iconUrlString); + HttpURLConnection con = (HttpURLConnection) iconUrl.openConnection(); + con.connect(); + + InputStream is = con.getInputStream(); + + Bitmap bitmap = BitmapFactory.decodeStream(is); + handler.post(() -> { + fd2.setImage(bitmap); + MyAdapter adapter = (MyAdapter) list.getAdapter(); + adapter.notifyDataSetChanged(); + }); + is.close(); + con.disconnect(); + }catch (Exception e){ + e.printStackTrace(); + } + }); + listData.add(fd2); + } else { //検索にヒットしたフレンドのみのリストにする if(friend.getName().contains(s)){ FilterDataModel fd2 = new FilterDataModel(); fd2.setText(friend.getUid()); fd2.setNameText(friend.getName()); + + executor.execute(() -> { + try{ + URL iconUrl = new URL(iconUrlString); + HttpURLConnection con = (HttpURLConnection) iconUrl.openConnection(); + con.connect(); + + InputStream is = con.getInputStream(); + + Bitmap bitmap = BitmapFactory.decodeStream(is); + handler.post(() -> { + fd2.setImage(bitmap); + MyAdapter adapter = (MyAdapter) list.getAdapter(); + adapter.notifyDataSetChanged(); + }); + is.close(); + con.disconnect(); + }catch (Exception e){ + e.printStackTrace(); + } + }); + listData.add(fd2); } } @@ -281,7 +356,6 @@ R.layout.filter_layout, listData )); - list.deferNotifyDataSetChanged(); } @Override @@ -307,7 +381,7 @@ public View getView(int position, View convertView, ViewGroup parent) { CheckBox checkBox; - if(isGenre) { + if (isGenre) { FilterDataModel item = (FilterDataModel) getItem(position); if (convertView == null) { convertView = layoutInflater.inflate(R.layout.filter_item, null); @@ -325,8 +399,10 @@ convertView = layoutInflater.inflate(R.layout.filter_friend_item, null); } + ImageView imageView = convertView.findViewById(R.id.filter_friend_ic); TextView textView = convertView.findViewById(R.id.filter_text); TextView nameTextView = convertView.findViewById(R.id.filter_name); + imageView.setImageBitmap(item.image); textView.setText(item.text); nameTextView.setText(item.nameText); @@ -425,6 +501,7 @@ private static class FilterDataModel{ private String text; private String nameText; + private Bitmap image; private boolean isChecked; @@ -438,6 +515,7 @@ public void setNameText(String text) { this.nameText = text; } + public void setImage(Bitmap ic) { this.image = ic; } }