Browse Source

Big refactoring

Fragment instead of activity
OSM instead of GMaps
Remove old code to replace by newer implementation
Fix warnings
tags/release-v3.0
Schoumi 3 years ago
parent
commit
b0f208823b
55 changed files with 2702 additions and 2463 deletions
  1. +24
    -7
      .gitignore
  2. +0
    -19
      BloodDonation.iml
  3. +0
    -113
      app/app.iml
  4. +15
    -7
      app/build.gradle
  5. +5
    -50
      app/src/main/AndroidManifest.xml
  6. +0
    -25
      app/src/main/java/fr/mobdev/blooddonation/App.java
  7. +459
    -446
      app/src/main/java/fr/mobdev/blooddonation/Database.java
  8. +10
    -8
      app/src/main/java/fr/mobdev/blooddonation/NetworkManager.java
  9. +1
    -1
      app/src/main/java/fr/mobdev/blooddonation/NewDonationListener.java
  10. +0
    -30
      app/src/main/java/fr/mobdev/blooddonation/activity/AboutActivity.java
  11. +0
    -260
      app/src/main/java/fr/mobdev/blooddonation/activity/DonationActivity.java
  12. +0
    -61
      app/src/main/java/fr/mobdev/blooddonation/activity/DonationInfoActivity.java
  13. +486
    -811
      app/src/main/java/fr/mobdev/blooddonation/activity/MainActivity.java
  14. +0
    -104
      app/src/main/java/fr/mobdev/blooddonation/activity/NotificationsActivity.java
  15. +0
    -32
      app/src/main/java/fr/mobdev/blooddonation/activity/PrefsActivity.java
  16. +15
    -17
      app/src/main/java/fr/mobdev/blooddonation/custom_object/DrawerAdapter.java
  17. +2
    -13
      app/src/main/java/fr/mobdev/blooddonation/custom_object/DrawerItem.java
  18. +6
    -6
      app/src/main/java/fr/mobdev/blooddonation/dialog/AddDonationDialog.java
  19. +4
    -13
      app/src/main/java/fr/mobdev/blooddonation/dialog/ConfirmDialog.java
  20. +3
    -3
      app/src/main/java/fr/mobdev/blooddonation/dialog/InformationDialog.java
  21. +15
    -42
      app/src/main/java/fr/mobdev/blooddonation/dialog/PostDonationDialog.java
  22. +62
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/AboutFragment.java
  23. +235
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/DonationFragment.java
  24. +62
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/DonationInfoFragment.java
  25. +146
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/InformationFragment.java
  26. +22
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/LicencesFragment.java
  27. +513
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/MapsFragment.java
  28. +108
    -0
      app/src/main/java/fr/mobdev/blooddonation/fragment/NotificationFragment.java
  29. +22
    -9
      app/src/main/java/fr/mobdev/blooddonation/fragment/PrefFragment.java
  30. +5
    -3
      app/src/main/java/fr/mobdev/blooddonation/objects/BloodSite.java
  31. +0
    -41
      app/src/main/java/fr/mobdev/blooddonation/objects/LatiLng.java
  32. +157
    -155
      app/src/main/java/fr/mobdev/blooddonation/service/AlarmReceiver.java
  33. BIN
      app/src/main/res/drawable/liberapay.png
  34. BIN
      app/src/main/res/drawable/userlocation.png
  35. +36
    -34
      app/src/main/res/layout/about.xml
  36. +35
    -0
      app/src/main/res/layout/licence.xml
  37. +75
    -0
      app/src/main/res/layout/main_activity.xml
  38. +0
    -60
      app/src/main/res/layout/main_activity_google.xml
  39. +41
    -0
      app/src/main/res/layout/map.xml
  40. +5
    -4
      app/src/main/res/layout/post_donation_dialog.xml
  41. +0
    -12
      app/src/main/res/menu/donnation_menu.xml
  42. +0
    -8
      app/src/main/res/menu/init_menu.xml
  43. +55
    -0
      app/src/main/res/menu/main_drawer.xml
  44. +22
    -5
      app/src/main/res/menu/main_menu.xml
  45. +0
    -11
      app/src/main/res/values-v11/styles.xml
  46. +0
    -12
      app/src/main/res/values-v14/styles.xml
  47. +8
    -0
      app/src/main/res/values-v21/styles.xml
  48. +9
    -0
      app/src/main/res/values-v23/styles.xml
  49. +6
    -0
      app/src/main/res/values/colors.xml
  50. +13
    -9
      app/src/main/res/values/strings.xml
  51. +12
    -13
      app/src/main/res/values/styles.xml
  52. +0
    -18
      app/src/main/res/xml/analytics.xml
  53. +2
    -1
      build.gradle
  54. BIN
      gradle/wrapper/gradle-wrapper.jar
  55. +6
    -0
      gradle/wrapper/gradle-wrapper.properties

+ 24
- 7
.gitignore View File

@@ -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/

+ 0
- 19
BloodDonation.iml View File

@@ -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>


+ 0
- 113
app/app.iml View File

@@ -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>


+ 15
- 7
app/build.gradle View File

@@ -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'
}

+ 5
- 50
app/src/main/AndroidManifest.xml View File

@@ -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>

+ 0
- 25
app/src/main/java/fr/mobdev/blooddonation/App.java View File

@@ -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;
}
}

+ 459
- 446
app/src/main/java/fr/mobdev/blooddonation/Database.java View File

@@ -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;

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)
private static Database instance;

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;
}

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)
{
db.execSQL("Alter Table notification Add Column skip INTEGER;");
}

}

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 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())
public void updateUserLoc(double latitude, double longitude)
{
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));
}
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();
}

Comparator<BloodSite> compareDate = new Comparator<BloodSite>() {
@Override
public int compare(BloodSite lhs, BloodSite rhs) {
return lhs.getDate().compareTo(rhs.getDate());
public boolean isFirstTime() {
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
if(cursor.getCount() != 0){
cursor.close();
return false;
}
};

removeNotifications(oldNotif);
Collections.sort(sites,compareDate);

return sites;
}

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 List<BloodSite> getBloodSites(LatiLng NE, LatiLng SW) {


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 LatiLng(lat, lon));
site.setType(SiteType.values()[cursor.getInt(col++)]);
if(site.getDate() == null || site.getDate().getTimeInMillis() >= dateInMillis)
list.add(site);
}
return list;
}

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;
}
cursor.close();
return true;
}

public List<Long> getAllNotifications()
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);
}


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() {

List<Long> notifications = new ArrayList<Long>();
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++);
notifications.add(id);
}
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);


getWritableDatabase().update("site", values, whereClause, whereArgs);
}

