Adapter - GachonCapstoneTeam/TTS_JAVA GitHub Wiki
๐งฉ Adapter (ItemAdapter & ReportAdapter)
ItemAdapter
์ ReportAdapter
๋ ๊ฐ๊ฐ ํ ํ๋ฉด๊ณผ ๊ฒ์ ํ๋ฉด์ RecyclerView์ ๋ฐ์ดํฐ๋ฅผ ํ์ํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ์ด๋ํฐ์
๋๋ค.
โ ์ฃผ์ ๊ธฐ๋ฅ ์์ฝ
์ด๋ํฐ๋ช | ์ค๋ช |
---|---|
ItemAdapter |
ํ ํ๋ฉด์์ ๋ฆฌํฌํธ ๋ฆฌ์คํธ๋ฅผ ํ์ํ๋ฉฐ, ํ์ฌ ์ฌ์ ์ค์ธ ํญ๋ชฉ์ ํ์ด๋ผ์ดํ ํจ |
ReportAdapter |
๊ฒ์ ํ๋ฉด์์ ๋ฆฌํฌํธ ๋ชฉ๋ก์ ํ์ํ๊ณ , ๊ฐ ํญ๋ชฉ์ TTS ์ฌ์ ๋ฐ ์ฆ๊ฒจ์ฐพ๊ธฐ ๊ธฐ๋ฅ์ ์ ๊ณต |
๐ง ํต์ฌ ๋ก์ง
ItemAdapter
- ํญ๋ชฉ ํด๋ฆญ ์ด๋ฒคํธ ์ฒ๋ฆฌ
๐ holder.itemView.setOnClickListener(v -> {
if (onItemClickListener != null) {
onItemClickListener.onItemClick(item);
}
});
- ์ฌ์ฉ์๊ฐ ๋ฆฌ์คํธ ์์ดํ ์ ํด๋ฆญํ๋ฉด ์ฝ๋ฐฑ์ ํตํด ํด๋น ํญ๋ชฉ์ ์ฌ์ํ๋๋ก ํธ์ถํจ
ItemAdapter
- ์ฌ์ ์ค์ธ ํญ๋ชฉ ํ์
๐ต if (position == playingIndex) {
holder.itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.background_color));
}
- ํ์ฌ ์ฌ์ ์ค์ธ ํญ๋ชฉ๋ง ๋ฐฐ๊ฒฝ์์ ๋ฐ๊พธ์ด ํ์ํด์ค
ReportAdapter
- TTS ์ฌ์ ํ SimplePlayer๋ก ์ด๋
โถ๏ธ ttsHelper.performTextToSpeech(item.getContent(), fileName, audioFile -> {
if (audioFile != null && audioFile.exists()) {
Intent intent = new Intent(context, SimplePlayerActivity.class);
// ์ธํ
ํธ์ ๋ฆฌํฌํธ ์ ๋ณด์ ์ค๋์ค ๊ฒฝ๋ก ๋ด๊ธฐ
context.startActivity(intent);
}
});
- ๊ฒ์๋ ๋ฆฌํฌํธ๋ฅผ TTS๋ก ๋ณํ ํ ๋จ๋
์ฌ์ ํ๋ฉด์ธ
SimplePlayerActivity
๋ก ์ด๋
ReportAdapter
- ์ฆ๊ฒจ์ฐพ๊ธฐ(์ข์์) ์ ์ฅ
โญ SharedPreferences.Editor editor = prefs.edit();
String key = "liked_" + item.getTitle();
if (newLikeState) {
String json = gson.toJson(item);
editor.putString(key, json);
} else {
editor.remove(key);
}
editor.apply();
- ์ฆ๊ฒจ์ฐพ๊ธฐ ํ ๊ธ ์ SharedPreferences์ ์ ์ฅํ๊ฑฐ๋ ์ ๊ฑฐํ์ฌ ์ํ๋ฅผ ์ ์งํจ