Skip to content

Commit

Permalink
fixed chapterlist
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst committed Feb 1, 2024
1 parent 577fb87 commit 18c3c05
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.lagradost.quicknovel.util.UIHelper.setImage
import com.lagradost.quicknovel.util.toPx
import com.lagradost.quicknovel.widget.AutofitRecyclerView
import kotlin.math.roundToInt
class ChapterAdapter : ListAdapter<ChapterData, RecyclerView.ViewHolder>(DiffCallback()) {
class ChapterAdapter(val viewmodel : ResultViewModel) : ListAdapter<ChapterData, RecyclerView.ViewHolder>(DiffCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return ChapterAdapterHolder(SimpleChapterBinding.inflate(LayoutInflater.from(parent.context),parent,false))
}
Expand All @@ -29,17 +29,20 @@ class ChapterAdapter : ListAdapter<ChapterData, RecyclerView.ViewHolder>(DiffCal
when(holder) {
is ChapterAdapterHolder -> {
val currentItem = getItem(position)
holder.bind(currentItem)
holder.bind(currentItem, viewmodel)
}
}
}

class ChapterAdapterHolder(private val binding : SimpleChapterBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(card : ChapterData) {
fun bind(card : ChapterData, viewmodel : ResultViewModel) {
binding.apply {
name.text = card.name
releaseDate.text = card.dateOfRelease
releaseDate.isGone = card.dateOfRelease.isNullOrBlank()
root.setOnClickListener {
viewmodel.streamRead(card)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class ResultFragment : Fragment() {
maxOf(0, total)
)
}
val parameter = binding.chapterList.layoutParams
parameter.height = displayMetrics.heightPixels - binding.viewsAndRating.height-binding.resultTabs.height - binding.resultScrollPadding.paddingTop

binding.chapterList.layoutParams = parameter
//ViewGroup.LayoutParams(binding.chapterList.layoutParams.width,displayMetrics.heightPixels)
/*binding.hiddenView.apply {
setPadding(
paddingLeft,
Expand Down Expand Up @@ -198,7 +203,7 @@ class ResultFragment : Fragment() {
resultTabs.removeAllTabs()
resultTabs.isVisible = false
val hasRelated = !res.related.isNullOrEmpty()
val hasChapters = false //res is StreamResponse && res.data.isNotEmpty() // this was removed because of lag, because of shitty android
val hasChapters = res is StreamResponse && res.data.isNotEmpty() // this was removed because of lag, because of shitty android
if (api.hasReviews || hasRelated || hasChapters) {
resultTabs.isVisible = true
resultTabs.addTab(resultTabs.newTab().setText(R.string.novel).setId(0))
Expand All @@ -223,8 +228,9 @@ class ResultFragment : Fragment() {
resultTabs.newTab().setText(R.string.read_action_chapters).setId(3)
)
chapterList.apply {
val mainPageAdapter = ChapterAdapter()
val mainPageAdapter = ChapterAdapter(viewModel)
adapter = mainPageAdapter
setHasFixedSize(true)
if (res is StreamResponse) {
mainPageAdapter.submitList(res.data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ import com.lagradost.quicknovel.BaseApplication.Companion.getKey
import com.lagradost.quicknovel.BaseApplication.Companion.setKey
import com.lagradost.quicknovel.BookDownloader2
import com.lagradost.quicknovel.BookDownloader2Helper.generateId
import com.lagradost.quicknovel.ChapterData
import com.lagradost.quicknovel.CommonActivity.activity
import com.lagradost.quicknovel.DOWNLOAD_EPUB_LAST_ACCESS
import com.lagradost.quicknovel.DataStore.getKey
import com.lagradost.quicknovel.DownloadActionType
import com.lagradost.quicknovel.DownloadProgressState
import com.lagradost.quicknovel.DownloadState
import com.lagradost.quicknovel.EPUB_CURRENT_POSITION
import com.lagradost.quicknovel.EPUB_CURRENT_POSITION_SCROLL
import com.lagradost.quicknovel.EPUB_CURRENT_POSITION_SCROLL_CHAR
import com.lagradost.quicknovel.HISTORY_FOLDER
import com.lagradost.quicknovel.LoadResponse
import com.lagradost.quicknovel.R
import com.lagradost.quicknovel.RESULT_BOOKMARK
import com.lagradost.quicknovel.RESULT_BOOKMARK_STATE
import com.lagradost.quicknovel.ReadActivity2
import com.lagradost.quicknovel.ReadActivityViewModel
import com.lagradost.quicknovel.StreamResponse
import com.lagradost.quicknovel.UserReview
import com.lagradost.quicknovel.mvvm.Resource
Expand Down Expand Up @@ -134,10 +140,23 @@ class ResultViewModel : ViewModel() {
}
}

fun streamRead() = ioSafe {
fun streamRead(chapter : ChapterData? = null) = ioSafe {
loadMutex.withLock {
if (!hasLoaded) return@ioSafe
addToHistory()

chapter?.let {
// TODO BETTER STORE
val streamResponse = ((loadResponse.value as? Resource.Success)?.value as? StreamResponse)
val index = streamResponse?.data?.indexOf(chapter)
if (index!= null && index >= 0) {
setKey(EPUB_CURRENT_POSITION, streamResponse.name, index)
setKey(
EPUB_CURRENT_POSITION_SCROLL_CHAR, streamResponse.name,0,
)
}
}

BookDownloader2.stream(load, apiName)
}
}
Expand Down
10 changes: 1 addition & 9 deletions app/src/main/res/layout/fragment_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ Translator: Rainbow Turtle"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="500dp"
android:clipToPadding="false"
android:paddingTop="5dp"
app:spanCount="1"
Expand All @@ -775,14 +775,6 @@ Translator: Rainbow Turtle"
</FrameLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

<FrameLayout
android:id="@+id/scroll_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">


</FrameLayout>
</FrameLayout>

<ImageView
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/simple_chapter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
android:backgroundTint="?attr/primaryBlackBackground"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
app:cardCornerRadius="@dimen/rounded_button_radius"
app:cardCornerRadius="0dp"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
android:layout_height="50dp">

<LinearLayout
Expand Down

0 comments on commit 18c3c05

Please sign in to comment.