|
@ -5,6 +5,9 @@ import android.content.Context; |
|
|
import android.content.SharedPreferences; |
|
|
import android.content.SharedPreferences; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.AsyncTask; |
|
|
import android.preference.PreferenceManager; |
|
|
import android.preference.PreferenceManager; |
|
|
|
|
|
import android.widget.CheckBox; |
|
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
|
import android.widget.RadioGroup; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
@ -16,12 +19,17 @@ import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditTask; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReply; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReply; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReplyResult; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReplyResult; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.ReplyTask; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.ReplyTask; |
|
|
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.SubmitVoteTask; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.TopicTask; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.TopicTask; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.TopicTaskResult; |
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.TopicTaskResult; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
|
|
|
import gr.thmmy.mthmmy.model.Poll; |
|
|
import gr.thmmy.mthmmy.model.Post; |
|
|
import gr.thmmy.mthmmy.model.Post; |
|
|
import gr.thmmy.mthmmy.model.TopicItem; |
|
|
import gr.thmmy.mthmmy.model.TopicItem; |
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
|
|
|
import gr.thmmy.mthmmy.utils.ExternalAsyncTask; |
|
|
|
|
|
import gr.thmmy.mthmmy.utils.NetworkResultCodes; |
|
|
|
|
|
import gr.thmmy.mthmmy.utils.NetworkTask; |
|
|
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; |
|
|
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; |
|
|
import timber.log.Timber; |
|
|
import timber.log.Timber; |
|
|
|
|
|
|
|
@ -44,7 +52,6 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
* holds the adapter position of the post being edited |
|
|
* holds the adapter position of the post being edited |
|
|
*/ |
|
|
*/ |
|
|
private int postBeingEditedPosition; |
|
|
private int postBeingEditedPosition; |
|
|
private ArrayList<Integer> selectedVoteIndices = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
private TopicTask currentTopicTask; |
|
|
private TopicTask currentTopicTask; |
|
|
private PrepareForEditTask currentPrepareForEditTask; |
|
|
private PrepareForEditTask currentPrepareForEditTask; |
|
@ -52,12 +59,14 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
|
|
|
|
|
|
//callbacks for topic activity
|
|
|
//callbacks for topic activity
|
|
|
private TopicTask.TopicTaskObserver topicTaskObserver; |
|
|
private TopicTask.TopicTaskObserver topicTaskObserver; |
|
|
private DeleteTask.OnParseTaskStartedListener deleteTaskStartedListener; |
|
|
private ExternalAsyncTask.OnTaskStartedListener deleteTaskStartedListener; |
|
|
private DeleteTask.OnParseTaskFinishedListener<Void> deleteTaskFinishedListener; |
|
|
private NetworkTask.OnNetworkTaskFinishedListener<Void> deleteTaskFinishedListener; |
|
|
private ReplyTask.ReplyTaskCallbacks replyFinishListener; |
|
|
private ReplyTask.ReplyTaskCallbacks replyFinishListener; |
|
|
private PrepareForEditTask.PrepareForEditCallbacks prepareForEditCallbacks; |
|
|
private PrepareForEditTask.PrepareForEditCallbacks prepareForEditCallbacks; |
|
|
private EditTask.EditTaskCallbacks editTaskCallbacks; |
|
|
private EditTask.EditTaskCallbacks editTaskCallbacks; |
|
|
private PrepareForReply.PrepareForReplyCallbacks prepareForReplyCallbacks; |
|
|
private PrepareForReply.PrepareForReplyCallbacks prepareForReplyCallbacks; |
|
|
|
|
|
private ExternalAsyncTask.OnTaskStartedListener voteTaskStartedListener; |
|
|
|
|
|
private NetworkTask.OnNetworkTaskFinishedListener<Void> voteTaskFinishedListener; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Holds the value (index) of the page to be requested when a user interaction with bottom |
|
|
* Holds the value (index) of the page to be requested when a user interaction with bottom |
|
@ -106,16 +115,25 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void viewVoteResults() { |
|
|
public void submitVote(LinearLayout optionsLayout) { |
|
|
if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); |
|
|
if (topicItems.getValue() == null) throw new NullPointerException("Topic task has not finished yet!"); |
|
|
Timber.i("Viewing poll results"); |
|
|
ArrayList<Integer> votes = new ArrayList<>(); |
|
|
loadUrl(ParseHelpers.getBaseURL(topicUrl) + ";viewResults"); |
|
|
if (optionsLayout.getChildAt(0) instanceof RadioGroup) { |
|
|
|
|
|
RadioGroup optionsRadioGroup = (RadioGroup) optionsLayout.getChildAt(0); |
|
|
|
|
|
votes.add(optionsRadioGroup.getCheckedRadioButtonId()); |
|
|
|
|
|
} else if (optionsLayout.getChildAt(0) instanceof CheckBox) { |
|
|
|
|
|
for (int i = 0; i < optionsLayout.getChildCount(); i++) { |
|
|
|
|
|
if (((CheckBox) optionsLayout.getChildAt(i)).isChecked()) |
|
|
|
|
|
votes.add(i); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
public void loadBaseUrl() { |
|
|
int[] votesArray = new int[votes.size()]; |
|
|
if (topicUrl == null) throw new NullPointerException("No topic task has been requested yet!"); |
|
|
for (int i = 0; i < votes.size(); i++) votesArray[i] = votes.get(i); |
|
|
Timber.i("Viewing poll results"); |
|
|
Poll poll = (Poll) topicItems.getValue().get(0); |
|
|
loadUrl(ParseHelpers.getBaseURL(topicUrl)); |
|
|
SubmitVoteTask submitVoteTask = new SubmitVoteTask(votesArray); |
|
|
|
|
|
submitVoteTask.setOnTaskStartedListener(voteTaskStartedListener); |
|
|
|
|
|
submitVoteTask.setOnNetworkTaskFinishedListener(voteTaskFinishedListener); |
|
|
|
|
|
submitVoteTask.execute(poll.getPollFormUrl(), poll.getSc()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void prepareForReply() { |
|
|
public void prepareForReply() { |
|
@ -259,17 +277,16 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
if (changePage && oldIndicatorIndex != this.pageIndicatorIndex.getValue()) performPageChange(); |
|
|
if (changePage && oldIndicatorIndex != this.pageIndicatorIndex.getValue()) performPageChange(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void onVoteCheckboxClicked(int index, boolean checked) { |
|
|
// <-------------Just getters, setters and helper methods below here---------------->
|
|
|
if (checked) selectedVoteIndices.add(index); |
|
|
|
|
|
else selectedVoteIndices.remove(index); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onRadioButtonCLicked(int index) { |
|
|
public void setVoteTaskStartedListener(ExternalAsyncTask.OnTaskStartedListener voteTaskStartedListener) { |
|
|
selectedVoteIndices.clear(); |
|
|
this.voteTaskStartedListener = voteTaskStartedListener; |
|
|
selectedVoteIndices.add(index); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// <-------------Just getters, setters and helper methods below here---------------->
|
|
|
public void setVoteTaskFinishedListener(NetworkTask.OnNetworkTaskFinishedListener<Void> voteTaskFinishedListener) { |
|
|
|
|
|
this.voteTaskFinishedListener = voteTaskFinishedListener; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public MutableLiveData<String> getTopicViewers() { |
|
|
public MutableLiveData<String> getTopicViewers() { |
|
|
return topicViewers; |
|
|
return topicViewers; |
|
@ -339,11 +356,11 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setDeleteTaskStartedListener(DeleteTask.OnParseTaskStartedListener deleteTaskStartedListener) { |
|
|
public void setDeleteTaskStartedListener(ExternalAsyncTask.OnTaskStartedListener deleteTaskStartedListener) { |
|
|
this.deleteTaskStartedListener = deleteTaskStartedListener; |
|
|
this.deleteTaskStartedListener = deleteTaskStartedListener; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setDeleteTaskFinishedListener(DeleteTask.OnParseTaskFinishedListener<Void> deleteTaskFinishedListener) { |
|
|
public void setDeleteTaskFinishedListener(NetworkTask.OnNetworkTaskFinishedListener<Void> deleteTaskFinishedListener) { |
|
|
this.deleteTaskFinishedListener = deleteTaskFinishedListener; |
|
|
this.deleteTaskFinishedListener = deleteTaskFinishedListener; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|