mirror of https://github.com/iSoron/uhabits.git
parent
d6dacfd24b
commit
a984467516
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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.intents;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.net.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.receivers.*;
|
||||||
|
|
||||||
|
import javax.inject.*;
|
||||||
|
|
||||||
|
import static android.app.PendingIntent.*;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class PendingIntentFactory
|
||||||
|
{
|
||||||
|
@NonNull
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected IntentFactory intentFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public PendingIntentFactory(@NonNull Context context)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
HabitsApplication.getComponent().inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent addCheckmark(@NonNull Habit habit,
|
||||||
|
@Nullable Long timestamp)
|
||||||
|
{
|
||||||
|
Uri data = habit.getUri();
|
||||||
|
Intent checkIntent = new Intent(context, WidgetReceiver.class);
|
||||||
|
checkIntent.setData(data);
|
||||||
|
checkIntent.setAction(WidgetReceiver.ACTION_ADD_REPETITION);
|
||||||
|
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
|
||||||
|
return PendingIntent.getBroadcast(context, 1, checkIntent,
|
||||||
|
FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent dismissNotification()
|
||||||
|
{
|
||||||
|
Intent deleteIntent = new Intent(context, ReminderReceiver.class);
|
||||||
|
deleteIntent.setAction(WidgetReceiver.ACTION_DISMISS_REMINDER);
|
||||||
|
return PendingIntent.getBroadcast(context, 0, deleteIntent,
|
||||||
|
FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent showReminder(@NonNull Habit habit,
|
||||||
|
@Nullable Long reminderTime,
|
||||||
|
long timestamp)
|
||||||
|
{
|
||||||
|
Uri uri = habit.getUri();
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, ReminderReceiver.class);
|
||||||
|
intent.setAction(ReminderReceiver.ACTION_SHOW_REMINDER);
|
||||||
|
intent.setData(uri);
|
||||||
|
intent.putExtra("timestamp", timestamp);
|
||||||
|
intent.putExtra("reminderTime", reminderTime);
|
||||||
|
int reqCode = ((int) (habit.getId() % Integer.MAX_VALUE)) + 1;
|
||||||
|
return PendingIntent.getBroadcast(context, reqCode, intent,
|
||||||
|
FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent snoozeNotification(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
Uri data = habit.getUri();
|
||||||
|
Intent snoozeIntent = new Intent(context, ReminderReceiver.class);
|
||||||
|
snoozeIntent.setData(data);
|
||||||
|
snoozeIntent.setAction(ReminderReceiver.ACTION_SNOOZE_REMINDER);
|
||||||
|
return PendingIntent.getBroadcast(context, 0, snoozeIntent,
|
||||||
|
FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent toggleCheckmark(@NonNull Habit habit,
|
||||||
|
@Nullable Long timestamp)
|
||||||
|
{
|
||||||
|
Uri data = habit.getUri();
|
||||||
|
Intent checkIntent = new Intent(context, WidgetReceiver.class);
|
||||||
|
checkIntent.setData(data);
|
||||||
|
checkIntent.setAction(WidgetReceiver.ACTION_TOGGLE_REPETITION);
|
||||||
|
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
|
||||||
|
return PendingIntent.getBroadcast(context, 2, checkIntent,
|
||||||
|
FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent showHabit(Habit habit)
|
||||||
|
{
|
||||||
|
Intent intent = intentFactory.startShowHabitActivity(context, habit);
|
||||||
|
|
||||||
|
return android.support.v4.app.TaskStackBuilder
|
||||||
|
.create(context)
|
||||||
|
.addNextIntentWithParentStack(intent)
|
||||||
|
.getPendingIntent(0, FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* 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()
|
||||||
|
{
|
||||||
|
context = HabitsApplication.getContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui.common.dialogs;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dialog that allows the user to choose a color.
|
||||||
|
*/
|
||||||
|
public class ColorPickerDialog extends com.android.colorpicker.ColorPickerDialog
|
||||||
|
{
|
||||||
|
public static ColorPickerDialog newInstance(int paletteColor)
|
||||||
|
{
|
||||||
|
ColorPickerDialog dialog = new ColorPickerDialog();
|
||||||
|
Context context = dialog.getContext();
|
||||||
|
|
||||||
|
int color = ColorUtils.getColor(context, paletteColor);
|
||||||
|
|
||||||
|
dialog.initialize(R.string.color_picker_default_title,
|
||||||
|
ColorUtils.getPalette(context), color, 4,
|
||||||
|
com.android.colorpicker.ColorPickerDialog.SIZE_SMALL);
|
||||||
|
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListener(OnColorSelectedListener listener)
|
||||||
|
{
|
||||||
|
super.setOnColorSelectedListener(c -> {
|
||||||
|
c = ColorUtils.colorToPaletteIndex(getContext(), c);
|
||||||
|
listener.onColorSelected(c);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnColorSelectedListener
|
||||||
|
{
|
||||||
|
void onColorSelected(int color);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui.common.dialogs;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.support.v7.app.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
|
||||||
|
import butterknife.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dialog that asks the user confirmation before executing a delete operation.
|
||||||
|
*/
|
||||||
|
public class ConfirmDeleteDialog extends AlertDialog
|
||||||
|
{
|
||||||
|
@BindString(R.string.delete_habits_message)
|
||||||
|
protected String question;
|
||||||
|
|
||||||
|
@BindString(android.R.string.yes)
|
||||||
|
protected String yes;
|
||||||
|
|
||||||
|
@BindString(android.R.string.no)
|
||||||
|
protected String no;
|
||||||
|
|
||||||
|
protected ConfirmDeleteDialog(@NonNull Context context,
|
||||||
|
@NonNull Callback callback)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
setTitle(R.string.delete_habits);
|
||||||
|
setMessage(question);
|
||||||
|
setButton(BUTTON_POSITIVE, yes, (dialog, which) -> callback.run());
|
||||||
|
setButton(BUTTON_NEGATIVE, no, (dialog, which) -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Callback
|
||||||
|
{
|
||||||
|
void run();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui.common.dialogs;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.habits.edit.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
import javax.inject.*;
|
||||||
|
|
||||||
|
public class DialogFactory
|
||||||
|
{
|
||||||
|
@Inject
|
||||||
|
public DialogFactory()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public ColorPickerDialog buildColorPicker(int paletteColor)
|
||||||
|
{
|
||||||
|
return ColorPickerDialog.newInstance(paletteColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public ConfirmDeleteDialog buildConfirmDeleteDialog(
|
||||||
|
@NonNull Context context,
|
||||||
|
@NonNull ConfirmDeleteDialog.Callback callback)
|
||||||
|
{
|
||||||
|
return new ConfirmDeleteDialog(context, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public CreateHabitDialog buildCreateHabitDialog()
|
||||||
|
{
|
||||||
|
return new CreateHabitDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public EditHabitDialog buildEditHabitDialog(Habit habit)
|
||||||
|
{
|
||||||
|
return EditHabitDialog.newInstance(habit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public FilePickerDialog buildFilePicker(Context context, File dir)
|
||||||
|
{
|
||||||
|
return new FilePickerDialog(context, dir);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,213 @@
|
|||||||
|
/*
|
||||||
|
* 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.ui.habits.list;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.v7.app.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.*;
|
||||||
|
import org.isoron.uhabits.ui.common.dialogs.*;
|
||||||
|
import org.isoron.uhabits.ui.common.dialogs.ColorPickerDialog.*;
|
||||||
|
import org.isoron.uhabits.ui.habits.edit.*;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
import org.junit.runners.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(JUnit4.class)
|
||||||
|
public class ListHabitsScreenTest extends BaseUnitTest
|
||||||
|
{
|
||||||
|
private BaseActivity activity;
|
||||||
|
|
||||||
|
private ListHabitsRootView rootView;
|
||||||
|
|
||||||
|
private ListHabitsScreen screen;
|
||||||
|
|
||||||
|
private ListHabitsController controller;
|
||||||
|
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
private Intent intent;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
activity = mock(BaseActivity.class);
|
||||||
|
rootView = mock(ListHabitsRootView.class);
|
||||||
|
controller = mock(ListHabitsController.class);
|
||||||
|
intent = mock(Intent.class);
|
||||||
|
|
||||||
|
habit = new Habit();
|
||||||
|
screen = new ListHabitsScreen(activity, rootView);
|
||||||
|
screen.setController(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateHabitScreen()
|
||||||
|
{
|
||||||
|
CreateHabitDialog dialog = mock(CreateHabitDialog.class);
|
||||||
|
when(dialogFactory.buildCreateHabitDialog()).thenReturn(dialog);
|
||||||
|
|
||||||
|
screen.showCreateHabitScreen();
|
||||||
|
|
||||||
|
verify(activity).showDialog(eq(dialog), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnResult_bugReport()
|
||||||
|
{
|
||||||
|
screen.onResult(0, HabitsApplication.RESULT_BUG_REPORT, null);
|
||||||
|
verify(controller).onSendBugReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnResult_exportCSV()
|
||||||
|
{
|
||||||
|
screen.onResult(0, HabitsApplication.RESULT_EXPORT_CSV, null);
|
||||||
|
verify(controller).onExportCSV();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnResult_exportDB()
|
||||||
|
{
|
||||||
|
screen.onResult(0, HabitsApplication.RESULT_EXPORT_DB, null);
|
||||||
|
verify(controller).onExportDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnResult_importData()
|
||||||
|
{
|
||||||
|
screen.onResult(0, HabitsApplication.RESULT_IMPORT_DATA, null);
|
||||||
|
testShowImportScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowAboutScreen() throws Exception
|
||||||
|
{
|
||||||
|
when(intentFactory.startAboutActivity(activity)).thenReturn(intent);
|
||||||
|
screen.showAboutScreen();
|
||||||
|
verify(activity).startActivity(eq(intent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowColorPicker()
|
||||||
|
{
|
||||||
|
habit.setColor(999);
|
||||||
|
ColorPickerDialog picker = mock(ColorPickerDialog.class);
|
||||||
|
when(dialogFactory.buildColorPicker(999)).thenReturn(picker);
|
||||||
|
OnColorSelectedListener callback = mock(OnColorSelectedListener.class);
|
||||||
|
|
||||||
|
screen.showColorPicker(habit, callback);
|
||||||
|
|
||||||
|
verify(activity).showDialog(eq(picker), any());
|
||||||
|
verify(picker).setListener(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowDeleteConfirmationScreen()
|
||||||
|
{
|
||||||
|
ConfirmDeleteDialog.Callback callback;
|
||||||
|
callback = mock(ConfirmDeleteDialog.Callback.class);
|
||||||
|
|
||||||
|
ConfirmDeleteDialog dialog = mock(ConfirmDeleteDialog.class);
|
||||||
|
when(dialogFactory.buildConfirmDeleteDialog(activity,
|
||||||
|
callback)).thenReturn(dialog);
|
||||||
|
|
||||||
|
screen.showDeleteConfirmationScreen(callback);
|
||||||
|
|
||||||
|
verify(activity).showDialog(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowEditHabitScreen()
|
||||||
|
{
|
||||||
|
EditHabitDialog dialog = mock(EditHabitDialog.class);
|
||||||
|
when(dialogFactory.buildEditHabitDialog(habit)).thenReturn(dialog);
|
||||||
|
|
||||||
|
screen.showEditHabitScreen(habit);
|
||||||
|
verify(activity).showDialog(eq(dialog), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowFAQScreen()
|
||||||
|
{
|
||||||
|
when(intentFactory.viewFAQ(activity)).thenReturn(intent);
|
||||||
|
screen.showFAQScreen();
|
||||||
|
verify(activity).startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowHabitScreen()
|
||||||
|
{
|
||||||
|
when(intentFactory.startShowHabitActivity(activity, habit)).thenReturn(
|
||||||
|
intent);
|
||||||
|
screen.showHabitScreen(habit);
|
||||||
|
verify(activity).startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(dialogFactory.buildFilePicker(activity, dir)).thenReturn(picker);
|
||||||
|
|
||||||
|
screen.showImportScreen();
|
||||||
|
|
||||||
|
verify(activity).showDialog(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowImportScreen_withInvalidPath()
|
||||||
|
{
|
||||||
|
when(dirFinder.findStorageDir(any())).thenReturn(null);
|
||||||
|
screen.showImportScreen();
|
||||||
|
verify(activity).showMessage(R.string.could_not_import);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowIntroScreen()
|
||||||
|
{
|
||||||
|
when(intentFactory.startIntroActivity(activity)).thenReturn(intent);
|
||||||
|
screen.showIntroScreen();
|
||||||
|
verify(activity).startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowSettingsScreen()
|
||||||
|
{
|
||||||
|
when(intentFactory.startSettingsActivity(activity)).thenReturn(intent);
|
||||||
|
screen.showSettingsScreen();
|
||||||
|
verify(activity).startActivityForResult(eq(intent), anyInt());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue