Browse Source

User profiles with zero posts fix

pull/24/head
Apostolos Fanakis 7 years ago
parent
commit
d03cd6d082
  1. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java
  2. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java
  3. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java
  4. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  5. 14
      app/src/main/res/layout/fragment_latest_posts_empty_message.xml
  6. 1
      app/src/main/res/values/strings.xml

9
app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.activities.profile.latestPosts;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -21,6 +22,7 @@ import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
* specified {@link LatestPostsFragment.LatestPostsFragmentInteractionListener}.
*/
class LatestPostsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int VIEW_TYPE_EMPTY = -1;
private final int VIEW_TYPE_ITEM = 0;
private final int VIEW_TYPE_LOADING = 1;
final private LatestPostsFragment.LatestPostsFragmentInteractionListener interactionListener;
@ -38,11 +40,18 @@ class LatestPostsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override
public int getItemViewType(int position) {
if (parsedTopicSummaries.get(position) == null && position == 0) return VIEW_TYPE_EMPTY;
return parsedTopicSummaries.get(position) == null ? VIEW_TYPE_LOADING : VIEW_TYPE_ITEM;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_EMPTY) {
Log.d("This", "in");
View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.fragment_latest_posts_empty_message, parent, false);
return new RecyclerView.ViewHolder(view){};
}
if (viewType == VIEW_TYPE_ITEM) {
View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.fragment_latest_posts_row, parent, false);

14
app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java

@ -50,6 +50,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
private LatestPostsTask profileLatestPostsTask;
private MaterialProgressBar progressBar;
private boolean isLoadingMore;
private boolean userHasPosts = true;
private static final int visibleThreshold = 5;
private int lastVisibleItem, totalItemCount;
@ -100,7 +101,8 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
totalItemCount = layoutManager.getItemCount();
lastVisibleItem = layoutManager.findLastVisibleItemPosition();
if (!isLoadingMore && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
if (userHasPosts && !isLoadingMore &&
totalItemCount <= (lastVisibleItem + visibleThreshold)) {
isLoadingMore = true;
onLoadMore();
}
@ -126,7 +128,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (parsedTopicSummaries.isEmpty()) {
if (parsedTopicSummaries.isEmpty() && userHasPosts) {
profileLatestPostsTask = new LatestPostsTask();
profileLatestPostsTask.execute(profileUrl + ";sa=showPosts");
pagesLoaded = 1;
@ -186,6 +188,7 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
//TODO: better parse error handling (ParseException etc.)
private boolean parseLatestPosts(Document latestPostsPage) {
//td:contains( Sorry, no matches were found)
Elements latestPostsRows = latestPostsPage.
select("td:has(table:Contains(Show Posts)):not([style]) > table");
if (latestPostsRows.isEmpty()) {
@ -197,6 +200,13 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
parsedTopicSummaries.remove(parsedTopicSummaries.size() - 1);
}
if (!latestPostsRows.select("td:contains(Sorry, no matches were found)").isEmpty() ||
!latestPostsRows.select("td:contains(Δυστυχώς δεν βρέθηκε τίποτα)").isEmpty()){
userHasPosts = false;
parsedTopicSummaries.add(null);
return true;
}
for (Element row : latestPostsRows) {
String pTopicUrl, pTopicTitle, pDateTime, pPost;
if (Integer.parseInt(row.attr("cellpadding")) == 4) {

20
app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java

@ -56,6 +56,7 @@ public class StatsFragment extends Fragment {
private MaterialProgressBar progressBar;
private boolean haveParsed = false;
private boolean userHasPosts = true;
private String generalStatisticsTitle = "", generalStatistics = "", postingActivityByTimeTitle = "", mostPopularBoardsByPostsTitle = "", mostPopularBoardsByActivityTitle = "";
final private List<Entry> postingActivityByTime = new ArrayList<>();
final private List<BarEntry> mostPopularBoardsByPosts = new ArrayList<>(), mostPopularBoardsByActivity = new ArrayList<>();
@ -123,6 +124,7 @@ public class StatsFragment extends Fragment {
* as String parameter!</p>
*/
private class ProfileStatsTask extends AsyncTask<String, Void, Boolean> {
@Override
protected void onPreExecute() {
progressBar.setVisibility(ProgressBar.VISIBLE);
@ -160,15 +162,24 @@ public class StatsFragment extends Fragment {
}
private boolean parseStats(Document statsPage) {
//Doesn't go through all the parsing if this user has no posts
if (!statsPage.select("td:contains(No posts to speak of!)").isEmpty()) {
userHasPosts = false;
}
if (!statsPage.select("td:contains(Δεν υπάρχει καμία αποστολή μηνύματος!)").isEmpty()) {
userHasPosts = false;
}
if (statsPage.select("table.bordercolor[align]>tbody>tr").size() != 6)
return false;
{
Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg");
generalStatisticsTitle = titleRows.first().text();
if (userHasPosts) {
postingActivityByTimeTitle = titleRows.get(1).text();
mostPopularBoardsByPostsTitle = titleRows.last().select("td").first().text();
mostPopularBoardsByActivityTitle = titleRows.last().select("td").last().text();
}
}
{
Elements statsRows = statsPage.select("table.bordercolor[align]>tbody>tr:not(.titlebg)");
{
@ -177,6 +188,7 @@ public class StatsFragment extends Fragment {
generalStatistics += generalStatisticsRow.text() + "\n";
generalStatistics = generalStatistics.trim();
}
if (userHasPosts) {
{
Elements postingActivityByTimeCols = statsRows.get(1).select(">td").last()
.select("tr").first().select("td[width=4%]");
@ -212,6 +224,7 @@ public class StatsFragment extends Fragment {
Collections.reverse(mostPopularBoardsByActivityLabels);
}
}
}
return true;
}
}
@ -221,6 +234,13 @@ public class StatsFragment extends Fragment {
.setText(generalStatisticsTitle);
((TextView) mainContent.findViewById(R.id.general_statistics))
.setText(generalStatistics);
if (!userHasPosts) {
mainContent.removeViews(2, mainContent.getChildCount() - 2);
//mainContent.removeViews(2, 6);
return;
}
((TextView) mainContent.findViewById(R.id.posting_activity_by_time_title))
.setText(postingActivityByTimeTitle);

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

@ -710,8 +710,7 @@ public class TopicActivity extends BaseActivity {
}
postsList.clear();
int oldSize = postsList.size();
topicAdapter.notifyItemRangeRemoved(0, oldSize);
topicAdapter.notifyItemRangeRemoved(0, postsList.size());
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
postsList.addAll(TopicParser.parseTopic(topic, language));
}

14
app/src/main/res/layout/fragment_latest_posts_empty_message.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="@dimen/big_text"
android:layout_marginTop="8dp"
android:textColor="@color/accent"
android:text="@string/latest_posts_empty_message"/>
</LinearLayout>

1
app/src/main/res/values/strings.xml

@ -51,6 +51,7 @@
<!--Profile Activity-->
<string name="username">Username</string>
<string name="latest_posts_empty_message">This user has no posts yet</string>
<string name="general_statistics_title">General Statistics</string>
<string name="general_statistics">Statistics</string>
<string name="posting_activity_by_time_title">Posting Activity</string>

Loading…
Cancel
Save