add option to allow multiple poll choices
This commit is contained in:
@@ -41,6 +41,7 @@ import android.view.WindowManager;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
@@ -152,6 +153,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
private ReorderableLinearLayout pollOptionsView;
|
||||
private View pollWrap;
|
||||
private View addPollOptionBtn;
|
||||
private View pollAllowMultipleItem;
|
||||
private CheckBox pollAllowMultipleCheckbox;
|
||||
private View sensitiveItem;
|
||||
private TextView pollDurationView;
|
||||
|
||||
@@ -297,6 +300,9 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
pollOptionsView=view.findViewById(R.id.poll_options);
|
||||
pollWrap=view.findViewById(R.id.poll_wrap);
|
||||
addPollOptionBtn=view.findViewById(R.id.add_poll_option);
|
||||
pollAllowMultipleItem=view.findViewById(R.id.poll_allow_multiple);
|
||||
pollAllowMultipleCheckbox=view.findViewById(R.id.poll_allow_multiple_checkbox);
|
||||
pollAllowMultipleItem.setOnClickListener(v->this.togglePollAllowMultiple());
|
||||
|
||||
addPollOptionBtn.setOnClickListener(v->{
|
||||
createDraftPollOption().edit.requestFocus();
|
||||
@@ -311,6 +317,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
pollBtn.setSelected(true);
|
||||
mediaBtn.setEnabled(false);
|
||||
pollWrap.setVisibility(View.VISIBLE);
|
||||
updatePollAllowMultiple(savedInstanceState.getBoolean("pollAllowMultiple", false));
|
||||
for(String oldText:savedInstanceState.getStringArrayList("pollOptions")){
|
||||
DraftPollOption opt=createDraftPollOption();
|
||||
opt.edit.setText(oldText);
|
||||
@@ -321,6 +328,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
pollBtn.setSelected(true);
|
||||
mediaBtn.setEnabled(false);
|
||||
pollWrap.setVisibility(View.VISIBLE);
|
||||
updatePollAllowMultiple(editingStatus.poll.multiple);
|
||||
for(Poll.Option eopt:editingStatus.poll.options){
|
||||
DraftPollOption opt=createDraftPollOption();
|
||||
opt.edit.setText(eopt.title);
|
||||
@@ -391,6 +399,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
outState.putStringArrayList("pollOptions", opts);
|
||||
outState.putInt("pollDuration", pollDuration);
|
||||
outState.putString("pollDurationStr", pollDurationStr);
|
||||
outState.putBoolean("pollAllowMultiple", pollAllowMultipleItem.isSelected());
|
||||
}
|
||||
outState.putBoolean("sensitive", sensitive);
|
||||
outState.putBoolean("hasSpoiler", hasSpoiler);
|
||||
@@ -527,15 +536,14 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
ignoreSelectionChanges=true;
|
||||
mainEditText.setSelection(mainEditText.length());
|
||||
ignoreSelectionChanges=false;
|
||||
if(!TextUtils.isEmpty(replyTo.spoilerText)){
|
||||
if(!TextUtils.isEmpty(replyTo.spoilerText) && AccountSessionManager.getInstance().isSelf(accountID, replyTo.account)){
|
||||
hasSpoiler=true;
|
||||
spoilerEdit.setVisibility(View.VISIBLE);
|
||||
spoilerEdit.setText(replyTo.spoilerText);
|
||||
spoilerBtn.setSelected(true);
|
||||
}
|
||||
}
|
||||
}else if (editingStatus==null || editingStatus.inReplyToId==null){
|
||||
// TODO: remove workaround after https://github.com/mastodon/mastodon-android/issues/341 gets fixed
|
||||
}else{
|
||||
replyText.setVisibility(View.GONE);
|
||||
}
|
||||
if(savedInstanceState==null){
|
||||
@@ -1208,6 +1216,11 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
option.view=LayoutInflater.from(getActivity()).inflate(R.layout.compose_poll_option, pollOptionsView, false);
|
||||
option.edit=option.view.findViewById(R.id.edit);
|
||||
option.dragger=option.view.findViewById(R.id.dragger_thingy);
|
||||
ImageView icon = option.view.findViewById(R.id.icon);
|
||||
icon.setImageDrawable(getContext().getDrawable(pollAllowMultipleItem.isSelected() ?
|
||||
R.drawable.ic_poll_checkbox_regular_selector :
|
||||
R.drawable.ic_poll_option_button
|
||||
));
|
||||
|
||||
option.dragger.setOnLongClickListener(v->{
|
||||
pollOptionsView.startDragging(option.view);
|
||||
@@ -1385,6 +1398,27 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
||||
});
|
||||
}
|
||||
|
||||
private void togglePollAllowMultiple() {
|
||||
updatePollAllowMultiple(!pollAllowMultipleItem.isSelected());
|
||||
}
|
||||
|
||||
private void updatePollAllowMultiple(boolean multiple){
|
||||
pollAllowMultipleItem.setSelected(multiple);
|
||||
pollAllowMultipleCheckbox.setChecked(multiple);
|
||||
ImageView btn = addPollOptionBtn.findViewById(R.id.add_poll_option_icon);
|
||||
btn.setImageDrawable(getContext().getDrawable(multiple ?
|
||||
R.drawable.ic_fluent_add_square_24_regular :
|
||||
R.drawable.ic_fluent_add_circle_24_regular
|
||||
));
|
||||
for (DraftPollOption opt:pollOptions) {
|
||||
ImageView icon = opt.view.findViewById(R.id.icon);
|
||||
icon.setImageDrawable(getContext().getDrawable(multiple ?
|
||||
R.drawable.ic_poll_checkbox_regular_selector :
|
||||
R.drawable.ic_poll_option_button
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectionChanged(int start, int end){
|
||||
if(ignoreSelectionChanges)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:pathData="M12 7c0.414 0 0.75 0.336 0.75 0.75v3.5h3.5c0.414 0 0.75 0.336 0.75 0.75s-0.336 0.75-0.75 0.75h-3.5v3.5c0 0.414-0.336 0.75-0.75 0.75s-0.75-0.336-0.75-0.75v-3.5h-3.5C7.336 12.75 7 12.414 7 12s0.336-0.75 0.75-0.75h3.5v-3.5C11.25 7.336 11.586 7 12 7zM3 6.25C3 4.455 4.455 3 6.25 3h11.5C19.545 3 21 4.455 21 6.25v11.5c0 1.795-1.455 3.25-3.25 3.25H6.25C4.455 21 3 19.545 3 17.75V6.25zM6.25 4.5C5.284 4.5 4.5 5.284 4.5 6.25v11.5c0 0.966 0.784 1.75 1.75 1.75h11.5c0.966 0 1.75-0.784 1.75-1.75V6.25c0-0.966-0.784-1.75-1.75-1.75H6.25z" android:fillColor="@color/fluent_default_icon_tint"/>
|
||||
</vector>
|
||||
@@ -15,6 +15,7 @@
|
||||
android:outlineProvider="background"
|
||||
android:elevation="2dp">
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_margin="16dp"
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
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"
|
||||
@@ -148,6 +149,39 @@
|
||||
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/poll_allow_multiple" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<org.joinmastodon.android.ui.views.ComposeMediaLayout
|
||||
|
||||
@@ -408,47 +408,5 @@
|
||||
<string name="login_title">Welcome Back</string>
|
||||
<string name="login_subtitle">Log in with the server where you created your account.</string>
|
||||
<string name="server_url">Server URL</string>
|
||||
|
||||
|
||||
<!-- <string name="app_name">Megalodon</string>-->
|
||||
<!-- <string name="pinned_posts">Pinned</string>-->
|
||||
<!-- <string name="delete_and_redraft">Delete and re-draft</string>-->
|
||||
<!-- <string name="confirm_delete_and_redraft_title">Delete and re-draft Post</string>-->
|
||||
<!-- <string name="confirm_delete_and_redraft">Are you sure you want to delete and re-draft this post?</string>-->
|
||||
<!-- <string name="pin_post">Pin to profile</string>-->
|
||||
<!-- <string name="confirm_pin_post_title">Pin post to profile</string>-->
|
||||
<!-- <string name="confirm_pin_post">Do you want to pin this post to your profile?</string>-->
|
||||
<!-- <string name="pinning">Pinning post…</string>-->
|
||||
<!-- <string name="unpin_post">Unpin from profile</string>-->
|
||||
<!-- <string name="confirm_unpin_post_title">Unpin post from profile</string>-->
|
||||
<!-- <string name="confirm_unpin_post">Are you sure you want to unpin this post?</string>-->
|
||||
<!-- <string name="unpinning">Unpinning post…</string>-->
|
||||
<!-- <string name="image_description">Image description</string>-->
|
||||
<!-- <string name="visibility_unlisted">Unlisted</string>-->
|
||||
<!-- <string name="settings_show_replies">Show replies</string>-->
|
||||
<!-- <string name="settings_show_boosts">Show boosts</string>-->
|
||||
<!-- <string name="settings_load_new_posts">Automatically load new posts</string>-->
|
||||
<!-- <string name="settings_show_interaction_counts">Show interaction counts</string>-->
|
||||
<!--<!– <string name="settings_app_version">Megalodon v%1$s (%2$d)</string>–>-->
|
||||
<!-- <string name="mark_media_as_sensitive">Mark media as sensitive</string>-->
|
||||
<!-- <string name="user_post_notifications_on">Turned on post notifications for %s</string>-->
|
||||
<!-- <string name="user_post_notifications_off">Turned off post notifications for %s</string>-->
|
||||
<!-- <string name="federated_timeline">Federation</string>-->
|
||||
<!-- <string name="federated_timeline_info_banner">These are the most recent posts by the people in your federation.</string>-->
|
||||
<!--<!– <string name="update_available">Megalodon %s is ready to download.</string>–>-->
|
||||
<!--<!– <string name="update_ready">Megalodon %s is downloaded and ready to install.</string>–>-->
|
||||
<!-- <string name="check_for_update">Check for update</string>-->
|
||||
<!-- <string name="no_update_available">No update available</string>-->
|
||||
<!-- <string name="list_timelines">Lists</string>-->
|
||||
<!-- <string name="follow_requests">Follow requests</string>-->
|
||||
<!-- <string name="accept_follow_request">Accept follow request</string>-->
|
||||
<!-- <string name="reject_follow_request">Reject follow request</string>-->
|
||||
<!-- <string name="lists_with_user">Lists with %s</string>-->
|
||||
<!--<!– <string name="settings_always_reveal_content_warnings">Always reveal content warnings</string>–>-->
|
||||
<!--<!– <string name="disable_marquee">Disable scrolling text in title bars</string>–>-->
|
||||
<!--<!– <string name="settings_contribute">Contribute to Megalodon</string>–>-->
|
||||
<!-- <string name="settings_show_federated_timeline">Show federated timeline</string>-->
|
||||
<!-- <string name="notification_type_status">Posts</string>-->
|
||||
<!-- <string name="notify_posts">Post notifications</string>-->
|
||||
|
||||
</resources>
|
||||
<string name="poll_allow_multiple">Allow multiple choices</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user