markdown: implement wysiwyg editor

main
Alibek Omarov 5 years ago
parent 9f31effaf2
commit e4400f0061
  1. 1
      app/build.gradle
  2. 52
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
  3. 55
      app/src/main/res/layout/activity_compose.xml

@ -165,6 +165,7 @@ dependencies {
implementation "com.evernote:android-job:1.4.2" implementation "com.evernote:android-job:1.4.2"
implementation "de.c1710:filemojicompat:1.0.17" implementation "de.c1710:filemojicompat:1.0.17"
implementation 'com.github.Tunous:MarkdownEdit:1.0.0'
testImplementation "androidx.test.ext:junit:1.1.1" testImplementation "androidx.test.ext:junit:1.1.1"

@ -160,6 +160,7 @@ import okhttp3.MultipartBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
import me.thanel.markdownedit.MarkdownEdit;
import static com.keylesspalace.tusky.util.MediaUtilsKt.MEDIA_SIZE_UNKNOWN; import static com.keylesspalace.tusky.util.MediaUtilsKt.MEDIA_SIZE_UNKNOWN;
import static com.keylesspalace.tusky.util.MediaUtilsKt.getImageSquarePixels; import static com.keylesspalace.tusky.util.MediaUtilsKt.getImageSquarePixels;
@ -231,6 +232,11 @@ public final class ComposeActivity
private TextView actionAddPoll; private TextView actionAddPoll;
private Button atButton; private Button atButton;
private Button hashButton; private Button hashButton;
private ImageButton codeButton;
private ImageButton linkButton;
private ImageButton strikethroughButton;
private ImageButton italicButton;
private ImageButton boldButton;
private ComposeOptionsView composeOptionsView; private ComposeOptionsView composeOptionsView;
private BottomSheetBehavior composeOptionsBehavior; private BottomSheetBehavior composeOptionsBehavior;
@ -300,6 +306,11 @@ public final class ComposeActivity
emojiList = Collections.emptyList(); emojiList = Collections.emptyList();
atButton = findViewById(R.id.atButton); atButton = findViewById(R.id.atButton);
hashButton = findViewById(R.id.hashButton); hashButton = findViewById(R.id.hashButton);
codeButton = findViewById(R.id.codeButton);
linkButton = findViewById(R.id.linkButton);
strikethroughButton = findViewById(R.id.strikethroughButton);
italicButton = findViewById(R.id.italicButton);
boldButton = findViewById(R.id.boldButton);
saveTootHelper = new SaveTootHelper(database.tootDao(), this); saveTootHelper = new SaveTootHelper(database.tootDao(), this);
@ -400,6 +411,11 @@ public final class ComposeActivity
scheduleView.setResetOnClickListener(v -> resetSchedule()); scheduleView.setResetOnClickListener(v -> resetSchedule());
atButton.setOnClickListener(v -> atButtonClicked()); atButton.setOnClickListener(v -> atButtonClicked());
hashButton.setOnClickListener(v -> hashButtonClicked()); hashButton.setOnClickListener(v -> hashButtonClicked());
codeButton.setOnClickListener(v -> codeButtonClicked());
linkButton.setOnClickListener(v -> linkButtonClicked());
strikethroughButton.setOnClickListener(v -> strikethroughButtonClicked());
italicButton.setOnClickListener(v -> italicButtonClicked());
boldButton.setOnClickListener(v -> boldButtonClicked());
TextView actionPhotoTake = findViewById(R.id.action_photo_take); TextView actionPhotoTake = findViewById(R.id.action_photo_take);
TextView actionPhotoPick = findViewById(R.id.action_photo_pick); TextView actionPhotoPick = findViewById(R.id.action_photo_pick);
@ -444,6 +460,7 @@ public final class ComposeActivity
onCommitContentInternal(previousInputContentInfo, previousFlags); onCommitContentInternal(previousInputContentInfo, previousFlags);
} }
photoUploadUri = savedInstanceState.getParcelable("photoUploadUri"); photoUploadUri = savedInstanceState.getParcelable("photoUploadUri");
markdownMode = savedInstanceState.getBoolean("statusMarkdownMode");
} else { } else {
statusMarkSensitive = activeAccount.getDefaultMediaSensitivity(); statusMarkSensitive = activeAccount.getDefaultMediaSensitivity();
startingHideText = false; startingHideText = false;
@ -764,6 +781,27 @@ public final class ComposeActivity
replaceTextAtCaret("#"); replaceTextAtCaret("#");
} }
private void codeButtonClicked() {
MarkdownEdit.addCode(textEditor);
}
private void linkButtonClicked() {
MarkdownEdit.addLink(textEditor);
}
private void strikethroughButtonClicked() {
MarkdownEdit.addStrikeThrough(textEditor);
}
private void italicButtonClicked() {
MarkdownEdit.addItalic(textEditor);
}
private void boldButtonClicked() {
MarkdownEdit.addBold(textEditor);
}
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
ArrayList<SavedQueuedMedia> savedMediaQueued = new ArrayList<>(); ArrayList<SavedQueuedMedia> savedMediaQueued = new ArrayList<>();
@ -783,6 +821,7 @@ public final class ComposeActivity
currentFlags = 0; currentFlags = 0;
outState.putParcelable("photoUploadUri", photoUploadUri); outState.putParcelable("photoUploadUri", photoUploadUri);
outState.putInt("statusVisibility", statusVisibility.getNum()); outState.putInt("statusVisibility", statusVisibility.getNum());
outState.putBoolean("statusMarkdownMode", markdownMode);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -809,6 +848,8 @@ public final class ComposeActivity
} }
private void enableMarkdownMode(boolean enable) { private void enableMarkdownMode(boolean enable) {
enableMarkdownWYSIWYGButtons(enable);
markdownMode = enable; markdownMode = enable;
TransitionManager.beginDelayedTransition((ViewGroup) markdownButton.getParent()); TransitionManager.beginDelayedTransition((ViewGroup) markdownButton.getParent());
@ -817,7 +858,6 @@ public final class ComposeActivity
color = ThemeUtils.getColor(this, markdownMode ? R.attr.colorPrimary : android.R.attr.textColorTertiary); color = ThemeUtils.getColor(this, markdownMode ? R.attr.colorPrimary : android.R.attr.textColorTertiary);
markdownButton.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); markdownButton.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
} }
private void toggleMarkdownMode() { private void toggleMarkdownMode() {
@ -880,6 +920,16 @@ public final class ComposeActivity
tootButton.setEnabled(true); tootButton.setEnabled(true);
} }
private void enableMarkdownWYSIWYGButtons(boolean enable) {
int visibility = enable ? View.VISIBLE : View.GONE;
codeButton.setVisibility(visibility);
linkButton.setVisibility(visibility);
strikethroughButton.setVisibility(visibility);
italicButton.setVisibility(visibility);
boldButton.setVisibility(visibility);
}
private void setStatusVisibility(Status.Visibility visibility) { private void setStatusVisibility(Status.Visibility visibility) {
statusVisibility = visibility; statusVisibility = visibility;
composeOptionsView.setStatusVisibility(visibility); composeOptionsView.setStatusVisibility(visibility);

@ -47,6 +47,61 @@
android:textColor="?android:textColorTertiary" android:textColor="?android:textColorTertiary"
android:textSize="?attr/status_text_large" android:textSize="?attr/status_text_large"
/> />
<ImageButton
android:id="@+id/codeButton"
style="?attr/image_button_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/md_code"
/>
<ImageButton
android:id="@+id/linkButton"
style="?attr/image_button_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/md_link"
/>
<ImageButton
android:id="@+id/strikethroughButton"
style="?attr/image_button_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/md_strikethrough"
/>
<ImageButton
android:id="@+id/italicButton"
style="?attr/image_button_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/md_italic"
/>
<ImageButton
android:id="@+id/boldButton"
style="?attr/image_button_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:padding="8dp"
android:visibility="gone"
android:src="@drawable/md_bold"
/>
</androidx.appcompat.widget.Toolbar> </androidx.appcompat.widget.Toolbar>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView

Loading…
Cancel
Save