From e92ffb3894ff0e413155554aa5ebbffc5ce2e325 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Tue, 23 May 2017 10:50:11 -0400 Subject: [PATCH] Drop support for Android ICS and Jelly Bean; remove obsolete code --- .gitignore | 1 + app/build.gradle | 2 +- .../java/org/isoron/uhabits/BaseViewTest.java | 6 +- .../isoron/uhabits/HabitsApplicationTest.java | 6 +- .../java/org/isoron/uhabits/AppComponent.java | 2 - .../common/dialogs/FilePickerDialog.java | 191 ------------------ .../habits/list/ListHabitsScreen.java | 44 +--- .../isoron/uhabits/intents/IntentFactory.java | 8 + .../uhabits/intents/IntentScheduler.java | 14 +- .../java/org/isoron/uhabits/io/DirFinder.java | 106 ---------- .../org/isoron/uhabits/utils/DateFormats.java | 7 +- .../org/isoron/uhabits/utils/WidgetUtils.java | 21 +- .../isoron/uhabits/widgets/BaseWidget.java | 5 +- .../uhabits/widgets/BaseWidgetProvider.java | 12 +- .../habits/list/ListHabitsScreenTest.java | 39 +--- 15 files changed, 33 insertions(+), 431 deletions(-) delete mode 100644 app/src/main/java/org/isoron/uhabits/activities/common/dialogs/FilePickerDialog.java delete mode 100644 app/src/main/java/org/isoron/uhabits/io/DirFinder.java diff --git a/.gitignore b/.gitignore index 1c7687f38..e575874af 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.class *.dex *.iml +*.local *.local.* *.swp *.trace diff --git a/app/build.gradle b/app/build.gradle index 8dbeffb25..eaefab308 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { defaultConfig { applicationId "org.isoron.uhabits" - minSdkVersion 15 + minSdkVersion 19 targetSdkVersion 25 buildConfigField "Integer", "databaseVersion", "19" diff --git a/app/src/androidTest/java/org/isoron/uhabits/BaseViewTest.java b/app/src/androidTest/java/org/isoron/uhabits/BaseViewTest.java index b41ba4675..c6d73d59f 100644 --- a/app/src/androidTest/java/org/isoron/uhabits/BaseViewTest.java +++ b/app/src/androidTest/java/org/isoron/uhabits/BaseViewTest.java @@ -31,6 +31,8 @@ import java.io.*; import java.util.*; import static android.os.Build.VERSION.*; +import static android.os.Build.VERSION_CODES.KITKAT; +import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.view.View.MeasureSpec.*; import static junit.framework.Assert.*; @@ -157,8 +159,8 @@ public class BaseViewTest extends BaseAndroidTest private String getVersionedPath(String path) { int version = SDK_INT; - if (version >= 21) version = 21; - else if (version >= 15) version = 15; + if (version >= LOLLIPOP) version = LOLLIPOP; + else if (version >= KITKAT) version = KITKAT; return String.format("views-v%d/%s", version, path); } diff --git a/app/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java b/app/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java index dea8f5867..d97f03ea3 100644 --- a/app/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java +++ b/app/src/androidTest/java/org/isoron/uhabits/HabitsApplicationTest.java @@ -19,7 +19,6 @@ package org.isoron.uhabits; -import android.os.*; import android.support.test.runner.*; import android.test.suitebuilder.annotation.*; @@ -29,8 +28,8 @@ import org.junit.runner.*; import java.io.*; -import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.*; @RunWith(AndroidJUnit4.class) @MediumTest @@ -39,9 +38,6 @@ public class HabitsApplicationTest extends BaseAndroidTest @Test public void test_getLogcat() throws IOException { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) - return; - String msg = "LOGCAT TEST"; new RuntimeException(msg).printStackTrace(); diff --git a/app/src/main/java/org/isoron/uhabits/AppComponent.java b/app/src/main/java/org/isoron/uhabits/AppComponent.java index adf4937ea..3dc205dd2 100644 --- a/app/src/main/java/org/isoron/uhabits/AppComponent.java +++ b/app/src/main/java/org/isoron/uhabits/AppComponent.java @@ -49,8 +49,6 @@ public interface AppComponent CreateHabitCommandFactory getCreateHabitCommandFactory(); - DirFinder getDirFinder(); - EditHabitCommandFactory getEditHabitCommandFactory(); GenericImporter getGenericImporter(); diff --git a/app/src/main/java/org/isoron/uhabits/activities/common/dialogs/FilePickerDialog.java b/app/src/main/java/org/isoron/uhabits/activities/common/dialogs/FilePickerDialog.java deleted file mode 100644 index a2cca7bbc..000000000 --- a/app/src/main/java/org/isoron/uhabits/activities/common/dialogs/FilePickerDialog.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * This file is part of Loop Habit Tracker. - * - * Loop Habit Tracker is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Loop Habit Tracker is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -package org.isoron.uhabits.activities.common.dialogs; - -import android.content.*; -import android.support.annotation.*; -import android.support.v7.app.*; -import android.view.*; -import android.view.WindowManager.*; -import android.widget.*; - -import com.google.auto.factory.*; - -import org.isoron.uhabits.activities.*; - -import java.io.*; -import java.util.*; - -/** - * Dialog that allows the user to pick a file. - */ -@AutoFactory(allowSubclasses = true) -public class FilePickerDialog implements AdapterView.OnItemClickListener -{ - private static final String PARENT_DIR = ".."; - - private final Context context; - - private ListView list; - - private AppCompatDialog dialog; - - private File currentPath; - - private OnFileSelectedListener listener; - - public FilePickerDialog(@Provided @ActivityContext Context context, - File initialDirectory) - { - this.context = context; - - list = new ListView(context); - list.setOnItemClickListener(this); - - dialog = new AppCompatDialog(context); - dialog.setContentView(list); - dialog - .getWindow() - .setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - - navigateTo(initialDirectory); - } - - public AppCompatDialog getDialog() - { - return dialog; - } - - @Override - public void onItemClick(AdapterView parent, - View view, - int which, - long id) - { - String filename = (String) list.getItemAtPosition(which); - File file; - - if (filename.equals(PARENT_DIR)) file = currentPath.getParentFile(); - else file = new File(currentPath, filename); - - if (file.isDirectory()) - { - navigateTo(file); - } - else - { - if (listener != null) listener.onFileSelected(file); - dialog.dismiss(); - } - } - - public void setListener(OnFileSelectedListener listener) - { - this.listener = listener; - } - - public void show() - { - dialog.show(); - } - - @NonNull - private String[] getFileList(File path, File[] dirs, File[] files) - { - int count = 0; - int length = dirs.length + files.length; - String[] fileList; - - if (path.getParentFile() == null || !path.getParentFile().canRead()) - { - fileList = new String[length]; - } - else - { - fileList = new String[length + 1]; - fileList[count++] = PARENT_DIR; - } - - Arrays.sort(dirs); - Arrays.sort(files); - - for (File dir : dirs) - fileList[count++] = dir.getName(); - - for (File file : files) - fileList[count++] = file.getName(); - - return fileList; - } - - private void navigateTo(File path) - { - if (!path.exists()) return; - - File[] dirs = path.listFiles(new ReadableDirFilter()); - File[] files = path.listFiles(new RegularReadableFileFilter()); - if (dirs == null || files == null) return; - - this.currentPath = path; - dialog.setTitle(currentPath.getPath()); - list.setAdapter(new FilePickerAdapter(getFileList(path, dirs, files))); - } - - public interface OnFileSelectedListener - { - void onFileSelected(File file); - } - - private static class ReadableDirFilter implements FileFilter - { - @Override - public boolean accept(File file) - { - return (file.isDirectory() && file.canRead()); - } - } - - private class FilePickerAdapter extends ArrayAdapter - { - public FilePickerAdapter(@NonNull String[] fileList) - { - super(FilePickerDialog.this.context, - android.R.layout.simple_list_item_1, fileList); - } - - @Override - public View getView(int pos, View view, ViewGroup parent) - { - view = super.getView(pos, view, parent); - TextView tv = (TextView) view; - tv.setSingleLine(true); - return view; - } - } - - private class RegularReadableFileFilter implements FileFilter - { - @Override - public boolean accept(File file) - { - return !file.isDirectory() && file.canRead(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java b/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java index 1a778101c..6c0a6f9ce 100644 --- a/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java +++ b/app/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.java @@ -35,7 +35,6 @@ import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*; import org.isoron.uhabits.activities.habits.edit.*; import org.isoron.uhabits.commands.*; import org.isoron.uhabits.intents.*; -import org.isoron.uhabits.io.*; import org.isoron.uhabits.models.*; import org.isoron.uhabits.preferences.*; import org.isoron.uhabits.utils.*; @@ -46,8 +45,6 @@ import java.lang.reflect.*; import javax.inject.*; import static android.content.DialogInterface.*; -import static android.os.Build.VERSION.*; -import static android.os.Build.VERSION_CODES.*; import static android.view.inputmethod.EditorInfo.*; @ActivityScope @@ -74,18 +71,12 @@ public class ListHabitsScreen extends BaseScreen @NonNull private final IntentFactory intentFactory; - @NonNull - private final DirFinder dirFinder; - @NonNull private final CommandRunner commandRunner; @NonNull private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory; - @NonNull - private final FilePickerDialogFactory filePickerDialogFactory; - @NonNull private final ColorPickerDialogFactory colorPickerFactory; @@ -101,12 +92,10 @@ public class ListHabitsScreen extends BaseScreen @Inject public ListHabitsScreen(@NonNull BaseActivity activity, @NonNull CommandRunner commandRunner, - @NonNull DirFinder dirFinder, @NonNull ListHabitsRootView rootView, @NonNull IntentFactory intentFactory, @NonNull ThemeSwitcher themeSwitcher, @NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory, - @NonNull FilePickerDialogFactory filePickerDialogFactory, @NonNull ColorPickerDialogFactory colorPickerFactory, @NonNull EditHabitDialogFactory editHabitDialogFactory, @NonNull Preferences prefs) @@ -118,8 +107,6 @@ public class ListHabitsScreen extends BaseScreen this.commandRunner = commandRunner; this.confirmDeleteDialogFactory = confirmDeleteDialogFactory; this.editHabitDialogFactory = editHabitDialogFactory; - this.dirFinder = dirFinder; - this.filePickerDialogFactory = filePickerDialogFactory; this.intentFactory = intentFactory; this.themeSwitcher = themeSwitcher; } @@ -237,39 +224,10 @@ public class ListHabitsScreen extends BaseScreen public void showImportScreen() { - if (SDK_INT < KITKAT) - { - showImportScreenPreKitKat(); - return; - } - - Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("*/*"); - + Intent intent = intentFactory.openDocument(); activity.startActivityForResult(intent, REQUEST_OPEN_DOCUMENT); } - public void showImportScreenPreKitKat() - { - File dir = dirFinder.findStorageDir(null); - - if (dir == null) - { - showMessage(R.string.could_not_import); - return; - } - - FilePickerDialog picker = filePickerDialogFactory.create(dir); - - if (controller != null) - picker.setListener(file -> controller.onImportData(file, () -> - { - })); - - activity.showDialog(picker.getDialog()); - } - public void showIntroScreen() { Intent intent = intentFactory.startIntroActivity(activity); diff --git a/app/src/main/java/org/isoron/uhabits/intents/IntentFactory.java b/app/src/main/java/org/isoron/uhabits/intents/IntentFactory.java index 47172d2fa..76b56243a 100644 --- a/app/src/main/java/org/isoron/uhabits/intents/IntentFactory.java +++ b/app/src/main/java/org/isoron/uhabits/intents/IntentFactory.java @@ -45,6 +45,14 @@ public class IntentFactory return buildViewIntent(url); } + public Intent openDocument() + { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + return intent; + } + public Intent rateApp(Context context) { String url = context.getString(R.string.playStoreURL); diff --git a/app/src/main/java/org/isoron/uhabits/intents/IntentScheduler.java b/app/src/main/java/org/isoron/uhabits/intents/IntentScheduler.java index 47dd4eebf..a53547654 100644 --- a/app/src/main/java/org/isoron/uhabits/intents/IntentScheduler.java +++ b/app/src/main/java/org/isoron/uhabits/intents/IntentScheduler.java @@ -30,6 +30,7 @@ import javax.inject.*; import static android.app.AlarmManager.*; import static android.content.Context.*; +import static android.os.Build.VERSION_CODES.M; @AppScope public class IntentScheduler @@ -44,18 +45,9 @@ public class IntentScheduler public void schedule(@NonNull Long timestamp, PendingIntent intent) { - if (Build.VERSION.SDK_INT >= 23) - { + if (Build.VERSION.SDK_INT >= M) manager.setExactAndAllowWhileIdle(RTC_WAKEUP, timestamp, intent); - return; - } - - if (Build.VERSION.SDK_INT >= 19) - { + else manager.setExact(RTC_WAKEUP, timestamp, intent); - return; - } - - manager.set(RTC_WAKEUP, timestamp, intent); } } diff --git a/app/src/main/java/org/isoron/uhabits/io/DirFinder.java b/app/src/main/java/org/isoron/uhabits/io/DirFinder.java deleted file mode 100644 index 392f7716c..000000000 --- a/app/src/main/java/org/isoron/uhabits/io/DirFinder.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * This file is part of Loop Habit Tracker. - * - * Loop Habit Tracker is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Loop Habit Tracker is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -package org.isoron.uhabits.io; - -import android.content.*; -import android.os.*; -import android.support.annotation.*; -import android.util.*; - -import org.isoron.uhabits.*; - -import java.io.*; - -import javax.inject.*; - -import static android.support.v4.content.ContextCompat.*; - -/** - * A DirFinder locates suitable directories for storing user files. - */ -public class DirFinder -{ - private static final String TAG = "DirFinder"; - - private final Context context; - - @Inject - public DirFinder(@AppContext Context context) - { - this.context = context; - } - - @Nullable - public File findSDCardDir(@Nullable String subpath) - { - File parents[] = new File[]{ - Environment.getExternalStorageDirectory() - }; - - return findDir(parents, subpath); - } - - @Nullable - public File findStorageDir(@Nullable String relativePath) - { - File potentialParents[] = getExternalFilesDirs(context, null); - - if (potentialParents == null) - { - Log.e(TAG, "getFilesDir: getExternalFilesDirs returned null"); - return null; - } - - return findDir(potentialParents, relativePath); - } - - @Nullable - private File findDir(@NonNull File potentialParents[], - @Nullable String relativePath) - { - if (relativePath == null) relativePath = ""; - - File chosenDir = null; - for (File dir : potentialParents) - { - if (dir == null || !dir.canWrite()) continue; - chosenDir = dir; - break; - } - - if (chosenDir == null) - { - Log.e(TAG, - "getDir: all potential parents are null or non-writable"); - return null; - } - - File dir = new File( - String.format("%s/%s/", chosenDir.getAbsolutePath(), relativePath)); - if (!dir.exists() && !dir.mkdirs()) - { - Log.e(TAG, - "getDir: chosen dir does not exist and cannot be created"); - return null; - } - - return dir; - } -} diff --git a/app/src/main/java/org/isoron/uhabits/utils/DateFormats.java b/app/src/main/java/org/isoron/uhabits/utils/DateFormats.java index e5325ab32..779170efe 100644 --- a/app/src/main/java/org/isoron/uhabits/utils/DateFormats.java +++ b/app/src/main/java/org/isoron/uhabits/utils/DateFormats.java @@ -24,8 +24,6 @@ import android.support.annotation.*; import java.text.*; import java.util.*; -import static android.os.Build.VERSION.*; -import static android.os.Build.VERSION_CODES.*; import static android.text.format.DateFormat.*; public class DateFormats @@ -43,10 +41,7 @@ public class DateFormats public static SimpleDateFormat fromSkeleton(@NonNull String skeleton) { Locale locale = Locale.getDefault(); - - if (SDK_INT >= JELLY_BEAN_MR2) - skeleton = getBestDateTimePattern(locale, skeleton); - + skeleton = getBestDateTimePattern(locale, skeleton); return fromSkeleton(skeleton, locale); } diff --git a/app/src/main/java/org/isoron/uhabits/utils/WidgetUtils.java b/app/src/main/java/org/isoron/uhabits/utils/WidgetUtils.java index 45b992205..ab55d0b9a 100644 --- a/app/src/main/java/org/isoron/uhabits/utils/WidgetUtils.java +++ b/app/src/main/java/org/isoron/uhabits/utils/WidgetUtils.java @@ -28,8 +28,6 @@ import android.widget.*; import org.isoron.uhabits.widgets.*; import static android.appwidget.AppWidgetManager.*; -import static android.os.Build.VERSION.*; -import static android.os.Build.VERSION_CODES.*; import static org.isoron.uhabits.utils.InterfaceUtils.*; public abstract class WidgetUtils @@ -38,9 +36,6 @@ public abstract class WidgetUtils public static WidgetDimensions getDimensionsFromOptions( @NonNull Context ctx, @NonNull Bundle options) { - if (SDK_INT < JELLY_BEAN) - throw new AssertionError("method requires jelly-bean"); - int maxWidth = (int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_WIDTH)); int maxHeight = @@ -56,17 +51,9 @@ public abstract class WidgetUtils public static void updateAppWidget(@NonNull AppWidgetManager manager, @NonNull BaseWidget widget) { - if (SDK_INT < JELLY_BEAN) - { - RemoteViews portrait = widget.getPortraitRemoteViews(); - manager.updateAppWidget(widget.getId(), portrait); - } - else - { - RemoteViews landscape = widget.getLandscapeRemoteViews(); - RemoteViews portrait = widget.getPortraitRemoteViews(); - RemoteViews views = new RemoteViews(landscape, portrait); - manager.updateAppWidget(widget.getId(), views); - } + RemoteViews landscape = widget.getLandscapeRemoteViews(); + RemoteViews portrait = widget.getPortraitRemoteViews(); + RemoteViews views = new RemoteViews(landscape, portrait); + manager.updateAppWidget(widget.getId(), views); } } diff --git a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidget.java b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidget.java index 40987b7b1..59d9f5094 100644 --- a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidget.java +++ b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidget.java @@ -30,8 +30,6 @@ import org.isoron.uhabits.*; import org.isoron.uhabits.intents.*; import org.isoron.uhabits.preferences.*; -import static android.os.Build.VERSION.*; -import static android.os.Build.VERSION_CODES.*; import static android.view.View.MeasureSpec.*; public abstract class BaseWidget @@ -126,8 +124,7 @@ public abstract class BaseWidget Bitmap bitmap = getBitmapFromView(view); remoteViews.setImageViewBitmap(R.id.imageView, bitmap); - if (SDK_INT >= JELLY_BEAN) - adjustRemoteViewsPadding(remoteViews, view, width, height); + adjustRemoteViewsPadding(remoteViews, view, width, height); PendingIntent onClickIntent = getOnClickPendingIntent(context); if (onClickIntent != null) diff --git a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java index e0a188851..74dc1fe2c 100644 --- a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java +++ b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java @@ -31,8 +31,6 @@ import org.isoron.uhabits.*; import org.isoron.uhabits.models.*; import org.isoron.uhabits.preferences.*; -import static android.os.Build.VERSION.*; -import static android.os.Build.VERSION_CODES.*; import static org.isoron.uhabits.utils.WidgetUtils.*; public abstract class BaseWidgetProvider extends AppWidgetProvider @@ -144,13 +142,9 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider try { BaseWidget widget = getWidgetFromId(context, widgetId); - - if (SDK_INT > JELLY_BEAN) - { - Bundle options = manager.getAppWidgetOptions(widgetId); - widget.setDimensions( - getDimensionsFromOptions(context, options)); - } + Bundle options = manager.getAppWidgetOptions(widgetId); + widget.setDimensions( + getDimensionsFromOptions(context, options)); updateAppWidget(manager, widget); } diff --git a/app/src/test/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreenTest.java b/app/src/test/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreenTest.java index 2e1e86b6f..e292c3b56 100644 --- a/app/src/test/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreenTest.java +++ b/app/src/test/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreenTest.java @@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.habits.list; import android.content.*; -import android.support.v7.app.*; import org.isoron.uhabits.*; import org.isoron.uhabits.activities.*; @@ -30,15 +29,12 @@ import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*; import org.isoron.uhabits.activities.habits.edit.*; import org.isoron.uhabits.commands.*; import org.isoron.uhabits.intents.*; -import org.isoron.uhabits.io.*; import org.isoron.uhabits.models.*; import org.isoron.uhabits.preferences.*; import org.junit.*; import org.junit.runner.*; import org.junit.runners.*; -import java.io.*; - import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*; import static org.mockito.Matchers.any; import static org.mockito.Mockito.anyInt; @@ -62,12 +58,8 @@ public class ListHabitsScreenTest extends BaseUnitTest private ConfirmDeleteDialogFactory confirmDeleteDialogFactory; - private FilePickerDialogFactory filePickerDialogFactory; - private IntentFactory intentFactory; - private DirFinder dirFinder; - private CommandRunner commandRunner; private ColorPickerDialogFactory colorPickerDialogFactory; @@ -76,8 +68,6 @@ public class ListHabitsScreenTest extends BaseUnitTest private ThemeSwitcher themeSwitcher; - private ListHabitsScreen baseScreen; - private Preferences prefs; @Before @@ -88,20 +78,17 @@ public class ListHabitsScreenTest extends BaseUnitTest activity = mock(BaseActivity.class); commandRunner = mock(CommandRunner.class); - dirFinder = mock(DirFinder.class); rootView = mock(ListHabitsRootView.class); intentFactory = mock(IntentFactory.class); themeSwitcher = mock(ThemeSwitcher.class); confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class); - filePickerDialogFactory = mock(FilePickerDialogFactory.class); colorPickerDialogFactory = mock(ColorPickerDialogFactory.class); dialogFactory = mock(EditHabitDialogFactory.class); prefs = mock(Preferences.class); - screen = spy(new ListHabitsScreen(activity, commandRunner, dirFinder, - rootView, intentFactory, themeSwitcher, confirmDeleteDialogFactory, - filePickerDialogFactory, colorPickerDialogFactory, dialogFactory, - prefs)); + screen = spy(new ListHabitsScreen(activity, commandRunner, rootView, + intentFactory, themeSwitcher, confirmDeleteDialogFactory, + colorPickerDialogFactory, dialogFactory, prefs)); doNothing().when(screen).showMessage(anyInt()); @@ -240,25 +227,9 @@ public class ListHabitsScreenTest extends BaseUnitTest @Test public void testShowImportScreen() { - File dir = mock(File.class); - when(dirFinder.findStorageDir(any())).thenReturn(dir); - - FilePickerDialog picker = mock(FilePickerDialog.class); - AppCompatDialog dialog = mock(AppCompatDialog.class); - when(picker.getDialog()).thenReturn(dialog); - when(filePickerDialogFactory.create(dir)).thenReturn(picker); - - screen.showImportScreen(); - - verify(activity).showDialog(dialog); - } - - @Test - public void testShowImportScreen_withInvalidPath() - { - when(dirFinder.findStorageDir(any())).thenReturn(null); + when(intentFactory.openDocument()).thenReturn(intent); screen.showImportScreen(); - verify(screen).showMessage(R.string.could_not_import); + verify(activity).startActivityForResult(intent, REQUEST_OPEN_DOCUMENT); } @Test