RecommendFragment - GachonCapstoneTeam/TTS_JAVA GitHub Wiki
RecommendFragment
๋ ์ฌ์ฉ์์ ๊ด์ฌ์ ๋ ์ ์๋ ์ถ์ฒ ๋ฆฌํฌํธ์ ์ธ๊ธฐ ๋ฆฌํฌํธ๋ฅผ ViewPager2๋ก ๋ณด์ฌ์ฃผ๋ ํ๋ฉด์
๋๋ค. ๊ฐ๊ฐ์ ์ฌ๋ผ์ด๋๋ ์๋ ์ํ๋๋ฉฐ, Shimmer ์์ด ์ฆ์ UI์ ๋ฐ์ดํฐ๋ฅผ ํ์ํ๋๋ก ์ค๊ณ๋์์ต๋๋ค.
๊ธฐ๋ฅ | ์ค๋ช |
---|---|
์ถ์ฒ ๋ฆฌํฌํธ ViewPager | ์๋จ ViewPager2์ ์๋ ์ํ ๋ฐฉ์์ผ๋ก ์ถ์ฒ ๋ฆฌํฌํธ ํ์ |
์ธ๊ธฐ ๋ฆฌํฌํธ ViewPager | ํ๋จ ViewPager2๋ก ์ธ๊ธฐ ์๋ ๋ฆฌํฌํธ ์ฌ๋ผ์ด๋ ์ ๊ณต |
์๋ ์ฌ๋ผ์ด๋ฉ | 3์ด ๊ฐ๊ฒฉ์ผ๋ก ํ์ด์ง ์๋ ๋ณ๊ฒฝ |
API ํต์ | ์ถ์ฒ/์ธ๊ธฐ ๋ฆฌํฌํธ ๋ชจ๋ ๋์ผํ API์์ ๋ฐ์ดํฐ ์์ฒญ |
๋๋ฏธ ๋ฐ์ดํฐ ๋์ฒด | API ์คํจ ์ ๋๋ฏธ ๋ฆฌํฌํธ๋ก ๋์ฒด ํ์ |
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(API_URL).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
List<Item> items = parseItemsFromJson(response.body().string());
recommendAdapter.updateItems(items);
startAutoSlide();
}
});
- ์ถ์ฒ ๋ฆฌํฌํธ ๋ฐ์ดํฐ๋ฅผ ๋น๋๊ธฐ๋ก ์์ฒญ ํ ์ด๋ํฐ์ ๋ฐ์ํ๋ฉฐ ์๋ ์ฌ๋ผ์ด๋ ์์
Runnable sliderRunnable = () -> {
recommendCurrentPage = (recommendCurrentPage + 1) % totalRecommendItems;
recommendViewPager.setCurrentItem(recommendCurrentPage, true);
rankCurrentPage = (rankCurrentPage + 1) % totalRankItems;
rankViewPager.setCurrentItem(rankCurrentPage, true);
sliderHandler.postDelayed(this, 3000);
};
sliderHandler.postDelayed(sliderRunnable, 3000);
- ์ถ์ฒ/์ธ๊ธฐ ViewPager๋ฅผ 3์ด ๊ฐ๊ฒฉ์ผ๋ก ์๋ ์ ํํ๋ฉฐ ๋ฐ๋ณต
JSONObject root = new JSONObject(jsonData);
JSONArray contents = root.getJSONArray("contents");
for (int i = 0; i < contents.length(); i++) {
JSONObject obj = contents.getJSONObject(i);
items.add(new Item(
obj.getString("Category"),
obj.getString("Title"),
obj.getString("์ฆ๊ถ์ฌ"),
obj.getString("PDF URL"),
obj.getString("์์ฑ์ผ"),
obj.getString("Views"),
obj.getString("Content"),
obj.getString("PDF Content")
));
}
- API ์๋ต์ผ๋ก ๋ฐ์ JSON ๋ฐฐ์ด์
Item
๊ฐ์ฒด ๋ฆฌ์คํธ๋ก ํ์ฑ