Browse Source

Fixes for post's date and index, unread posts tab in MainActivity, quote buttons in topics

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
fbe8b00322
  1. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  2. 34
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java
  3. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  4. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  5. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  6. 6
      app/src/main/res/layout-v21/activity_topic_post_row.xml
  7. 4
      app/src/main/res/layout/activity_topic_post_row.xml
  8. 15
      app/src/main/res/layout/fragment_unread_mark_read_row.xml

8
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());

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

@ -21,6 +21,7 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
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<TopicSummary> topicSummaryList, BaseFragment.FragmentInteractionListener listener) {
this.context = context;
@ -30,6 +31,7 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@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<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
}
});
} 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<RecyclerView.ViewHolder> {
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);
}
}
}

10
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("<br>", "");
dateTime = dateTime.substring(0, dateTime.indexOf("<br>"));
dateTime = dateTime.replace("<b>", "");
dateTime = dateTime.replace("</b>", "");
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));

20
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;
}
}

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

@ -99,6 +99,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
}
//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<RecyclerView.ViewHolder> {
}
}
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

6
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">
<TextView
@ -173,7 +175,7 @@
android:gravity="start"
android:text=""
android:textColor="@color/card_expand_text_color"
android:textSize="8sp" />
android:textSize="10sp" />
<TextView
android:id="@+id/post_number"
@ -182,7 +184,7 @@
android:gravity="end"
android:text=""
android:textColor="@color/card_expand_text_color"
android:textSize="8sp" />
android:textSize="10sp" />
</FrameLayout>

4
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" />
<TextView
android:id="@+id/post_number"
@ -183,7 +183,7 @@
android:gravity="end"
android:text=""
android:textColor="@color/card_expand_text_color"
android:textSize="8sp" />
android:textSize="10sp" />
</FrameLayout>

15
app/src/main/res/layout/fragment_unread_mark_read_row.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingEnd="10dp"
android:paddingTop="7dp">
<TextView
android:id="@+id/mark_read"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="textEnd"
android:textColor="@color/accent" />
</LinearLayout>
Loading…
Cancel
Save