move compose action to layout file
This commit is contained in:
parent
f0a704b93b
commit
676e166459
|
@ -22,6 +22,7 @@ import android.graphics.PixelFormat;
|
||||||
import android.graphics.RenderEffect;
|
import android.graphics.RenderEffect;
|
||||||
import android.graphics.Shader;
|
import android.graphics.Shader;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.graphics.drawable.InsetDrawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.icu.text.BreakIterator;
|
import android.icu.text.BreakIterator;
|
||||||
import android.media.MediaMetadataRetriever;
|
import android.media.MediaMetadataRetriever;
|
||||||
|
@ -38,6 +39,7 @@ import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -167,7 +169,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||||
private String accountID;
|
private String accountID;
|
||||||
private int charCount, charLimit, trimmedCharCount;
|
private int charCount, charLimit, trimmedCharCount;
|
||||||
|
|
||||||
private Button publishButton, languageButton, scheduleTimeBtn;
|
private Button publishButton, languageButton, scheduleTimeBtn, draftsBtn;
|
||||||
private PopupMenu languagePopup, visibilityPopup, moreOptionsPopup;
|
private PopupMenu languagePopup, visibilityPopup, moreOptionsPopup;
|
||||||
private ImageButton mediaBtn, pollBtn, emojiBtn, spoilerBtn, visibilityBtn, moreBtn, scheduleDraftDismiss;
|
private ImageButton mediaBtn, pollBtn, emojiBtn, spoilerBtn, visibilityBtn, moreBtn, scheduleDraftDismiss;
|
||||||
private ImageView sensitiveIcon;
|
private ImageView sensitiveIcon;
|
||||||
|
@ -679,40 +681,32 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
|
||||||
publishButton=new Button(getActivity());
|
|
||||||
resetPublishButtonText();
|
|
||||||
publishButton.setSingleLine();
|
|
||||||
publishButton.setEllipsize(TextUtils.TruncateAt.END);
|
|
||||||
publishButton.setOnClickListener(this::onPublishClick);
|
|
||||||
LinearLayout wrap=new LinearLayout(getActivity());
|
|
||||||
wrap.setOrientation(LinearLayout.HORIZONTAL);
|
|
||||||
|
|
||||||
sendProgress=new ProgressBar(getActivity());
|
|
||||||
LinearLayout.LayoutParams progressLP=new LinearLayout.LayoutParams(V.dp(24), V.dp(24));
|
|
||||||
progressLP.setMarginEnd(V.dp(16));
|
|
||||||
progressLP.gravity=Gravity.CENTER_VERTICAL;
|
|
||||||
wrap.addView(sendProgress, progressLP);
|
|
||||||
|
|
||||||
sendError=new ImageView(getActivity());
|
|
||||||
sendError.setImageResource(R.drawable.ic_fluent_error_circle_24_regular);
|
|
||||||
sendError.setImageTintList(getResources().getColorStateList(R.color.error_600));
|
|
||||||
sendError.setScaleType(ImageView.ScaleType.CENTER);
|
|
||||||
wrap.addView(sendError, progressLP);
|
|
||||||
|
|
||||||
sendError.setVisibility(View.GONE);
|
|
||||||
sendProgress.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
LinearLayout.LayoutParams langParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
langParams.setMarginEnd(V.dp(8));
|
|
||||||
wrap.addView(buildLanguageSelector(), langParams);
|
|
||||||
|
|
||||||
wrap.addView(publishButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
||||||
wrap.setPadding(V.dp(16), V.dp(4), V.dp(16), V.dp(8));
|
|
||||||
wrap.setClipToPadding(false);
|
|
||||||
MenuItem item=menu.add(editingStatus==null ? R.string.publish : R.string.save);
|
MenuItem item=menu.add(editingStatus==null ? R.string.publish : R.string.save);
|
||||||
|
LinearLayout wrap=new LinearLayout(getActivity());
|
||||||
|
getActivity().getLayoutInflater().inflate(R.layout.compose_action, wrap);
|
||||||
item.setActionView(wrap);
|
item.setActionView(wrap);
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||||
|
|
||||||
|
publishButton = wrap.findViewById(R.id.publish_btn);
|
||||||
|
draftsBtn = wrap.findViewById(R.id.drafts_btn);
|
||||||
|
languageButton = wrap.findViewById(R.id.language_btn);
|
||||||
|
sendProgress = wrap.findViewById(R.id.send_progress);
|
||||||
|
sendError = wrap.findViewById(R.id.send_error);
|
||||||
|
|
||||||
|
publishButton.setOnClickListener(this::onPublishClick);
|
||||||
|
draftsBtn.setOnClickListener(this::onDraftsClick);
|
||||||
updatePublishButtonState();
|
updatePublishButtonState();
|
||||||
|
buildLanguageSelector(languageButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDraftsClick(View v) {
|
||||||
|
Bundle args=new Bundle();
|
||||||
|
args.putString("account", accountID);
|
||||||
|
InputMethodManager imm=getActivity().getSystemService(InputMethodManager.class);
|
||||||
|
imm.hideSoftInputFromWindow(draftsBtn.getWindowToken(), 0);
|
||||||
|
Nav.go(getActivity(), ScheduledStatusListFragment.class, args);
|
||||||
|
// TODO: figure out a better way to handle the back stack
|
||||||
|
// if (!hasDraft()) content.postDelayed(()->Nav.finish(this), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLanguage(String lang) {
|
private void updateLanguage(String lang) {
|
||||||
|
@ -726,18 +720,10 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private Button buildLanguageSelector() {
|
private void buildLanguageSelector(Button btn) {
|
||||||
languageButton=new Button(getActivity());
|
|
||||||
languageButton.setTextColor(UiUtils.getThemeColor(getActivity(), android.R.attr.textColorSecondary));
|
|
||||||
languageButton.setBackground(getActivity().getDrawable(R.drawable.bg_text_button));
|
|
||||||
languageButton.setPadding(V.dp(8), 0, V.dp(8), 0);
|
|
||||||
languageButton.setCompoundDrawablesRelativeWithIntrinsicBounds(getActivity().getDrawable(R.drawable.ic_fluent_local_language_16_regular), null, null, null);
|
|
||||||
languageButton.setCompoundDrawableTintList(languageButton.getTextColors());
|
|
||||||
languageButton.setCompoundDrawablePadding(V.dp(6));
|
|
||||||
|
|
||||||
languagePopup=new PopupMenu(getActivity(), languageButton);
|
languagePopup=new PopupMenu(getActivity(), languageButton);
|
||||||
languageButton.setOnTouchListener(languagePopup.getDragToOpenListener());
|
btn.setOnTouchListener(languagePopup.getDragToOpenListener());
|
||||||
languageButton.setOnClickListener(v->languagePopup.show());
|
btn.setOnClickListener(v->languagePopup.show());
|
||||||
|
|
||||||
Preferences prefs = AccountSessionManager.getInstance().getAccount(accountID).preferences;
|
Preferences prefs = AccountSessionManager.getInstance().getAccount(accountID).preferences;
|
||||||
updateLanguage(prefs != null && prefs.postingDefaultLanguage != null && prefs.postingDefaultLanguage.length() > 0
|
updateLanguage(prefs != null && prefs.postingDefaultLanguage != null && prefs.postingDefaultLanguage.length() > 0
|
||||||
|
@ -761,8 +747,6 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||||
updateLanguage(allLanguages.get(i.getItemId()));
|
updateLanguage(allLanguages.get(i.getItemId()));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return languageButton;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -835,25 +819,6 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||||
@Override
|
@Override
|
||||||
protected void updateToolbar(){
|
protected void updateToolbar(){
|
||||||
super.updateToolbar();
|
super.updateToolbar();
|
||||||
if (replyTo != null || hasDraft()) return;
|
|
||||||
Button draftsBtn=new Button(getActivity());
|
|
||||||
draftsBtn.setTextColor(UiUtils.getThemeColor(getActivity(), android.R.attr.textColorSecondary));
|
|
||||||
draftsBtn.setBackground(getActivity().getDrawable(R.drawable.bg_text_button));
|
|
||||||
draftsBtn.setPadding(V.dp(8), 0, V.dp(8), 0);
|
|
||||||
draftsBtn.setCompoundDrawablesRelativeWithIntrinsicBounds(getActivity().getDrawable(R.drawable.ic_fluent_drafts_20_regular), null, null, null);
|
|
||||||
draftsBtn.setCompoundDrawableTintList(draftsBtn.getTextColors());
|
|
||||||
draftsBtn.setContentDescription(getString(R.string.sk_unsent_posts));
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) draftsBtn.setTooltipText(getString(R.string.sk_unsent_posts));
|
|
||||||
draftsBtn.setOnClickListener(v->{
|
|
||||||
Bundle args=new Bundle();
|
|
||||||
args.putString("account", accountID);
|
|
||||||
InputMethodManager imm=getActivity().getSystemService(InputMethodManager.class);
|
|
||||||
imm.hideSoftInputFromWindow(draftsBtn.getWindowToken(), 0);
|
|
||||||
Nav.go(getActivity(), ScheduledStatusListFragment.class, args);
|
|
||||||
// TODO: figure out a better way to handle the back stack
|
|
||||||
// if (!hasDraft()) content.postDelayed(()->Nav.finish(this), 200);
|
|
||||||
});
|
|
||||||
getToolbar().addView(draftsBtn);
|
|
||||||
getToolbar().setNavigationIcon(R.drawable.ic_fluent_dismiss_24_regular);
|
getToolbar().setNavigationIcon(R.drawable.ic_fluent_dismiss_24_regular);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1581,13 +1546,17 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||||
if (scheduledAt.isAfter(DRAFTS_AFTER_INSTANT)) {
|
if (scheduledAt.isAfter(DRAFTS_AFTER_INSTANT)) {
|
||||||
scheduleTimeBtn.setVisibility(View.GONE);
|
scheduleTimeBtn.setVisibility(View.GONE);
|
||||||
scheduleDraftText.setText(R.string.sk_compose_draft);
|
scheduleDraftText.setText(R.string.sk_compose_draft);
|
||||||
publishButton.setText(scheduledStatus != null ? R.string.save : R.string.sk_draft);
|
scheduleDraftText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_fluent_drafts_20_regular, 0, 0, 0);
|
||||||
|
publishButton.setText(scheduledStatus != null && scheduledStatus.scheduledAt.isAfter(DRAFTS_AFTER_INSTANT)
|
||||||
|
? R.string.save : R.string.sk_draft);
|
||||||
} else {
|
} else {
|
||||||
String at = scheduledAt.atZone(ZoneId.systemDefault()).format(formatter);
|
String at = scheduledAt.atZone(ZoneId.systemDefault()).format(formatter);
|
||||||
scheduleTimeBtn.setVisibility(View.VISIBLE);
|
scheduleTimeBtn.setVisibility(View.VISIBLE);
|
||||||
scheduleTimeBtn.setText(at);
|
scheduleTimeBtn.setText(at);
|
||||||
scheduleDraftText.setText(R.string.sk_compose_scheduled);
|
scheduleDraftText.setText(R.string.sk_compose_scheduled);
|
||||||
publishButton.setText(scheduledStatus != null ? R.string.save : R.string.sk_schedule);
|
scheduleDraftText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||||
|
publishButton.setText(scheduledStatus != null && scheduledStatus.scheduledAt.equals(scheduledAt)
|
||||||
|
? R.string.save : R.string.sk_schedule);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resetPublishButtonText();
|
resetPublishButtonText();
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/send_progress"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/send_error"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:src="@drawable/ic_fluent_error_circle_24_regular"
|
||||||
|
android:tint="@color/error_600"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/language_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:paddingHorizontal="8dp"
|
||||||
|
android:drawableStart="@drawable/ic_fluent_local_language_16_regular"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:drawableTint="?android:textColorSecondary"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:background="@drawable/bg_text_button" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/drafts_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:paddingHorizontal="8dp"
|
||||||
|
android:drawableStart="@drawable/ic_fluent_drafts_20_regular"
|
||||||
|
android:drawableTint="?android:textColorSecondary"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:background="@drawable/bg_text_button"
|
||||||
|
android:contentDescription="@string/sk_unsent_posts"
|
||||||
|
android:tooltipText="@string/sk_unsent_posts" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/publish_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:ellipsize="end" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -247,10 +247,18 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/schedule_draft_text"
|
android:id="@+id/schedule_draft_text"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:drawableStart="@drawable/ic_fluent_drafts_20_regular"
|
||||||
|
android:drawableTint="?android:textColorSecondary"
|
||||||
|
android:drawablePadding="16dp"
|
||||||
android:text="@string/sk_compose_draft" />
|
android:text="@string/sk_compose_draft" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/scheduled_time_btn"
|
android:id="@+id/scheduled_time_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -259,7 +267,7 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:minHeight="48dp"
|
android:minHeight="40dp"
|
||||||
android:textColor="?android:textColorSecondary"
|
android:textColor="?android:textColorSecondary"
|
||||||
android:background="@drawable/bg_text_button"
|
android:background="@drawable/bg_text_button"
|
||||||
android:fontFamily="sans-serif"
|
android:fontFamily="sans-serif"
|
||||||
|
@ -349,11 +357,6 @@
|
||||||
android:tooltipText="@string/post_visibility"
|
android:tooltipText="@string/post_visibility"
|
||||||
android:src="@drawable/ic_fluent_earth_24_regular"/>
|
android:src="@drawable/ic_fluent_earth_24_regular"/>
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="0px"
|
|
||||||
android:layout_height="1px"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/btn_more"
|
android:id="@+id/btn_more"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
|
@ -367,6 +370,11 @@
|
||||||
android:tooltipText="@string/more_options"
|
android:tooltipText="@string/more_options"
|
||||||
android:src="@drawable/ic_fluent_more_vertical_24_regular"/>
|
android:src="@drawable/ic_fluent_more_vertical_24_regular"/>
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="0px"
|
||||||
|
android:layout_height="1px"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/char_counter"
|
android:id="@+id/char_counter"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -374,7 +382,6 @@
|
||||||
android:textAppearance="@style/m3_body_large"
|
android:textAppearance="@style/m3_body_large"
|
||||||
android:textColor="?android:textColorSecondary"
|
android:textColor="?android:textColorSecondary"
|
||||||
tools:text="500"/>
|
tools:text="500"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue