CW in compose
This commit is contained in:
parent
938a6b6c78
commit
b2588fbb6e
|
@ -7,6 +7,7 @@ import android.content.ClipData;
|
|||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.icu.text.BreakIterator;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
@ -54,6 +55,7 @@ import org.joinmastodon.android.model.Status;
|
|||
import org.joinmastodon.android.ui.CustomEmojiPopupKeyboard;
|
||||
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
|
||||
import org.joinmastodon.android.ui.PopupKeyboard;
|
||||
import org.joinmastodon.android.ui.drawables.SpoilerStripesDrawable;
|
||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
||||
import org.joinmastodon.android.ui.utils.SimpleTextWatcher;
|
||||
import org.joinmastodon.android.ui.views.ReorderableLinearLayout;
|
||||
|
@ -132,6 +134,8 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
|
|||
private String uuid;
|
||||
private int pollDuration=24*3600;
|
||||
private String pollDurationStr;
|
||||
private EditText spoilerEdit;
|
||||
private boolean hasSpoiler;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
|
@ -191,6 +195,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
|
|||
mediaBtn.setOnClickListener(v->openFilePicker());
|
||||
pollBtn.setOnClickListener(v->togglePoll());
|
||||
emojiBtn.setOnClickListener(v->emojiKeyboard.toggleKeyboardPopup(mainEditText));
|
||||
spoilerBtn.setOnClickListener(v->toggleSpoiler());
|
||||
emojiKeyboard.setOnIconChangedListener(new PopupKeyboard.OnIconChangeListener(){
|
||||
@Override
|
||||
public void onIconChanged(int icon){
|
||||
|
@ -230,6 +235,15 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
|
|||
pollDurationView.setText(getString(R.string.compose_poll_duration, pollDurationStr=getResources().getQuantityString(R.plurals.x_days, 1, 1)));
|
||||
}
|
||||
|
||||
spoilerEdit=view.findViewById(R.id.content_warning);
|
||||
LayerDrawable spoilerBg=(LayerDrawable) spoilerEdit.getBackground();
|
||||
spoilerBg.setDrawableByLayerId(R.id.left_drawable, new SpoilerStripesDrawable());
|
||||
spoilerBg.setDrawableByLayerId(R.id.right_drawable, new SpoilerStripesDrawable());
|
||||
if((savedInstanceState!=null && savedInstanceState.getBoolean("hasSpoiler", false)) || hasSpoiler){
|
||||
spoilerEdit.setVisibility(View.VISIBLE);
|
||||
spoilerBtn.setSelected(true);
|
||||
}
|
||||
|
||||
// TODO save and restore media attachments (when design is ready)
|
||||
|
||||
return view;
|
||||
|
@ -246,6 +260,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
|
|||
outState.putStringArrayList("pollOptions", opts);
|
||||
outState.putInt("pollDuration", pollDuration);
|
||||
outState.putString("pollDurationStr", pollDurationStr);
|
||||
outState.putBoolean("hasSpoiler", hasSpoiler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,6 +412,9 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
|
|||
for(DraftPollOption opt:pollOptions)
|
||||
req.poll.options.add(opt.edit.getText().toString());
|
||||
}
|
||||
if(hasSpoiler && spoilerEdit.length()>0){
|
||||
req.spoilerText=spoilerEdit.getText().toString();
|
||||
}
|
||||
if(uuid==null)
|
||||
uuid=UUID.randomUUID().toString();
|
||||
ProgressDialog progress=new ProgressDialog(getActivity());
|
||||
|
@ -648,6 +666,20 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
|
|||
menu.show();
|
||||
}
|
||||
|
||||
private void toggleSpoiler(){
|
||||
hasSpoiler=!hasSpoiler;
|
||||
if(hasSpoiler){
|
||||
spoilerEdit.setVisibility(View.VISIBLE);
|
||||
spoilerBtn.setSelected(true);
|
||||
spoilerEdit.requestFocus();
|
||||
}else{
|
||||
spoilerEdit.setVisibility(View.GONE);
|
||||
spoilerEdit.setText("");
|
||||
spoilerBtn.setSelected(false);
|
||||
mainEditText.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
private static class DraftMediaAttachment{
|
||||
public Attachment serverAttachment;
|
||||
public Uri uri;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package org.joinmastodon.android.ui.drawables;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import org.joinmastodon.android.MastodonApp;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class SpoilerStripesDrawable extends Drawable{
|
||||
private Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
public SpoilerStripesDrawable(){
|
||||
paint.setColor(0xff000000);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas){
|
||||
Rect bounds=getBounds();
|
||||
canvas.save();
|
||||
canvas.translate(bounds.left, bounds.top);
|
||||
canvas.clipRect(0, 0, bounds.width(), bounds.height());
|
||||
float scale=MastodonApp.context.getResources().getDisplayMetrics().density;
|
||||
canvas.scale(scale, scale, 0, 0);
|
||||
|
||||
float height=bounds.height()/scale;
|
||||
float y1=6.80133f;
|
||||
float y2=-1.22874f;
|
||||
while(y2<height){
|
||||
canvas.drawLine(-0.860365f, y1, 10.6078f, y2, paint);
|
||||
y1+=8.03007f;
|
||||
y2+=8.03007f;
|
||||
}
|
||||
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(@Nullable ColorFilter colorFilter){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity(){
|
||||
return PixelFormat.TRANSLUCENT;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<color android:color="?colorSearchField"/>
|
||||
</item>
|
||||
<item android:gravity="left" android:width="8dp">
|
||||
<shape>
|
||||
<gradient android:type="linear" android:angle="270" android:startColor="#FEC84B" android:endColor="#F79009"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@+id/left_drawable" android:width="8dp" android:gravity="left">
|
||||
<color android:color="#0f0"/>
|
||||
</item>
|
||||
<item android:gravity="right" android:width="8dp">
|
||||
<shape>
|
||||
<gradient android:type="linear" android:angle="270" android:startColor="#FEC84B" android:endColor="#F79009"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@+id/right_drawable" android:width="8dp" android:gravity="right">
|
||||
<color android:color="#0f0"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -16,6 +16,20 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/content_warning"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:elevation="0dp"
|
||||
android:hint="@string/content_warning"
|
||||
android:inputType="textMultiLine|textCapSentences"
|
||||
android:visibility="gone"
|
||||
android:textColorHint="?android:textColorSecondary"
|
||||
android:background="@drawable/bg_cw_edit"
|
||||
android:padding="16dp"
|
||||
android:minHeight="56dp"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reply_text"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -204,4 +204,5 @@
|
|||
<string name="open_email_app">Open email app</string>
|
||||
<string name="resent_email">Confirmation email sent</string>
|
||||
<string name="compose_hint">Type or paste what\'s on your mind</string>
|
||||
<string name="content_warning">Content warning</string>
|
||||
</resources>
|
Loading…
Reference in New Issue