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