diff --git a/SoulissApp/build.gradle b/SoulissApp/build.gradle index 5d57b5e5..cd18d023 100644 --- a/SoulissApp/build.gradle +++ b/SoulissApp/build.gradle @@ -8,13 +8,13 @@ android { defaultConfig { applicationId "it.angelic.soulissclient" - testApplicationId "it.angelic.soulissclientest" + // testApplicationId "it.angelic.soulissclientest" minSdkVersion 14 targetSdkVersion rootProject.ext.targetSdkVersion versionName rootProject.ext.VERSION_NAME versionCode rootProject.ext.VERSION_CODE vectorDrawables.useSupportLibrary = true - // multiDexEnabled true + //multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/ManifestTest.java b/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/ManifestTest.java index b9f4281c..81a12d84 100644 --- a/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/ManifestTest.java +++ b/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/ManifestTest.java @@ -137,8 +137,8 @@ public void testTargetSdk() { } try { - final Context localeContext = getContext().createPackageContext(hostPackage, 0); - assertTrue(getContext().getApplicationInfo().targetSdkVersion >= localeContext.getApplicationInfo().targetSdkVersion); + final Context localeContext = context.createPackageContext(hostPackage, 0); + assertTrue(context.getApplicationInfo().targetSdkVersion >= localeContext.getApplicationInfo().targetSdkVersion); } catch (final NameNotFoundException e) { throw new RuntimeException(e); } diff --git a/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/SoulissTestExport.java b/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/SoulissTestExport.java index 53ec4733..07ce5e1c 100644 --- a/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/SoulissTestExport.java +++ b/SoulissApp/src/androidTest/java/it/angelic/soulissclient/net/SoulissTestExport.java @@ -1,10 +1,13 @@ package it.angelic.soulissclient.net; import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteException; import android.os.Environment; import android.util.Log; import java.io.File; +import java.io.IOException; import androidx.test.platform.app.InstrumentationRegistry; import it.angelic.soulissclient.Constants; @@ -15,6 +18,8 @@ import it.angelic.soulissclient.model.db.SoulissDBOpenHelper; import it.angelic.soulissclient.model.typicals.SoulissTypical11DigitalOutput; import it.angelic.soulissclient.model.typicals.SoulissTypical51AnalogueSensor; +import it.angelic.soulissclient.util.FontAwesomeEnum; +import it.angelic.soulissclient.util.FontAwesomeUtil; /** @@ -41,6 +46,7 @@ protected void addFakeLight() { protected void addFakeNode() { SoulissNode testNode = new SoulissNode(context, fakeNodeId); + //testNode.setIconResourceId(null); // Here i have my new database wich is not connected to the standard database of the App db.createOrUpdateNode(testNode); assertEquals(1, db.countNodes()); @@ -59,15 +65,44 @@ protected void addFakeSensor() { // Here i have my new database wich is not connected to the standard database of the App } + private boolean checkDataBase(String path) throws IOException { + SQLiteDatabase checkDB = null; + try { + File file = new File(path); + File dir = new File( file.getParent()); + if (file.exists() && !file.isDirectory()) + checkDB = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE); + else if (!dir.exists()){ + dir.mkdir(); + }else if (!file.exists()){ + file.createNewFile(); + } + } catch (SQLiteException e) { + // database does't exist yet. + + } + + if (checkDB != null) { + checkDB.close(); + } + + return checkDB != null ? true : false; + } + @Override public void setUp() throws Exception { super.setUp(); context = InstrumentationRegistry.getInstrumentation().getContext(); - //non va perche` il context e` farlocco, mDatabaseDir nulla + db = new SoulissDBHelper(context); opzioni = new SoulissPreferenceHelper(context); - SoulissDBHelper.open(); + + checkDataBase(context.getDatabasePath(SoulissDBOpenHelper.DATABASE_NAME).getPath()); + //non va perche` il context e` farlocco, mDatabaseDir nulla? + //SoulissDBHelper.open(); + + assertNotNull(db); addFakeNode(); addFakeLight(); @@ -77,7 +112,7 @@ public void setUp() throws Exception { @Override public void tearDown() throws Exception { - context.deleteDatabase(SoulissDBOpenHelper.DATABASE_NAME); + //context.deleteDatabase(SoulissDBOpenHelper.DATABASE_NAME); Log.i(Constants.TAG, "tearDown test DB"); db.close(); @@ -88,7 +123,9 @@ public void tearDown() throws Exception { } public void testExport() { - + db = new SoulissDBHelper(context); + opzioni = new SoulissPreferenceHelper(context); + SoulissDBHelper.open(); ExportDatabaseCSVTask tas = new ExportDatabaseCSVTask(); tas.loadContext(context); diff --git a/SoulissApp/src/main/java/it/angelic/soulissclient/MainActivity.java b/SoulissApp/src/main/java/it/angelic/soulissclient/MainActivity.java index deb1ccc0..a104081a 100644 --- a/SoulissApp/src/main/java/it/angelic/soulissclient/MainActivity.java +++ b/SoulissApp/src/main/java/it/angelic/soulissclient/MainActivity.java @@ -561,6 +561,21 @@ protected void onStart() { private void startLocationUpdates() { Log.w(Constants.TAG, "Requesting POS updates "); + locationCallback = new LocationCallback() { + @Override + public void onLocationResult(LocationResult locationResult) { + Log.w(Constants.TAG, "RECEIVE POS updates " + locationResult); + if (locationResult == null) { + return; + } + for (Location location : locationResult.getLocations()) { + if (launcherMainAdapter.getLocationLauncherElements() != null) { + onLocationChanged(location); + } + } + } + }; + LocationRequest locReq = createLocationRequest(); locationCallback = new LocationCallback() { @Override diff --git a/soulissLib/build.gradle b/soulissLib/build.gradle index 89e166cb..f70b9bbb 100644 --- a/soulissLib/build.gradle +++ b/soulissLib/build.gradle @@ -19,6 +19,5 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - testImplementation 'junit:junit:4.12' implementation 'androidx.appcompat:appcompat:1.1.0' }