mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Move ExportCSVTask to uhabits-core
This commit is contained in:
@@ -33,8 +33,8 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
targetCompatibility 1.8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
sourceCompatibility 1.8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
testOptions {
|
testOptions {
|
||||||
@@ -52,7 +52,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation project(":uhabits-core")
|
implementation project(":uhabits-core")
|
||||||
|
|
||||||
implementation 'com.android.support:appcompat-v7:25.3.1'
|
implementation 'com.android.support:appcompat-v7:25.3.1'
|
||||||
@@ -61,7 +60,6 @@ dependencies {
|
|||||||
implementation 'com.android.support:support-v4:25.3.1'
|
implementation 'com.android.support:support-v4:25.3.1'
|
||||||
implementation 'com.getpebble:pebblekit:3.0.0'
|
implementation 'com.getpebble:pebblekit:3.0.0'
|
||||||
implementation 'com.github.paolorotolo:appintro:3.4.0'
|
implementation 'com.github.paolorotolo:appintro:3.4.0'
|
||||||
implementation 'com.google.auto.factory:auto-factory:1.0-beta3'
|
|
||||||
implementation 'com.google.dagger:dagger:2.11-rc2'
|
implementation 'com.google.dagger:dagger:2.11-rc2'
|
||||||
implementation 'com.jakewharton:butterknife:8.6.1-SNAPSHOT'
|
implementation 'com.jakewharton:butterknife:8.6.1-SNAPSHOT'
|
||||||
implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
|
implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
|
||||||
@@ -75,18 +73,21 @@ dependencies {
|
|||||||
testImplementation 'org.hamcrest:hamcrest-library:1.4-atlassian-1'
|
testImplementation 'org.hamcrest:hamcrest-library:1.4-atlassian-1'
|
||||||
testImplementation 'org.mockito:mockito-core:2.8.9'
|
testImplementation 'org.mockito:mockito-core:2.8.9'
|
||||||
testImplementation 'org.json:json:20160810'
|
testImplementation 'org.json:json:20160810'
|
||||||
|
|
||||||
testImplementation 'org.robolectric:robolectric:3.4-rc2'
|
testImplementation 'org.robolectric:robolectric:3.4-rc2'
|
||||||
|
|
||||||
androidTestImplementation 'com.android.support:support-annotations:25.3.1'
|
androidTestImplementation 'com.android.support:support-annotations:25.3.1'
|
||||||
androidTestImplementation 'com.android.support.test:rules:0.5'
|
androidTestImplementation 'com.android.support.test:rules:0.5'
|
||||||
androidTestImplementation 'com.android.support.test:runner:0.5'
|
androidTestImplementation 'com.android.support.test:runner:0.5'
|
||||||
androidTestImplementation 'com.google.auto.factory:auto-factory:1.0-beta3'
|
|
||||||
androidTestImplementation "com.google.dexmaker:dexmaker:1.2"
|
androidTestImplementation "com.google.dexmaker:dexmaker:1.2"
|
||||||
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
|
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
|
||||||
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
|
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
|
||||||
androidTestImplementation 'com.google.guava:guava:20.0'
|
androidTestImplementation 'com.google.guava:guava:20.0'
|
||||||
|
|
||||||
compileOnly 'javax.annotation:jsr250-api:1.0'
|
compileOnly 'javax.annotation:jsr250-api:1.0'
|
||||||
|
compileOnly 'com.google.auto.factory:auto-factory:1.0-beta3'
|
||||||
|
|
||||||
|
androidTestCompileOnly 'com.google.auto.factory:auto-factory:1.0-beta3'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
|
||||||
@@ -99,11 +100,9 @@ dependencies {
|
|||||||
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2'
|
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.11-rc2'
|
||||||
androidTestAnnotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
|
androidTestAnnotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
|
||||||
androidTestAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
|
androidTestAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
|
||||||
|
|
||||||
implementation('com.opencsv:opencsv:3.9') {
|
implementation('com.opencsv:opencsv:3.9') {
|
||||||
exclude group: 'commons-logging', module: 'commons-logging'
|
exclude group: 'commons-logging', module: 'commons-logging'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation('io.socket:socket.io-client:+') {
|
implementation('io.socket:socket.io-client:+') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.support.test.*;
|
|||||||
import android.util.*;
|
import android.util.*;
|
||||||
|
|
||||||
import org.isoron.androidbase.*;
|
import org.isoron.androidbase.*;
|
||||||
|
import org.isoron.androidbase.activities.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.preferences.*;
|
import org.isoron.uhabits.preferences.*;
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
@@ -68,6 +69,8 @@ public class BaseAndroidTest
|
|||||||
|
|
||||||
protected ModelFactory modelFactory;
|
protected ModelFactory modelFactory;
|
||||||
|
|
||||||
|
protected BaseSystem baseSystem;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
@@ -90,6 +93,8 @@ public class BaseAndroidTest
|
|||||||
.appModule(new AppModule(targetContext.getApplicationContext()))
|
.appModule(new AppModule(targetContext.getApplicationContext()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
baseSystem = new BaseSystem(targetContext);
|
||||||
|
|
||||||
HabitsApplication.setComponent(component);
|
HabitsApplication.setComponent(component);
|
||||||
prefs = component.getPreferences();
|
prefs = component.getPreferences();
|
||||||
habitList = component.getHabitList();
|
habitList = component.getHabitList();
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import android.support.annotation.*;
|
|||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.androidbase.activities.*;
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.widgets.*;
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
|
||||||
@@ -170,7 +172,7 @@ public class BaseViewTest extends BaseAndroidTest
|
|||||||
{
|
{
|
||||||
File dir = FileUtils.getSDCardDir("test-screenshots");
|
File dir = FileUtils.getSDCardDir("test-screenshots");
|
||||||
if (dir == null)
|
if (dir == null)
|
||||||
dir = FileUtils.getFilesDir(targetContext, "test-screenshots");
|
dir = baseSystem.getFilesDir("test-screenshots");
|
||||||
if (dir == null) throw new RuntimeException(
|
if (dir == null) throw new RuntimeException(
|
||||||
"Could not find suitable dir for screenshots");
|
"Could not find suitable dir for screenshots");
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import android.support.test.*;
|
|||||||
import android.support.test.runner.*;
|
import android.support.test.runner.*;
|
||||||
import android.test.suitebuilder.annotation.*;
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.junit.runner.*;
|
import org.junit.runner.*;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.support.test.*;
|
|||||||
import android.support.test.runner.*;
|
import android.support.test.runner.*;
|
||||||
import android.test.suitebuilder.annotation.*;
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|||||||
@@ -54,9 +54,11 @@ public class ExportCSVTaskTest extends BaseAndroidTest
|
|||||||
|
|
||||||
List<Habit> selected = new LinkedList<>();
|
List<Habit> selected = new LinkedList<>();
|
||||||
for (Habit h : habitList) selected.add(h);
|
for (Habit h : habitList) selected.add(h);
|
||||||
|
File outputDir = baseSystem.getFilesDir("CSV");
|
||||||
|
assertNotNull(outputDir);
|
||||||
|
|
||||||
taskRunner.execute(
|
taskRunner.execute(
|
||||||
new ExportCSVTask(targetContext,habitList, selected, archiveFilename -> {
|
new ExportCSVTask(habitList, selected, outputDir, archiveFilename -> {
|
||||||
assertThat(archiveFilename, is(not(nullValue())));
|
assertThat(archiveFilename, is(not(nullValue())));
|
||||||
File f = new File(archiveFilename);
|
File f = new File(archiveFilename);
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
|
|||||||
@@ -23,20 +23,19 @@ import android.support.test.runner.*;
|
|||||||
import android.test.suitebuilder.annotation.*;
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.tasks.android.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.junit.runner.*;
|
import org.junit.runner.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
import static junit.framework.Assert.*;
|
import static junit.framework.Assert.*;
|
||||||
import static org.hamcrest.MatcherAssert.*;
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
import static org.hamcrest.core.IsNot.not;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public class ExportDBTaskTest extends BaseAndroidTest
|
public class ExportDBTaskTest extends BaseAndroidTest
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
@@ -46,9 +45,9 @@ public class ExportDBTaskTest extends BaseAndroidTest
|
|||||||
@Test
|
@Test
|
||||||
public void testExportCSV() throws Throwable
|
public void testExportCSV() throws Throwable
|
||||||
{
|
{
|
||||||
ExportDBTask task = new ExportDBTask(targetContext, filename -> {
|
ExportDBTask task =
|
||||||
assertThat(filename, is(not(nullValue())));
|
new ExportDBTask(targetContext, baseSystem, filename -> {
|
||||||
|
assertNotNull(filename);
|
||||||
File f = new File(filename);
|
File f = new File(filename);
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
assertTrue(f.canRead());
|
assertTrue(f.canRead());
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ public abstract class BaseMenu
|
|||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public BaseActivity getActivity()
|
||||||
|
{
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare that the menu has changed, and should be recreated.
|
* Declare that the menu has changed, and should be recreated.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,8 +22,11 @@ package org.isoron.androidbase.activities;
|
|||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
import android.support.v4.content.*;
|
||||||
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
@@ -52,6 +55,19 @@ public class BaseSystem
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public File getFilesDir(@Nullable String relativePath)
|
||||||
|
{
|
||||||
|
File externalFilesDirs[] = ContextCompat.getExternalFilesDirs(context, null);
|
||||||
|
if (externalFilesDirs == null)
|
||||||
|
{
|
||||||
|
Log.e("BaseSystem", "getFilesDir: getExternalFilesDirs returned null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FileUtils.getDir(externalFilesDirs, relativePath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Captures a bug report and saves it to a file in the SD card.
|
* Captures a bug report and saves it to a file in the SD card.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -70,7 +86,7 @@ public class BaseSystem
|
|||||||
|
|
||||||
if (context == null) throw new RuntimeException(
|
if (context == null) throw new RuntimeException(
|
||||||
"application context should not be null");
|
"application context should not be null");
|
||||||
File dir = FileUtils.getFilesDir(context, "Logs");
|
File dir = getFilesDir("Logs");
|
||||||
if (dir == null) throw new IOException("log dir should not be null");
|
if (dir == null) throw new IOException("log dir should not be null");
|
||||||
|
|
||||||
File logFile =
|
File logFile =
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of Loop Habit Tracker.
|
* This file is part of Loop Habit Tracker.
|
||||||
*
|
*
|
||||||
@@ -17,12 +17,10 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.isoron.uhabits.utils;
|
package org.isoron.androidbase.utils;
|
||||||
|
|
||||||
import android.content.*;
|
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.v4.content.*;
|
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -52,7 +50,7 @@ public abstract class FileUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static File getDir(@NonNull File potentialParentDirs[],
|
public static File getDir(@NonNull File potentialParentDirs[],
|
||||||
@Nullable String relativePath)
|
@Nullable String relativePath)
|
||||||
{
|
{
|
||||||
if (relativePath == null) relativePath = "";
|
if (relativePath == null) relativePath = "";
|
||||||
@@ -67,7 +65,7 @@ public abstract class FileUtils
|
|||||||
|
|
||||||
if (chosenDir == null)
|
if (chosenDir == null)
|
||||||
{
|
{
|
||||||
Log.e("DatabaseHelper",
|
Log.e("FileUtils",
|
||||||
"getDir: all potential parents are null or non-writable");
|
"getDir: all potential parents are null or non-writable");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -76,7 +74,7 @@ public abstract class FileUtils
|
|||||||
String.format("%s/%s/", chosenDir.getAbsolutePath(), relativePath));
|
String.format("%s/%s/", chosenDir.getAbsolutePath(), relativePath));
|
||||||
if (!dir.exists() && !dir.mkdirs())
|
if (!dir.exists() && !dir.mkdirs())
|
||||||
{
|
{
|
||||||
Log.e("DatabaseHelper",
|
Log.e("FileUtils",
|
||||||
"getDir: chosen dir does not exist and cannot be created");
|
"getDir: chosen dir does not exist and cannot be created");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -84,22 +82,6 @@ public abstract class FileUtils
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static File getFilesDir(@NonNull Context context, @Nullable String relativePath)
|
|
||||||
{
|
|
||||||
File externalFilesDirs[] =
|
|
||||||
ContextCompat.getExternalFilesDirs(context, null);
|
|
||||||
|
|
||||||
if (externalFilesDirs == null)
|
|
||||||
{
|
|
||||||
Log.e("DatabaseHelper",
|
|
||||||
"getFilesDir: getExternalFilesDirs returned null");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getDir(externalFilesDirs, relativePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static File getSDCardDir(@Nullable String relativePath)
|
public static File getSDCardDir(@Nullable String relativePath)
|
||||||
{
|
{
|
||||||
@@ -32,6 +32,7 @@ import org.isoron.uhabits.notifications.*;
|
|||||||
import org.isoron.uhabits.preferences.*;
|
import org.isoron.uhabits.preferences.*;
|
||||||
import org.isoron.uhabits.sync.*;
|
import org.isoron.uhabits.sync.*;
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
|
import org.isoron.uhabits.tasks.android.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.widgets.*;
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.isoron.uhabits.commands.*;
|
|||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.preferences.*;
|
import org.isoron.uhabits.preferences.*;
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
|
import org.isoron.uhabits.tasks.android.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.widgets.*;
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
|
||||||
@@ -105,8 +106,10 @@ public class ListHabitsController
|
|||||||
{
|
{
|
||||||
List<Habit> selected = new LinkedList<>();
|
List<Habit> selected = new LinkedList<>();
|
||||||
for (Habit h : habitList) selected.add(h);
|
for (Habit h : habitList) selected.add(h);
|
||||||
|
File outputDir = system.getFilesDir("CSV");
|
||||||
|
|
||||||
taskRunner.execute(exportCSVFactory.create(selected, filename -> {
|
taskRunner.execute(
|
||||||
|
exportCSVFactory.create(selected, outputDir, filename -> {
|
||||||
if (filename != null) screen.showSendFileScreen(filename);
|
if (filename != null) screen.showSendFileScreen(filename);
|
||||||
else screen.showMessage(R.string.could_not_export);
|
else screen.showMessage(R.string.could_not_export);
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.view.*;
|
|||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
import org.isoron.androidbase.activities.*;
|
import org.isoron.androidbase.activities.*;
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.activities.*;
|
import org.isoron.uhabits.activities.*;
|
||||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.isoron.uhabits.*;
|
|||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
@@ -34,6 +35,9 @@ import javax.inject.*;
|
|||||||
@ActivityScope
|
@ActivityScope
|
||||||
public class ShowHabitsMenu extends BaseMenu
|
public class ShowHabitsMenu extends BaseMenu
|
||||||
{
|
{
|
||||||
|
@NonNull
|
||||||
|
private final BaseSystem system;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ShowHabitScreen screen;
|
private final ShowHabitScreen screen;
|
||||||
|
|
||||||
@@ -48,12 +52,14 @@ public class ShowHabitsMenu extends BaseMenu
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ShowHabitsMenu(@NonNull BaseActivity activity,
|
public ShowHabitsMenu(@NonNull BaseActivity activity,
|
||||||
|
@NonNull BaseSystem system,
|
||||||
@NonNull ShowHabitScreen screen,
|
@NonNull ShowHabitScreen screen,
|
||||||
@NonNull Habit habit,
|
@NonNull Habit habit,
|
||||||
@NonNull ExportCSVTaskFactory exportCSVFactory,
|
@NonNull ExportCSVTaskFactory exportCSVFactory,
|
||||||
@NonNull TaskRunner taskRunner)
|
@NonNull TaskRunner taskRunner)
|
||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
|
this.system = system;
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.taskRunner = taskRunner;
|
this.taskRunner = taskRunner;
|
||||||
@@ -64,7 +70,9 @@ public class ShowHabitsMenu extends BaseMenu
|
|||||||
{
|
{
|
||||||
List<Habit> selected = new LinkedList<>();
|
List<Habit> selected = new LinkedList<>();
|
||||||
selected.add(habit);
|
selected.add(habit);
|
||||||
ExportCSVTask task = exportCSVFactory.create(selected, filename -> {
|
File outputDir = system.getFilesDir("CSV");
|
||||||
|
ExportCSVTask task = exportCSVFactory.create(selected,
|
||||||
|
outputDir, filename -> {
|
||||||
if (filename != null) screen.showSendFileScreen(filename);
|
if (filename != null) screen.showSendFileScreen(filename);
|
||||||
else screen.showMessage(R.string.could_not_export);
|
else screen.showMessage(R.string.could_not_export);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -68,41 +68,41 @@ public class CommandParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Command parse(@NonNull JSONObject json) throws JSONException
|
public Command parse(@NonNull String json) throws JSONException
|
||||||
{
|
{
|
||||||
String event = json.getString("event");
|
String event = new JSONObject(json).getString("event");
|
||||||
Gson gson = new GsonBuilder().create();
|
Gson gson = new GsonBuilder().create();
|
||||||
|
|
||||||
if (event.equals("Archive")) return gson
|
if (event.equals("Archive")) return gson
|
||||||
.fromJson(json.toString(), ArchiveHabitsCommand.Record.class)
|
.fromJson(json, ArchiveHabitsCommand.Record.class)
|
||||||
.toCommand(habitList);
|
.toCommand(habitList);
|
||||||
|
|
||||||
if (event.equals("ChangeColor")) return gson
|
if (event.equals("ChangeColor")) return gson
|
||||||
.fromJson(json.toString(), ChangeHabitColorCommand.Record.class)
|
.fromJson(json, ChangeHabitColorCommand.Record.class)
|
||||||
.toCommand(habitList);
|
.toCommand(habitList);
|
||||||
|
|
||||||
if (event.equals("CreateHabit")) return gson
|
if (event.equals("CreateHabit")) return gson
|
||||||
.fromJson(json.toString(), CreateHabitCommand.Record.class)
|
.fromJson(json, CreateHabitCommand.Record.class)
|
||||||
.toCommand(modelFactory, habitList);
|
.toCommand(modelFactory, habitList);
|
||||||
|
|
||||||
if (event.equals("CreateRep")) return gson
|
if (event.equals("CreateRep")) return gson
|
||||||
.fromJson(json.toString(), CreateRepetitionCommand.Record.class)
|
.fromJson(json, CreateRepetitionCommand.Record.class)
|
||||||
.toCommand(habitList);
|
.toCommand(habitList);
|
||||||
|
|
||||||
if (event.equals("DeleteHabit")) return gson
|
if (event.equals("DeleteHabit")) return gson
|
||||||
.fromJson(json.toString(), DeleteHabitsCommand.Record.class)
|
.fromJson(json, DeleteHabitsCommand.Record.class)
|
||||||
.toCommand(habitList);
|
.toCommand(habitList);
|
||||||
|
|
||||||
if (event.equals("EditHabit")) return gson
|
if (event.equals("EditHabit")) return gson
|
||||||
.fromJson(json.toString(), EditHabitCommand.Record.class)
|
.fromJson(json, EditHabitCommand.Record.class)
|
||||||
.toCommand(modelFactory, habitList);
|
.toCommand(modelFactory, habitList);
|
||||||
|
|
||||||
if (event.equals("Toggle")) return gson
|
if (event.equals("Toggle")) return gson
|
||||||
.fromJson(json.toString(), ToggleRepetitionCommand.Record.class)
|
.fromJson(json, ToggleRepetitionCommand.Record.class)
|
||||||
.toCommand(habitList);
|
.toCommand(habitList);
|
||||||
|
|
||||||
if (event.equals("Unarchive")) return gson
|
if (event.equals("Unarchive")) return gson
|
||||||
.fromJson(json.toString(), UnarchiveHabitsCommand.Record.class)
|
.fromJson(json, UnarchiveHabitsCommand.Record.class)
|
||||||
.toCommand(habitList);
|
.toCommand(habitList);
|
||||||
|
|
||||||
throw new IllegalStateException("Unknown command");
|
throw new IllegalStateException("Unknown command");
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ import android.util.*;
|
|||||||
import com.activeandroid.*;
|
import com.activeandroid.*;
|
||||||
|
|
||||||
import org.isoron.androidbase.*;
|
import org.isoron.androidbase.*;
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.DatabaseUtils;
|
import org.isoron.uhabits.utils.DatabaseUtils;
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ public class SyncManager implements CommandRunner.Listener
|
|||||||
|
|
||||||
private void executeCommand(JSONObject root) throws JSONException
|
private void executeCommand(JSONObject root) throws JSONException
|
||||||
{
|
{
|
||||||
Command received = commandParser.parse(root);
|
Command received = commandParser.parse(root.toString());
|
||||||
received.setRemote(true);
|
received.setRemote(true);
|
||||||
|
|
||||||
for (Event e : pendingConfirmation)
|
for (Event e : pendingConfirmation)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of Loop Habit Tracker.
|
* This file is part of Loop Habit Tracker.
|
||||||
*
|
*
|
||||||
@@ -17,11 +17,12 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.isoron.uhabits.tasks;
|
package org.isoron.uhabits.tasks.android;
|
||||||
|
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.tasks.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of Loop Habit Tracker.
|
* This file is part of Loop Habit Tracker.
|
||||||
*
|
*
|
||||||
@@ -17,15 +17,16 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.isoron.uhabits.tasks;
|
package org.isoron.uhabits.tasks.android;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import com.google.auto.factory.AutoFactory;
|
import com.google.auto.factory.*;
|
||||||
import com.google.auto.factory.Provided;
|
|
||||||
|
|
||||||
import org.isoron.androidbase.AppContext;
|
import org.isoron.androidbase.*;
|
||||||
|
import org.isoron.androidbase.activities.*;
|
||||||
|
import org.isoron.uhabits.tasks.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -38,11 +39,16 @@ public class ExportDBTask implements Task
|
|||||||
@NonNull
|
@NonNull
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
|
private BaseSystem system;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Listener listener;
|
private final Listener listener;
|
||||||
|
|
||||||
public ExportDBTask(@Provided @AppContext @NonNull Context context, @NonNull Listener listener)
|
public ExportDBTask(@Provided @AppContext @NonNull Context context,
|
||||||
|
@Provided @NonNull BaseSystem system,
|
||||||
|
@NonNull Listener listener)
|
||||||
{
|
{
|
||||||
|
this.system = system;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
@@ -54,7 +60,7 @@ public class ExportDBTask implements Task
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File dir = FileUtils.getFilesDir(context, "Backups");
|
File dir = system.getFilesDir("Backups");
|
||||||
if (dir == null) return;
|
if (dir == null) return;
|
||||||
|
|
||||||
filename = DatabaseUtils.saveDatabaseCopy(context, dir);
|
filename = DatabaseUtils.saveDatabaseCopy(context, dir);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of Loop Habit Tracker.
|
* This file is part of Loop Habit Tracker.
|
||||||
*
|
*
|
||||||
@@ -17,13 +17,14 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.isoron.uhabits.tasks;
|
package org.isoron.uhabits.tasks.android;
|
||||||
|
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import com.google.auto.factory.*;
|
import com.google.auto.factory.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.io.*;
|
import org.isoron.uhabits.io.*;
|
||||||
|
import org.isoron.uhabits.tasks.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of Loop Habit Tracker.
|
* This file is part of Loop Habit Tracker.
|
||||||
*
|
*
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* Provides async tasks for useful operations such as {@link
|
* Provides async tasks for useful operations such as {@link
|
||||||
* org.isoron.uhabits.tasks.ExportCSVTask}.
|
* org.isoron.uhabits.tasks.ExportCSVTask}.
|
||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.tasks;
|
package org.isoron.uhabits.tasks.android;
|
||||||
@@ -24,6 +24,7 @@ import android.support.annotation.*;
|
|||||||
|
|
||||||
import com.activeandroid.*;
|
import com.activeandroid.*;
|
||||||
|
|
||||||
|
import org.isoron.androidbase.utils.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.sqlite.*;
|
import org.isoron.uhabits.models.sqlite.*;
|
||||||
import org.isoron.uhabits.models.sqlite.records.*;
|
import org.isoron.uhabits.models.sqlite.records.*;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.activities.habits.show;
|
|||||||
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
|
import org.isoron.androidbase.activities.*;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
@@ -43,19 +44,20 @@ public class ShowHabitsMenuTest extends BaseUnitTest
|
|||||||
|
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
|
||||||
private ExportCSVTask task;
|
private BaseSystem system;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
activity = mock(ShowHabitActivity.class);
|
activity = mock(ShowHabitActivity.class);
|
||||||
|
system = mock(BaseSystem.class);
|
||||||
screen = mock(ShowHabitScreen.class);
|
screen = mock(ShowHabitScreen.class);
|
||||||
habit = mock(Habit.class);
|
habit = mock(Habit.class);
|
||||||
exportCSVFactory = mock(ExportCSVTaskFactory.class);
|
exportCSVFactory = mock(ExportCSVTaskFactory.class);
|
||||||
taskRunner = mock(TaskRunner.class);
|
taskRunner = mock(TaskRunner.class);
|
||||||
menu = new ShowHabitsMenu(activity, screen, habit, exportCSVFactory,
|
menu = new ShowHabitsMenu(activity, system, screen, habit,
|
||||||
taskRunner);
|
exportCSVFactory, taskRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ apply plugin: 'java'
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'javax.annotation:jsr250-api:1.0'
|
compileOnly 'javax.annotation:jsr250-api:1.0'
|
||||||
|
compileOnly 'com.google.auto.factory:auto-factory:1.0-beta3'
|
||||||
|
|
||||||
implementation 'com.google.dagger:dagger:2.11-rc2'
|
implementation 'com.google.dagger:dagger:2.11-rc2'
|
||||||
implementation 'com.android.support:support-annotations:25.3.1'
|
implementation 'com.android.support:support-annotations:25.3.1'
|
||||||
implementation 'com.google.auto.factory:auto-factory:1.0-beta3'
|
|
||||||
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
implementation 'org.apache.commons:commons-lang3:3.5'
|
implementation 'org.apache.commons:commons-lang3:3.5'
|
||||||
implementation 'com.google.code.gson:gson:2.7'
|
implementation 'com.google.code.gson:gson:2.7'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of Loop Habit Tracker.
|
* This file is part of Loop Habit Tracker.
|
||||||
*
|
*
|
||||||
@@ -19,15 +19,12 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.tasks;
|
package org.isoron.uhabits.tasks;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import com.google.auto.factory.*;
|
import com.google.auto.factory.*;
|
||||||
|
|
||||||
import org.isoron.androidbase.AppContext;
|
|
||||||
import org.isoron.uhabits.io.*;
|
import org.isoron.uhabits.io.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -37,27 +34,26 @@ public class ExportCSVTask implements Task
|
|||||||
{
|
{
|
||||||
private String archiveFilename;
|
private String archiveFilename;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final Context context;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<Habit> selectedHabits;
|
private final List<Habit> selectedHabits;
|
||||||
|
|
||||||
|
private File outputDir;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ExportCSVTask.Listener listener;
|
private final ExportCSVTask.Listener listener;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final HabitList habitList;
|
private final HabitList habitList;
|
||||||
|
|
||||||
public ExportCSVTask(@Provided @AppContext @NonNull Context context,
|
public ExportCSVTask(@Provided @NonNull HabitList habitList,
|
||||||
@Provided @NonNull HabitList habitList,
|
|
||||||
@NonNull List<Habit> selectedHabits,
|
@NonNull List<Habit> selectedHabits,
|
||||||
|
@NonNull File outputDir,
|
||||||
@NonNull Listener listener)
|
@NonNull Listener listener)
|
||||||
{
|
{
|
||||||
this.context = context;
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.habitList = habitList;
|
this.habitList = habitList;
|
||||||
this.selectedHabits = selectedHabits;
|
this.selectedHabits = selectedHabits;
|
||||||
|
this.outputDir = outputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,11 +61,8 @@ public class ExportCSVTask implements Task
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File dir = FileUtils.getFilesDir(context, "CSV");
|
|
||||||
if (dir == null) return;
|
|
||||||
|
|
||||||
HabitsCSVExporter exporter;
|
HabitsCSVExporter exporter;
|
||||||
exporter = new HabitsCSVExporter(habitList, selectedHabits, dir);
|
exporter = new HabitsCSVExporter(habitList, selectedHabits, outputDir);
|
||||||
archiveFilename = exporter.writeArchive();
|
archiveFilename = exporter.writeArchive();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
Reference in New Issue
Block a user