public List<BloodSite> getBloodSites(LatLng NE, LatLng SW) {


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<>();

Cursor cursor = getWritableDatabase().query("notification",null,null,null,null,null,null);
while(cursor.moveToNext())
{
int col = 1;
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)
{


+ 10
- 8
app/src/main/java/fr/mobdev/blooddonation/NetworkManager.java View File

@@ -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();
}

public List<BloodSite> loadFrenchData(LatiLng nECorner, LatiLng sWCorner)
private List<BloodSite> loadFrenchData(LatLng nECorner, LatLng sWCorner)
{
List<BloodSite> siteList = new ArrayList<BloodSite>();
List<BloodSite> siteList = new ArrayList<>();
String urlstr = "http://carte.dondusang.com/gmap_regionchanged.php?"
+"nelat="+nECorner.latitude
+"&nelon="+nECorner.longitude
@@ -98,7 +100,7 @@ public class NetworkManager {
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
URLConnection connect = null;
URLConnection connect;
InputStream stream = null;
try {
if(isConnectedToInternet(context))
@@ -245,7 +247,7 @@ public class NetworkManager {
newSite.setSiteId(siteId);
newSite.setDate(date);
newSite.setSiteName(siteName);
newSite.setLoc(new LatiLng(latitude,longitude));
newSite.setLoc(new LatLng(latitude,longitude));
newSite.setType(type);
newSite.setCityName(cityName);
newSite.setPhone(phone);


+ 1
- 1
app/src/main/java/fr/mobdev/blooddonation/NewDonationListener.java View File

@@ -3,5 +3,5 @@ package fr.mobdev.blooddonation;
import java.util.EventListener;

public interface NewDonationListener extends EventListener {
public void needUpdate();
void needUpdate();
}

+ 0
- 30
app/src/main/java/fr/mobdev/blooddonation/activity/AboutActivity.java View File

@@ -1,30 +0,0 @@
package fr.mobdev.blooddonation.activity;

import com.google.android.gms.analytics.GoogleAnalytics;

import fr.mobdev.blooddonation.R;
import android.app.Activity;
import android.os.Bundle;


public class AboutActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
getActionBar().setTitle(R.string.about);
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}

+ 0
- 260
app/src/main/java/fr/mobdev/blooddonation/activity/DonationActivity.java View File

@@ -1,260 +0,0 @@
package fr.mobdev.blooddonation.activity;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

import com.google.android.gms.analytics.GoogleAnalytics;

import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.NewDonationListener;
import fr.mobdev.blooddonation.R;
import fr.mobdev.blooddonation.SelectionModeListener;
import fr.mobdev.blooddonation.custom_object.DrawerAdapter;
import fr.mobdev.blooddonation.custom_object.DrawerItem;
import fr.mobdev.blooddonation.dialog.AddDonationDialog;
import fr.mobdev.blooddonation.enums.DrawerItemType;
import fr.mobdev.blooddonation.objects.Donation;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemLongClickListener;

public class DonationActivity extends FragmentActivity {
ListView donation_list;
List<Donation> donations;
SelectionModeListener listener;
boolean isOnSelection;
List<DrawerItem> items;
MenuItem del_item;
Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.donation);
donation_list = (ListView) findViewById(R.id.donation_list);
items = new ArrayList<DrawerItem>();
isOnSelection = false;
context = this;
listener = new SelectionModeListener() {
@Override
public void selectionModeChange(View v) {
isOnSelection = !isOnSelection;
if(isOnSelection)
{
for(DrawerItem item:items)
{
item.setType(DrawerItemType.STATE_CHECK);
}
selectView(v);
del_item.setVisible(true);
DrawerAdapter adapter = new DrawerAdapter(context,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
else
{
for(DrawerItem item:items)
{
item.setType(DrawerItemType.STATE_NORMAL);
item.setSelected(false);
}
del_item.setVisible(false);
DrawerAdapter adapter = new DrawerAdapter(context,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
}
};
donation_list.setOnItemLongClickListener(new OnItemLongClickListener() {

@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int pos, long id) {
if(!isOnSelection)
{
listener.selectionModeChange(v);
}
else
{
selectView(v);
}
return true;
}
});
donation_list.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View v, int arg2, long id) {
selectView(v);
}
});
updateDonationList();
getActionBar().setTitle(R.string.donations);
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
private void selectView(View v)
{
if(isOnSelection)
{
TextView view = (TextView) v.findViewById(R.id.pos);
long donationId = Integer.valueOf((String) view.getText());
for(DrawerItem item:items)
{
item.setType(DrawerItemType.STATE_CHECK);
if(item.getPos() == donationId)
{
item.setSelected(!item.isSelected());
}
}
DrawerAdapter adapter = new DrawerAdapter(context,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.donnation_menu, menu);
del_item = menu.findItem(R.id.action_del);
del_item.setVisible(false);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add:
addDonation();
return true;
case R.id.action_del:
askRemoveDonation();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onBackPressed(){
if(isOnSelection)
{
listener.selectionModeChange(null);
}
else
{
finish();
}
}
private void addDonation()
{
AddDonationDialog dialog = new AddDonationDialog();
Bundle bundle = new Bundle();
bundle.putInt("siteId", -1);
dialog.setArguments(bundle);
dialog.setListener(new NewDonationListener() {
@Override
public void needUpdate() {
updateDonationList();
}
});
dialog.show(getSupportFragmentManager(), "add donation dialog");
}
private void askRemoveDonation()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.delete_donation_message)
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
removeSelectedDonation();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void removeSelectedDonation()
{
List<Donation> deletedList = new ArrayList<Donation>();
for(int i = 0; i<items.size(); i++)
{
DrawerItem item = items.get(i);
if(item.isSelected())
{
deletedList.add(donations.get(i));
}
}
Database.getInstance(this).deleteDonation(deletedList);
updateDonationList();
}
private void updateDonationList()
{
donations = Database.getInstance(this).getDonations();
items.clear();
for(Donation don : donations)
{
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
String texte = df.format(don.getDate().getTime());
texte += " - ";
texte += don.getCityName();
if(don.getCityName().length() > 0)
texte += " - ";
switch(don.getDonationType())
{
case TOTAL_BLOOD:
texte += getResources().getStringArray(R.array.donation_type)[0];
break;
case PLASMA:
texte += getResources().getStringArray(R.array.donation_type)[1];
break;
case PLATELET:
texte += getResources().getStringArray(R.array.donation_type)[2];
break;
default:
//do nothing
break;
}
DrawerItem item = new DrawerItem(DrawerItemType.STATE_NORMAL, texte, null);
items.add(item);
}
DrawerAdapter adapter = new DrawerAdapter(this,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
}

+ 0
- 61
app/src/main/java/fr/mobdev/blooddonation/activity/DonationInfoActivity.java View File

@@ -1,61 +0,0 @@
package fr.mobdev.blooddonation.activity;

import java.util.HashMap;

import com.google.android.gms.analytics.GoogleAnalytics;

import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class DonationInfoActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.donation_info);
HashMap<String, Object> maps = Database.getInstance(this).getUserInformation();
String userName = (String) maps.get("UserName");
String blood = (String) maps.get("BloodGroup");
String city = (String) maps.get("CityName");
int D = (Integer) maps.get("D");
int C = (Integer) maps.get("C");
int E = (Integer) maps.get("E");
int c = (Integer) maps.get("c");
int e = (Integer) maps.get("e");
int K = (Integer) maps.get("K");
TextView view = (TextView) findViewById(R.id.user_name);
view.setText(userName);
view = (TextView) findViewById(R.id.blood_group);
view.setText(blood);
view = (TextView) findViewById(R.id.city_name);
view.setText(city);
view = (TextView) findViewById(R.id.rhesus);
String rhesus = "D" + getStringFor(D) +" C" + getStringFor(C) +" E"+ getStringFor(E) +" c"+ getStringFor(c) +" e" + getStringFor(e) + " K"+getStringFor(K);
view.setText(rhesus);
getActionBar().setTitle(R.string.donation_info);
}
private String getStringFor(int plus)
{
if(plus == 0)
return "-";
else
return "+";
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}

+ 486
- 811
app/src/main/java/fr/mobdev/blooddonation/activity/MainActivity.java
File diff suppressed because it is too large
View File


+ 0
- 104
app/src/main/java/fr/mobdev/blooddonation/activity/NotificationsActivity.java View File

@@ -1,104 +0,0 @@
package fr.mobdev.blooddonation.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.R;
import fr.mobdev.blooddonation.dialog.InformationDialog;
import fr.mobdev.blooddonation.objects.BloodSite;

public class NotificationsActivity extends FragmentActivity implements AdapterView.OnItemClickListener {

private List<Long> notificationsIds;
private List<Long> readedNotifications;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notifications);

notificationsIds = new ArrayList<Long>();
readedNotifications = new ArrayList<Long>();
buildListView();
ListView view = (ListView) findViewById(R.id.notifications_list);
view.setOnItemClickListener(this);

}

@Override
protected void onDestroy()
{
Database.getInstance(getApplicationContext()).skipNotifications(readedNotifications);
super.onDestroy();
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position != notificationsIds.size()) {
long siteId = notificationsIds.get(position);
Bundle args = new Bundle();
args.putLong("siteId", siteId);
InformationDialog dialog = new InformationDialog();
dialog.setArguments(args);
dialog.show(getSupportFragmentManager(), "information dialog");
notificationsIds.remove(id);
readedNotifications.add(siteId);
}
else
{
readedNotifications.addAll(notificationsIds);
Database.getInstance(getApplicationContext()).skipNotifications(readedNotifications);
buildListView();
}
/*List<Long> notificationsToRemove = new ArrayList<Long>();
notificationsToRemove.add(siteId);
Database.getInstance(getApplicationContext()).removeNotifications(notificationsToRemove);*/
//buildListView();
}

private void buildListView()
{
notificationsIds.clear();
ListView view = (ListView) findViewById(R.id.notifications_list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.simple_list_item);
Comparator<BloodSite> compareDate = new Comparator<BloodSite>() {
@Override
public int compare(BloodSite lhs, BloodSite rhs) {
return lhs.getDate().compareTo(rhs.getDate());
}
};

List<BloodSite> notifications = Database.getInstance(getApplicationContext()).getNotifications();
Collections.sort(notifications, compareDate);

for(BloodSite site : notifications)
{

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
String date = df.format(site.getDate().getTime());
String notif = date + " - " + site.getCityName();
adapter.add(notif);

notificationsIds.add(site.getDbId());
}
if(notifications.size() > 1)
adapter.add(getString(R.string.clear));
else
adapter.add(getString(R.string.no_notif));
view.setAdapter(adapter);
}
}

+ 0
- 32
app/src/main/java/fr/mobdev/blooddonation/activity/PrefsActivity.java View File

@@ -1,32 +0,0 @@
package fr.mobdev.blooddonation.activity;

import com.google.android.gms.analytics.GoogleAnalytics;

import fr.mobdev.blooddonation.PrefFragment;
import fr.mobdev.blooddonation.R;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class PrefsActivity extends FragmentActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new PrefFragment())
.commit();
getActionBar().setTitle(R.string.preference);
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}

+ 15
- 17
app/src/main/java/fr/mobdev/blooddonation/custom_object/DrawerAdapter.java View File

@@ -5,6 +5,7 @@ import java.util.List;
import fr.mobdev.blooddonation.R;
import fr.mobdev.blooddonation.enums.DrawerItemType;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -23,26 +24,25 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
items = objects;
}

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ViewHolder holder;
DrawerItem item = items.get(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.drawer_item, parent, false);
}
holder = new ViewHolder();
holder.pos = (TextView) convertView.findViewById(R.id.pos);
holder.title = (TextView) convertView.findViewById(R.id.title);
holder.separator = (TextView) convertView.findViewById(R.id.separator);
holder.checkbox = (CheckedTextView) convertView.findViewById(R.id.checkbox);
holder.radio = (CheckedTextView) convertView.findViewById(R.id.radio);
holder.pos = convertView.findViewById(R.id.pos);
holder.title = convertView.findViewById(R.id.title);
holder.separator = convertView.findViewById(R.id.separator);
holder.checkbox = convertView.findViewById(R.id.checkbox);
holder.radio = convertView.findViewById(R.id.radio);
holder.pos.setText(String.valueOf(item.getPos()));
if (item.getType() == DrawerItemType.STATE_NORMAL)
{
holder.title.setVisibility(View.VISIBLE);
holder.title.setText(item.getTitle());
if(item.getOnClickListener() != null)
holder.title.setOnClickListener(item.getOnClickListener());
holder.separator.setVisibility(View.GONE);
holder.checkbox.setVisibility(View.GONE);
holder.radio.setVisibility(View.GONE);
@@ -51,8 +51,6 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
{
holder.separator.setVisibility(View.VISIBLE);
holder.separator.setText(item.getTitle());
if(item.getOnClickListener() != null)
holder.separator.setOnClickListener(item.getOnClickListener());
holder.title.setVisibility(View.GONE);
holder.checkbox.setVisibility(View.GONE);
holder.radio.setVisibility(View.GONE);
@@ -62,8 +60,6 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
holder.checkbox.setVisibility(View.VISIBLE);
holder.checkbox.setText(item.getTitle());
holder.checkbox.setChecked(item.isSelected());
if(item.getOnClickListener() != null)
holder.checkbox.setOnClickListener(item.getOnClickListener());
holder.separator.setVisibility(View.GONE);
holder.title.setVisibility(View.GONE);
@@ -74,8 +70,6 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
holder.radio.setVisibility(View.VISIBLE);
holder.radio.setText(item.getTitle());
holder.radio.setChecked(item.isSelected());
if(item.getOnClickListener() != null)
holder.radio.setOnClickListener(item.getOnClickListener());
holder.separator.setVisibility(View.GONE);
holder.checkbox.setVisibility(View.GONE);
holder.title.setVisibility(View.GONE);
@@ -101,13 +95,17 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
}
@Override
public int getItemViewType(int position) {
return getItem(position).getType().equals(DrawerItemType.STATE_SECTION) ? 0 : 1;
public int getItemViewType(int position) {
DrawerItem item = getItem(position);
assert item != null;
return item.getType().equals(DrawerItemType.STATE_SECTION) ? 0 : 1;
}
@Override
public boolean isEnabled(int position) {
return !getItem(position).getType().equals(DrawerItemType.STATE_SECTION);
DrawerItem item = getItem(position);
assert item != null;
return !item.getType().equals(DrawerItemType.STATE_SECTION);
}
}


+ 2
- 13
app/src/main/java/fr/mobdev/blooddonation/custom_object/DrawerItem.java View File

@@ -1,26 +1,23 @@
package fr.mobdev.blooddonation.custom_object;

import fr.mobdev.blooddonation.enums.DrawerItemType;
import android.view.View.OnClickListener;

public class DrawerItem {
private DrawerItemType type;
private String title;
private OnClickListener listener;
private boolean selected;
private static int pos = 0;
private int id;
public DrawerItem(DrawerItemType type, String title, OnClickListener onClickListener)
public DrawerItem(DrawerItemType type, String title)
{
this.type = type;
this.title = title;
this.listener = onClickListener;
this.selected = false;
id = pos++;
}
public DrawerItemType getType() {
DrawerItemType getType() {
return type;
}
public void setType(DrawerItemType type) {
@@ -33,14 +30,6 @@ public class DrawerItem {
this.title = title;
}
public void setOnClicListener(OnClickListener listerner){
this.listener = listerner;
}
public OnClickListener getOnClickListener(){
return listener;
}
public boolean isSelected() {
return selected;
}


+ 6
- 6
app/src/main/java/fr/mobdev/blooddonation/dialog/AddDonationDialog.java View File

@@ -18,7 +18,7 @@ import android.widget.EditText;
import android.widget.Spinner;

@SuppressLint("InflateParams")
public class AddDonationDialog extends android.support.v4.app.DialogFragment {
public class AddDonationDialog extends android.app.DialogFragment {

private int siteId;
private NewDonationListener listener;
@@ -35,16 +35,16 @@ public class AddDonationDialog extends android.support.v4.app.DialogFragment {

LayoutInflater inflater = getActivity().getLayoutInflater();
<