|
|
@ -9,22 +9,24 @@ import android.preference.PreferenceManager; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.activities.settings.SettingsActivity; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.DeleteTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.EditTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.PrepareForReply; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.PrepareForReplyResult; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.PrepareForEditResult; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.PrepareForEditTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.ReplyTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.TopicTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.TopicTaskResult; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.DeleteTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReply; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReplyResult; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditTask; |
|
|
|
import gr.thmmy.mthmmy.activities.topic.tasks.ReplyTask; |
|
|
|
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.Post; |
|
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
|
|
|
|
|
public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTaskCompleted, |
|
|
|
PrepareForReply.OnPrepareForReplyFinished, PrepareForEditTask.OnPrepareEditFinished { |
|
|
|
|
|
|
|
/** |
|
|
|
* topic state |
|
|
|
*/ |
|
|
|
private boolean editingPost = false; |
|
|
|
private boolean writingReply = false; |
|
|
|
/** |
|
|
@ -36,6 +38,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
|
private PrepareForEditTask currentPrepareForEditTask; |
|
|
|
private PrepareForReply currentPrepareForReplyTask; |
|
|
|
|
|
|
|
//callbacks for topic activity
|
|
|
|
private TopicTask.TopicTaskObserver topicTaskObserver; |
|
|
|
private DeleteTask.DeleteTaskCallbacks deleteTaskCallbacks; |
|
|
|
private ReplyTask.ReplyTaskCallbacks replyFinishListener; |
|
|
@ -49,116 +52,6 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
|
|
|
|
|
private String firstTopicUrl; |
|
|
|
|
|
|
|
public void setTopicTaskObserver(TopicTask.TopicTaskObserver topicTaskObserver) { |
|
|
|
this.topicTaskObserver = topicTaskObserver; |
|
|
|
} |
|
|
|
|
|
|
|
public void setDeleteTaskCallbacks(DeleteTask.DeleteTaskCallbacks deleteTaskCallbacks) { |
|
|
|
this.deleteTaskCallbacks = deleteTaskCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public void setReplyFinishListener(ReplyTask.ReplyTaskCallbacks replyFinishListener) { |
|
|
|
this.replyFinishListener = replyFinishListener; |
|
|
|
} |
|
|
|
|
|
|
|
public void setPrepareForEditCallbacks(PrepareForEditTask.PrepareForEditCallbacks prepareForEditCallbacks) { |
|
|
|
this.prepareForEditCallbacks = prepareForEditCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public void setEditTaskCallbacks(EditTask.EditTaskCallbacks editTaskCallbacks) { |
|
|
|
this.editTaskCallbacks = editTaskCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public void setPrepareForReplyCallbacks(PrepareForReply.PrepareForReplyCallbacks prepareForReplyCallbacks) { |
|
|
|
this.prepareForReplyCallbacks = prepareForReplyCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public MutableLiveData<TopicTaskResult> getTopicTaskResult() { |
|
|
|
return topicTaskResult; |
|
|
|
} |
|
|
|
|
|
|
|
public MutableLiveData<PrepareForReplyResult> getPrepareForReplyResult() { |
|
|
|
return prepareForReplyResult; |
|
|
|
} |
|
|
|
|
|
|
|
public MutableLiveData<PrepareForEditResult> getPrepareForEditResult() { |
|
|
|
return prepareForEditResult; |
|
|
|
} |
|
|
|
|
|
|
|
public void setEditingPost(boolean editingPost) { |
|
|
|
this.editingPost = editingPost; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isEditingPost() { |
|
|
|
return editingPost; |
|
|
|
} |
|
|
|
|
|
|
|
public int getPostBeingEditedPosition() { |
|
|
|
return postBeingEditedPosition; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean canReply() { |
|
|
|
return topicTaskResult.getValue() != null && topicTaskResult.getValue().getReplyPageUrl() != null; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isWritingReply() { |
|
|
|
return writingReply; |
|
|
|
} |
|
|
|
|
|
|
|
public void setWritingReply(boolean writingReply) { |
|
|
|
this.writingReply = writingReply; |
|
|
|
} |
|
|
|
|
|
|
|
public String getBaseUrl() { |
|
|
|
if (topicTaskResult.getValue() != null) { |
|
|
|
return topicTaskResult.getValue().getBaseUrl(); |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getTopicUrl() { |
|
|
|
if (topicTaskResult.getValue() != null) { |
|
|
|
return topicTaskResult.getValue().getLastPageLoadAttemptedUrl(); |
|
|
|
} else { |
|
|
|
// topic task has not finished yet (log? disable menu button until load is finished?)
|
|
|
|
return firstTopicUrl; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getTopicTitle() { |
|
|
|
if (topicTaskResult.getValue() == null) |
|
|
|
throw new NullPointerException("Topic task has not finished yet!"); |
|
|
|
return topicTaskResult.getValue().getTopicTitle(); |
|
|
|
} |
|
|
|
|
|
|
|
public int getCurrentPageIndex() { |
|
|
|
if (topicTaskResult.getValue() == null) |
|
|
|
throw new NullPointerException("No page has been loaded yet!"); |
|
|
|
return topicTaskResult.getValue().getCurrentPageIndex(); |
|
|
|
} |
|
|
|
|
|
|
|
public int getPageCount() { |
|
|
|
if (topicTaskResult.getValue() == null) |
|
|
|
throw new NullPointerException("No page has been loaded yet!"); |
|
|
|
|
|
|
|
return topicTaskResult.getValue().getPageCount(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getPostBeingEditedText() { |
|
|
|
if (prepareForEditResult.getValue() == null) |
|
|
|
throw new NullPointerException("Edit preparation was not found!"); |
|
|
|
return prepareForEditResult.getValue().getPostText(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getBuildedQuotes() { |
|
|
|
if (prepareForReplyResult.getValue() != null) { |
|
|
|
return prepareForReplyResult.getValue().getBuildedQuotes(); |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void initialLoad(String pageUrl) { |
|
|
|
firstTopicUrl = pageUrl; |
|
|
|
currentTopicTask = new TopicTask(topicTaskObserver, this); |
|
|
@ -257,6 +150,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
|
// after he is done posting, editing or deleting
|
|
|
|
} |
|
|
|
|
|
|
|
// callbacks for viewmodel
|
|
|
|
@Override |
|
|
|
public void onTopicTaskCompleted(TopicTaskResult result) { |
|
|
|
topicTaskResult.setValue(result); |
|
|
@ -274,4 +168,116 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa |
|
|
|
postBeingEditedPosition = position; |
|
|
|
prepareForEditResult.setValue(result); |
|
|
|
} |
|
|
|
|
|
|
|
// <-------------Just getters, setters and helper methods below here---------------->
|
|
|
|
|
|
|
|
public void setTopicTaskObserver(TopicTask.TopicTaskObserver topicTaskObserver) { |
|
|
|
this.topicTaskObserver = topicTaskObserver; |
|
|
|
} |
|
|
|
|
|
|
|
public void setDeleteTaskCallbacks(DeleteTask.DeleteTaskCallbacks deleteTaskCallbacks) { |
|
|
|
this.deleteTaskCallbacks = deleteTaskCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public void setReplyFinishListener(ReplyTask.ReplyTaskCallbacks replyFinishListener) { |
|
|
|
this.replyFinishListener = replyFinishListener; |
|
|
|
} |
|
|
|
|
|
|
|
public void setPrepareForEditCallbacks(PrepareForEditTask.PrepareForEditCallbacks prepareForEditCallbacks) { |
|
|
|
this.prepareForEditCallbacks = prepareForEditCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public void setEditTaskCallbacks(EditTask.EditTaskCallbacks editTaskCallbacks) { |
|
|
|
this.editTaskCallbacks = editTaskCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public void setPrepareForReplyCallbacks(PrepareForReply.PrepareForReplyCallbacks prepareForReplyCallbacks) { |
|
|
|
this.prepareForReplyCallbacks = prepareForReplyCallbacks; |
|
|
|
} |
|
|
|
|
|
|
|
public MutableLiveData<TopicTaskResult> getTopicTaskResult() { |
|
|
|
return topicTaskResult; |
|
|
|
} |
|
|
|
|
|
|
|
public MutableLiveData<PrepareForReplyResult> getPrepareForReplyResult() { |
|
|
|
return prepareForReplyResult; |
|
|
|
} |
|
|
|
|
|
|
|
public MutableLiveData<PrepareForEditResult> getPrepareForEditResult() { |
|
|
|
return prepareForEditResult; |
|
|
|
} |
|
|
|
|
|
|
|
public void setEditingPost(boolean editingPost) { |
|
|
|
this.editingPost = editingPost; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isEditingPost() { |
|
|
|
return editingPost; |
|
|
|
} |
|
|
|
|
|
|
|
public int getPostBeingEditedPosition() { |
|
|
|
return postBeingEditedPosition; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean canReply() { |
|
|
|
return topicTaskResult.getValue() != null && topicTaskResult.getValue().getReplyPageUrl() != null; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isWritingReply() { |
|
|
|
return writingReply; |
|
|
|
} |
|
|
|
|
|
|
|
public void setWritingReply(boolean writingReply) { |
|
|
|
this.writingReply = writingReply; |
|
|
|
} |
|
|
|
|
|
|
|
public String getBaseUrl() { |
|
|
|
if (topicTaskResult.getValue() != null) { |
|
|
|
return topicTaskResult.getValue().getBaseUrl(); |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getTopicUrl() { |
|
|
|
if (topicTaskResult.getValue() != null) { |
|
|
|
return topicTaskResult.getValue().getLastPageLoadAttemptedUrl(); |
|
|
|
} else { |
|
|
|
// topic task has not finished yet (log? disable menu button until load is finished?)
|
|
|
|
return firstTopicUrl; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getTopicTitle() { |
|
|
|
if (topicTaskResult.getValue() == null) |
|
|
|
throw new NullPointerException("Topic task has not finished yet!"); |
|
|
|
return topicTaskResult.getValue().getTopicTitle(); |
|
|
|
} |
|
|
|
|
|
|
|
public int getCurrentPageIndex() { |
|
|
|
if (topicTaskResult.getValue() == null) |
|
|
|
throw new NullPointerException("No page has been loaded yet!"); |
|
|
|
return topicTaskResult.getValue().getCurrentPageIndex(); |
|
|
|
} |
|
|
|
|
|
|
|
public int getPageCount() { |
|
|
|
if (topicTaskResult.getValue() == null) |
|
|
|
throw new NullPointerException("No page has been loaded yet!"); |
|
|
|
|
|
|
|
return topicTaskResult.getValue().getPageCount(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getPostBeingEditedText() { |
|
|
|
if (prepareForEditResult.getValue() == null) |
|
|
|
throw new NullPointerException("Edit preparation was not found!"); |
|
|
|
return prepareForEditResult.getValue().getPostText(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getBuildedQuotes() { |
|
|
|
if (prepareForReplyResult.getValue() != null) { |
|
|
|
return prepareForReplyResult.getValue().getBuildedQuotes(); |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|