Drop support for Android ICS and Jelly Bean; remove obsolete code

pull/231/merge
Alinson S. Xavier 8 years ago
parent 96bdb42365
commit e92ffb3894

1
.gitignore vendored

@ -3,6 +3,7 @@
*.class *.class
*.dex *.dex
*.iml *.iml
*.local
*.local.* *.local.*
*.swp *.swp
*.trace *.trace

@ -9,7 +9,7 @@ android {
defaultConfig { defaultConfig {
applicationId "org.isoron.uhabits" applicationId "org.isoron.uhabits"
minSdkVersion 15 minSdkVersion 19
targetSdkVersion 25 targetSdkVersion 25
buildConfigField "Integer", "databaseVersion", "19" buildConfigField "Integer", "databaseVersion", "19"

@ -31,6 +31,8 @@ import java.io.*;
import java.util.*; import java.util.*;
import static android.os.Build.VERSION.*; 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 android.view.View.MeasureSpec.*;
import static junit.framework.Assert.*; import static junit.framework.Assert.*;
@ -157,8 +159,8 @@ public class BaseViewTest extends BaseAndroidTest
private String getVersionedPath(String path) private String getVersionedPath(String path)
{ {
int version = SDK_INT; int version = SDK_INT;
if (version >= 21) version = 21; if (version >= LOLLIPOP) version = LOLLIPOP;
else if (version >= 15) version = 15; else if (version >= KITKAT) version = KITKAT;
return String.format("views-v%d/%s", version, path); return String.format("views-v%d/%s", version, path);
} }

@ -19,7 +19,6 @@
package org.isoron.uhabits; package org.isoron.uhabits;
import android.os.*;
import android.support.test.runner.*; import android.support.test.runner.*;
import android.test.suitebuilder.annotation.*; import android.test.suitebuilder.annotation.*;
@ -29,8 +28,8 @@ import org.junit.runner.*;
import java.io.*; import java.io.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@MediumTest @MediumTest
@ -39,9 +38,6 @@ public class HabitsApplicationTest extends BaseAndroidTest
@Test @Test
public void test_getLogcat() throws IOException public void test_getLogcat() throws IOException
{ {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
return;
String msg = "LOGCAT TEST"; String msg = "LOGCAT TEST";
new RuntimeException(msg).printStackTrace(); new RuntimeException(msg).printStackTrace();

@ -49,8 +49,6 @@ public interface AppComponent
CreateHabitCommandFactory getCreateHabitCommandFactory(); CreateHabitCommandFactory getCreateHabitCommandFactory();
DirFinder getDirFinder();
EditHabitCommandFactory getEditHabitCommandFactory(); EditHabitCommandFactory getEditHabitCommandFactory();
GenericImporter getGenericImporter(); GenericImporter getGenericImporter();

@ -1,191 +0,0 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<String>
{
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();
}
}
}

@ -35,7 +35,6 @@ import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialog.*;
import org.isoron.uhabits.activities.habits.edit.*; import org.isoron.uhabits.activities.habits.edit.*;
import org.isoron.uhabits.commands.*; import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.intents.*; import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*; import org.isoron.uhabits.preferences.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
@ -46,8 +45,6 @@ import java.lang.reflect.*;
import javax.inject.*; import javax.inject.*;
import static android.content.DialogInterface.*; import static android.content.DialogInterface.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static android.view.inputmethod.EditorInfo.*; import static android.view.inputmethod.EditorInfo.*;
@ActivityScope @ActivityScope
@ -74,18 +71,12 @@ public class ListHabitsScreen extends BaseScreen
@NonNull @NonNull
private final IntentFactory intentFactory; private final IntentFactory intentFactory;
@NonNull
private final DirFinder dirFinder;
@NonNull @NonNull
private final CommandRunner commandRunner; private final CommandRunner commandRunner;
@NonNull @NonNull
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory; private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
@NonNull
private final FilePickerDialogFactory filePickerDialogFactory;
@NonNull @NonNull
private final ColorPickerDialogFactory colorPickerFactory; private final ColorPickerDialogFactory colorPickerFactory;
@ -101,12 +92,10 @@ public class ListHabitsScreen extends BaseScreen
@Inject @Inject
public ListHabitsScreen(@NonNull BaseActivity activity, public ListHabitsScreen(@NonNull BaseActivity activity,
@NonNull CommandRunner commandRunner, @NonNull CommandRunner commandRunner,
@NonNull DirFinder dirFinder,
@NonNull ListHabitsRootView rootView, @NonNull ListHabitsRootView rootView,
@NonNull IntentFactory intentFactory, @NonNull IntentFactory intentFactory,
@NonNull ThemeSwitcher themeSwitcher, @NonNull ThemeSwitcher themeSwitcher,
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory, @NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
@NonNull FilePickerDialogFactory filePickerDialogFactory,
@NonNull ColorPickerDialogFactory colorPickerFactory, @NonNull ColorPickerDialogFactory colorPickerFactory,
@NonNull EditHabitDialogFactory editHabitDialogFactory, @NonNull EditHabitDialogFactory editHabitDialogFactory,
@NonNull Preferences prefs) @NonNull Preferences prefs)
@ -118,8 +107,6 @@ public class ListHabitsScreen extends BaseScreen
this.commandRunner = commandRunner; this.commandRunner = commandRunner;
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory; this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
this.editHabitDialogFactory = editHabitDialogFactory; this.editHabitDialogFactory = editHabitDialogFactory;
this.dirFinder = dirFinder;
this.filePickerDialogFactory = filePickerDialogFactory;
this.intentFactory = intentFactory; this.intentFactory = intentFactory;
this.themeSwitcher = themeSwitcher; this.themeSwitcher = themeSwitcher;
} }
@ -237,39 +224,10 @@ public class ListHabitsScreen extends BaseScreen
public void showImportScreen() public void showImportScreen()
{ {
if (SDK_INT < KITKAT) Intent intent = intentFactory.openDocument();
{
showImportScreenPreKitKat();
return;
}
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
activity.startActivityForResult(intent, REQUEST_OPEN_DOCUMENT); 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() public void showIntroScreen()
{ {
Intent intent = intentFactory.startIntroActivity(activity); Intent intent = intentFactory.startIntroActivity(activity);

@ -45,6 +45,14 @@ public class IntentFactory
return buildViewIntent(url); 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) public Intent rateApp(Context context)
{ {
String url = context.getString(R.string.playStoreURL); String url = context.getString(R.string.playStoreURL);

@ -30,6 +30,7 @@ import javax.inject.*;
import static android.app.AlarmManager.*; import static android.app.AlarmManager.*;
import static android.content.Context.*; import static android.content.Context.*;
import static android.os.Build.VERSION_CODES.M;
@AppScope @AppScope
public class IntentScheduler public class IntentScheduler
@ -44,18 +45,9 @@ public class IntentScheduler
public void schedule(@NonNull Long timestamp, PendingIntent intent) 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); manager.setExactAndAllowWhileIdle(RTC_WAKEUP, timestamp, intent);
return; else
}
if (Build.VERSION.SDK_INT >= 19)
{
manager.setExact(RTC_WAKEUP, timestamp, intent); manager.setExact(RTC_WAKEUP, timestamp, intent);
return;
}
manager.set(RTC_WAKEUP, timestamp, intent);
} }
} }

@ -1,106 +0,0 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

@ -24,8 +24,6 @@ import android.support.annotation.*;
import java.text.*; import java.text.*;
import java.util.*; import java.util.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static android.text.format.DateFormat.*; import static android.text.format.DateFormat.*;
public class DateFormats public class DateFormats
@ -43,10 +41,7 @@ public class DateFormats
public static SimpleDateFormat fromSkeleton(@NonNull String skeleton) public static SimpleDateFormat fromSkeleton(@NonNull String skeleton)
{ {
Locale locale = Locale.getDefault(); Locale locale = Locale.getDefault();
skeleton = getBestDateTimePattern(locale, skeleton);
if (SDK_INT >= JELLY_BEAN_MR2)
skeleton = getBestDateTimePattern(locale, skeleton);
return fromSkeleton(skeleton, locale); return fromSkeleton(skeleton, locale);
} }

@ -28,8 +28,6 @@ import android.widget.*;
import org.isoron.uhabits.widgets.*; import org.isoron.uhabits.widgets.*;
import static android.appwidget.AppWidgetManager.*; 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.*; import static org.isoron.uhabits.utils.InterfaceUtils.*;
public abstract class WidgetUtils public abstract class WidgetUtils
@ -38,9 +36,6 @@ public abstract class WidgetUtils
public static WidgetDimensions getDimensionsFromOptions( public static WidgetDimensions getDimensionsFromOptions(
@NonNull Context ctx, @NonNull Bundle options) @NonNull Context ctx, @NonNull Bundle options)
{ {
if (SDK_INT < JELLY_BEAN)
throw new AssertionError("method requires jelly-bean");
int maxWidth = int maxWidth =
(int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_WIDTH)); (int) dpToPixels(ctx, options.getInt(OPTION_APPWIDGET_MAX_WIDTH));
int maxHeight = int maxHeight =
@ -56,17 +51,9 @@ public abstract class WidgetUtils
public static void updateAppWidget(@NonNull AppWidgetManager manager, public static void updateAppWidget(@NonNull AppWidgetManager manager,
@NonNull BaseWidget widget) @NonNull BaseWidget widget)
{ {
if (SDK_INT < JELLY_BEAN) RemoteViews landscape = widget.getLandscapeRemoteViews();
{ RemoteViews portrait = widget.getPortraitRemoteViews();
RemoteViews portrait = widget.getPortraitRemoteViews(); RemoteViews views = new RemoteViews(landscape, portrait);
manager.updateAppWidget(widget.getId(), portrait); manager.updateAppWidget(widget.getId(), views);
}
else
{
RemoteViews landscape = widget.getLandscapeRemoteViews();
RemoteViews portrait = widget.getPortraitRemoteViews();
RemoteViews views = new RemoteViews(landscape, portrait);
manager.updateAppWidget(widget.getId(), views);
}
} }
} }

@ -30,8 +30,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.intents.*; import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.preferences.*; import org.isoron.uhabits.preferences.*;
import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION_CODES.*;
import static android.view.View.MeasureSpec.*; import static android.view.View.MeasureSpec.*;
public abstract class BaseWidget public abstract class BaseWidget
@ -126,8 +124,7 @@ public abstract class BaseWidget
Bitmap bitmap = getBitmapFromView(view); Bitmap bitmap = getBitmapFromView(view);
remoteViews.setImageViewBitmap(R.id.imageView, bitmap); 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); PendingIntent onClickIntent = getOnClickPendingIntent(context);
if (onClickIntent != null) if (onClickIntent != null)

@ -31,8 +31,6 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*; 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.*; import static org.isoron.uhabits.utils.WidgetUtils.*;
public abstract class BaseWidgetProvider extends AppWidgetProvider public abstract class BaseWidgetProvider extends AppWidgetProvider
@ -144,13 +142,9 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
try try
{ {
BaseWidget widget = getWidgetFromId(context, widgetId); BaseWidget widget = getWidgetFromId(context, widgetId);
Bundle options = manager.getAppWidgetOptions(widgetId);
if (SDK_INT > JELLY_BEAN) widget.setDimensions(
{ getDimensionsFromOptions(context, options));
Bundle options = manager.getAppWidgetOptions(widgetId);
widget.setDimensions(
getDimensionsFromOptions(context, options));
}
updateAppWidget(manager, widget); updateAppWidget(manager, widget);
} }

@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.habits.list;
import android.content.*; import android.content.*;
import android.support.v7.app.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*; 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.activities.habits.edit.*;
import org.isoron.uhabits.commands.*; import org.isoron.uhabits.commands.*;
import org.isoron.uhabits.intents.*; import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.io.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*; import org.isoron.uhabits.preferences.*;
import org.junit.*; import org.junit.*;
import org.junit.runner.*; import org.junit.runner.*;
import org.junit.runners.*; import org.junit.runners.*;
import java.io.*;
import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*; import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyInt;
@ -62,12 +58,8 @@ public class ListHabitsScreenTest extends BaseUnitTest
private ConfirmDeleteDialogFactory confirmDeleteDialogFactory; private ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
private FilePickerDialogFactory filePickerDialogFactory;
private IntentFactory intentFactory; private IntentFactory intentFactory;
private DirFinder dirFinder;
private CommandRunner commandRunner; private CommandRunner commandRunner;
private ColorPickerDialogFactory colorPickerDialogFactory; private ColorPickerDialogFactory colorPickerDialogFactory;
@ -76,8 +68,6 @@ public class ListHabitsScreenTest extends BaseUnitTest
private ThemeSwitcher themeSwitcher; private ThemeSwitcher themeSwitcher;
private ListHabitsScreen baseScreen;
private Preferences prefs; private Preferences prefs;
@Before @Before
@ -88,20 +78,17 @@ public class ListHabitsScreenTest extends BaseUnitTest
activity = mock(BaseActivity.class); activity = mock(BaseActivity.class);
commandRunner = mock(CommandRunner.class); commandRunner = mock(CommandRunner.class);
dirFinder = mock(DirFinder.class);
rootView = mock(ListHabitsRootView.class); rootView = mock(ListHabitsRootView.class);
intentFactory = mock(IntentFactory.class); intentFactory = mock(IntentFactory.class);
themeSwitcher = mock(ThemeSwitcher.class); themeSwitcher = mock(ThemeSwitcher.class);
confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class); confirmDeleteDialogFactory = mock(ConfirmDeleteDialogFactory.class);
filePickerDialogFactory = mock(FilePickerDialogFactory.class);
colorPickerDialogFactory = mock(ColorPickerDialogFactory.class); colorPickerDialogFactory = mock(ColorPickerDialogFactory.class);
dialogFactory = mock(EditHabitDialogFactory.class); dialogFactory = mock(EditHabitDialogFactory.class);
prefs = mock(Preferences.class); prefs = mock(Preferences.class);
screen = spy(new ListHabitsScreen(activity, commandRunner, dirFinder, screen = spy(new ListHabitsScreen(activity, commandRunner, rootView,
rootView, intentFactory, themeSwitcher, confirmDeleteDialogFactory, intentFactory, themeSwitcher, confirmDeleteDialogFactory,
filePickerDialogFactory, colorPickerDialogFactory, dialogFactory, colorPickerDialogFactory, dialogFactory, prefs));
prefs));
doNothing().when(screen).showMessage(anyInt()); doNothing().when(screen).showMessage(anyInt());
@ -240,25 +227,9 @@ public class ListHabitsScreenTest extends BaseUnitTest
@Test @Test
public void testShowImportScreen() public void testShowImportScreen()
{ {
File dir = mock(File.class); when(intentFactory.openDocument()).thenReturn(intent);
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);
screen.showImportScreen(); screen.showImportScreen();
verify(screen).showMessage(R.string.could_not_import); verify(activity).startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
} }
@Test @Test

Loading…
Cancel
Save