Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support min_options for polls in instance configuration #959

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ public void updatePublishButtonState(){
uuid=null;
if(publishButton==null)
return;
publishButton.setEnabled((!isInstancePixelfed() || !mediaViewController.isEmpty()) && (trimmedCharCount>0 || !mediaViewController.isEmpty()) && charCount<=charLimit && mediaViewController.getNonDoneAttachmentCount()==0 && (pollViewController.isEmpty() || pollViewController.getNonEmptyOptionsCount()>1));
publishButton.setEnabled((!isInstancePixelfed() || !mediaViewController.isEmpty()) && (trimmedCharCount>0 || !mediaViewController.isEmpty()) && charCount<=charLimit && mediaViewController.getNonDoneAttachmentCount()==0 && (pollViewController.isEmpty() || pollViewController.hasEnoughNonEmptyOptions()));
}

private void onCustomEmojiClick(Emoji emoji){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public static class MediaAttachmentsConfiguration{

@Parcel
public static class PollsConfiguration{
public int minOptions;
public int maxOptions;
public int maxCharactersPerOption;
public int minExpiration;
Expand All @@ -226,6 +227,7 @@ public static class V2 extends BaseModel {
@Parcel
public static class Configuration {
public TranslationConfiguration translation;
public PollsConfiguration polls;
}

@Parcel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class ComposePollViewController{
private boolean pollChanged;

private int maxPollOptions=4;
private int minPollOptions=2;
private int maxPollOptionLength=50;

public ComposePollViewController(ComposeFragment fragment){
Expand All @@ -75,16 +76,22 @@ public void setView(View view, Bundle savedInstanceState){
pollWrap=view.findViewById(R.id.poll_wrap);

Instance instance=fragment.instance;
if (!instance.isAkkoma()) {
if(instance!=null && instance.configuration!=null && instance.configuration.polls!=null && instance.configuration.polls.maxOptions>0)
maxPollOptions=instance.configuration.polls.maxOptions;
if(instance!=null && instance.configuration!=null && instance.configuration.polls!=null && instance.configuration.polls.maxCharactersPerOption>0)
maxPollOptionLength=instance.configuration.polls.maxCharactersPerOption;
} else {
if(instance!=null && instance.pollLimits!=null && instance.pollLimits.maxOptions>0)
maxPollOptions=instance.pollLimits.maxOptions;
if(instance!=null && instance.pollLimits!=null && instance.pollLimits.maxOptionChars>0)
maxPollOptionLength=instance.pollLimits.maxOptionChars;
if(instance!=null){
if(!instance.isAkkoma()){
if(instance.v2!=null && instance.v2.configuration!=null && instance.v2.configuration.polls!=null){
if(instance.v2.configuration.polls.maxOptions>0) maxPollOptions=instance.v2.configuration.polls.maxOptions;
if(instance.v2.configuration.polls.maxOptions>0) minPollOptions=instance.v2.configuration.polls.minOptions;
if(instance.v2.configuration.polls.maxCharactersPerOption>0) maxPollOptionLength=instance.v2.configuration.polls.maxCharactersPerOption;
}
if(instance.configuration!=null && instance.configuration.polls!=null){
if(instance.configuration.polls.maxOptions>0) maxPollOptions=instance.configuration.polls.maxOptions;
if(instance.configuration.polls.minOptions>0) minPollOptions=instance.configuration.polls.minOptions;
if(instance.configuration.polls.maxCharactersPerOption>0) maxPollOptionLength=instance.configuration.polls.maxCharactersPerOption;
}
}else{
if(instance.pollLimits!=null && instance.pollLimits.maxOptions>0) maxPollOptions=instance.pollLimits.maxOptions;
if(instance.pollLimits!=null && instance.pollLimits.maxOptionChars>0) maxPollOptionLength=instance.pollLimits.maxOptionChars;
}
}

pollOptionsView=pollWrap.findViewById(R.id.poll_options);
Expand Down Expand Up @@ -256,6 +263,10 @@ public boolean isEmpty(){
return pollOptions.isEmpty();
}

public boolean hasEnoughNonEmptyOptions(){
return getNonEmptyOptionsCount()>=minPollOptions;
}

public int getNonEmptyOptionsCount(){
int nonEmptyPollOptionsCount=0;
for(DraftPollOption opt:pollOptions){
Expand All @@ -268,7 +279,7 @@ public int getNonEmptyOptionsCount(){
public void toggle(){
if(pollOptions.isEmpty()){
pollWrap.setVisibility(View.VISIBLE);
for(int i=0;i<2;i++)
for(int i=0; i<minPollOptions; i++)
createDraftPollOption(false);
updatePollOptionHints();
}else{
Expand Down Expand Up @@ -329,7 +340,7 @@ public void onDragStart(View view){
anim.setInterpolator(CubicBezierInterpolator.DEFAULT);
anim.start();
fragment.mainLayout.setClipChildren(false);
if(pollOptions.size()>2){
if(pollOptions.size()>minPollOptions){
// UiUtils.beginLayoutTransition(pollSettingsView);
deletePollOptionBtn.setVisibility(View.VISIBLE);
addPollOptionBtn.setVisibility(View.GONE);
Expand All @@ -338,7 +349,7 @@ public void onDragStart(View view){

@Override
public void onDragEnd(View view){
if(pollOptions.size()>2){
if(pollOptions.size()>minPollOptions){
// UiUtils.beginLayoutTransition(pollSettingsView);
deletePollOptionBtn.setVisibility(View.GONE);
addPollOptionBtn.setVisibility(View.VISIBLE);
Expand Down