display original post when replying

closes sk22#193
This commit is contained in:
sk 2022-12-31 01:33:37 +01:00 committed by LucasGGamerM
parent ff15bdeaea
commit 247669644c
3 changed files with 272 additions and 194 deletions

View File

@ -59,6 +59,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -107,6 +108,7 @@ import org.joinmastodon.android.ui.utils.TransferSpeedTracker;
import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.ui.views.ComposeEditText; import org.joinmastodon.android.ui.views.ComposeEditText;
import org.joinmastodon.android.ui.views.ComposeMediaLayout; import org.joinmastodon.android.ui.views.ComposeMediaLayout;
import org.joinmastodon.android.ui.views.LinkedTextView;
import org.joinmastodon.android.ui.views.ReorderableLinearLayout; import org.joinmastodon.android.ui.views.ReorderableLinearLayout;
import org.joinmastodon.android.ui.views.SizeListenerLinearLayout; import org.joinmastodon.android.ui.views.SizeListenerLinearLayout;
import org.joinmastodon.android.utils.MastodonLanguage; import org.joinmastodon.android.utils.MastodonLanguage;
@ -180,6 +182,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
private View sensitiveItem; private View sensitiveItem;
private View pollAllowMultipleItem; private View pollAllowMultipleItem;
private View scheduleDraftView; private View scheduleDraftView;
private ScrollView scrollView;
private boolean initiallyScrolled = false;
private TextView scheduleDraftText; private TextView scheduleDraftText;
private CheckBox pollAllowMultipleCheckbox; private CheckBox pollAllowMultipleCheckbox;
private TextView pollDurationView; private TextView pollDurationView;
@ -295,10 +299,11 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
mainEditTextWrap=view.findViewById(R.id.toot_text_wrap); mainEditTextWrap=view.findViewById(R.id.toot_text_wrap);
charCounter=view.findViewById(R.id.char_counter); charCounter=view.findViewById(R.id.char_counter);
charCounter.setText(String.valueOf(charLimit)); charCounter.setText(String.valueOf(charLimit));
scrollView=view.findViewById(R.id.scroll_view);
selfName=view.findViewById(R.id.name); selfName=view.findViewById(R.id.self_name);
selfUsername=view.findViewById(R.id.username); selfUsername=view.findViewById(R.id.self_username);
selfAvatar=view.findViewById(R.id.avatar); selfAvatar=view.findViewById(R.id.self_avatar);
HtmlParser.setTextWithCustomEmoji(selfName, self.displayName, self.emojis); HtmlParser.setTextWithCustomEmoji(selfName, self.displayName, self.emojis);
selfUsername.setText('@'+self.username+'@'+instanceDomain); selfUsername.setText('@'+self.username+'@'+instanceDomain);
ViewImageLoader.load(selfAvatar, null, new UrlImageLoaderRequest(self.avatar)); ViewImageLoader.load(selfAvatar, null, new UrlImageLoaderRequest(self.avatar));
@ -559,6 +564,71 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
}); });
spoilerEdit.addTextChangedListener(new SimpleTextWatcher(e->updateCharCounter())); spoilerEdit.addTextChangedListener(new SimpleTextWatcher(e->updateCharCounter()));
if(replyTo!=null){ if(replyTo!=null){
View replyWrap = view.findViewById(R.id.reply_wrap);
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
int scrollHeight = scrollView.getHeight();
if (replyWrap.getMinimumHeight() != scrollHeight) {
replyWrap.setMinimumHeight(scrollHeight);
if (!initiallyScrolled) {
initiallyScrolled = true;
scrollView.post(() -> {
int bottom = scrollView.getChildAt(0).getBottom();
int sy = scrollView.getScrollY();
int sh = scrollView.getHeight();
scrollView.scrollBy(0, bottom - (sy + sh));
});
}
}
});
View originalPost = view.findViewById(R.id.original_post);
originalPost.setVisibility(View.VISIBLE);
originalPost.setOnClickListener(v->{
Bundle args=new Bundle();
args.putString("account", accountID);
args.putParcelable("status", Parcels.wrap(replyTo));
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
Nav.go(getActivity(), ThreadFragment.class, args);
});
ImageView avatar = view.findViewById(R.id.avatar);
ViewImageLoader.load(avatar, null, new UrlImageLoaderRequest(replyTo.account.avatar));
ViewOutlineProvider roundCornersOutline=new ViewOutlineProvider(){
@Override
public void getOutline(View view, Outline outline){
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), V.dp(12));
}
};
avatar.setOutlineProvider(roundCornersOutline);
avatar.setClipToOutline(true);
avatar.setOnClickListener(v->{
Bundle args=new Bundle();
args.putString("account", accountID);
args.putParcelable("profileAccount", Parcels.wrap(replyTo.account));
Nav.go(getActivity(), ProfileFragment.class, args);
});
((TextView) view.findViewById(R.id.name)).setText(replyTo.account.displayName);
((TextView) view.findViewById(R.id.username)).setText(replyTo.account.getDisplayUsername());
view.findViewById(R.id.visibility).setVisibility(View.GONE);
Drawable visibilityIcon = getActivity().getDrawable(switch(replyTo.visibility){
case PUBLIC -> R.drawable.ic_fluent_earth_20_regular;
case UNLISTED -> R.drawable.ic_fluent_people_community_20_regular;
case PRIVATE -> R.drawable.ic_fluent_people_checkmark_20_regular;
case DIRECT -> R.drawable.ic_fluent_mention_20_regular;
});
ImageView moreBtn = view.findViewById(R.id.more);
moreBtn.setImageDrawable(visibilityIcon);
moreBtn.setBackground(null);
TextView timestamp = view.findViewById(R.id.timestamp);
if (replyTo.editedAt==null) timestamp.setText(UiUtils.formatRelativeTimestamp(getContext(), replyTo.createdAt));
else timestamp.setText(getString(R.string.edited_timestamp, UiUtils.formatRelativeTimestamp(getContext(), replyTo.editedAt)));
if (replyTo.spoilerText != null && !replyTo.spoilerText.isBlank()) {
view.findViewById(R.id.spoiler_header).setVisibility(View.VISIBLE);
((TextView) view.findViewById(R.id.spoiler_title_inline)).setText(replyTo.spoilerText);
}
((LinkedTextView) view.findViewById(R.id.text)).setText(HtmlParser.parse(replyTo.content, replyTo.emojis, replyTo.mentions, replyTo.tags, accountID));
replyText.setText(getString(R.string.in_reply_to, replyTo.account.displayName)); replyText.setText(getString(R.string.in_reply_to, replyTo.account.displayName));
int visibilityNameRes = switch (replyTo.visibility) { int visibilityNameRes = switch (replyTo.visibility) {
case PUBLIC -> R.string.visibility_public; case PUBLIC -> R.string.visibility_public;
@ -567,24 +637,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
case DIRECT -> R.string.visibility_private; case DIRECT -> R.string.visibility_private;
}; };
replyText.setContentDescription(getString(R.string.in_reply_to, replyTo.account.displayName) + ". " + getString(R.string.post_visibility) + ": " + getString(visibilityNameRes)); replyText.setContentDescription(getString(R.string.in_reply_to, replyTo.account.displayName) + ". " + getString(R.string.post_visibility) + ": " + getString(visibilityNameRes));
Drawable visibilityIcon = getActivity().getDrawable(switch(replyTo.visibility){
case PUBLIC -> R.drawable.ic_fluent_earth_20_regular;
case UNLISTED -> R.drawable.ic_fluent_people_community_20_regular;
case PRIVATE -> R.drawable.ic_fluent_people_checkmark_20_regular;
case DIRECT -> R.drawable.ic_fluent_mention_20_regular;
});
visibilityIcon.setBounds(0, 0, V.dp(20), V.dp(20));
Drawable replyArrow = getActivity().getDrawable(R.drawable.ic_fluent_arrow_reply_20_filled);
replyArrow.setBounds(0, 0, V.dp(20), V.dp(20));
replyText.setCompoundDrawables(replyArrow, null, visibilityIcon, null);
replyText.setOnClickListener(v->{
Bundle args=new Bundle();
args.putString("account", accountID);
args.putParcelable("status", Parcels.wrap(replyTo));
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
Nav.go(getActivity(), ThreadFragment.class, args);
});
ArrayList<String> mentions=new ArrayList<>(); ArrayList<String> mentions=new ArrayList<>();
String ownID=AccountSessionManager.getInstance().getAccount(accountID).self.id; String ownID=AccountSessionManager.getInstance().getAccount(accountID).self.id;
if(!replyTo.account.id.equals(ownID)) if(!replyTo.account.id.equals(ownID))

