Prepares stats

This commit is contained in:
tom79 2019-07-23 16:31:40 +02:00
parent 14cc8575f4
commit 544cbe8dcf
8 changed files with 533 additions and 8 deletions

View File

@ -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<Status> 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) {
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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<Void, Void, Void> {
private OnRetrieveStatsInterface listener;
private WeakReference<Context> 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);
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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;
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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);
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M3.5,18.49l6,-6.01 4,4L22,6.92l-1.41,-1.41 -7.09,7.97 -4,-4L2,16.99z"/>
</vector>

View File

@ -0,0 +1,272 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="@dimen/fab_margin"
android:paddingRight="@dimen/fab_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/stats_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingStart="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_vertical_margin"
android:paddingEnd="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_vertical_margin"
android:layout_height="wrap_content">
<!-- STATUSES -->
<LinearLayout
android:layout_width="match_parent"
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/statuses"
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/total_statuses"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/total_statuses"
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/number_boosts"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/number_boosts"
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/number_replies"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/number_replies"
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/number_statuses"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/number_statuses"
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/number_with_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/number_with_media"
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/number_with_cw"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/number_with_cw"
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/number_with_sensitive_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/number_with_sensitive_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- VISIBILITY -->
<LinearLayout
android:layout_width="match_parent"
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/visibility"
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/v_public"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/v_public"
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/v_unlisted"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/v_unlisted"
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/v_private"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/v_private"
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/v_direct"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="@+id/v_direct"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<!-- Main Loader -->
<RelativeLayout
android:id="@+id/loader"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
</RelativeLayout>

View File

@ -6,6 +6,11 @@
android:title="@string/action_sync"
android:icon="@drawable/ic_sync"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_stats"
android:title="@string/action_stats"
android:icon="@drawable/ic_show_stats"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_filter"
android:title="@string/action_filter"

View File

@ -1122,6 +1122,16 @@
<string name="crash_message">You can send me by email the crash report. It will help to fix it :)\n\nYou can add additional content. Thank you!</string>
<string name="set_wysiwyg">Use the wysiwyg</string>
<string name="set_wysiwyg_indication">When enabled, you will be able to format your text easily with tools.</string>
<string name="action_stats">Statistics</string>
<string name="total_statuses">Total statuses</string>
<string name="number_boosts">Number of boosts</string>
<string name="number_replies">Number of replies</string>
<string name="number_statuses">Number of statuses</string>
<string name="statuses">Statuses</string>
<string name="visibility">Visibility</string>
<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>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>
<item quantity="other">%d votes</item>