comment #702 - Allow to format the text when composing

This commit is contained in:
Thomas 2022-12-30 17:40:03 +01:00
parent 2164c2fe91
commit e5c4efb4e9
10 changed files with 103 additions and 4 deletions

View file

@ -60,7 +60,8 @@ public interface MastodonStatusesService {
@Field("spoiler_text") String spoiler_text,
@Field("visibility") String visibility,
@Field("language") String language,
@Field("quote_id") String quote_id
@Field("quote_id") String quote_id,
@Field("content_type") String content_type
);
@GET("statuses/{id}/source")

View file

@ -50,6 +50,8 @@ public class Status implements Serializable, Cloneable {
public String text;
@SerializedName("quote_id")
public String quote_id;
@SerializedName("content_type")
public String content_type;
@SerializedName("visibility")
public String visibility;
@SerializedName("language")

View file

@ -221,7 +221,7 @@ public class ComposeWorker extends Worker {
if (dataPost.scheduledDate == null) {
if (dataPost.statusEditId == null) {
statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language, statuses.get(i).quote_id);
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language, statuses.get(i).quote_id, statuses.get(i).content_type);
} else { //Status is edited
statusCall = mastodonStatusesService.updateStatus(null, dataPost.token, dataPost.statusEditId, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language);

View file

@ -28,6 +28,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
@ -99,6 +100,7 @@ import java.util.regex.Pattern;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.ComposeActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.client.entities.api.Attachment;
import app.fedilab.android.client.entities.api.Emoji;
import app.fedilab.android.client.entities.api.EmojiInstance;
@ -1273,9 +1275,40 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
Status statusDraft = statusList.get(position);
ComposeViewHolder holder = (ComposeViewHolder) viewHolder;
boolean extraFeatures = sharedpreferences.getBoolean(context.getString(R.string.SET_EXTAND_EXTRA_FEATURES) + MainActivity.currentUserID + MainActivity.currentInstance, false);
holder.binding.buttonEmojiOne.setVisibility(View.VISIBLE);
if (extraFeatures) {
holder.binding.buttonTextFormat.setVisibility(View.VISIBLE);
holder.binding.buttonTextFormat.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle());
builder.setTitle(context.getString(R.string.post_format));
Resources res = context.getResources();
String[] formatArr = res.getStringArray(R.array.SET_POST_FORMAT);
int selection = 0;
String defaultFormat = sharedpreferences.getString(context.getString(R.string.SET_POST_FORMAT) + account.user_id + account.instance, "text/plain");
for (String format : formatArr) {
if (statusDraft.content_type != null && statusDraft.content_type.equalsIgnoreCase(format)) {
break;
} else if (statusDraft.content_type == null && defaultFormat.equalsIgnoreCase(format)) {
break;
}
selection++;
}
builder.setSingleChoiceItems(formatArr, selection, null);
builder.setPositiveButton(R.string.validate, (dialog, which) -> {
int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
statusDraft.content_type = formatArr[selectedPosition];
notifyItemChanged(holder.getLayoutPosition());
dialog.dismiss();
});
builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builder.create().show();
});
} else {
holder.binding.buttonTextFormat.setVisibility(View.GONE);
}
holder.binding.buttonEmojiOne.setOnClickListener(v -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(holder.binding.buttonEmojiOne.getWindowToken(), 0);

View file

@ -17,6 +17,7 @@ package app.fedilab.android.ui.fragment.settings;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@ -24,6 +25,7 @@ import androidx.preference.SwitchPreferenceCompat;
import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.helper.Helper;
public class FragmentExtraFeaturesSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -55,6 +57,13 @@ public class FragmentExtraFeaturesSettings extends PreferenceFragmentCompat impl
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false);
SET_DISPLAY_TRANSLATE.setChecked(checked);
}
ListPreference SET_POST_FORMAT = findPreference(getString(R.string.SET_POST_FORMAT));
if (SET_POST_FORMAT != null) {
SET_POST_FORMAT.getContext().setTheme(Helper.dialogStyle());
String format = sharedpreferences.getString(getString(R.string.SET_POST_FORMAT) + MainActivity.currentUserID + MainActivity.currentInstance, "text/plain");
SET_POST_FORMAT.setValue(format);
}
}
@Override
@ -80,6 +89,12 @@ public class FragmentExtraFeaturesSettings extends PreferenceFragmentCompat impl
editor.putBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_TRANSLATE.isChecked());
}
}
if (key.compareToIgnoreCase(getString(R.string.SET_POST_FORMAT)) == 0) {
ListPreference SET_POST_FORMAT = findPreference(getString(R.string.SET_POST_FORMAT));
if (SET_POST_FORMAT != null) {
editor.putString(getString(R.string.SET_POST_FORMAT) + MainActivity.currentUserID + MainActivity.currentInstance, SET_POST_FORMAT.getValue());
}
}
editor.apply();
}
}

View file

@ -187,12 +187,13 @@ public class StatusesVM extends AndroidViewModel {
String spoiler_text,
String visibility,
String language,
String quote_id) {
String quote_id,
String content_type) {
MastodonStatusesService mastodonStatusesService = init(instance);
statusMutableLiveData = new MutableLiveData<>();
new Thread(() -> {
Call<Status> statusCall = mastodonStatusesService.createStatus(idempotency_Key, token, text, media_ids, poll_options, poll_expire_in,
poll_multiple, poll_hide_totals, in_reply_to_id, sensitive, spoiler_text, visibility, language, quote_id);
poll_multiple, poll_hide_totals, in_reply_to_id, sensitive, spoiler_text, visibility, language, quote_id, content_type);
Status status = null;
if (statusCall != null) {
try {

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M9,4v3h5v12h3L17,7h5L22,4L9,4zM3,12h3v7h3v-7h3L12,9L3,9v3z" />
</vector>

View file

@ -91,6 +91,18 @@
app:layout_constraintTop_toBottomOf="@id/button_emoji"
tools:visibility="visible" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button_text_format"
style="@style/Fedilab.SmallIconButton"
android:layout_marginEnd="6dp"
android:contentDescription="@string/post_format"
android:visibility="gone"
app:icon="@drawable/ic_baseline_format_size_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_emoji_one"
tools:visibility="visible" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/sensitive_media"
android:layout_width="0dp"

View file

@ -761,6 +761,15 @@
<item>BrainCrash</item>
<item>Mastalab</item>
</string-array>
<string-array name="SET_POST_FORMAT" translatable="false">
<item>text/plain</item>
<item>text/html</item>
<item>text/markdown</item>
<item>text/bbcode</item>
<item>text/x.misskeymarkdown</item>
</string-array>
<string-array name="set_load_media_type_value">
<item>Always</item>
<item>Wifi only</item>
@ -1420,6 +1429,8 @@
<string name="SET_NOTIF_VALIDATION" translatable="false">SET_NOTIF_VALIDATION</string>
<string name="SET_DISPLAY_BOOKMARK" translatable="false">SET_DISPLAY_BOOKMARK</string>
<string name="SET_DISPLAY_TRANSLATE" translatable="false">SET_DISPLAY_TRANSLATE</string>
<string name="SET_POST_FORMAT" translatable="false">SET_POST_FORMAT</string>
<string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string>
<string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string>
@ -2154,4 +2165,6 @@
<string name="set_extand_extra_features">By enabling that option the app will display extra features. This feature is done for social softwares like Pleroma, Akkoma or Glitch Social</string>
<string name="icons_visibility">Icons visibility</string>
<string name="icons_visibility_summary">You can safely hide these icons at the bottom to have more space. They are also in the submenu.</string>
<string name="post_format">Post format</string>
<string name="set_post_format">Post format</string>
</resources>

View file

@ -28,4 +28,16 @@
app:title="@string/set_display_translate_indication" />
</app.fedilab.android.helper.settings.LongSummaryPreferenceCategory>
<ListPreference
app:defaultValue="text/plain"
app:dependency="@string/SET_EXTAND_EXTRA_FEATURES"
app:dialogTitle="@string/post_format"
app:entries="@array/SET_POST_FORMAT"
app:entryValues="@array/SET_POST_FORMAT"
app:iconSpaceReserved="false"
app:key="@string/SET_POST_FORMAT"
app:summary="@string/change_logo_description"
app:title="@string/set_post_format"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>