From 813544ec148afcdde473a2a36d5b05d8aa9a103c Mon Sep 17 00:00:00 2001 From: Ezerous Date: Thu, 3 Oct 2019 20:20:55 +0300 Subject: [PATCH] Prevent NumberFormatException crash --- .../activities/main/recent/RecentAdapter.java | 9 ++++++- .../activities/main/unread/UnreadAdapter.java | 25 +++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java index 0bd447f6..8d66209e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentAdapter.java @@ -15,6 +15,7 @@ import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.utils.RelativeTimeTextView; +import timber.log.Timber; /** @@ -45,7 +46,13 @@ class RecentAdapter extends RecyclerView.Adapter { String dateTimeString = recentList.get(position).getDateTimeModified(); if(BaseApplication.getInstance().isDisplayRelativeTimeEnabled()) - holder.mDateTimeView.setReferenceTime(Long.valueOf(dateTimeString)); + try{ + holder.mDateTimeView.setReferenceTime(Long.valueOf(dateTimeString)); + } + catch(NumberFormatException e){ + Timber.e(e, "Invalid number format."); + holder.mDateTimeView.setText(dateTimeString); + } else holder.mDateTimeView.setText(dateTimeString); 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 d213e480..9312178f 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 @@ -15,6 +15,7 @@ import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.utils.RelativeTimeTextView; +import timber.log.Timber; class UnreadAdapter extends RecyclerView.Adapter { private final List unreadList; @@ -69,8 +70,15 @@ class UnreadAdapter extends RecyclerView.Adapter { viewHolder.mTitleView.setText(unreadList.get(holder.getAdapterPosition()).getSubject()); String dateTimeString=unreadList.get(holder.getAdapterPosition()).getDateTimeModified(); - if(BaseApplication.getInstance().isDisplayRelativeTimeEnabled()) - viewHolder.mDateTimeView.setReferenceTime(Long.valueOf(dateTimeString)); + if(BaseApplication.getInstance().isDisplayRelativeTimeEnabled()){ + try{ + viewHolder.mDateTimeView.setReferenceTime(Long.valueOf(dateTimeString)); + } + catch(NumberFormatException e){ + Timber.e(e, "Invalid number format."); + viewHolder.mDateTimeView.setText(dateTimeString); + } + } else viewHolder.mDateTimeView.setText(dateTimeString); @@ -89,14 +97,11 @@ class UnreadAdapter extends RecyclerView.Adapter { markReadViewHolder.text.setText(unreadList.get(holder.getAdapterPosition()).getSubject()); markReadViewHolder.topic = unreadList.get(holder.getAdapterPosition()); - 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. - markReadListener.onMarkReadInteraction(unreadList.get(holder.getAdapterPosition()).getTopicUrl()); - } + markReadViewHolder.mView.setOnClickListener(v -> { + if (null != mListener) { + // Notify the active callbacks interface (the activity, if the + // fragment is attached to one) that an item has been selected. + markReadListener.onMarkReadInteraction(unreadList.get(holder.getAdapterPosition()).getTopicUrl()); } }); }