|
|
@ -12,7 +12,6 @@ import android.os.Bundle; |
|
|
|
import android.os.Handler; |
|
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
|
import android.support.design.widget.Snackbar; |
|
|
|
import android.support.v4.content.ContextCompat; |
|
|
|
import android.support.v4.content.res.ResourcesCompat; |
|
|
|
import android.support.v7.app.AlertDialog; |
|
|
|
import android.support.v7.app.AppCompatDelegate; |
|
|
@ -50,6 +49,7 @@ import gr.thmmy.mthmmy.editorview.EmojiKeyboard; |
|
|
|
import gr.thmmy.mthmmy.model.Bookmark; |
|
|
|
import gr.thmmy.mthmmy.model.Post; |
|
|
|
import gr.thmmy.mthmmy.model.ThmmyPage; |
|
|
|
import gr.thmmy.mthmmy.model.TopicItem; |
|
|
|
import gr.thmmy.mthmmy.utils.CustomLinearLayoutManager; |
|
|
|
import gr.thmmy.mthmmy.utils.HTMLUtils; |
|
|
|
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; |
|
|
@ -85,7 +85,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
/** |
|
|
|
* Holds a list of this topic's posts |
|
|
|
*/ |
|
|
|
private ArrayList<Post> postsList; |
|
|
|
private ArrayList<TopicItem> topicItems; |
|
|
|
//Reply related
|
|
|
|
private FloatingActionButton replyFAB; |
|
|
|
//Topic's pages related
|
|
|
@ -170,7 +170,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
progressBar = findViewById(R.id.progressBar); |
|
|
|
emojiKeyboard = findViewById(R.id.emoji_keyboard); |
|
|
|
|
|
|
|
postsList = new ArrayList<>(); |
|
|
|
topicItems = new ArrayList<>(); |
|
|
|
|
|
|
|
recyclerView = findViewById(R.id.topic_recycler_view); |
|
|
|
recyclerView.setHasFixedSize(true); |
|
|
@ -179,7 +179,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
getApplicationContext(), topicPageUrl); |
|
|
|
|
|
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
|
topicAdapter = new TopicAdapter(this, postsList); |
|
|
|
topicAdapter = new TopicAdapter(this, topicItems); |
|
|
|
recyclerView.setAdapter(topicAdapter); |
|
|
|
|
|
|
|
replyFAB = findViewById(R.id.topic_fab); |
|
|
@ -280,15 +280,15 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
} |
|
|
|
return; |
|
|
|
} else if (viewModel.isWritingReply()) { |
|
|
|
postsList.remove(postsList.size() - 1); |
|
|
|
topicAdapter.notifyItemRemoved(postsList.size()); |
|
|
|
topicItems.remove(topicItems.size() - 1); |
|
|
|
topicAdapter.notifyItemRemoved(topicItems.size()); |
|
|
|
topicAdapter.setBackButtonHidden(); |
|
|
|
viewModel.setWritingReply(false); |
|
|
|
replyFAB.show(); |
|
|
|
bottomNavBar.setVisibility(View.VISIBLE); |
|
|
|
return; |
|
|
|
} else if (viewModel.isEditingPost()) { |
|
|
|
postsList.get(viewModel.getPostBeingEditedPosition()).setPostType(Post.TYPE_POST); |
|
|
|
((Post) topicItems.get(viewModel.getPostBeingEditedPosition())).setPostType(Post.TYPE_POST); |
|
|
|
topicAdapter.notifyItemChanged(viewModel.getPostBeingEditedPosition()); |
|
|
|
topicAdapter.setBackButtonHidden(); |
|
|
|
viewModel.setEditingPost(false); |
|
|
@ -538,7 +538,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
replyFAB.show(); |
|
|
|
bottomNavBar.setVisibility(View.VISIBLE); |
|
|
|
viewModel.setWritingReply(false); |
|
|
|
if ((postsList.get(postsList.size() - 1).getPostNumber() + 1) % 15 == 0) { |
|
|
|
if ((((Post) topicItems.get(topicItems.size() - 1)).getPostNumber() + 1) % 15 == 0) { |
|
|
|
Timber.i("Reply was posted in new page. Switching to last page."); |
|
|
|
viewModel.loadUrl(ParseHelpers.getBaseURL(viewModel.getTopicUrl()) + "." + 2147483647); |
|
|
|
} else { |
|
|
@ -547,8 +547,8 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
} else { |
|
|
|
Timber.w("Post reply unsuccessful"); |
|
|
|
Toast.makeText(getBaseContext(), "Post failed!", Toast.LENGTH_SHORT).show(); |
|
|
|
recyclerView.getChildAt(postsList.size() - 1).setAlpha(1); |
|
|
|
recyclerView.getChildAt(postsList.size() - 1).setEnabled(true); |
|
|
|
recyclerView.getChildAt(topicItems.size() - 1).setAlpha(1); |
|
|
|
recyclerView.getChildAt(topicItems.size() - 1).setEnabled(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
@ -581,7 +581,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
|
|
|
|
if (result) { |
|
|
|
Timber.i("Post edit successful"); |
|
|
|
postsList.get(position).setPostType(Post.TYPE_POST); |
|
|
|
((Post) topicItems.get(position)).setPostType(Post.TYPE_POST); |
|
|
|
topicAdapter.notifyItemChanged(position); |
|
|
|
replyFAB.show(); |
|
|
|
bottomNavBar.setVisibility(View.VISIBLE); |
|
|
@ -631,11 +631,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
else |
|
|
|
replyFAB.show(); |
|
|
|
}); |
|
|
|
viewModel.getPostsList().observe(this, postList -> { |
|
|
|
viewModel.getTopicItems().observe(this, postList -> { |
|
|
|
if (postList == null) progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
|
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
|
|
|
|
postsList.clear(); |
|
|
|
postsList.addAll(postList); |
|
|
|
topicItems.clear(); |
|
|
|
topicItems.addAll(postList); |
|
|
|
topicAdapter.notifyDataSetChanged(); |
|
|
|
}); |
|
|
|
/*viewModel.getFocusedPostIndex().observe(this, focusedPostIndex -> { |
|
|
@ -652,7 +652,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
break; |
|
|
|
case NETWORK_ERROR: |
|
|
|
Timber.w("Network error on loaded page"); |
|
|
|
if (viewModel.getPostsList().getValue() == null) { |
|
|
|
if (viewModel.getTopicItems().getValue() == null) { |
|
|
|
// no page has been loaded yet. Give user the ability to refresh
|
|
|
|
recyclerView.setVisibility(View.GONE); |
|
|
|
TextView errorTextview = findViewById(R.id.error_textview); |
|
|
@ -710,9 +710,9 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
Timber.i("Prepare for reply successful"); |
|
|
|
//prepare for a reply
|
|
|
|
viewModel.setWritingReply(true); |
|
|
|
postsList.add(Post.newQuickReply()); |
|
|
|
topicAdapter.notifyItemInserted(postsList.size()); |
|
|
|
recyclerView.scrollToPosition(postsList.size() - 1); |
|
|
|
topicItems.add(Post.newQuickReply()); |
|
|
|
topicAdapter.notifyItemInserted(topicItems.size()); |
|
|
|
recyclerView.scrollToPosition(topicItems.size() - 1); |
|
|
|
replyFAB.hide(); |
|
|
|
bottomNavBar.setVisibility(View.GONE); |
|
|
|
} else { |
|
|
@ -725,7 +725,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo |
|
|
|
if (result != null && result.isSuccessful()) { |
|
|
|
Timber.i("Prepare for edit successful"); |
|
|
|
viewModel.setEditingPost(true); |
|
|
|
postsList.get(result.getPosition()).setPostType(Post.TYPE_EDIT); |
|
|
|
((Post) topicItems.get(result.getPosition())).setPostType(Post.TYPE_EDIT); |
|
|
|
topicAdapter.notifyItemChanged(result.getPosition()); |
|
|
|
recyclerView.scrollToPosition(result.getPosition()); |
|
|
|
replyFAB.hide(); |
|
|
|