From d6ef3e43821571e3cbc1dfcd7946653709cfa694 Mon Sep 17 00:00:00 2001 From: tom79 Date: Thu, 18 Apr 2019 18:01:44 +0200 Subject: [PATCH] Some changes --- .../asynctasks/ManagePollAsyncTask.java | 10 +++++-- .../fr/gouv/etalab/mastodon/client/API.java | 3 +- .../mastodon/drawers/StatusListAdapter.java | 30 ++++++++++++++----- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +-- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java index 9df82ac9e..282617161 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java @@ -53,10 +53,16 @@ public class ManagePollAsyncTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { - if( status.getPoll().getId() == null) + Poll _poll; + if( status.getReblog() != null) + _poll = status.getReblog().getPoll(); + else + _poll = status.getPoll(); + + if( _poll.getId() == null) return null; if (type == type_s.SUBMIT){ - poll = new API(contextReference.get()).submiteVote(status.getPoll().getId(),choices); + poll = new API(contextReference.get()).submiteVote(_poll.getId(),choices); }else if( type == type_s.REFRESH){ poll = new API(contextReference.get()).getPoll(status); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 1563524f1..61d507689 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -2223,8 +2223,9 @@ public class API { */ public Poll getPoll(Status status){ try { + Poll _p = (status.getReblog() != null)?status.getReblog().getPoll():status.getPoll(); HttpsConnection httpsConnection = new HttpsConnection(context); - String response = httpsConnection.get(getAbsoluteUrl(String.format("/polls/%s", status.getPoll().getId())), 60, null, prefKeyOauthTokenT); + String response = httpsConnection.get(getAbsoluteUrl(String.format("/polls/%s", _p.getId())), 60, null, prefKeyOauthTokenT); Poll poll = parsePoll(context, new JSONObject(response)); Bundle b = new Bundle(); status.setPoll(poll); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 83779e78b..e2f00bcf9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -557,18 +557,28 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.multiple_choice.setVisibility(View.GONE); holder.single_choice.setVisibility(View.GONE); holder.submit_vote.setVisibility(View.GONE); - if( status.getPoll() != null && status.getPoll().getOptionsList() != null ){ - Poll poll = status.getPoll(); - int choiceCount = status.getPoll().getOptionsList().size(); + if( (status.getPoll() != null && status.getPoll().getOptionsList() != null) + || (status.getReblog() != null && status.getReblog().getPoll() != null && status.getReblog().getPoll().getOptionsList() != null) + ){ + Poll poll; + int choiceCount; + if( status.getReblog() != null) { + poll = status.getReblog().getPoll(); + choiceCount = status.getReblog().getPoll().getOptionsList().size(); + }else { + poll = status.getPoll(); + choiceCount = status.getPoll().getOptionsList().size(); + } + if( poll.isVoted() || poll.isExpired()){ holder.rated.setVisibility(View.VISIBLE); List items = new ArrayList<>(); int greaterValue = 0; - for(PollOptions pollOption: status.getPoll().getOptionsList()){ + for(PollOptions pollOption: poll.getOptionsList()){ if( pollOption.getVotes_count() > greaterValue) greaterValue = pollOption.getVotes_count(); } - for(PollOptions pollOption: status.getPoll().getOptionsList()){ + for(PollOptions pollOption: poll.getOptionsList()){ double value = ((double)(pollOption.getVotes_count()* 100) / (double)poll.getVotes_count()) ; if( pollOption.getVotes_count() == greaterValue) { BarItem bar = new BarItem(pollOption.getTitle(), value, "%", ContextCompat.getColor(context, R.color.mastodonC4), Color.WHITE); @@ -598,7 +608,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if( choiceCount > 3) holder.c_choice_4.setVisibility(View.VISIBLE); int j = 1; - for(PollOptions pollOption: status.getPoll().getOptionsList()){ + for(PollOptions pollOption: poll.getOptionsList()){ if( j == 1 ) holder.c_choice_1.setText(pollOption.getTitle()); else if( j == 2 ) @@ -619,7 +629,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if( choiceCount > 3) holder.r_choice_4.setVisibility(View.VISIBLE); int j = 1; - for(PollOptions pollOption: status.getPoll().getOptionsList()){ + for(PollOptions pollOption: poll.getOptionsList()){ if( j == 1 ) holder.r_choice_1.setText(pollOption.getTitle()); else if( j == 2 ) @@ -675,7 +685,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } }); holder.poll_container.setVisibility(View.VISIBLE); - holder.number_votes.setText(context.getResources().getQuantityString(R.plurals.number_of_vote,status.getPoll().getVotes_count(),status.getPoll().getVotes_count())); + holder.number_votes.setText(context.getResources().getQuantityString(R.plurals.number_of_vote,poll.getVotes_count(),poll.getVotes_count())); holder.remaining_time.setText(context.getString(R.string.poll_finish_at, Helper.dateToStringPoll(poll.getExpires_at()))); }else { holder.poll_container.setVisibility(View.GONE); @@ -2536,6 +2546,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct toot.setVisibility(status.getVisibility()); if( status.getPoll() != null){ toot.setPoll(status.getPoll()); + }else if(status.getReblog() != null && status.getReblog().getPoll() != null ) { + toot.setPoll(status.getPoll()); } new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { @@ -2548,6 +2560,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct toot.setContent(status.getContent()); if( status.getPoll() != null){ toot.setPoll(status.getPoll()); + }else if(status.getReblog() != null && status.getReblog().getPoll() != null ) { + toot.setPoll(status.getPoll()); } final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); long id = new StatusStoredDAO(context, db).insertStatus(toot, null); diff --git a/build.gradle b/build.gradle index 2d45a15b1..748746728 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.4.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d3d98894..99b4c2351 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 17 11:18:18 CET 2019 +#Thu Apr 18 13:00:25 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip