Skip to content

Commit

Permalink
feat: replying to activities
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed May 12, 2024
1 parent 6e3a3bb commit d355cc5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@ class AnilistMutations {
return errors?.toString()
?: (currContext()?.getString(ani.dantotsu.R.string.success) ?: "Success")
}

suspend fun postReply(activityId: Int, text: String): String {
val encodedText = Gson().toJson(text)
val query = "mutation{SaveActivityReply(activityId:$activityId,text:$encodedText){id}}"
val result = executeQuery<JsonObject>(query)
val errors = result?.get("errors")
return errors?.toString()
?: (currContext()?.getString(ani.dantotsu.R.string.success) ?: "Success")
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/ani/dantotsu/profile/activity/ActivityItem.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ani.dantotsu.profile.activity

import android.content.Intent
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
Expand All @@ -17,6 +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 com.xwray.groupie.GroupieAdapter
import com.xwray.groupie.viewbinding.BindableItem
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -67,6 +69,21 @@ class ActivityItem(
repliesAdapter.addAll(replyItems)
binding.activityReplies.visibility = View.VISIBLE
binding.commentTotalReplies.setText(R.string.hide_replies)
if (activity.isLocked != true) {
binding.commentReply.setOnClickListener {
val context = binding.root.context
ContextCompat.startActivity(
context,
Intent(context, MarkdownCreatorActivity::class.java)
.putExtra("type", "replyActivity")
.putExtra("parentId", activity.id),
null
)
}
} else {
binding.commentReply.visibility = View.GONE
binding.dot.visibility = View.GONE
}
}

else -> {
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/ani/dantotsu/util/MarkdownCreatorActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import io.noties.markwon.editor.MarkwonEditor
import io.noties.markwon.editor.MarkwonEditorTextWatcher
import kotlinx.coroutines.DelicateCoroutinesApi
import tachiyomi.core.util.lang.launchIO
import java.util.Locale

class MarkdownCreatorActivity : AppCompatActivity() {
private lateinit var binding: ActivityMarkdownCreatorBinding
private lateinit var type: String
private var text: String = ""
private var parentId: Int = 0
@OptIn(DelicateCoroutinesApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -40,11 +40,22 @@ class MarkdownCreatorActivity : AppCompatActivity() {
if (intent.hasExtra("type")) {
type = intent.getStringExtra("type")!!
} else {
toast("Error: No type")
finish()
return
}
binding.markdownCreatorTitle.text = when (type) {
"activity" -> getString(R.string.create_new_activity)
"review" -> getString(R.string.create_new_review)
"replyActivity" -> {
parentId = intent.getIntExtra("parentId", -1)
if (parentId == -1) {
toast("Error: No parent ID")
finish()
return
}
getString(R.string.create_new_reply)
}
else -> ""
}
binding.editText.setText(text)
Expand Down Expand Up @@ -73,6 +84,7 @@ class MarkdownCreatorActivity : AppCompatActivity() {
val success = when (type) {
"activity" -> Anilist.mutation.postActivity(text)
//"review" -> Anilist.mutation.postReview(text)
"replyActivity" -> Anilist.mutation.postReply(parentId, text)
else -> "Error: Unknown type"
}
toast(success)
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/item_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,28 @@
android:text="View replies"
android:textSize="12sp"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/dot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:alpha="0.8"
android:fontFamily="@font/poppins_semi_bold"
android:text=""
android:textSize="12sp"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/commentReply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:alpha="0.8"
android:fontFamily="@font/poppins_semi_bold"
android:text="@string/reply"
android:textSize="12sp"
tools:ignore="HardcodedText" />
</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,9 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
<string name="vote_out_of_total">(%1$s out of %2$s liked this review)</string>
<string name="create_new_activity">Create New Activity</string>
<string name="create_new_review">Create New Review</string>
<string name="create_new_reply">Create New Reply</string>
<string name="create">Create</string>
<string name="preview">Preview</string>
<string name="cannot_be_empty">Text cannot be empty</string>
<string name="reply">Reply</string>
</resources>

0 comments on commit d355cc5

Please sign in to comment.