Statistics per toot #274

This commit is contained in:
tom79 2019-08-27 18:22:34 +02:00
parent 4a763abccc
commit 8af6d9de07
8 changed files with 329 additions and 155 deletions

View File

@ -67,12 +67,15 @@ import app.fedilab.android.R;
import app.fedilab.android.asynctasks.RetrieveNotificationChartsAsyncTask;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.NotificationCharts;
import app.fedilab.android.client.Entities.Status;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnRetrieveNotificationChartsInterface;
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.NotificationCacheDAO;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.StatusCacheDAO;
import static app.fedilab.android.sqlite.StatusCacheDAO.NOTIFICATION_CACHE;
/**
@ -90,6 +93,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
private int theme;
private RelativeLayout loader;
private ImageButton validate;
private String status_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -110,6 +114,10 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
default:
setTheme(R.style.AppThemeDark);
}
Bundle b = getIntent().getExtras();
status_id = null;
if(b != null)
status_id = b.getString("status_id");
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
@ -156,10 +164,22 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
settings_time_to = findViewById(R.id.settings_time_to);
loader = findViewById(R.id.loader);
validate = findViewById(R.id.validate);
LinearLayout date_container = findViewById(R.id.date_container);
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationChartsActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
dateIni = new NotificationCacheDAO(OwnerNotificationChartsActivity.this, db).getSmallerDate();
dateEnd = new NotificationCacheDAO(OwnerNotificationChartsActivity.this, db).getGreaterDate();
if( status_id == null) {
dateIni = new NotificationCacheDAO(OwnerNotificationChartsActivity.this, db).getSmallerDate();
dateEnd = new NotificationCacheDAO(OwnerNotificationChartsActivity.this, db).getGreaterDate();
}else{
Status status = new StatusCacheDAO(getApplicationContext(), db).getStatus(status_id);
if( status == null){
finish();
return;
}else{
dateIni = status.getCreated_at();
dateEnd = dateIni;
date_container.setVisibility(View.GONE);
}
}
int style;
@ -171,7 +191,9 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
style = R.style.Dialog;
}
Calendar c = Calendar.getInstance();
c.setTime(dateIni);
if(dateIni != null) {
c.setTime(dateIni);
}
int yearIni = c.get(Calendar.YEAR);
int monthIni = c.get(Calendar.MONTH);
int dayIni = c.get(Calendar.DAY_OF_MONTH);
@ -185,51 +207,51 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
}
});
if( dateIni != null) {
Calendar ce = Calendar.getInstance();
c.setTime(dateEnd);
int yearEnd = ce.get(Calendar.YEAR);
int monthEnd = ce.get(Calendar.MONTH);
int dayEnd = ce.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog dateEndPickerDialog = new DatePickerDialog(
OwnerNotificationChartsActivity.this, style, endDateSetListener, yearEnd, monthEnd, dayEnd);
settings_time_to.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dateEndPickerDialog.show();
}
});
Calendar ce = Calendar.getInstance();
c.setTime(dateEnd);
int yearEnd = ce.get(Calendar.YEAR);
int monthEnd = ce.get(Calendar.MONTH);
int dayEnd = ce.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog dateEndPickerDialog = new DatePickerDialog(
OwnerNotificationChartsActivity.this, style, endDateSetListener, yearEnd, monthEnd, dayEnd);
settings_time_to.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dateEndPickerDialog.show();
dateIniPickerDialog.getDatePicker().setMinDate(dateIni.getTime());
dateIniPickerDialog.getDatePicker().setMaxDate(dateEnd.getTime());
dateEndPickerDialog.getDatePicker().setMinDate(dateIni.getTime());
dateEndPickerDialog.getDatePicker().setMaxDate(dateEnd.getTime());
Calendar cal = Calendar.getInstance();
cal.setTime(dateEnd);
cal.add(Calendar.MONTH, -1);
Date result = cal.getTime();
if (result.after(dateIni))
dateIni = result;
if (dateIni == null) {
dateIni = new Date();
}
if (dateEnd == null) {
dateEnd = new Date();
}
});
dateIniPickerDialog.getDatePicker().setMinDate(dateIni.getTime());
dateIniPickerDialog.getDatePicker().setMaxDate(dateEnd.getTime());
dateEndPickerDialog.getDatePicker().setMinDate(dateIni.getTime());
dateEndPickerDialog.getDatePicker().setMaxDate(dateEnd.getTime());
Calendar cal = Calendar.getInstance();
cal.setTime(dateEnd);
cal.add(Calendar.MONTH, -1);
Date result = cal.getTime();
if (result.after(dateIni))
dateIni = result;
if (dateIni == null) {
dateIni = new Date();
}
if (dateEnd == null) {
dateEnd = new Date();
}
CustomMarkerView mv = new CustomMarkerView(getApplicationContext(), R.layout.markerview);
chart.setMarkerView(mv);
CustomMarkerView mv = new CustomMarkerView(getApplicationContext(), R.layout.markerview);
chart.setMarkerView(mv);
validate.setOnClickListener(v -> {
loadGraph(dateIni, dateEnd);
});
validate.setOnClickListener(v->{
loadGraph(dateIni, dateEnd);
});
loadGraph(dateIni, dateEnd);
}
}
@ -272,13 +294,13 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
it.remove();
}
List<Entry> pollEntry = new ArrayList<>();
/*List<Entry> pollEntry = new ArrayList<>();
it = charts.getFollows().entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
pollEntry.add(new Entry((long)pair.getKey(), (int)pair.getValue()));
it.remove();
}
}*/
@ -292,7 +314,11 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetBoosts.setDrawCircles(false);
dataSetBoosts.setDrawCircleHole(false);
dataSetBoosts.setLineWidth(2f);
dataSetBoosts.setMode(LineDataSet.Mode.CUBIC_BEZIER);
if( status_id == null) {
dataSetBoosts.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
dataSetBoosts.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
LineDataSet dateSetFavorites = new LineDataSet(favEntry, getString(R.string.favourite));
dateSetFavorites.setColor(ContextCompat.getColor(OwnerNotificationChartsActivity.this, R.color.chart_notif_fav));
@ -304,7 +330,11 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dateSetFavorites.setDrawCircles(false);
dateSetFavorites.setDrawCircleHole(false);
dateSetFavorites.setLineWidth(2f);
dateSetFavorites.setMode(LineDataSet.Mode.CUBIC_BEZIER);
if( status_id == null) {
dateSetFavorites.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
dateSetFavorites.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
LineDataSet dataSetMention = new LineDataSet(mentionEntry, getString(R.string.mention));
dataSetMention.setColor(ContextCompat.getColor(OwnerNotificationChartsActivity.this, R.color.chart_notif_mention));
@ -316,7 +346,11 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetMention.setDrawCircles(false);
dataSetMention.setDrawCircleHole(false);
dataSetMention.setLineWidth(2f);
dataSetMention.setMode(LineDataSet.Mode.CUBIC_BEZIER);
if( status_id == null) {
dataSetMention.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
dataSetMention.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
LineDataSet dataSetFollow = new LineDataSet(followEntry, getString(R.string.follow));
@ -329,7 +363,11 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetFollow.setDrawCircles(false);
dataSetFollow.setDrawCircleHole(false);
dataSetFollow.setLineWidth(2f);
dataSetFollow.setMode(LineDataSet.Mode.CUBIC_BEZIER);
if( status_id == null) {
dataSetFollow.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}else{
dataSetFollow.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
}
@ -343,7 +381,9 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
dataSetPolls.setDrawCircles(false);
dataSetPolls.setDrawCircleHole(false);
dataSetPolls.setLineWidth(2f);
dataSetPolls.setMode(LineDataSet.Mode.CUBIC_BEZIER);*/
if( status_id == null) {
dataSetPolls.setMode(LineDataSet.Mode.CUBIC_BEZIER);
}*/
List<ILineDataSet> dataSets = new ArrayList<>();
@ -494,7 +534,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
chart.setVisibility(View.GONE);
loader.setVisibility(View.VISIBLE);
validate.setEnabled(false);
new RetrieveNotificationChartsAsyncTask(OwnerNotificationChartsActivity.this, null, dateIni, dateEnd, OwnerNotificationChartsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new RetrieveNotificationChartsAsyncTask(OwnerNotificationChartsActivity.this, status_id, dateIni, dateEnd, OwnerNotificationChartsActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -510,7 +550,11 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
private Date mDate;
MyXAxisValueFormatter() {
this.mDataFormat = new SimpleDateFormat("dd.MM", Locale.getDefault());
if( status_id == null) {
this.mDataFormat = new SimpleDateFormat("dd.MM", Locale.getDefault());
}else{
this.mDataFormat = new SimpleDateFormat("hh'h'", Locale.getDefault());
}
this.mDate = new Date();
}
@Override

View File

@ -72,6 +72,7 @@ import java.util.TimerTask;
import app.fedilab.android.activities.AccountReportActivity;
import app.fedilab.android.activities.BaseMainActivity;
import app.fedilab.android.activities.OwnerNotificationChartsActivity;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
@ -890,7 +891,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
public void onClick(View v) {
PopupMenu popup = new PopupMenu(context, attached);
assert status != null;
final boolean isOwner = status.getAccount().getId().equals(userId);
final boolean isOwner = status.getReblog()!=null?status.getReblog().getAccount().getId().equals(userId):status.getAccount().getId().equals(userId);
popup.getMenuInflater()
.inflate(R.menu.option_toot, popup.getMenu());
if( notification.getType().equals("mention"))
@ -910,7 +911,11 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
if( social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
}
}else {
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
}
@ -978,6 +983,13 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_stats:
intent = new Intent(context, OwnerNotificationChartsActivity.class);
b = new Bundle();
b.putString("status_id", status.getReblog()!=null?status.getReblog().getId():status.getId());
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_info:
intent = new Intent(context, TootInfoActivity.class);
b = new Bundle();

View File

@ -111,6 +111,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.android.activities.AccountReportActivity;
import app.fedilab.android.activities.OwnerNotificationChartsActivity;
import app.fedilab.android.asynctasks.PostStatusAsyncTask;
import app.fedilab.android.asynctasks.RetrieveRelationshipQuickReplyAsyncTask;
import app.fedilab.android.client.API;
@ -2302,7 +2303,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.spark_button_reblog.setVisibility(View.GONE);
break;
case "private":
boolean isOwner = status.getAccount().getId().equals(userId);
final boolean isOwner = status.getReblog()!=null?status.getReblog().getAccount().getId().equals(userId):status.getAccount().getId().equals(userId);
if (isOwner) {
holder.status_reblog_count.setVisibility(View.VISIBLE);
holder.spark_button_reblog.setVisibility(View.VISIBLE);
@ -2369,7 +2370,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
else
Helper.changeDrawableColor(context, R.drawable.ic_reply, R.color.action_light);
boolean isOwner = status.getAccount().getId().equals(userId);
final boolean isOwner = status.getReblog()!=null?status.getReblog().getAccount().getId().equals(userId):status.getAccount().getId().equals(userId);
// Pinning toots is only available on Mastodon 1._6_.0 instances.
if (isOwner && Helper.canPin && (status.getVisibility().equals("public") || status.getVisibility().equals("unlisted")) && status.getReblog() == null) {
@ -2986,7 +2987,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(context, attached);
final boolean isOwner = status.getAccount().getId().equals(userId);
final boolean isOwner = status.getReblog()!=null?status.getReblog().getAccount().getId().equals(userId):status.getAccount().getId().equals(userId);
popup.getMenuInflater()
.inflate(R.menu.option_toot, popup.getMenu());
if (status.getVisibility().equals("private") || status.getVisibility().equals("direct")) {
@ -3012,7 +3013,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
if( social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
}
} else {
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
//popup.getMenu().findItem(R.id.action_mute_conversation).setVisible(false);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && (isAdmin || isModerator)) {
@ -3160,6 +3165,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
}
return true;
case R.id.action_stats:
intent = new Intent(context, OwnerNotificationChartsActivity.class);
b = new Bundle();
b.putString("status_id", status.getReblog()!=null?status.getReblog().getId():status.getId());
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_timed_mute:
timedMuteAction(status);
return true;

View File

@ -27,7 +27,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import app.fedilab.android.client.Entities.Charts;
import app.fedilab.android.client.Entities.Notification;
import app.fedilab.android.client.Entities.NotificationCharts;
import app.fedilab.android.client.Entities.StatisticsNotification;
@ -76,6 +75,9 @@ public class NotificationCacheDAO {
}else {
id = status.getDb_id();
}
if( notification.getType().equals("mention")){
values.put(Sqlite.COL_IN_REPLY_TO_ID, notification.getStatus().getIn_reply_to_id());
}
}
values.put(Sqlite.COL_STATUS_ID_CACHE, id);
values.put(Sqlite.COL_ACCOUNT, Helper.accountToStringStorage(notification.getAccount()));
@ -173,6 +175,9 @@ public class NotificationCacheDAO {
}else {
id = status.getDb_id();
}
if( notification.getType().equals("mention")){
values.put(Sqlite.COL_IN_REPLY_TO_ID, notification.getStatus().getIn_reply_to_id());
}
}
values.put(Sqlite.COL_STATUS_ID_CACHE, id);
values.put(Sqlite.COL_ACCOUNT, Helper.accountToStringStorage(notification.getAccount()));
@ -579,7 +584,10 @@ public class NotificationCacheDAO {
end.set(Calendar.MINUTE, 59);
end.set(Calendar.SECOND, 59);
}else{
start.setTime(dateIni);
end.setTime(dateIni);
end.add(Calendar.HOUR, 24);
}
long msDiff = end.getTimeInMillis() - start.getTimeInMillis();
@ -598,55 +606,55 @@ public class NotificationCacheDAO {
int mentionCount = 0;
Date smallestDate = getSmallerDate();
int minYVal = 0;
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 "
+ Sqlite.COL_TYPE + " = 'reblog'"
, null);
mCount.moveToFirst();
reblogCount = mCount.getInt(0);
mCount.close();
minYVal = reblogCount;
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'favourite'"
, null);
mCount.moveToFirst();
favCount = mCount.getInt(0);
mCount.close();
if( favCount < minYVal){
minYVal = favCount;
}
if( status_id == null) {
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("'");
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'mention'"
, null);
mCount.moveToFirst();
mentionCount = mCount.getInt(0);
mCount.close();
if( mentionCount < minYVal){
minYVal = mentionCount;
}
try {
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'reblog'"
, null);
mCount.moveToFirst();
reblogCount = mCount.getInt(0);
mCount.close();
minYVal = reblogCount;
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'follow'"
, null);
mCount.moveToFirst();
mCount.moveToFirst();
followCount = mCount.getInt(0);
mCount.close();
if( followCount < minYVal){
minYVal = followCount;
}
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'favourite'"
, null);
mCount.moveToFirst();
favCount = mCount.getInt(0);
mCount.close();
if (favCount < minYVal) {
minYVal = favCount;
}
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'mention'"
, null);
mCount.moveToFirst();
mentionCount = mCount.getInt(0);
mCount.close();
if (mentionCount < minYVal) {
minYVal = mentionCount;
}
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'follow'"
, null);
mCount.moveToFirst();
mCount.moveToFirst();
followCount = mCount.getInt(0);
mCount.close();
if (followCount < minYVal) {
minYVal = followCount;
}
/* mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
@ -659,64 +667,64 @@ public class NotificationCacheDAO {
if( pollCount < minYVal){
minYVal = pollCount;
}*/
} catch (Exception e) {
e.printStackTrace();
}
for (Date date = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
Calendar startTmp = Calendar.getInstance();
startTmp.setTime(date);
startTmp.set(Calendar.HOUR_OF_DAY,0);
startTmp.set(Calendar.MINUTE,0);
startTmp.set(Calendar.SECOND,0);
} catch (Exception e) {
e.printStackTrace();
}
for (Date date = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
Calendar startTmp = Calendar.getInstance();
startTmp.setTime(date);
startTmp.set(Calendar.HOUR_OF_DAY,0);
startTmp.set(Calendar.MINUTE,0);
startTmp.set(Calendar.SECOND,0);
Calendar endTmp = Calendar.getInstance();
endTmp.setTime(date);
endTmp.set(Calendar.HOUR_OF_DAY,23);
endTmp.set(Calendar.MINUTE,59);
endTmp.set(Calendar.SECOND,59);
Calendar endTmp = Calendar.getInstance();
endTmp.setTime(date);
endTmp.set(Calendar.HOUR_OF_DAY,23);
endTmp.set(Calendar.MINUTE,59);
endTmp.set(Calendar.SECOND,59);
selection = new StringBuilder(Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(Helper.dateToString(startTmp.getTime())).append("'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(Helper.dateToString(endTmp.getTime())).append("'");
try {
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'reblog'"
, null);
mCount.moveToFirst();
reblogCount += mCount.getInt(0);
charts.getReblogs().put(date.getTime(), reblogCount);
mCount.close();
selection = new StringBuilder(Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(Helper.dateToString(startTmp.getTime())).append("'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(Helper.dateToString(endTmp.getTime())).append("'");
try {
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'reblog'"
, null);
mCount.moveToFirst();
reblogCount += mCount.getInt(0);
charts.getReblogs().put(date.getTime(), reblogCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'favourite'"
, null);
mCount.moveToFirst();
favCount += mCount.getInt(0);
charts.getFavourites().put(date.getTime(),favCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'favourite'"
, null);
mCount.moveToFirst();
favCount += mCount.getInt(0);
charts.getFavourites().put(date.getTime(),favCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'mention'"
, null);
mCount.moveToFirst();
mentionCount += mCount.getInt(0);
charts.getMentions().put(date.getTime(), mentionCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'mention'"
, null);
mCount.moveToFirst();
mentionCount += mCount.getInt(0);
charts.getMentions().put(date.getTime(), mentionCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'follow'"
, null);
mCount.moveToFirst();
followCount += mCount.getInt(0);
charts.getFollows().put(date.getTime(),followCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'follow'"
, null);
mCount.moveToFirst();
followCount += mCount.getInt(0);
charts.getFollows().put(date.getTime(),followCount);
mCount.close();
/* mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
@ -727,10 +735,87 @@ public class NotificationCacheDAO {
charts.getPolls().put(date.getTime(), pollCount);
mCount.close();*/
} catch (Exception e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}else{
start.add(Calendar.HOUR, -1);
charts.getReblogs().put(start.getTimeInMillis(), 0);
charts.getFavourites().put(start.getTimeInMillis(), 0);
charts.getMentions().put(start.getTimeInMillis(), 0);
charts.getFollows().put(start.getTimeInMillis(), 0);
start.add(Calendar.HOUR, 1);
for (Date date = start.getTime(); start.before(end); start.add(Calendar.HOUR, 1), date = start.getTime()) {
Calendar startTmp = Calendar.getInstance();
startTmp.setTime(date);
Calendar endTmp = Calendar.getInstance();
endTmp.setTime(date);
endTmp.add(Calendar.MINUTE, 59);
endTmp.add(Calendar.SECOND, 59);
StringBuilder selection = new StringBuilder(Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(Helper.dateToString(startTmp.getTime())).append("'");
selection.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(Helper.dateToString(endTmp.getTime())).append("'");
selection.append(" AND (" + Sqlite.COL_STATUS_ID + " = '").append(status_id).append("'").append( " OR ");
selection.append(Sqlite.COL_IN_REPLY_TO_ID + " = '").append(status_id).append("'").append( " ) ");
try {
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'reblog'"
, null);
mCount.moveToFirst();
reblogCount += mCount.getInt(0);
charts.getReblogs().put(date.getTime(), reblogCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'favourite'"
, null);
mCount.moveToFirst();
favCount += mCount.getInt(0);
charts.getFavourites().put(date.getTime(),favCount);
mCount.close();
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'mention'"
, null);
mCount.moveToFirst();
mentionCount += mCount.getInt(0);
charts.getMentions().put(date.getTime(), mentionCount);
mCount.close();
StringBuilder selectionFollow = new StringBuilder(Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
selectionFollow.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(Helper.dateToString(startTmp.getTime())).append("'");
selectionFollow.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(Helper.dateToString(endTmp.getTime())).append("'");
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selectionFollow.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'follow'"
, null);
mCount.moveToFirst();
followCount += mCount.getInt(0);
charts.getFollows().put(date.getTime(),followCount);
mCount.close();
/* mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_NOTIFICATION_CACHE
+ " where " + selection.toString() + " AND "
+ Sqlite.COL_TYPE + " = 'poll'"
, null);
mCount.moveToFirst();
pollCount += mCount.getInt(0);
charts.getPolls().put(date.getTime(), pollCount);
mCount.close();*/
} catch (Exception e) {
e.printStackTrace();
}
}
}
charts.setMinYVal(minYVal);
charts.setxLabels(xLabel);
return charts;

View File

@ -315,6 +315,7 @@ public class Sqlite extends SQLiteOpenHelper {
+ COL_ACCOUNT + " TEXT NOT NULL, "
+ COL_TYPE + " TEXT NOT NULL, "
+ COL_STATUS_ID + " TEXT, "
+ COL_IN_REPLY_TO_ID + " TEXT, "
+ COL_STATUS_ID_CACHE + " INTEGER, "
+ COL_CREATED_AT + " TEXT NOT NULL)";

View File

@ -476,6 +476,21 @@ public class StatusCacheDAO {
}
/**
* Returns a cached status by id in db
* @return stored status StoredStatus
*/
public Status getStatus(String id){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
try {
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_STATUS_ID + " = '" + id + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, null, null);
return cursorToStoredStatus(c);
} catch (Exception e) {
return null;
}
}
public Charts getCharts(Date dateIni, Date dateEnd){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);

View File

@ -9,6 +9,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/date_container"
android:paddingBottom="10dp"
android:orientation="horizontal">
<TextView

View File

@ -14,6 +14,10 @@
android:id="@+id/action_admin"
android:title="@string/administration"
app:showAsAction="never" />
<item
android:id="@+id/action_stats"
android:title="@string/action_stats"
app:showAsAction="never" />
<item
android:id="@+id/action_info"
android:title="@string/information"