Skip to content

Commit

Permalink
change view results layout, remove unused setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sk22 committed Nov 27, 2023
1 parent f244c17 commit 2f2f4b6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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;
Expand Down Expand Up @@ -99,7 +98,6 @@ public static void load(){
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ protected void updatePoll(String itemID, Status status, Poll poll){
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);
Expand All @@ -531,7 +532,7 @@ public void onPollOptionClick(PollOptionStatusDisplayItem.Holder holder){
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())){
Expand All @@ -540,9 +541,9 @@ public void onPollOptionClick(PollOptionStatusDisplayItem.Holder holder){
}
}
}
}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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
Expand All @@ -29,35 +28,38 @@ public Type getType(){
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);
text=findViewById(R.id.text);
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);
}
}
Expand Down
53 changes: 31 additions & 22 deletions mastodon/src/main/res/layout/display_item_poll_footer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,45 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/text"
<LinearLayout
android:id="@+id/wrapper"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="12dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textAppearance="@style/m3_body_medium"
android:gravity="center_vertical"
android:textColor="?colorM3OnSurfaceVariant"
tools:text="fdsafdsafsdafds"/>
android:layout_height="wrap_content">

<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginVertical="6dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textAppearance="@style/m3_body_medium"
android:layout_gravity="center_vertical"
android:textColor="?colorM3OnSurfaceVariant"
tools:text="fdsafdsafsdafds"/>

<Button
android:id="@+id/results_btn"
style="@style/Widget.Mastodon.M3.Button.Tonal"
android:background="@drawable/bg_button_m3_tonal_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:layout_marginVertical="4dp"
android:textAppearance="@style/m3_label_small"
android:text="@string/sk_poll_show_results"/>

</LinearLayout>

<Button
android:id="@+id/results_btn"
style="@style/Widget.Mastodon.M3.Button.Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:minHeight="48dp"
android:textAppearance="@style/m3_label_small"
android:textAllCaps="true"
android:text="@string/sk_poll_results"/>
<Button
android:id="@+id/vote_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginBottom="4dp"
android:layout_marginTop="-4dp"
android:enabled="false"
style="@style/Widget.Mastodon.M3.Button.Filled.Elevated"
android:text="@string/action_vote"/>
Expand Down
2 changes: 0 additions & 2 deletions mastodon/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,4 @@
<string name="manage_list_members">Manage list members</string>
<string name="list_no_members">No members yet</string>
<string name="list_find_users">Find users to add</string>
<string name="sk_poll_results">View results</string>
<string name="sk_poll_view">Hide results</string>
</resources>
2 changes: 2 additions & 0 deletions mastodon/src/main/res/values/strings_sk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,6 @@
<string name="sk_open_post_preview">Preview post</string>
<string name="sk_post_preview">Preview</string>
<string name="sk_poll_multiple_choice">Multiple choices</string>
<string name="sk_poll_show_results">Show results</string>
<string name="sk_poll_hide_results">Hide results</string>
</resources>
12 changes: 6 additions & 6 deletions mastodon/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,24 +334,24 @@

<style name="m3_body_large">
<item name="android:textSize">16sp</item>
<item name="android:lineSpacingExtra">5dp</item>
<item name="android:lineSpacingExtra">5sp</item>
<item name="android:lineHeight" tools:ignore="NewApi">24dp</item>
</style>

<style name="m3_body_medium">
<item name="android:textSize">14sp</item>
<item name="android:lineSpacingExtra">4dp</item>
<item name="android:lineSpacingExtra">4sp</item>
</style>

<style name="m3_body_small">
<item name="android:textSize">12sp</item>
<item name="android:lineSpacingExtra">2dp</item>
<item name="android:lineSpacingExtra">2sp</item>
</style>

<style name="m3_title_medium">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">16sp</item>
<item name="android:lineSpacingExtra">5dp</item>
<item name="android:lineSpacingExtra">5sp</item>
</style>

<style name="m3_title_small">
Expand All @@ -362,7 +362,7 @@
<style name="m3_label_small">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">11sp</item>
<item name="android:lineSpacingExtra">3dp</item>
<item name="android:lineSpacingExtra">3sp</item>
</style>

<style name="m3_label_medium">
Expand Down Expand Up @@ -403,7 +403,7 @@

<style name="m3_headline_medium">
<item name="android:textSize">28sp</item>
<item name="android:lineSpacingExtra">3dp</item>
<item name="android:lineSpacingExtra">3sp</item>
</style>

<style name="window_fade_out">
Expand Down

0 comments on commit 2f2f4b6

Please sign in to comment.