From ce7ae28e1e49c2a6a19813fe78aa25d92a0508a0 Mon Sep 17 00:00:00 2001
From: ibo <41344259+sneazy-ibo@users.noreply.github.com>
Date: Sat, 1 Jun 2024 15:27:11 +0200
Subject: [PATCH] feat: revamping text activities (#406)
* feat(storyReply): redesigned components
* feat(storyReply): fixed all markdowns
---
app/src/main/AndroidManifest.xml | 3 +-
.../dantotsu/util/MarkdownCreatorActivity.kt | 165 ++++++++-
.../res/drawable/format_align_center_24.xml | 10 +
app/src/main/res/drawable/format_bold_24.xml | 10 +
app/src/main/res/drawable/format_code_24.xml | 10 +
app/src/main/res/drawable/format_image_24.xml | 10 +
.../main/res/drawable/format_italic_24.xml | 10 +
app/src/main/res/drawable/format_link_24.xml | 10 +
.../res/drawable/format_list_bulleted_24.xml | 11 +
.../res/drawable/format_list_numbered_24.xml | 10 +
app/src/main/res/drawable/format_quote_24.xml | 10 +
.../main/res/drawable/format_spoiler_24.xml | 10 +
.../res/drawable/format_strikethrough_24.xml | 10 +
app/src/main/res/drawable/format_title_24.xml | 10 +
app/src/main/res/drawable/format_video_24.xml | 11 +
.../main/res/drawable/format_youtube_24.xml | 10 +
.../res/layout/activity_markdown_creator.xml | 326 +++++++++++++-----
app/src/main/res/layout/fragment_status.xml | 12 +
app/src/main/res/values/strings.xml | 2 +
19 files changed, 546 insertions(+), 104 deletions(-)
create mode 100644 app/src/main/res/drawable/format_align_center_24.xml
create mode 100644 app/src/main/res/drawable/format_bold_24.xml
create mode 100644 app/src/main/res/drawable/format_code_24.xml
create mode 100644 app/src/main/res/drawable/format_image_24.xml
create mode 100644 app/src/main/res/drawable/format_italic_24.xml
create mode 100644 app/src/main/res/drawable/format_link_24.xml
create mode 100644 app/src/main/res/drawable/format_list_bulleted_24.xml
create mode 100644 app/src/main/res/drawable/format_list_numbered_24.xml
create mode 100644 app/src/main/res/drawable/format_quote_24.xml
create mode 100644 app/src/main/res/drawable/format_spoiler_24.xml
create mode 100644 app/src/main/res/drawable/format_strikethrough_24.xml
create mode 100644 app/src/main/res/drawable/format_title_24.xml
create mode 100644 app/src/main/res/drawable/format_video_24.xml
create mode 100644 app/src/main/res/drawable/format_youtube_24.xml
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c42fee0d981..1104ba865ff 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -201,7 +201,8 @@
android:name=".others.imagesearch.ImageSearchActivity"
android:parentActivityName=".MainActivity" />
+ android:name=".util.MarkdownCreatorActivity"
+ android:windowSoftInputMode="adjustResize" />
", 2, R.id.formatQuote),
+ CODE("``", 1, R.id.formatCode)
+ }
@OptIn(DelicateCoroutinesApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
@@ -36,11 +64,15 @@ class MarkdownCreatorActivity : AppCompatActivity() {
binding.markdownCreatorToolbar.updateLayoutParams {
topMargin = statusBarHeight
}
- binding.buttonContainer.updateLayoutParams {
+ binding.markdownOptionsContainer.updateLayoutParams {
bottomMargin += navBarHeight
}
setContentView(binding.root)
+ val params = binding.createButton.layoutParams as ViewGroup.MarginLayoutParams
+ params.marginEnd = 16 * resources.displayMetrics.density.toInt()
+ binding.createButton.layoutParams = params
+
if (intent.hasExtra("type")) {
type = intent.getStringExtra("type")!!
} else {
@@ -69,17 +101,12 @@ class MarkdownCreatorActivity : AppCompatActivity() {
text = ping ?: ""
binding.editText.setText(text)
binding.editText.addTextChangedListener {
- if (!binding.markdownCreatorPreviewCheckbox.isChecked) {
+ if (!isPreviewMode) {
text = it.toString()
}
}
previewMarkdown(false)
- binding.markdownCreatorPreviewCheckbox.setOnClickListener {
- previewMarkdown(binding.markdownCreatorPreviewCheckbox.isChecked)
- }
- binding.cancelButton.setOnClickListener {
- onBackPressedDispatcher.onBackPressed()
- }
+
binding.markdownCreatorBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
@@ -89,10 +116,10 @@ class MarkdownCreatorActivity : AppCompatActivity() {
toast(getString(R.string.cannot_be_empty))
return@setOnClickListener
}
- AlertDialogBuilder(this).apply {
+ AlertDialog.Builder(this, R.style.MyPopup).apply {
setTitle(R.string.warning)
setMessage(R.string.post_to_anilist_warning)
- setPosButton(R.string.ok) {
+ setPositiveButton(R.string.ok) { _, _ ->
launchIO {
val editId = intent.getIntExtra("edit", -1)
val isEdit = editId != -1
@@ -119,14 +146,126 @@ class MarkdownCreatorActivity : AppCompatActivity() {
finish()
}
}
- setNeutralButton(R.string.open_rules) {
+ setNeutralButton(R.string.open_rules) { _, _ ->
openLinkInBrowser("https://anilist.co/forum/thread/14")
}
- setNegButton(R.string.cancel)
+ setNegativeButton(R.string.cancel, null)
}.show()
}
+ binding.createButton.setOnLongClickListener {
+ isPreviewMode = !isPreviewMode
+ previewMarkdown(isPreviewMode)
+ if (isPreviewMode) {
+ toast("Preview enabled")
+ } else {
+ toast("Preview disabled")
+ }
+ true
+ }
binding.editText.requestFocus()
+ setupMarkdownButtons()
+ }
+
+ private fun setupMarkdownButtons() {
+ MarkdownFormat.entries.forEach { format ->
+ findViewById(format.imageViewId)?.setOnClickListener {
+ applyMarkdownFormat(format)
+ }
+ }
+ }
+
+ private fun applyMarkdownFormat(format: MarkdownFormat) {
+ val start = binding.editText.selectionStart
+ val end = binding.editText.selectionEnd
+
+ if (start != end) {
+ val selectedText = binding.editText.text?.substring(start, end) ?: ""
+ val lines = selectedText.split("\n")
+
+ val newText = when (format) {
+ 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)
+ } else {
+ format.syntax.substring(0, format.selectionOffset) +
+ selectedText +
+ format.syntax.substring(format.selectionOffset)
+ }
+ }
+ }
+
+ binding.editText.text?.replace(start, end, newText)
+ binding.editText.setSelection(start + newText.length)
+ } else {
+ if (format.syntax.contains("%s")) {
+ showInputDialog(format, start)
+ } else {
+ val newText = format.syntax
+ binding.editText.text?.insert(start, newText)
+ binding.editText.setSelection(start + format.selectionOffset)
+ }
+ }
+ }
+
+
+ private fun showInputDialog(format: MarkdownFormat, position: Int) {
+ val inputLayout = TextInputLayout(this).apply {
+ layoutParams = ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT
+ )
+ boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_OUTLINE
+ hint = "Paste your link here"
+ isHintEnabled = true
+ }
+
+ val inputEditText = TextInputEditText(this).apply {
+ layoutParams = LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT
+ )
+ }
+
+ inputLayout.addView(inputEditText)
+
+ val container = FrameLayout(this).apply {
+ addView(inputLayout)
+ layoutParams = ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT
+ )
+ setPadding(64, 64, 64, 0)
+ }
+
+ val dialog = AlertDialog.Builder(this, R.style.MyPopup).apply {
+ setView(container)
+ setPositiveButton(getString(R.string.ok)) { dialog, _ ->
+ 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()
+
+ 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()
}
private fun previewMarkdown(preview: Boolean) {
diff --git a/app/src/main/res/drawable/format_align_center_24.xml b/app/src/main/res/drawable/format_align_center_24.xml
new file mode 100644
index 00000000000..c174a0ea794
--- /dev/null
+++ b/app/src/main/res/drawable/format_align_center_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_bold_24.xml b/app/src/main/res/drawable/format_bold_24.xml
new file mode 100644
index 00000000000..c640aaaa408
--- /dev/null
+++ b/app/src/main/res/drawable/format_bold_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_code_24.xml b/app/src/main/res/drawable/format_code_24.xml
new file mode 100644
index 00000000000..61eaae2dc43
--- /dev/null
+++ b/app/src/main/res/drawable/format_code_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_image_24.xml b/app/src/main/res/drawable/format_image_24.xml
new file mode 100644
index 00000000000..f6cc30a4eb2
--- /dev/null
+++ b/app/src/main/res/drawable/format_image_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_italic_24.xml b/app/src/main/res/drawable/format_italic_24.xml
new file mode 100644
index 00000000000..7f9ea8f94b2
--- /dev/null
+++ b/app/src/main/res/drawable/format_italic_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_link_24.xml b/app/src/main/res/drawable/format_link_24.xml
new file mode 100644
index 00000000000..c8c0c1b61ec
--- /dev/null
+++ b/app/src/main/res/drawable/format_link_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_list_bulleted_24.xml b/app/src/main/res/drawable/format_list_bulleted_24.xml
new file mode 100644
index 00000000000..d2558d8514b
--- /dev/null
+++ b/app/src/main/res/drawable/format_list_bulleted_24.xml
@@ -0,0 +1,11 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_list_numbered_24.xml b/app/src/main/res/drawable/format_list_numbered_24.xml
new file mode 100644
index 00000000000..bc344d32248
--- /dev/null
+++ b/app/src/main/res/drawable/format_list_numbered_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_quote_24.xml b/app/src/main/res/drawable/format_quote_24.xml
new file mode 100644
index 00000000000..74ecc150817
--- /dev/null
+++ b/app/src/main/res/drawable/format_quote_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_spoiler_24.xml b/app/src/main/res/drawable/format_spoiler_24.xml
new file mode 100644
index 00000000000..647711b4d39
--- /dev/null
+++ b/app/src/main/res/drawable/format_spoiler_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_strikethrough_24.xml b/app/src/main/res/drawable/format_strikethrough_24.xml
new file mode 100644
index 00000000000..a7556219ac5
--- /dev/null
+++ b/app/src/main/res/drawable/format_strikethrough_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_title_24.xml b/app/src/main/res/drawable/format_title_24.xml
new file mode 100644
index 00000000000..4b15683f54b
--- /dev/null
+++ b/app/src/main/res/drawable/format_title_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_video_24.xml b/app/src/main/res/drawable/format_video_24.xml
new file mode 100644
index 00000000000..9813485dae6
--- /dev/null
+++ b/app/src/main/res/drawable/format_video_24.xml
@@ -0,0 +1,11 @@
+
+
+
diff --git a/app/src/main/res/drawable/format_youtube_24.xml b/app/src/main/res/drawable/format_youtube_24.xml
new file mode 100644
index 00000000000..909e5a21b24
--- /dev/null
+++ b/app/src/main/res/drawable/format_youtube_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_markdown_creator.xml b/app/src/main/res/layout/activity_markdown_creator.xml
index 87af585d2dc..504557a0dbc 100644
--- a/app/src/main/res/layout/activity_markdown_creator.xml
+++ b/app/src/main/res/layout/activity_markdown_creator.xml
@@ -1,107 +1,253 @@
-
+ android:fitsSystemWindows="false">
-
-
-
-
-
+
+
-
-
-
-
-
+ android:orientation="horizontal"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_status.xml b/app/src/main/res/layout/fragment_status.xml
index c5fdd65fd7b..4660a18294b 100644
--- a/app/src/main/res/layout/fragment_status.xml
+++ b/app/src/main/res/layout/fragment_status.xml
@@ -65,6 +65,18 @@
+
Apply
Cancel
Edit
+ Publish
+ Write a response…
This Season
Next Season
Previous Season