Browse Source

Unread tab fetches all pages, More fixes for vector drawables

pull/44/head
Apostolos Fanakis 6 years ago
parent
commit
3f1cce8d00
  1. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java
  2. 51
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  3. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  4. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  5. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  6. 2
      app/src/main/res/layout/activity_topic_overflow_menu.xml
  7. 1
      app/src/main/res/layout/activity_upload.xml

10
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java

@ -1,6 +1,5 @@
package gr.thmmy.mthmmy.activities.main.unread;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -15,7 +14,6 @@ import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.model.TopicSummary;
class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context context;
private final List<TopicSummary> unreadList;
private final UnreadFragment.UnreadFragmentInteractionListener mListener;
private final MarkReadInteractionListener markReadListener;
@ -24,10 +22,9 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int VIEW_TYPE_NADA = 1;
private final int VIEW_TYPE_MARK_READ = 2;
UnreadAdapter(Context context, @NonNull List<TopicSummary> topicSummaryList,
UnreadAdapter(@NonNull List<TopicSummary> topicSummaryList,
BaseFragment.FragmentInteractionListener listener,
MarkReadInteractionListener markReadInteractionListener) {
this.context = context;
this.unreadList = topicSummaryList;
mListener = (UnreadFragment.UnreadFragmentInteractionListener) listener;
markReadListener = markReadInteractionListener;
@ -39,8 +36,9 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
return unreadList.get(position).getTopicUrl() == null ? VIEW_TYPE_NADA : VIEW_TYPE_ITEM;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_ITEM) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_unread_row, parent, false);
@ -58,7 +56,7 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof UnreadAdapter.EmptyViewHolder) {
final UnreadAdapter.EmptyViewHolder emptyViewHolder = (UnreadAdapter.EmptyViewHolder) holder;
emptyViewHolder.text.setText(unreadList.get(holder.getAdapterPosition()).getDateTimeModified());

51
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java

@ -2,9 +2,11 @@ package gr.thmmy.mthmmy.activities.main.unread;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -25,7 +27,6 @@ import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.model.TopicSummary;
import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.parsing.ParseTask;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Request;
@ -42,13 +43,14 @@ import timber.log.Timber;
public class UnreadFragment extends BaseFragment {
private static final String TAG = "UnreadFragment";
// Fragment initialization parameters, e.g. ARG_SECTION_NUMBER
private MaterialProgressBar progressBar;
private SwipeRefreshLayout swipeRefreshLayout;
private UnreadAdapter unreadAdapter;
private List<TopicSummary> topicSummaries;
private int numberOfPages = 0;
private int loadedPages = 0;
private UnreadTask unreadTask;
private MarkReadTask markReadTask;
@ -83,6 +85,7 @@ public class UnreadFragment extends BaseFragment {
super.onActivityCreated(savedInstanceState);
if (topicSummaries.isEmpty()) {
unreadTask = new UnreadTask();
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString());
}
markReadTask = new MarkReadTask();
@ -91,7 +94,7 @@ public class UnreadFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View rootView = inflater.inflate(R.layout.fragment_unread, container, false);
@ -99,7 +102,7 @@ public class UnreadFragment extends BaseFragment {
// Set the adapter
if (rootView instanceof RelativeLayout) {
progressBar = rootView.findViewById(R.id.progressBar);
unreadAdapter = new UnreadAdapter(getActivity(), topicSummaries,
unreadAdapter = new UnreadAdapter(topicSummaries,
fragmentInteractionListener, new UnreadAdapter.MarkReadInteractionListener() {
@Override
public void onMarkReadInteraction(String markReadLinkUrl) {
@ -126,7 +129,11 @@ public class UnreadFragment extends BaseFragment {
@Override
public void onRefresh() {
if (unreadTask != null && unreadTask.getStatus() != AsyncTask.Status.RUNNING) {
topicSummaries.clear();
numberOfPages = 0;
loadedPages = 0;
unreadTask = new UnreadTask();
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString());
}
}
@ -158,10 +165,10 @@ public class UnreadFragment extends BaseFragment {
}
@Override
public void parse(Document document) throws ParseException {
public void parse(Document document) {
Elements unread = document.select("table.bordercolor[cellspacing=1] tr:not(.titlebg)");
if (!unread.isEmpty()) {
topicSummaries.clear();
//topicSummaries.clear();
for (Element row : unread) {
Elements information = row.select("td");
String link = information.last().select("a").first().attr("href");
@ -186,9 +193,26 @@ public class UnreadFragment extends BaseFragment {
topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime));
}
Element markRead = document.select("table:not(.bordercolor):not([width])").select("a")
Element topBar = document.select("table:not(.bordercolor):not(#bodyarea):has(td.middletext)").first();
Element pagesElement = null, markRead = null;
if (topBar != null) {
pagesElement = topBar.select("td.middletext").first();
markRead = document.select("table:not(.bordercolor):not([width])").select("a")
.first();
if (markRead != null)
}
if (numberOfPages == 0 && pagesElement != null) {
Elements pages = pagesElement.select("a");
if (!pages.isEmpty()) {
numberOfPages = Integer.parseInt(pages.last().text());
} else {
numberOfPages = 1;
}
}
if (markRead != null && loadedPages == numberOfPages - 1)
topicSummaries.add(new TopicSummary(markRead.attr("href"), markRead.text(), null,
null));
} else {
@ -205,13 +229,21 @@ public class UnreadFragment extends BaseFragment {
@Override
protected void postExecution(ParseTask.ResultCode result) {
if (result == ResultCode.SUCCESS)
if (result == ResultCode.SUCCESS) {
unreadAdapter.notifyDataSetChanged();
++loadedPages;
if (loadedPages < numberOfPages) {
unreadTask = new UnreadTask();
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString() + ";start=" + loadedPages * 20);
}
progressBar.setVisibility(ProgressBar.INVISIBLE);
swipeRefreshLayout.setRefreshing(false);
}
}
}
private class MarkReadTask extends AsyncTask<String, Void, Integer> {
private static final int SUCCESS = 0;
@ -254,6 +286,7 @@ public class UnreadFragment extends BaseFragment {
} else {
if (unreadTask != null && unreadTask.getStatus() != AsyncTask.Status.RUNNING) {
unreadTask = new UnreadTask();
assert SessionManager.unreadUrl != null;
unreadTask.execute(SessionManager.unreadUrl.toString());
}
}

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

@ -203,11 +203,16 @@ public class TopicActivity extends BaseActivity {
boolean includeAppSignaturePreference = true;
//Fix for vector drawables on android <21
static {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Fix for vector drawables on android <21
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
setContentView(R.layout.activity_topic);
Bundle extras = getIntent().getExtras();

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

@ -7,12 +7,14 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
@ -434,7 +436,10 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
popUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
popUp.setFocusable(true);
popUpContent.findViewById(R.id.post_share_button).setOnClickListener(new View.OnClickListener() {
TextView shareButton = popUpContent.findViewById(R.id.post_share_button);
Drawable shareStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_share_white_24dp);
shareButton.setCompoundDrawablesRelativeWithIntrinsicBounds(shareStartDrawable, null, null, null);
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
@ -450,6 +455,8 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals("")) {
deletePostButton.setVisibility(View.GONE);
} else {
Drawable deleteStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_white_24dp);
deletePostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteStartDrawable, null, null, null);
popUpContent.findViewById(R.id.delete_post).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

4
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@ -14,6 +15,7 @@ import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
@ -179,6 +181,8 @@ public class UploadActivity extends BaseActivity {
uploadDescription = findViewById(R.id.upload_description);
selectFileButton = findViewById(R.id.upload_select_file_button);
Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp);
selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null);
selectFileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

2
app/src/main/res/layout/activity_topic_overflow_menu.xml

@ -10,7 +10,6 @@
android:layout_height="35dp"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_share_white_24dp"
android:gravity="center_vertical"
android:paddingBottom="6dp"
android:paddingEnd="12dp"
@ -25,7 +24,6 @@
android:layout_height="35dp"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_delete_white_24dp"
android:gravity="center_vertical"
android:paddingBottom="6dp"
android:paddingEnd="12dp"

1
app/src/main/res/layout/activity_upload.xml

@ -123,7 +123,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_insert_drive_file_white_24dp"
android:gravity="center_vertical"
android:text="@string/upload_select_file"
android:textColor="@color/primary_text" />

Loading…
Cancel
Save