Browse Source

WebView-RecyclerView improvements

pull/70/head
Ezerous 5 years ago
parent
commit
5f7c996db2
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  4. 9
      app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java

1
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -19,7 +19,6 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

8
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -187,6 +187,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
recyclerView.setLayoutManager(layoutManager);
topicAdapter = new TopicAdapter(this, emojiKeyboard, topicItems);
recyclerView.setAdapter(topicAdapter);
recyclerView.setItemViewCacheSize(15); //Every page has maximum 15 posts
replyFAB = findViewById(R.id.topic_fab);
replyFAB.hide();
@ -661,11 +662,11 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
Toast.makeText(this, "Failed to remove vote", Toast.LENGTH_LONG).show();
}
});
// observe the chages in data
// observe the changes in data
viewModel.getPageIndicatorIndex().observe(this, pageIndicatorIndex -> {
if (pageIndicatorIndex == null) return;
pageIndicator.setText(String.valueOf(pageIndicatorIndex) + "/" +
String.valueOf(viewModel.getPageCount()));
pageIndicator.setText(pageIndicatorIndex + "/" +
viewModel.getPageCount());
});
viewModel.getTopicTitle().observe(this, newTopicTitle -> {
if (newTopicTitle == null) return;
@ -692,6 +693,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo
viewModel.getTopicItems().observe(this, postList -> {
if (postList == null) progressBar.setVisibility(ProgressBar.VISIBLE);
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
recyclerView.scrollToPosition(0);
topicItems.clear();
topicItems.addAll(postList);
topicAdapter.notifyDataSetChanged();

4
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -43,13 +43,10 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.content.res.ResourcesCompat;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
@ -67,7 +64,6 @@ import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Poll;
import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyFile;

9
app/src/main/java/gr/thmmy/mthmmy/views/ReactiveWebView.java

@ -31,19 +31,24 @@ public class ReactiveWebView extends WebView {
public ReactiveWebView(Context context) {
super(context);
this.context = context;
setOnLongClickListener();
init();
}
public ReactiveWebView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
setOnLongClickListener();
init();
}
public ReactiveWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
init();
}
private void init(){
setOnLongClickListener();
this.setVerticalScrollBarEnabled(false);
}
@Override

Loading…
Cancel
Save