diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index c730b9df..b85ee294 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -36,7 +36,7 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, ForumFragment.ForumFragmentInteractionListener, UnreadFragment.UnreadFragmentInteractionListener { - //----------------------------------------CLASS VARIABLES----------------------------------------- +//-----------------------------------------CLASS VARIABLES------------------------------------------ private static final int TIME_INTERVAL = 2000; private long mBackPressed; @@ -57,7 +57,6 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); } - //Initialize drawer createDrawer(); @@ -117,7 +116,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF } @Override - public void onUnreadFragmentInteraction(TopicSummary topicSummary){ + public void onUnreadFragmentInteraction(TopicSummary topicSummary) { + if (topicSummary.getLastUser() == null && topicSummary.getDateTimeModified() == null) { + return; //TODO! + } Intent i = new Intent(MainActivity.this, TopicActivity.class); i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java index c6ae194d..2d415dd0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java @@ -21,6 +21,7 @@ class UnreadAdapter extends RecyclerView.Adapter { private final int VIEW_TYPE_ITEM = 0; private final int VIEW_TYPE_NADA = 1; + private final int VIEW_TYPE_MARK_READ = 2; UnreadAdapter(Context context, @NonNull List topicSummaryList, BaseFragment.FragmentInteractionListener listener) { this.context = context; @@ -30,6 +31,7 @@ class UnreadAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { + if (unreadList.get(position).getDateTimeModified() == null) return VIEW_TYPE_MARK_READ; return unreadList.get(position).getTopicUrl() == null ? VIEW_TYPE_NADA : VIEW_TYPE_ITEM; } @@ -43,6 +45,10 @@ class UnreadAdapter extends RecyclerView.Adapter { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.fragment_unread_empty_row, parent, false); return new EmptyViewHolder(view); + } else if (viewType == VIEW_TYPE_MARK_READ) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.fragment_unread_mark_read_row, parent, false); + return new MarkReadViewHolder(view); } return null; } @@ -74,6 +80,22 @@ class UnreadAdapter extends RecyclerView.Adapter { } }); + } else if (holder instanceof UnreadAdapter.MarkReadViewHolder) { + final UnreadAdapter.MarkReadViewHolder markReadViewHolder = (UnreadAdapter.MarkReadViewHolder) holder; + markReadViewHolder.text.setText(unreadList.get(position).getSubject()); + markReadViewHolder.topic = unreadList.get(position); + + markReadViewHolder.mView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (null != mListener) { + // Notify the active callbacks interface (the activity, if the + // fragment is attached to one) that an item has been selected. + mListener.onUnreadFragmentInteraction(markReadViewHolder.topic); + } + } + }); } } @@ -106,4 +128,16 @@ class UnreadAdapter extends RecyclerView.Adapter { text = (TextView) view.findViewById(R.id.text); } } + + private static class MarkReadViewHolder extends RecyclerView.ViewHolder { + final View mView; + final TextView text; + public TopicSummary topic; + + MarkReadViewHolder(View view) { + super(view); + mView = view; + text = (TextView) view.findViewById(R.id.mark_read); + } + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index f5145c43..99954acd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java @@ -158,16 +158,22 @@ public class UnreadFragment extends BaseFragment { String dateTime = lastUserAndDate.select("span").html(); //dateTime = dateTime.replace("
", ""); dateTime = dateTime.substring(0, dateTime.indexOf("
")); + dateTime = dateTime.replace("", ""); dateTime = dateTime.replace("", ""); topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); } + Element markRead = document.select("table:not(.bordercolor):not([width])").select("a") + .first(); + if (markRead != null) + topicSummaries.add(new TopicSummary(markRead.attr("href"), markRead.text(), null, + null)); } else { topicSummaries.clear(); String message = document.select("table.bordercolor[cellspacing=1]").first().text(); - if (message.contains("No messages")){ //It's english + if (message.contains("No messages")) { //It's english message = "No unread posts!"; - }else{ //It's greek + } else { //It's greek message = "Δεν υπάρχουν μη διαβασμένα μυνήματα!"; } topicSummaries.add(new TopicSummary(null, null, null, message)); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index a10b7daf..ba559876 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -135,7 +135,7 @@ public class TopicActivity extends BaseActivity { ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory( Uri.parse(topicPageUrl)); if (!target.is(ThmmyPage.PageCategory.TOPIC)) { - Timber.e("Bundle came with a non topic url!\nUrl: %s" , topicPageUrl); + Timber.e("Bundle came with a non topic url!\nUrl: %s", topicPageUrl); Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); finish(); } @@ -551,8 +551,11 @@ public class TopicActivity extends BaseActivity { } progressBar.setVisibility(ProgressBar.INVISIBLE); - topicAdapter.customNotifyDataSetChanged(new TopicTask()); - if (replyPageUrl == null) replyFAB.hide(); + if (replyPageUrl == null) { + replyFAB.hide(); + topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); + } else topicAdapter.customNotifyDataSetChanged(new TopicTask(), true); + if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); //Set current page @@ -566,7 +569,10 @@ public class TopicActivity extends BaseActivity { break; case SAME_PAGE: progressBar.setVisibility(ProgressBar.INVISIBLE); - topicAdapter.customNotifyDataSetChanged(new TopicTask()); + if (replyPageUrl == null) { + replyFAB.hide(); + topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); + } else topicAdapter.customNotifyDataSetChanged(new TopicTask(), true); if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); paginationEnabled(true); Toast.makeText(TopicActivity.this, "That's the same page.", Toast.LENGTH_SHORT).show(); @@ -709,10 +715,10 @@ public class TopicActivity extends BaseActivity { sc = document.select("input[name=sc]").first().attr("value"); topic = document.select("input[name=topic]").first().attr("value"); } catch (IOException e) { - Timber.e(e,"Post failed."); + Timber.e(e, "Post failed."); return false; } catch (Selector.SelectorParseException e) { - Timber.e(e,"Post failed."); + Timber.e(e, "Post failed."); return false; } @@ -746,7 +752,7 @@ public class TopicActivity extends BaseActivity { return true; } } catch (IOException e) { - Timber.e(e,"Post failed."); + Timber.e(e, "Post failed."); return false; } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 88c9694b..4a5f5798 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -99,6 +99,7 @@ class TopicAdapter extends RecyclerView.Adapter { private final String[] replyDataHolder = new String[2]; private final int replySubject = 0, replyText = 1; private String loadedPageUrl = ""; + private boolean canReply = false; /** * @param context the context of the {@link RecyclerView} @@ -403,9 +404,9 @@ class TopicAdapter extends RecyclerView.Adapter { } //noinspection PointlessBooleanExpression,ConstantConditions - if (!BaseActivity.getSessionManager().isLoggedIn()) + if (!BaseActivity.getSessionManager().isLoggedIn() || !canReply) { holder.quoteToggle.setVisibility(View.GONE); - else { + } else { if (viewProperties.get(position)[isQuoteButtonChecked]) holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); else @@ -469,8 +470,9 @@ class TopicAdapter extends RecyclerView.Adapter { } } - void customNotifyDataSetChanged(TopicActivity.TopicTask topicTask) { + void customNotifyDataSetChanged(TopicActivity.TopicTask topicTask, boolean canReply) { this.topicTask = topicTask; + this.canReply = canReply; viewProperties.clear(); for (int i = 0; i < postsList.size(); ++i) { //Initializes properties, array's values will be false by default diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 64bd6610..2362427d 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -164,6 +164,8 @@ android:id="@+id/post_date_and_number_exp" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" android:layout_marginTop="16dp"> + android:textSize="10sp" /> + android:textSize="10sp" /> diff --git a/app/src/main/res/layout/activity_topic_post_row.xml b/app/src/main/res/layout/activity_topic_post_row.xml index 696566e1..99eeefd6 100644 --- a/app/src/main/res/layout/activity_topic_post_row.xml +++ b/app/src/main/res/layout/activity_topic_post_row.xml @@ -174,7 +174,7 @@ android:gravity="start" android:text="" android:textColor="@color/card_expand_text_color" - android:textSize="8sp" /> + android:textSize="10sp" /> + android:textSize="10sp" /> diff --git a/app/src/main/res/layout/fragment_unread_mark_read_row.xml b/app/src/main/res/layout/fragment_unread_mark_read_row.xml new file mode 100644 index 00000000..ee3a4f49 --- /dev/null +++ b/app/src/main/res/layout/fragment_unread_mark_read_row.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file