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์— ์ €์žฅํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•˜์—ฌ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•จ