-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0fabd3
commit fa659c7
Showing
10 changed files
with
266 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/ani/dantotsu/util/MarkdownCreatorActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package ani.dantotsu.util | ||
|
||
import android.os.Bundle | ||
import android.view.ViewGroup | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.updateLayoutParams | ||
import androidx.core.widget.addTextChangedListener | ||
import ani.dantotsu.R | ||
import ani.dantotsu.buildMarkwon | ||
import ani.dantotsu.connections.anilist.Anilist | ||
import ani.dantotsu.databinding.ActivityMarkdownCreatorBinding | ||
import ani.dantotsu.initActivity | ||
import ani.dantotsu.navBarHeight | ||
import ani.dantotsu.statusBarHeight | ||
import ani.dantotsu.themes.ThemeManager | ||
import ani.dantotsu.toast | ||
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 = "" | ||
@OptIn(DelicateCoroutinesApi::class) | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
ThemeManager(this).applyTheme() | ||
initActivity(this) | ||
binding = ActivityMarkdownCreatorBinding.inflate(layoutInflater) | ||
binding.markdownCreatorToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
topMargin = statusBarHeight | ||
} | ||
binding.buttonContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
bottomMargin += navBarHeight | ||
} | ||
setContentView(binding.root) | ||
if (intent.hasExtra("type")) { | ||
type = intent.getStringExtra("type")!! | ||
} else { | ||
finish() | ||
} | ||
binding.markdownCreatorTitle.text = when (type) { | ||
"activity" -> getString(R.string.create_new_activity) | ||
"review" -> getString(R.string.create_new_review) | ||
else -> "" | ||
} | ||
binding.editText.setText(text) | ||
binding.editText.addTextChangedListener { | ||
if (!binding.markdownCreatorPreviewCheckbox.isChecked) { | ||
text = it.toString() | ||
} | ||
} | ||
previewMarkdown(false) | ||
binding.markdownCreatorPreviewCheckbox.setOnClickListener { | ||
previewMarkdown(binding.markdownCreatorPreviewCheckbox.isChecked) | ||
} | ||
binding.cancelButton.setOnClickListener { | ||
onBackPressedDispatcher.onBackPressed() | ||
} | ||
binding.markdownCreatorBack.setOnClickListener { | ||
onBackPressedDispatcher.onBackPressed() | ||
} | ||
|
||
binding.createButton.setOnClickListener { | ||
launchIO { | ||
val success = when (type) { | ||
"activity" -> Anilist.mutation.postActivity(text) | ||
//"review" -> Anilist.mutation.postReview(text) | ||
else -> "Error: Unknown type" | ||
} | ||
toast(success) | ||
} | ||
onBackPressedDispatcher.onBackPressed() | ||
} | ||
|
||
binding.editText.requestFocus() | ||
} | ||
|
||
private fun previewMarkdown(preview: Boolean) { | ||
val markwon = buildMarkwon(this, false, anilist = true) | ||
if (preview) { | ||
binding.editText.isEnabled = false | ||
markwon.setMarkdown(binding.editText, text) | ||
} else { | ||
binding.editText.setText(text) | ||
binding.editText.isEnabled = true | ||
val markwonEditor = MarkwonEditor.create(markwon) | ||
binding.editText.addTextChangedListener( | ||
MarkwonEditorTextWatcher.withProcess(markwonEditor) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<FrameLayout | ||
android:id="@+id/markdownCreatorToolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:orientation="horizontal" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<ImageView | ||
android:id="@+id/markdownCreatorBack" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="start|center_vertical" | ||
android:layout_marginStart="12dp" | ||
android:src="@drawable/ic_round_arrow_back_ios_new_24" | ||
app:tint="?attr/colorOnBackground" | ||
tools:ignore="ContentDescription" /> | ||
|
||
<TextView | ||
android:id="@+id/markdownCreatorTitle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="48dp" | ||
android:layout_gravity="center_vertical" | ||
android:layout_marginStart="44dp" | ||
android:ellipsize="end" | ||
android:fontFamily="@font/poppins_bold" | ||
android:gravity="center|start" | ||
android:singleLine="true" | ||
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" | ||
android:textColor="?attr/colorOnBackground" | ||
android:textSize="18sp" | ||
tools:text="@string/placeholder" /> | ||
|
||
<CheckBox | ||
android:id="@+id/markdownCreatorPreviewCheckbox" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="end|center_vertical" | ||
android:layout_marginEnd="8dp" | ||
android:contentDescription="@string/preview" | ||
android:text="@string/preview" | ||
tools:ignore="ContentDescription" /> | ||
</FrameLayout> | ||
|
||
<EditText | ||
android:id="@+id/editText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="16dp" | ||
android:fontFamily="@font/poppins" | ||
android:inputType="textMultiLine" | ||
android:padding="16dp" | ||
android:textColor="?attr/colorOnBackground" | ||
android:textIsSelectable="true" | ||
android:textSize="12sp" | ||
app:layout_constraintTop_toBottomOf="@+id/markdownCreatorToolbar" | ||
tools:ignore="LabelFor" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/buttonContainer" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|center_horizontal" | ||
android:layout_marginBottom="24dp" | ||
android:gravity="center_horizontal" | ||
android:orientation="horizontal" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent"> | ||
|
||
<Button | ||
android:id="@+id/cancelButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="64dp" | ||
android:layout_marginEnd="16dp" | ||
android:fontFamily="@font/poppins_bold" | ||
android:maxLines="1" | ||
android:text="@string/cancel" | ||
app:cornerRadius="16dp" | ||
tools:ignore="ButtonStyle" /> | ||
|
||
<Button | ||
android:id="@+id/createButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="64dp" | ||
android:layout_marginStart="16dp" | ||
android:fontFamily="@font/poppins_bold" | ||
android:maxLines="1" | ||
android:text="@string/create" | ||
app:cornerRadius="16dp" | ||
tools:ignore="ButtonStyle" /> | ||
|
||
</LinearLayout> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters