Skip to content

Commit

Permalink
fixed site + tested chapterlist
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst committed Feb 1, 2024
1 parent 167b87a commit 577fb87
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ open class AllNovelProvider : MainAPI() {

override val iconBackgroundId = R.color.wuxiaWorldOnlineColor

open val ajaxUrl = "ajax-chapter-option"

override val tags = listOf(
"All" to "All",
"Shounen" to "Shounen",
Expand Down Expand Up @@ -122,7 +124,8 @@ open class AllNovelProvider : MainAPI() {

override suspend fun loadHtml(url: String): String? {
val document = app.get(url).document
return document.selectFirst("#chapter-content")?.html()?.replace(
return (document.selectFirst("#chapter-content")
?: document.selectFirst("#chr-content"))?.html()?.replace(
" If you find any errors ( broken links, non-standard content, etc.. ), Please let us know < report chapter > so we can fix it as soon as possible.",
" "
)?.replace("[Updated from F r e e w e b n o v e l. c o m]", "")
Expand All @@ -148,12 +151,21 @@ open class AllNovelProvider : MainAPI() {
document.selectFirst("h3.title")?.text() ?: throw ErrorLoadingException("invalid name")

val dataNovelId = document.select("#rating").attr("data-novel-id")

val chapterData = app.get("$mainUrl/ajax-chapter-option?novelId=$dataNovelId").document
val parsed = chapterData.select("select > option")
val ajaxUrl = "$mainUrl/$ajaxUrl?novelId=$dataNovelId"
val chapterData = app.get(ajaxUrl).document
var parsed = chapterData.select("select > option")
if (parsed.isEmpty()) {
parsed = chapterData.select(".list-chapter>li>a")
}

val data = parsed.mapNotNull { c ->
val cUrl = c?.attr("value") ?: return@mapNotNull null
var cUrl = c?.attr("value")
if (cUrl.isNullOrBlank()) {
cUrl = c.attr("href")
}
if (cUrl.isNullOrBlank()) {
return@mapNotNull null
}
val cName = c.text().ifEmpty {
"chapter $c"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jsoup.nodes.Element
class ReadNovelFullProvider : AllNovelProvider() { // todo check
override val mainUrl = "https://readnovelfull.com"
override val name = "ReadNovelFull"
override val ajaxUrl = "ajax/chapter-archive"
}
/*
class ReadNovelFullProvider : MainAPI() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.lagradost.quicknovel.ui.result

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.quicknovel.ChapterData
import com.lagradost.quicknovel.MainActivity
import com.lagradost.quicknovel.MainActivity.Companion.loadResult
import com.lagradost.quicknovel.SearchResponse
import com.lagradost.quicknovel.databinding.LoadingBottomBinding
import com.lagradost.quicknovel.databinding.SearchResultGridBinding
import com.lagradost.quicknovel.databinding.SimpleChapterBinding
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()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return ChapterAdapterHolder(SimpleChapterBinding.inflate(LayoutInflater.from(parent.context),parent,false))
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when(holder) {
is ChapterAdapterHolder -> {
val currentItem = getItem(position)
holder.bind(currentItem)
}
}
}

class ChapterAdapterHolder(private val binding : SimpleChapterBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(card : ChapterData) {
binding.apply {
name.text = card.name
releaseDate.text = card.dateOfRelease
releaseDate.isGone = card.dateOfRelease.isNullOrBlank()
}
}
}

class DiffCallback : DiffUtil.ItemCallback<ChapterData>() {
override fun areItemsTheSame(oldItem: ChapterData, newItem: ChapterData): Boolean = oldItem.url == newItem.url
override fun areContentsTheSame(oldItem: ChapterData, newItem: ChapterData): Boolean = oldItem == newItem
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.marginTop
import androidx.core.widget.NestedScrollView
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -126,6 +127,14 @@ class ResultFragment : Fragment() {
maxOf(0, total)
)
}
/*binding.hiddenView.apply {
setPadding(
paddingLeft,
paddingTop,
paddingRight,
maxOf(0, total)
)
}*/
}


Expand Down Expand Up @@ -187,9 +196,11 @@ class ResultFragment : Fragment() {

resultBack.setColorFilter(Color.WHITE)
resultTabs.removeAllTabs()
resultTabs.isVisible = api.hasReviews
resultTabs.isVisible = false
val hasRelated = !res.related.isNullOrEmpty()
if (api.hasReviews || hasRelated) {
val hasChapters = false //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))
if (api.hasReviews) {
resultTabs.addTab(
Expand All @@ -207,6 +218,18 @@ class ResultFragment : Fragment() {
}
setupGridView()
}
if (hasChapters) {
resultTabs.addTab(
resultTabs.newTab().setText(R.string.read_action_chapters).setId(3)
)
chapterList.apply {
val mainPageAdapter = ChapterAdapter()
adapter = mainPageAdapter
if (res is StreamResponse) {
mainPageAdapter.submitList(res.data)
}
}
}
}
val target = viewModel.currentTabIndex.value
if (target != null) {
Expand Down Expand Up @@ -444,9 +467,11 @@ class ResultFragment : Fragment() {
observe(viewModel.currentTabIndex) { pos ->
binding.apply {
resultNovelHolder.isVisible = 0 == pos
// hiddenView.isGone = 0 == pos
resultReviewsholder.isVisible = 1 == pos
reviewsFab.isVisible = 1 == pos
resultRelatedholder.isVisible = 2 == pos
resultChapterholder.isVisible = 3 == pos
}
}

Expand Down Expand Up @@ -529,7 +554,14 @@ class ResultFragment : Fragment() {
//result_container.setBackgroundColor(requireContext().colorFromAttribute(R.attr.bitDarkerGrayBackground))

binding.resultMainscroll.setOnScrollChangeListener { v: NestedScrollView, _, scrollY, _, oldScrollY ->
if (viewModel.isInReviews()) {
val arr = IntArray(2)
binding.resultScrollPadding.getLocationOnScreen(arr)
/*context?.resources?.displayMetrics?.let { displayMetrics->
binding.scrollHolder.setPadding(0, (displayMetrics.heightPixels - arr[1]),0,0)
println("scrolled: ${binding.scrollHolder.paddingTop}")
}*/
if (viewModel.isInReviews()) {
binding.reviewsFab.alpha = scrollY / 50.toPx.toFloat()
}

Expand Down
173 changes: 102 additions & 71 deletions app/src/main/res/layout/fragment_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,77 +425,6 @@
app:tabTextColor="?attr/textColor" />


<FrameLayout
android:visibility="gone"
tools:visibility="gone"
android:id="@+id/result_reviewsholder"
android:orientation="vertical"
android:minHeight="500dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/resultview_reviews_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:visibility="gone"
tools:visibility="visible">

<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/resultview_reviews_loading_shimmer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
app:shimmer_auto_start="true"
app:shimmer_base_alpha="0.2"
app:shimmer_duration="@integer/loading_time"
app:shimmer_highlight_alpha="0.3">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<include layout="@layout/loading_review" />

<include layout="@layout/loading_review" />

<include layout="@layout/loading_review" />

</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
</FrameLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_reviews"
tools:listitem="@layout/result_review"
android:layout_width="match_parent"
android:layout_height="match_parent">

</androidx.recyclerview.widget.RecyclerView>
</FrameLayout>

<FrameLayout
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/result_relatedholder"
android:orientation="vertical"
android:minHeight="500dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.lagradost.quicknovel.widget.AutofitRecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="5dp"
app:spanCount="3"
android:id="@+id/related_list"
android:orientation="vertical" />
</FrameLayout>

<LinearLayout
tools:visibility="gone"
android:id="@+id/result_novel_holder"
Expand Down Expand Up @@ -747,11 +676,113 @@ Translator: Rainbow Turtle"
</LinearLayout>
</LinearLayout>

<FrameLayout
android:background="@drawable/white_card"
android:visibility="gone"
tools:visibility="gone"
android:id="@+id/result_reviewsholder"
android:orientation="vertical"
android:minHeight="500dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/resultview_reviews_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:visibility="gone"
tools:visibility="visible">

<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/resultview_reviews_loading_shimmer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
app:shimmer_auto_start="true"
app:shimmer_base_alpha="0.2"
app:shimmer_duration="@integer/loading_time"
app:shimmer_highlight_alpha="0.3">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<include layout="@layout/loading_review" />

<include layout="@layout/loading_review" />

<include layout="@layout/loading_review" />

</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
</FrameLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/result_reviews"
tools:listitem="@layout/result_review"
android:layout_width="match_parent"
android:layout_height="match_parent">

</androidx.recyclerview.widget.RecyclerView>
</FrameLayout>

<FrameLayout
android:background="@drawable/white_card"
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/result_relatedholder"
android:orientation="vertical"
android:minHeight="500dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.lagradost.quicknovel.widget.AutofitRecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="5dp"
app:spanCount="3"
android:id="@+id/related_list"
android:orientation="vertical" />
</FrameLayout>

<FrameLayout
android:background="@drawable/white_card"
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/result_chapterholder"
android:orientation="vertical"
android:minHeight="500dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="5dp"
app:spanCount="1"
android:id="@+id/chapter_list"
android:orientation="vertical" />
</FrameLayout>

</LinearLayout>
</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
Loading

0 comments on commit 577fb87

Please sign in to comment.