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