Merge remote-tracking branch 'megalodon_main/main'

# Conflicts:
#	mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollFooterStatusDisplayItem.java
This commit is contained in:
LucasGGamerM
2023-11-28 14:31:42 -03:00
39 changed files with 73 additions and 82 deletions

View File

@@ -42,7 +42,6 @@ public class GlobalUserPreferences{
public static boolean showNewPostsButton;
public static boolean toolbarMarquee;
public static boolean disableSwipe;
public static boolean voteButtonForSingleChoice;
public static boolean enableDeleteNotifications;
public static boolean translateButtonOpenedOnly;
public static boolean uniformNotificationIcon;
@@ -117,7 +116,6 @@ public class GlobalUserPreferences{
showNewPostsButton=prefs.getBoolean("showNewPostsButton", true);
toolbarMarquee=prefs.getBoolean("toolbarMarquee", true);
disableSwipe=prefs.getBoolean("disableSwipe", false);
voteButtonForSingleChoice=prefs.getBoolean("voteButtonForSingleChoice", true);
enableDeleteNotifications=prefs.getBoolean("enableDeleteNotifications", false);
translateButtonOpenedOnly=prefs.getBoolean("translateButtonOpenedOnly", false);
uniformNotificationIcon=prefs.getBoolean("uniformNotificationIcon", false);

View File

@@ -599,7 +599,8 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
public void onPollOptionClick(PollOptionStatusDisplayItem.Holder holder){
Poll poll=holder.getItem().poll;
Poll.Option option=holder.getItem().option;
if(poll.multiple || GlobalUserPreferences.voteButtonForSingleChoice){
// MEGALODON: always show vote button
// if(poll.multiple){
if(poll.selectedOptions==null)
poll.selectedOptions=new ArrayList<>();
boolean optionContained=poll.selectedOptions.contains(option);
@@ -614,7 +615,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
for(int i=0;i<list.getChildCount();i++){
RecyclerView.ViewHolder vh=list.getChildViewHolder(list.getChildAt(i));
if(!poll.multiple && vh instanceof PollOptionStatusDisplayItem.Holder item){
if (item != holder) item.itemView.setSelected(false);
if(item!=holder) item.itemView.setSelected(false);
}
if(vh instanceof PollFooterStatusDisplayItem.Holder footer){
if(footer.getItemID().equals(holder.getItemID())){
@@ -623,9 +624,9 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
}
}
}
}else{
submitPollVote(holder.getItemID(), poll.id, Collections.singletonList(poll.options.indexOf(option)));
}
// }else{
// submitPollVote(holder.getItemID(), poll.id, Collections.singletonList(poll.options.indexOf(option)));
// }
}
public void onPollVoteButtonClick(PollFooterStatusDisplayItem.Holder holder){

View File

@@ -1561,8 +1561,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
.withMinute(0);
new DatePickerDialog(getActivity(), (datePicker, year, arrayMonth, dayOfMonth) -> {
new TimePickerDialog(getActivity(), (timePicker, hour, minute) -> {
updateScheduledAt(LocalDateTime.of(year, arrayMonth + 1, dayOfMonth, hour, minute)
.toInstant(OffsetDateTime.now().getOffset()));
LocalDateTime at=LocalDateTime.of(year, arrayMonth + 1, dayOfMonth, hour, minute);
updateScheduledAt(at.toInstant(ZoneId.systemDefault().getRules().getOffset(at)));
}, soon.getHour(), soon.getMinute(), DateFormat.is24HourFormat(getActivity())).show();
}, soon.getYear(), soon.getMonthValue() - 1, soon.getDayOfMonth()).show();
}

View File

@@ -6,7 +6,6 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.model.Poll;
@@ -32,6 +31,7 @@ public class PollFooterStatusDisplayItem extends StatusDisplayItem{
public static class Holder extends StatusDisplayItem.Holder<PollFooterStatusDisplayItem>{
private TextView text;
private Button voteButton, resultsButton;
private ViewGroup wrapper;
public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_poll_footer, parent);
@@ -39,28 +39,30 @@ public class PollFooterStatusDisplayItem extends StatusDisplayItem{
voteButton=findViewById(R.id.vote_btn);
voteButton.setOnClickListener(v->item.parentFragment.onPollVoteButtonClick(this));
resultsButton=findViewById(R.id.results_btn);
wrapper=findViewById(R.id.wrapper);
resultsButton.setOnClickListener(v-> {
item.resultsVisible = !item.resultsVisible;
item.parentFragment.onPollViewResultsButtonClick(this, item.resultsVisible);
rebind();
UiUtils.beginLayoutTransition(wrapper);
});
}
@Override
public void onBind(PollFooterStatusDisplayItem item){
String text=item.parentFragment.getResources().getQuantityString(R.plurals.x_votes, item.poll.votesCount, item.poll.votesCount);
String sep=item.parentFragment.getString(R.string.sk_separator);
if(item.poll.expiresAt!=null && !item.poll.isExpired()){
text+=" "+sep+" "+UiUtils.formatTimeLeft(itemView.getContext(), item.poll.expiresAt);
if(item.poll.multiple)
text+=" "+sep+" "+item.parentFragment.getString(R.string.poll_multiple_choice);
}else if(item.poll.isExpired()){
text+=" "+sep+" "+item.parentFragment.getString(R.string.poll_closed);
}
String sep=" "+item.parentFragment.getString(R.string.sk_separator)+" ";
if(item.poll.expiresAt!=null && !item.poll.isExpired())
text+=sep+UiUtils.formatTimeLeft(itemView.getContext(), item.poll.expiresAt).replaceAll(" ", " ");
else if(item.poll.isExpired())
text+=sep+item.parentFragment.getString(R.string.poll_closed).replaceAll(" ", " ");
if(item.poll.multiple)
text+=sep+item.parentFragment.getString(R.string.sk_poll_multiple_choice).replaceAll(" ", " ");
this.text.setText(text);
resultsButton.setVisibility(item.poll.isExpired() || item.poll.voted ? View.GONE : View.VISIBLE);
resultsButton.setText(item.resultsVisible ? R.string.sk_poll_view : R.string.sk_poll_results);
voteButton.setVisibility(item.poll.isExpired() || item.poll.voted || (!item.poll.multiple && !GlobalUserPreferences.voteButtonForSingleChoice) ? View.GONE : View.VISIBLE);
resultsButton.setText(item.resultsVisible ? R.string.sk_poll_hide_results : R.string.sk_poll_show_results);
resultsButton.setSelected(item.resultsVisible);
voteButton.setVisibility(item.poll.isExpired() || item.poll.voted ? View.GONE : View.VISIBLE);
voteButton.setEnabled(item.poll.selectedOptions!=null && !item.poll.selectedOptions.isEmpty() && !item.resultsVisible);
}
}