drafts: fix applying formatting syntax from drafts, fix icon in settings, small refactoring
This commit is contained in:
parent
2eacdfb198
commit
833803359e
@ -164,16 +164,24 @@ class ComposeActivity : BaseActivity(),
|
|||||||
composeMediaPreviewBar.adapter = mediaAdapter
|
composeMediaPreviewBar.adapter = mediaAdapter
|
||||||
composeMediaPreviewBar.itemAnimator = null
|
composeMediaPreviewBar.itemAnimator = null
|
||||||
|
|
||||||
subscribeToUpdates(mediaAdapter)
|
// set before subscribing to updates to not accidentally catch it
|
||||||
|
viewModel.formattingSyntax.value = activeAccount.defaultFormattingSyntax
|
||||||
|
|
||||||
|
subscribeToUpdates(mediaAdapter, activeAccount)
|
||||||
setupButtons()
|
setupButtons()
|
||||||
|
|
||||||
photoUploadUri = savedInstanceState?.getParcelable(PHOTO_UPLOAD_URI_KEY)
|
photoUploadUri = savedInstanceState?.getParcelable(PHOTO_UPLOAD_URI_KEY)
|
||||||
viewModel.formattingSyntax = activeAccount.defaultFormattingSyntax
|
|
||||||
|
|
||||||
/* If the composer is started up as a reply to another post, override the "starting" state
|
/* If the composer is started up as a reply to another post, override the "starting" state
|
||||||
* based on what the intent from the reply request passes. */
|
* based on what the intent from the reply request passes. */
|
||||||
|
|
||||||
val composeOptions = intent.getParcelableExtra<ComposeOptions?>(COMPOSE_OPTIONS_EXTRA)
|
val composeOptions = intent.getParcelableExtra<ComposeOptions?>(COMPOSE_OPTIONS_EXTRA)
|
||||||
|
|
||||||
|
if (!composeOptions?.formattingSyntax.isNullOrEmpty()) {
|
||||||
|
suggestFormattingSyntax = composeOptions?.formattingSyntax!!
|
||||||
|
} else {
|
||||||
|
suggestFormattingSyntax = activeAccount.defaultFormattingSyntax
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.setup(composeOptions)
|
viewModel.setup(composeOptions)
|
||||||
setupReplyViews(composeOptions?.replyingStatusAuthor, composeOptions?.replyingStatusContent)
|
setupReplyViews(composeOptions?.replyingStatusAuthor, composeOptions?.replyingStatusContent)
|
||||||
@ -181,13 +189,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
if (!tootText.isNullOrEmpty()) {
|
if (!tootText.isNullOrEmpty()) {
|
||||||
composeEditField.setText(tootText)
|
composeEditField.setText(tootText)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(viewModel.formattingSyntax.length == 0) {
|
|
||||||
suggestFormattingSyntax = "text/markdown"
|
|
||||||
} else {
|
|
||||||
suggestFormattingSyntax = viewModel.formattingSyntax
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!composeOptions?.scheduledAt.isNullOrEmpty()) {
|
if (!composeOptions?.scheduledAt.isNullOrEmpty()) {
|
||||||
composeScheduleView.setDateTime(composeOptions?.scheduledAt)
|
composeScheduleView.setDateTime(composeOptions?.scheduledAt)
|
||||||
}
|
}
|
||||||
@ -323,7 +325,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
var supportedFormattingSyntax = arrayListOf<String>()
|
var supportedFormattingSyntax = arrayListOf<String>()
|
||||||
|
|
||||||
private fun subscribeToUpdates(mediaAdapter: MediaPreviewAdapter) {
|
private fun subscribeToUpdates(mediaAdapter: MediaPreviewAdapter, activeAccount: AccountEntity) {
|
||||||
withLifecycleContext {
|
withLifecycleContext {
|
||||||
viewModel.instanceParams.observe { instanceData ->
|
viewModel.instanceParams.observe { instanceData ->
|
||||||
maximumTootCharacters = instanceData.maxChars
|
maximumTootCharacters = instanceData.maxChars
|
||||||
@ -346,18 +348,18 @@ class ComposeActivity : BaseActivity(),
|
|||||||
if(supportedFormattingSyntax.size != 0) {
|
if(supportedFormattingSyntax.size != 0) {
|
||||||
composeFormattingSyntax.visible(true)
|
composeFormattingSyntax.visible(true)
|
||||||
|
|
||||||
val supportsPrefferedSyntax = supportedFormattingSyntax.contains(viewModel.formattingSyntax)
|
val supportsPrefferedSyntax = supportedFormattingSyntax.contains(viewModel.formattingSyntax.value!!)
|
||||||
|
|
||||||
if(!supportsPrefferedSyntax) {
|
if(!supportsPrefferedSyntax) {
|
||||||
viewModel.formattingSyntax = ""
|
suggestFormattingSyntax = if(supportedFormattingSyntax.contains(activeAccount.defaultFormattingSyntax))
|
||||||
|
activeAccount.defaultFormattingSyntax
|
||||||
setIconForSyntax(supportedFormattingSyntax[0], false)
|
else supportedFormattingSyntax[0]
|
||||||
} else {
|
|
||||||
setIconForSyntax(viewModel.formattingSyntax, true)
|
viewModel.formattingSyntax.value = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(instanceData.software.equals("pleroma")) {
|
if(instanceData.software == "pleroma") {
|
||||||
composePreviewButton.visibility = View.VISIBLE
|
composePreviewButton.visibility = View.VISIBLE
|
||||||
reenableAttachments()
|
reenableAttachments()
|
||||||
}
|
}
|
||||||
@ -420,6 +422,17 @@ class ComposeActivity : BaseActivity(),
|
|||||||
// Focus may have changed during view model setup, ensure initial focus is on the edit field
|
// Focus may have changed during view model setup, ensure initial focus is on the edit field
|
||||||
composeEditField.requestFocus()
|
composeEditField.requestFocus()
|
||||||
}
|
}
|
||||||
|
viewModel.formattingSyntax.observe {
|
||||||
|
if(it.isEmpty()) {
|
||||||
|
enableFormattingSyntaxButton(suggestFormattingSyntax, false)
|
||||||
|
setIconForSyntax(suggestFormattingSyntax, false)
|
||||||
|
} else {
|
||||||
|
val enable = it == suggestFormattingSyntax
|
||||||
|
|
||||||
|
enableFormattingSyntaxButton(it, enable)
|
||||||
|
setIconForSyntax(it, enable)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,12 +560,10 @@ class ComposeActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFormattingMode() {
|
private fun toggleFormattingMode() {
|
||||||
if(viewModel.formattingSyntax.equals(suggestFormattingSyntax)) {
|
if(viewModel.formattingSyntax.value!! == suggestFormattingSyntax) {
|
||||||
viewModel.formattingSyntax = ""
|
viewModel.formattingSyntax.value = ""
|
||||||
enableFormattingSyntaxButton(suggestFormattingSyntax, false)
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.formattingSyntax = suggestFormattingSyntax
|
viewModel.formattingSyntax.value = suggestFormattingSyntax
|
||||||
enableFormattingSyntaxButton(suggestFormattingSyntax, true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,13 +590,8 @@ class ComposeActivity : BaseActivity(),
|
|||||||
htmlId -> "text/html"
|
htmlId -> "text/html"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
if(choose.length == 0) {
|
suggestFormattingSyntax = choose
|
||||||
// leave previous
|
viewModel.formattingSyntax.value = choose
|
||||||
setIconForSyntax(viewModel.formattingSyntax, false)
|
|
||||||
} else {
|
|
||||||
setIconForSyntax(choose, true)
|
|
||||||
}
|
|
||||||
viewModel.formattingSyntax = choose
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
menu.show()
|
menu.show()
|
||||||
@ -652,7 +658,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun codeButtonClicked() {
|
private fun codeButtonClicked() {
|
||||||
when(viewModel.formattingSyntax) {
|
when(viewModel.formattingSyntax.value!!) {
|
||||||
"text/markdown" -> MarkdownEdit.addCode(composeEditField)
|
"text/markdown" -> MarkdownEdit.addCode(composeEditField)
|
||||||
"text/bbcode" -> BBCodeEdit.addCode(composeEditField)
|
"text/bbcode" -> BBCodeEdit.addCode(composeEditField)
|
||||||
"text/html" -> HTMLEdit.addCode(composeEditField)
|
"text/html" -> HTMLEdit.addCode(composeEditField)
|
||||||
@ -660,7 +666,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun linkButtonClicked() {
|
private fun linkButtonClicked() {
|
||||||
when(viewModel.formattingSyntax) {
|
when(viewModel.formattingSyntax.value!!) {
|
||||||
"text/markdown" -> MarkdownEdit.addLink(composeEditField)
|
"text/markdown" -> MarkdownEdit.addLink(composeEditField)
|
||||||
"text/bbcode" -> BBCodeEdit.addLink(composeEditField)
|
"text/bbcode" -> BBCodeEdit.addLink(composeEditField)
|
||||||
"text/html" -> HTMLEdit.addLink(composeEditField)
|
"text/html" -> HTMLEdit.addLink(composeEditField)
|
||||||
@ -668,7 +674,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun strikethroughButtonClicked() {
|
private fun strikethroughButtonClicked() {
|
||||||
when(viewModel.formattingSyntax) {
|
when(viewModel.formattingSyntax.value!!) {
|
||||||
"text/markdown" -> MarkdownEdit.addStrikeThrough(composeEditField)
|
"text/markdown" -> MarkdownEdit.addStrikeThrough(composeEditField)
|
||||||
"text/bbcode" -> BBCodeEdit.addStrikeThrough(composeEditField)
|
"text/bbcode" -> BBCodeEdit.addStrikeThrough(composeEditField)
|
||||||
"text/html" -> HTMLEdit.addStrikeThrough(composeEditField)
|
"text/html" -> HTMLEdit.addStrikeThrough(composeEditField)
|
||||||
@ -676,7 +682,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun italicButtonClicked() {
|
private fun italicButtonClicked() {
|
||||||
when(viewModel.formattingSyntax) {
|
when(viewModel.formattingSyntax.value!!) {
|
||||||
"text/markdown" -> MarkdownEdit.addItalic(composeEditField)
|
"text/markdown" -> MarkdownEdit.addItalic(composeEditField)
|
||||||
"text/bbcode" -> BBCodeEdit.addItalic(composeEditField)
|
"text/bbcode" -> BBCodeEdit.addItalic(composeEditField)
|
||||||
"text/html" -> HTMLEdit.addItalic(composeEditField)
|
"text/html" -> HTMLEdit.addItalic(composeEditField)
|
||||||
@ -684,7 +690,7 @@ class ComposeActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun boldButtonClicked() {
|
private fun boldButtonClicked() {
|
||||||
when(viewModel.formattingSyntax) {
|
when(viewModel.formattingSyntax.value!!) {
|
||||||
"text/markdown" -> MarkdownEdit.addBold(composeEditField)
|
"text/markdown" -> MarkdownEdit.addBold(composeEditField)
|
||||||
"text/bbcode" -> BBCodeEdit.addBold(composeEditField)
|
"text/bbcode" -> BBCodeEdit.addBold(composeEditField)
|
||||||
"text/html" -> HTMLEdit.addBold(composeEditField)
|
"text/html" -> HTMLEdit.addBold(composeEditField)
|
||||||
|
@ -60,7 +60,6 @@ class ComposeViewModel @Inject constructor(
|
|||||||
private var inReplyToId: String? = null
|
private var inReplyToId: String? = null
|
||||||
private var startingVisibility: Status.Visibility = Status.Visibility.UNKNOWN
|
private var startingVisibility: Status.Visibility = Status.Visibility.UNKNOWN
|
||||||
private var contentWarningStateChanged: Boolean = false
|
private var contentWarningStateChanged: Boolean = false
|
||||||
public var formattingSyntax: String = ""
|
|
||||||
private var modifiedInitialState: Boolean = false
|
private var modifiedInitialState: Boolean = false
|
||||||
|
|
||||||
val markMediaAsSensitive =
|
val markMediaAsSensitive =
|
||||||
@ -71,6 +70,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
val setupComplete = mutableLiveData(false)
|
val setupComplete = mutableLiveData(false)
|
||||||
val poll: MutableLiveData<NewPoll?> = mutableLiveData(null)
|
val poll: MutableLiveData<NewPoll?> = mutableLiveData(null)
|
||||||
val scheduledAt: MutableLiveData<String?> = mutableLiveData(null)
|
val scheduledAt: MutableLiveData<String?> = mutableLiveData(null)
|
||||||
|
val formattingSyntax: MutableLiveData<String> = mutableLiveData("")
|
||||||
|
|
||||||
private val isEditingScheduledToot get() = !scheduledTootId.isNullOrEmpty()
|
private val isEditingScheduledToot get() = !scheduledTootId.isNullOrEmpty()
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
mediaUris = mediaUris,
|
mediaUris = mediaUris,
|
||||||
mediaDescriptions = mediaDescriptions,
|
mediaDescriptions = mediaDescriptions,
|
||||||
poll = poll.value,
|
poll = poll.value,
|
||||||
formattingSyntax = formattingSyntax,
|
formattingSyntax = formattingSyntax.value!!,
|
||||||
failedToSend = false
|
failedToSend = false
|
||||||
).subscribe()
|
).subscribe()
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
poll = poll.value,
|
poll = poll.value,
|
||||||
replyingStatusContent = null,
|
replyingStatusContent = null,
|
||||||
replyingStatusAuthorUsername = null,
|
replyingStatusAuthorUsername = null,
|
||||||
formattingSyntax = formattingSyntax,
|
formattingSyntax = formattingSyntax.value!!,
|
||||||
preview = preview,
|
preview = preview,
|
||||||
accountId = accountManager.activeAccount!!.id,
|
accountId = accountManager.activeAccount!!.id,
|
||||||
savedTootUid = savedTootUid,
|
savedTootUid = savedTootUid,
|
||||||
@ -271,7 +271,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
replyingStatusContent = composeOptions?.replyingStatusContent
|
replyingStatusContent = composeOptions?.replyingStatusContent
|
||||||
replyingStatusAuthor = composeOptions?.replyingStatusAuthor
|
replyingStatusAuthor = composeOptions?.replyingStatusAuthor
|
||||||
|
|
||||||
formattingSyntax = composeOptions?.formattingSyntax ?: accountManager.activeAccount!!.defaultFormattingSyntax
|
formattingSyntax.value = composeOptions?.formattingSyntax ?: accountManager.activeAccount!!.defaultFormattingSyntax
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updatePoll(newPoll: NewPoll) {
|
fun updatePoll(newPoll: NewPoll) {
|
||||||
|
@ -138,7 +138,8 @@ class DraftsActivity : BaseActivity(), DraftActionListener {
|
|||||||
draftAttachments = draft.attachments,
|
draftAttachments = draft.attachments,
|
||||||
poll = draft.poll,
|
poll = draft.poll,
|
||||||
sensitive = draft.sensitive,
|
sensitive = draft.sensitive,
|
||||||
visibility = draft.visibility
|
visibility = draft.visibility,
|
||||||
|
formattingSyntax = draft.formattingSyntax
|
||||||
)
|
)
|
||||||
|
|
||||||
bottomSheet.state = BottomSheetBehavior.STATE_HIDDEN
|
bottomSheet.state = BottomSheetBehavior.STATE_HIDDEN
|
||||||
@ -174,7 +175,8 @@ class DraftsActivity : BaseActivity(), DraftActionListener {
|
|||||||
draftAttachments = draft.attachments,
|
draftAttachments = draft.attachments,
|
||||||
poll = draft.poll,
|
poll = draft.poll,
|
||||||
sensitive = draft.sensitive,
|
sensitive = draft.sensitive,
|
||||||
visibility = draft.visibility
|
visibility = draft.visibility,
|
||||||
|
formattingSyntax = draft.formattingSyntax
|
||||||
)
|
)
|
||||||
|
|
||||||
startActivity(ComposeActivity.startIntent(this, composeOptions))
|
startActivity(ComposeActivity.startIntent(this, composeOptions))
|
||||||
|
@ -156,7 +156,7 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), Injectable {
|
|||||||
"text/html" -> "HTML"
|
"text/html" -> "HTML"
|
||||||
else -> "Plaintext"
|
else -> "Plaintext"
|
||||||
}
|
}
|
||||||
setIcon(getIconForSyntax(value))
|
setIcon(getIconForSyntax(syntax))
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
val syntax = when(newValue) {
|
val syntax = when(newValue) {
|
||||||
"Markdown" -> "text/markdown"
|
"Markdown" -> "text/markdown"
|
||||||
@ -372,7 +372,7 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), Injectable {
|
|||||||
"text/html" -> R.drawable.ic_html_24dp
|
"text/html" -> R.drawable.ic_html_24dp
|
||||||
"text/bbcode" -> R.drawable.ic_bbcode_24dp
|
"text/bbcode" -> R.drawable.ic_bbcode_24dp
|
||||||
"text/markdown" -> R.drawable.ic_markdown
|
"text/markdown" -> R.drawable.ic_markdown
|
||||||
else -> 0
|
else -> android.R.color.transparent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,6 @@ data class DraftAttachment(
|
|||||||
get() = uriString.toUri()
|
get() = uriString.toUri()
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
IMAGE, VIDEO, AUDIO;
|
IMAGE, VIDEO, AUDIO, UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user