Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
aayush262 2024-03-18 10:39:42 +05:30
commit 22dccaa24b
40 changed files with 561 additions and 165 deletions

View file

@ -7,7 +7,10 @@ import ani.dantotsu.databinding.ItemChartBinding
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartView
import com.github.aachartmodel.aainfographics.aachartcreator.AAMoveOverEventMessageModel
import com.github.aachartmodel.aainfographics.aachartcreator.AAOptions
import com.xwray.groupie.OnItemClickListener
import com.xwray.groupie.OnItemLongClickListener
import com.xwray.groupie.viewbinding.BindableItem
import com.xwray.groupie.viewbinding.GroupieViewHolder
class ChartItem(
private val title: String,
@ -31,6 +34,7 @@ class ChartItem(
) {
}
}
binding.chartView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
binding.chartView.callBack = callback
binding.chartView.reload()
binding.chartView.aa_drawChartWithChartOptions(aaOptions)
@ -49,4 +53,32 @@ class ChartItem(
override fun initializeViewBinding(view: View): ItemChartBinding {
return ItemChartBinding.bind(view)
}
override fun bind(viewHolder: GroupieViewHolder<ItemChartBinding>, position: Int) {
viewHolder.setIsRecyclable(false)
super.bind(viewHolder, position)
}
override fun bind(
viewHolder: GroupieViewHolder<ItemChartBinding>,
position: Int,
payloads: MutableList<Any>
) {
viewHolder.setIsRecyclable(false)
super.bind(viewHolder, position, payloads)
}
override fun bind(
viewHolder: GroupieViewHolder<ItemChartBinding>,
position: Int,
payloads: MutableList<Any>,
onItemClickListener: OnItemClickListener?,
onItemLongClickListener: OnItemLongClickListener?
) {
viewHolder.setIsRecyclable(false)
super.bind(viewHolder, position, payloads, onItemClickListener, onItemLongClickListener)
}
override fun getViewType(): Int {
return 0
}
}

View file

