diff --git a/app/src/main/java/com/example/nemophila/RequestedActivity.java b/app/src/main/java/com/example/nemophila/RequestedActivity.java index 6a1ef91..1ef29da 100644 --- a/app/src/main/java/com/example/nemophila/RequestedActivity.java +++ b/app/src/main/java/com/example/nemophila/RequestedActivity.java @@ -11,11 +11,15 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -23,11 +27,21 @@ import com.example.nemophila.entities.AccountNameJson; import com.example.nemophila.viewmodels.FriendViewModel; +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 RequestedActivity extends AppCompatActivity { + + private final ExecutorService executor = Executors.newSingleThreadExecutor(); + private final Handler handler = new Handler(); + private String IconUrlString; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -105,10 +119,33 @@ data.setId(acj.getUid()); data.setName(acj.getName()); requestedDataSet.add(data); + + IconUrlString = "http://nitta-lab-www.is.konan-u.ac.jp/nemophila-data/test01.jpg"; + executor.execute(() -> { + try { + URL url = new URL(IconUrlString); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.connect(); + + InputStream is = con.getInputStream(); + + Bitmap bitmap = BitmapFactory.decodeStream(is); + handler.post(() -> { + data.setIcon(bitmap); + adapter.notifyItemChanged(adapter.getPosition(data)); + }); + is.close(); + con.disconnect(); + } catch (Exception e){ + e.printStackTrace(); + } + }); } adapter.setList(requestedDataSet); rv.setAdapter(adapter); } + + }); } @@ -121,6 +158,7 @@ public void setList(List list) { this.list = list; } + public int getPosition(RequestedActivity.RequestedUserModel d) { return list.indexOf(d); } @NonNull @Override @@ -150,6 +188,7 @@ @Override public void onBindViewHolder(@NonNull RequestedViewHolder holder, int position) { holder.nameView.setText(list.get(position).getName()); + holder.iconView.setImageBitmap(list.get(position).getIcon()); } @Override @@ -166,12 +205,14 @@ public TextView nameView; public Button okButton; public Button noButton; + public ImageView iconView; public RequestedViewHolder(@NonNull View view) { super(view); nameView = (TextView) view.findViewById(R.id.textView3); okButton = view.findViewById(R.id.okButton); noButton = view.findViewById(R.id.noButton); + iconView = view.findViewById(R.id.imageView); } } @@ -179,6 +220,7 @@ public static class RequestedUserModel { private String name; private String id; + private Bitmap icon; public String getName() { return name; @@ -186,10 +228,16 @@ public String getId() { return id; } + public Bitmap getIcon() { + return icon; + } public void setName(String name) { this.name = name; } public void setId(String id) { this.id = id;} + public void setIcon(Bitmap icon) { + this.icon = icon; + } } } \ No newline at end of file