chore: cleanup
This commit is contained in:
parent
a573fbdc89
commit
ea48809d07
10 changed files with 42 additions and 116 deletions
|
@ -373,70 +373,11 @@ class AnilistQueries {
|
|||
}
|
||||
return media
|
||||
}
|
||||
|
||||
suspend fun continueMedia(type: String, planned: Boolean = false): ArrayList<Media> {
|
||||
val returnArray = arrayListOf<Media>()
|
||||
val map = mutableMapOf<Int, Media>()
|
||||
val query = if (planned) {
|
||||
"""{ planned: ${continueMediaQuery(type, "PLANNING")} }"""
|
||||
} else {
|
||||
"""{
|
||||
current: ${continueMediaQuery(type, "CURRENT")},
|
||||
repeating: ${continueMediaQuery(type, "REPEATING")}
|
||||
}"""
|
||||
}
|
||||
|
||||
val response = executeQuery<Query.CombinedMediaListResponse>(query)
|
||||
if (planned) {
|
||||
response?.data?.planned?.lists?.forEach { li ->
|
||||
li.entries?.reversed()?.forEach {
|
||||
val m = Media(it)
|
||||
m.cameFromContinue = true
|
||||
map[m.id] = m
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response?.data?.current?.lists?.forEach { li ->
|
||||
li.entries?.reversed()?.forEach {
|
||||
val m = Media(it)
|
||||
m.cameFromContinue = true
|
||||
map[m.id] = m
|
||||
}
|
||||
}
|
||||
response?.data?.repeating?.lists?.forEach { li ->
|
||||
li.entries?.reversed()?.forEach {
|
||||
val m = Media(it)
|
||||
m.cameFromContinue = true
|
||||
map[m.id] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type != "ANIME") {
|
||||
returnArray.addAll(map.values)
|
||||
return returnArray
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val list = PrefManager.getNullableCustomVal(
|
||||
"continueAnimeList",
|
||||
listOf<Int>(),
|
||||
List::class.java
|
||||
) as List<Int>
|
||||
if (list.isNotEmpty()) {
|
||||
list.reversed().forEach {
|
||||
if (map.containsKey(it)) returnArray.add(map[it]!!)
|
||||
}
|
||||
for (i in map) {
|
||||
if (i.value !in returnArray) returnArray.add(i.value)
|
||||
}
|
||||
} else returnArray.addAll(map.values)
|
||||
return returnArray
|
||||
}
|
||||
|
||||
private fun continueMediaQuery(type: String, status: String): String {
|
||||
return """ MediaListCollection(userId: ${Anilist.userid}, type: $type, status: $status , sort: UPDATED_TIME ) { lists { entries { progress private score(format:POINT_100) status media { id idMal type isAdult status chapters episodes nextAiringEpisode {episode} meanScore isFavourite format bannerImage coverImage{large} title { english romaji userPreferred } } } } } """
|
||||
}
|
||||
|
||||
suspend fun favMedia(anime: Boolean, id: Int? = Anilist.userid): ArrayList<Media> {
|
||||
private suspend fun favMedia(anime: Boolean, id: Int? = Anilist.userid): ArrayList<Media> {
|
||||
var hasNextPage = true
|
||||
var page = 0
|
||||
|
||||
|
@ -464,41 +405,6 @@ class AnilistQueries {
|
|||
return """User(id:${id}){id favourites{${if (anime) "anime" else "manga"}(page:$page){pageInfo{hasNextPage}edges{favouriteOrder node{id idMal isAdult mediaListEntry{ progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode{episode}meanScore isFavourite format startDate{year month day} title{english romaji userPreferred}type status(version:2)bannerImage coverImage{large}}}}}}"""
|
||||
}
|
||||
|
||||
suspend fun recommendations(): ArrayList<Media> {
|
||||
val response = executeQuery<Query.Page>("""{${recommendationQuery()}}""")
|
||||
val map = mutableMapOf<Int, Media>()
|
||||
response?.data?.page?.apply {
|
||||
recommendations?.onEach {
|
||||
val json = it.mediaRecommendation
|
||||
if (json != null) {
|
||||
val m = Media(json)
|
||||
m.relation = json.type?.toString()
|
||||
map[m.id] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val types = arrayOf("ANIME", "MANGA")
|
||||
suspend fun repeat(type: String) {
|
||||
val res =
|
||||
executeQuery<Query.MediaListCollection>("""{${recommendationPlannedQuery(type)}}""")
|
||||
res?.data?.mediaListCollection?.lists?.forEach { li ->
|
||||
li.entries?.forEach {
|
||||
val m = Media(it)
|
||||
if (m.status == "RELEASING" || m.status == "FINISHED") {
|
||||
m.relation = it.media?.type?.toString()
|
||||
map[m.id] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
types.forEach { repeat(it) }
|
||||
|
||||
val list = ArrayList(map.values.toList())
|
||||
list.sortByDescending { it.meanScore }
|
||||
return list
|
||||
}
|
||||
|
||||
private fun recommendationQuery(): String {
|
||||
return """ Page(page: 1, perPage:30) { pageInfo { total currentPage hasNextPage } recommendations(sort: RATING_DESC, onList: true) { rating userRating mediaRecommendation { id idMal isAdult mediaListEntry { progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode {episode} popularity meanScore isFavourite format title {english romaji userPreferred } type status(version: 2) bannerImage coverImage { large } } } } """
|
||||
}
|
||||
|
@ -1562,7 +1468,7 @@ Page(page:$page,perPage:50) {
|
|||
return getUserProfile(id)
|
||||
}
|
||||
|
||||
suspend fun getUserId(username: String): Int? {
|
||||
private suspend fun getUserId(username: String): Int? {
|
||||
return executeQuery<Query.User>(
|
||||
"""{User(name:"$username"){id}}""",
|
||||
force = true
|
||||
|
@ -1577,8 +1483,8 @@ Page(page:$page,perPage:50) {
|
|||
)
|
||||
}
|
||||
|
||||
private fun userFavMediaQuery(anime: Boolean, page: Int, id: Int): String {
|
||||
return """User(id:${id}){id favourites{${if (anime) "anime" else "manga"}(page:$page){pageInfo{hasNextPage}edges{favouriteOrder node{id idMal isAdult mediaListEntry{ progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode{episode}meanScore isFavourite format startDate{year month day} title{english romaji userPreferred}type status(version:2)bannerImage coverImage{large}}}}}}"""
|
||||
private fun userFavMediaQuery(anime: Boolean, id: Int): String {
|
||||
return """User(id:${id}){id favourites{${if (anime) "anime" else "manga"}(page:1){pageInfo{hasNextPage}edges{favouriteOrder node{id idMal isAdult mediaListEntry{ progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode{episode}meanScore isFavourite format startDate{year month day} title{english romaji userPreferred}type status(version:2)bannerImage coverImage{large}}}}}}"""
|
||||
}
|
||||
|
||||
suspend fun userFollowing(id: Int): Query.Following? {
|
||||
|
@ -1598,8 +1504,8 @@ Page(page:$page,perPage:50) {
|
|||
suspend fun initProfilePage(id: Int): Query.ProfilePageMedia? {
|
||||
return executeQuery<Query.ProfilePageMedia>(
|
||||
"""{
|
||||
favoriteAnime:${userFavMediaQuery(true, 1, id)}
|
||||
favoriteManga:${userFavMediaQuery(false, 1, id)}
|
||||
favoriteAnime:${userFavMediaQuery(true, id)}
|
||||
favoriteManga:${userFavMediaQuery(false, id)}
|
||||
}""".trimIndent(), force = true
|
||||
)
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ class HomeFragment : Fragment() {
|
|||
binding.homeRecommendedEmpty,
|
||||
binding.homeRecommended
|
||||
)
|
||||
binding.homeUserStatusContainer.visibility = if (PrefManager.getVal<List<Boolean>>(PrefName.HomeLayout)[7]) View.VISIBLE else View.GONE
|
||||
binding.homeUserStatusContainer.visibility =View.VISIBLE
|
||||
binding.homeUserStatusProgressBar.visibility = View.VISIBLE
|
||||
binding.homeUserStatusRecyclerView.visibility = View.GONE
|
||||
model.getUserStatus().observe(viewLifecycleOwner) {
|
||||
|
@ -364,7 +364,8 @@ class HomeFragment : Fragment() {
|
|||
"MangaContinue",
|
||||
"MangaFav",
|
||||
"MangaPlanned",
|
||||
"Recommendation"
|
||||
"Recommendation",
|
||||
"UserStatus"
|
||||
)
|
||||
|
||||
val containers = arrayOf(
|
||||
|
@ -375,6 +376,7 @@ class HomeFragment : Fragment() {
|
|||
binding.homeFavMangaContainer,
|
||||
binding.homePlannedMangaContainer,
|
||||
binding.homeRecommendedContainer,
|
||||
binding.homeUserStatusContainer,
|
||||
)
|
||||
|
||||
val live = Refresh.activity.getOrPut(1) { MutableLiveData(false) }
|
||||
|
|
|
@ -38,7 +38,7 @@ class CircleView(context: Context, attrs: AttributeSet?) : View(context, attrs)
|
|||
val secondColor = typedValue1.data
|
||||
fun setColor(int: Int) {
|
||||
paint.color = if (int < booleanList.size && booleanList[int]) {
|
||||
if (isUser) secondColor else Color.GRAY
|
||||
Color.GRAY
|
||||
} else {
|
||||
if (isUser) secondColor else primaryColor
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ class StatusActivity : AppCompatActivity(), StoriesCallback {
|
|||
slideOutLeft = AnimationUtils.loadAnimation(this, R.anim.slide_out_left)
|
||||
slideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right)
|
||||
|
||||
val watchedActivity = PrefManager.getCustomVal<Set<Int>>("activities", setOf())
|
||||
val key = "activities"
|
||||
val watchedActivity = PrefManager.getCustomVal<Set<Int>>(key, setOf())
|
||||
val startFrom = findFirstNonMatch(watchedActivity, activity[position].activity )
|
||||
val startIndex = if ( startFrom > 0) startFrom else 0
|
||||
binding.stories.setStoriesList(activity[position].activity, this, startIndex + 1)
|
||||
|
@ -77,7 +78,8 @@ class StatusActivity : AppCompatActivity(), StoriesCallback {
|
|||
override fun onStoriesEnd() {
|
||||
position += 1
|
||||
if (position < activity.size) {
|
||||
val watchedActivity = PrefManager.getCustomVal<Set<Int>>("activities", setOf())
|
||||
val key = "activities"
|
||||
val watchedActivity = PrefManager.getCustomVal<Set<Int>>(key, setOf())
|
||||
val startFrom = findFirstNonMatch(watchedActivity, activity[position].activity )
|
||||
val startIndex= if ( startFrom > 0) startFrom else 0
|
||||
binding.stories.startAnimation(slideOutLeft)
|
||||
|
|
|
@ -262,7 +262,7 @@ constructor(
|
|||
}
|
||||
|
||||
private fun resetProgressBar(storyIndex: Int) {
|
||||
for (i in storyIndex until activityList.size) {
|
||||
for (i in storyIndex until activityList.size + 1) {
|
||||
val progressBar = findViewWithTag<ProgressBar>("story${i}")
|
||||
progressBar?.let {
|
||||
it.progress = 0
|
||||
|
@ -317,7 +317,7 @@ constructor(
|
|||
}
|
||||
userClicked = true
|
||||
animation.end()
|
||||
if (storyIndex < activityList.size)
|
||||
if (storyIndex <= activityList.size)
|
||||
storyIndex += 1
|
||||
showStory()
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ constructor(
|
|||
|
||||
val key = "activities"
|
||||
val set = PrefManager.getCustomVal<Set<Int>>(key, setOf()).plus((story.id))
|
||||
val newList = set.sorted().takeLast(120).toSet()
|
||||
val newList = set.sorted().takeLast(200).toSet()
|
||||
PrefManager.setCustomVal(key, newList)
|
||||
binding.statusUserAvatar.loadImage(story.user?.avatar?.large)
|
||||
binding.statusUserName.text = story.user?.name
|
||||
|
@ -395,7 +395,7 @@ constructor(
|
|||
it.toString()
|
||||
}
|
||||
}} ${story.progress ?: story.media?.title?.userPreferred} " +
|
||||
if (story.status?.contains("completed") == false) {
|
||||
if (story.status?.contains("completed") == false && !story.status.contains("plans") && !story.status.contains("repeating")) {
|
||||
"of ${story.media?.title?.userPreferred}"
|
||||
}else {
|
||||
""
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ani.dantotsu.home.status.listener
|
||||
|
||||
interface StoriesCallback {
|
||||
|
||||
fun onStoriesEnd()
|
||||
fun onStoriesStart()
|
||||
}
|
|
@ -40,6 +40,7 @@ import ani.dantotsu.databinding.ItemTitleTrailerBinding
|
|||
import ani.dantotsu.displayTimer
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.navBarHeight
|
||||
import ani.dantotsu.profile.User
|
||||
import ani.dantotsu.px
|
||||
import ani.dantotsu.setSafeOnClickListener
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
|
@ -572,6 +573,22 @@ class MediaInfoFragment : Fragment() {
|
|||
parent.addView(root)
|
||||
}
|
||||
}
|
||||
val users = media.users!!
|
||||
if (Anilist.token != null && media.userStatus != null) {
|
||||
users.add(0,
|
||||
User(
|
||||
Anilist.userid!!,
|
||||
Anilist.username!!,
|
||||
Anilist.avatar,
|
||||
Anilist.bg,
|
||||
status = media.userStatus,
|
||||
score = media.userScore.toFloat(),
|
||||
progress = media.userProgress,
|
||||
totalEpisodes = if (type == "ANIME") media.anime?.totalEpisodes else media.manga?.totalChapters,
|
||||
nextAiringEpisode = media.anime?.nextAiringEpisode
|
||||
)
|
||||
)
|
||||
}
|
||||
if (!media.users.isNullOrEmpty() && !offline) {
|
||||
ItemTitleRecyclerBinding.inflate(
|
||||
LayoutInflater.from(context),
|
||||
|
@ -580,7 +597,7 @@ class MediaInfoFragment : Fragment() {
|
|||
).apply {
|
||||
itemTitle.setText(R.string.social)
|
||||
itemRecycler.adapter =
|
||||
MediaSocialAdapter(media.users!!, type, requireActivity())
|
||||
MediaSocialAdapter(users, type, requireActivity())
|
||||
itemRecycler.layoutManager = LinearLayoutManager(
|
||||
requireContext(),
|
||||
LinearLayoutManager.HORIZONTAL,
|
||||
|
|
|
@ -27,7 +27,7 @@ import eltos.simpledialogfragment.color.SimpleColorDialog
|
|||
|
||||
class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListener {
|
||||
private lateinit var binding: ActivitySettingsThemeBinding
|
||||
private var reload = false
|
||||
private var reload = PrefManager.getCustomVal("reload", true)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ThemeManager(this).applyTheme()
|
||||
|
@ -211,7 +211,6 @@ class SettingsThemeActivity : AppCompatActivity(), SimpleDialog.OnDialogResultLi
|
|||
fun reload() {
|
||||
PrefManager.setCustomVal("reload", true)
|
||||
restartApp()
|
||||
reload = true
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue