Add possible fix for NPE in ExplorerActivity

This commit is contained in:
William Brawner 2018-03-04 22:30:15 -06:00 committed by William Brawner
parent 3c3e8701ee
commit b86f0d248e
2 changed files with 26 additions and 9 deletions

View file

@ -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 {

View file

@ -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());