summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authortom79 <tschneider.ac@gmail.com>2020-04-09 14:09:43 +0200
committertom79 <tschneider.ac@gmail.com>2020-04-09 14:09:43 +0200
commit1e779ddfc4dba7aab1f3669d21b81cf38a16cfac (patch)
tree773fa3c183ad1a52eae30f7df0762a8a12fa6cc6 /app/src/main/java
parent5855ac8b7ed2e4783cc78646c88aa0b3acddd6c2 (diff)
some improvements
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/fedilab/android/client/API.java34
-rw-r--r--app/src/main/java/app/fedilab/android/client/Entities/Poll.java88
-rw-r--r--app/src/main/java/app/fedilab/android/client/Entities/Status.java2
-rw-r--r--app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java46
-rw-r--r--app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java47
5 files changed, 108 insertions, 109 deletions
diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java
index 8a7a59fd4..f2c726a57 100644
--- a/app/src/main/java/app/fedilab/android/client/API.java
+++ b/app/src/main/java/app/fedilab/android/client/API.java
@@ -705,6 +705,13 @@ public class API {
pollOptions.add(pollOption);
}
poll.setOptionsList(pollOptions);
+ JSONArray own_votes = resobj.getJSONArray("own_votes");
+ List<Integer> own_votes_list = new ArrayList<>();
+ for (int i = 0; i < own_votes.length(); i++) {
+ int own_vote = own_votes.getInt(i);
+ own_votes_list.add(own_vote);
+ }
+ poll.setOwn_votes(own_votes_list);
} catch (JSONException | ParseException e) {
e.printStackTrace();
}
@@ -884,32 +891,7 @@ public class API {
}
if (resobj.has("poll") && !resobj.isNull("poll")) {
- Poll poll = new Poll();
- poll.setId(resobj.getJSONObject("poll").getString("id"));
- try {
- poll.setExpires_at(Helper.mstStringToDate(resobj.getJSONObject("poll").getString("expires_at")));
- } catch (Exception e) {
- poll.setExpires_at(new Date());
- }
- poll.setExpired(resobj.getJSONObject("poll").getBoolean("expired"));
- poll.setMultiple(resobj.getJSONObject("poll").getBoolean("multiple"));
- poll.setVotes_count(resobj.getJSONObject("poll").getInt("votes_count"));
- if (resobj.getJSONObject("poll").has("voters_count") && !resobj.getJSONObject("poll").isNull("voters_count")) {
- poll.setVoters_count(resobj.getJSONObject("poll").getInt("voters_count"));
- } else {
- poll.setVoters_count(resobj.getJSONObject("poll").getInt("votes_count"));
- }
- poll.setVoted(resobj.getJSONObject("poll").getBoolean("voted"));
- JSONArray options = resobj.getJSONObject("poll").getJSONArray("options");
- List<PollOptions> pollOptions = new ArrayList<>();
- for (int i = 0; i < options.length(); i++) {
- JSONObject option = options.getJSONObject(i);
- PollOptions pollOption = new PollOptions();
- pollOption.setTitle(option.getString("title"));
- pollOption.setVotes_count(option.getInt("votes_count"));
- pollOptions.add(pollOption);
- }
- poll.setOptionsList(pollOptions);
+ Poll poll = parsePoll(context, resobj.getJSONObject("poll"));
status.setPoll(poll);
}
diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Poll.java b/app/src/main/java/app/fedilab/android/client/Entities/Poll.java
index 85ba55b60..38e711369 100644
--- a/app/src/main/java/app/fedilab/android/client/Entities/Poll.java
+++ b/app/src/main/java/app/fedilab/android/client/Entities/Poll.java
@@ -18,22 +18,12 @@ package app.fedilab.android.client.Entities;
import android.os.Parcel;
import android.os.Parcelable;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Poll implements Parcelable {
- public static final Parcelable.Creator<Poll> CREATOR = new Parcelable.Creator<Poll>() {
- @Override
- public Poll createFromParcel(Parcel source) {
- return new Poll(source);
- }
-
- @Override
- public Poll[] newArray(int size) {
- return new Poll[size];
- }
- };
private String id;
private Date expires_at;
private int expires_in;
@@ -44,24 +34,11 @@ public class Poll implements Parcelable {
private boolean voted;
private List<PollOptions> optionsList;
private List<Emojis> emojis;
+ private List<Integer> own_votes;
public Poll() {
}
- protected Poll(Parcel in) {
- this.id = in.readString();
- long tmpExpires_at = in.readLong();
- this.expires_at = tmpExpires_at == -1 ? null : new Date(tmpExpires_at);
- this.expires_in = in.readInt();
- this.expired = in.readByte() != 0;
- this.multiple = in.readByte() != 0;
- this.votes_count = in.readInt();
- this.voters_count = in.readInt();
- this.voted = in.readByte() != 0;
- this.optionsList = in.createTypedArrayList(PollOptions.CREATOR);
- this.emojis = in.createTypedArrayList(Emojis.CREATOR);
- }
-
public String getId() {
return id;
}
@@ -126,6 +103,30 @@ public class Poll implements Parcelable {
this.expires_in = expires_in;
}
+ public int getVoters_count() {
+ return voters_count;
+ }
+
+ public void setVoters_count(int voters_count) {
+ this.voters_count = voters_count;
+ }
+
+ public List<Emojis> getEmojis() {
+ return emojis;
+ }
+
+ public void setEmojis(List<Emojis> emojis) {
+ this.emojis = emojis;
+ }
+
+ public List<Integer> getOwn_votes() {
+ return own_votes;
+ }
+
+ public void setOwn_votes(List<Integer> own_votes) {
+ this.own_votes = own_votes;
+ }
+
@Override
public int describeContents() {
return 0;
@@ -143,21 +144,34 @@ public class Poll implements Parcelable {
dest.writeByte(this.voted ? (byte) 1 : (byte) 0);
dest.writeTypedList(this.optionsList);
dest.writeTypedList(this.emojis);
+ dest.writeList(this.own_votes);
}
- public int getVoters_count() {
- return voters_count;
- }
-
- public void setVoters_count(int voters_count) {
- this.voters_count = voters_count;
+ protected Poll(Parcel in) {
+ this.id = in.readString();
+ long tmpExpires_at = in.readLong();
+ this.expires_at = tmpExpires_at == -1 ? null : new Date(tmpExpires_at);
+ this.expires_in = in.readInt();
+ this.expired = in.readByte() != 0;
+ this.multiple = in.readByte() != 0;
+ this.votes_count = in.readInt();
+ this.voters_count = in.readInt();
+ this.voted = in.readByte() != 0;
+ this.optionsList = in.createTypedArrayList(PollOptions.CREATOR);
+ this.emojis = in.createTypedArrayList(Emojis.CREATOR);
+ this.own_votes = new ArrayList<>();
+ in.readList(this.own_votes, Integer.class.getClassLoader());
}
- public List<Emojis> getEmojis() {
- return emojis;
- }
+ public static final Creator<Poll> CREATOR = new Creator<Poll>() {
+ @Override
+ public Poll createFromParcel(Parcel source) {
+ return new Poll(source);
+ }
- public void setEmojis(List<Emojis> emojis) {
- this.emojis = emojis;
- }
+ @Override
+ public Poll[] newArray(int size) {
+ return new Poll[size];
+ }
+ };
}
diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java
index a8556f95f..02948752e 100644
--- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java
+++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java
@@ -925,7 +925,7 @@ public class Status implements Parcelable {
}
public static void makeEmojiPoll(final Context context, Poll poll) {
- if (((Activity) context).isFinishing())
+ if (((Activity) context).isFinishing() || poll == null)
return;
final List<Emojis> emojis = poll.getEmojis();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
diff --git a/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java
index 59e30f840..f6ebbe28c 100644
--- a/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java
+++ b/app/src/main/java/app/fedilab/android/drawers/NotificationsListAdapter.java
@@ -14,12 +14,14 @@ package app.fedilab.android.drawers;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
+import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
+import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
@@ -39,6 +41,7 @@ import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
@@ -61,6 +64,7 @@ import com.varunest.sparkbutton.SparkButton;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@@ -103,8 +107,6 @@ import app.fedilab.android.interfaces.OnPostNotificationsActionInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
import app.fedilab.android.interfaces.OnRetrieveImageInterface;
-import br.com.felix.horizontalbargraph.HorizontalBar;
-import br.com.felix.horizontalbargraph.model.BarItem;
import es.dmoral.toasty.Toasty;
import static android.content.Context.MODE_PRIVATE;
@@ -531,34 +533,34 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
Poll poll = status.getPoll();
if (poll.isVoted() || poll.isExpired()) {
holder.rated.setVisibility(View.VISIBLE);
- List<BarItem> items = new ArrayList<>();
int greaterValue = 0;
for (PollOptions pollOption : status.getPoll().getOptionsList()) {
if (pollOption.getVotes_count() > greaterValue)
greaterValue = pollOption.getVotes_count();
}
- for (PollOptions pollOption : status.getPoll().getOptionsList()) {
+ LayoutInflater inflater = ((Activity)context).getLayoutInflater();
+ holder.rated.removeAllViews();
+ List<Integer> ownvotes = poll.getOwn_votes();
+ int j = 0;
+ for (PollOptions pollOption : poll.getOptionsList()) {
+ View item = inflater.inflate(R.layout.layout_poll_item, new LinearLayout(context), false);
double value = ((double) (pollOption.getVotes_count() * 100) / (double) poll.getVoters_count());
- if (pollOption.getVotes_count() == greaterValue) {
- BarItem bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC4), Color.WHITE);
- bar.setRounded(true);
- bar.setHeight1(30);
- items.add(bar);
- } else {
- BarItem bar;
- if (theme == Helper.THEME_LIGHT)
- bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC2), Color.BLACK);
- else
- bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC2), Color.WHITE);
- bar.setRounded(true);
- bar.setHeight1(30);
- items.add(bar);
+ TextView poll_item_percent = item.findViewById(R.id.poll_item_percent);
+ TextView poll_item_text = item.findViewById(R.id.poll_item_text);
+ ProgressBar poll_item_value = item.findViewById(R.id.poll_item_value);
+ poll_item_percent.setText(String.format("%s %%", String.valueOf((int)value)));
+ poll_item_text.setText(pollOption.getTitle(), TextView.BufferType.SPANNABLE);
+ poll_item_value.setProgress((int)value);
+ holder.rated.addView(item);
+ if (ownvotes.contains(j)) {
+ Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_check_poll);
+ assert img != null;
+ img.setColorFilter(ContextCompat.getColor(context, R.color.cyanea_accent_reference), PorterDuff.Mode.SRC_IN);
+ img.setBounds(0, 0, (int) (20 * scale + 0.5f), (int) (20 * scale + 0.5f));
+ poll_item_text.setCompoundDrawables(null, null, img, null);
}
+ j++;
}
- holder.rated.removeAllViews();
- HorizontalBar horizontalBar = new HorizontalBar(context);
- horizontalBar.hasAnimation(true).addAll(items).build();
- holder.rated.addView(horizontalBar);
} else {
if (poll.isMultiple()) {
if ((holder.multiple_choice).getChildCount() > 0)
diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java
index fa0691bb5..4d09c529e 100644
--- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java
+++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java
@@ -24,6 +24,7 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Color;
+import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
@@ -62,6 +63,7 @@ import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
@@ -100,7 +102,9 @@ import com.varunest.sparkbutton.SparkButton;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
@@ -176,8 +180,6 @@ import app.fedilab.android.sqlite.StatusStoredDAO;
import app.fedilab.android.sqlite.TempMuteDAO;
import app.fedilab.android.sqlite.TimelineCacheDAO;
import app.fedilab.android.sqlite.TimelinesDAO;
-import br.com.felix.horizontalbargraph.HorizontalBar;
-import br.com.felix.horizontalbargraph.model.BarItem;
import es.dmoral.toasty.Toasty;
import jp.wasabeef.glide.transformations.BlurTransformation;
@@ -742,36 +744,35 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if (poll != null && poll.getOptionsList() != null) {
if (poll.isVoted() || poll.isExpired()) {
holder.rated.setVisibility(View.VISIBLE);
- List<BarItem> items = new ArrayList<>();
int greaterValue = 0;
for (PollOptions pollOption : poll.getOptionsList()) {
if (pollOption.getVotes_count() > greaterValue)
greaterValue = pollOption.getVotes_count();
}
+ LayoutInflater inflater = ((Activity)context).getLayoutInflater();
+ holder.rated.removeAllViews();
+ List<Integer> ownvotes = poll.getOwn_votes();
+ int j = 0;
for (PollOptions pollOption : poll.getOptionsList()) {
+ View item = inflater.inflate(R.layout.layout_poll_item, new LinearLayout(context), false);
double value = ((double) (pollOption.getVotes_count() * 100) / (double) poll.getVoters_count());
- if (pollOption.getVotes_count() == greaterValue) {
- BarItem bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC4), Color.WHITE);
- bar.setDescriptionSpan(pollOption.getTitleSpan());
- bar.setRounded(true);
- bar.setHeight1(30);
- items.add(bar);
- } else {
- BarItem bar;
- if (theme == Helper.THEME_LIGHT)
- bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC2), Color.BLACK);
- else
- bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC2), Color.WHITE);
- bar.setDescriptionSpan(pollOption.getTitleSpan());
- bar.setRounded(true);
- bar.setHeight1(30);
- items.add(bar);
+ TextView poll_item_percent = item.findViewById(R.id.poll_item_percent);
+ TextView poll_item_text = item.findViewById(R.id.poll_item_text);
+ ProgressBar poll_item_value = item.findViewById(R.id.poll_item_value);
+ poll_item_percent.setText(String.format("%s %%", String.valueOf((int)value)));
+ poll_item_text.setText(pollOption.getTitle(), TextView.BufferType.SPANNABLE);
+ poll_item_value.setProgress((int)value);
+ holder.rated.addView(item);
+ if (ownvotes.contains(j)) {
+ Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_check_poll);
+ assert img != null;
+ final float scale = context.getResources().getDisplayMetrics().density;
+ img.setColorFilter(ContextCompat.getColor(context, R.color.cyanea_accent_reference), PorterDuff.Mode.SRC_IN);
+ img.setBounds(0, 0, (int) (20 * scale + 0.5f), (int) (20 * scale + 0.5f));
+ poll_item_text.setCompoundDrawables(null, null, img, null);
}
+ j++;
}
- holder.rated.removeAllViews();
- HorizontalBar horizontalBar = new HorizontalBar(context);
- horizontalBar.hasAnimation(true).addAll(items).build();
- holder.rated.addView(horizontalBar);
} else {
if (poll.isMultiple()) {