diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index c5c0ff3b..0897082f 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,17 +4,15 @@
diff --git a/app/src/main/java/com/lagradost/quicknovel/providers/RoyalRoadProvider.kt b/app/src/main/java/com/lagradost/quicknovel/providers/RoyalRoadProvider.kt
index 3f787e59..d1f37746 100644
--- a/app/src/main/java/com/lagradost/quicknovel/providers/RoyalRoadProvider.kt
+++ b/app/src/main/java/com/lagradost/quicknovel/providers/RoyalRoadProvider.kt
@@ -7,7 +7,7 @@ import org.jsoup.Jsoup
import java.lang.Exception
import java.util.*
import kotlin.collections.ArrayList
-
+// TODO https://www.royalroad.com/fictions/similar?fictionId=68679
class RoyalRoadProvider : MainAPI() {
override val name = "Royal Road"
override val mainUrl = "https://www.royalroad.com"
@@ -26,10 +26,12 @@ class RoyalRoadProvider : MainAPI() {
"Latest Updates" to "latest-updates",
"New Releases" to "new-releases",
"Trending" to "trending",
+ "Rising Stars" to "rising-stars",
+ "Writathon" to "writathon"
)
override val tags = listOf(
- "All" to "",
+ "All" to "") + (listOf(
"Wuxia" to "wuxia",
"Xianxia" to "xianxia",
"War and Military" to "war_and_military",
@@ -69,7 +71,6 @@ class RoyalRoadProvider : MainAPI() {
Pair("Female Lead", "female_lead"),
Pair("Portal Fantasy / Isekai", "summoned_hero"),
Pair("Reincarnation", "reincarnation"),
- Pair("High Fantasy", "high_fantasy"),
Pair("Harem", "harem"),
Pair("Gender Bender", "gender_bender"),
Pair("Anti-Hero Lead", "anti-hero_lead"),
@@ -77,7 +78,7 @@ class RoyalRoadProvider : MainAPI() {
Pair("Strategy", "strategy"),
Pair("Short Story", "one_shot"),
Pair("Tragedy", "tragedy")
- ).sortedBy { it.first }
+ ).sortedBy { it.first })
override val hasReviews = true
diff --git a/app/src/main/java/com/lagradost/quicknovel/ui/download/DownloadViewModel.kt b/app/src/main/java/com/lagradost/quicknovel/ui/download/DownloadViewModel.kt
index f373152f..73157a80 100644
--- a/app/src/main/java/com/lagradost/quicknovel/ui/download/DownloadViewModel.kt
+++ b/app/src/main/java/com/lagradost/quicknovel/ui/download/DownloadViewModel.kt
@@ -74,6 +74,7 @@ class DownloadViewModel : ViewModel() {
MutableLiveData()
var currentTab: MutableLiveData =
MutableLiveData()
+
fun refreshCard(card: DownloadFragment.DownloadDataLoaded) = viewModelScope.launch {
BookDownloader2.downloadFromCard(card)
}
@@ -121,7 +122,8 @@ class DownloadViewModel : ViewModel() {
cardsData.values
}
for (card in values) {
- if ((card.downloadedCount * 100 / card.downloadedTotal) > 90) {
+ // avoid div by zero
+ if (card.downloadedTotal <= 0 || (card.downloadedCount * 100 / card.downloadedTotal) > 90) {
BookDownloader2.downloadFromCard(card)
}
}
@@ -289,7 +291,7 @@ class DownloadViewModel : ViewModel() {
}
}
- fun selectTab(index : Int) {
+ fun selectTab(index: Int) {
currentTab.postValue(index)
if (index == 0) {
loadData()
diff --git a/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainAdapter2.kt b/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainAdapter2.kt
index d9a030b2..4b584ea3 100644
--- a/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainAdapter2.kt
+++ b/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainAdapter2.kt
@@ -10,22 +10,59 @@ import androidx.recyclerview.widget.RecyclerView
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.util.SettingsHelper.getGridIsCompact
import com.lagradost.quicknovel.util.UIHelper.setImage
import com.lagradost.quicknovel.util.toPx
import com.lagradost.quicknovel.widget.AutofitRecyclerView
import kotlin.math.roundToInt
+const val REGULAR_VIEW_TYPE = 0
+const val FOOTER_VIEW_TYPE = 1
+class MainAdapter2(private val resView: AutofitRecyclerView) : ListAdapter(DiffCallback()) {
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
+ return when (viewType) { // Use 'when' to create the correct holder for any position
+ REGULAR_VIEW_TYPE -> MainAdapter2Holder(SearchResultGridBinding.inflate(LayoutInflater.from(parent.context),parent,false))
+ FOOTER_VIEW_TYPE -> LoadingHolder(LoadingBottomBinding.inflate(LayoutInflater.from(parent.context),parent,false))
+ else -> {
+ throw NotImplementedError()
+ }
+ }
+ }
+
+ /* private var loadingItems : Boolean = false
+
+ fun setLoading(to : Boolean) {
+ if (loadingItems == to) return
+ if (to) {
+ loadingItems = true
+ notifyItemRemoved(currentList.size)
+ } else {
+ loadingItems = false
+ notifyItemInserted(currentList.size)
+ }
+ }*/
+
+ //override fun getItemCount() = currentList.size//if(loadingItems) 1 else 0 // We need the extra 1 for the footer to be counted
-class MainAdapter2(private val resView: AutofitRecyclerView) : ListAdapter(DiffCallback()) {
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainAdapter2Holder {
- val binding = SearchResultGridBinding.inflate(LayoutInflater.from(parent.context),parent,false)
- return MainAdapter2Holder(binding)
+ override fun getItemViewType(position: Int) =
+ if (position == currentList.size) FOOTER_VIEW_TYPE else REGULAR_VIEW_TYPE
+
+ override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
+ when(holder) {
+ is MainAdapter2Holder -> {
+ val currentItem = getItem(position)
+ holder.bind(currentItem, resView)
+ }
+ is LoadingHolder -> {
+ holder.bind()
+ }
+ }
}
- override fun onBindViewHolder(holder: MainAdapter2Holder, position: Int) {
- val currentItem = getItem(position)
- holder.bind(currentItem, resView)
+ class LoadingHolder(private val binding : LoadingBottomBinding) : RecyclerView.ViewHolder(binding.root) {
+ fun bind() {
+
+ }
}
class MainAdapter2Holder(private val binding : SearchResultGridBinding) : RecyclerView.ViewHolder(binding.root) {
diff --git a/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageFragment.kt b/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageFragment.kt
index 92e75827..41026de3 100644
--- a/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageFragment.kt
+++ b/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageFragment.kt
@@ -39,14 +39,15 @@ class MainPageFragment : Fragment() {
binding = FragmentMainpageBinding.inflate(inflater)
return binding.root
}
+
companion object {
- fun newInstance(
- apiName: String,
- mainCategory: Int? = null,
- orderBy: Int? = null,
- tag: Int? = null
- ) : Bundle =
- Bundle().apply {
+ fun newInstance(
+ apiName: String,
+ mainCategory: Int? = null,
+ orderBy: Int? = null,
+ tag: Int? = null
+ ): Bundle =
+ Bundle().apply {
putString("apiName", apiName)
if (mainCategory != null)
@@ -88,7 +89,6 @@ class MainPageFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val apiName = requireArguments().getString("apiName")!!
- viewModel.repo = MainPageRepository(Apis.getApiFromName(apiName))
defMainCategory = arguments?.getInt("mainCategory", 0)
defOrderBy = arguments?.getInt("orderBy", 0)
@@ -101,9 +101,8 @@ class MainPageFragment : Fragment() {
activity?.fixPaddingStatusbar(binding.mainpageToolbar)
- viewModel.load(
- 0,
- defMainCategory,
+ viewModel.init(
+ apiName, defMainCategory,
defOrderBy,
defTag
)
@@ -195,18 +194,20 @@ class MainPageFragment : Fragment() {
binding.mainpageLoadingError.isVisible = false
mainPageAdapter.submitList(value)
+ // mainPageAdapter.setLoading(false)
}
is Resource.Loading -> {
binding.mainpageLoading.isVisible = true
binding.mainpageLoadingError.isVisible = false
+ // mainPageAdapter.setLoading(true)
}
is Resource.Failure -> {
binding.mainpageErrorText.text = data.errorString
binding.mainpageLoading.isVisible = false
binding.mainpageLoadingError.isVisible = true
-
+ // mainPageAdapter.setLoading(false)
}
}
diff --git a/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageViewModel.kt b/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageViewModel.kt
index 81d8a990..2a279032 100644
--- a/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageViewModel.kt
+++ b/app/src/main/java/com/lagradost/quicknovel/ui/mainpage/MainPageViewModel.kt
@@ -9,11 +9,13 @@ import com.lagradost.quicknovel.APIRepository
import com.lagradost.quicknovel.CommonActivity.activity
import com.lagradost.quicknovel.SearchResponse
import com.lagradost.quicknovel.mvvm.Resource
+import com.lagradost.quicknovel.util.Apis
import kotlinx.coroutines.launch
class MainPageViewModel : ViewModel() {
lateinit var repo : MainPageRepository
val api: APIRepository get() = repo.api
+ private var hasInit = false
/*private val searchCards: MutableLiveData> by lazy {
MutableLiveData>()
@@ -80,6 +82,20 @@ class MainPageViewModel : ViewModel() {
isInSearch.postValue(false)
}
+ fun init(apiName : String, mainCategory: Int?,
+ orderBy: Int?,
+ tag: Int?) {
+ if (hasInit) return
+ hasInit = true
+ repo = MainPageRepository(Apis.getApiFromName(apiName))
+ load(
+ 0,
+ mainCategory,
+ orderBy,
+ tag
+ )
+ }
+
fun load(
page: Int?,
mainCategory: Int?,
diff --git a/app/src/main/res/layout/loading_bottom.xml b/app/src/main/res/layout/loading_bottom.xml
new file mode 100644
index 00000000..4361fa44
--- /dev/null
+++ b/app/src/main/res/layout/loading_bottom.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+