View File

@ -56,7 +56,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:gravity="center_vertical"> android:gravity="center_vertical"
android:visibility="gone">
<FrameLayout <FrameLayout
android:id="@+id/action_btn_wrap" android:id="@+id/action_btn_wrap"

View File

@ -6,6 +6,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<ScrollView <ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
@ -16,142 +17,205 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> 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"
android:textSize="16sp"
tools:visibility="visible"/>
<TextView
android:id="@+id/reply_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-12dp"
android:paddingHorizontal="16dp"
android:paddingTop="16dp"
android:paddingBottom="6dp"
android:textAppearance="@style/m3_title_small"
android:drawableStart="@drawable/ic_fluent_arrow_reply_20_filled"
tools:drawableEnd="@drawable/ic_fluent_earth_20_regular"
android:drawableTint="?android:textColorSecondary"
android:drawablePadding="6dp"
android:singleLine="true"
android:ellipsize="end"
android:background="?android:selectableItemBackground"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingLeft="16dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="46dp"
android:layout_height="46dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="12dp" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_toEndOf="@id/avatar"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="@style/m3_title_medium"
tools:text="Eugen" />
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_below="@id/name"
android:layout_toEndOf="@id/avatar"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="@style/m3_title_small"
tools:text="\@Gargron" />
</RelativeLayout>
<FrameLayout
android:id="@+id/toot_text_wrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<org.joinmastodon.android.ui.views.ComposeEditText
android:id="@+id/toot_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:textAppearance="@style/m3_body_large"
android:textSize="16sp"
android:gravity="top"
android:background="@null"
android:hint="@string/compose_hint"
android:elevation="0dp"
android:inputType="textMultiLine|textCapSentences"/>
</FrameLayout>
<LinearLayout <LinearLayout
android:id="@+id/poll_wrap" android:id="@+id/original_post"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible"> android:background="?android:selectableItemBackground">
<org.joinmastodon.android.ui.views.ReorderableLinearLayout <include layout="@layout/display_item_header" />
android:id="@+id/poll_options" <include layout="@layout/display_item_text" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorPollVoted"/>
</LinearLayout>
<LinearLayout
android:id="@+id/reply_wrap"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/content_warning"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"/> android:elevation="0dp"
<LinearLayout android:hint="@string/content_warning"
android:id="@+id/add_poll_option" android:inputType="textMultiLine|textCapSentences"
android:layout_width="match_parent" android:visibility="gone"
android:layout_height="56dp" android:textColorHint="?android:textColorSecondary"
android:layout_marginStart="16dp" android:background="@drawable/bg_cw_edit"
android:layout_marginEnd="56dp" android:padding="16dp"
android:layout_marginBottom="8dp" android:minHeight="56dp"
android:background="@drawable/bg_poll_option_clickable" android:textSize="16sp"
android:outlineProvider="background" tools:visibility="visible"/>
android:elevation="2dp">
<ImageView
android:id="@+id/add_poll_option_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="16dp"
android:tint="?colorDarkIcon"
android:src="@drawable/ic_fluent_add_circle_24_regular"/>
</LinearLayout>
<TextView <TextView
android:id="@+id/poll_duration" android:id="@+id/reply_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="16dp" android:layout_marginBottom="-12dp"
android:layout_marginRight="16dp" android:paddingHorizontal="16dp"
android:layout_marginBottom="8dp" android:paddingTop="16dp"
android:textAppearance="@style/m3_label_large" android:paddingBottom="6dp"
android:textColor="?android:textColorPrimary" android:textAppearance="@style/m3_title_small"
tools:text="Duration: 7 days"/> android:drawableStart="@drawable/ic_fluent_arrow_reply_20_filled"
tools:drawableEnd="@drawable/ic_fluent_earth_20_regular"
android:drawableTint="?android:textColorSecondary"
android:drawablePadding="6dp"
android:singleLine="true"
android:ellipsize="end"
android:background="?android:selectableItemBackground"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingLeft="16dp">
<ImageView
android:id="@+id/self_avatar"
android:layout_width="46dp"
android:layout_height="46dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="12dp" />
<TextView
android:id="@+id/self_name"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_toEndOf="@id/self_avatar"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="@style/m3_title_medium"
tools:text="Eugen" />
<TextView
android:id="@+id/self_username"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_below="@id/self_name"
android:layout_toEndOf="@id/self_avatar"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="@style/m3_title_small"
tools:text="\@Gargron" />
</RelativeLayout>
<FrameLayout
android:id="@+id/toot_text_wrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<org.joinmastodon.android.ui.views.ComposeEditText
android:id="@+id/toot_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:textAppearance="@style/m3_body_large"
android:textSize="16sp"
android:gravity="top"
android:background="@null"
android:hint="@string/compose_hint"
android:elevation="0dp"
android:inputType="textMultiLine|textCapSentences"/>
</FrameLayout>
<LinearLayout <LinearLayout
android:id="@+id/poll_allow_multiple" android:id="@+id/poll_wrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<org.joinmastodon.android.ui.views.ReorderableLinearLayout
android:id="@+id/poll_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/add_poll_option"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="8dp"
android:background="@drawable/bg_poll_option_clickable"
android:outlineProvider="background"
android:elevation="2dp">
<ImageView
android:id="@+id/add_poll_option_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="16dp"
android:tint="?colorDarkIcon"
android:src="@drawable/ic_fluent_add_circle_24_regular"/>
</LinearLayout>
<TextView
android:id="@+id/poll_duration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:textAppearance="@style/m3_label_large"
android:textColor="?android:textColorPrimary"
tools:text="Duration: 7 days"/>
<LinearLayout
android:id="@+id/poll_allow_multiple"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:layoutDirection="locale"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:background="?android:selectableItemBackground">
<CheckBox
android:id="@+id/poll_allow_multiple_checkbox"
android:clickable="false"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_marginEnd="24dp"
android:duplicateParentState="true"
android:importantForAccessibility="no"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp"
android:singleLine="true"
android:text="@string/sk_poll_allow_multiple" />
</LinearLayout>
</LinearLayout>
<org.joinmastodon.android.ui.views.ComposeMediaLayout
android:id="@+id/attachments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/sensitive_item"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -163,15 +227,16 @@
android:paddingRight="16dp" android:paddingRight="16dp"
android:paddingTop="12dp" android:paddingTop="12dp"
android:paddingBottom="12dp" android:paddingBottom="12dp"
android:background="?android:selectableItemBackground"> android:background="?android:selectableItemBackground"
android:visibility="gone">
<CheckBox <ImageView
android:id="@+id/poll_allow_multiple_checkbox" android:id="@+id/sensitive_icon"
android:clickable="false" android:layout_width="24dp"
android:layout_width="wrap_content"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="32dp"
android:duplicateParentState="true" android:src="@drawable/ic_fluent_flag_24_selector"
android:tint="?android:textColorPrimary"
android:importantForAccessibility="no"/> android:importantForAccessibility="no"/>
<TextView <TextView
@ -180,50 +245,9 @@
android:layout_weight="1" android:layout_weight="1"
android:textSize="16sp" android:textSize="16sp"
android:singleLine="true" android:singleLine="true"
android:text="@string/sk_poll_allow_multiple" /> android:text="@string/sk_mark_media_as_sensitive" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<org.joinmastodon.android.ui.views.ComposeMediaLayout
android:id="@+id/attachments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/sensitive_item"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:layoutDirection="locale"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:background="?android:selectableItemBackground"
android:visibility="gone">
<ImageView
android:id="@+id/sensitive_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="32dp"
android:src="@drawable/ic_fluent_flag_24_selector"
android:tint="?android:textColorPrimary"
android:importantForAccessibility="no"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp"
android:singleLine="true"
android:text="@string/sk_mark_media_as_sensitive" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>