diff --git a/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java b/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java index 1512846e0..487a95b1d 100644 --- a/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java @@ -31,7 +31,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.appcompat.widget.Toolbar; @@ -55,12 +54,15 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import app.fedilab.android.asynctasks.RetrieveStatsAsyncTask; import app.fedilab.android.client.APIResponse; import app.fedilab.android.client.Entities.Account; +import app.fedilab.android.client.Entities.Statistics; import app.fedilab.android.client.Entities.Status; import app.fedilab.android.drawers.StatusListAdapter; import app.fedilab.android.helper.FilterToots; import app.fedilab.android.helper.Helper; +import app.fedilab.android.interfaces.OnRetrieveStatsInterface; import app.fedilab.android.services.BackupStatusInDataBaseService; import app.fedilab.android.sqlite.AccountDAO; import app.fedilab.android.sqlite.Sqlite; @@ -76,12 +78,11 @@ import app.fedilab.android.interfaces.OnRetrieveFeedsInterface; * Show owner's toots */ -public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeedsInterface { +public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeedsInterface, OnRetrieveStatsInterface { private ImageView pp_actionBar; private StatusListAdapter statusListAdapter; - private SharedPreferences sharedpreferences; private String max_id; private List statuses; private RelativeLayout mainLoader, nextElementLoader, textviewNoAction; @@ -94,12 +95,13 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds private Button settings_time_from, settings_time_to; private FilterToots filterToots; private Date dateIni, dateEnd; + private View statsDialogView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); switch (theme){ case Helper.THEME_LIGHT: @@ -286,7 +288,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds Intent backupIntent = new Intent(OwnerStatusActivity.this, BackupStatusInDataBaseService.class); startService(backupIntent); return true; - case R.id.action_filter: + case R.id.action_stats: SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); if (theme == Helper.THEME_DARK) { @@ -298,6 +300,31 @@ 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); + dialogBuilder.setView(statsDialogView); + dialogBuilder + .setTitle(R.string.action_filter) + .setPositiveButton(R.string.cancel, 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); + return true; + case R.id.action_filter: + sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + if (theme == Helper.THEME_DARK) { + style = R.style.DialogDark; + } else if (theme == Helper.THEME_BLACK){ + style = R.style.DialogBlack; + }else { + style = R.style.Dialog; + } + dialogBuilder = new AlertDialog.Builder(OwnerStatusActivity.this, style); + inflater = this.getLayoutInflater(); @SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.filter_owner_toots, null); dialogBuilder.setView(dialogView); @@ -411,9 +438,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds dialog.dismiss(); } }); - final AlertDialog alertDialog = dialogBuilder.create(); - - alertDialog.show(); + dialogBuilder.create().show(); return true; default: return super.onOptionsItemSelected(item); @@ -483,4 +508,8 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds .unregisterReceiver(backupFinishedReceiver); } + @Override + public void onStats(Statistics statistics) { + + } } diff --git a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveStatsAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveStatsAsyncTask.java new file mode 100644 index 000000000..0e0adc21b --- /dev/null +++ b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveStatsAsyncTask.java @@ -0,0 +1,59 @@ +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ +package app.fedilab.android.asynctasks; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.os.AsyncTask; +import java.lang.ref.WeakReference; +import app.fedilab.android.client.Entities.Statistics; +import app.fedilab.android.interfaces.OnRetrieveStatsInterface; +import app.fedilab.android.sqlite.Sqlite; + + +/** + * Created by Thomas on 23/07/2019. + * Retrieves stats for an account + */ + +public class RetrieveStatsAsyncTask extends AsyncTask { + + + private OnRetrieveStatsInterface listener; + private WeakReference contextReference; + private Statistics statistics; + + public RetrieveStatsAsyncTask(Context context, OnRetrieveStatsInterface onRetrieveStatsInterface){ + this.contextReference = new WeakReference<>(context); + this.listener = onRetrieveStatsInterface; + } + + + @Override + protected Void doInBackground(Void... params) { + + statistics = new Statistics(); + SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + + + return null; + } + + @Override + protected void onPostExecute(Void result) { + listener.onStats(statistics); + } + +} diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Statistics.java b/app/src/main/java/app/fedilab/android/client/Entities/Statistics.java new file mode 100644 index 000000000..feef702a4 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/client/Entities/Statistics.java @@ -0,0 +1,120 @@ +package app.fedilab.android.client.Entities; +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + +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; + + public int getTotal_statuses() { + return total_statuses; + } + + public void setTotal_statuses(int total_statuses) { + this.total_statuses = total_statuses; + } + + public int getNumber_boosts() { + return number_boosts; + } + + public void setNumber_boosts(int number_boosts) { + this.number_boosts = number_boosts; + } + + public int getNumber_replies() { + return number_replies; + } + + public void setNumber_replies(int number_replies) { + this.number_replies = number_replies; + } + + public int getNumber_status() { + return number_status; + } + + public void setNumber_status(int number_status) { + this.number_status = number_status; + } + + public int getNumber_with_media() { + return number_with_media; + } + + public void setNumber_with_media(int number_with_media) { + this.number_with_media = number_with_media; + } + + public int getNumber_with_cw() { + return number_with_cw; + } + + public void setNumber_with_cw(int number_with_cw) { + this.number_with_cw = number_with_cw; + } + + public int getNumber_with_sensitive_media() { + return number_with_sensitive_media; + } + + public void setNumber_with_sensitive_media(int number_with_sensitive_media) { + this.number_with_sensitive_media = number_with_sensitive_media; + } + + public int getV_public() { + return v_public; + } + + public void setV_public(int v_public) { + this.v_public = v_public; + } + + public int getV_unlisted() { + return v_unlisted; + } + + public void setV_unlisted(int v_unlisted) { + this.v_unlisted = v_unlisted; + } + + public int getV_private() { + return v_private; + } + + public void setV_private(int v_private) { + this.v_private = v_private; + } + + public int getV_direct() { + return v_direct; + } + + public void setV_direct(int v_direct) { + this.v_direct = v_direct; + } + + private int v_direct; +} diff --git a/app/src/main/java/app/fedilab/android/interfaces/OnRetrieveStatsInterface.java b/app/src/main/java/app/fedilab/android/interfaces/OnRetrieveStatsInterface.java new file mode 100644 index 000000000..42f8b7f64 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/interfaces/OnRetrieveStatsInterface.java @@ -0,0 +1,25 @@ +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ +package app.fedilab.android.interfaces; + +import app.fedilab.android.client.Entities.Statistics; + +/** + * Created by Thomas on 23/07/2019. + * Interface when retrieving stats + */ +public interface OnRetrieveStatsInterface { + void onStats(Statistics statistics); +} diff --git a/app/src/main/res/drawable/ic_show_stats.xml b/app/src/main/res/drawable/ic_show_stats.xml new file mode 100644 index 000000000..f62b9850a --- /dev/null +++ b/app/src/main/res/drawable/ic_show_stats.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/stats_owner_toots.xml b/app/src/main/res/layout/stats_owner_toots.xml new file mode 100644 index 000000000..3ff059248 --- /dev/null +++ b/app/src/main/res/layout/stats_owner_toots.xml @@ -0,0 +1,272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/option_owner_cache.xml b/app/src/main/res/menu/option_owner_cache.xml index 4134f0b9a..b69928177 100644 --- a/app/src/main/res/menu/option_owner_cache.xml +++ b/app/src/main/res/menu/option_owner_cache.xml @@ -6,6 +6,11 @@ android:title="@string/action_sync" android:icon="@drawable/ic_sync" app:showAsAction="ifRoom" /> + You can send me by email the crash report. It will help to fix it :)\n\nYou can add additional content. Thank you! Use the wysiwyg When enabled, you will be able to format your text easily with tools. + Statistics + Total statuses + Number of boosts + Number of replies + Number of statuses + Statuses + Visibility + Number with media + Number with sensitive media + Number with CW %d vote %d votes