Commit e5c4efb4 authored by Thomas's avatar Thomas
Browse files

comment #702 - Allow to format the text when composing

parent 2164c2fe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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")
+2 −0
Original line number Diff line number Diff line
@@ -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")
+1 −1
Original line number Diff line number Diff line
@@ -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);
+33 −0
Original line number Diff line number Diff line
@@ -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);
+15 −0
Original line number Diff line number Diff line
@@ -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();
        }
    }
Loading