Add FAB in profile

This commit is contained in:
Grishka 2022-02-18 00:01:29 +03:00
parent 3215960115
commit 8b8dc4fbf9
4 changed files with 264 additions and 222 deletions

View File

@ -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<EmojiCategory> 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;
}

View File

@ -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/*");

View File

@ -5,235 +5,256 @@
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.joinmastodon.android.ui.views.NestedRecyclerScrollView
android:id="@+id/scroller"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_height="match_parent">
<org.joinmastodon.android.ui.views.NestedRecyclerScrollView
android:id="@+id/scroller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_height="match_parent"
android:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="23dp"
android:clipToPadding="false">
<org.joinmastodon.android.ui.views.CoverImageView
android:id="@+id/cover"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="229dp"
android:background="#808080"
android:scaleType="centerCrop"/>
<View
android:id="@+id/avatar_border"
android:layout_width="102dp"
android:layout_height="102dp"
android:layout_below="@id/cover"
android:layout_alignParentStart="true"
android:layout_marginTop="-40dp"
android:layout_marginStart="14dp"
android:background="@drawable/profile_ava_bg"/>
<ImageView
android:id="@+id/avatar"
android:layout_width="98dp"
android:layout_height="98dp"
android:layout_below="@id/cover"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:layout_marginTop="-38dp"
android:scaleType="centerCrop"
tools:src="#0f0" />
<LinearLayout
android:id="@+id/following_btn"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_alignParentEnd="true"
android:layout_below="@id/cover"
android:layout_marginTop="12dp"
android:layout_marginEnd="16dp"
android:padding="4dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/following_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123"/>
<TextView
android:id="@+id/following_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following"/>
</LinearLayout>
<LinearLayout
android:id="@+id/followers_btn"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_toStartOf="@id/following_btn"
android:layout_below="@id/cover"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:padding="4dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/followers_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123"/>
<TextView
android:id="@+id/followers_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following"/>
</LinearLayout>
<LinearLayout
android:id="@+id/posts_btn"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_below="@id/cover"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:layout_toStartOf="@id/followers_btn"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:id="@+id/posts_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123" />
<TextView
android:id="@+id/posts_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following" />
</LinearLayout>
<FrameLayout
android:id="@+id/profile_action_btn_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@id/following_btn"
android:padding="16dp"
android:paddingBottom="23dp"
android:clipToPadding="false">
<org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/profile_action_btn"
<org.joinmastodon.android.ui.views.CoverImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="229dp"
android:background="#808080"
android:scaleType="centerCrop"/>
<View
android:id="@+id/avatar_border"
android:layout_width="102dp"
android:layout_height="102dp"
android:layout_below="@id/cover"
android:layout_alignParentStart="true"
android:layout_marginTop="-40dp"
android:layout_marginStart="14dp"
android:background="@drawable/profile_ava_bg"/>
<ImageView
android:id="@+id/avatar"
android:layout_width="98dp"
android:layout_height="98dp"
android:layout_below="@id/cover"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:layout_marginTop="-38dp"
android:scaleType="centerCrop"
tools:src="#0f0" />
<LinearLayout
android:id="@+id/following_btn"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_alignParentEnd="true"
android:layout_below="@id/cover"
android:layout_marginTop="12dp"
android:layout_marginEnd="16dp"
android:padding="4dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/following_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123"/>
<TextView
android:id="@+id/following_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following"/>
</LinearLayout>
<LinearLayout
android:id="@+id/followers_btn"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_toStartOf="@id/following_btn"
android:layout_below="@id/cover"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:padding="4dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/followers_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123"/>
<TextView
android:id="@+id/followers_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following"/>
</LinearLayout>
<LinearLayout
android:id="@+id/posts_btn"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_below="@id/cover"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:layout_toStartOf="@id/followers_btn"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:id="@+id/posts_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123" />
<TextView
android:id="@+id/posts_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following" />
</LinearLayout>
<FrameLayout
android:id="@+id/profile_action_btn_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Edit Profile"/>
<ProgressBar
android:id="@+id/action_progress"
android:layout_width="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@id/following_btn"
android:padding="16dp"
android:clipToPadding="false">
<org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/profile_action_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Edit Profile"/>
<ProgressBar
android:id="@+id/action_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:progressBarStyleSmall"
android:elevation="10dp"
android:outlineProvider="none"
android:indeterminateTint="?colorButtonText"
android:visibility="gone"/>
</FrameLayout>
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:progressBarStyleSmall"
android:elevation="10dp"
android:outlineProvider="none"
android:indeterminateTint="?colorButtonText"
android:visibility="gone"/>
</FrameLayout>
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" />
<TextView
android:id="@+id/name"
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_marginStart="16dp"
android:layout_toStartOf="@id/profile_action_btn_wrap"
android:textAppearance="@style/m3_title_medium"
android:textColor="?android:textColorSecondary"
tools:text="\@Gargron"/>
<org.joinmastodon.android.ui.views.LinkedTextView
android:id="@+id/bio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:textAppearance="@style/m3_body_large"
tools:text="Founder, CEO and lead developer @Mastodon, Germany." />
<EditText
android:id="@+id/name_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_body_large"
android:background="@drawable/edit_text_border"
android:inputType="textPersonName|textCapWords"
android:visibility="gone"
tools:text="Eugen" />
<EditText
android:id="@+id/bio_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:textAppearance="@style/m3_body_large"
android:background="@drawable/edit_text_border"
android:inputType="textMultiLine|textCapSentences"
android:visibility="gone"
tools:text="Founder, CEO and lead developer @Mastodon, Germany." />
</RelativeLayout>
<org.joinmastodon.android.ui.tabs.TabLayout
android:id="@+id/tabbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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" />
<TextView
android:id="@+id/username"
android:layout_height="38dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
app:tabPaddingStart="12dp"
app:tabPaddingEnd="12dp"
app:tabMinWidth="0dp"
app:tabIndicator="@drawable/tab_indicator_inset"
app:tabIndicatorAnimationMode="elastic"
app:tabIndicatorColor="?android:textColorPrimary"
app:tabMode="scrollable"
app:tabGravity="start"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_marginStart="16dp"
android:layout_toStartOf="@id/profile_action_btn_wrap"
android:textAppearance="@style/m3_title_medium"
android:textColor="?android:textColorSecondary"
tools:text="\@Gargron"/>
android:layout_height="wrap_content"/>
</LinearLayout>
</org.joinmastodon.android.ui.views.NestedRecyclerScrollView>
<org.joinmastodon.android.ui.views.LinkedTextView
android:id="@+id/bio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:textAppearance="@style/m3_body_large"
tools:text="Founder, CEO and lead developer @Mastodon, Germany." />
<ImageButton
android:id="@+id/fab"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="24dp"
android:background="@drawable/bg_fab"
android:tint="@color/fab_icon"
android:scaleType="center"
android:stateListAnimator="@animator/fab_shadow"
android:src="@drawable/ic_edit_34"/>
<EditText
android:id="@+id/name_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_body_large"
android:background="@drawable/edit_text_border"
android:inputType="textPersonName|textCapWords"
android:visibility="gone"
tools:text="Eugen" />
</FrameLayout>
<EditText
android:id="@+id/bio_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:textAppearance="@style/m3_body_large"
android:background="@drawable/edit_text_border"
android:inputType="textMultiLine|textCapSentences"
android:visibility="gone"
tools:text="Founder, CEO and lead developer @Mastodon, Germany." />
</RelativeLayout>
<org.joinmastodon.android.ui.tabs.TabLayout
android:id="@+id/tabbar"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
app:tabPaddingStart="12dp"
app:tabPaddingEnd="12dp"
app:tabMinWidth="0dp"
app:tabIndicator="@drawable/tab_indicator_inset"
app:tabIndicatorAnimationMode="elastic"
app:tabIndicatorColor="?android:textColorPrimary"
app:tabMode="scrollable"
app:tabGravity="start"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</org.joinmastodon.android.ui.views.NestedRecyclerScrollView>
</me.grishka.appkit.views.RecursiveSwipeRefreshLayout>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/mention" android:title="@string/mention_user" android:icon="@drawable/ic_fluent_arrow_reply_24_regular" android:showAsAction="always"/>
<item android:id="@+id/share" android:title="@string/share_user"/>
<item android:id="@+id/mute" android:title="@string/mute_user"/>
<item android:id="@+id/block" android:title="@string/block_user"/>