Meilleurs gestion des notifications + ajout du centre de notification

This commit is contained in:
Schoumi 2015-04-16 18:07:16 +02:00
parent 51dcba8f1a
commit c524297eaa
15 changed files with 240 additions and 58 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ build/*
gradle/*
gradlew*
import-summary.txt
*.apk

View File

@ -8,8 +8,6 @@
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />

View File

@ -85,9 +85,29 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="play-services-6.5.87" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<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>

View File

@ -18,5 +18,5 @@ android {
dependencies {
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.0'
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.mobdev.blooddonation"
android:versionCode="4"
android:versionName="1.0" >
android:versionCode="5"
android:versionName="2.0" >
<uses-sdk
android:minSdkVersion="11"
@ -90,10 +90,8 @@
<activity
android:name=".activity.NotificationsActivity"
android:label="@string/title_activity_notifications"
android:parentActivityName=".activity.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="fr.mobdev.blooddonation.activity.MainActivity" />
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="portrait">
</activity>
</application>

View File

@ -2,6 +2,8 @@ package fr.mobdev.blooddonation;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.TimeZone;
@ -26,7 +28,7 @@ public class Database extends SQLiteOpenHelper {
public static Database getInstance(Context context)
{
if(instance == null)
instance = new Database(context, "BloodDonation.db", null, 2);
instance = new Database(context, "BloodDonation.db", null, 3);
return instance;
}
@ -47,7 +49,7 @@ public class Database extends SQLiteOpenHelper {
"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 " +
"id integer primary key autoincrement, siteId INTEGER, skip INTEGER " +
");");
@ -63,6 +65,10 @@ public class Database extends SQLiteOpenHelper {
"id integer primary key autoincrement, siteId INTEGER " +
");");
}
else if(oldVersion == 2 && newVersion == 3)
{
db.execSQL("Alter Table notification Add Column skip INTEGER;");
}
}
@ -327,7 +333,9 @@ public class Database extends SQLiteOpenHelper {
Calendar cal = Calendar.getInstance();
while(cursor.moveToNext())
{
Long id = cursor.getLong(1);
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)
@ -336,12 +344,20 @@ public class Database extends SQLiteOpenHelper {
}
else
{
if(site.size() > 0)
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);
return sites;
}
@ -349,7 +365,7 @@ public class Database extends SQLiteOpenHelper {
public void removeNotifications(List<Long> notificationIds)
{
String args[] = new String[1];
String clause = "id = ?";
String clause = "siteId = ?";
for(Long id : notificationIds)
{
args[0] = String.valueOf(id);
@ -357,7 +373,7 @@ public class Database extends SQLiteOpenHelper {
}
}
public void sheduleDonation(long siteId, boolean scheduling)
public void scheduleDonation(long siteId, boolean scheduling)
{
String whereClause = "id = ? ";
String[] whereArgs = new String[1];
@ -454,13 +470,49 @@ public class Database extends SQLiteOpenHelper {
return null;
}
public List<Long> getAllNotifications()
{
List<Long> notifications = new ArrayList<Long>();
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);
}
return notifications;
}
public void addNotifications(List<Long> newNotifications) {
List<Long> ids = getAllNotifications();
for(Long id : newNotifications)
{
ContentValues values = new ContentValues();
values.put("siteId", id);
getWritableDatabase().insert("notification", null, values);
if(!ids.contains(id)) {
System.out.println("Db add notif "+id);
ContentValues values = new ContentValues();
values.put("siteId", id);
values.put("skip", 0);
getWritableDatabase().insert("notification", null, values);
}
}
}
public void skipNotifications(List<Long> notifications)
{
String whereClause = "siteId = ? ";
String[] whereArgs = new String[1];
for(Long id : notifications)
{
whereArgs[0] = String.valueOf(id);
ContentValues values = new ContentValues();
values.put("skip",1);
getWritableDatabase().update("notification",values,whereClause,whereArgs);
}
}
}

View File

@ -63,9 +63,9 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -81,13 +81,12 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
@SuppressLint({ "UseSparseArrays", "InflateParams" })
public class MainActivity extends FragmentActivity implements LocationSource {
public class MainActivity extends FragmentActivity implements LocationSource{
private GoogleMap map;
private enum CORNER {
private enum CORNER {
TOP_LEFT, TOP_RIGHT, BOT_LEFT, BOT_RIGHT
};
@ -339,6 +338,7 @@ public class MainActivity extends FragmentActivity implements LocationSource {
adView.loadAd(adRequest);
country = Country.FRANCE;
countryMap = new HashMap<Country, LatLng>();
markerList = new HashMap<Long, Marker>();
@ -394,8 +394,7 @@ public class MainActivity extends FragmentActivity implements LocationSource {
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
R.drawable.ic_drawer
) {
/** Called when a drawer has settled in a completely closed state. */
@ -540,16 +539,17 @@ public class MainActivity extends FragmentActivity implements LocationSource {
{
final int MENU_ITEM = Menu.FIRST;
final int SHOW_ALL = MENU_ITEM + 3;
PopupMenu menu = new PopupMenu(MainActivity.this,v);
final PopupMenu menu = new PopupMenu(MainActivity.this,v);
int i = 0;
List<BloodSite> sites = Database.getInstance(getApplicationContext()).getNotifications();
notifications.clear();
for(BloodSite site : sites)
{
if(i == 3)
break;
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
String date = df.format(site.getDate().getTime());
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();
menu.getMenu().add(0,MENU_ITEM + i, Menu.NONE,notif);
notifications.add(site.getDbId());
@ -576,7 +576,17 @@ public class MainActivity extends FragmentActivity implements LocationSource {
InformationDialog dialog = new InformationDialog();
dialog.setArguments(args);
dialog.show(getSupportFragmentManager(), "information dialog");
notifications.remove(id);
List<Long> notificationsToRemove = new ArrayList<Long>();
notificationsToRemove.add(siteId);
Database.getInstance(getApplicationContext()).skipNotifications(notificationsToRemove);
menu.getMenu().removeItem(id);
}
else
{
Intent newIntent = new Intent(MainActivity.this, NotificationsActivity.class);
startActivity(newIntent);
}
}
return true;
}

View File

@ -2,16 +2,103 @@ package fr.mobdev.blooddonation.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
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 Activity {
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);
}
}

View File

@ -91,7 +91,7 @@ public class ConfirmDialog extends android.support.v4.app.DialogFragment {
Calendar date = site.getDate();
Donation donation = new Donation(type,date,siteId,-1,site.getCityName());
Database.getInstance(getActivity()).addDonation(donation);
Database.getInstance(getActivity()).sheduleDonation(siteId, false);
Database.getInstance(getActivity()).scheduleDonation(siteId, false);
if(donationListener != null)
donationListener.needUpdate();
if(registerListener != null)
@ -100,7 +100,7 @@ public class ConfirmDialog extends android.support.v4.app.DialogFragment {
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Database.getInstance(getActivity()).sheduleDonation(siteId, false);
Database.getInstance(getActivity()).scheduleDonation(siteId, false);
if(registerListener != null)
registerListener.processNewRegistration();
dialog.cancel();

View File

@ -99,7 +99,7 @@ public class InformationDialog extends DialogFragment {
final int endHour = Integer.valueOf(end.substring(0,2)) * 1000 * 60 *60 + Integer.valueOf(end.substring(3,5))*1000*60;
intent.putExtra("beginTime", site.getDate().getTimeInMillis()+beginHour);
intent.putExtra("endTime", site.getDate().getTimeInMillis()+endHour);
Database.getInstance(getActivity()).sheduleDonation(siteId, true);
Database.getInstance(getActivity()).scheduleDonation(siteId, true);
}
intent.putExtra("allDay", false);

View File

@ -163,15 +163,14 @@ public class AlarmReceiver extends BroadcastReceiver {
List<BloodSite> sites = Database.getInstance(context).getBloodSites(-1);
checkForProximity(sites, context);
checkForDate(sites, context);
List<BloodSite> notifications = Database.getInstance(context).getNotifications();
List<Long> notifications = Database.getInstance(context).getAllNotifications();
List<Long> newNotifications = new ArrayList<Long>();
for(BloodSite site : sites)
{
if(!notifications.contains(site))
{
newNotifications.add(site.getDbId());
}
}
newNotifications.removeAll(notifications);
Database.getInstance(context).addNotifications(newNotifications);
notifyUser(context,newNotifications);
}

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivityNokia" >
tools:context=".MainActivity">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/mainview_layout"
@ -21,11 +21,12 @@
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
android:paddingTop="@dimen/activity_vertical_margin">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
@ -37,9 +38,9 @@
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/adView"
android:layout_alignParentTop="true"
android:tag="Test"/>
android:layout_above="@+id/adView"
android:layout_alignParentTop="true"
android:tag="Test" />
</RelativeLayout>
</FrameLayout>
<!-- The navigation drawer -->
@ -49,11 +50,11 @@
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFFFF"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFFFFFFF"/>
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>

View File

@ -1,9 +1,15 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="fr.mobdev.blooddonation.activity.NotificationsActivity">
tools:context=".NotificationsActivity">
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/notifications_list" />
</LinearLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="48dp"
android:singleLine="true"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical"
/>

View File

@ -80,6 +80,7 @@
<string name="action_notif">Centre de Notification</string>
<string name="show_all">Voir tout</string>
<string name="no_notif">Pas de Notifications</string>
<string name="clear">Supprimer tout</string>
<string-array name="gender_array">
<item>Homme</item>