Prepare per toot #274

This commit is contained in:
tom79 2019-08-27 11:43:20 +02:00
parent 3f6ab087b1
commit 4a763abccc
3 changed files with 22 additions and 13 deletions

View File

@ -494,7 +494,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
chart.setVisibility(View.GONE);
loader.setVisibility(View.VISIBLE);
validate.setEnabled(false);
new RetrieveNotificationChartsAsyncTask(OwnerNotificationChartsActivity.this, dateIni, dateEnd, OwnerNotificationChartsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveNotificationChartsAsyncTask(OwnerNotificationChartsActivity.this, null, dateIni, dateEnd, OwnerNotificationChartsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

View File

@ -40,12 +40,14 @@ public class RetrieveNotificationChartsAsyncTask extends AsyncTask<Void, Void, V
private NotificationCharts charts;
private Date dateIni;
private Date dateEnd;
private String status_id;
public RetrieveNotificationChartsAsyncTask(Context context, Date dateIni, Date dateEnd, OnRetrieveNotificationChartsInterface onRetrieveNotificationChartsInterface){
public RetrieveNotificationChartsAsyncTask(Context context, String status_id, Date dateIni, Date dateEnd, OnRetrieveNotificationChartsInterface onRetrieveNotificationChartsInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onRetrieveNotificationChartsInterface;
this.dateIni = dateIni;
this.dateEnd = dateEnd;
this.status_id = status_id;
}
@ -53,7 +55,7 @@ public class RetrieveNotificationChartsAsyncTask extends AsyncTask<Void, Void, V
protected Void doInBackground(Void... params) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
charts = new NotificationCacheDAO(contextReference.get(), db).getChartsEvolution(dateIni, dateEnd);
charts = new NotificationCacheDAO(contextReference.get(), db).getChartsEvolution(status_id, dateIni, dateEnd);
return null;
}

View File

@ -560,23 +560,27 @@ public class NotificationCacheDAO {
}
public NotificationCharts getChartsEvolution(Date dateIni, Date dateEnd){
public NotificationCharts getChartsEvolution(String status_id, Date dateIni, Date dateEnd){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
NotificationCharts charts = new NotificationCharts();
Calendar start = Calendar.getInstance();
start.setTime(dateIni);
start.set(Calendar.HOUR_OF_DAY,0);
start.set(Calendar.MINUTE,0);
start.set(Calendar.SECOND,0);
Calendar end = Calendar.getInstance();
end.setTime(dateEnd);
end.set(Calendar.HOUR_OF_DAY,23);
end.set(Calendar.MINUTE,59);
end.set(Calendar.SECOND,59);
if( status_id == null) {
start.setTime(dateIni);
start.set(Calendar.HOUR_OF_DAY,0);
start.set(Calendar.MINUTE,0);
start.set(Calendar.SECOND,0);
end.setTime(dateEnd);
end.set(Calendar.HOUR_OF_DAY, 23);
end.set(Calendar.MINUTE, 59);
end.set(Calendar.SECOND, 59);
}else{
}
long msDiff = end.getTimeInMillis() - start.getTimeInMillis();
long daysDiff = TimeUnit.MILLISECONDS.toDays(msDiff);
@ -597,6 +601,9 @@ public class NotificationCacheDAO {
StringBuilder selection = new StringBuilder(Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(Helper.dateToString(smallestDate)).append("'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(Helper.dateToString(start.getTime())).append("'");
if( status_id != null ){
selection.append(" AND " + Sqlite.COL_STATUS_ID + " = '").append(status_id).append("'");
}
try {
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "