Browse Source

fix: improved error handling (UnreadAdapter)

develop
Ezerous 2 years ago
parent
commit
a2e3ce1ad7
  1. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadAdapter.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java

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

@ -37,16 +37,16 @@ class UnreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@Override @Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) { public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
TopicSummary topicSummary = unreadList.get(holder.getAdapterPosition()); TopicSummary topicSummary = unreadList.get(holder.getBindingAdapterPosition());
final UnreadAdapter.ViewHolder viewHolder = (UnreadAdapter.ViewHolder) holder; final UnreadAdapter.ViewHolder viewHolder = (UnreadAdapter.ViewHolder) holder;
viewHolder.mTitleView.setText(topicSummary.getSubject()); viewHolder.mTitleView.setText(topicSummary.getSubject());
if (BaseApplication.getInstance().isDisplayRelativeTimeEnabled()) { if (BaseApplication.getInstance().isDisplayRelativeTimeEnabled()) {
String timestamp = topicSummary.getLastPostTimestamp(); String timestamp = topicSummary.getLastPostTimestamp();
try { try {
viewHolder.mDateTimeView.setReferenceTime(Long.valueOf(timestamp)); viewHolder.mDateTimeView.setReferenceTime(Long.parseLong(timestamp));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Timber.e(e, "Invalid number format: %s", timestamp); Timber.e(e, "Invalid number format \"%s\" for %s", timestamp, topicSummary.getTopicUrl());
viewHolder.mDateTimeView.setText(topicSummary.getLastPostSimplifiedDateTime()); viewHolder.mDateTimeView.setText(topicSummary.getLastPostSimplifiedDateTime());
} }
} }

4
app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java

@ -184,10 +184,8 @@ public class ThmmyPage {
public static String getTopicId(String topicUrl) { public static String getTopicId(String topicUrl) {
if (resolvePageCategory(Uri.parse(topicUrl)) == PageCategory.TOPIC) { if (resolvePageCategory(Uri.parse(topicUrl)) == PageCategory.TOPIC) {
Matcher topicIdMatcher = Pattern.compile("topic=[0-9]+").matcher(topicUrl); Matcher topicIdMatcher = Pattern.compile("topic=[0-9]+").matcher(topicUrl);
if (topicIdMatcher.find()) { if (topicIdMatcher.find())
return topicUrl.substring(topicIdMatcher.start() + 6, topicIdMatcher.end()); return topicUrl.substring(topicIdMatcher.start() + 6, topicIdMatcher.end());
}
else return null;
} }
return null; return null;
} }

Loading…
Cancel
Save