From c17771fcc427e14fe7c92f2e5cad2108a64d6bcc Mon Sep 17 00:00:00 2001 From: bellerbrock Date: Fri, 8 Sep 2023 14:50:16 -0400 Subject: [PATCH] better null handling --- .../preferences/GeneralPreferencesFragment.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/fieldbook/tracker/preferences/GeneralPreferencesFragment.java b/app/src/main/java/com/fieldbook/tracker/preferences/GeneralPreferencesFragment.java index deaddfb64..efda7e1d6 100644 --- a/app/src/main/java/com/fieldbook/tracker/preferences/GeneralPreferencesFragment.java +++ b/app/src/main/java/com/fieldbook/tracker/preferences/GeneralPreferencesFragment.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.util.Log; import androidx.documentfile.provider.DocumentFile; import androidx.preference.ListPreference; @@ -16,8 +15,6 @@ import com.fieldbook.tracker.activities.DefineStorageActivity; import com.fieldbook.tracker.activities.PreferencesActivity; -import java.util.Objects; - import org.phenoapps.utils.BaseDocumentTreeUtil; public class GeneralPreferencesFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener { @@ -260,8 +257,12 @@ public void onResume() { if (root != null && root.exists()) { - String path = Objects.requireNonNull(root.getUri().getLastPathSegment()); - Log.d("GeneralPreferencesFragment", "path: " + path); + String path = root.getUri().getLastPathSegment(); + if (path == null) { + // default to directory name if path is null + path = BaseDocumentTreeUtil.Companion.getStem(root.getUri(), context) + } + defaultStorageLocation.setSummary(path); }