diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java index 5724a933..37f52f83 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java @@ -22,6 +22,7 @@ public class UpdateAccountCredentials extends MastodonAPIRequest{ private Uri avatar, cover; private File avatarFile, coverFile; private List fields; + private Boolean discoverable, indexable; public UpdateAccountCredentials(String displayName, String bio, Uri avatar, Uri cover, List fields){ super(HttpMethod.PATCH, "/accounts/update_credentials", Account.class); @@ -41,6 +42,12 @@ public class UpdateAccountCredentials extends MastodonAPIRequest{ this.fields=fields; } + public UpdateAccountCredentials setDiscoverableIndexable(boolean discoverable, boolean indexable){ + this.discoverable=discoverable; + this.indexable=indexable; + return this; + } + @Override public RequestBody getRequestBody() throws IOException{ MultipartBody.Builder bldr=new MultipartBody.Builder() @@ -58,15 +65,21 @@ public class UpdateAccountCredentials extends MastodonAPIRequest{ }else if(coverFile!=null){ bldr.addFormDataPart("header", coverFile.getName(), new ResizedImageRequestBody(Uri.fromFile(coverFile), 1500*500, null)); } - if(fields.isEmpty()){ - bldr.addFormDataPart("fields_attributes[0][name]", "").addFormDataPart("fields_attributes[0][value]", ""); - }else{ - int i=0; - for(AccountField field:fields){ - bldr.addFormDataPart("fields_attributes["+i+"][name]", field.name).addFormDataPart("fields_attributes["+i+"][value]", field.value); - i++; + if(fields!=null){ + if(fields.isEmpty()){ + bldr.addFormDataPart("fields_attributes[0][name]", "").addFormDataPart("fields_attributes[0][value]", ""); + }else{ + int i=0; + for(AccountField field:fields){ + bldr.addFormDataPart("fields_attributes["+i+"][name]", field.name).addFormDataPart("fields_attributes["+i+"][value]", field.value); + i++; + } } } + if(discoverable!=null) + bldr.addFormDataPart("discoverable", discoverable.toString()); + if(indexable!=null) + bldr.addFormDataPart("indexable", indexable.toString()); return bldr.build(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/OnboardingProfileSetupFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/OnboardingProfileSetupFragment.java index 9cb34708..619801a8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/OnboardingProfileSetupFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/OnboardingProfileSetupFragment.java @@ -12,6 +12,7 @@ import android.view.WindowInsets; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ScrollView; import org.joinmastodon.android.R; @@ -20,12 +21,17 @@ import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.HomeFragment; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.AccountField; +import org.joinmastodon.android.model.viewmodel.CheckableListItem; +import org.joinmastodon.android.ui.M3AlertDialogBuilder; import org.joinmastodon.android.ui.OutlineProviders; +import org.joinmastodon.android.ui.adapters.GenericListItemsAdapter; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.ui.viewholders.ListItemViewHolder; import org.joinmastodon.android.ui.views.ReorderableLinearLayout; import org.joinmastodon.android.utils.ElevationOnScrollListener; import java.util.ArrayList; +import java.util.List; import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; @@ -36,7 +42,7 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.FragmentRootLinearLayout; -public class OnboardingProfileSetupFragment extends ToolbarFragment implements ReorderableLinearLayout.OnDragListener{ +public class OnboardingProfileSetupFragment extends ToolbarFragment{ private Button btn; private View buttonBar; private String accountID; @@ -44,9 +50,9 @@ public class OnboardingProfileSetupFragment extends ToolbarFragment implements R private ScrollView scroller; private EditText nameEdit, bioEdit; private ImageView avaImage, coverImage; - private Button addRow; - private ReorderableLinearLayout profileFieldsLayout; private Uri avatarUri, coverUri; + private LinearLayout scrollContent; + private CheckableListItem discoverableItem; private static final int AVATAR_RESULT=348; private static final int COVER_RESULT=183; @@ -74,8 +80,6 @@ public class OnboardingProfileSetupFragment extends ToolbarFragment implements R bioEdit=view.findViewById(R.id.bio); avaImage=view.findViewById(R.id.avatar); coverImage=view.findViewById(R.id.header); - addRow=view.findViewById(R.id.add_row); - profileFieldsLayout=view.findViewById(R.id.profile_fields); btn=view.findViewById(R.id.btn_next); btn.setOnClickListener(v->onButtonClick()); @@ -87,31 +91,20 @@ public class OnboardingProfileSetupFragment extends ToolbarFragment implements R Account account=AccountSessionManager.getInstance().getAccount(accountID).self; if(savedInstanceState==null){ nameEdit.setText(account.displayName); - makeFieldsRow(); - }else{ - ArrayList fieldTitles=savedInstanceState.getStringArrayList("fieldTitles"); - ArrayList fieldValues=savedInstanceState.getStringArrayList("fieldValues"); - for(int i=0;i{ - makeFieldsRow(); - if(profileFieldsLayout.getChildCount()==4){ - addRow.setVisibility(View.GONE); - } - }); - profileFieldsLayout.setDragListener(this); avaImage.setOnClickListener(v->startActivityForResult(UiUtils.getMediaPickerIntent(new String[]{"image/*"}, 1), AVATAR_RESULT)); coverImage.setOnClickListener(v->startActivityForResult(UiUtils.getMediaPickerIntent(new String[]{"image/*"}, 1), COVER_RESULT)); + scrollContent=view.findViewById(R.id.scrollable_content); + discoverableItem=new CheckableListItem<>(R.string.make_profile_discoverable, 0, CheckableListItem.Style.SWITCH_SEPARATED, true, R.drawable.ic_campaign_24px, item->showDiscoverabilityAlert()); + GenericListItemsAdapter fakeAdapter=new GenericListItemsAdapter<>(List.of(discoverableItem)); + ListItemViewHolder holder=fakeAdapter.onCreateViewHolder(scrollContent, fakeAdapter.getItemViewType(0)); + fakeAdapter.bindViewHolder(holder, 0); + holder.itemView.setBackground(UiUtils.getThemeDrawable(getActivity(), android.R.attr.selectableItemBackground)); + holder.itemView.setOnClickListener(v->holder.onClick()); + scrollContent.addView(holder.itemView); + return view; } @@ -130,17 +123,8 @@ public class OnboardingProfileSetupFragment extends ToolbarFragment implements R } protected void onButtonClick(){ - ArrayList fields=new ArrayList<>(); - for(int i=0;i(){ @Override public void onSuccess(Account result){ @@ -164,39 +148,6 @@ public class OnboardingProfileSetupFragment extends ToolbarFragment implements R super.onApplyWindowInsets(UiUtils.applyBottomInsetToFixedView(buttonBar, insets)); } - private View makeFieldsRow(){ - View view=LayoutInflater.from(getActivity()).inflate(R.layout.onboarding_profile_field, profileFieldsLayout, false); - profileFieldsLayout.addView(view); - view.findViewById(R.id.dragger_thingy).setOnLongClickListener(v->{ - profileFieldsLayout.startDragging(view); - return true; - }); - view.findViewById(R.id.delete).setOnClickListener(v->{ - profileFieldsLayout.removeView(view); - if(addRow.getVisibility()==View.GONE) - addRow.setVisibility(View.VISIBLE); - }); - return view; - } - - @Override - public void onSwapItems(int oldIndex, int newIndex){} - - @Override - public void onSaveInstanceState(Bundle outState){ - super.onSaveInstanceState(outState); - ArrayList fieldTitles=new ArrayList<>(), fieldValues=new ArrayList<>(); - for(int i=0;i extends ListItem{ case CHECKBOX -> R.id.list_item_checkbox; case RADIO -> R.id.list_item_radio; case SWITCH -> R.id.list_item_switch; + case SWITCH_SEPARATED -> R.id.list_item_switch_separated; }; } @@ -69,6 +70,7 @@ public class CheckableListItem extends ListItem{ public enum Style{ CHECKBOX, RADIO, - SWITCH + SWITCH, + SWITCH_SEPARATED } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/adapters/GenericListItemsAdapter.java b/mastodon/src/main/java/org/joinmastodon/android/ui/adapters/GenericListItemsAdapter.java index d8db4d9c..bd057a42 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/adapters/GenericListItemsAdapter.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/adapters/GenericListItemsAdapter.java @@ -39,8 +39,8 @@ public class GenericListItemsAdapter extends UsableRecyclerView.Adapter onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ if(viewType==R.id.list_item_simple || viewType==R.id.list_item_simple_tinted) return new SimpleListItemViewHolder(parent.getContext(), parent); - if(viewType==R.id.list_item_switch) - return new SwitchListItemViewHolder(parent.getContext(), parent); + if(viewType==R.id.list_item_switch || viewType==R.id.list_item_switch_separated) + return new SwitchListItemViewHolder(parent.getContext(), parent, viewType==R.id.list_item_switch_separated); if(viewType==R.id.list_item_checkbox) return new CheckboxOrRadioListItemViewHolder(parent.getContext(), parent, false); if(viewType==R.id.list_item_radio) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/SwitchListItemViewHolder.java b/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/SwitchListItemViewHolder.java index 85cefd00..6dd042a2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/SwitchListItemViewHolder.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/SwitchListItemViewHolder.java @@ -2,10 +2,13 @@ package org.joinmastodon.android.ui.viewholders; import android.content.Context; import android.view.Gravity; +import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; +import org.joinmastodon.android.R; import org.joinmastodon.android.model.viewmodel.CheckableListItem; +import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.M3Switch; import me.grishka.appkit.utils.V; @@ -14,8 +17,17 @@ public class SwitchListItemViewHolder extends CheckableListItemViewHolder{ private final M3Switch sw; private boolean ignoreListener; - public SwitchListItemViewHolder(Context context, ViewGroup parent){ + public SwitchListItemViewHolder(Context context, ViewGroup parent, boolean separated){ super(context, parent); + if(separated){ + View separator=new View(context); + separator.setBackgroundColor(UiUtils.getThemeColor(context, R.attr.colorM3OutlineVariant)); + LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(V.dp(1), V.dp(32)); + lp.gravity=Gravity.TOP; + lp.setMarginStart(V.dp(16)); + lp.setMarginEnd(V.dp(-1)); + checkableLayout.addView(separator, lp); + } sw=new M3Switch(context); LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(V.dp(52), V.dp(32)); lp.gravity=Gravity.TOP; diff --git a/mastodon/src/main/res/drawable/ic_campaign_24px.xml b/mastodon/src/main/res/drawable/ic_campaign_24px.xml new file mode 100644 index 00000000..0f34633b --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_campaign_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/mastodon/src/main/res/layout/fragment_onboarding_profile_setup.xml b/mastodon/src/main/res/layout/fragment_onboarding_profile_setup.xml index 4b1e3b8e..2ad0cb94 100644 --- a/mastodon/src/main/res/layout/fragment_onboarding_profile_setup.xml +++ b/mastodon/src/main/res/layout/fragment_onboarding_profile_setup.xml @@ -11,6 +11,7 @@ android:layout_height="0dp" android:layout_weight="1"> @@ -104,39 +107,6 @@ android:hint="@string/profile_bio"/> - - - -