Add descriptions to post visibility options

This commit is contained in:
Grishka 2024-04-20 04:48:57 +03:00
parent 1124bc48c2
commit 09be5b3f97
8 changed files with 108 additions and 20 deletions

View File

@ -13,7 +13,7 @@ android {
applicationId "org.joinmastodon.android" applicationId "org.joinmastodon.android"
minSdk 23 minSdk 23
targetSdk 33 targetSdk 33
versionCode 93 versionCode 97
versionName "2.5.0" versionName "2.5.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -66,7 +66,9 @@ import org.joinmastodon.android.model.Mention;
import org.joinmastodon.android.model.Preferences; import org.joinmastodon.android.model.Preferences;
import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.StatusPrivacy; import org.joinmastodon.android.model.StatusPrivacy;
import org.joinmastodon.android.model.viewmodel.ListItem;
import org.joinmastodon.android.ui.CustomEmojiPopupKeyboard; import org.joinmastodon.android.ui.CustomEmojiPopupKeyboard;
import org.joinmastodon.android.ui.ExtendedPopupMenu;
import org.joinmastodon.android.ui.M3AlertDialogBuilder; import org.joinmastodon.android.ui.M3AlertDialogBuilder;
import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.OutlineProviders;
import org.joinmastodon.android.ui.PopupKeyboard; import org.joinmastodon.android.ui.PopupKeyboard;
@ -87,6 +89,7 @@ import org.parceler.Parcels;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -909,24 +912,18 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
} }
private void onVisibilityClick(View v){ private void onVisibilityClick(View v){
PopupMenu menu=new PopupMenu(getActivity(), v); ArrayList<ListItem<StatusPrivacy>> items=new ArrayList<>();
menu.inflate(R.menu.compose_visibility); ExtendedPopupMenu menu=new ExtendedPopupMenu(getActivity(), items);
menu.setOnMenuItemClickListener(item->{ Consumer<ListItem<StatusPrivacy>> onClick=i->{
int id=item.getItemId(); statusVisibility=i.parentObject;
if(id==R.id.vis_public){
statusVisibility=StatusPrivacy.PUBLIC;
}else if(id==R.id.vis_unlisted){
statusVisibility=StatusPrivacy.UNLISTED;
}else if(id==R.id.vis_followers){
statusVisibility=StatusPrivacy.PRIVATE;
}else if(id==R.id.vis_private){
statusVisibility=StatusPrivacy.DIRECT;
}
item.setChecked(true);
updateVisibilityIcon(); updateVisibilityIcon();
return true; menu.dismiss();
}); };
menu.show(); items.add(new ListItem<>(R.string.visibility_public, R.string.visibility_subtitle_public, R.drawable.ic_public_24px, StatusPrivacy.PUBLIC, onClick));
items.add(new ListItem<>(R.string.visibility_unlisted, R.string.visibility_subtitle_unlisted, R.drawable.ic_clear_night_24px, StatusPrivacy.UNLISTED, onClick));
items.add(new ListItem<>(R.string.visibility_followers_only, R.string.visibility_subtitle_followers, R.drawable.ic_lock_24px, StatusPrivacy.PRIVATE, onClick));
items.add(new ListItem<>(R.string.visibility_private, R.string.visibility_subtitle_private, R.drawable.ic_alternate_email_24px, StatusPrivacy.DIRECT, onClick));
menu.showAsDropDown(v);
} }
private void loadDefaultStatusVisibility(Bundle savedInstanceState){ private void loadDefaultStatusVisibility(Bundle savedInstanceState){

View File

@ -68,6 +68,12 @@ public class ListItem<T>{
this.subtitleRes=subtitleRes; this.subtitleRes=subtitleRes;
} }
public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, T parentObject, Consumer<ListItem<T>> onClick){
this(null, null, iconRes, onClick, parentObject, 0, false);
this.titleRes=titleRes;
this.subtitleRes=subtitleRes;
}
public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Consumer<ListItem<T>> onClick, int colorOverrideAttr, boolean dividerAfter){ public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Consumer<ListItem<T>> onClick, int colorOverrideAttr, boolean dividerAfter){
this(null, null, iconRes, onClick, null, colorOverrideAttr, dividerAfter); this(null, null, iconRes, onClick, null, colorOverrideAttr, dividerAfter);
this.titleRes=titleRes; this.titleRes=titleRes;

View File

@ -0,0 +1,61 @@
package org.joinmastodon.android.ui;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import org.joinmastodon.android.R;
import org.joinmastodon.android.model.viewmodel.ListItem;
import org.joinmastodon.android.ui.adapters.GenericListItemsAdapter;
import org.joinmastodon.android.ui.viewholders.ListItemViewHolder;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.UsableRecyclerView;
public class ExtendedPopupMenu extends PopupWindow{
private UsableRecyclerView list;
public <T> ExtendedPopupMenu(Context context, List<ListItem<T>> items){
super(context, null, 0, R.style.Widget_Mastodon_PopupMenu);
setWidth(V.dp(200));
setElevation(V.dp(3));
setOutsideTouchable(true);
setFocusable(true);
setInputMethodMode(INPUT_METHOD_NOT_NEEDED);
list=new UsableRecyclerView(context);
list.setLayoutManager(new LinearLayoutManager(context));
list.setAdapter(new ReducedPaddingItemsAdapter<>(items));
list.setClipToPadding(false);
setContentView(list);
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity){
super.showAsDropDown(anchor, xoff, yoff, gravity);
View bgView=(View) list.getParent();
list.setPadding(0, bgView.getPaddingTop(), 0, bgView.getPaddingBottom());
bgView.setPadding(0, 0, 0, 0);
}
private static class ReducedPaddingItemsAdapter<T> extends GenericListItemsAdapter<T>{
public ReducedPaddingItemsAdapter(List<ListItem<T>> listItems){
super(listItems);
}
@NonNull
@Override
public ListItemViewHolder<?> onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
ListItemViewHolder<?> holder=super.onCreateViewHolder(parent, viewType);
int padH=V.dp(12), padV=V.dp(8);
holder.itemView.setPadding(padH, padV, padH, padV);
View icon=holder.itemView.findViewById(R.id.icon);
((ViewGroup.MarginLayoutParams)icon.getLayoutParams()).setMarginEnd(padH);
return holder;
}
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,20Q13.35,20 14.613,19.562Q15.875,19.125 16.925,18.3Q15.475,17.775 13.863,16.612Q12.25,15.45 11.025,13.7Q9.8,11.95 9.238,9.637Q8.675,7.325 9.275,4.5Q6.95,5.325 5.475,7.362Q4,9.4 4,12Q4,15.325 6.338,17.663Q8.675,20 12,20ZM12,22Q9.925,22 8.1,21.212Q6.275,20.425 4.925,19.075Q3.575,17.725 2.788,15.9Q2,14.075 2,12Q2,8.325 4.312,5.525Q6.625,2.725 10.5,2.125Q11.225,2 11.538,2.462Q11.85,2.925 11.575,3.675Q10.825,5.775 11.05,7.912Q11.275,10.05 12.275,11.85Q13.275,13.65 14.963,14.962Q16.65,16.275 18.825,16.75Q19.625,16.925 19.837,17.425Q20.05,17.925 19.575,18.475Q18.2,20.1 16.238,21.05Q14.275,22 12,22Z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,22Q5.175,22 4.588,21.413Q4,20.825 4,20V10Q4,9.175 4.588,8.587Q5.175,8 6,8H7V6Q7,3.925 8.463,2.462Q9.925,1 12,1Q14.075,1 15.538,2.462Q17,3.925 17,6V8H18Q18.825,8 19.413,8.587Q20,9.175 20,10V20Q20,20.825 19.413,21.413Q18.825,22 18,22ZM9,8H15V6Q15,4.75 14.125,3.875Q13.25,3 12,3Q10.75,3 9.875,3.875Q9,4.75 9,6ZM6,20H18Q18,20 18,20Q18,20 18,20V10Q18,10 18,10Q18,10 18,10H6Q6,10 6,10Q6,10 6,10V20Q6,20 6,20Q6,20 6,20ZM12,17Q12.825,17 13.413,16.413Q14,15.825 14,15Q14,14.175 13.413,13.587Q12.825,13 12,13Q11.175,13 10.588,13.587Q10,14.175 10,15Q10,15.825 10.588,16.413Q11.175,17 12,17ZM12,15Q12,15 12,15Q12,15 12,15Q12,15 12,15Q12,15 12,15Q12,15 12,15Q12,15 12,15Q12,15 12,15Q12,15 12,15Z"/>
</vector>

View File

@ -171,8 +171,8 @@
<string name="save">Save</string> <string name="save">Save</string>
<string name="add_alt_text">Add alt text</string> <string name="add_alt_text">Add alt text</string>
<string name="visibility_public">Public</string> <string name="visibility_public">Public</string>
<string name="visibility_followers_only">Followers only</string> <string name="visibility_followers_only">Followers</string>
<string name="visibility_private">Only people mentioned</string> <string name="visibility_private">Specific people</string>
<string name="recent_searches">Recents</string> <string name="recent_searches">Recents</string>
<string name="skip">Skip</string> <string name="skip">Skip</string>
<string name="notification_type_follow">New followers</string> <string name="notification_type_follow">New followers</string>
@ -747,4 +747,8 @@
<string name="notifications_from_user">Notifications from %s</string> <string name="notifications_from_user">Notifications from %s</string>
<string name="notifications_muted">Notifications from %s have been dismissed.</string> <string name="notifications_muted">Notifications from %s have been dismissed.</string>
<string name="notifications_allowed">%s will now appear in your notification list.</string> <string name="notifications_allowed">%s will now appear in your notification list.</string>
<string name="visibility_subtitle_public">Everyone on and off Mastodon</string>
<string name="visibility_subtitle_unlisted">Fewer algorithmic fanfares</string>
<string name="visibility_subtitle_followers">Only your followers</string>
<string name="visibility_subtitle_private">Everyone mentioned in the post</string>
</resources> </resources>

View File

@ -211,6 +211,7 @@
<item name="android:popupBackground">@drawable/bg_popup</item> <item name="android:popupBackground">@drawable/bg_popup</item>
<item name="android:background">@drawable/bg_spinner</item> <item name="android:background">@drawable/bg_spinner</item>
<item name="android:backgroundTint">?colorM3OnSurface</item> <item name="android:backgroundTint">?colorM3OnSurface</item>
<item name="android:popupElevation">3dp</item>
</style> </style>
<style name="Theme.Mastodon.Dialog.Alert" parent="android:Theme.Material.Light.Dialog.Alert"> <style name="Theme.Mastodon.Dialog.Alert" parent="android:Theme.Material.Light.Dialog.Alert">
@ -253,6 +254,7 @@
<style name="Widget.Mastodon.PopupMenu" parent="android:Widget.Material.Light.PopupMenu"> <style name="Widget.Mastodon.PopupMenu" parent="android:Widget.Material.Light.PopupMenu">
<item name="android:popupBackground">@drawable/bg_popup</item> <item name="android:popupBackground">@drawable/bg_popup</item>
<item name="android:popupElevation">3dp</item>
</style> </style>
<style name="Widget.Mastodon.M3.Button" parent="android:Widget.Material.Button"> <style name="Widget.Mastodon.M3.Button" parent="android:Widget.Material.Button">