fix: random things

This commit is contained in:
aayush262 2024-06-11 20:56:59 +05:30
parent 3ae59b8d22
commit 903423b842
6 changed files with 56 additions and 56 deletions

View file

@ -48,8 +48,10 @@ class ActivityFragment : Fragment() {
userId = it.getInt("userId")
activityId = it.getInt("activityId")
}
binding.titleBar.visibility = if (type == ActivityType.OTHER_USER) View.VISIBLE else View.GONE
binding.titleText.text = if (userId == Anilist.userid) getString(R.string.create_new_activity) else getString(R.string.write_a_message)
binding.titleBar.visibility =
if (type == ActivityType.OTHER_USER) View.VISIBLE else View.GONE
binding.titleText.text =
if (userId == Anilist.userid) getString(R.string.create_new_activity) else getString(R.string.write_a_message)
binding.titleImage.setOnClickListener { handleTitleImageClick() }
binding.listRecyclerView.adapter = adapter
binding.listRecyclerView.layoutManager = LinearLayoutManager(context)
@ -88,6 +90,7 @@ class ActivityFragment : Fragment() {
}
})
}
private fun handleTitleImageClick() {
val intent = Intent(context, ActivityMarkdownCreator::class.java).apply {
putExtra("type", if (userId == Anilist.userid) "activity" else "message")
@ -103,7 +106,7 @@ class ActivityFragment : Fragment() {
ActivityType.OTHER_USER -> getActivities(userId = userId)
ActivityType.ONE -> getActivities(activityId = activityId)
}
adapter.addAll(list.map { ActivityItem(it, ::onActivityClick, adapter ,requireActivity()) })
adapter.addAll(list.map { ActivityItem(it, adapter, ::onActivityClick) })
}
private suspend fun getActivities(
@ -133,7 +136,11 @@ class ActivityFragment : Fragment() {
private fun onActivityClick(id: Int, type: String) {
val intent = when (type) {
"USER" -> Intent(requireContext(), ProfileActivity::class.java).putExtra("userId", id)
"MEDIA" -> Intent(requireContext(), MediaDetailsActivity::class.java).putExtra("mediaId", id)
"MEDIA" -> Intent(
requireContext(),
MediaDetailsActivity::class.java
).putExtra("mediaId", id)
else -> return
}
ContextCompat.startActivity(requireContext(), intent, null)
@ -149,7 +156,11 @@ class ActivityFragment : Fragment() {
companion object {
enum class ActivityType { GLOBAL, USER, OTHER_USER, ONE }
fun newInstance(type: ActivityType, userId: Int? = null, activityId: Int? = null): ActivityFragment {
fun newInstance(
type: ActivityType,
userId: Int? = null,
activityId: Int? = null
): ActivityFragment {
return ActivityFragment().apply {
arguments = Bundle().apply {
putSerializable("type", type)

View file

@ -29,9 +29,8 @@ import kotlinx.coroutines.withContext
class ActivityItem(
private val activity: Activity,
val clickCallback: (Int, type: String) -> Unit,
private val parentAdapter: GroupieAdapter,
private val fragActivity: FragmentActivity
val clickCallback: (Int, type: String) -> Unit,
) : BindableItem<ItemActivityBinding>() {
private lateinit var binding: ItemActivityBinding
@ -54,14 +53,14 @@ class ActivityItem(
}
binding.activityRepliesContainer.setOnClickListener {
RepliesBottomDialog.newInstance(activity.id)
.show(fragActivity.supportFragmentManager, "replies")
.show((context as FragmentActivity).supportFragmentManager, "replies")
}
binding.replyCount.text = activity.replyCount.toString()
binding.activityReplies.setColorFilter(ContextCompat.getColor(binding.root.context, R.color.bg_opp))
binding.activityLikeContainer.setOnLongClickListener {
UsersDialogFragment().apply {
userList(userList)
show(fragActivity.supportFragmentManager, "dialog")
show((context as FragmentActivity).supportFragmentManager, "dialog")
}
true
}

View file

@ -14,6 +14,7 @@ import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.statusBarHeight
import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.util.customAlertDialog
class UserInterfaceSettingsActivity : AppCompatActivity() {
lateinit var binding: ActivityUserInterfaceSettingsBinding
@ -38,20 +39,21 @@ class UserInterfaceSettingsActivity : AppCompatActivity() {
binding.uiSettingsHomeLayout.setOnClickListener {
val set = PrefManager.getVal<List<Boolean>>(PrefName.HomeLayout).toMutableList()
val views = resources.getStringArray(R.array.home_layouts)
val dialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.home_layout_show)).apply {
setMultiChoiceItems(
views,
PrefManager.getVal<List<Boolean>>(PrefName.HomeLayout).toBooleanArray()
) { _, i, value ->
set[i] = value
customAlertDialog()
.setTitle(getString(R.string.home_layout_show))
.multiChoiceItems(
items = views,
checkedItems = PrefManager.getVal<List<Boolean>>(PrefName.HomeLayout).toBooleanArray()
) { selectedItems ->
for (i in selectedItems.indices) {
set[i] = selectedItems[i]
}
setPositiveButton("Done") { _, _ ->
}
.setPosButton("Done") {
PrefManager.setVal(PrefName.HomeLayout, set)
restartApp()
}
}.show()
dialog.window?.setDimAmount(0.8f)
.show()
}
binding.uiSettingsSmallView.isChecked = PrefManager.getVal(PrefName.SmallView)

View file

@ -1,5 +1,6 @@
package ani.dantotsu.util
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.view.View
@ -21,6 +22,8 @@ class AlertDialogBuilder(private val context: Context) {
private var onItemSelected: ((Int) -> Unit)? = null
private var customView: View? = null
private var attach: ((dialog: AlertDialog) -> Unit)? = null
private var onDismiss: (() -> Unit)? = null
fun setTitle(title: String?): AlertDialogBuilder {
this.title = title
return this
@ -52,11 +55,7 @@ class AlertDialogBuilder(private val context: Context) {
return this
}
fun setPosButton(
int: Int,
formatArgs: Int? = null,
onClick: (() -> Unit)? = null
): AlertDialogBuilder {
fun setPosButton(int: Int, formatArgs: Int? = null, onClick: (() -> Unit)? = null): AlertDialogBuilder {
this.posButtonTitle = context.getString(int, formatArgs)
this.onPositiveButtonClick = onClick
return this
@ -68,11 +67,7 @@ class AlertDialogBuilder(private val context: Context) {
return this
}
fun setNegButton(
int: Int,
formatArgs: Int? = null,
onClick: (() -> Unit)? = null
): AlertDialogBuilder {
fun setNegButton(int: Int, formatArgs: Int? = null, onClick: (() -> Unit)? = null): AlertDialogBuilder {
this.negButtonTitle = context.getString(int, formatArgs)
this.onNegativeButtonClick = onClick
return this
@ -84,11 +79,7 @@ class AlertDialogBuilder(private val context: Context) {
return this
}
fun setNeutralButton(
int: Int,
formatArgs: Int? = null,
onClick: (() -> Unit)? = null
): AlertDialogBuilder {
fun setNeutralButton(int: Int, formatArgs: Int? = null, onClick: (() -> Unit)? = null): AlertDialogBuilder {
this.neutralButtonTitle = context.getString(int, formatArgs)
this.onNeutralButtonClick = onClick
return this
@ -99,22 +90,19 @@ class AlertDialogBuilder(private val context: Context) {
return this
}
fun singleChoiceItems(
items: Array<String>,
selectedItemIndex: Int = -1,
onItemSelected: (Int) -> Unit
): AlertDialogBuilder {
fun onDismiss(onDismiss: (() -> Unit)? = null): AlertDialogBuilder {
this.onDismiss = onDismiss
return this
}
fun singleChoiceItems(items: Array<String>, selectedItemIndex: Int = -1, onItemSelected: (Int) -> Unit): AlertDialogBuilder {
this.items = items
this.selectedItemIndex = selectedItemIndex
this.onItemSelected = onItemSelected
return this
}
fun multiChoiceItems(
items: Array<String>,
checkedItems: BooleanArray? = null,
onItemsSelected: (BooleanArray) -> Unit
): AlertDialogBuilder {
fun multiChoiceItems(items: Array<String>, checkedItems: BooleanArray? = null, onItemsSelected: (BooleanArray) -> Unit): AlertDialogBuilder {
this.items = items
this.checkedItems = checkedItems ?: BooleanArray(items.size) { false }
this.onItemsSelected = onItemsSelected
@ -122,6 +110,8 @@ class AlertDialogBuilder(private val context: Context) {
}
fun show() {
if (context is Activity && context.isFinishing) return // Ensure context is valid
val builder = AlertDialog.Builder(context, R.style.MyPopup)
if (title != null) builder.setTitle(title)
if (message != null) builder.setMessage(message)
@ -160,10 +150,12 @@ class AlertDialogBuilder(private val context: Context) {
builder.setCancelable(false)
val dialog = builder.create()
attach?.invoke(dialog)
dialog.setOnDismissListener {
onDismiss?.invoke()
}
dialog.window?.setDimAmount(0.8f)
dialog.show()
}
}
fun Context.customAlertDialog(): AlertDialogBuilder {

View file

@ -129,7 +129,6 @@
android:textSize="12sp"
tools:visibility="visible"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/activityDelete"
android:layout_width="wrap_content"

View file

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define your preferences here. For example: -->
<CheckBoxPreference
android:defaultValue="true"
android:key="some_key"
android:title="Some Title" />
z
</PreferenceScreen>