Wlo-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
March 2014
- 4 participants
- 35 discussions
Author: maven-release
Date: 2014-03-04 10:42:48 +0100 (Tue, 04 Mar 2014)
New Revision: 69
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/69
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-04 09:42:39 UTC (rev 68)
+++ trunk/pom.xml 2014-03-04 09:42:48 UTC (rev 69)
@@ -33,7 +33,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wlo</artifactId>
- <version>0.2</version>
+ <version>0.3-SNAPSHOT</version>
<name>WLO</name>
<description>
@@ -76,12 +76,12 @@
</developers>
<scm>
- <url>https://svn.codelutin.com/wlo/tags/wlo-0.2</url>
+ <url>https://svn.codelutin.com/wlo/trunk</url>
<connection>
- scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.2
+ scm:svn:https://svn.codelutin.com/wlo/trunk
</connection>
<developerConnection>
- scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.2
+ scm:svn:https://svn.codelutin.com/wlo/trunk
</developerConnection>
</scm>
<distributionManagement>
1
0
Author: maven-release
Date: 2014-03-04 10:42:39 +0100 (Tue, 04 Mar 2014)
New Revision: 68
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/68
Log:
[maven-release-plugin] copy for tag wlo-0.2
Added:
tags/wlo-0.2/
1
0
Author: maven-release
Date: 2014-03-04 10:42:31 +0100 (Tue, 04 Mar 2014)
New Revision: 67
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/67
Log:
[maven-release-plugin] prepare release wlo-0.2
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-04 09:41:24 UTC (rev 66)
+++ trunk/pom.xml 2014-03-04 09:42:31 UTC (rev 67)
@@ -21,8 +21,7 @@
#L%
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -34,7 +33,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wlo</artifactId>
- <version>0.2-SNAPSHOT</version>
+ <version>0.2</version>
<name>WLO</name>
<description>
@@ -77,12 +76,12 @@
</developers>
<scm>
- <url>https://svn.codelutin.com/wlo/trunk</url>
+ <url>https://svn.codelutin.com/wlo/tags/wlo-0.2</url>
<connection>
- scm:svn:https://svn.codelutin.com/wlo/trunk
+ scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.2
</connection>
<developerConnection>
- scm:svn:https://svn.codelutin.com/wlo/trunk
+ scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.2
</developerConnection>
</scm>
<distributionManagement>
1
0
04 Mar '14
Author: kmorin
Date: 2014-03-04 10:41:24 +0100 (Tue, 04 Mar 2014)
New Revision: 66
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/66
Log:
fix issues to release
Modified:
trunk/pom.xml
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-04 09:26:46 UTC (rev 65)
+++ trunk/pom.xml 2014-03-04 09:41:24 UTC (rev 66)
@@ -177,6 +177,12 @@
</dependency>
<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>3.0-rc-2</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
@@ -336,7 +342,7 @@
<goals>
<goal>share-server-secret</goal>
</goals>
- <phase>package</phase>
+ <phase>prepare-package</phase>
<configuration>
<serverId>codelutin-keystore</serverId>
<privateKeyOut>jarsigner.keystore</privateKeyOut>
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-04 09:26:46 UTC (rev 65)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-04 09:41:24 UTC (rev 66)
@@ -87,7 +87,7 @@
import fr.ifremer.wlo.utils.BaseTextWatcher;
import fr.ifremer.wlo.utils.BigFinFeedReaderRecord;
import fr.ifremer.wlo.utils.UIUtils;
-import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections.CollectionUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
1
0
r65 - in trunk: res/values res/values-fr src/fr/ifremer/wlo/preferences src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 04 Mar '14
by kmorin@users.forge.codelutin.com 04 Mar '14
04 Mar '14
Author: kmorin
Date: 2014-03-04 10:26:46 +0100 (Tue, 04 Mar 2014)
New Revision: 65
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/65
Log:
fixes #4630 [TECH] Mise ?\195?\160 jour automatique de l'application
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-04 09:17:33 UTC (rev 64)
+++ trunk/res/values/strings.xml 2014-03-04 09:26:46 UTC (rev 65)
@@ -226,5 +226,6 @@
<string name="update_available_title">New version available</string>
<string name="update_available_message">A new version of WLO is available. Would you like to install it?</string>
<string name="no_update">You already have the latest version of the application</string>
+ <string name="update_error">An error occured while checking the last version</string>
</resources>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-04 09:17:33 UTC (rev 64)
+++ trunk/res/values-fr/strings.xml 2014-03-04 09:26:46 UTC (rev 65)
@@ -218,5 +218,6 @@
<string name="update_available_title">Nouvelle version disponible</string>
<string name="update_available_message">Une nouvelle version de WLO est disponible. Voulez-vous la télécharger et l\'installer ?</string>
<string name="no_update">Vous avez déjà la version la plus récente de l\'application</string>
+ <string name="update_error">Une erreur est survenue pendant la vérification de la version</string>
</resources>
Modified: trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-04 09:17:33 UTC (rev 64)
+++ trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-04 09:26:46 UTC (rev 65)
@@ -489,11 +489,6 @@
.create().show();
}
- @Override
- protected void onCancelled() {
- super.onCancelled();
- onCancelled(null);
- }
}
}
Modified: trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-04 09:17:33 UTC (rev 64)
+++ trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-04 09:26:46 UTC (rev 65)
@@ -156,4 +156,12 @@
}
}
+ @Override
+ protected void onCancelled(String s) {
+ super.onCancelled(s);
+ if (showLoading) {
+ loadingDialog.dismiss();
+ Toast.makeText(context, R.string.update_error, Toast.LENGTH_LONG).show();
+ }
+ }
}
1
0
r64 - in trunk: res/values res/values-fr res/xml src/fr/ifremer/wlo src/fr/ifremer/wlo/imports src/fr/ifremer/wlo/models/categorization src/fr/ifremer/wlo/preferences src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 04 Mar '14
by kmorin@users.forge.codelutin.com 04 Mar '14
04 Mar '14
Author: kmorin
Date: 2014-03-04 10:17:33 +0100 (Tue, 04 Mar 2014)
New Revision: 64
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/64
Log:
fixes #4630 [TECH] Mise ?\195?\160 jour automatique de l'application
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/res/xml/preferences.xml
trunk/src/fr/ifremer/wlo/WloApplication.java
trunk/src/fr/ifremer/wlo/imports/QualitativeValueRowModel.java
trunk/src/fr/ifremer/wlo/models/categorization/CategoryModel.java
trunk/src/fr/ifremer/wlo/models/categorization/QualitativeValueModel.java
trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java
trunk/src/fr/ifremer/wlo/preferences/MultiSelectionActivity.java
trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/res/values/strings.xml 2014-03-04 09:17:33 UTC (rev 64)
@@ -127,6 +127,10 @@
<string name="qualitative_values_nb">%s qualitative values</string>
<string name="category_created">The category has been successfully created.</string>
+ <string name="preferences_update">Update</string>
+ <string name="preferences_check_update">Check if the application is up to date</string>
+ <string name="preferences_current_version">Current version: %s</string>
+
<!-- Contexts -->
<string name="add_context">Create a new context</string>
<string name="contexts_title">Contexts</string>
@@ -217,8 +221,10 @@
<string name="crash_dialog_ok_toast">Thank you !</string>
<!-- Update -->
+ <string name="checking_update">Checking last available version</string>
<string name="update_dowload_error">Error while downloading the new version of WLO</string>
<string name="update_available_title">New version available</string>
<string name="update_available_message">A new version of WLO is available. Would you like to install it?</string>
+ <string name="no_update">You already have the latest version of the application</string>
</resources>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/res/values-fr/strings.xml 2014-03-04 09:17:33 UTC (rev 64)
@@ -120,6 +120,10 @@
<string name="qualitative_values_nb">%s valeurs pour cette catégorie</string>
<string name="category_created">La catégorie a bien été créée.</string>
+ <string name="preferences_update">Mise à jour</string>
+ <string name="preferences_check_update">Vérifier si l\'application est à jour</string>
+ <string name="preferences_current_version">Version actuelle : %s</string>
+
<!-- Contexts -->
<string name="add_context">Créer un nouveau contexte</string>
<string name="contexts_title">Contextes</string>
@@ -209,8 +213,10 @@
<string name="crash_dialog_ok_toast">Merci !</string>
<!-- Update -->
+ <string name="checking_update">Recherche d\'une version plus récente</string>
<string name="update_dowload_error">Erreur lors du téléchargement de la dernière version de WLO</string>
<string name="update_available_title">Nouvelle version disponible</string>
<string name="update_available_message">Une nouvelle version de WLO est disponible. Voulez-vous la télécharger et l\'installer ?</string>
+ <string name="no_update">Vous avez déjà la version la plus récente de l\'application</string>
</resources>
Modified: trunk/res/xml/preferences.xml
===================================================================
--- trunk/res/xml/preferences.xml 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/res/xml/preferences.xml 2014-03-04 09:17:33 UTC (rev 64)
@@ -85,4 +85,13 @@
</PreferenceCategory>
+ <PreferenceCategory
+ android:title="@string/preferences_update"
+ android:key="preferences_update">
+
+ <Preference android:title="@string/preferences_check_update"
+ android:key="preferences_check_update"/>
+
+ </PreferenceCategory>
+
</PreferenceScreen>
\ No newline at end of file
Modified: trunk/src/fr/ifremer/wlo/WloApplication.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloApplication.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/WloApplication.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,5 +1,29 @@
package fr.ifremer.wlo;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import android.app.Application;
import android.app.DownloadManager;
import android.app.ProgressDialog;
Modified: trunk/src/fr/ifremer/wlo/imports/QualitativeValueRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/QualitativeValueRowModel.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/imports/QualitativeValueRowModel.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,5 +1,29 @@
package fr.ifremer.wlo.imports;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
import org.nuiton.csv.ValueSetter;
Modified: trunk/src/fr/ifremer/wlo/models/categorization/CategoryModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/categorization/CategoryModel.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/models/categorization/CategoryModel.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,5 +1,29 @@
package fr.ifremer.wlo.models.categorization;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;
Modified: trunk/src/fr/ifremer/wlo/models/categorization/QualitativeValueModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/categorization/QualitativeValueModel.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/models/categorization/QualitativeValueModel.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,5 +1,29 @@
package fr.ifremer.wlo.models.categorization;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;
Modified: trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,5 +1,29 @@
package fr.ifremer.wlo.preferences;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
Modified: trunk/src/fr/ifremer/wlo/preferences/MultiSelectionActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/MultiSelectionActivity.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/preferences/MultiSelectionActivity.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,6 +1,30 @@
package fr.ifremer.wlo.preferences;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
Modified: trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -30,6 +30,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
@@ -55,6 +56,7 @@
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
import fr.ifremer.wlo.utils.ImportUtil;
import fr.ifremer.wlo.utils.UIUtils;
+import fr.ifremer.wlo.utils.UpdateCheckTask;
import fr.ifremer.wlo.utils.filechooser.FileDialog;
import fr.ifremer.wlo.utils.filechooser.SelectionMode;
import org.apache.commons.io.FileUtils;
@@ -193,6 +195,23 @@
ScientificSpecies.class,
REQUEST_FAVORITES_SCIENTIFIC_SPECIES);
+ // update
+ Preference updatePref = findPreference("preferences_check_update");
+ try {
+ String currentVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
+ updatePref.setSummary(getString(R.string.preferences_current_version, currentVersion));
+
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "error while getting the version");
+ }
+ updatePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ new UpdateCheckTask(getActivity(), true).execute();
+ return true;
+ }
+ });
+
}
@Override
Modified: trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-03 17:36:04 UTC (rev 63)
+++ trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-04 09:17:33 UTC (rev 64)
@@ -1,7 +1,32 @@
package fr.ifremer.wlo.utils;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
import android.app.AlertDialog;
import android.app.DownloadManager;
+import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -41,12 +66,30 @@
public static final String URL_PROP = "application.url";
protected Context context;
+ protected boolean showLoading;
+ protected ProgressDialog loadingDialog;
public UpdateCheckTask(Context context) {
+ this(context, false);
+ }
+
+ public UpdateCheckTask(Context context, boolean showLoading) {
this.context = context;
+ this.showLoading = showLoading;
}
@Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ if (showLoading) {
+ loadingDialog = new ProgressDialog(context);
+ loadingDialog.setIndeterminate(true);
+ loadingDialog.setMessage(context.getString(R.string.checking_update));
+ loadingDialog.show();
+ }
+ }
+
+ @Override
protected String doInBackground(String... params) {
String result;
@@ -85,6 +128,9 @@
@Override
protected void onPostExecute(final String result) {
super.onPostExecute(result);
+ if (showLoading) {
+ loadingDialog.dismiss();
+ }
if (result != null && WloBaseActivity.getDownloadingApkId() == null) {
new AlertDialog.Builder(context)
@@ -105,6 +151,8 @@
.create()
.show();
+ } else if (showLoading) {
+ Toast.makeText(context, R.string.no_update, Toast.LENGTH_LONG).show();
}
}
1
0
r63 - in trunk: . res/values res/values-fr src/fr/ifremer/wlo src/fr/ifremer/wlo/imports src/fr/ifremer/wlo/preferences src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 03 Mar '14
by kmorin@users.forge.codelutin.com 03 Mar '14
03 Mar '14
Author: kmorin
Date: 2014-03-03 18:36:04 +0100 (Mon, 03 Mar 2014)
New Revision: 63
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/63
Log:
setup application sign
fixes #4630 [TECH] Mise ?\195?\160 jour automatique de l'application
Added:
trunk/src/fr/ifremer/wlo/utils/ImportUtil.java
Removed:
trunk/proguard.cfg
trunk/src/fr/ifremer/wlo/imports/ImportUtil.java
Modified:
trunk/AndroidManifest.xml
trunk/pom.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/MainActivity.java
trunk/src/fr/ifremer/wlo/WloApplication.java
trunk/src/fr/ifremer/wlo/WloBaseActivity.java
trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java
trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/AndroidManifest.xml 2014-03-03 17:36:04 UTC (rev 63)
@@ -16,7 +16,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.ifremer.wlo"
android:versionCode="1"
- android:versionName="1.0">
+ android:versionName="0.2">
<uses-sdk minSdkVersion="15"
android:targetSdkVersion="15"/>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/pom.xml 2014-03-03 17:36:04 UTC (rev 63)
@@ -269,9 +269,6 @@
<excludeJarResources>
<excludeJarResource>.*nuiton.*</excludeJarResource>
</excludeJarResources>
- <!--<sign>-->
- <!--<debug>false</debug>-->
- <!--</sign>-->
<!--<device>emulator</device>-->
<device>usb</device>
<zipalign>
@@ -284,9 +281,6 @@
${project.build.directory}/${project.artifactId}-${project.version}-aligned.apk
</outputApk>
</zipalign>
- <proguard>
- <skip>true</skip> <!-- android.proguard.skip -->
- </proguard>
</configuration>
<extensions>true</extensions>
</plugin>
@@ -324,6 +318,70 @@
<profiles>
<profile>
+ <id>sign</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>get-keystore</id>
+ <goals>
+ <goal>share-server-secret</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <serverId>codelutin-keystore</serverId>
+ <privateKeyOut>jarsigner.keystore</privateKeyOut>
+ <passwordOut>jarsigner.storepass</passwordOut>
+ <usernameOut>jarsigner.alias</usernameOut>
+ <passphraseOut>jarsigner.keypass</passphraseOut>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jarsigner-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>signing</id>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ <phase>package</phase>
+ <inherited>true</inherited>
+ <configuration>
+ <includes>
+ <include>target/*.apk</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
+ <artifactId>android-maven-plugin</artifactId>
+ <inherited>true</inherited>
+ <configuration>
+ <sign>
+ <debug>false</debug>
+ </sign>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
<id>check-release-profile</id>
<activation>
<property>
Deleted: trunk/proguard.cfg
===================================================================
--- trunk/proguard.cfg 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/proguard.cfg 2014-03-03 17:36:04 UTC (rev 63)
@@ -1,10 +0,0 @@
--dontoptimize
--dontobfuscate
--dontwarn javax.annotation.**
--dontwarn javax.inject.**
--dontwarn sun.misc.Unsafe
--dontwarn com.google.common.collect.MinMaxPriorityQueue
-
--keepclasseswithmembers public class * {
- public static void main(java.lang.String[]);
-}
\ No newline at end of file
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/res/values/strings.xml 2014-03-03 17:36:04 UTC (rev 63)
@@ -216,4 +216,9 @@
<string name="crash_dialog_comment_prompt">You might add your comments about the problem below:</string>
<string name="crash_dialog_ok_toast">Thank you !</string>
+ <!-- Update -->
+ <string name="update_dowload_error">Error while downloading the new version of WLO</string>
+ <string name="update_available_title">New version available</string>
+ <string name="update_available_message">A new version of WLO is available. Would you like to install it?</string>
+
</resources>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/res/values-fr/strings.xml 2014-03-03 17:36:04 UTC (rev 63)
@@ -208,4 +208,9 @@
<string name="crash_dialog_comment_prompt">Vous pouvez ajouter un commentaire ci-dessous:</string>
<string name="crash_dialog_ok_toast">Merci !</string>
+ <!-- Update -->
+ <string name="update_dowload_error">Erreur lors du téléchargement de la dernière version de WLO</string>
+ <string name="update_available_title">Nouvelle version disponible</string>
+ <string name="update_available_message">Une nouvelle version de WLO est disponible. Voulez-vous la télécharger et l\'installer ?</string>
+
</resources>
Modified: trunk/src/fr/ifremer/wlo/MainActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -28,8 +28,10 @@
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -40,13 +42,14 @@
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
-import fr.ifremer.wlo.imports.ImportUtil;
+import fr.ifremer.wlo.utils.ImportUtil;
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.preferences.SettingsActivity;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.Exporter;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
import fr.ifremer.wlo.utils.UIUtils;
+import fr.ifremer.wlo.utils.UpdateCheckTask;
import fr.ifremer.wlo.utils.filechooser.FileDialog;
import fr.ifremer.wlo.utils.filechooser.SelectionMode;
import org.apache.commons.io.FileUtils;
@@ -109,6 +112,9 @@
super.onCreate(savedInstanceState);
+ new InitializationTask().execute();
+ new UpdateCheckTask(this).execute();
+
mainPanel = (LinearLayout) findViewById(R.id.main_panel);
logoPanel = (LinearLayout) findViewById(R.id.logo_panel);
buttonPanel = (LinearLayout) findViewById(R.id.button_panel);
@@ -277,4 +283,108 @@
startActivityForResult(serverIntent, REQUEST_CONNECT_ICHTYOMETER);
}
+ protected class InitializationTask extends AsyncTask<Void, Integer, Void> {
+
+ protected ProgressDialog dialog;
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+
+ dialog = new ProgressDialog(MainActivity.this);
+ dialog.setIndeterminate(false);
+ dialog.setCancelable(false);
+ dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ dialog.setMax(9);
+ dialog.setMessage(getString(R.string.main_loading_referential));
+ dialog.show();
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ Context context = MainActivity.this;
+ try {
+ int i = 1;
+ if (DataCache.getAllCommercialSpecies(context).isEmpty()) {
+ ImportUtil.importCommercialSpecies(context, getAssets().open("ref_import_commercial_species.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllLocations(context).isEmpty()) {
+ ImportUtil.importLocations(context, getAssets().open("ref_import_locations.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllMensurations(context).isEmpty()) {
+ ImportUtil.importMensurations(context, getAssets().open("ref_import_mensurations.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllMetiers(context).isEmpty()) {
+ ImportUtil.importMetiers(context, getAssets().open("ref_import_metiers.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllPresentations(context).isEmpty()) {
+ ImportUtil.importPresentations(context, getAssets().open("ref_import_presentations.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllScientificSpecies(context).isEmpty()) {
+ ImportUtil.importScientificSpecies(context, getAssets().open("ref_import_scientific_species.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllStates(context).isEmpty()) {
+ ImportUtil.importStates(context, getAssets().open("ref_import_states.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllVessels(context).isEmpty()) {
+ ImportUtil.importVessels(context, getAssets().open("ref_import_vessels.csv"));
+ }
+ publishProgress(i++);
+
+ if (DataCache.getAllCategories(context).isEmpty()) {
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
+
+ CategoryModel ageCategory = new CategoryModel();
+ ageCategory.setLabel(getString(R.string.age));
+ soh.saveData(ageCategory);
+
+ CategoryModel genderCategory = new CategoryModel();
+ genderCategory.setLabel(getString(R.string.gender));
+ soh.saveData(genderCategory);
+
+ CategoryModel maturityCategory = new CategoryModel();
+ maturityCategory.setLabel(getString(R.string.maturity));
+ soh.saveData(maturityCategory);
+
+ soh.saveData(ImportUtil.importQualitativeValues(ageCategory, getAssets().open("ref_import_ages.csv")));
+ soh.saveData(ImportUtil.importQualitativeValues(genderCategory, getAssets().open("ref_import_genders.csv")));
+ soh.saveData(ImportUtil.importQualitativeValues(maturityCategory, getAssets().open("ref_import_maturities.csv")));
+
+ soh.close();
+ }
+ publishProgress(i++);
+
+ } catch (IOException | RuntimeException e) {
+ Log.e(TAG, "error on initial import", e);
+ }
+ return null;
+ }
+
+ @Override
+ protected void onProgressUpdate(Integer... progress) {
+ dialog.setProgress(progress[0]);
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ dialog.dismiss();
+ }
+
+ }
+
}
\ No newline at end of file
Modified: trunk/src/fr/ifremer/wlo/WloApplication.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloApplication.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/WloApplication.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -1,16 +1,23 @@
package fr.ifremer.wlo;
import android.app.Application;
+import android.app.DownloadManager;
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.AsyncTask;
import android.util.Log;
-import fr.ifremer.wlo.imports.ImportUtil;
+import fr.ifremer.wlo.utils.ImportUtil;
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
+import fr.ifremer.wlo.utils.UpdateCheckTask;
import org.acra.ACRA;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
+import java.io.FileNotFoundException;
import java.io.IOException;
/**
@@ -34,68 +41,6 @@
public void onCreate() {
ACRA.init(this);
super.onCreate();
-
- new Thread(new Runnable() {
- @Override
- public void run() {
- initData();
- }
- }).start();
-
}
- protected void initData() {
- try {
- if (DataCache.getAllCommercialSpecies(this).isEmpty()) {
- ImportUtil.importCommercialSpecies(this, getAssets().open("ref_import_commercial_species.csv"));
- }
- if (DataCache.getAllLocations(this).isEmpty()) {
- ImportUtil.importLocations(this, getAssets().open("ref_import_locations.csv"));
- }
- if (DataCache.getAllMensurations(this).isEmpty()) {
- ImportUtil.importMensurations(this, getAssets().open("ref_import_mensurations.csv"));
- }
- if (DataCache.getAllMetiers(this).isEmpty()) {
- ImportUtil.importMetiers(this, getAssets().open("ref_import_metiers.csv"));
- }
- if (DataCache.getAllPresentations(this).isEmpty()) {
- ImportUtil.importPresentations(this, getAssets().open("ref_import_presentations.csv"));
- }
- if (DataCache.getAllScientificSpecies(this).isEmpty()) {
- ImportUtil.importScientificSpecies(this, getAssets().open("ref_import_scientific_species.csv"));
- }
- if (DataCache.getAllStates(this).isEmpty()) {
- ImportUtil.importStates(this, getAssets().open("ref_import_states.csv"));
- }
- if (DataCache.getAllVessels(this).isEmpty()) {
- ImportUtil.importVessels(this, getAssets().open("ref_import_vessels.csv"));
- }
- if (DataCache.getAllCategories(this).isEmpty()) {
- WloSqlOpenHelper soh = new WloSqlOpenHelper(this);
-
- CategoryModel ageCategory = new CategoryModel();
- ageCategory.setLabel(getString(R.string.age));
- soh.saveData(ageCategory);
-
- CategoryModel genderCategory = new CategoryModel();
- genderCategory.setLabel(getString(R.string.gender));
- soh.saveData(genderCategory);
-
- CategoryModel maturityCategory = new CategoryModel();
- maturityCategory.setLabel(getString(R.string.maturity));
- soh.saveData(maturityCategory);
-
- soh.saveData(ImportUtil.importQualitativeValues(ageCategory, getAssets().open("ref_import_ages.csv")));
- soh.saveData(ImportUtil.importQualitativeValues(genderCategory, getAssets().open("ref_import_genders.csv")));
- soh.saveData(ImportUtil.importQualitativeValues(maturityCategory, getAssets().open("ref_import_maturities.csv")));
-
- soh.close();
- }
-
- } catch (IOException | RuntimeException e) {
- //TODO kmorin 20140130 show error to the user
- Log.e(TAG, "error on initial import", e);
- }
- }
-
}
Modified: trunk/src/fr/ifremer/wlo/WloBaseActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloBaseActivity.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/WloBaseActivity.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -24,20 +24,30 @@
* #L%
*/
+import android.app.DownloadManager;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.ServiceConnection;
+import android.database.Cursor;
+import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
+import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
+import android.widget.Toast;
+import java.io.File;
+import java.io.FileNotFoundException;
+
/**
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
@@ -49,10 +59,47 @@
protected Messenger mServiceMessenger = null;
protected Messenger mMessenger = null;
+ protected DownloadManager downloadManager;
+ protected static Long downloadingApkId = null;
+ protected final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context arg0, Intent arg1) {
+ DownloadManager.Query query = new DownloadManager.Query();
+ query.setFilterById(downloadingApkId);
+ Cursor cursor = downloadManager.query(query);
+
+ if(cursor.moveToFirst()){
+ int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
+ int status = cursor.getInt(columnIndex);
+ int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
+ int reason = cursor.getInt(columnReason);
+
+ if(status == DownloadManager.STATUS_SUCCESSFUL){
+ //Retrieve the saved download id
+ Uri uri = downloadManager.getUriForDownloadedFile(downloadingApkId);
+
+ Intent promptInstall = new Intent(Intent.ACTION_VIEW)
+ .setDataAndType(uri, "application/vnd.android.package-archive");
+ startActivity(promptInstall);
+
+ } else if (status == DownloadManager.STATUS_FAILED){
+ Toast.makeText(WloBaseActivity.this,
+ R.string.update_dowload_error,
+ Toast.LENGTH_LONG).show();
+ }
+ downloadingApkId = null;
+ }
+ }
+
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
+
Integer viewId = getContentView();
if (viewId != null) {
setContentView(viewId);
@@ -65,6 +112,19 @@
}
@Override
+ protected void onResume() {
+ super.onResume();
+ IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
+ registerReceiver(downloadReceiver, intentFilter);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ unregisterReceiver(downloadReceiver);
+ }
+
+ @Override
protected void onDestroy() {
Log.d(TAG, "destroy");
super.onDestroy();
@@ -128,4 +188,12 @@
Intent intent = new Intent(this, upClass);
return intent;
}
+
+ public static Long getDownloadingApkId() {
+ return downloadingApkId;
+ }
+
+ public static void setDownloadingApkId(Long downloadingApkId) {
+ WloBaseActivity.downloadingApkId = downloadingApkId;
+ }
}
Deleted: trunk/src/fr/ifremer/wlo/imports/ImportUtil.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/ImportUtil.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/imports/ImportUtil.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -1,284 +0,0 @@
-package fr.ifremer.wlo.imports;
-
-/*
- * #%L
- * WLO
- * $Id:$
- * $HeadURL:$
- * %%
- * Copyright (C) 2013 - 2014 Ifremer
- * %%
- * This program 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.
- *
- * This program 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/gpl-3.0.html>.
- * #L%
- */
-
-import android.content.Context;
-import android.util.Log;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import fr.ifremer.wlo.models.BaseModel;
-import fr.ifremer.wlo.models.categorization.CategoryModel;
-import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
-import fr.ifremer.wlo.models.referentials.CalcifiedPartTaking;
-import fr.ifremer.wlo.models.referentials.HasCode;
-import fr.ifremer.wlo.storage.DataCache;
-import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import org.apache.commons.collections.CollectionUtils;
-import org.nuiton.csv.Import;
-import org.nuiton.csv.ImportModel;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * @author kmorin <kmorin(a)codelutin.com>
- * @since 0.1
- */
-public class ImportUtil {
-
- private static final String TAG = "ImportUtil";
-
- public static final char CSV_SEPARATOR = ';';
-
- public static int importCommercialSpecies(Context context, String path) {
- try {
- return importCommercialSpecies(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importCommercialSpecies(Context context, InputStream inputStream) {
- CommercialSpeciesRowModel commercialSpeciesRowModel = new CommercialSpeciesRowModel(CSV_SEPARATOR);
- int result = importData(context, commercialSpeciesRowModel, inputStream, DataCache.getAllCommercialSpecies(context));
- DataCache.invalidateCommercialSpecies();
- return result;
- }
-
- public static int importLocations(Context context, String path) {
- try {
- return importLocations(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importLocations(Context context, InputStream inputStream) {
- LocationRowModel locationRowModel = new LocationRowModel(CSV_SEPARATOR);
- int result = importData(context, locationRowModel, inputStream, DataCache.getAllLocations(context));
- DataCache.invalidateLocations();
- return result;
- }
-
- public static int importMensurations(Context context, String path) {
- try {
- return importMensurations(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importMensurations(Context context, InputStream inputStream) {
- MensurationRowModel mensurationRowModel = new MensurationRowModel(CSV_SEPARATOR);
- int result = importData(context, mensurationRowModel, inputStream, DataCache.getAllMensurations(context));
- DataCache.invalidateMensurations();
- return result;
- }
-
- public static int importMetiers(Context context, String path) {
- try {
- return importMetiers(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importMetiers(Context context, InputStream inputStream) {
- MetierRowModel metierRowModel = new MetierRowModel(CSV_SEPARATOR);
- int result = importData(context, metierRowModel, inputStream, DataCache.getAllMetiers(context));
- DataCache.invalidateMetiers();
- return result;
- }
-
- public static int importPresentations(Context context, String path) {
- try {
- return importPresentations(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importPresentations(Context context, InputStream inputStream) {
- PresentationRowModel presentationRowModel = new PresentationRowModel(CSV_SEPARATOR);
- int result = importData(context, presentationRowModel, inputStream, DataCache.getAllPresentations(context));
- DataCache.invalidatePresentations();
- return result;
- }
-
- public static int importScientificSpecies(Context context, String path) {
- try {
- return importScientificSpecies(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importScientificSpecies(Context context, InputStream inputStream) {
- ScientificSpeciesRowModel scientificSpeciesRowModel = new ScientificSpeciesRowModel(CSV_SEPARATOR);
- int result = importData(context, scientificSpeciesRowModel, inputStream, DataCache.getAllScientificSpecies(context));
- DataCache.invalidateScientificSpecies();
- return result;
- }
-
- public static int importStates(Context context, String path) {
- try {
- return importStates(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importStates(Context context, InputStream inputStream) {
- StateRowModel stateRowModel = new StateRowModel(CSV_SEPARATOR);
- int result = importData(context, stateRowModel, inputStream, DataCache.getAllStates(context));
- DataCache.invalidateStates();
- return result;
- }
-
- public static int importVessels(Context context, String path) {
- try {
- return importVessels(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importVessels(Context context, InputStream inputStream) {
- VesselRowModel vesselRowModel = new VesselRowModel(CSV_SEPARATOR);
- int result = importData(context, vesselRowModel, inputStream, DataCache.getAllVessels(context));
- DataCache.invalidateVessels();
- return result;
- }
-
- public static int importCalcifiedPartTakings(Context context, String path) {
- try {
- return importCalcifiedPartTakings(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importCalcifiedPartTakings(Context context, InputStream inputStream) {
- CalcifiedPartTakingRowModel calcifiedPartTakingRowModel = new CalcifiedPartTakingRowModel(CSV_SEPARATOR, DataCache.getAllScientificSpecies(context));
- int result = importData(context, calcifiedPartTakingRowModel, inputStream, new ArrayList<CalcifiedPartTaking>());
- return result;
- }
-
- public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, String path) {
- try {
- return importQualitativeValues(categoryModel, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return null;
- }
-
- public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, InputStream inputStream) {
- QualitativeValueRowModel qualitativeValueRowModel = new QualitativeValueRowModel(CSV_SEPARATOR, categoryModel);
- Collection<QualitativeValueModel> result = importData(qualitativeValueRowModel, inputStream, new ArrayList<QualitativeValueModel>());
- return result;
- }
-
- protected static <M extends BaseModel> int importData(Context context, ImportModel<M> importModel,
- InputStream inputStream, final Collection<M> actualReferential) {
-
- Collection<M> models = importData(importModel, inputStream, actualReferential);
-
- if (CollectionUtils.isNotEmpty(models)) {
- Predicate<M> filter;
- //if the models have a code attribute, check
- M first = models.iterator().next();
- if (HasCode.class.isAssignableFrom(first.getClass())) {
- Collection<HasCode> hasCodes = Collections2.transform(actualReferential, new Function<M, HasCode>() {
- @Override
- public HasCode apply(M m) {
- return (HasCode) m;
- }
- });
- final Collection<String> codes = Collections2.transform(hasCodes, HasCode.GET_CODE_FUNCTION);
- filter = new Predicate<M>() {
- @Override
- public boolean apply(M model) {
- HasCode hasCode = (HasCode) model;
- return !codes.contains(hasCode.getCode());
- }
- };
- } else {
- filter = new Predicate<M>() {
- @Override
- public boolean apply(M m) {
- return !actualReferential.contains(m);
- }
- };
- }
-
- models = Collections2.filter(models, filter);
- WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
- soh.saveData(models);
- soh.close();
- }
-
- return models.size();
- }
-
- protected static <M extends BaseModel> Collection<M> importData(ImportModel<M> importModel, InputStream inputStream,
- Collection<M> actualReferential) {
- Preconditions.checkNotNull(actualReferential);
- Import<M> importer = null;
- Collection<M> models = null;
-
- try {
- importer = Import.newImport(importModel, inputStream);
- models = Lists.newArrayList(importer.iterator());
-
- } catch (ClassCastException e) {
- // cf issue #4205
- // nuiton-i18n provocks an error when trying to get the error message
- Log.e(TAG, "error during import", e);
- throw e;
-
- } finally {
- if (importer != null) {
- importer.close();
- }
- }
- return models;
- }
-}
Modified: trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -10,7 +10,7 @@
import android.widget.TextView;
import fr.ifremer.wlo.R;
import fr.ifremer.wlo.WloBaseActivity;
-import fr.ifremer.wlo.imports.ImportUtil;
+import fr.ifremer.wlo.utils.ImportUtil;
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
import fr.ifremer.wlo.storage.DataCache;
@@ -100,16 +100,10 @@
// cf issue #4205
// nuiton-i18n provocks an error when trying to get the error message
Log.e(TAG, "error during import", e);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- new AlertDialog.Builder(CategoryCreationAcivity.this)
- .setMessage(R.string.import_error)
- .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
- .create().show();
- }
- });
-
+ new AlertDialog.Builder(CategoryCreationAcivity.this)
+ .setMessage(R.string.import_error)
+ .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
+ .create().show();
}
} else {
Modified: trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -30,6 +30,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.MultiSelectListPreference;
@@ -38,6 +39,7 @@
import android.util.Log;
import android.widget.Toast;
import com.google.common.base.Functions;
+import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.Collections2;
import com.google.common.collect.HashBiMap;
@@ -51,7 +53,7 @@
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.StorageUtils;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import fr.ifremer.wlo.imports.ImportUtil;
+import fr.ifremer.wlo.utils.ImportUtil;
import fr.ifremer.wlo.utils.UIUtils;
import fr.ifremer.wlo.utils.filechooser.FileDialog;
import fr.ifremer.wlo.utils.filechooser.SelectionMode;
@@ -291,112 +293,8 @@
protected void importData(final int requestCode, final Intent data, final boolean backupFile) {
final Context context = getActivity();
-
- final ProgressDialog dialog = new ProgressDialog(context);
- dialog.setCancelable(false);
- dialog.setMessage(getString(R.string.preferences_importing_referential));
- dialog.show();
-
- new Thread(new Runnable() {
- @Override
- public void run() {
- String path = data.getStringExtra(FileDialog.RESULT_PATH);
- Log.d(TAG, path);
- final Integer updatedNb;
- final Integer newNb;
-
- try {
- switch (requestCode) {
- case REQUEST_IMPORT_COMMERCIAL_SPECIES:
- newNb = ImportUtil.importCommercialSpecies(context, path);
- updatedNb = DataCache.getAllCommercialSpecies(context).size();
- break;
- case REQUEST_IMPORT_LOCATIONS:
- newNb = ImportUtil.importLocations(context, path);
- updatedNb = DataCache.getAllLocations(context).size();
- break;
- case REQUEST_IMPORT_MENSURATIONS:
- newNb = ImportUtil.importMensurations(context, path);
- updatedNb = DataCache.getAllMensurations(context).size();
- break;
- case REQUEST_IMPORT_METIERS:
- newNb = ImportUtil.importMetiers(context, path);
- updatedNb = DataCache.getAllMetiers(context).size();
- break;
- case REQUEST_IMPORT_PRESENTATIONS:
- newNb = ImportUtil.importPresentations(context, path);
- updatedNb = DataCache.getAllPresentations(context).size();
- break;
- case REQUEST_IMPORT_SCIENTIFIC_SPECIES:
- newNb = ImportUtil.importScientificSpecies(context, path);
- updatedNb = DataCache.getAllScientificSpecies(context).size();
- break;
- case REQUEST_IMPORT_STATES:
- newNb = ImportUtil.importStates(context, path);
- updatedNb = DataCache.getAllStates(context).size();
- break;
- case REQUEST_IMPORT_VESSELS:
- newNb = ImportUtil.importVessels(context, path);
- updatedNb = DataCache.getAllVessels(context).size();
- break;
- case REQUEST_IMPORT_CALCIFIED_PARTS_TAKINGS:
- WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
- soh.clearCalcifiedPartTakings();
- soh.close();
- newNb = ImportUtil.importCalcifiedPartTakings(context, path);
- updatedNb = null;
- break;
- default:
- newNb = null;
- updatedNb = null;
- }
-
- if (backupFile) {
- File importedFile = new File(path);
- String copyFileName = String.format("%1$tY%1$tm%1$td-%1$tH%1$tM%1$tS-", new Date()) + importedFile.getName();
- File dir = Environment.getExternalStoragePublicDirectory(".wlo");
- File file = new File(dir, copyFileName);
- try {
- FileUtils.copyInputStreamToFile(new FileInputStream(path), file);
- } catch (IOException e) {
- Log.e(TAG, "Error while copying the file", e);
- }
- }
-
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- dialog.dismiss();
-
- if (updatedNb != null) {
- String key = requestCodeByPrefKey.inverse().get(requestCode);
- Preference filePicker = findPreference(key);
- filePicker.setSummary(getString(R.string.preferences_import_summary, updatedNb));
- }
-
- Toast.makeText(context, context.getString(R.string.import_new_element_number, newNb), Toast.LENGTH_SHORT).show();
- }
- });
-
- } catch (Exception e) {
- // cf issue #4205
- // nuiton-i18n provocks an error when trying to get the error message
- Log.e(TAG, "error during import", e);
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- dialog.dismiss();
- new AlertDialog.Builder(context)
- .setMessage(R.string.import_error)
- .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
- .create().show();
- }
- });
-
- }
-
- }
- }).start();
+ String path = data.getStringExtra(FileDialog.RESULT_PATH);
+ new ImportAsyncTask().execute(path, requestCode, backupFile);
}
protected <M extends BaseModel> void initMultiSelectListPreference(String prefKey,
@@ -439,7 +337,145 @@
}
pref.setSummary(getString(R.string.favorite_nb, favoriteIds.size()));
}
+
+ protected class ImportAsyncTask extends AsyncTask<Object, Integer, Integer[]> {
+
+ protected ProgressDialog dialog;
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+
+ dialog = new ProgressDialog(getActivity());
+ dialog.setCancelable(false);
+ dialog.setMessage(getString(R.string.preferences_importing_referential));
+ dialog.show();
+ }
+
+ @Override
+ protected Integer[] doInBackground(Object... params) {
+ if (params.length != 3) {
+ return null;
+ }
+ Context context = getActivity();
+ String path = (String) params[0];
+ Integer requestCode = (Integer) params[1];
+ Boolean backupFile = (Boolean) params[2];
+ Log.d(TAG, path);
+
+ Integer[] result = new Integer[3];
+ result[2] = requestCode;
+
+ try {
+ switch (requestCode) {
+ case REQUEST_IMPORT_COMMERCIAL_SPECIES:
+ result[0] = ImportUtil.importCommercialSpecies(context, path);
+ result[1] = DataCache.getAllCommercialSpecies(context).size();
+ break;
+ case REQUEST_IMPORT_LOCATIONS:
+ result[0] = ImportUtil.importLocations(context, path);
+ result[1] = DataCache.getAllLocations(context).size();
+ break;
+ case REQUEST_IMPORT_MENSURATIONS:
+ result[0] = ImportUtil.importMensurations(context, path);
+ result[1] = DataCache.getAllMensurations(context).size();
+ break;
+ case REQUEST_IMPORT_METIERS:
+ result[0] = ImportUtil.importMetiers(context, path);
+ result[1] = DataCache.getAllMetiers(context).size();
+ break;
+ case REQUEST_IMPORT_PRESENTATIONS:
+ result[0] = ImportUtil.importPresentations(context, path);
+ result[1] = DataCache.getAllPresentations(context).size();
+ break;
+ case REQUEST_IMPORT_SCIENTIFIC_SPECIES:
+ result[0] = ImportUtil.importScientificSpecies(context, path);
+ result[1] = DataCache.getAllScientificSpecies(context).size();
+ break;
+ case REQUEST_IMPORT_STATES:
+ result[0] = ImportUtil.importStates(context, path);
+ result[1] = DataCache.getAllStates(context).size();
+ break;
+ case REQUEST_IMPORT_VESSELS:
+ result[0] = ImportUtil.importVessels(context, path);
+ result[1] = DataCache.getAllVessels(context).size();
+ break;
+ case REQUEST_IMPORT_CALCIFIED_PARTS_TAKINGS:
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
+ soh.clearCalcifiedPartTakings();
+ soh.close();
+ result[0] = ImportUtil.importCalcifiedPartTakings(context, path);
+ result[1] = null;
+ break;
+ default:
+ result[0] = null;
+ result[1] = null;
+ }
+
+ if (backupFile) {
+ File importedFile = new File(path);
+ String copyFileName = String.format("%1$tY%1$tm%1$td-%1$tH%1$tM%1$tS-", new Date()) + importedFile.getName();
+ File dir = Environment.getExternalStoragePublicDirectory(".wlo");
+ File file = new File(dir, copyFileName);
+ try {
+ FileUtils.copyInputStreamToFile(new FileInputStream(path), file);
+ } catch (IOException e) {
+ Log.e(TAG, "Error while copying the file", e);
+ }
+ }
+
+ } catch (Exception e) {
+ // cf issue #4205
+ // nuiton-i18n provocks an error when trying to get the error message
+ Log.e(TAG, "error during import", e);
+ result = null;
+ cancel(true);
+
+ }
+ return result;
+ }
+
+ @Override
+ protected void onPostExecute(Integer[] result) {
+ super.onPostExecute(result);
+
+ dialog.dismiss();
+
+ if (result != null) {
+ if (result[1] != null) {
+ String key = requestCodeByPrefKey.inverse().get(result[2]);
+ Preference filePicker = findPreference(key);
+ filePicker.setSummary(getString(R.string.preferences_import_summary, result[1]));
+ }
+
+ Toast.makeText(getActivity(), getString(R.string.import_new_element_number, result[0]), Toast.LENGTH_LONG).show();
+
+// } else {
+// //error
+// new AlertDialog.Builder(getActivity())
+// .setMessage(R.string.import_error)
+// .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
+// .create().show();
+ }
+ }
+
+ @Override
+ protected void onCancelled(Integer[] integer) {
+ super.onCancelled(integer);
+ dialog.dismiss();
+
+ new AlertDialog.Builder(getActivity())
+ .setMessage(R.string.import_error)
+ .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
+ .create().show();
+ }
+
+ @Override
+ protected void onCancelled() {
+ super.onCancelled();
+ onCancelled(null);
+ }
+ }
}
-
}
\ No newline at end of file
Copied: trunk/src/fr/ifremer/wlo/utils/ImportUtil.java (from rev 57, trunk/src/fr/ifremer/wlo/imports/ImportUtil.java)
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/ImportUtil.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/utils/ImportUtil.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -0,0 +1,295 @@
+package fr.ifremer.wlo.utils;
+
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program 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.
+ *
+ * This program 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/gpl-3.0.html>.
+ * #L%
+ */
+
+import android.content.Context;
+import android.os.AsyncTask;
+import android.util.Log;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import fr.ifremer.wlo.imports.CalcifiedPartTakingRowModel;
+import fr.ifremer.wlo.imports.CommercialSpeciesRowModel;
+import fr.ifremer.wlo.imports.LocationRowModel;
+import fr.ifremer.wlo.imports.MensurationRowModel;
+import fr.ifremer.wlo.imports.MetierRowModel;
+import fr.ifremer.wlo.imports.PresentationRowModel;
+import fr.ifremer.wlo.imports.QualitativeValueRowModel;
+import fr.ifremer.wlo.imports.ScientificSpeciesRowModel;
+import fr.ifremer.wlo.imports.StateRowModel;
+import fr.ifremer.wlo.imports.VesselRowModel;
+import fr.ifremer.wlo.models.BaseModel;
+import fr.ifremer.wlo.models.categorization.CategoryModel;
+import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
+import fr.ifremer.wlo.models.referentials.CalcifiedPartTaking;
+import fr.ifremer.wlo.models.referentials.HasCode;
+import fr.ifremer.wlo.storage.DataCache;
+import fr.ifremer.wlo.storage.WloSqlOpenHelper;
+import org.apache.commons.collections.CollectionUtils;
+import org.nuiton.csv.Import;
+import org.nuiton.csv.ImportModel;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author kmorin <kmorin(a)codelutin.com>
+ * @since 0.1
+ */
+public class ImportUtil {
+
+ private static final String TAG = "ImportUtil";
+
+ public static final char CSV_SEPARATOR = ';';
+
+ public static int importCommercialSpecies(Context context, String path) {
+ try {
+ return importCommercialSpecies(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importCommercialSpecies(Context context, InputStream inputStream) {
+ CommercialSpeciesRowModel commercialSpeciesRowModel = new CommercialSpeciesRowModel(CSV_SEPARATOR);
+ int result = importData(context, commercialSpeciesRowModel, inputStream, DataCache.getAllCommercialSpecies(context));
+ DataCache.invalidateCommercialSpecies();
+ return result;
+ }
+
+ public static int importLocations(Context context, String path) {
+ try {
+ return importLocations(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importLocations(Context context, InputStream inputStream) {
+ LocationRowModel locationRowModel = new LocationRowModel(CSV_SEPARATOR);
+ int result = importData(context, locationRowModel, inputStream, DataCache.getAllLocations(context));
+ DataCache.invalidateLocations();
+ return result;
+ }
+
+ public static int importMensurations(Context context, String path) {
+ try {
+ return importMensurations(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importMensurations(Context context, InputStream inputStream) {
+ MensurationRowModel mensurationRowModel = new MensurationRowModel(CSV_SEPARATOR);
+ int result = importData(context, mensurationRowModel, inputStream, DataCache.getAllMensurations(context));
+ DataCache.invalidateMensurations();
+ return result;
+ }
+
+ public static int importMetiers(Context context, String path) {
+ try {
+ return importMetiers(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importMetiers(Context context, InputStream inputStream) {
+ MetierRowModel metierRowModel = new MetierRowModel(CSV_SEPARATOR);
+ int result = importData(context, metierRowModel, inputStream, DataCache.getAllMetiers(context));
+ DataCache.invalidateMetiers();
+ return result;
+ }
+
+ public static int importPresentations(Context context, String path) {
+ try {
+ return importPresentations(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importPresentations(Context context, InputStream inputStream) {
+ PresentationRowModel presentationRowModel = new PresentationRowModel(CSV_SEPARATOR);
+ int result = importData(context, presentationRowModel, inputStream, DataCache.getAllPresentations(context));
+ DataCache.invalidatePresentations();
+ return result;
+ }
+
+ public static int importScientificSpecies(Context context, String path) {
+ try {
+ return importScientificSpecies(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importScientificSpecies(Context context, InputStream inputStream) {
+ ScientificSpeciesRowModel scientificSpeciesRowModel = new ScientificSpeciesRowModel(CSV_SEPARATOR);
+ int result = importData(context, scientificSpeciesRowModel, inputStream, DataCache.getAllScientificSpecies(context));
+ DataCache.invalidateScientificSpecies();
+ return result;
+ }
+
+ public static int importStates(Context context, String path) {
+ try {
+ return importStates(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importStates(Context context, InputStream inputStream) {
+ StateRowModel stateRowModel = new StateRowModel(CSV_SEPARATOR);
+ int result = importData(context, stateRowModel, inputStream, DataCache.getAllStates(context));
+ DataCache.invalidateStates();
+ return result;
+ }
+
+ public static int importVessels(Context context, String path) {
+ try {
+ return importVessels(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importVessels(Context context, InputStream inputStream) {
+ VesselRowModel vesselRowModel = new VesselRowModel(CSV_SEPARATOR);
+ int result = importData(context, vesselRowModel, inputStream, DataCache.getAllVessels(context));
+ DataCache.invalidateVessels();
+ return result;
+ }
+
+ public static int importCalcifiedPartTakings(Context context, String path) {
+ try {
+ return importCalcifiedPartTakings(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importCalcifiedPartTakings(Context context, InputStream inputStream) {
+ CalcifiedPartTakingRowModel calcifiedPartTakingRowModel = new CalcifiedPartTakingRowModel(CSV_SEPARATOR, DataCache.getAllScientificSpecies(context));
+ int result = importData(context, calcifiedPartTakingRowModel, inputStream, new ArrayList<CalcifiedPartTaking>());
+ return result;
+ }
+
+ public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, String path) {
+ try {
+ return importQualitativeValues(categoryModel, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return null;
+ }
+
+ public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, InputStream inputStream) {
+ QualitativeValueRowModel qualitativeValueRowModel = new QualitativeValueRowModel(CSV_SEPARATOR, categoryModel);
+ Collection<QualitativeValueModel> result = importData(qualitativeValueRowModel, inputStream, new ArrayList<QualitativeValueModel>());
+ return result;
+ }
+
+ protected static <M extends BaseModel> int importData(Context context, ImportModel<M> importModel,
+ InputStream inputStream, final Collection<M> actualReferential) {
+
+ Collection<M> models = importData(importModel, inputStream, actualReferential);
+
+ if (CollectionUtils.isNotEmpty(models)) {
+ Predicate<M> filter;
+ //if the models have a code attribute, check
+ M first = models.iterator().next();
+ if (HasCode.class.isAssignableFrom(first.getClass())) {
+ Collection<HasCode> hasCodes = Collections2.transform(actualReferential, new Function<M, HasCode>() {
+ @Override
+ public HasCode apply(M m) {
+ return (HasCode) m;
+ }
+ });
+ final Collection<String> codes = Collections2.transform(hasCodes, HasCode.GET_CODE_FUNCTION);
+ filter = new Predicate<M>() {
+ @Override
+ public boolean apply(M model) {
+ HasCode hasCode = (HasCode) model;
+ return !codes.contains(hasCode.getCode());
+ }
+ };
+ } else {
+ filter = new Predicate<M>() {
+ @Override
+ public boolean apply(M m) {
+ return !actualReferential.contains(m);
+ }
+ };
+ }
+
+ models = Collections2.filter(models, filter);
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
+ soh.saveData(models);
+ soh.close();
+ }
+
+ return models.size();
+ }
+
+ protected static <M extends BaseModel> Collection<M> importData(ImportModel<M> importModel, InputStream inputStream,
+ Collection<M> actualReferential) {
+ Preconditions.checkNotNull(actualReferential);
+ Import<M> importer = null;
+ Collection<M> models = null;
+
+ try {
+ importer = Import.newImport(importModel, inputStream);
+ models = Lists.newArrayList(importer.iterator());
+
+ } catch (ClassCastException e) {
+ // cf issue #4205
+ // nuiton-i18n provocks an error when trying to get the error message
+ Log.e(TAG, "error during import", e);
+ throw e;
+
+ } finally {
+ if (importer != null) {
+ importer.close();
+ }
+ }
+ return models;
+ }
+}
Modified: trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-03 15:24:16 UTC (rev 62)
+++ trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-03 17:36:04 UTC (rev 63)
@@ -1,18 +1,111 @@
package fr.ifremer.wlo.utils;
+import android.app.AlertDialog;
+import android.app.DownloadManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Environment;
+import android.util.Log;
+import android.widget.Toast;
+import fr.ifremer.wlo.R;
+import fr.ifremer.wlo.WloBaseActivity;
+import org.nuiton.util.Version;
+import org.nuiton.util.VersionUtil;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Date;
+import java.util.Properties;
/**
* @author Kevin Morin (Code Lutin)
* @since x.x
*/
-public class UpdateCheckTask extends AsyncTask<URL, Integer, Long> {
+public class UpdateCheckTask extends AsyncTask<String, Integer, String> {
+ private static final String TAG = "UpdateCheckTask";
+
+ public static final String UPDATE_URL = "http://appup.nuiton.org/wlo/wlo-update.properties";
+ public static final String VERSION_PROP = "application.version";
+ public static final String URL_PROP = "application.url";
+
+ protected Context context;
+
+ public UpdateCheckTask(Context context) {
+ this.context = context;
+ }
+
@Override
- protected Long doInBackground(URL... params) {
+ protected String doInBackground(String... params) {
+ String result;
- return null;
+ if (WloBaseActivity.getDownloadingApkId() != null) {
+ result = null;
+ } else {
+ try {
+ // Create a URL for the desired page
+ URL url = new URL(UPDATE_URL);
+
+ Properties props = new Properties();
+ props.load(url.openStream());
+ String version = props.getProperty(VERSION_PROP);
+
+ String currentVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
+
+ Version newVersion = new Version(version);
+ if (!newVersion.isSnapshot() && VersionUtil.greaterThan(version, currentVersion)) {
+ result = props.getProperty(URL_PROP);
+
+ } else {
+ Log.d(TAG, "The application is up to date");
+ result = null;
+ }
+
+ } catch (IOException | PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "error while getting the version");
+ cancel(true);
+ result = null;
+ }
+ }
+
+ return result;
}
+
+ @Override
+ protected void onPostExecute(final String result) {
+ super.onPostExecute(result);
+ if (result != null && WloBaseActivity.getDownloadingApkId() == null) {
+
+ new AlertDialog.Builder(context)
+ .setTitle(R.string.update_available_title)
+ .setMessage(R.string.update_available_message)
+ .setNegativeButton(R.string.no, UIUtils.getCancelClickListener())
+ .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+ Uri toDownload = Uri.parse(result);
+ DownloadManager.Request request = new DownloadManager.Request(toDownload);
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, toDownload.getLastPathSegment());
+ long enqueue = downloadManager.enqueue(request);
+ WloBaseActivity.setDownloadingApkId(enqueue);
+ }
+ })
+ .create()
+ .show();
+
+ }
+ }
+
}
1
0
Author: tchemit
Date: 2014-03-03 16:24:16 +0100 (Mon, 03 Mar 2014)
New Revision: 62
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/62
Log:
refs #4630: [TECH] Mise ?\195?\160 jour automatique de l'application
Added:
trunk/update/
trunk/update/wlo-update.properties
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-03 12:45:57 UTC (rev 61)
+++ trunk/pom.xml 2014-03-03 15:24:16 UTC (rev 62)
@@ -503,6 +503,75 @@
</plugins>
</build>
</profile>
+
+ <profile>
+ <id>deploy-wlo-application-update</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+
+ <build>
+ <defaultGoal>deploy</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>Generate wlo-update.properties</id>
+ <phase>package</phase>
+ <inherited>false</inherited>
+ <configuration>
+ <tasks>
+ <copy verbose="true" failonerror="false" overwrite="true" filtering="true" todir="${project.build.directory}/update">
+ <filterset>
+ <filter value="${project.version}" token="projectVersion" />
+ </filterset>
+ <fileset dir="${basedir}/update/">
+ <include name="wlo-update.properties" />
+ </fileset>
+ </copy>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>wagon-maven-plugin</artifactId>
+ <version>1.0-beta-4</version>
+ <executions>
+ <execution>
+ <id>deploy wlo-update.properties</id>
+ <phase>deploy</phase>
+ <inherited>false</inherited>
+ <goals>
+ <goal>upload-single</goal>
+ </goals>
+ <configuration>
+ <serverId>doc.codelutin.com</serverId>
+ <fromFile>
+ ${project.build.directory}/update/wlo-update.properties
+ </fromFile>
+ <url>
+ scpexe://doc.codelutin.com/var/www/ApplicationUpdate/http/wlo
+ </url>
+ </configuration>
+ </execution>
+ </executions>
+
+ </plugin>
+ </plugins>
+ </build>
+
+ </profile>
+
</profiles>
</project>
Added: trunk/update/wlo-update.properties
===================================================================
--- trunk/update/wlo-update.properties (rev 0)
+++ trunk/update/wlo-update.properties 2014-03-03 15:24:16 UTC (rev 62)
@@ -0,0 +1,28 @@
+###
+# #%L
+# WLO
+# %%
+# Copyright (C) 2014 Ifremer, Code Lutin
+# %%
+# This program 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.
+#
+# This program 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/gpl-3.0.html>.
+# #L%
+###
+
+################################################################################
+### Application Updates ########################################################
+################################################################################
+
+application.version=@projectVersion@
+application.url=https://nexus.nuiton.org/nexus/content/groups/wlo-group/fr/ifremer/wlo/@projectVersion@/wlo-@projectVersion@.apk
Property changes on: trunk/update/wlo-update.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
r61 - in trunk: res/layout src/fr/ifremer/wlo src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 03 Mar '14
by kmorin@users.forge.codelutin.com 03 Mar '14
03 Mar '14
Author: kmorin
Date: 2014-03-03 13:45:57 +0100 (Mon, 03 Mar 2014)
New Revision: 61
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/61
Log:
fix bug when the user selects the item "No appaired device" in the device list
Added:
trunk/res/layout/device_list.xml
trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
Modified:
trunk/src/fr/ifremer/wlo/DeviceListActivity.java
Added: trunk/res/layout/device_list.xml
===================================================================
--- trunk/res/layout/device_list.xml (rev 0)
+++ trunk/res/layout/device_list.xml 2014-03-03 12:45:57 UTC (rev 61)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ListView android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ <TextView android:id="@android:id/empty"
+ android:text="@string/devices_none_paired"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="5dp"
+ android:textSize="18sp"
+ android:textStyle="italic"/>
+
+</FrameLayout>
\ No newline at end of file
Modified: trunk/src/fr/ifremer/wlo/DeviceListActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/DeviceListActivity.java 2014-03-02 19:42:31 UTC (rev 60)
+++ trunk/src/fr/ifremer/wlo/DeviceListActivity.java 2014-03-03 12:45:57 UTC (rev 61)
@@ -56,6 +56,7 @@
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
@@ -91,39 +92,15 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // Initialize the button to perform device discovery
-// Button scanButton = (Button) findViewById(R.id.button_scan);
-// scanButton.setOnClickListener(new OnClickListener() {
-// public void onClick(View v) {
-// doDiscovery();
-// v.setVisibility(View.GONE);
-// }
-// });
+ setContentView(R.layout.device_list);
- // Initialize array adapters. One for already paired devices and
- // one for newly discovered devices
mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
-// mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
// Find and set up the ListView for paired devices
-// ListView pairedListView = (ListView) findViewById(R.id.paired_devices);
ListView pairedListView = getListView();
pairedListView.setAdapter(mPairedDevicesArrayAdapter);
pairedListView.setOnItemClickListener(mDeviceClickListener);
- // Find and set up the ListView for newly discovered devices
-// ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
-// newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
-// newDevicesListView.setOnItemClickListener(mDeviceClickListener);
-
- // Register for broadcasts when a device is discovered
-// IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
-// this.registerReceiver(mReceiver, filter);
-
- // Register for broadcasts when discovery has finished
-// filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
-// this.registerReceiver(mReceiver, filter);
-
// Get the local Bluetooth adapter
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -132,13 +109,9 @@
// If there are paired devices, add each one to the ArrayAdapter
if (pairedDevices.size() > 0) {
-// findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
for (BluetoothDevice device : pairedDevices) {
mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
- } else {
- String noDevices = getResources().getText(R.string.devices_none_paired).toString();
- mPairedDevicesArrayAdapter.add(noDevices);
}
bindService(new Intent(this, BigFinCommunicationService.class), this, Context.BIND_AUTO_CREATE);
@@ -153,32 +126,9 @@
mBtAdapter.cancelDiscovery();
}
- // Unregister broadcast listeners
-// this.unregisterReceiver(mReceiver);
doUnbindService();
}
- /**
- * Start device discover with the BluetoothAdapter
- */
-// private void doDiscovery() {
-// Log.d(TAG, "doDiscovery()");
-//
-// // Indicate scanning in the title
-// setProgressBarIndeterminateVisibility(true);
-// setTitle(R.string.scanning);
-//
-// // Turn on sub-title for new devices
-// findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE);
-//
-// // If we're already discovering, stop it
-// if (mBtAdapter.isDiscovering()) {
-// mBtAdapter.cancelDiscovery();
-// }
-//
-// // Request discover from BluetoothAdapter
-// mBtAdapter.startDiscovery();
-// }
/**
* Un-bind this Activity to MyService
@@ -227,10 +177,6 @@
String info = ((TextView) v).getText().toString();
String address = info.substring(info.length() - 17);
- // Create the result Intent and include the MAC address
-// Intent intent = new Intent();
-// intent.putExtra(EXTRA_DEVICE_ADDRESS, address);
-
// Attempt to connect to the device
Message message = Message.obtain(null, BigFinCommunicationService.MESSAGE_CONNECT_DEVICE);
Bundle bundle = new Bundle();
@@ -243,39 +189,9 @@
Log.e(TAG, "Error while sending data to the service");
}
- // Set result and finish this Activity
-// setResult(Activity.RESULT_OK, intent);
-// finish();
}
};
- // The BroadcastReceiver that listens for discovered devices and
- // changes the title when discovery is finished
-// private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
-// @Override
-// public void onReceive(Context context, Intent intent) {
-// String action = intent.getAction();
-//
-// // When discovery finds a device
-// if (BluetoothDevice.ACTION_FOUND.equals(action)) {
-// // Get the BluetoothDevice object from the Intent
-// BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
-// // If it's already paired, skip it, because it's been listed already
-// if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
-// mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
-// }
-// // When discovery is finished, change the Activity title
-// } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
-// setProgressBarIndeterminateVisibility(false);
-// setTitle(R.string.select_device);
-// if (mNewDevicesArrayAdapter.getCount() == 0) {
-// String noDevices = getResources().getText(R.string.none_found).toString();
-// mNewDevicesArrayAdapter.add(noDevices);
-// }
-// }
-// }
-// };
-
protected void sendDataToDevice(String data) {
Message message = Message.obtain(null, BigFinCommunicationService.MESSAGE_SEND_DATA);
Bundle bundle = new Bundle();
Added: trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/utils/UpdateCheckTask.java 2014-03-03 12:45:57 UTC (rev 61)
@@ -0,0 +1,18 @@
+package fr.ifremer.wlo.utils;
+
+import android.os.AsyncTask;
+
+import java.net.URL;
+
+/**
+ * @author Kevin Morin (Code Lutin)
+ * @since x.x
+ */
+public class UpdateCheckTask extends AsyncTask<URL, Integer, Long> {
+
+ @Override
+ protected Long doInBackground(URL... params) {
+
+ return null;
+ }
+}
1
0
r60 - in trunk: res/layout src/fr/ifremer/wlo src/fr/ifremer/wlo/measurement
by kmorin@users.forge.codelutin.com 02 Mar '14
by kmorin@users.forge.codelutin.com 02 Mar '14
02 Mar '14
Author: kmorin
Date: 2014-03-02 20:42:31 +0100 (Sun, 02 Mar 2014)
New Revision: 60
Url: http://codelutin.com/projects/wlo/repository/revisions/60
Log:
refs #4372 navigation ?\195?\160 am?\195?\169liorer
refs #4253 proposer le m?\195?\170me principe de navigation disponible actuellement sur le lot feuille (observations) ?\195?\160 toutes les ?\195?\169tapes
Added:
trunk/res/layout/wlo_list.xml
Modified:
trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java
trunk/src/fr/ifremer/wlo/WloBaseListActivity.java
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
Copied: trunk/res/layout/wlo_list.xml (from rev 57, trunk/res/layout/measurement.xml)
===================================================================
--- trunk/res/layout/wlo_list.xml (rev 0)
+++ trunk/res/layout/wlo_list.xml 2014-03-02 19:42:31 UTC (rev 60)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<android.support.v4.widget.DrawerLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/drawer_layout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ListView android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <ListView android:id="@+id/left_drawer"
+ android:layout_width="240dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="start"
+ android:choiceMode="singleChoice"
+ android:background="@color/dark_gray"/>
+
+</android.support.v4.widget.DrawerLayout>
\ No newline at end of file
Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java 2014-03-01 21:36:10 UTC (rev 59)
+++ trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java 2014-03-02 19:42:31 UTC (rev 60)
@@ -113,9 +113,10 @@
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
ScientificSpeciesModel model = createNewModel(l, position);
-
Log.d(TAG, model.toString(this) + " clicked");
+ updateDrawerItems(model);
+
Intent intent = new Intent(this, getNextActivity());
intent.putExtra(MeasurementActivity.INTENT_EXTRA_SCIENTIFIC_SPECIES, model);
startActivity(intent);
Modified: trunk/src/fr/ifremer/wlo/WloBaseListActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloBaseListActivity.java 2014-03-01 21:36:10 UTC (rev 59)
+++ trunk/src/fr/ifremer/wlo/WloBaseListActivity.java 2014-03-02 19:42:31 UTC (rev 60)
@@ -39,6 +39,7 @@
* #L%
*/
+import android.app.ActionBar;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
@@ -46,6 +47,8 @@
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v4.app.ActionBarDrawerToggle;
+import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.ContextMenu;
@@ -54,14 +57,29 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
import fr.ifremer.wlo.models.BaseModel;
+import fr.ifremer.wlo.models.CommercialSpeciesModel;
+import fr.ifremer.wlo.models.ContextModel;
import fr.ifremer.wlo.models.HierarchicalModel;
+import fr.ifremer.wlo.models.LocationModel;
+import fr.ifremer.wlo.models.MetierModel;
+import fr.ifremer.wlo.models.ScientificSpeciesModel;
+import fr.ifremer.wlo.models.VesselModel;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
import fr.ifremer.wlo.utils.UIUtils;
import fr.ifremer.wlo.utils.WloItemListViewBinder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* An activity that displays a list of items by binding to a data source such as
* an array or Cursor, and exposes event handlers when the user selects an item.
@@ -220,11 +238,18 @@
public static final String INTENT_EXTRA_PARENT_MODEL = "parentModel";
+ public static final int REQUEST_EDIT_MODEL = 0;
+
+ protected final static Map<Class, BaseModel> drawerItems = new LinkedHashMap<>();
+
protected BaseModel parentModel;
protected WloSqlOpenHelper woh;
protected SimpleCursorAdapter adapter;
+ protected ActionBarDrawerToggle mDrawerToggle;
+ protected ListView mDrawerList;
+
/**
* This field should be made private, so it is hidden from the SDK.
* {@hide}
@@ -264,7 +289,7 @@
@Override
protected Integer getContentView() {
- return android.R.layout.list_content;
+ return R.layout.wlo_list;
}
protected SimpleCursorAdapter.ViewBinder getAdapterBinder() {
@@ -282,13 +307,53 @@
setListAdapter(adapter);
registerForContextMenu(mList);
+
+ DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+ mDrawerList = (ListView) findViewById(R.id.left_drawer);
+
+ // Set the list's click listener
+ mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView parent, View view, int position, long id) {
+ selectItem(position);
+ }
+ });
+ mDrawerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ editItem(position);
+ return true;
+ }
+ });
+ mDrawerToggle = new ActionBarDrawerToggle(
+ this, /* host Activity */
+ mDrawerLayout, /* DrawerLayout object */
+ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
+ R.string.drawer_open, /* "open drawer" description */
+ R.string.drawer_close /* "close drawer" description */
+ );
+
+ // Set the drawer toggle as the DrawerListener
+ mDrawerLayout.setDrawerListener(mDrawerToggle);
+
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setHomeButtonEnabled(true);
}
@Override
+ protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ // Sync the toggle state after onRestoreInstanceState has occurred.
+ mDrawerToggle.syncState();
+ }
+
+ @Override
protected void onResume() {
super.onResume();
parentModel = (BaseModel) getIntent().getSerializableExtra(INTENT_EXTRA_PARENT_MODEL);
+ Log.d(TAG, "resume " + parentModel);
if (parentModel != null) {
Cursor cursor = getAllData();
Log.d(TAG, "cursor size : " + cursor.getCount());
@@ -299,7 +364,10 @@
String subtitle = getString(subtitleId, parentModel.toString(this));
getSupportActionBar().setSubtitle(subtitle);
}
+
}
+ // Set the adapter for the list view
+ setDrawerListAdapter();
}
@Override
@@ -328,6 +396,12 @@
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ // Pass the event to ActionBarDrawerToggle, if it returns
+ // true, then it has handled the app icon touch event
+ if (mDrawerToggle.onOptionsItemSelected(item)) {
+ return true;
+ }
+
switch (item.getItemId()) {
case R.id.add_item:
Intent intent = new Intent(this, getEditionActivity());
@@ -338,6 +412,39 @@
return super.onOptionsItemSelected(item);
}
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ mDrawerToggle.onConfigurationChanged(newConfig);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_EDIT_MODEL && resultCode == RESULT_OK) {
+ BaseModel editedModel = (BaseModel) data.getSerializableExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL);
+ if (editedModel != null) {
+ drawerItems.put(editedModel.getClass(), editedModel);
+ }
+ } else {
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ }
+
+ protected void setDrawerListAdapter() {
+ List<String> drawerItemsLabels = new ArrayList<>();
+ drawerItemsLabels.add(getString(R.string.home_title));
+ List<BaseModel> values = new ArrayList<>(drawerItems.values());
+ drawerItemsLabels.addAll(Lists.transform(values, new Function<BaseModel, String>() {
+ @Override
+ public String apply(BaseModel input) {
+ return input.toString(WloBaseListActivity.this);
+ }
+ }));
+ mDrawerList.setAdapter(new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1,
+ drawerItemsLabels));
+ }
+
/**
* This method will be called when an item in the list is selected.
* Subclasses should override. Subclasses can call
@@ -354,6 +461,8 @@
Log.d(TAG, model.toString(this) + " clicked");
+ updateDrawerItems(model);
+
Intent intent = new Intent(this, getNextActivity());
intent.putExtra(INTENT_EXTRA_PARENT_MODEL, model);
startActivity(intent);
@@ -508,4 +617,101 @@
}
};
+ protected void updateDrawerItems(M model) {
+ Class<? extends BaseModel> itemClass = model.getClass();
+ BaseModel currentItem = drawerItems.get(itemClass);
+ if (!model.equals(currentItem)) {
+ drawerItems.put(itemClass, model);
+ String itemTable = model.getTableName();
+ switch (itemTable) {
+ case ContextModel.TABLE_NAME:
+ drawerItems.remove(LocationModel.class);
+ case LocationModel.TABLE_NAME:
+ drawerItems.remove(VesselModel.class);
+ case VesselModel.TABLE_NAME:
+ drawerItems.remove(MetierModel.class);
+ case MetierModel.TABLE_NAME:
+ drawerItems.remove(CommercialSpeciesModel.class);
+ case CommercialSpeciesModel.TABLE_NAME:
+ drawerItems.remove(ScientificSpeciesModel.class);
+ }
+ }
+ }
+
+ protected void selectItem(int position) {
+ Class activityClass;
+ Class parentModelClass = null;
+ switch (position) {
+ case 0:
+ activityClass = MainActivity.class;
+ break;
+ case 1:
+ activityClass = ContextsActivity.class;
+ break;
+ case 2:
+ activityClass = LocationsActivity.class;
+ parentModelClass = ContextModel.class;
+ break;
+ case 3:
+ activityClass = VesselsActivity.class;
+ parentModelClass = LocationModel.class;
+ break;
+ case 4:
+ activityClass = MetiersActivity.class;
+ parentModelClass = VesselModel.class;
+ break;
+ case 5:
+ activityClass = CommercialSpeciesActivity.class;
+ parentModelClass = MetierModel.class;
+ break;
+ case 6:
+ activityClass = ScientificSpeciesActivity.class;
+ parentModelClass = CommercialSpeciesModel.class;
+ break;
+ default:
+ activityClass = null;
+ }
+ BaseModel parentModel = drawerItems.get(parentModelClass);
+ Intent intent = new Intent(this, activityClass);
+ intent.putExtra(WloBaseListActivity.INTENT_EXTRA_PARENT_MODEL, parentModel);
+ startActivity(intent);
+ }
+
+ protected void editItem(int position) {
+ Class activityClass = null;
+ Class modelClass = null;
+
+ switch (position) {
+ case 1:
+ activityClass = ContextFormActivity.class;
+ modelClass = ContextModel.class;
+ break;
+ case 2:
+ activityClass = LocationFormActivity.class;
+ modelClass = LocationModel.class;
+ break;
+ case 3:
+ activityClass = VesselFormActivity.class;
+ modelClass = VesselModel.class;
+ break;
+ case 4:
+ activityClass = MetierFormActivity.class;
+ modelClass = MetierModel.class;
+ break;
+ case 5:
+ activityClass = CommercialSpeciesFormActivity.class;
+ modelClass = CommercialSpeciesModel.class;
+ break;
+ case 6:
+ activityClass = ScientificSpeciesFormActivity.class;
+ modelClass = ScientificSpeciesModel.class;
+ break;
+ }
+ if (activityClass != null) {
+ BaseModel model = drawerItems.get(modelClass);
+ Intent intent = new Intent(this, activityClass);
+ intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, model);
+ startActivityForResult(intent, REQUEST_EDIT_MODEL);
+ }
+ }
}
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-01 21:36:10 UTC (rev 59)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-02 19:42:31 UTC (rev 60)
@@ -57,16 +57,21 @@
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import fr.ifremer.wlo.BigFinCommunicationService;
+import fr.ifremer.wlo.CommercialSpeciesActivity;
import fr.ifremer.wlo.CommercialSpeciesFormActivity;
import fr.ifremer.wlo.MainActivity;
import fr.ifremer.wlo.MetierFormActivity;
+import fr.ifremer.wlo.MetiersActivity;
import fr.ifremer.wlo.R;
import fr.ifremer.wlo.ScientificSpeciesActivity;
import fr.ifremer.wlo.ScientificSpeciesFormActivity;
import fr.ifremer.wlo.VesselFormActivity;
+import fr.ifremer.wlo.VesselsActivity;
import fr.ifremer.wlo.WloBaseActivity;
+import fr.ifremer.wlo.WloBaseListActivity;
import fr.ifremer.wlo.WloModelEditionActivity;
import fr.ifremer.wlo.models.CategoryWeightModel;
+import fr.ifremer.wlo.models.LocationModel;
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
import fr.ifremer.wlo.models.referentials.CalcifiedPartTaking;
@@ -124,6 +129,7 @@
protected CommercialSpeciesModel commercialSpecies;
protected MetierModel metier;
protected VesselModel vessel;
+ protected LocationModel location;
protected ListView mDrawerList;
@@ -188,6 +194,7 @@
measurements.setPrecision(commercialSpecies.getPrecision());
metier = commercialSpecies.getParent();
vessel = metier.getParent();
+ location = vessel.getParent();
tabs = (TabHost)findViewById(android.R.id.tabhost);
@@ -248,7 +255,20 @@
setDrawerListAdapter();
// Set the list's click listener
- mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
+ mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView parent, View view, int position, long id) {
+ selectItem(position);
+ }
+ });
+ mDrawerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ editItem(position);
+ return true;
+ }
+ });
+
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
@@ -624,15 +644,15 @@
}
protected void setDrawerListAdapter() {
- mDrawerList.setAdapter(new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1,
- new String[]{
- getString(R.string.home_title),
- vessel.toString(this),
- metier.toString(this),
- commercialSpecies.toString(this),
- scientificSpecies.toString(this)
- }));
+ mDrawerList.setAdapter(new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1,
+ new String[]{
+ getString(R.string.home_title),
+ vessel.toString(this),
+ metier.toString(this),
+ commercialSpecies.toString(this),
+ scientificSpecies.toString(this)
+ }));
}
protected void fetchCalcifiedPartTakings() {
@@ -650,15 +670,8 @@
}
}
- private class DrawerItemClickListener implements ListView.OnItemClickListener {
- @Override
- public void onItemClick(AdapterView parent, View view, int position, long id) {
- selectItem(position);
- }
- }
-
/** Swaps fragments in the main content view */
- private void selectItem(int position) {
+ protected void editItem(int position) {
Class clazz;
BaseModel modelToEdit;
switch (position) {
@@ -686,9 +699,44 @@
clazz = null;
modelToEdit = null;
}
- Intent intent = new Intent(this, clazz);
- intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, modelToEdit);
- startActivityForResult(intent, position);
+ if (clazz != null) {
+ Intent intent = new Intent(this, clazz);
+ intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, modelToEdit);
+ startActivityForResult(intent, position);
+ }
}
+ protected void selectItem(int position) {
+ Class activityClass;
+ BaseModel parentModel = null;
+ switch (position) {
+ case 0:
+ activityClass = MainActivity.class;
+ break;
+ case 1:
+ activityClass = VesselsActivity.class;
+ parentModel = location;
+ break;
+ case 2:
+ activityClass = MetiersActivity.class;
+ parentModel = vessel;
+ break;
+ case 3:
+ activityClass = CommercialSpeciesActivity.class;
+ parentModel = metier;
+ break;
+ case 4:
+ activityClass = ScientificSpeciesActivity.class;
+ parentModel = commercialSpecies;
+ break;
+ default:
+ activityClass = null;
+ }
+ if (activityClass != null) {
+ Intent intent = new Intent(this, activityClass);
+ intent.putExtra(WloBaseListActivity.INTENT_EXTRA_PARENT_MODEL, parentModel);
+ startActivity(intent);
+ }
+ }
+
}
1
0