From 6f685a43885f4a344b694e4f970397cd8b97d3fb Mon Sep 17 00:00:00 2001 From: aayush262 Date: Sun, 2 Jun 2024 02:11:56 +0530 Subject: [PATCH 01/20] feat: private message --- app/src/main/AndroidManifest.xml | 2 +- app/src/main/java/ani/dantotsu/Functions.kt | 6 +- .../connections/anilist/AnilistMutations.kt | 26 +- .../home/status/RepliesBottomDialog.kt | 5 +- .../dantotsu/home/status/UserStatusAdapter.kt | 5 +- .../java/ani/dantotsu/media/ReviewActivity.kt | 5 +- .../ani/dantotsu/profile/ProfileActivity.kt | 1 - .../profile/activity/ActivityFragment.kt | 7 +- .../dantotsu/profile/activity/ActivityItem.kt | 7 +- .../profile/activity/ActivityReplyItem.kt | 6 +- ...Activity.kt => ActivityMarkdownCreator.kt} | 74 +++--- .../res/layout/activity_markdown_creator.xml | 248 ++++++++++-------- app/src/main/res/layout/fragment_status.xml | 13 - app/src/main/res/values/strings.xml | 1 + 14 files changed, 208 insertions(+), 198 deletions(-) rename app/src/main/java/ani/dantotsu/util/{MarkdownCreatorActivity.kt => ActivityMarkdownCreator.kt} (85%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1104ba865ff..4c267042acc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -201,7 +201,7 @@ android:name=".others.imagesearch.ImageSearchActivity" android:parentActivityName=".MainActivity" /> (query) val errors = result?.get("errors") return errors?.toString() ?: (currContext()?.getString(ani.dantotsu.R.string.success) ?: "Success") } - suspend fun postMessage(userId: Int, text: String, edit: Int? = null,isPrivate: Boolean = false): String { - val encodedText = text.replace("","").stringSanitizer() - val query = "mutation{SaveMessageActivity(${if (edit != null) "id:$edit," else ""} recipientId:$userId,message:$encodedText,private:$isPrivate){id}}" + + suspend fun postMessage( + userId: Int, + text: String, + edit: Int? = null, + isPrivate: Boolean = false + ): String { + val encodedText = text.replace("", "").stringSanitizer() + val query = + "mutation{SaveMessageActivity(${if (edit != null) "id:$edit," else ""} recipientId:$userId,message:$encodedText,private:$isPrivate){id}}" val result = executeQuery(query) val errors = result?.get("errors") return errors?.toString() ?: (currContext()?.getString(ani.dantotsu.R.string.success) ?: "Success") } - suspend fun postReply(activityId: Int, text: String, edit: Int? = null ): String { + + suspend fun postReply(activityId: Int, text: String, edit: Int? = null): String { val encodedText = text.stringSanitizer() - val query = "mutation{SaveActivityReply(${if (edit != null) "id:$edit," else ""} activityId:$activityId,text:$encodedText){id}}" + val query = + "mutation{SaveActivityReply(${if (edit != null) "id:$edit," else ""} activityId:$activityId,text:$encodedText){id}}" val result = executeQuery(query) val errors = result?.get("errors") return errors?.toString() ?: (currContext()?.getString(ani.dantotsu.R.string.success) ?: "Success") } + suspend fun postReview(summary: String, body: String, mediaId: Int, score: Int): String { val encodedSummary = summary.stringSanitizer() val encodedBody = body.stringSanitizer() @@ -143,7 +154,6 @@ class AnilistMutations { } - private fun String.stringSanitizer(): String { val sb = StringBuilder() var i = 0 diff --git a/app/src/main/java/ani/dantotsu/home/status/RepliesBottomDialog.kt b/app/src/main/java/ani/dantotsu/home/status/RepliesBottomDialog.kt index 218bf7fe584..44a11baf6ed 100644 --- a/app/src/main/java/ani/dantotsu/home/status/RepliesBottomDialog.kt +++ b/app/src/main/java/ani/dantotsu/home/status/RepliesBottomDialog.kt @@ -16,10 +16,9 @@ import ani.dantotsu.databinding.BottomSheetRecyclerBinding import ani.dantotsu.profile.ProfileActivity import ani.dantotsu.profile.activity.ActivityReplyItem import ani.dantotsu.snackString -import ani.dantotsu.util.MarkdownCreatorActivity +import ani.dantotsu.util.ActivityMarkdownCreator import com.xwray.groupie.GroupieAdapter import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -50,7 +49,7 @@ class RepliesBottomDialog : BottomSheetDialogFragment() { binding.replyButton.setOnClickListener { ContextCompat.startActivity( context, - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "replyActivity") .putExtra("parentId", activityId), null diff --git a/app/src/main/java/ani/dantotsu/home/status/UserStatusAdapter.kt b/app/src/main/java/ani/dantotsu/home/status/UserStatusAdapter.kt index 8aa021049e8..c8db4c99c1e 100644 --- a/app/src/main/java/ani/dantotsu/home/status/UserStatusAdapter.kt +++ b/app/src/main/java/ani/dantotsu/home/status/UserStatusAdapter.kt @@ -1,6 +1,5 @@ package ani.dantotsu.home.status -import android.content.Context import android.content.Intent import android.view.LayoutInflater import android.view.ViewGroup @@ -16,7 +15,7 @@ import ani.dantotsu.profile.User import ani.dantotsu.setAnimation import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.snackString -import ani.dantotsu.util.MarkdownCreatorActivity +import ani.dantotsu.util.ActivityMarkdownCreator class UserStatusAdapter(private val user: ArrayList) : RecyclerView.Adapter() { @@ -43,7 +42,7 @@ class UserStatusAdapter(private val user: ArrayList) : if (user[bindingAdapterPosition].id == Anilist.userid) { ContextCompat.startActivity( itemView.context, - Intent(itemView.context, MarkdownCreatorActivity::class.java) + Intent(itemView.context, ActivityMarkdownCreator::class.java) .putExtra("type", "activity"), null ) diff --git a/app/src/main/java/ani/dantotsu/media/ReviewActivity.kt b/app/src/main/java/ani/dantotsu/media/ReviewActivity.kt index 6b08734cd6f..0f6d0e4ffc2 100644 --- a/app/src/main/java/ani/dantotsu/media/ReviewActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/ReviewActivity.kt @@ -3,7 +3,6 @@ package ani.dantotsu.media import android.annotation.SuppressLint import android.content.Intent import android.os.Bundle -import android.text.SpannableString import android.view.MotionEvent import android.view.View import android.view.ViewGroup @@ -21,7 +20,7 @@ import ani.dantotsu.initActivity import ani.dantotsu.navBarHeight import ani.dantotsu.statusBarHeight import ani.dantotsu.themes.ThemeManager -import ani.dantotsu.util.MarkdownCreatorActivity +import ani.dantotsu.util.ActivityMarkdownCreator import com.xwray.groupie.GroupieAdapter import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -59,7 +58,7 @@ class ReviewActivity : AppCompatActivity() { binding.followFilterButton.setOnClickListener { ContextCompat.startActivity( this, - Intent(this, MarkdownCreatorActivity::class.java) + Intent(this, ActivityMarkdownCreator::class.java) .putExtra("type", "review"), null ) diff --git a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt index 29ac59d44b3..856dc0b8e3c 100644 --- a/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt +++ b/app/src/main/java/ani/dantotsu/profile/ProfileActivity.kt @@ -38,7 +38,6 @@ import ani.dantotsu.snackString import ani.dantotsu.statusBarHeight import ani.dantotsu.themes.ThemeManager import ani.dantotsu.toast -import ani.dantotsu.util.MarkdownCreatorActivity import com.google.android.material.appbar.AppBarLayout import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/ani/dantotsu/profile/activity/ActivityFragment.kt b/app/src/main/java/ani/dantotsu/profile/activity/ActivityFragment.kt index ce647f15a6e..fa7826b780e 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/ActivityFragment.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/ActivityFragment.kt @@ -19,8 +19,7 @@ import ani.dantotsu.databinding.FragmentFeedBinding import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.navBarHeight import ani.dantotsu.profile.ProfileActivity -import ani.dantotsu.setBaseline -import ani.dantotsu.util.MarkdownCreatorActivity +import ani.dantotsu.util.ActivityMarkdownCreator import com.xwray.groupie.GroupieAdapter import eu.kanade.tachiyomi.util.system.getSerializableCompat import kotlinx.coroutines.launch @@ -53,14 +52,14 @@ class ActivityFragment : Fragment() { if(userId == Anilist.userid) { ContextCompat.startActivity( requireContext(), - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "activity"), null ) } else{ ContextCompat.startActivity( requireContext(), - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "message") .putExtra("userId", userId), diff --git a/app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt b/app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt index 9dd423dab0d..22cf432b61a 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt @@ -5,7 +5,6 @@ import android.view.View import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.FragmentActivity -import androidx.recyclerview.widget.LinearLayoutManager import ani.dantotsu.R import ani.dantotsu.blurImage import ani.dantotsu.buildMarkwon @@ -19,7 +18,7 @@ import ani.dantotsu.profile.UsersDialogFragment import ani.dantotsu.setAnimation import ani.dantotsu.snackString import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML -import ani.dantotsu.util.MarkdownCreatorActivity +import ani.dantotsu.util.ActivityMarkdownCreator import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.viewbinding.BindableItem import kotlinx.coroutines.CoroutineScope @@ -152,7 +151,7 @@ class ActivityItem( binding.activityEdit.setOnClickListener { ContextCompat.startActivity( context, - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "activity") .putExtra("other", activity.text) .putExtra("edit", activity.id), @@ -183,7 +182,7 @@ class ActivityItem( binding.activityEdit.setOnClickListener { ContextCompat.startActivity( context, - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "message") .putExtra("other", activity.message) .putExtra("edit", activity.id) diff --git a/app/src/main/java/ani/dantotsu/profile/activity/ActivityReplyItem.kt b/app/src/main/java/ani/dantotsu/profile/activity/ActivityReplyItem.kt index 1f9039d1ca0..073ada94cd2 100644 --- a/app/src/main/java/ani/dantotsu/profile/activity/ActivityReplyItem.kt +++ b/app/src/main/java/ani/dantotsu/profile/activity/ActivityReplyItem.kt @@ -15,7 +15,7 @@ import ani.dantotsu.profile.User import ani.dantotsu.profile.UsersDialogFragment import ani.dantotsu.snackString import ani.dantotsu.util.AniMarkdown.Companion.getBasicAniHTML -import ani.dantotsu.util.MarkdownCreatorActivity +import ani.dantotsu.util.ActivityMarkdownCreator import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.viewbinding.BindableItem import kotlinx.coroutines.CoroutineScope @@ -81,7 +81,7 @@ class ActivityReplyItem( binding.activityReply.setOnClickListener { ContextCompat.startActivity( context, - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "replyActivity") .putExtra("parentId", parentId) .putExtra("other", "@${reply.user.name} "), @@ -92,7 +92,7 @@ class ActivityReplyItem( binding.activityEdit.setOnClickListener { ContextCompat.startActivity( context, - Intent(context, MarkdownCreatorActivity::class.java) + Intent(context, ActivityMarkdownCreator::class.java) .putExtra("type", "replyActivity") .putExtra("parentId", parentId) .putExtra("other", reply.text) diff --git a/app/src/main/java/ani/dantotsu/util/MarkdownCreatorActivity.kt b/app/src/main/java/ani/dantotsu/util/ActivityMarkdownCreator.kt similarity index 85% rename from app/src/main/java/ani/dantotsu/util/MarkdownCreatorActivity.kt rename to app/src/main/java/ani/dantotsu/util/ActivityMarkdownCreator.kt index a66dba939bb..1a3e9f18896 100644 --- a/app/src/main/java/ani/dantotsu/util/MarkdownCreatorActivity.kt +++ b/app/src/main/java/ani/dantotsu/util/ActivityMarkdownCreator.kt @@ -26,7 +26,7 @@ import io.noties.markwon.editor.MarkwonEditorTextWatcher import kotlinx.coroutines.DelicateCoroutinesApi import tachiyomi.core.util.lang.launchIO -class MarkdownCreatorActivity : AppCompatActivity() { +class ActivityMarkdownCreator : AppCompatActivity() { private lateinit var binding: ActivityMarkdownCreatorBinding private lateinit var type: String private var text: String = "" @@ -80,24 +80,28 @@ class MarkdownCreatorActivity : AppCompatActivity() { finish() return } - binding.markdownCreatorTitle.text = when (type) { - "activity" -> getString(R.string.create_new_activity) - "review" -> getString(R.string.create_new_review) - "message" -> getString(R.string.create_new_message) - "replyActivity" -> { - parentId = intent.getIntExtra("parentId", -1) - if (parentId == -1) { - toast("Error: No parent ID") - finish() - return - } - getString(R.string.create_new_reply) + val editId = intent.getIntExtra("edit", -1) + val userId = intent.getIntExtra("userId", -1) + parentId = intent.getIntExtra("parentId", -1) + when (type) { + "replyActivity" -> if (parentId == -1) { + toast("Error: No parent ID") + finish() + return } - else -> "" + "message" -> { + if (editId == -1) { + binding.privateCheckbox.visibility = ViewGroup.VISIBLE + } + } } + var private = false + binding.privateCheckbox.setOnCheckedChangeListener { _, isChecked -> + private = isChecked + } + ping = intent.getStringExtra("other") - val userId = intent.getIntExtra("userId", -1) text = ping ?: "" binding.editText.setText(text) binding.editText.addTextChangedListener { @@ -121,7 +125,7 @@ class MarkdownCreatorActivity : AppCompatActivity() { setMessage(R.string.post_to_anilist_warning) setPositiveButton(R.string.ok) { _, _ -> launchIO { - val editId = intent.getIntExtra("edit", -1) + val isEdit = editId != -1 val success = when (type) { "activity" -> if (isEdit) { @@ -135,11 +139,13 @@ class MarkdownCreatorActivity : AppCompatActivity() { } else { Anilist.mutation.postReply(parentId, text) } - "message" -> if (isEdit) { //TODO private - Anilist.mutation.postMessage(userId , text, editId) + + "message" -> if (isEdit) { + Anilist.mutation.postMessage(userId, text, editId) } else { - Anilist.mutation.postMessage(userId , text) + Anilist.mutation.postMessage(userId, text, isPrivate = private) } + else -> "Error: Unknown type" } toast(success) @@ -153,7 +159,7 @@ class MarkdownCreatorActivity : AppCompatActivity() { }.show() } - binding.createButton.setOnLongClickListener { + binding.previewCheckbox.setOnClickListener { isPreviewMode = !isPreviewMode previewMarkdown(isPreviewMode) if (isPreviewMode) { @@ -161,7 +167,6 @@ class MarkdownCreatorActivity : AppCompatActivity() { } else { toast("Preview disabled") } - true } binding.editText.requestFocus() setupMarkdownButtons() @@ -187,9 +192,11 @@ class MarkdownCreatorActivity : AppCompatActivity() { MarkdownFormat.UNORDERED_LIST -> { lines.joinToString("\n") { "- $it" } } + MarkdownFormat.ORDERED_LIST -> { lines.mapIndexed { index, line -> "${index + 1}. $line" }.joinToString("\n") } + else -> { if (format.syntax.contains("%s")) { String.format(format.syntax, selectedText) @@ -222,7 +229,6 @@ class MarkdownCreatorActivity : AppCompatActivity() { ViewGroup.LayoutParams.WRAP_CONTENT ) boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_OUTLINE - hint = "Paste your link here" isHintEnabled = true } @@ -241,30 +247,20 @@ class MarkdownCreatorActivity : AppCompatActivity() { ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) - setPadding(64, 64, 64, 0) + setPadding(0, 0, 0, 0) } - - val dialog = AlertDialog.Builder(this, R.style.MyPopup).apply { - setView(container) - setPositiveButton(getString(R.string.ok)) { dialog, _ -> + customAlertDialog().apply { + setTitle("Paste your link here") + setCustomView(container) + setPosButton(getString(R.string.ok)) { val input = inputEditText.text.toString() val formattedText = String.format(format.syntax, input) binding.editText.text?.insert(position, formattedText) binding.editText.setSelection(position + formattedText.length) - dialog.dismiss() - } - setNegativeButton(getString(R.string.cancel)) { dialog, _ -> - dialog.dismiss() } - }.create() + setNegButton(getString(R.string.cancel)) + }.show() - val widthInDp = 245 - val layoutParams = ViewGroup.LayoutParams( - (widthInDp * resources.displayMetrics.density).toInt(), - ViewGroup.LayoutParams.WRAP_CONTENT - ) - dialog.window?.setLayout(layoutParams.width, layoutParams.height) - dialog.show() inputEditText.requestFocus() } diff --git a/app/src/main/res/layout/activity_markdown_creator.xml b/app/src/main/res/layout/activity_markdown_creator.xml index 504557a0dbc..fb66d6f0362 100644 --- a/app/src/main/res/layout/activity_markdown_creator.xml +++ b/app/src/main/res/layout/activity_markdown_creator.xml @@ -1,92 +1,99 @@ - + android:fitsSystemWindows="false" + android:orientation="vertical" + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + android:layout_height="48dp" + android:orientation="horizontal" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - + - + - + -