Big refactoring
Fragment instead of activity OSM instead of GMaps Remove old code to replace by newer implementation Fix warnings
This commit is contained in:
parent
2985520c89
commit
b0f208823b
55 changed files with 2661 additions and 2422 deletions
31
.gitignore
vendored
31
.gitignore
vendored
|
@ -1,9 +1,26 @@
|
|||
app/build/*
|
||||
build/*
|
||||
.gradle/*
|
||||
.idea/*
|
||||
gradle/*
|
||||
gradlew*
|
||||
import-summary.txt
|
||||
*.apk
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
/*/build/
|
||||
gradlew*
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
#android-studio file
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
captures/
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
113
app/app.iml
113
app/app.iml
|
@ -1,113 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="BloodDonation" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="play-services-plus-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-cast-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-maps-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-base-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-fitness-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-panorama-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-safetynet-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-location-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-identity-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-ads-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-appstate-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-drive-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-games-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-analytics-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-appindexing-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-gcm-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-nearby-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-wearable-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-wallet-7.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-21.0.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -1,22 +1,30 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion '21.1.2'
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion '26.0.1'
|
||||
defaultConfig {
|
||||
applicationId "fr.mobdev.blooddonation"
|
||||
minSdkVersion 11
|
||||
targetSdkVersion 21
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 26
|
||||
versionCode = "8"
|
||||
versionName = "3.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.android.gms:play-services:+'
|
||||
compile 'com.android.support:appcompat-v7:21.0.0'
|
||||
compile 'com.google.android.gms:play-services-ads:11.0.4'
|
||||
|
||||
compile 'com.github.car2go.AnyMaps:anymaps-base:6.0.0'
|
||||
compile 'com.github.car2go.AnyMaps:anymaps-osm:6.0.0'
|
||||
|
||||
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
|
||||
compile 'com.android.support:design:26.0.0-alpha1'
|
||||
compile 'com.android.support:support-v4:26.0.0-alpha1'
|
||||
}
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="fr.mobdev.blooddonation"
|
||||
android:versionCode="7"
|
||||
android:versionName="2.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="21" />
|
||||
>
|
||||
|
||||
<supports-screens
|
||||
android:largeScreens="false"
|
||||
|
@ -19,63 +14,29 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<uses-feature
|
||||
android:glEsVersion="0x00020000"
|
||||
android:required="true" />
|
||||
<uses-feature android:name="android.hardware.location.gps"/>
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<uses-library
|
||||
android:name="com.google.android.maps"
|
||||
android:required="false" />
|
||||
|
||||
<!-- google Maps API -->
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
<meta-data
|
||||
android:name="com.google.android.maps.v2.API_KEY"
|
||||
android:value="AIzaSyBtxQBjEu5XZ0Gw_ObqTx-iCaCsLth4Id8" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait" >
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:screenOrientation="portrait"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.AboutActivity"
|
||||
android:parentActivityName=".activity.MainActivity"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.PrefsActivity"
|
||||
android:parentActivityName=".activity.MainActivity"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.DonationActivity"
|
||||
android:parentActivityName=".activity.MainActivity"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.DonationInfoActivity"
|
||||
android:parentActivityName=".activity.MainActivity"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.google.android.gms.ads.AdActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
|
||||
|
@ -87,12 +48,6 @@
|
|||
</receiver>
|
||||
<receiver android:name=".service.AlarmReceiver" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.NotificationsActivity"
|
||||
android:label="@string/title_activity_notifications"
|
||||
android:parentActivityName=".activity.MainActivity"
|
||||
android:screenOrientation="portrait">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,25 +0,0 @@
|
|||
package fr.mobdev.blooddonation;
|
||||
|
||||
|
||||
import com.google.android.gms.analytics.GoogleAnalytics;
|
||||
import com.google.android.gms.analytics.Tracker;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
public class App extends Application {
|
||||
private Tracker tracker;
|
||||
|
||||
public void onCreate(){
|
||||
super.onCreate();
|
||||
tracker = null;
|
||||
getTracker();
|
||||
}
|
||||
|
||||
synchronized Tracker getTracker() {
|
||||
|
||||
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
|
||||
if(tracker == null)
|
||||
tracker = analytics.newTracker(R.xml.analytics);
|
||||
return tracker;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import fr.mobdev.blooddonation.enums.DonationType;
|
|||
import fr.mobdev.blooddonation.enums.SiteType;
|
||||
import fr.mobdev.blooddonation.objects.BloodSite;
|
||||
import fr.mobdev.blooddonation.objects.Donation;
|
||||
import fr.mobdev.blooddonation.objects.LatiLng;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
@ -21,474 +21,487 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import com.car2go.maps.model.LatLng;
|
||||
|
||||
|
||||
public class Database extends SQLiteOpenHelper {
|
||||
|
||||
private static Database instance;
|
||||
private static Database instance;
|
||||
|
||||
public static Database getInstance(Context context)
|
||||
{
|
||||
if(instance == null)
|
||||
instance = new Database(context, "BloodDonation.db", null, 3);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Database(Context context, String name, CursorFactory factory, int version) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("Create table if not exists user (" +
|
||||
"id integer primary key autoincrement, name varchar(1024), city varchar(1024), postal varchar(10), gender INTEGER, blood varchar(10), D INTEGER, C INTEGER, E INTEGER, min_c INTEGER, min_e INTEGER, K INTEGER" +
|
||||
",latitude REAL, longitude REAL);");
|
||||
db.execSQL("Create table if not exists site (" +
|
||||
"id integer primary key autoincrement, country INTEGER, address varchar(1024), city varchar(1024), details varchar(4096), mail varchar(1024), phone varchar(1024),"
|
||||
+"siteName varchar(1024), siteId INTEGER, date INTEGER, latitude REAL, longitude REAL, type INTEGER, schedule INTEGER" +
|
||||
");");
|
||||
db.execSQL("Create table if not exists donation (" +
|
||||
"id integer primary key autoincrement, date INTEGER, siteId INTEGER, city varchar(1024), donation_type INTEGER" +
|
||||
");");
|
||||
db.execSQL("Create table if not exists notification (" +
|
||||
"id integer primary key autoincrement, siteId INTEGER, skip INTEGER " +
|
||||
");");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
//nothing to do right now
|
||||
|
||||
db.execSQL("Create table if not exists notification (" +
|
||||
"id integer primary key autoincrement, siteId INTEGER, skip INTEGER " +
|
||||
");");
|
||||
if(oldVersion == 2 && newVersion == 3)
|
||||
public static Database getInstance(Context context)
|
||||
{
|
||||
db.execSQL("Alter Table notification Add Column skip INTEGER;");
|
||||
if(instance == null)
|
||||
instance = new Database(context, "BloodDonation.db", null, 3);
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateUserInfo(String name, boolean isMale, String city, String postal, String blood, boolean D, boolean C, boolean E, boolean c, boolean e, boolean K) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("name", name);
|
||||
values.put("city", city);
|
||||
values.put("postal", postal);
|
||||
values.put("blood", blood);
|
||||
values.put("gender", isMale);
|
||||
values.put("D",D);
|
||||
values.put("C",C);
|
||||
values.put("E",E);
|
||||
values.put("min_c",c);
|
||||
values.put("min_e",e);
|
||||
values.put("K",K);
|
||||
values.put("latitude", 0);
|
||||
values.put("longitude", 0);
|
||||
if(!isFirstTime())
|
||||
{
|
||||
int userId = -1;
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
userId = cursor.getInt(0);
|
||||
String whereClause = "id = ?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(userId);
|
||||
getWritableDatabase().update("user", values, whereClause, whereArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
getWritableDatabase().insert("user", null, values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateUserLoc(double latitude, double longitude)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("latitude", latitude);
|
||||
values.put("longitude", longitude);
|
||||
int userId = -1;
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
userId = cursor.getInt(0);
|
||||
String whereClause = "id = ?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(userId);
|
||||
getWritableDatabase().update("user", values, whereClause, whereArgs);
|
||||
}
|
||||
|
||||
public boolean isFirstTime() {
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
if(cursor.getCount() != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addSitesToDb(List<BloodSite> sites) {
|
||||
//remove existing site in the list
|
||||
List<BloodSite> oldList = getBloodSites(-1);
|
||||
List<BloodSite> removeList = new ArrayList<BloodSite>();
|
||||
for(BloodSite site : sites)
|
||||
{
|
||||
if(oldList.contains(site))
|
||||
{
|
||||
removeList.add(site);
|
||||
}
|
||||
else
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("address", site.getAddress());
|
||||
values.put("city", site.getCityName());
|
||||
values.put("details", site.getDetails());
|
||||
values.put("mail", site.getMail());
|
||||
values.put("phone", site.getPhone());
|
||||
values.put("siteName", site.getSiteName());
|
||||
values.put("siteId", site.getSiteId());
|
||||
values.put("country", site.getCountry().ordinal());
|
||||
if(site.getDate()!=null)
|
||||
values.put("date", site.getDate().getTimeInMillis());
|
||||
else
|
||||
values.put("date", -1);
|
||||
values.put("latitude", site.getLoc().latitude);
|
||||
values.put("longitude", site.getLoc().longitude);
|
||||
values.put("type", site.getType().ordinal());
|
||||
getWritableDatabase().insert("site", null, values);
|
||||
}
|
||||
}
|
||||
sites.removeAll(removeList);
|
||||
}
|
||||
|
||||
public List<Donation> getDonations() {
|
||||
List<Donation> donations = new ArrayList<Donation>();
|
||||
String orderBy = "date ASC";
|
||||
Cursor cursor = getReadableDatabase().query("donation", null, null, null, null, null, orderBy);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 0;
|
||||
int donationId = cursor.getInt(col++);
|
||||
long date = cursor.getLong(col++);
|
||||
int siteId = cursor.getInt(col++);
|
||||
String city_name = cursor.getString(col++);
|
||||
int donation_type = cursor.getInt(col++);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
cal.setTimeInMillis(date);
|
||||
|
||||
Donation donation = new Donation(DonationType.values()[donation_type], cal, siteId, donationId, city_name);
|
||||
donations.add(donation);
|
||||
}
|
||||
return donations;
|
||||
}
|
||||
|
||||
public void deleteDonation(List<Donation> deletedList) {
|
||||
for(Donation donation : deletedList)
|
||||
{
|
||||
String whereClause = "id = ?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(donation.getDonationId());
|
||||
getWritableDatabase().delete("donation", whereClause, whereArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public void addDonation(Donation donation) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("siteId", donation.getSiteId());
|
||||
values.put("date", donation.getDate().getTimeInMillis());
|
||||
values.put("donation_type", donation.getDonationType().ordinal());
|
||||
values.put("city", donation.getCityName());
|
||||
getWritableDatabase().insert("donation", null, values);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getUserInformation()
|
||||
{
|
||||
HashMap<String, Object> maps = new HashMap<String, Object>();
|
||||
if(!isFirstTime())
|
||||
{
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
int col = 1;
|
||||
maps.put("UserName", cursor.getString(col++));//1
|
||||
maps.put("CityName", cursor.getString(col++));//2
|
||||
maps.put("Postal", cursor.getString(col++));//3
|
||||
maps.put("Gender", cursor.getInt(col++));//4
|
||||
maps.put("BloodGroup", cursor.getString(col++));//5
|
||||
maps.put("D", cursor.getInt(col++));
|
||||
maps.put("C", cursor.getInt(col++));
|
||||
maps.put("E", cursor.getInt(col++));
|
||||
maps.put("c", cursor.getInt(col++));
|
||||
maps.put("e", cursor.getInt(col++));
|
||||
maps.put("K", cursor.getInt(col++));
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
public List<BloodSite> getBloodSites(long siteId) {
|
||||
ArrayList<BloodSite> list = new ArrayList<BloodSite>();
|
||||
String whereClause = null;
|
||||
String[] whereArgs = null;
|
||||
if(siteId != -1)
|
||||
{
|
||||
whereClause = "id = ?";
|
||||
whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(siteId);
|
||||
}
|
||||
|
||||
|
||||
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, null);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 0;
|
||||
long dbId = cursor.getLong(col++);
|
||||
|
||||
int ordinal =cursor.getInt(col++);
|
||||
BloodSite site = new BloodSite(Country.values()[ordinal]);
|
||||
site.setDbId(dbId);
|
||||
site.setAddress(cursor.getString(col++));
|
||||
site.setCityName(cursor.getString(col++));
|
||||
site.setDetails(cursor.getString(col++));
|
||||
site.setMail(cursor.getString(col++));
|
||||
site.setPhone(cursor.getString(col++));
|
||||
site.setSiteName(cursor.getString(col++));
|
||||
site.setSiteId(cursor.getLong(col++));
|
||||
long time = cursor.getLong(col++);
|
||||
if(time == -1)
|
||||
site.setDate(null);
|
||||
else
|
||||
{
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
date.setTimeInMillis(time);
|
||||
site.setDate(date);
|
||||
}
|
||||
double lat = cursor.getDouble(col++);
|
||||
double lon = cursor.getDouble(col++);
|
||||
site.setLoc(new LatiLng(lat, lon));
|
||||
site.setType(SiteType.values()[cursor.getInt(col++)]);
|
||||
list.add(site);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public BloodSite getPastUnregisteredDonation() {
|
||||
|
||||
String whereClause = "schedule = ? and date < ?";
|
||||
String[] whereArgs = new String[2];
|
||||
whereArgs[0] = String.valueOf(1);
|
||||
|
||||
Calendar dateTime = Calendar.getInstance();
|
||||
dateTime.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
dateTime.set(Calendar.HOUR_OF_DAY, 0);
|
||||
dateTime.set(Calendar.MILLISECOND, 0);
|
||||
dateTime.set(Calendar.MINUTE, 0);
|
||||
dateTime.set(Calendar.SECOND, 0);
|
||||
whereArgs[1] = String.valueOf(dateTime.getTimeInMillis());
|
||||
String orderBy = "date ASC";
|
||||
|
||||
BloodSite site = null;
|
||||
|
||||
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, orderBy);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
int col = 0;
|
||||
long dbId = cursor.getLong(col++);
|
||||
|
||||
int ordinal = cursor.getInt(col++);
|
||||
site = new BloodSite(Country.values()[ordinal]);
|
||||
site.setDbId(dbId);
|
||||
site.setAddress(cursor.getString(col++));
|
||||
site.setCityName(cursor.getString(col++));
|
||||
site.setDetails(cursor.getString(col++));
|
||||
site.setMail(cursor.getString(col++));
|
||||
site.setPhone(cursor.getString(col++));
|
||||
site.setSiteName(cursor.getString(col++));
|
||||
site.setSiteId(cursor.getLong(col++));
|
||||
long time = cursor.getLong(col++);
|
||||
if(time == -1)
|
||||
site.setDate(null);
|
||||
else
|
||||
{
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
date.setTimeInMillis(time);
|
||||
site.setDate(date);
|
||||
}
|
||||
double lat = cursor.getDouble(col++);
|
||||
double lon = cursor.getDouble(col++);
|
||||
site.setLoc(new LatiLng(lat, lon));
|
||||
site.setType(SiteType.values()[cursor.getInt(col++)]);
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
||||
public List<BloodSite> getNotifications()
|
||||
{
|
||||
Cursor cursor = getWritableDatabase().query("notification",null,null,null,null,null,null);
|
||||
List<Long> oldNotif = new ArrayList<Long>();
|
||||
List<BloodSite> sites = new ArrayList<BloodSite>();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 1;
|
||||
Long id = cursor.getLong(col++);
|
||||
int skip = cursor.getInt(col++);
|
||||
List<BloodSite> site = getBloodSites(id);
|
||||
//for each siteId found check if date is passed and if it was remove item from the notifications
|
||||
if(site.size() == 1 && cal.compareTo(site.get(0).getDate()) > 0)
|
||||
{
|
||||
oldNotif.add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(site.size() > 0 && skip == 0)
|
||||
sites.add(site.get(0));
|
||||
}
|
||||
private Database(Context context, String name, CursorFactory factory, int version) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
|
||||
Comparator<BloodSite> compareDate = new Comparator<BloodSite>() {
|
||||
@Override
|
||||
public int compare(BloodSite lhs, BloodSite rhs) {
|
||||
return lhs.getDate().compareTo(rhs.getDate());
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("Create table if not exists user (" +
|
||||
"id integer primary key autoincrement, name varchar(1024), city varchar(1024), postal varchar(10), gender INTEGER, blood varchar(10), D INTEGER, C INTEGER, E INTEGER, min_c INTEGER, min_e INTEGER, K INTEGER" +
|
||||
",latitude REAL, longitude REAL);");
|
||||
db.execSQL("Create table if not exists site (" +
|
||||
"id integer primary key autoincrement, country INTEGER, address varchar(1024), city varchar(1024), details varchar(4096), mail varchar(1024), phone varchar(1024),"
|
||||
+"siteName varchar(1024), siteId INTEGER, date INTEGER, latitude REAL, longitude REAL, type INTEGER, schedule INTEGER" +
|
||||
");");
|
||||
db.execSQL("Create table if not exists donation (" +
|
||||
"id integer primary key autoincrement, date INTEGER, siteId INTEGER, city varchar(1024), donation_type INTEGER" +
|
||||
");");
|
||||
db.execSQL("Create table if not exists notification (" +
|
||||
"id integer primary key autoincrement, siteId INTEGER, skip INTEGER " +
|
||||
");");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
//nothing to do right now
|
||||
|
||||
db.execSQL("Create table if not exists notification (" +
|
||||
"id integer primary key autoincrement, siteId INTEGER, skip INTEGER " +
|
||||
");");
|
||||
if(oldVersion == 2 && newVersion == 3)
|
||||
{
|
||||
db.execSQL("Alter Table notification Add Column skip INTEGER;");
|
||||
}
|
||||
};
|
||||
|
||||
removeNotifications(oldNotif);
|
||||
Collections.sort(sites,compareDate);
|
||||
}
|
||||
|
||||
return sites;
|
||||
}
|
||||
public void updateUserInfo(String name, boolean isMale, String city, String postal, String blood, boolean D, boolean C, boolean E, boolean c, boolean e, boolean K) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("name", name);
|
||||
values.put("city", city);
|
||||
values.put("postal", postal);
|
||||
values.put("blood", blood);
|
||||
values.put("gender", isMale);
|
||||
values.put("D",D);
|
||||
values.put("C",C);
|
||||
values.put("E",E);
|
||||
values.put("min_c",c);
|
||||
values.put("min_e",e);
|
||||
values.put("K",K);
|
||||
values.put("latitude", 0);
|
||||
values.put("longitude", 0);
|
||||
if(!isFirstTime())
|
||||
{
|
||||
int userId;
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
userId = cursor.getInt(0);
|
||||
String whereClause = "id = ?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(userId);
|
||||
getWritableDatabase().update("user", values, whereClause, whereArgs);
|
||||
cursor.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
getWritableDatabase().insert("user", null, values);
|
||||
}
|
||||
|
||||
public void removeNotifications(List<Long> notificationIds)
|
||||
{
|
||||
String args[] = new String[1];
|
||||
String clause = "siteId = ?";
|
||||
for(Long id : notificationIds)
|
||||
{
|
||||
args[0] = String.valueOf(id);
|
||||
getWritableDatabase().delete("notification", clause, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void scheduleDonation(long siteId, boolean scheduling)
|
||||
{
|
||||
String whereClause = "id = ? ";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(siteId);
|
||||
ContentValues values = new ContentValues();
|
||||
if(scheduling)
|
||||
values.put("schedule", 1);
|
||||
else
|
||||
values.put("schedule", 0);
|
||||
|
||||
|
||||
getWritableDatabase().update("site", values, whereClause, whereArgs);
|
||||
}
|
||||
public void updateUserLoc(double latitude, double longitude)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("latitude", latitude);
|
||||
values.put("longitude", longitude);
|
||||
int userId;
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
userId = cursor.getInt(0);
|
||||
String whereClause = "id = ?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(userId);
|
||||
getWritableDatabase().update("user", values, whereClause, whereArgs);
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
public List<BloodSite> getBloodSites(LatiLng NE, LatiLng SW) {
|
||||
public boolean isFirstTime() {
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
if(cursor.getCount() != 0){
|
||||
cursor.close();
|
||||
return false;
|
||||
}
|
||||
cursor.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addSitesToDb(List<BloodSite> sites) {
|
||||
//remove existing site in the list
|
||||
List<BloodSite> oldList = getBloodSites(-1);
|
||||
List<BloodSite> removeList = new ArrayList<>();
|
||||
for(BloodSite site : sites)
|
||||
{
|
||||
if(oldList.contains(site))
|
||||
{
|
||||
removeList.add(site);
|
||||
}
|
||||
else
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("address", site.getAddress());
|
||||
values.put("city", site.getCityName());
|
||||
values.put("details", site.getDetails());
|
||||
values.put("mail", site.getMail());
|
||||
values.put("phone", site.getPhone());
|
||||
values.put("siteName", site.getSiteName());
|
||||
values.put("siteId", site.getSiteId());
|
||||
values.put("country", site.getCountry().ordinal());
|
||||
if(site.getDate()!=null)
|
||||
values.put("date", site.getDate().getTimeInMillis());
|
||||
else
|
||||
values.put("date", -1);
|
||||
values.put("latitude", site.getLoc().latitude);
|
||||
values.put("longitude", site.getLoc().longitude);
|
||||
values.put("type", site.getType().ordinal());
|
||||
getWritableDatabase().insert("site", null, values);
|
||||
}
|
||||
}
|
||||
sites.removeAll(removeList);
|
||||
}
|
||||
|
||||
public List<Donation> getDonations() {
|
||||
List<Donation> donations = new ArrayList<>();
|
||||
String orderBy = "date DESC";
|
||||
Cursor cursor = getReadableDatabase().query("donation", null, null, null, null, null, orderBy);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 0;
|
||||
int donationId = cursor.getInt(col++);
|
||||
long date = cursor.getLong(col++);
|
||||
int siteId = cursor.getInt(col++);
|
||||
String city_name = cursor.getString(col++);
|
||||
int donation_type = cursor.getInt(col);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
cal.setTimeInMillis(date);
|
||||
|
||||
Donation donation = new Donation(DonationType.values()[donation_type], cal, siteId, donationId, city_name);
|
||||
donations.add(donation);
|
||||
}
|
||||
cursor.close();
|
||||
return donations;
|
||||
}
|
||||
|
||||
public void deleteDonation(List<Donation> deletedList) {
|
||||
for(Donation donation : deletedList)
|
||||
{
|
||||
String whereClause = "id = ?";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(donation.getDonationId());
|
||||
getWritableDatabase().delete("donation", whereClause, whereArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public void addDonation(Donation donation) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("siteId", donation.getSiteId());
|
||||
values.put("date", donation.getDate().getTimeInMillis());
|
||||
values.put("donation_type", donation.getDonationType().ordinal());
|
||||
values.put("city", donation.getCityName());
|
||||
getWritableDatabase().insert("donation", null, values);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getUserInformation()
|
||||
{
|
||||
HashMap<String, Object> maps = new HashMap<>();
|
||||
if(!isFirstTime())
|
||||
{
|
||||
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
int col = 1;
|
||||
maps.put("UserName", cursor.getString(col++));//1
|
||||
maps.put("CityName", cursor.getString(col++));//2
|
||||
maps.put("Postal", cursor.getString(col++));//3
|
||||
maps.put("Gender", cursor.getInt(col++));//4
|
||||
maps.put("BloodGroup", cursor.getString(col++));//5
|
||||
maps.put("D", cursor.getInt(col++));
|
||||
maps.put("C", cursor.getInt(col++));
|
||||
maps.put("E", cursor.getInt(col++));
|
||||
maps.put("c", cursor.getInt(col++));
|
||||
maps.put("e", cursor.getInt(col++));
|
||||
maps.put("K", cursor.getInt(col));
|
||||
cursor.close();
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
public List<BloodSite> getBloodSites(long siteId) {
|
||||
ArrayList<BloodSite> list = new ArrayList<>();
|
||||
String whereClause = null;
|
||||
String[] whereArgs = null;
|
||||
if(siteId != -1)
|
||||
{
|
||||
whereClause = "id = ?";
|
||||
whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(siteId);
|
||||
}
|
||||
|
||||
|
||||
List<BloodSite> list = new ArrayList<BloodSite>();
|
||||
|
||||
String whereClause = "latitude < ? and latitude > ? and longitude < ? and longitude > ? ";
|
||||
String[] whereArgs = new String[4];
|
||||
whereArgs[0] = String.valueOf(NE.latitude);
|
||||
whereArgs[1] = String.valueOf(SW.latitude);
|
||||
whereArgs[2] = String.valueOf(NE.longitude);
|
||||
whereArgs[3] = String.valueOf(SW.longitude);
|
||||
|
||||
Calendar dateTime = Calendar.getInstance();
|
||||
dateTime.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
dateTime.set(Calendar.HOUR_OF_DAY, 0);
|
||||
dateTime.set(Calendar.MILLISECOND, 0);
|
||||
dateTime.set(Calendar.MINUTE, 0);
|
||||
dateTime.set(Calendar.SECOND, 0);
|
||||
long dateInMillis = dateTime.getTimeInMillis();
|
||||
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, null);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 0;
|
||||
long dbId = cursor.getLong(col++);
|
||||
|
||||
int ordinal =cursor.getInt(col++);
|
||||
BloodSite site = new BloodSite(Country.values()[ordinal]);
|
||||
site.setDbId(dbId);
|
||||
site.setAddress(cursor.getString(col++));
|
||||
site.setCityName(cursor.getString(col++));
|
||||
site.setDetails(cursor.getString(col++));
|
||||
site.setMail(cursor.getString(col++));
|
||||
site.setPhone(cursor.getString(col++));
|
||||
site.setSiteName(cursor.getString(col++));
|
||||
site.setSiteId(cursor.getLong(col++));
|
||||
long time = cursor.getLong(col++);
|
||||
if(time == -1)
|
||||
site.setDate(null);
|
||||
else
|
||||
{
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
date.setTimeInMillis(time);
|
||||
site.setDate(date);
|
||||
}
|
||||
double lat = cursor.getDouble(col++);
|
||||
double lon = cursor.getDouble(col++);
|
||||
site.setLoc(new LatLng(lat, lon));
|
||||
site.setType(SiteType.values()[cursor.getInt(col)]);
|
||||
list.add(site);
|
||||
}
|
||||
cursor.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
public BloodSite getPastUnregisteredDonation() {
|
||||
|
||||
String whereClause = "schedule = ? and date < ?";
|
||||
String[] whereArgs = new String[2];
|
||||
whereArgs[0] = String.valueOf(1);
|
||||
|
||||
Calendar dateTime = Calendar.getInstance();
|
||||
dateTime.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
dateTime.set(Calendar.HOUR_OF_DAY, 0);
|
||||
dateTime.set(Calendar.MILLISECOND, 0);
|
||||
dateTime.set(Calendar.MINUTE, 0);
|
||||
dateTime.set(Calendar.SECOND, 0);
|
||||
whereArgs[1] = String.valueOf(dateTime.getTimeInMillis());
|
||||
String orderBy = "date ASC";
|
||||
|
||||
BloodSite site = null;
|
||||
|
||||
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, orderBy);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
int col = 0;
|
||||
long dbId = cursor.getLong(col++);
|
||||
|
||||
int ordinal = cursor.getInt(col++);
|
||||
site = new BloodSite(Country.values()[ordinal]);
|
||||
site.setDbId(dbId);
|
||||
site.setAddress(cursor.getString(col++));
|
||||
site.setCityName(cursor.getString(col++));
|
||||
site.setDetails(cursor.getString(col++));
|
||||
site.setMail(cursor.getString(col++));
|
||||
site.setPhone(cursor.getString(col++));
|
||||
site.setSiteName(cursor.getString(col++));
|
||||
site.setSiteId(cursor.getLong(col++));
|
||||
long time = cursor.getLong(col++);
|
||||
if(time == -1)
|
||||
site.setDate(null);
|
||||
else
|
||||
{
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
date.setTimeInMillis(time);
|
||||
site.setDate(date);
|
||||
}
|
||||
double lat = cursor.getDouble(col++);
|
||||
double lon = cursor.getDouble(col++);
|
||||
site.setLoc(new LatLng(lat, lon));
|
||||
site.setType(SiteType.values()[cursor.getInt(col)]);
|
||||
}
|
||||
cursor.close();
|
||||
return site;
|
||||
}
|
||||
|
||||
public List<BloodSite> getNotifications()
|
||||
{
|
||||
Cursor cursor = getWritableDatabase().query("notification",null,null,null,null,null,null);
|
||||
List<Long> oldNotif = new ArrayList<>();
|
||||
List<BloodSite> sites = new ArrayList<>();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 1;
|
||||
Long id = cursor.getLong(col++);
|
||||
int skip = cursor.getInt(col);
|
||||
List<BloodSite> site = getBloodSites(id);
|
||||
//for each siteId found check if date is passed and if it was remove item from the notifications
|
||||
if(site.size() == 1 && cal.compareTo(site.get(0).getDate()) > 0)
|
||||
{
|
||||
oldNotif.add(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(site.size() > 0 && skip == 0)
|
||||
sites.add(site.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
Comparator<BloodSite> compareDate = new Comparator<BloodSite>() {
|
||||
@Override
|
||||
public int compare(BloodSite lhs, BloodSite rhs) {
|
||||
return lhs.getDate().compareTo(rhs.getDate());
|
||||
}
|
||||
};
|
||||
|
||||
removeNotifications(oldNotif);
|
||||
Collections.sort(sites,compareDate);
|
||||
cursor.close();
|
||||
return sites;
|
||||
}
|
||||
|
||||
private void removeNotifications(List<Long> notificationIds)
|
||||
{
|
||||
String args[] = new String[1];
|
||||
String clause = "siteId = ?";
|
||||
for(Long id : notificationIds)
|
||||
{
|
||||
args[0] = String.valueOf(id);
|
||||
getWritableDatabase().delete("notification", clause, args);
|
||||
}
|
||||
}
|
||||
|
||||
public void scheduleDonation(long siteId, boolean scheduling)
|
||||
{
|
||||
String whereClause = "id = ? ";
|
||||
String[] whereArgs = new String[1];
|
||||
whereArgs[0] = String.valueOf(siteId);
|
||||
ContentValues values = new ContentValues();
|
||||
if(scheduling)
|
||||
values.put("schedule", 1);
|
||||
else
|
||||
values.put("schedule", 0);
|
||||
|
||||
|
||||
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, null);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 0;
|
||||
long dbId = cursor.getLong(col++);
|
||||
getWritableDatabase().update("site", values, whereClause, whereArgs);
|
||||
}
|
||||
|
||||
int ordinal =cursor.getInt(col++);
|
||||
BloodSite site = new BloodSite(Country.values()[ordinal]);
|
||||
site.setDbId(dbId);
|
||||
site.setAddress(cursor.getString(col++));
|
||||
site.setCityName(cursor.getString(col++));
|
||||
site.setDetails(cursor.getString(col++));
|
||||
site.setMail(cursor.getString(col++));
|
||||
site.setPhone(cursor.getString(col++));
|
||||
site.setSiteName(cursor.getString(col++));
|
||||
site.setSiteId(cursor.getLong(col++));
|
||||
long time = cursor.getLong(col++);
|
||||
if(time == -1)
|
||||
site.setDate(null);
|
||||
else
|
||||
{
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
date.setTimeInMillis(time);
|
||||
site.setDate(date);
|
||||
}
|
||||
double lat = cursor.getDouble(col++);
|
||||
double lon = cursor.getDouble(col++);
|
||||
site.setLoc(new LatiLng(lat, lon));
|
||||
site.setType(SiteType.values()[cursor.getInt(col++)]);
|
||||
if(site.getDate() == null || site.getDate().getTimeInMillis() >= dateInMillis)
|
||||
list.add(site);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public List<BloodSite> getBloodSites(LatLng NE, LatLng SW) {
|
||||
|
||||
public LatiLng getUserLastLocation() {
|
||||
String[] columns = new String[2];
|
||||
columns[0] = "latitude";
|
||||
columns[1] = "longitude";
|
||||
Cursor cursor = getReadableDatabase().query("user",columns,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
LatiLng loc = new LatiLng(cursor.getDouble(0),cursor.getDouble(1));
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Calendar getLastDonationDate() {
|
||||
// TODO
|
||||
String[] columns = new String[1];
|
||||
columns[0] = "date";
|
||||
String orderBy = "date DESC";
|
||||
Cursor cursor = getReadableDatabase().query("donation", columns, null, null, null, null, orderBy);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(cursor.getLong(0));
|
||||
return cal;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
List<BloodSite> list = new ArrayList<>();
|
||||
|
||||
String whereClause = "latitude < ? and latitude > ? and longitude < ? and longitude > ? ";
|
||||
String[] whereArgs = new String[4];
|
||||
whereArgs[0] = String.valueOf(NE.latitude);
|
||||
whereArgs[1] = String.valueOf(SW.latitude);
|
||||
whereArgs[2] = String.valueOf(NE.longitude);
|
||||
whereArgs[3] = String.valueOf(SW.longitude);
|
||||
|
||||
Calendar dateTime = Calendar.getInstance();
|
||||
dateTime.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
dateTime.set(Calendar.HOUR_OF_DAY, 0);
|
||||
dateTime.set(Calendar.MILLISECOND, 0);
|
||||
dateTime.set(Calendar.MINUTE, 0);
|
||||
dateTime.set(Calendar.SECOND, 0);
|
||||
long dateInMillis = dateTime.getTimeInMillis();
|
||||
|
||||
|
||||
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, null);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 0;
|
||||
long dbId = cursor.getLong(col++);
|
||||
|
||||
int ordinal =cursor.getInt(col++);
|
||||
BloodSite site = new BloodSite(Country.values()[ordinal]);
|
||||
site.setDbId(dbId);
|
||||
site.setAddress(cursor.getString(col++));
|
||||
site.setCityName(cursor.getString(col++));
|
||||
site.setDetails(cursor.getString(col++));
|
||||
site.setMail(cursor.getString(col++));
|
||||
site.setPhone(cursor.getString(col++));
|
||||
site.setSiteName(cursor.getString(col++));
|
||||
site.setSiteId(cursor.getLong(col++));
|
||||
long time = cursor.getLong(col++);
|
||||
if(time == -1)
|
||||
site.setDate(null);
|
||||
else
|
||||
{
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
|
||||
date.setTimeInMillis(time);
|
||||
site.setDate(date);
|
||||
}
|
||||
double lat = cursor.getDouble(col++);
|
||||
double lon = cursor.getDouble(col++);
|
||||
site.setLoc(new LatLng(lat, lon));
|
||||
site.setType(SiteType.values()[cursor.getInt(col)]);
|
||||
if(site.getDate() == null || site.getDate().getTimeInMillis() >= dateInMillis)
|
||||
list.add(site);
|
||||
}
|
||||
cursor.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
public LatLng getUserLastLocation() {
|
||||
String[] columns = new String[2];
|
||||
columns[0] = "latitude";
|
||||
columns[1] = "longitude";
|
||||
Cursor cursor = getReadableDatabase().query("user",columns,null,null,null,null,null);
|
||||
cursor.moveToFirst();
|
||||
LatLng loc = new LatLng(cursor.getDouble(0),cursor.getDouble(1));
|
||||
cursor.close();
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Calendar getLastDonationDate() {
|
||||
String[] columns = new String[1];
|
||||
columns[0] = "date";
|
||||
String orderBy = "date DESC";
|
||||
Cursor cursor = getReadableDatabase().query("donation", columns, null, null, null, null, orderBy);
|
||||
if(cursor.moveToFirst())
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(cursor.getLong(0));
|
||||
return cal;
|
||||
}
|
||||
cursor.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Long> getAllNotifications()
|
||||
{
|
||||
|
||||
List<Long> notifications = new ArrayList<Long>();
|
||||
List<Long> notifications = new ArrayList<>();
|
||||
|
||||
Cursor cursor = getWritableDatabase().query("notification",null,null,null,null,null,null);
|
||||
while(cursor.moveToNext())
|
||||
{
|
||||
int col = 1;
|
||||
Long id = cursor.getLong(col++);
|
||||
Long id = cursor.getLong(col);
|
||||
notifications.add(id);
|
||||
}
|
||||
|
||||
}
|
||||
cursor.close();
|
||||
return notifications;
|
||||
}
|
||||
|
||||
public void addNotifications(List<Long> newNotifications) {
|
||||
public void addNotifications(List<Long> newNotifications) {
|
||||
|
||||
List<Long> ids = getAllNotifications();
|
||||
|
||||
for(Long id : newNotifications)
|
||||
{
|
||||
for(Long id : newNotifications)
|
||||
{
|
||||
if(!ids.contains(id)) {
|
||||
System.out.println("Db add notif "+id);
|
||||
ContentValues values = new ContentValues();
|
||||
|
@ -496,8 +509,8 @@ public class Database extends SQLiteOpenHelper {
|
|||
values.put("skip", 0);
|
||||
getWritableDatabase().insert("notification", null, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void skipNotifications(List<Long> notifications)
|
||||
{
|
||||
|
|
|
@ -20,13 +20,15 @@ import android.net.ConnectivityManager;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.State;
|
||||
import android.util.Log;
|
||||
|
||||
import com.car2go.maps.model.LatLng;
|
||||
|
||||
import fr.mobdev.blooddonation.enums.Country;
|
||||
import fr.mobdev.blooddonation.enums.SiteType;
|
||||
import fr.mobdev.blooddonation.objects.BloodSite;
|
||||
import fr.mobdev.blooddonation.objects.LatiLng;
|
||||
|
||||
public class NetworkManager {
|
||||
|
||||
//TODO Complete rework with thread and message Queue
|
||||
private NetworkListener listener;
|
||||
private static NetworkManager instance;
|
||||
private Context context;
|
||||
|
@ -37,7 +39,7 @@ public class NetworkManager {
|
|||
{
|
||||
this.listener = listener;
|
||||
this.context = context;
|
||||
idList = new ArrayList<Integer>();
|
||||
idList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static NetworkManager getInstance(NetworkListener listener, Context context){
|
||||
|
@ -58,7 +60,7 @@ public class NetworkManager {
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void loadFromNet(final Country ctr,final LatiLng nECorner, final LatiLng sWCorner)
|
||||
public void loadFromNet(final Country ctr, final LatLng nECorner, final LatLng sWCorner)
|
||||
{
|
||||
if(!isConnectedToInternet(context))
|
||||
return;
|
||||
|
@ -81,9 +83,9 @@ public class NetworkManager {
|
|||
}).start();
|
||||
}
|
||||