Commit d6ef3e43 authored by Thomas's avatar Thomas

Some changes

parent a85ca833
......@@ -53,10 +53,16 @@ public class ManagePollAsyncTask extends AsyncTask<Void, Void, Void> {
@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);
}
......
......@@ -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);
......
......@@ -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<BarItem> 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);
......
......@@ -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
......
#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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment