Adding a whole lot of stuff

This commit is contained in:
sk 2022-12-30 15:24:30 -03:00 committed by LucasGGamerM
parent fe3052a359
commit 519894a461
3 changed files with 116 additions and 95 deletions

View File

@ -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;
@ -259,8 +261,6 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
charLimit=instance.configuration.statuses.maxCharacters; charLimit=instance.configuration.statuses.maxCharacters;
else else
charLimit=500; charLimit=500;
if (editingStatus == null) loadDefaultStatusVisibility(savedInstanceState);
} }
@Override @Override
@ -326,15 +326,6 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
sensitiveItem=view.findViewById(R.id.sensitive_item); sensitiveItem=view.findViewById(R.id.sensitive_item);
replyText=view.findViewById(R.id.reply_text); replyText=view.findViewById(R.id.reply_text);
if(GlobalUserPreferences.relocatePublishButton){
publishButton=view.findViewById(R.id.publish);
// publishButton.setText(editingStatus==null || redraftStatus ? R.string.publish : R.string.save);
publishButton.setEllipsize(TextUtils.TruncateAt.END);
publishButton.setOnClickListener(this::onPublishClick);
publishButton.setSingleLine(true);
publishButton.setVisibility(View.VISIBLE);
}
mediaBtn.setOnClickListener(v->openFilePicker()); mediaBtn.setOnClickListener(v->openFilePicker());
pollBtn.setOnClickListener(v->togglePoll()); pollBtn.setOnClickListener(v->togglePoll());
emojiBtn.setOnClickListener(v->emojiKeyboard.toggleKeyboardPopup(mainEditText)); emojiBtn.setOnClickListener(v->emojiKeyboard.toggleKeyboardPopup(mainEditText));
@ -680,6 +671,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
} }
updateSensitive(); updateSensitive();
updateScheduledAt(scheduledAt != null ? scheduledAt : scheduledStatus != null ? scheduledStatus.scheduledAt : null);
if(editingStatus!=null){ if(editingStatus!=null){
updateCharCounter(); updateCharCounter();
@ -689,45 +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){
if(!GlobalUserPreferences.relocatePublishButton){
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);
if(!GlobalUserPreferences.relocatePublishButton){
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) {
@ -741,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
@ -776,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
@ -816,13 +785,11 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
private void resetPublishButtonText() { private void resetPublishButtonText() {
int publishText = editingStatus==null || redraftStatus ? R.string.publish : R.string.save; int publishText = editingStatus==null || redraftStatus ? R.string.publish : R.string.save;
// if (publishText == R.string.publish && !GlobalUserPreferences.publishButtonText.isEmpty()) { if (publishText == R.string.publish && !GlobalUserPreferences.publishButtonText.isEmpty()) {
// publishButton.setText(GlobalUserPreferences.publishButtonText); publishButton.setText(GlobalUserPreferences.publishButtonText);
// } else { } else {
if(!GlobalUserPreferences.relocatePublishButton){
publishButton.setText(publishText); publishButton.setText(publishText);
} }
// }
} }
private void updatePublishButtonState(){ private void updatePublishButtonState(){
@ -852,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);
} }
@ -1598,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();

View File

@ -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>

View File

@ -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"
@ -288,7 +296,7 @@
android:id="@+id/btn_media" android:id="@+id/btn_media"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="0px" android:padding="0px"
android:tint="@color/compose_button" android:tint="@color/compose_button"
@ -301,7 +309,7 @@
android:id="@+id/btn_poll" android:id="@+id/btn_poll"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="0px" android:padding="0px"
android:tint="@color/compose_button" android:tint="@color/compose_button"
@ -314,7 +322,7 @@
android:id="@+id/btn_emoji" android:id="@+id/btn_emoji"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="0px" android:padding="0px"
android:tint="@color/compose_button" android:tint="@color/compose_button"
@ -327,7 +335,7 @@
android:id="@+id/btn_spoiler" android:id="@+id/btn_spoiler"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="0px" android:padding="0px"
android:tint="@color/compose_button" android:tint="@color/compose_button"
@ -340,7 +348,7 @@
android:id="@+id/btn_visibility" android:id="@+id/btn_visibility"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="0px" android:padding="0px"
android:tint="@color/compose_button" android:tint="@color/compose_button"
@ -386,7 +394,6 @@
/> />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</org.joinmastodon.android.ui.views.SizeListenerLinearLayout> </org.joinmastodon.android.ui.views.SizeListenerLinearLayout>