@ -68,8 +68,11 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
binding.profileViewPager.isUserInputEnabled = false
lifecycleScope.launch(Dispatchers.IO) {
val userid = intent.getIntExtra("userId", 0)
val respond = Anilist.query.getUserProfile(userid)
val userid = intent.getIntExtra("userId", -1)
val username = intent.getStringExtra("username") ?: ""
val respond =
if (userid != -1) Anilist.query.getUserProfile(userid) else
Anilist.query.getUserProfile(username)
val user = respond?.data?.user
if (user == null) {
toast("User not found")

View file

@ -65,7 +65,7 @@ class ProfileFragment : Fragment() {
binding.profileUserBio.setInitialScale(1)
val styledHtml = getFullAniHTML(
user.about ?: "",
activity.getColor(R.color.bg_opp)
ContextCompat.getColor(activity, R.color.bg_opp)
)
binding.profileUserBio.loadDataWithBaseURL(
null,
@ -76,7 +76,7 @@ class ProfileFragment : Fragment() {
)
binding.profileUserBio.setBackgroundColor(
ContextCompat.getColor(
requireContext(),
activity,
android.R.color.transparent
)
)
@ -86,7 +86,7 @@ class ProfileFragment : Fragment() {
super.onPageFinished(view, url)
binding.profileUserBio.setBackgroundColor(
ContextCompat.getColor(
requireContext(),
activity,
android.R.color.transparent
)
)
@ -146,7 +146,7 @@ class ProfileFragment : Fragment() {
}
binding.profileFavStaffRecycler.adapter = AuthorAdapter(favStaff)
binding.profileFavStaffRecycler.layoutManager = LinearLayoutManager(
requireContext(),
activity,
LinearLayoutManager.HORIZONTAL,
false
)
@ -155,7 +155,7 @@ class ProfileFragment : Fragment() {
}
binding.profileFavCharactersRecycler.adapter = CharacterAdapter(favCharacter)
binding.profileFavCharactersRecycler.layoutManager = LinearLayoutManager(
requireContext(),
activity,
LinearLayoutManager.HORIZONTAL,
false
)
@ -177,9 +177,9 @@ class ProfileFragment : Fragment() {
recyclerView.visibility = View.GONE
if (it != null) {
if (it.isNotEmpty()) {
recyclerView.adapter = MediaAdaptor(0, it, requireActivity(), fav=true)
recyclerView.adapter = MediaAdaptor(0, it, activity, fav=true)
recyclerView.layoutManager = LinearLayoutManager(
requireContext(),
activity,
LinearLayoutManager.HORIZONTAL,
false
)

View file

@ -51,9 +51,9 @@ class StatsFragment :
user = arguments?.getSerializable("user") as Query.UserProfile
binding.statisticList.adapter = adapter
binding.statisticList.setHasFixedSize(true)
binding.statisticList.recycledViewPool.setMaxRecycledViews(0, 0)
binding.statisticList.isNestedScrollingEnabled = true
binding.statisticList.layoutManager = LinearLayoutManager(requireContext())
binding.statisticList.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.statisticProgressBar.visibility = View.VISIBLE
binding.compare.visibility = if (user.id == Anilist.userid) View.GONE else View.VISIBLE
binding.filterContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin = statusBarHeight }
@ -104,9 +104,15 @@ class StatsFragment :
binding.filterContainer.visibility = View.GONE
}
override fun onPause() {
super.onPause()
binding.statisticList.visibility = View.GONE
}
override fun onResume() {
super.onResume()
if (this::binding.isInitialized) {
binding.statisticList.visibility = View.VISIBLE
binding.root.requestLayout()
if (!loadedFirstTime) {
activity.lifecycleScope.launch {

View file

@ -79,6 +79,10 @@ class ActivityItemBuilder {
NotificationType.MEDIA_DELETION -> {
"${notification.deletedMediaTitle} has been deleted from the site"
}
NotificationType.COMMENT_REPLY -> {
notification.context ?: "You should not see this"
}
}
}

View file

@ -19,6 +19,7 @@ import ani.dantotsu.databinding.FragmentFeedBinding
import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.snackString
import ani.dantotsu.util.Logger
import com.xwray.groupie.GroupieAdapter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -80,7 +81,8 @@ class FeedFragment : Fragment() {
binding.listRecyclerView.setOnTouchListener { _, event ->
if (event?.action == MotionEvent.ACTION_UP) {
if (activityList.size % AnilistQueries.ITEMS_PER_PAGE != 0 && !global) {
snackString("No more activities")
//snackString("No more activities") fix spam?
Logger.log("No more activities")
} else if (!scrollView.canScrollVertically(1) && !binding.feedRefresh.isVisible
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
(binding.listRecyclerView.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() == (binding.listRecyclerView.adapter!!.itemCount - 1)

View file

@ -18,6 +18,7 @@ import ani.dantotsu.databinding.ActivityFollowBinding
import ani.dantotsu.initActivity
import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.navBarHeight
import ani.dantotsu.notifications.comment.CommentStore
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
@ -29,6 +30,7 @@ import com.xwray.groupie.GroupieAdapter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Locale
class NotificationActivity : AppCompatActivity() {
private lateinit var binding: ActivityFollowBinding
@ -73,7 +75,25 @@ class NotificationActivity : AppCompatActivity() {
notifications.filter { it.id == activityId }
} else {
notifications
}.toMutableList()
val commentStore = PrefManager.getNullableVal<List<CommentStore>>(
PrefName.CommentNotificationStore,
null
) ?: listOf()
commentStore.forEach {
val notification = Notification(
"COMMENT_REPLY",
System.currentTimeMillis().toInt(),
commentId = it.commentId,
notificationType = "COMMENT_REPLY",
mediaId = it.mediaId,
context = it.title + "\n" + it.content,
createdAt = (it.time / 1000L).toInt(),
)
notificationList = notificationList + notification
}
notificationList = notificationList.sortedByDescending { it.createdAt }
adapter.update(notificationList.map { NotificationItem(it, ::onNotificationClick) })
}
withContext(Dispatchers.Main) {
@ -81,7 +101,8 @@ class NotificationActivity : AppCompatActivity() {
binding.listRecyclerView.setOnTouchListener { _, event ->
if (event?.action == MotionEvent.ACTION_UP) {
if (adapter.itemCount % AnilistQueries.ITEMS_PER_PAGE != 0) {
snackString("No more notifications")
//snackString("No more notifications") fix spam?
Logger.log("No more notifications")
} else if (!binding.listRecyclerView.canScrollVertically(1) && !binding.followRefresh.isVisible
&& binding.listRecyclerView.adapter!!.itemCount != 0 &&
(binding.listRecyclerView.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() == (binding.listRecyclerView.adapter!!.itemCount - 1)
@ -105,7 +126,6 @@ class NotificationActivity : AppCompatActivity() {
}
}
}
private fun loadPage(onFinish: () -> Unit = {}) {
lifecycleScope.launch(Dispatchers.IO) {
val res = Anilist.query.getNotifications(Anilist.userid ?: 0, page)
@ -120,7 +140,7 @@ class NotificationActivity : AppCompatActivity() {
}
}
private fun onNotificationClick(id: Int, type: NotificationClickType) {
private fun onNotificationClick(id: Int, optional: Int?, type: NotificationClickType) {
when (type) {
NotificationClickType.USER -> {
ContextCompat.startActivity(
@ -143,6 +163,16 @@ class NotificationActivity : AppCompatActivity() {
)
}
NotificationClickType.COMMENT -> {
ContextCompat.startActivity(this, Intent(this, MediaDetailsActivity::class.java)
.putExtra("FRAGMENT_TO_LOAD", "COMMENTS")
.putExtra("mediaId", id)
.putExtra("commentId", optional ?: -1),
null
)
}
NotificationClickType.UNDEFINED -> {
// Do nothing
}
@ -151,7 +181,7 @@ class NotificationActivity : AppCompatActivity() {
companion object {
enum class NotificationClickType {
USER, MEDIA, ACTIVITY, UNDEFINED
USER, MEDIA, ACTIVITY, COMMENT, UNDEFINED
}
}
}

View file

@ -14,7 +14,7 @@ import com.xwray.groupie.viewbinding.BindableItem
class NotificationItem(
private val notification: Notification,
val clickCallback: (Int, NotificationClickType) -> Unit
val clickCallback: (Int, Int?, NotificationClickType) -> Unit
) : BindableItem<ItemNotificationBinding>() {
private lateinit var binding: ItemNotificationBinding
override fun bind(viewBinding: ItemNotificationBinding, position: Int) {
@ -31,7 +31,7 @@ class NotificationItem(
return ItemNotificationBinding.bind(view)
}
private fun image(user: Boolean = false) {
private fun image(user: Boolean = false, commentNotification: Boolean = false) {
val cover = if (user) notification.user?.bannerImage
?: notification.user?.avatar?.medium else notification.media?.bannerImage
@ -52,7 +52,13 @@ class NotificationItem(
binding.notificationCover.visibility = View.GONE
binding.notificationCoverUser.visibility = View.VISIBLE
binding.notificationCoverUserContainer.visibility = View.VISIBLE
binding.notificationCoverUser.loadImage(notification.user?.avatar?.large)
if (commentNotification) {
binding.notificationCoverUser.setImageResource(R.drawable.ic_dantotsu_round)
binding.notificationCoverUser.scaleX = 1.4f
binding.notificationCoverUser.scaleY = 1.4f
} else {
binding.notificationCoverUser.loadImage(notification.user?.avatar?.large)
}
binding.notificationBannerImage.layoutParams.height = userHeight
} else {
binding.notificationCover.visibility = View.VISIBLE
@ -75,12 +81,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.activityId ?: 0, NotificationClickType.ACTIVITY
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
)
}
}
@ -90,12 +96,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.activityId ?: 0, NotificationClickType.ACTIVITY
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
)
}
}
@ -105,12 +111,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.userId ?: 0, NotificationClickType.USER
notification.userId ?: 0, null, NotificationClickType.USER
)
}
}
@ -120,12 +126,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.activityId ?: 0, NotificationClickType.ACTIVITY
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
)
}
}
@ -135,12 +141,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
}
@ -150,12 +156,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
}
@ -165,12 +171,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
}
@ -180,7 +186,7 @@ class NotificationItem(
image()
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.media?.id ?: 0, NotificationClickType.MEDIA
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
)
}
}
@ -190,12 +196,12 @@ class NotificationItem(
binding.notificationCover.loadImage(notification.user?.avatar?.large)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.activityId ?: 0, NotificationClickType.ACTIVITY
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
)
}
}
@ -205,12 +211,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.activityId ?: 0, NotificationClickType.ACTIVITY
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
)
}
}
@ -220,12 +226,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
}
@ -235,12 +241,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
}
@ -250,12 +256,12 @@ class NotificationItem(
image(true)
binding.notificationCoverUser.setOnClickListener {
clickCallback(
notification.user?.id ?: 0, NotificationClickType.USER
notification.user?.id ?: 0, null, NotificationClickType.USER
)
}
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.activityId ?: 0, NotificationClickType.ACTIVITY
notification.activityId ?: 0, null, NotificationClickType.ACTIVITY
)
}
}
@ -265,7 +271,7 @@ class NotificationItem(
image()
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.media?.id ?: 0, NotificationClickType.MEDIA
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
)
}
}
@ -275,7 +281,7 @@ class NotificationItem(
image()
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.media?.id ?: 0, NotificationClickType.MEDIA
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
)
}
}
@ -285,7 +291,7 @@ class NotificationItem(
image()
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.media?.id ?: 0, NotificationClickType.MEDIA
notification.media?.id ?: 0, null, NotificationClickType.MEDIA
)
}
}
@ -293,6 +299,17 @@ class NotificationItem(
NotificationType.MEDIA_DELETION -> {
binding.notificationCover.visibility = View.GONE
}
NotificationType.COMMENT_REPLY -> {
image(user = true, commentNotification = true)
if (notification.commentId != null && notification.mediaId != null) {
binding.notificationBannerImage.setOnClickListener {
clickCallback(
notification.mediaId, notification.commentId, NotificationClickType.COMMENT
)
}
}
}
}
}