Skip to content

Commit

Permalink
Criado novo modelo para a biblioteca com separador.
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonnySalles committed Sep 2, 2023
1 parent c0080aa commit 7127508
Show file tree
Hide file tree
Showing 33 changed files with 558 additions and 235 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package br.com.fenix.bilingualreader.model.entity

data class Separator(
var title: String,
var items: Int = 0
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Separator

if (title != other.title) return false

return true
}

override fun hashCode(): Int {
return title.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package br.com.fenix.bilingualreader.model.enums

enum class LibraryMangaType {
GRID_BIG, GRID_MEDIUM, GRID_SMALL, LINE
GRID_BIG, GRID_MEDIUM, GRID_SMALL, SEPARATOR_BIG, SEPARATOR_MEDIUM, LINE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package br.com.fenix.bilingualreader.service.listener

sealed interface BaseCardListenner
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package br.com.fenix.bilingualreader.service.listener
import android.view.View
import br.com.fenix.bilingualreader.model.entity.Book

interface BookCardListener {
interface BookCardListener: BaseCardListenner {
fun onClick(book: Book)
fun onClickFavorite(book: Book)
fun onClickConfig(book: Book, root: View, item: View, position: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package br.com.fenix.bilingualreader.service.listener
import android.view.View
import br.com.fenix.bilingualreader.model.entity.Manga

interface MangaCardListener {
interface MangaCardListener : BaseCardListenner {
fun onClick(manga: Manga)
fun onClickLong(manga: Manga, view : View, position: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ class ScannerManga(private val context: Context) {
var mIsRestarted = false
}

private fun generateCover(parse: Parse, manga: Manga) =
MangaImageCoverController.instance.getCoverFromFile(context, manga.file, parse)
private fun generateCover(parse: Parse, manga: Manga) = MangaImageCoverController.instance.getCoverFromFile(context, manga.file, parse)

private inner class LibraryUpdateRunnable(var library: Library, val isSilent: Boolean = false) : Runnable {
override fun run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import br.com.fenix.bilingualreader.model.entity.Chapters
import br.com.fenix.bilingualreader.service.listener.ChapterCardListener


class ChaptersLineAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ChaptersGridAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private lateinit var mListener: ChapterCardListener
private var mChaptersList: List<Chapters> = listOf()
Expand Down Expand Up @@ -50,13 +50,9 @@ class ChaptersLineAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
HEADER -> ChaptersHeaderViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.grid_card_divider_chapters, parent, false), mListener
)
HEADER -> ChaptersHeaderViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.grid_separator_header, parent, false))
else -> ChaptersViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.grid_card_chapters, parent, false), mListener
LayoutInflater.from(parent.context).inflate(R.layout.grid_card_chapters, parent, false), mListener
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import br.com.fenix.bilingualreader.R
import br.com.fenix.bilingualreader.model.entity.Chapters
import br.com.fenix.bilingualreader.service.listener.ChapterCardListener

class ChaptersHeaderViewHolder(itemView: View, private val listener: ChapterCardListener) :
RecyclerView.ViewHolder(itemView) {
class ChaptersHeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

fun bind(chapters: Chapters) {
itemView.findViewById<TextView>(R.id.chapters_title).text = chapters.title
itemView.findViewById<TextView>(R.id.separator_title).text = chapters.title
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import br.com.fenix.bilingualreader.model.entity.Chapters
import br.com.fenix.bilingualreader.service.listener.ChapterCardListener
import com.google.android.material.card.MaterialCardView

class ChaptersViewHolder(itemView: View, private val listener: ChapterCardListener) :
RecyclerView.ViewHolder(itemView) {
class ChaptersViewHolder(itemView: View, private val listener: ChapterCardListener) : RecyclerView.ViewHolder(itemView) {

companion object {
var mPageSelectStroke: Int = 0
}

init {
mPageSelectStroke =
itemView.resources.getDimension(R.dimen.manga_chapter_selected_stroke).toInt()
mPageSelectStroke = itemView.resources.getDimension(R.dimen.manga_chapter_selected_stroke).toInt()
}

fun bind(chapter: Chapters, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package br.com.fenix.bilingualreader.view.adapter.library

import br.com.fenix.bilingualreader.model.entity.Manga
import br.com.fenix.bilingualreader.model.enums.Order
import br.com.fenix.bilingualreader.service.listener.BaseCardListenner
import br.com.fenix.bilingualreader.service.listener.MangaCardListener

interface BaseAdapter<T, L : BaseCardListenner> {
abstract var isAnimation: Boolean
fun removeList(item: T);
fun updateList(order: Order, list: MutableList<T>)
fun attachListener(listener: L)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import android.view.animation.AnimationUtils
import androidx.recyclerview.widget.RecyclerView
import br.com.fenix.bilingualreader.R
import br.com.fenix.bilingualreader.model.entity.Book
import br.com.fenix.bilingualreader.model.enums.Order
import br.com.fenix.bilingualreader.service.listener.BookCardListener
import br.com.fenix.bilingualreader.service.listener.MangaCardListener

class BookGridCardAdapter : RecyclerView.Adapter<BookGridViewHolder>() {
class BookGridCardAdapter : RecyclerView.Adapter<BookGridViewHolder>(), BaseAdapter<Book, BookCardListener> {

private lateinit var mListener: BookCardListener
private var mMangaList: MutableList<Book> = mutableListOf()
var isAnimation: Boolean = true
override var isAnimation: Boolean = true

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookGridViewHolder {
val item =
Expand All @@ -35,17 +37,17 @@ class BookGridCardAdapter : RecyclerView.Adapter<BookGridViewHolder>() {
return mMangaList.size
}

fun attachListener(listener: BookCardListener) {
override fun attachListener(listener: BookCardListener) {
mListener = listener
}

fun removeList(book: Book) {
override fun removeList(book: Book) {
if (mMangaList.contains(book))
notifyItemRemoved(mMangaList.indexOf(book))
mMangaList.remove(book)
}

fun updateList(list: MutableList<Book>) {
override fun updateList(order: Order, list: MutableList<Book>) {
mMangaList = list
notifyDataSetChanged()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import android.view.animation.AnimationUtils
import androidx.recyclerview.widget.RecyclerView
import br.com.fenix.bilingualreader.R
import br.com.fenix.bilingualreader.model.entity.Book
import br.com.fenix.bilingualreader.model.entity.Manga
import br.com.fenix.bilingualreader.model.enums.Order
import br.com.fenix.bilingualreader.service.listener.BookCardListener
import br.com.fenix.bilingualreader.service.listener.MangaCardListener


class BookLineCardAdapter : RecyclerView.Adapter<BookLineViewHolder>() {
class BookLineCardAdapter : RecyclerView.Adapter<BookLineViewHolder>(), BaseAdapter<Book, BookCardListener> {

private lateinit var mListener: BookCardListener
private var mMangaList: MutableList<Book> = mutableListOf()
var isAnimation: Boolean = true
override var isAnimation: Boolean = true

override fun onBindViewHolder(holder: BookLineViewHolder, position: Int) {
holder.bind(mMangaList[position])
Expand All @@ -35,18 +38,19 @@ class BookLineCardAdapter : RecyclerView.Adapter<BookLineViewHolder>() {
return mMangaList.size
}

fun removeList(book: Book) {
override fun attachListener(listener: BookCardListener) {
mListener = listener
}

override fun removeList(book: Book) {
if (mMangaList.contains(book))
notifyItemRemoved(mMangaList.indexOf(book))
mMangaList.remove(book)
}

fun updateList(list: MutableList<Book>) {
override fun updateList(order: Order, list: MutableList<Book>) {
mMangaList = list
notifyDataSetChanged()
}

fun attachListener(listener: BookCardListener) {
mListener = listener
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import androidx.recyclerview.widget.RecyclerView
import br.com.fenix.bilingualreader.R
import br.com.fenix.bilingualreader.model.entity.Manga
import br.com.fenix.bilingualreader.model.enums.LibraryMangaType
import br.com.fenix.bilingualreader.model.enums.Order
import br.com.fenix.bilingualreader.service.listener.MangaCardListener

class MangaGridCardAdapter(var type: LibraryMangaType) : RecyclerView.Adapter<MangaGridViewHolder>() {
class MangaGridCardAdapter(var type: LibraryMangaType) : RecyclerView.Adapter<MangaGridViewHolder>(), BaseAdapter<Manga, MangaCardListener> {

private lateinit var mListener: MangaCardListener
private var mMangaList: MutableList<Manga> = mutableListOf()
var isAnimation: Boolean = true

override var isAnimation: Boolean = true
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MangaGridViewHolder {
val item = LayoutInflater.from(parent.context).inflate(R.layout.grid_card_manga, parent, false)
return MangaGridViewHolder(type, item, mListener)
Expand All @@ -35,17 +35,17 @@ class MangaGridCardAdapter(var type: LibraryMangaType) : RecyclerView.Adapter<Ma
return mMangaList.size
}

fun attachListener(listener: MangaCardListener) {
override fun attachListener(listener: MangaCardListener) {
mListener = listener
}

fun removeList(manga: Manga) {
override fun removeList(manga: Manga) {
if (mMangaList.contains(manga))
notifyItemRemoved(mMangaList.indexOf(manga))
mMangaList.remove(manga)
}

fun updateList(list: MutableList<Manga>) {
override fun updateList(order: Order, list: MutableList<Manga>) {
mMangaList = list
notifyDataSetChanged()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class MangaGridViewHolder(var type: LibraryMangaType, itemView: View, private va
subtitle.visibility = if (manga.hasSubtitle) View.VISIBLE else View.GONE

when (type) {
LibraryMangaType.GRID_MEDIUM -> if (mIsLandscape) cardView.layoutParams.width = mMangaCardWidthLandscapeMedium
else cardView.layoutParams.width = mMangaCardWidthMedium
LibraryMangaType.GRID_MEDIUM -> cardView.layoutParams.width = if (mIsLandscape) mMangaCardWidthLandscapeMedium else mMangaCardWidthMedium
LibraryMangaType.GRID_SMALL ->
if (mIsLandscape) {
cardView.layoutParams.width = mMangaCardWidthSmall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import android.view.animation.AnimationUtils
import androidx.recyclerview.widget.RecyclerView
import br.com.fenix.bilingualreader.R
import br.com.fenix.bilingualreader.model.entity.Manga
import br.com.fenix.bilingualreader.model.enums.Order
import br.com.fenix.bilingualreader.service.listener.MangaCardListener


class MangaLineCardAdapter : RecyclerView.Adapter<MangaLineViewHolder>() {
class MangaLineCardAdapter : RecyclerView.Adapter<MangaLineViewHolder>(), BaseAdapter<Manga, MangaCardListener> {

private lateinit var mListener: MangaCardListener
private var mMangaList: MutableList<Manga> = mutableListOf()
var isAnimation: Boolean = true
override var isAnimation: Boolean = true

override fun onBindViewHolder(holder: MangaLineViewHolder, position: Int) {
holder.bind(mMangaList[position])
Expand All @@ -35,18 +36,18 @@ class MangaLineCardAdapter : RecyclerView.Adapter<MangaLineViewHolder>() {
return mMangaList.size
}

fun removeList(manga: Manga) {
override fun removeList(manga: Manga) {
if (mMangaList.contains(manga))
notifyItemRemoved(mMangaList.indexOf(manga))
mMangaList.remove(manga)
}

fun updateList(list: MutableList<Manga>) {
override fun updateList(order: Order, list: MutableList<Manga>) {
mMangaList = list
notifyDataSetChanged()
}

fun attachListener(listener: MangaCardListener) {
override fun attachListener(listener: MangaCardListener) {
mListener = listener
}
}
Loading

0 comments on commit 7127508

Please sign in to comment.