feat : qol things

This commit is contained in:
aayush262 2024-05-22 00:20:59 +05:30
parent 039e3d63fe
commit 48ccb2c581
9 changed files with 98 additions and 110 deletions

View file

@ -84,6 +84,7 @@ import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.RecyclerView
@ -96,6 +97,7 @@ import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.databinding.ItemCountDownBinding
import ani.dantotsu.media.Media
import ani.dantotsu.notifications.IncognitoNotificationClickReceiver
import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.others.SpoilerPlugin
import ani.dantotsu.parsers.ShowResponse
import ani.dantotsu.settings.saving.PrefManager
@ -1392,6 +1394,13 @@ fun Context.getThemeColor(@AttrRes attribute: Int): Int {
theme.resolveAttribute(attribute, typedValue, true)
return typedValue.data
}
fun ImageView.openImage(title: String, image: String) {
setOnLongClickListener{
ImageViewDialog.newInstance(
context as FragmentActivity, title, image
)
}
}
/**
* Builds the markwon instance with all the plugins
* @return the markwon instance

View file

@ -1,55 +0,0 @@
package ani.dantotsu.connections.github
import ani.dantotsu.settings.Developer
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
class Forks {
fun getForks(): Array<Developer> {
var forks = arrayOf<Developer>()
runBlocking(Dispatchers.IO) {
val trustedForks = arrayOf(
GithubResponse(
"Awery",
GithubResponse.Owner(
"MrBoomDeveloper",
"https://avatars.githubusercontent.com/u/92123190?v=4"
),
"https://github.com/MrBoomDeveloper/Awery"
),
)
trustedForks.forEach {
forks = forks.plus(
Developer(
it.name,
it.owner.avatarUrl,
it.owner.login,
it.htmlUrl
)
)
}
}
return forks
}
@Serializable
data class GithubResponse(
@SerialName("name")
val name: String,
val owner: Owner,
@SerialName("html_url")
val htmlUrl: String,
) {
@Serializable
data class Owner(
@SerialName("login")
val login: String,
@SerialName("avatar_url")
val avatarUrl: String
)
}
}

View file

@ -528,26 +528,11 @@ class MediaInfoFragment : Fragment() {
parent,
false
).apply {
fun onUserClick(userId: Int) {
val review = media.review!!.find { i -> i.id == userId }
if (review != null) {
startActivity(
Intent(requireContext(), ReviewViewActivity::class.java)
.putExtra("review", review)
)
}
}
val adapter = GroupieAdapter()
media.review!!.forEach {
adapter.add(ReviewAdapter(it, ::onUserClick))
}
media.review!!.forEach { adapter.add(ReviewAdapter(it)) }
itemTitle.setText(R.string.reviews)
itemRecycler.adapter = adapter
itemRecycler.layoutManager = LinearLayoutManager(
requireContext(),
LinearLayoutManager.VERTICAL,
false
)
itemRecycler.layoutManager = LinearLayoutManager(requireContext())
itemMore.visibility = View.VISIBLE
itemMore.setSafeOnClickListener {
startActivity(

View file

@ -122,19 +122,7 @@ class ReviewActivity : AppCompatActivity() {
private fun fillList() {
adapter.clear()
reviews.forEach {
adapter.add(
ReviewAdapter(
it,
this::onUserClick
)
)
}
}
private fun onUserClick(userId: Int) {
val review = reviews.find { it.id == userId }
if (review != null) {
startActivity(Intent(this, ReviewViewActivity::class.java).putExtra("review", review))
adapter.add(ReviewAdapter(it))
}
}
}

View file

@ -1,12 +1,24 @@
package ani.dantotsu.media
import android.app.Activity
import android.content.Intent
import android.view.View
import androidx.activity.ComponentActivity
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.ContextCompat
import androidx.core.util.Pair
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.api.Query
import ani.dantotsu.databinding.ItemReviewsBinding
import ani.dantotsu.loadImage
import ani.dantotsu.openImage
import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.profile.activity.ActivityItemBuilder
import ani.dantotsu.toast
import com.xwray.groupie.viewbinding.BindableItem
@ -18,19 +30,49 @@ import kotlinx.coroutines.withContext
class ReviewAdapter(
private var review: Query.Review,
val clickCallback: (Int) -> Unit
) : BindableItem<ItemReviewsBinding>() {
private lateinit var binding: ItemReviewsBinding
override fun bind(viewBinding: ItemReviewsBinding, position: Int) {
binding = viewBinding
val context = binding.root.context
binding.reviewUserName.text = review.user?.name
binding.reviewUserAvatar.loadImage(review.user?.avatar?.medium)
binding.reviewText.text = review.summary
binding.reviewPostTime.text = ActivityItemBuilder.getDateTime(review.createdAt)
val text = "[${review.score/ 10.0f}]"
binding.reviewTag.text = text
binding.root.setOnClickListener { clickCallback(review.id) }
binding.root.setOnClickListener {
ContextCompat.startActivity(
context,
Intent(context, ReviewViewActivity::class.java)
.putExtra("review", review),
null
)
}
binding.reviewUserName.setOnClickListener {
ContextCompat.startActivity(
context,
Intent(context, ProfileActivity::class.java)
.putExtra("userId", review.user?.id),
null
)
}
binding.reviewUserAvatar.setOnClickListener {
ContextCompat.startActivity(
context,
Intent(context, ProfileActivity::class.java)
.putExtra("userId", review.user?.id),
null
)
}
binding.reviewUserAvatar.openImage(
context.getString(
R.string.avatar,
review.user?.name
),
review.user?.avatar?.medium ?: ""
)
userVote(review.userRating)
enableVote()
binding.reviewTotalVotes.text = review.rating.toString()

View file

@ -1,5 +1,6 @@
package ani.dantotsu.media
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
@ -18,6 +19,9 @@ import ani.dantotsu.getThemeColor
import ani.dantotsu.initActivity
import ani.dantotsu.loadImage
import ani.dantotsu.navBarHeight
import ani.dantotsu.openImage
import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.profile.activity.ActivityItemBuilder
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
@ -47,6 +51,20 @@ class ReviewViewActivity : AppCompatActivity() {
binding.userName.text = review.user?.name
binding.userAvatar.loadImage(review.user?.avatar?.medium)
binding.userTime.text = ActivityItemBuilder.getDateTime(review.createdAt)
binding.userContainer.setOnClickListener {
startActivity(Intent(this, ProfileActivity::class.java)
.putExtra("userId", review.user?.id)
)
}
binding.userAvatar.openImage(
binding.root.context.getString(R.string.avatar, review.user?.name),
review.user?.avatar?.medium ?: ""
)
binding.userAvatar.setOnClickListener {
startActivity(Intent(this, ProfileActivity::class.java)
.putExtra("userId", review.user?.id)
)
}
binding.profileUserBio.settings.loadWithOverviewMode = true
binding.profileUserBio.settings.useWideViewPort = true
binding.profileUserBio.setInitialScale(1)

View file

@ -14,6 +14,7 @@ import ani.dantotsu.copyToClipboard
import ani.dantotsu.databinding.ItemCommentsBinding
import ani.dantotsu.getAppString
import ani.dantotsu.loadImage
import ani.dantotsu.openImage
import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.setAnimation
@ -251,13 +252,10 @@ class CommentItem(
}
}
commentTotalVotes.text = (comment.upvotes - comment.downvotes).toString()
commentUserAvatar.setOnLongClickListener {
ImageViewDialog.newInstance(
commentsFragment.activity,
commentUserAvatar.openImage(
commentsFragment.activity.getString(R.string.avatar, comment.username),
comment.profilePictureUrl
comment.profilePictureUrl ?: ""
)
}
comment.profilePictureUrl?.let { commentUserAvatar.loadImage(it) }
commentUserName.text = comment.username
val userColor = "[${levelColor.second}]"

View file

@ -28,6 +28,7 @@ import ani.dantotsu.initActivity
import ani.dantotsu.loadImage
import ani.dantotsu.media.user.ListActivity
import ani.dantotsu.navBarHeight
import ani.dantotsu.openImage
import ani.dantotsu.openLinkInBrowser
import ani.dantotsu.others.ImageViewDialog
import ani.dantotsu.profile.activity.FeedFragment
@ -171,13 +172,10 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
}
profileUserAvatar.loadImage(user.avatar?.medium)
profileUserAvatar.setOnLongClickListener {
ImageViewDialog.newInstance(
context,
getString(R.string.avatar, user.name),
user.avatar?.medium
profileUserAvatar.openImage(
context.getString(R.string.avatar, user.name),
user.avatar?.medium ?: ""
)
}
profileUserName.text = user.name
val bannerAnimations: ImageView= if (PrefManager.getVal(PrefName.BannerAnimations)) profileBannerImage else profileBannerImageNoKen
@ -192,13 +190,10 @@ class ProfileActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedListene
profileMenuButton.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += statusBarHeight }
profileButtonContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += statusBarHeight }
profileBannerImage.setOnLongClickListener {
ImageViewDialog.newInstance(
context,
getString(R.string.banner, user.name),
user.bannerImage
profileBannerImage.openImage(
context.getString(R.string.banner, user.name),
user.bannerImage ?: user.avatar?.medium ?: ""
)
}
mMaxScrollSize = profileAppBar.totalScrollRange
profileAppBar.addOnOffsetChangedListener(context)

View file

@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.BottomSheetDialogFragment
import ani.dantotsu.R
import ani.dantotsu.connections.github.Forks
import ani.dantotsu.databinding.BottomSheetDevelopersBinding
class ForksDialogFragment : BottomSheetDialogFragment() {
@ -26,7 +25,16 @@ class ForksDialogFragment : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.devsTitle.setText(R.string.forks)
binding.devsRecyclerView.adapter = DevelopersAdapter(Forks().getForks())
binding.devsRecyclerView.adapter = DevelopersAdapter(
arrayOf(
Developer(
"Awery",
"https://avatars.githubusercontent.com/u/92123190?v=4",
"MrBoomDeveloper",
"https://github.com/MrBoomDeveloper/Awery"
),
)
)
binding.devsRecyclerView.layoutManager = LinearLayoutManager(requireContext())
}