From 8b8dc4fbf90be3ac4f0dc0a61ae35e1036ad2551 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 18 Feb 2022 00:01:29 +0300 Subject: [PATCH] Add FAB in profile --- .../android/fragments/ComposeFragment.java | 17 +- .../android/fragments/ProfileFragment.java | 17 +- .../src/main/res/layout/fragment_profile.xml | 451 +++++++++--------- mastodon/src/main/res/menu/profile.xml | 1 - 4 files changed, 264 insertions(+), 222 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index cef17446..7a7fc815 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -50,7 +50,6 @@ import org.joinmastodon.android.model.Attachment; import org.joinmastodon.android.model.Emoji; import org.joinmastodon.android.model.EmojiCategory; import org.joinmastodon.android.model.Mention; -import org.joinmastodon.android.model.Poll; import org.joinmastodon.android.model.Status; import org.joinmastodon.android.ui.CustomEmojiPopupKeyboard; import org.joinmastodon.android.ui.M3AlertDialogBuilder; @@ -129,7 +128,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis private List customEmojis; private CustomEmojiPopupKeyboard emojiKeyboard; private Status replyTo; - private String initialReplyMentions; + private String initialText; private String uuid; private int pollDuration=24*3600; private String pollDurationStr; @@ -291,14 +290,22 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis if(!mentions.contains(m)) mentions.add(m); } - initialReplyMentions=TextUtils.join(" ", mentions)+" "; + initialText=TextUtils.join(" ", mentions)+" "; if(savedInstanceState==null){ - mainEditText.setText(initialReplyMentions); + mainEditText.setText(initialText); mainEditText.setSelection(mainEditText.length()); } }else{ replyText.setVisibility(View.GONE); } + if(savedInstanceState==null){ + String prefilledText=getArguments().getString("prefilledText"); + if(!TextUtils.isEmpty(prefilledText)){ + mainEditText.setText(prefilledText); + mainEditText.setSelection(mainEditText.length()); + initialText=prefilledText; + } + } } @Override @@ -418,7 +425,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis boolean pollFieldsHaveContent=false; for(DraftPollOption opt:pollOptions) pollFieldsHaveContent|=opt.edit.length()>0; - return (mainEditText.length()>0 && !mainEditText.getText().toString().equals(initialReplyMentions)) || !attachments.isEmpty() + return (mainEditText.length()>0 && !mainEditText.getText().toString().equals(initialText)) || !attachments.isEmpty() || uploadingAttachment!=null || !queuedAttachments.isEmpty() || !failedAttachments.isEmpty() || pollFieldsHaveContent; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 656e13a6..482dd578 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -71,6 +71,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager2.widget.ViewPager2; +import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; @@ -116,6 +117,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private Uri editNewAvatar, editNewCover; private String profileAccountID; private boolean refreshing; + private View fab; public ProfileFragment(){ super(R.layout.loader_fragment_overlay_toolbar); @@ -175,6 +177,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList nameEdit=content.findViewById(R.id.name_edit); bioEdit=content.findViewById(R.id.bio_edit); actionProgress=content.findViewById(R.id.action_progress); + fab=content.findViewById(R.id.fab); avatar.setOutlineProvider(new ViewOutlineProvider(){ @Override @@ -244,11 +247,14 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList avatar.setOnClickListener(this::onAvatarClick); cover.setOnClickListener(this::onCoverClick); refreshLayout.setOnRefreshListener(this); + fab.setOnClickListener(this::onFabClick); if(loaded){ bindHeaderView(); dataLoaded(); tabLayoutMediator.attach(); + }else{ + fab.setVisibility(View.GONE); } return sizeWrapper; @@ -280,6 +286,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList if(mediaFragment.loaded) mediaFragment.onRefresh(); } + V.setVisibilityAnimated(fab, View.VISIBLE); } }) .exec(accountID); @@ -452,7 +459,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList if(relationship==null) return; inflater.inflate(R.menu.profile, menu); - menu.findItem(R.id.mention).setTitle(getString(R.string.mention_user, account.displayName)); menu.findItem(R.id.share).setTitle(getString(R.string.share_user, account.displayName)); menu.findItem(R.id.mute).setTitle(getString(relationship.muting ? R.string.unmute_user : R.string.mute_user, account.displayName)); menu.findItem(R.id.block).setTitle(getString(relationship.blocking ? R.string.unblock_user : R.string.block_user, account.displayName)); @@ -804,6 +810,15 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList } } + private void onFabClick(View v){ + Bundle args=new Bundle(); + args.putString("account", accountID); + if(!AccountSessionManager.getInstance().isSelf(accountID, account)){ + args.putString("prefilledText", '@'+account.acct+' '); + } + Nav.go(getActivity(), ComposeFragment.class, args); + } + private void startImagePicker(int requestCode){ Intent intent=new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index c712d67d..b64b7a98 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -5,235 +5,256 @@ android:id="@+id/refresh_layout" android:layout_width="match_parent" android:layout_height="match_parent"> - - + + - + - - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - + android:layout_below="@id/avatar" + android:layout_alignParentStart="true" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" + android:layout_toStartOf="@id/profile_action_btn_wrap" + android:textAppearance="@style/m3_headline_small" + android:textAlignment="viewStart" + tools:text="Eugen" /> - + + + + + + + + + - - + + android:layout_height="wrap_content"/> + + - + - + - - - - - - - \ No newline at end of file diff --git a/mastodon/src/main/res/menu/profile.xml b/mastodon/src/main/res/menu/profile.xml index 7816855b..9ed13754 100644 --- a/mastodon/src/main/res/menu/profile.xml +++ b/mastodon/src/main/res/menu/profile.xml @@ -1,6 +1,5 @@ -