From b86f0d248eaa9510064dca259d29fe82ba17173b Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 4 Mar 2018 22:30:15 -0600 Subject: [PATCH] Add possible fix for NPE in ExplorerActivity --- app/build.gradle | 6 ++-- .../view/activity/ExplorerActivity.java | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b2b5d7b..b8fbb48 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,8 +36,8 @@ android { applicationId "com.wbrawner.simplemarkdown" minSdkVersion 19 targetSdkVersion 27 - versionCode 6 - versionName "0.4.0" + versionCode 7 + versionName "0.4.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -65,7 +65,7 @@ android { } ext { - support_version = "27.0.2" + support_version = "27.1.0" } dependencies { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java index 0b2cd12..81e1ace 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/ExplorerActivity.java @@ -15,6 +15,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.SimpleAdapter; +import com.crashlytics.android.Crashlytics; import com.wbrawner.simplemarkdown.R; import com.wbrawner.simplemarkdown.utility.Constants; import com.wbrawner.simplemarkdown.utility.Utils; @@ -100,11 +101,7 @@ public class ExplorerActivity extends AppCompatActivity { // ); listView = findViewById(R.id.file_list); - File docsDir = new File(docsDirPath); - if (!docsDir.exists()) { - docsDir = Environment.getExternalStorageDirectory(); - } - updateListView(docsDir); + updateListView(); } @Override @@ -117,7 +114,19 @@ public class ExplorerActivity extends AppCompatActivity { if (hasRemovableStorage()) { menu.findItem(R.id.action_use_sdcard).setVisible(true); - if (filePath.get().contains(mounts[1].getAbsolutePath())) { + boolean sdcardSelected = false; + try { + sdcardSelected = filePath.get().contains(mounts[1].getAbsolutePath()); + } catch (NullPointerException e) { + updateListView(); + menu.findItem(R.id.action_use_sdcard).setVisible(false); + Crashlytics.logException(e); + Crashlytics.log(mounts.length + " mounts found"); + for (File mount : mounts) { + Crashlytics.log(mount.getAbsolutePath()); + } + } + if (sdcardSelected) { menu.findItem(R.id.action_use_sdcard).setChecked(true); } } @@ -196,6 +205,14 @@ public class ExplorerActivity extends AppCompatActivity { return sortedFiles; } + private void updateListView() { + File docsDir = new File(docsDirPath); + if (!docsDir.exists()) { + docsDir = Environment.getExternalStorageDirectory(); + } + updateListView(docsDir); + } + private void updateListView(File filesDir) { setTitle(filesDir.getName()); filePath.set(filesDir.getAbsolutePath());