- fravments_BitmapCallback.java
๋นํธ๋งต์ ์ฒ๋ฆฌํ๋ ์ฝ๋ฐฑ ๋ฉ์๋๋ฅผ ์ ์ํ๋๋ฐ ์ฌ์ฉ, ๋น๋๊ธฐ์ ์ธ ๋นํธ๋งต ๋ก๋ฉ ์์
์ ์ํํ๊ณ , ๋ก๋๋ ๋นํธ๋งต์ ์ ์ ํ๊ฒ ์ฒ๋ฆฌํ๊ฑฐ๋ ์ค๋ฅ ์ฒ๋ฆฌ
package com.example.stylerent.fragments;
import android.graphics.Bitmap;
public interface BitmapCallback {
void onBitmapLoaded(Bitmap bitmap);
void onFailure(Throwable t);
}
void onBitmapLoaded(Bitmap bitmap) : ๋นํธ๋งต์ด ์ฑ๊ณต์ ์ผ๋ก ๋ก๋๋์์ ๋ ํธ์ถ๋๋ ์ฝ๋ฐฑ ๋ฉ์๋
๋นํธ๋งต ๊ฐ์ฒด๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ๋๋ค.
๋ก๋๋ ๋นํธ๋งต์ ์ฒ๋ฆฌํ๊ณ ํ์ํ ์์
์ ์ํํ๋ ๋ก์ง์ ๋ฉ์๋ ๋ด์์ ๊ตฌํ ๊ฐ๋ฅ
void onFailure(Throwable t) : ๋นํธ๋งต ๋ก๋ ์ค ๋ฐ์ํ ์ค๋ฅ๋ ์์ธ๊ฐ ์์ ๊ฒฝ์ฐ ํธ์ถ๋๋ ์ฝ๋ฐฑ ๋ฉ์๋
๋ฐ์ํ ์ค๋ฅ๋ ์์ธ๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ๋๋ค.
์์ธ ์ฒ๋ฆฌ ๋ก์ง์ ์ด ๋ฉ์๋ ๋ด์์ ๊ตฌํํ์ฌ ์ค๋ฅ ์ํฉ์ ๋์
- FavoriteFragment.java
์ฌ์ฉ์์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ๊ฐ์ ธ์ ํ๋ฉด์ ํ์
๊ฐ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๋ํ ์ด๋ฏธ์ง๋ฅผ ๋น๋๊ธฐ์ ์ผ๋ก ๊ฐ์ ธ์ ํ์
package com.example.stylerent.fragments;
import static android.content.ContentValues.TAG;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.example.stylerent.R;
import com.example.stylerent.auth.ApiInterface;
import com.example.stylerent.auth.FavModel;
import com.example.stylerent.auth.ImagePathRequest;
import com.example.stylerent.auth.RetrofitClient;
import com.example.stylerent.userdata.CoordinateResponse;
import com.example.stylerent.userdata.CustomAdapter;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class FavoriteFragment extends Fragment {
private ListView favListView; // ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ํ์ํ ๋ฆฌ์คํธ
private List<FavModel> fList = new ArrayList<>(); // ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ ์ ์ฅ ๋ฆฌ์คํธ
private List<FavModel> changedVer = new ArrayList<>(); // ์ด๋ฏธ์ง๊ฐ ๋ก๋๋ ํ ์์ ๋ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ฆฌ์ค
private CustomAdapter customAdapter; // ๋ฆฌ์คํธ๋ทฐ์ ์ฌ์ฉ๋ ์ปค์คํ
์ด๋ํฐ ์ฒด
public static final String MyPREFERENCES = "MyPrefs";
SharedPreferences sharedPreferences; // ์ฑ์ ์ค์ ๋ ์ ๋ณด ์ ์ฅ
public FavoriteFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@SuppressLint("MissingInflatedId")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_favorite, container, false);
sharedPreferences = this.getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
favListView = rootView.findViewById(R.id.favListV);
// request
getMyFav(rootView);
// Inflate the layout for this fragment
return rootView;
}
private void getImage(View view) {
List<Bitmap> bitmapList = new ArrayList<>();
for (FavModel f : fList) {
getImageByPath(f.getProductImage(), new BitmapCallback() {
@Override
public void onBitmapLoaded(Bitmap bitmap) {
System.out.println("Bitmap --------->>" + bitmap.toString());
bitmapList.add(bitmap);
if (bitmapList.size() == fList.size()) {
// All bitmaps are loaded, add them to the FavModel objects
for (int i = 0; i < fList.size(); i++) {
fList.get(i).setImageBitmap(bitmapList.get(i));
}
// Create the custom adapter
customAdapter = new CustomAdapter(getContext(), fList);
favListView.setAdapter(customAdapter);
}
}
@Override
public void onFailure(Throwable t) {
// Handle the failure here
}
});
}
System.out.println("finish get image request");
System.out.println("finish get image request" + bitmapList.size());
// for(int i =0; i<fList.size(); i++){
// fList.get(i).setImageBitmap(bitmapList.get(i));
// System.out.println(fList.get(i).getImageBitmap() == null);
// }
}
private void getImageByPath(String imagePath, BitmapCallback callback){
String TOKEN = sharedPreferences.getString("TOKEN", null);
ApiInterface apiInterface = RetrofitClient.getRetrofitInstance(getContext()).create(ApiInterface.class);
// Create a new ImagePathRequest with current image path
ImagePathRequest imagePathRequest = new ImagePathRequest(imagePath);
Call<ResponseBody> userProfileCall = apiInterface.getImageByPath("Bearer" + TOKEN, imagePathRequest);
userProfileCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful() && response.body() != null) {
InputStream inputStream = response.body().byteStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
callback.onBitmapLoaded(bitmap); // Pass the bitmap to the callback
} else {
callback.onFailure(new Exception("Failed to load image")); // Pass failure to the callback
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
callback.onFailure(t);
}
});
}
private void getMyFav(View view){
//make Get request to get user's current location
String TOKEN = sharedPreferences.getString("TOKEN", null);
System.out.println("get current location ------>>>>>>>>>>>>>>>>>>>>>>");
ApiInterface apiInterface = RetrofitClient.getRetrofitInstance(getContext()).create(ApiInterface.class);
Call<List<FavModel>> userProfileCall = apiInterface.getMyFav("Bearer" + TOKEN);
userProfileCall.enqueue(new Callback<List<FavModel>>() {
@Override
public void onResponse(Call<List<FavModel>> call, Response<List<FavModel>> response) {
if (response.isSuccessful()) {
fList = response.body();
for(FavModel f : fList){
System.out.println("Items --------->" + f.getProductName());
}
//get image and change it bitmap
getImage(view);
}
}
@Override
public void onFailure(Call<List<FavModel>> call, Throwable t) {
// Handle network failure
Log.e(TAG, "Failed to get user current location: " + t.getMessage());
}
});
}
}
-
onCreateView() ๋ฉ์๋ :
ํ๋๊ทธ๋จผํธ์ ๋ทฐ๋ฅผ ์์ฑํ๊ณ ์ด๊ธฐํ
R.layout.fragment_favorite๋ฅผ ์ธํ๋ ์ดํธํ์ฌ ์ฆ๊ฒจ์ฐพ๊ธฐ ํ๋ฉด์ ๋ทฐ๋ฅผ ์์ฑ
favListView๋ฅผ ์ด๊ธฐํํ๊ณ , getMyFav() ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์๋ฒ๋ก๋ถํฐ ์ฌ์ฉ์์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก ๊ฐ์ ธ์ด
์ต์ข
์ ์ผ๋ก ๋ทฐ๋ฅผ ๋ฐํ
-
getMyFav() ๋ฉ์๋ :
์๋ฒ๋ก๋ถํฐ ์ฌ์ฉ์์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ๊ฐ์ ธ์ค๋ ๋ฉ์๋
SharedPreferences์์ ์ธ์ฆ ํ ํฐ ๊ฐ์ ธ์ด
Retrofit์ ์ฌ์ฉํ์ฌ API ํธ์ถ์ ์ํ ์ธํฐํ์ด์ค ๊ฐ์ฒด๋ฅผ ์์ฑ
API ํธ์ถ์ ์ํ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ณ , ์๋ต์ ์ฒ๋ฆฌ
์ฑ๊ณต์ ์ธ ์๋ต์ด๋ฉด fList์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ์ ์ฅํ๊ณ , getImage() ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ๊ฐ ํญ๋ชฉ์ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ด
-
getImage() ๋ฉ์๋ :
fList์ ์๋ ๊ฐ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ์ด๋ฏธ์ง๋ฅผ ๋น๋๊ธฐ์ ์ผ๋ก ๊ฐ์ ธ์ค๋ ๋ฉ์๋
getImageByPath() ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์๋ฒ๋ก๋ถํฐ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ด
๋น๋๊ธฐ์ ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ๋๋ฌธ์ BitmapCallback ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ ๋นํธ๋งต ๋ก๋ ์๋ฃ ๋๋ ์คํจ ์ ์ฒ๋ฆฌ ๋ก์ง์ ๊ตฌํ
๋ชจ๋ ์ด๋ฏธ์ง๊ฐ ๋ก๋๋๋ฉด customAdapter๋ฅผ ์์ฑํ์ฌ favListView์ ์ ์ฉ
-
getImageByPath() ๋ฉ์๋ :
์๋ฒ๋ก๋ถํฐ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฉ์๋
SharedPreferences์์ ์ธ์ฆ ํ ํฐ์ ๊ฐ์ ธ์ด
Retrofit์ ์ฌ์ฉํ์ฌ API ํธ์ถ์ ์ํ ์ธํฐํ์ด์ค ๊ฐ์ฒด๋ฅผ ์์ฑ
API ํธ์ถ์ ์ํ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ณ , ์๋ต์ ์ฒ๋ฆฌ
์ฑ๊ณต์ ์ธ ์๋ต์ด๋ฉด ์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ , Bitmap์ผ๋ก ๋์ฝ๋ฉํ์ฌ ์ฝ๋ฐฑ์ ํตํด ์ ๋ฌ
์คํจํ ๊ฒฝ์ฐ ์ค๋ฅ๋ฅผ ์ฝ๋ฐฑ์ผ๋ก ์ ๋ฌ
- userdata_CustomAdapter
FavoriteFragment์์ ์ฌ์ฉ๋๋ ์ปค์คํ
์ด๋ํฐ ํด๋์ค, ListView์ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ํ์ํ๊ธฐ ์ํด ์ฌ์ฉ
package com.example.stylerent.userdata;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.stylerent.R;
import com.example.stylerent.auth.FavModel;
import java.util.List;
public class CustomAdapter extends BaseAdapter {
private List<FavModel> favList;
private LayoutInflater inflater;
public CustomAdapter(Context context, List<FavModel> favList) {
this.favList = favList;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return favList.size();
}
@Override
public FavModel getItem(int position) {
return favList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.fav_item, parent, false);
holder = new ViewHolder();
holder.productImage = convertView.findViewById(R.id.productImage);
holder.productPrice = convertView.findViewById(R.id.productPrice);
holder.productTitle = convertView.findViewById(R.id.productTitle);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
FavModel fav = favList.get(position);
holder.productImage.setImageBitmap(fav.getImageBitmap());
holder.productTitle.setText(fav.getProductName());
holder.productPrice.setText(fav.getProductPrice());
// holder.messageTextView.setText(user.getLastMessage());
return convertView;
}
private static class ViewHolder {
TextView productPrice;
ImageView productImage;
TextView productTitle;
}
}
-
CustomAdapter ํด๋์ค ์ ์ธ :
List<FavModel> favList : ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ์ ์ฅํ๋ ๋ฆฌ์คํธ
LayoutInflater inflater : ๋ ์ด์์ ์ธํ๋ ์ด์
์ ์ํ LayoutInflater ๊ฐ์ฒด
CustomAdapter ์์ฑ์ :
context์ favlist๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ์ ์ด๋ํฐ๋ฅผ ์ด๊ธฐํ
getCount() ๋ฉ์๋ : ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๊ฐ์๋ฅผ ๋ฐํ
getItem() ๋ฉ์๋ : ์ง์ ๋ ์์น์ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๋ฐํ
getItemId ๋ฉ์๋ : ์ง์ ๋ ์์น์ ํญ๋ชฉ ID๋ฅผ ๋ฐํ
getView ๋ฉ์๋ :
์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๋ทฐ(convertView)๋ฅผ ์ด์ฉํ์ฌ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ์ต์ ํ
๋ทฐ ํ๋ ํจํด์ ์ฌ์ฉํ์ฌ ๋ทฐ์ ์ฐธ์กฐ๋ฅผ ์ ์ฅํ๊ณ ์ฌ์ฌ์ฉ
ํด๋น ์์น์ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๊ฐ์ ธ์ ๋ทฐ์ ๋ฐ์ดํฐ ์ค์
๋ทฐ์ ํ์ ํญ๋ชฉ์ ๋ํ ์ฐธ์กฐ๋ฅผ ์ ์ฅํ๋ ๋ด๋ถ ํด๋์ค
- userdata_lmageResponse
์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ ๋ํ๋ด๋ ํด๋์ค ,์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
package com.example.stylerent.userdata;
public class ImageResponse {
private String imageByte;
public ImageResponse(String imageByte) {
this.imageByte = imageByte;
}
public String getImageByte() {
return imageByte;
}
// constructor, getters and setters
}
-
ImageResponse ํด๋์ค : String imageByte ์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ๋ณ์
-
ImageResponse ์์ฑ์ : ๋งค๊ฐ๋ณ์๋ก ์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ๊ฐ์ฒด ์ด๊ธฐํ
๋งค๊ฐ๋ณ์๋ก ๋ฐ์ ๊ฐ์ `imageByte` ๋ณ์์ ์ค์
-
getImageByte ๋ฉ์๋ : imageByte ๋ณ์์ ๊ฐ์ ๋ฐํ
๋นํธ๋งต์ ์ฒ๋ฆฌํ๋ ์ฝ๋ฐฑ ๋ฉ์๋๋ฅผ ์ ์ํ๋๋ฐ ์ฌ์ฉ, ๋น๋๊ธฐ์ ์ธ ๋นํธ๋งต ๋ก๋ฉ ์์ ์ ์ํํ๊ณ , ๋ก๋๋ ๋นํธ๋งต์ ์ ์ ํ๊ฒ ์ฒ๋ฆฌํ๊ฑฐ๋ ์ค๋ฅ ์ฒ๋ฆฌ
void onBitmapLoaded(Bitmap bitmap): ๋นํธ๋งต์ด ์ฑ๊ณต์ ์ผ๋ก ๋ก๋๋์์ ๋ ํธ์ถ๋๋ ์ฝ๋ฐฑ ๋ฉ์๋๋นํธ๋งต ๊ฐ์ฒด๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ๋๋ค.
๋ก๋๋ ๋นํธ๋งต์ ์ฒ๋ฆฌํ๊ณ ํ์ํ ์์ ์ ์ํํ๋ ๋ก์ง์ ๋ฉ์๋ ๋ด์์ ๊ตฌํ ๊ฐ๋ฅ
void onFailure(Throwable t): ๋นํธ๋งต ๋ก๋ ์ค ๋ฐ์ํ ์ค๋ฅ๋ ์์ธ๊ฐ ์์ ๊ฒฝ์ฐ ํธ์ถ๋๋ ์ฝ๋ฐฑ ๋ฉ์๋๋ฐ์ํ ์ค๋ฅ๋ ์์ธ๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ๋๋ค.
์์ธ ์ฒ๋ฆฌ ๋ก์ง์ ์ด ๋ฉ์๋ ๋ด์์ ๊ตฌํํ์ฌ ์ค๋ฅ ์ํฉ์ ๋์
์ฌ์ฉ์์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ๊ฐ์ ธ์ ํ๋ฉด์ ํ์
๊ฐ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๋ํ ์ด๋ฏธ์ง๋ฅผ ๋น๋๊ธฐ์ ์ผ๋ก ๊ฐ์ ธ์ ํ์
onCreateView()๋ฉ์๋ :ํ๋๊ทธ๋จผํธ์ ๋ทฐ๋ฅผ ์์ฑํ๊ณ ์ด๊ธฐํ
R.layout.fragment_favorite๋ฅผ ์ธํ๋ ์ดํธํ์ฌ ์ฆ๊ฒจ์ฐพ๊ธฐ ํ๋ฉด์ ๋ทฐ๋ฅผ ์์ฑfavListView๋ฅผ ์ด๊ธฐํํ๊ณ ,getMyFav()๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์๋ฒ๋ก๋ถํฐ ์ฌ์ฉ์์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก ๊ฐ์ ธ์ด์ต์ข ์ ์ผ๋ก ๋ทฐ๋ฅผ ๋ฐํ
getMyFav()๋ฉ์๋ :์๋ฒ๋ก๋ถํฐ ์ฌ์ฉ์์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ๊ฐ์ ธ์ค๋ ๋ฉ์๋
SharedPreferences์์ ์ธ์ฆ ํ ํฐ ๊ฐ์ ธ์ดRetrofit์ ์ฌ์ฉํ์ฌ API ํธ์ถ์ ์ํ ์ธํฐํ์ด์ค ๊ฐ์ฒด๋ฅผ ์์ฑAPI ํธ์ถ์ ์ํ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ณ , ์๋ต์ ์ฒ๋ฆฌ
์ฑ๊ณต์ ์ธ ์๋ต์ด๋ฉด
fList์ ์ฆ๊ฒจ์ฐพ๊ธฐ ๋ชฉ๋ก์ ์ ์ฅํ๊ณ ,getImage()๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ๊ฐ ํญ๋ชฉ์ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ดgetImage()๋ฉ์๋ :fList์ ์๋ ๊ฐ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ์ด๋ฏธ์ง๋ฅผ ๋น๋๊ธฐ์ ์ผ๋ก ๊ฐ์ ธ์ค๋ ๋ฉ์๋getImageByPath()๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์๋ฒ๋ก๋ถํฐ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ด๋น๋๊ธฐ์ ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ๋๋ฌธ์
BitmapCallback์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ ๋นํธ๋งต ๋ก๋ ์๋ฃ ๋๋ ์คํจ ์ ์ฒ๋ฆฌ ๋ก์ง์ ๊ตฌํ๋ชจ๋ ์ด๋ฏธ์ง๊ฐ ๋ก๋๋๋ฉด
customAdapter๋ฅผ ์์ฑํ์ฌfavListView์ ์ ์ฉgetImageByPath()๋ฉ์๋ :์๋ฒ๋ก๋ถํฐ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฉ์๋
SharedPreferences์์ ์ธ์ฆ ํ ํฐ์ ๊ฐ์ ธ์ดRetrofit์ ์ฌ์ฉํ์ฌ API ํธ์ถ์ ์ํ ์ธํฐํ์ด์ค ๊ฐ์ฒด๋ฅผ ์์ฑAPI ํธ์ถ์ ์ํ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ณ , ์๋ต์ ์ฒ๋ฆฌ
์ฑ๊ณต์ ์ธ ์๋ต์ด๋ฉด ์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ ,
Bitmap์ผ๋ก ๋์ฝ๋ฉํ์ฌ ์ฝ๋ฐฑ์ ํตํด ์ ๋ฌ์คํจํ ๊ฒฝ์ฐ ์ค๋ฅ๋ฅผ ์ฝ๋ฐฑ์ผ๋ก ์ ๋ฌ
FavoriteFragment์์ ์ฌ์ฉ๋๋ ์ปค์คํ ์ด๋ํฐ ํด๋์ค, ListView์ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ํ์ํ๊ธฐ ์ํด ์ฌ์ฉ
CustomAdapterํด๋์ค ์ ์ธ :List<FavModel> favList: ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ์ ์ฅํ๋ ๋ฆฌ์คํธLayoutInflater inflater: ๋ ์ด์์ ์ธํ๋ ์ด์ ์ ์ํLayoutInflater๊ฐ์ฒดCustomAdapter์์ฑ์ :context์ favlist๋ฅผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ์ ์ด๋ํฐ๋ฅผ ์ด๊ธฐํ
getCount()๋ฉ์๋ : ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๊ฐ์๋ฅผ ๋ฐํgetItem()๋ฉ์๋ : ์ง์ ๋ ์์น์ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๋ฐํgetItemId๋ฉ์๋ : ์ง์ ๋ ์์น์ ํญ๋ชฉ ID๋ฅผ ๋ฐํgetView๋ฉ์๋ :์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๋ทฐ(convertView)๋ฅผ ์ด์ฉํ์ฌ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ์ต์ ํ
๋ทฐ ํ๋ ํจํด์ ์ฌ์ฉํ์ฌ ๋ทฐ์ ์ฐธ์กฐ๋ฅผ ์ ์ฅํ๊ณ ์ฌ์ฌ์ฉ
ํด๋น ์์น์ ์ฆ๊ฒจ์ฐพ๊ธฐ ํญ๋ชฉ์ ๊ฐ์ ธ์ ๋ทฐ์ ๋ฐ์ดํฐ ์ค์
ViewHolderํด๋์ค :๋ทฐ์ ํ์ ํญ๋ชฉ์ ๋ํ ์ฐธ์กฐ๋ฅผ ์ ์ฅํ๋ ๋ด๋ถ ํด๋์ค
์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ ๋ํ๋ด๋ ํด๋์ค ,์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
ImageResponseํด๋์ค :String imageByte์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ๋ณ์ImageResponse์์ฑ์ : ๋งค๊ฐ๋ณ์๋ก ์ด๋ฏธ์ง ๋ฐ์ดํธ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ๊ฐ์ฒด ์ด๊ธฐํgetImageByte๋ฉ์๋ :imageByte๋ณ์์ ๊ฐ์ ๋ฐํ