This commit is contained in:
tom79 2019-07-23 18:22:52 +02:00
parent f735878932
commit cb80b662ec
6 changed files with 309 additions and 16 deletions

View File

@ -45,10 +45,12 @@ import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@ -96,6 +98,8 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
private FilterToots filterToots;
private Date dateIni, dateEnd;
private View statsDialogView;
private Statistics statistics;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -287,6 +291,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
case R.id.action_sync:
Intent backupIntent = new Intent(OwnerStatusActivity.this, BackupStatusInDataBaseService.class);
startService(backupIntent);
statistics = null;
return true;
case R.id.action_stats:
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
@ -300,18 +305,22 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OwnerStatusActivity.this, style);
LayoutInflater inflater = this.getLayoutInflater();
statsDialogView = inflater.inflate(R.layout.filter_owner_toots, null);
statsDialogView = inflater.inflate(R.layout.stats_owner_toots, null);
dialogBuilder.setView(statsDialogView);
dialogBuilder
.setTitle(R.string.action_filter)
.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
.setTitle(R.string.action_stats)
.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialogBuilder.create().show();
new RetrieveStatsAsyncTask(getApplicationContext(),OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( statistics == null) {
new RetrieveStatsAsyncTask(getApplicationContext(), OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
displayStats();
}
return true;
case R.id.action_filter:
sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
@ -510,6 +519,55 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
@Override
public void onStats(Statistics statistics) {
this.statistics = statistics;
displayStats();
}
private void displayStats(){
if( statsDialogView != null){
ScrollView stats_container = statsDialogView.findViewById(R.id.stats_container);
RelativeLayout loader = statsDialogView.findViewById(R.id.loader);
TextView total_statuses = statsDialogView.findViewById(R.id.total_statuses);
TextView number_boosts = statsDialogView.findViewById(R.id.number_boosts);
TextView number_replies = statsDialogView.findViewById(R.id.number_replies);
TextView number_statuses = statsDialogView.findViewById(R.id.number_statuses);
TextView number_with_media = statsDialogView.findViewById(R.id.number_with_media);
TextView number_with_cw = statsDialogView.findViewById(R.id.number_with_cw);
TextView number_with_sensitive_media = statsDialogView.findViewById(R.id.number_with_sensitive_media);
TextView v_public = statsDialogView.findViewById(R.id.v_public);
TextView v_unlisted = statsDialogView.findViewById(R.id.v_unlisted);
TextView v_private = statsDialogView.findViewById(R.id.v_private);
TextView v_direct = statsDialogView.findViewById(R.id.v_direct);
TextView frequency = statsDialogView.findViewById(R.id.frequency);
TextView last_toot_date = statsDialogView.findViewById(R.id.last_toot_date);
TextView first_toot_date = statsDialogView.findViewById(R.id.first_toot_date);
total_statuses.setText(String.valueOf(statistics.getTotal_statuses()));
number_boosts.setText(String.valueOf(statistics.getNumber_boosts()));
number_replies.setText(String.valueOf(statistics.getNumber_replies()));
number_statuses.setText(String.valueOf(statistics.getNumber_status()));
number_with_media.setText(String.valueOf(statistics.getNumber_with_media()));
number_with_cw.setText(String.valueOf(statistics.getNumber_with_cw()));
number_with_sensitive_media.setText(String.valueOf(statistics.getNumber_with_sensitive_media()));
v_public.setText(String.valueOf(statistics.getV_public()));
v_unlisted.setText(String.valueOf(statistics.getV_unlisted()));
v_private.setText(String.valueOf(statistics.getV_private()));
v_direct.setText(String.valueOf(statistics.getV_direct()));
first_toot_date.setText(Helper.dateToString(statistics.getFirstTootDate()));
last_toot_date.setText(Helper.dateToString(statistics.getLastTootDate()));
DecimalFormat df = new DecimalFormat("#.##");
frequency.setText(getString(R.string.toot_per_day, df.format(statistics.getFrequency())));
stats_container.setVisibility(View.VISIBLE);
loader.setVisibility(View.GONE);
}else{
Toasty.error(OwnerStatusActivity.this,getString(R.string.toast_error),Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -21,6 +21,7 @@ import java.lang.ref.WeakReference;
import app.fedilab.android.client.Entities.Statistics;
import app.fedilab.android.interfaces.OnRetrieveStatsInterface;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.StatusCacheDAO;
/**
@ -44,9 +45,8 @@ public class RetrieveStatsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
statistics = new Statistics();
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
statistics = new StatusCacheDAO(contextReference.get(), db).getStat();
return null;
}

View File

@ -14,19 +14,49 @@ package app.fedilab.android.client.Entities;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import java.util.Date;
public class Statistics {
private int total_statuses;
private int number_boosts;
private int number_replies;
private int number_status;
private int number_with_media;
private int number_with_cw;
private int number_with_sensitive_media;
private int v_public;
private int v_unlisted;
private int v_private;
private int total_statuses = 0;
private int number_boosts = 0;
private int number_replies = 0;
private int number_status = 0;
private int number_with_media = 0;
private int number_with_cw = 0;
private int number_with_sensitive_media = 0;
private int v_public = 0;
private int v_unlisted = 0;
private int v_private = 0;
private Date firstTootDate;
private Date lastTootDate;
private float frequency;
public Date getFirstTootDate() {
return firstTootDate;
}
public void setFirstTootDate(Date firstTootDate) {
this.firstTootDate = firstTootDate;
}
public Date getLastTootDate() {
return lastTootDate;
}
public void setLastTootDate(Date lastTootDate) {
this.lastTootDate = lastTootDate;
}
public float getFrequency() {
return frequency;
}
public void setFrequency(float frequency) {
this.frequency = frequency;
}
public int getTotal_statuses() {
return total_statuses;

View File

@ -23,7 +23,9 @@ import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import app.fedilab.android.client.Entities.Statistics;
import app.fedilab.android.client.Entities.Status;
import app.fedilab.android.helper.FilterToots;
import app.fedilab.android.helper.Helper;
@ -443,7 +445,117 @@ public class StatusCacheDAO {
}
}
public Statistics getStat(){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = Helper.getLiveInstance(context);
Statistics statistics = new Statistics();
//Count All
Cursor mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"'"
, null);
mCount.moveToFirst();
statistics.setTotal_statuses(mCount.getInt(0));
mCount.close();
//Count boosts
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_REBLOG + " IS NOT NULL" + " AND " + Sqlite.COL_REBLOG + " != ''"
, null);
mCount.moveToFirst();
statistics.setNumber_boosts(mCount.getInt(0));
mCount.close();
//Count replies
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_IN_REPLY_TO_ID + " IS NOT NULL" + " AND " + Sqlite.COL_IN_REPLY_TO_ID + " != 'null'" + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setNumber_replies(mCount.getInt(0));
mCount.close();
statistics.setNumber_status(statistics.getTotal_statuses() - statistics.getNumber_boosts() - statistics.getNumber_replies());
//Count media
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_MEDIA_ATTACHMENTS + " IS NOT NULL" + " AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " !='"+Helper.attachmentToStringStorage(new ArrayList<>())+"' " + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setNumber_with_media(mCount.getInt(0));
mCount.close();
//Count sensitive
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_SENSITIVE + "= 1 AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " IS NOT NULL" + " AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " !='"+Helper.attachmentToStringStorage(new ArrayList<>())+"' " + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setNumber_with_sensitive_media(mCount.getInt(0));
mCount.close();
//Count sensitive
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_SPOILER_TEXT + " IS NOT NULL" + " AND " + Sqlite.COL_SPOILER_TEXT + " != '' " + " AND " +Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setNumber_with_cw(mCount.getInt(0));
mCount.close();
//Count public
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_VISIBILITY + "='public'" + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setV_public(mCount.getInt(0));
mCount.close();
//Count unlisted
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_VISIBILITY + "='unlisted'" + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setV_unlisted(mCount.getInt(0));
mCount.close();
//Count private
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_VISIBILITY + "='private'" + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setV_private(mCount.getInt(0));
mCount.close();
//Count private
mCount = db.rawQuery("select count(*) from " + Sqlite.TABLE_STATUSES_CACHE
+ " where " + Sqlite.COL_CACHED_ACTION + " = '" + ARCHIVE_CACHE + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance +"' AND "
+ Sqlite.COL_VISIBILITY + "='direct'" + " AND " + Sqlite.COL_REBLOG + " IS NULL"
, null);
mCount.moveToFirst();
statistics.setV_direct(mCount.getInt(0));
mCount.close();
statistics.setFirstTootDate(getSmallerDate(ARCHIVE_CACHE));
statistics.setLastTootDate(getGreaterDate(ARCHIVE_CACHE));
long diff = statistics.getLastTootDate().getTime() - statistics.getFirstTootDate().getTime();
long days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
statistics.setFrequency((float)statistics.getTotal_statuses()/days);
return statistics;
}
/***

View File

@ -24,6 +24,7 @@
android:id="@+id/stats_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
@ -32,10 +33,85 @@
android:paddingEnd="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_vertical_margin"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="?colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/date_range"
android:textColor="?colorAccent"
android:textSize="16sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="?colorAccent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="2"
android:text="@string/first_toot_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/first_toot_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="2"
android:text="@string/last_toot_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/last_toot_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="2"
android:text="@string/frequency"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/frequency"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- STATUSES -->
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
@ -71,6 +147,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/total_statuses"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -86,6 +163,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/number_boosts"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -101,6 +179,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/number_replies"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -116,6 +195,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/number_statuses"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -131,6 +211,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/number_with_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -147,6 +228,7 @@
<TextView
android:layout_weight="1"
android:id="@+id/number_with_cw"
android:textAlignment="textEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
@ -161,6 +243,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/number_with_sensitive_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -170,6 +253,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<View
android:layout_width="0dp"
@ -204,6 +288,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/v_public"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -219,6 +304,7 @@
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:textAlignment="textEnd"
android:id="@+id/v_unlisted"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -235,6 +321,7 @@
<TextView
android:layout_weight="1"
android:id="@+id/v_private"
android:textAlignment="textEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
@ -250,6 +337,7 @@
<TextView
android:layout_weight="1"
android:id="@+id/v_direct"
android:textAlignment="textEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -1132,6 +1132,11 @@
<string name="number_with_media">Number with media</string>
<string name="number_with_sensitive_media">Number with sensitive media</string>
<string name="number_with_cw">Number with CW</string>
<string name="first_toot_date">First status date</string>
<string name="last_toot_date">Last status date</string>
<string name="frequency">Frequency</string>
<string name="toot_per_day">%s statuses per day</string>
<string name="date_range">Date range</string>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>
<item quantity="other">%d votes</item>