markdown: implement choosing markdown mode in compose activity and sending toot with it
This commit is contained in:
parent
5620120b9f
commit
793c21eb85
@ -202,6 +202,7 @@ public final class ComposeActivity
|
|||||||
private static final String SCHEDULED_AT_EXTRA = "scheduled_at";
|
private static final String SCHEDULED_AT_EXTRA = "scheduled_at";
|
||||||
private static final String SENSITIVE_EXTRA = "sensitive";
|
private static final String SENSITIVE_EXTRA = "sensitive";
|
||||||
private static final String POLL_EXTRA = "poll";
|
private static final String POLL_EXTRA = "poll";
|
||||||
|
private static final String MARKDOWN_MODE_EXTRA = "markdownMode";
|
||||||
// Mastodon only counts URLs as this long in terms of status character limits
|
// Mastodon only counts URLs as this long in terms of status character limits
|
||||||
static final int MAXIMUM_URL_LENGTH = 23;
|
static final int MAXIMUM_URL_LENGTH = 23;
|
||||||
// https://github.com/tootsuite/mastodon/blob/1656663/app/models/media_attachment.rb#L94
|
// https://github.com/tootsuite/mastodon/blob/1656663/app/models/media_attachment.rb#L94
|
||||||
@ -226,6 +227,7 @@ public final class ComposeActivity
|
|||||||
private ImageButton emojiButton;
|
private ImageButton emojiButton;
|
||||||
private ImageButton hideMediaToggle;
|
private ImageButton hideMediaToggle;
|
||||||
private ImageButton scheduleButton;
|
private ImageButton scheduleButton;
|
||||||
|
private ImageButton markdownButton;
|
||||||
private TextView actionAddPoll;
|
private TextView actionAddPoll;
|
||||||
private Button atButton;
|
private Button atButton;
|
||||||
private Button hashButton;
|
private Button hashButton;
|
||||||
@ -263,6 +265,7 @@ public final class ComposeActivity
|
|||||||
private @Px
|
private @Px
|
||||||
int thumbnailViewSize;
|
int thumbnailViewSize;
|
||||||
private boolean isPleroma = false;
|
private boolean isPleroma = false;
|
||||||
|
private boolean markdownMode = false;
|
||||||
|
|
||||||
private SaveTootHelper saveTootHelper;
|
private SaveTootHelper saveTootHelper;
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
@ -291,6 +294,7 @@ public final class ComposeActivity
|
|||||||
emojiButton = findViewById(R.id.composeEmojiButton);
|
emojiButton = findViewById(R.id.composeEmojiButton);
|
||||||
hideMediaToggle = findViewById(R.id.composeHideMediaButton);
|
hideMediaToggle = findViewById(R.id.composeHideMediaButton);
|
||||||
scheduleButton = findViewById(R.id.composeScheduleButton);
|
scheduleButton = findViewById(R.id.composeScheduleButton);
|
||||||
|
markdownButton = findViewById(R.id.composeMarkdownButton);
|
||||||
scheduleView = findViewById(R.id.composeScheduleView);
|
scheduleView = findViewById(R.id.composeScheduleView);
|
||||||
emojiView = findViewById(R.id.emojiView);
|
emojiView = findViewById(R.id.emojiView);
|
||||||
emojiList = Collections.emptyList();
|
emojiList = Collections.emptyList();
|
||||||
@ -382,6 +386,7 @@ public final class ComposeActivity
|
|||||||
emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false));
|
emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false));
|
||||||
|
|
||||||
enableButton(emojiButton, false, false);
|
enableButton(emojiButton, false, false);
|
||||||
|
enableButton(markdownButton, false, false);
|
||||||
|
|
||||||
// Setup the interface buttons.
|
// Setup the interface buttons.
|
||||||
tootButton.setOnClickListener(v -> onSendClicked());
|
tootButton.setOnClickListener(v -> onSendClicked());
|
||||||
@ -391,6 +396,7 @@ public final class ComposeActivity
|
|||||||
emojiButton.setOnClickListener(v -> showEmojis());
|
emojiButton.setOnClickListener(v -> showEmojis());
|
||||||
hideMediaToggle.setOnClickListener(v -> toggleHideMedia());
|
hideMediaToggle.setOnClickListener(v -> toggleHideMedia());
|
||||||
scheduleButton.setOnClickListener(v -> showScheduleView());
|
scheduleButton.setOnClickListener(v -> showScheduleView());
|
||||||
|
markdownButton.setOnClickListener(v -> toggleMarkdownMode());
|
||||||
scheduleView.setResetOnClickListener(v -> resetSchedule());
|
scheduleView.setResetOnClickListener(v -> resetSchedule());
|
||||||
atButton.setOnClickListener(v -> atButtonClicked());
|
atButton.setOnClickListener(v -> atButtonClicked());
|
||||||
hashButton.setOnClickListener(v -> hashButtonClicked());
|
hashButton.setOnClickListener(v -> hashButtonClicked());
|
||||||
@ -549,10 +555,14 @@ public final class ComposeActivity
|
|||||||
if(intent.hasExtra(POLL_EXTRA) && (mediaAttachments == null || mediaAttachments.size() == 0)) {
|
if(intent.hasExtra(POLL_EXTRA) && (mediaAttachments == null || mediaAttachments.size() == 0)) {
|
||||||
updatePoll(intent.getParcelableExtra(POLL_EXTRA));
|
updatePoll(intent.getParcelableExtra(POLL_EXTRA));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mediaAttachments != null && mediaAttachments.size() > 0) {
|
if(mediaAttachments != null && mediaAttachments.size() > 0) {
|
||||||
enablePollButton(false);
|
enablePollButton(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(intent.hasExtra(MARKDOWN_MODE_EXTRA)) {
|
||||||
|
enableMarkdownMode(intent.getBooleanExtra(MARKDOWN_MODE_EXTRA, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After the starting state is finalised, the interface can be set to reflect this state.
|
// After the starting state is finalised, the interface can be set to reflect this state.
|
||||||
@ -796,7 +806,23 @@ public final class ComposeActivity
|
|||||||
statusMarkSensitive = !statusMarkSensitive;
|
statusMarkSensitive = !statusMarkSensitive;
|
||||||
updateHideMediaToggle();
|
updateHideMediaToggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableMarkdownMode(boolean enable) {
|
||||||
|
markdownMode = enable;
|
||||||
|
|
||||||
|
TransitionManager.beginDelayedTransition((ViewGroup) markdownButton.getParent());
|
||||||
|
|
||||||
|
@ColorInt int color;
|
||||||
|
color = ThemeUtils.getColor(this, markdownMode ? R.attr.colorPrimary : android.R.attr.textColorTertiary);
|
||||||
|
|
||||||
|
markdownButton.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleMarkdownMode() {
|
||||||
|
enableMarkdownMode(!markdownMode);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateHideMediaToggle() {
|
private void updateHideMediaToggle() {
|
||||||
TransitionManager.beginDelayedTransition((ViewGroup) hideMediaToggle.getParent());
|
TransitionManager.beginDelayedTransition((ViewGroup) hideMediaToggle.getParent());
|
||||||
|
|
||||||
@ -822,7 +848,7 @@ public final class ComposeActivity
|
|||||||
hideMediaToggle.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
hideMediaToggle.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateScheduleButton() {
|
private void updateScheduleButton() {
|
||||||
@ColorInt int color;
|
@ColorInt int color;
|
||||||
if(scheduleView.getTime() == null) {
|
if(scheduleView.getTime() == null) {
|
||||||
@ -1138,7 +1164,7 @@ public final class ComposeActivity
|
|||||||
getIntent().getStringExtra(REPLYING_STATUS_CONTENT_EXTRA),
|
getIntent().getStringExtra(REPLYING_STATUS_CONTENT_EXTRA),
|
||||||
getIntent().getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA),
|
getIntent().getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA),
|
||||||
getIntent().getStringExtra(SAVED_JSON_URLS_EXTRA),
|
getIntent().getStringExtra(SAVED_JSON_URLS_EXTRA),
|
||||||
accountManager.getActiveAccount(), savedTootUid);
|
accountManager.getActiveAccount(), savedTootUid, markdownMode);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
startForegroundService(sendIntent);
|
startForegroundService(sendIntent);
|
||||||
@ -2011,7 +2037,14 @@ public final class ComposeActivity
|
|||||||
maxPollOptionLength = instance.getPollLimits().getMaxOptionChars();
|
maxPollOptionLength = instance.getPollLimits().getMaxOptionChars();
|
||||||
}
|
}
|
||||||
|
|
||||||
isPleroma = instance.isPleroma();
|
if ((isPleroma = instance.isPleroma())) {
|
||||||
|
// TODO: implement nodeinfo later
|
||||||
|
enableButton(markdownButton, true, true);
|
||||||
|
|
||||||
|
// we always can add new poll but only one
|
||||||
|
if (poll == null)
|
||||||
|
enablePollButton(true);
|
||||||
|
}
|
||||||
|
|
||||||
cacheInstanceMetadata(accountManager.getActiveAccount());
|
cacheInstanceMetadata(accountManager.getActiveAccount());
|
||||||
}
|
}
|
||||||
@ -2153,6 +2186,8 @@ public final class ComposeActivity
|
|||||||
private Boolean sensitive;
|
private Boolean sensitive;
|
||||||
@Nullable
|
@Nullable
|
||||||
private NewPoll poll;
|
private NewPoll poll;
|
||||||
|
@Nullable
|
||||||
|
private Boolean markdownMode;
|
||||||
|
|
||||||
public IntentBuilder savedTootUid(int uid) {
|
public IntentBuilder savedTootUid(int uid) {
|
||||||
this.savedTootUid = uid;
|
this.savedTootUid = uid;
|
||||||
@ -2228,6 +2263,11 @@ public final class ComposeActivity
|
|||||||
this.poll = poll;
|
this.poll = poll;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IntentBuilder markdownMode(boolean mode) {
|
||||||
|
this.markdownMode = mode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Intent build(Context context) {
|
public Intent build(Context context) {
|
||||||
Intent intent = new Intent(context, ComposeActivity.class);
|
Intent intent = new Intent(context, ComposeActivity.class);
|
||||||
@ -2278,6 +2318,9 @@ public final class ComposeActivity
|
|||||||
if (poll != null) {
|
if (poll != null) {
|
||||||
intent.putExtra(POLL_EXTRA, poll);
|
intent.putExtra(POLL_EXTRA, poll);
|
||||||
}
|
}
|
||||||
|
if (markdownMode != null) {
|
||||||
|
intent.putExtra(MARKDOWN_MODE_EXTRA, markdownMode);
|
||||||
|
}
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ data class NewStatus(
|
|||||||
val sensitive: Boolean,
|
val sensitive: Boolean,
|
||||||
@SerializedName("media_ids") val mediaIds: List<String>?,
|
@SerializedName("media_ids") val mediaIds: List<String>?,
|
||||||
@SerializedName("scheduled_at") val scheduledAt: String?,
|
@SerializedName("scheduled_at") val scheduledAt: String?,
|
||||||
val poll: NewPoll?
|
val poll: NewPoll?,
|
||||||
|
var content_type: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
@ -35,4 +36,4 @@ data class NewPoll(
|
|||||||
val options: List<String>,
|
val options: List<String>,
|
||||||
@SerializedName("expires_in") val expiresIn: Int,
|
@SerializedName("expires_in") val expiresIn: Int,
|
||||||
val multiple: Boolean
|
val multiple: Boolean
|
||||||
): Parcelable
|
): Parcelable
|
||||||
|
@ -97,7 +97,7 @@ class SendStatusBroadcastReceiver : BroadcastReceiver() {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null, account, 0)
|
null, account, 0, null)
|
||||||
|
|
||||||
context.startService(sendIntent)
|
context.startService(sendIntent)
|
||||||
|
|
||||||
@ -146,4 +146,4 @@ class SendStatusBroadcastReceiver : BroadcastReceiver() {
|
|||||||
return remoteInput.getCharSequence(NotificationHelper.KEY_REPLY, "")
|
return remoteInput.getCharSequence(NotificationHelper.KEY_REPLY, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,8 @@ class SendTootService : Service(), Injectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tootToSend.retries++
|
tootToSend.retries++
|
||||||
|
|
||||||
|
val contentType : String? = if (tootToSend.markdownMode != null && tootToSend.markdownMode == true) "text/markdown" else null
|
||||||
|
|
||||||
val newStatus = NewStatus(
|
val newStatus = NewStatus(
|
||||||
tootToSend.text,
|
tootToSend.text,
|
||||||
@ -142,7 +144,8 @@ class SendTootService : Service(), Injectable {
|
|||||||
tootToSend.sensitive,
|
tootToSend.sensitive,
|
||||||
tootToSend.mediaIds,
|
tootToSend.mediaIds,
|
||||||
tootToSend.scheduledAt,
|
tootToSend.scheduledAt,
|
||||||
tootToSend.poll
|
tootToSend.poll,
|
||||||
|
contentType
|
||||||
)
|
)
|
||||||
|
|
||||||
val sendCall = mastodonApi.createStatus(
|
val sendCall = mastodonApi.createStatus(
|
||||||
@ -298,7 +301,8 @@ class SendTootService : Service(), Injectable {
|
|||||||
replyingStatusAuthorUsername: String?,
|
replyingStatusAuthorUsername: String?,
|
||||||
savedJsonUrls: String?,
|
savedJsonUrls: String?,
|
||||||
account: AccountEntity,
|
account: AccountEntity,
|
||||||
savedTootUid: Int
|
savedTootUid: Int,
|
||||||
|
markdownMode: Boolean?
|
||||||
): Intent {
|
): Intent {
|
||||||
val intent = Intent(context, SendTootService::class.java)
|
val intent = Intent(context, SendTootService::class.java)
|
||||||
|
|
||||||
@ -317,6 +321,7 @@ class SendTootService : Service(), Injectable {
|
|||||||
replyingStatusContent,
|
replyingStatusContent,
|
||||||
replyingStatusAuthorUsername,
|
replyingStatusAuthorUsername,
|
||||||
savedJsonUrls,
|
savedJsonUrls,
|
||||||
|
markdownMode,
|
||||||
account.id,
|
account.id,
|
||||||
savedTootUid,
|
savedTootUid,
|
||||||
idempotencyKey,
|
idempotencyKey,
|
||||||
@ -361,6 +366,7 @@ data class TootToSend(val text: String,
|
|||||||
val replyingStatusContent: String?,
|
val replyingStatusContent: String?,
|
||||||
val replyingStatusAuthorUsername: String?,
|
val replyingStatusAuthorUsername: String?,
|
||||||
val savedJsonUrls: String?,
|
val savedJsonUrls: String?,
|
||||||
|
var markdownMode: Boolean?,
|
||||||
val accountId: Long,
|
val accountId: Long,
|
||||||
val savedTootUid: Int,
|
val savedTootUid: Int,
|
||||||
val idempotencyKey: String,
|
val idempotencyKey: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user