Skip to content

Commit

Permalink
Fix potential crashes (catch exceptions/check for nulls)
Browse files Browse the repository at this point in the history
  • Loading branch information
fat-tire committed Sep 26, 2018
1 parent 10da388 commit 409b213
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/havenapp/main/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_play_arrow);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.WHITE);
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);

fab.setImageDrawable(drawable);

if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.WHITE);
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
fab.setImageDrawable(drawable);
}
}


Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/havenapp/main/model/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ public Date getStartTime ()
@Override
public boolean delete() {
for (EventTrigger trigger : this.getEventTriggers()) {
File file = new File(trigger.getPath());
try {
File file = new File(trigger.getPath());

if (!file.delete() || !trigger.delete()) {
if (!file.delete() || !trigger.delete()) {
return false;
}
} catch (NullPointerException e) {
return false;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/havenapp/main/ui/EventActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ private void deleteEventTrigger (final EventTrigger eventTrigger, final int posi
{
public void run ()
{

new File(eventTrigger.getPath()).delete();
eventTrigger.delete();
if (eventTrigger != null) {
new File(eventTrigger.getPath()).delete();
eventTrigger.delete();
}

}
};
Expand Down

0 comments on commit 409b213

Please sign in to comment.