2018-02-17 11:28:52 +01:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2018-02-17 11:28:52 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2018-02-17 11:28:52 +01:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2018-02-17 11:28:52 +01:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.activities;
|
2018-02-17 11:28:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
2018-02-17 12:35:54 +01:00
|
|
|
import android.app.DatePickerDialog;
|
2018-02-17 16:09:06 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2018-02-17 12:35:54 +01:00
|
|
|
import android.content.DialogInterface;
|
2018-02-17 11:28:52 +01:00
|
|
|
import android.content.Intent;
|
2018-02-17 16:09:06 +01:00
|
|
|
import android.content.IntentFilter;
|
2018-02-17 11:28:52 +01:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
2019-06-11 19:38:26 +02:00
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2018-02-17 11:28:52 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2018-02-17 12:35:54 +01:00
|
|
|
import android.widget.Button;
|
2018-02-17 14:43:12 +01:00
|
|
|
import android.widget.CheckBox;
|
2018-02-17 12:35:54 +01:00
|
|
|
import android.widget.DatePicker;
|
2018-02-17 15:14:54 +01:00
|
|
|
import android.widget.EditText;
|
2019-07-29 17:03:36 +02:00
|
|
|
import android.widget.ImageButton;
|
2018-02-17 11:28:52 +01:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.RelativeLayout;
|
2019-07-23 18:22:52 +02:00
|
|
|
import android.widget.ScrollView;
|
2018-02-17 14:43:12 +01:00
|
|
|
import android.widget.Spinner;
|
2018-02-17 11:28:52 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-07-23 18:22:52 +02:00
|
|
|
import java.text.DecimalFormat;
|
2018-02-17 11:28:52 +01:00
|
|
|
import java.util.ArrayList;
|
2018-02-17 12:35:54 +01:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
2019-07-24 17:48:24 +02:00
|
|
|
import java.util.Iterator;
|
2018-02-17 11:28:52 +01:00
|
|
|
import java.util.List;
|
2019-07-24 17:48:24 +02:00
|
|
|
import java.util.Map;
|
2018-11-14 14:07:25 +01:00
|
|
|
|
2019-07-23 16:31:40 +02:00
|
|
|
import app.fedilab.android.asynctasks.RetrieveStatsAsyncTask;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.APIResponse;
|
|
|
|
import app.fedilab.android.client.Entities.Account;
|
2019-07-23 16:31:40 +02:00
|
|
|
import app.fedilab.android.client.Entities.Statistics;
|
2019-05-18 11:10:30 +02:00
|
|
|
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;
|
2019-07-23 16:31:40 +02:00
|
|
|
import app.fedilab.android.interfaces.OnRetrieveStatsInterface;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.services.BackupStatusInDataBaseService;
|
|
|
|
import app.fedilab.android.sqlite.AccountDAO;
|
|
|
|
import app.fedilab.android.sqlite.Sqlite;
|
|
|
|
import app.fedilab.android.sqlite.StatusCacheDAO;
|
2018-11-25 10:45:16 +01:00
|
|
|
import es.dmoral.toasty.Toasty;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
|
|
|
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
2018-05-11 13:53:08 +02:00
|
|
|
|
2018-02-17 11:28:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 17/02/2018.
|
|
|
|
* Show owner's toots
|
|
|
|
*/
|
|
|
|
|
2019-07-23 16:31:40 +02:00
|
|
|
public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeedsInterface, OnRetrieveStatsInterface {
|
2018-02-17 11:28:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
private ImageView pp_actionBar;
|
|
|
|
private StatusListAdapter statusListAdapter;
|
|
|
|
private String max_id;
|
|
|
|
private List<Status> statuses;
|
|
|
|
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
|
|
|
private boolean firstLoad;
|
|
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
|
|
|
private boolean swiped;
|
|
|
|
private boolean flag_loading;
|
|
|
|
LinearLayoutManager mLayoutManager;
|
2018-02-17 12:35:54 +01:00
|
|
|
private int style;
|
|
|
|
private Button settings_time_from, settings_time_to;
|
2018-02-17 14:43:12 +01:00
|
|
|
private FilterToots filterToots;
|
|
|
|
private Date dateIni, dateEnd;
|
2019-07-23 16:31:40 +02:00
|
|
|
private View statsDialogView;
|
2019-07-23 18:22:52 +02:00
|
|
|
private Statistics statistics;
|
|
|
|
|
2018-02-17 11:28:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2019-07-23 16:31:40 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
2018-02-17 11:28:52 +01:00
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
2018-05-11 11:28:05 +02:00
|
|
|
switch (theme){
|
|
|
|
case Helper.THEME_LIGHT:
|
2019-07-20 15:15:47 +02:00
|
|
|
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
|
2018-05-11 11:28:05 +02:00
|
|
|
break;
|
|
|
|
case Helper.THEME_DARK:
|
|
|
|
setTheme(R.style.AppThemeDark_NoActionBar);
|
|
|
|
break;
|
|
|
|
case Helper.THEME_BLACK:
|
|
|
|
setTheme(R.style.AppThemeBlack_NoActionBar);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setTheme(R.style.AppThemeDark_NoActionBar);
|
2018-02-17 11:28:52 +01:00
|
|
|
}
|
|
|
|
setContentView(R.layout.activity_ower_status);
|
|
|
|
|
2018-02-17 14:43:12 +01:00
|
|
|
filterToots = new FilterToots();
|
|
|
|
|
2018-02-17 16:09:06 +01:00
|
|
|
LocalBroadcastManager.getInstance(this)
|
|
|
|
.registerReceiver(backupFinishedReceiver,
|
|
|
|
new IntentFilter(Helper.INTENT_BACKUP_FINISH));
|
|
|
|
|
2018-02-17 11:28:52 +01:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2019-05-18 11:10:30 +02:00
|
|
|
if( theme == Helper.THEME_BLACK)
|
2018-05-11 13:53:08 +02:00
|
|
|
toolbar.setBackgroundColor(ContextCompat.getColor(OwnerStatusActivity.this, R.color.black));
|
2018-02-17 11:28:52 +01:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if( actionBar != null ){
|
|
|
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(android.content.Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
assert inflater != null;
|
|
|
|
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.toot_action_bar, null);
|
|
|
|
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
|
|
|
|
|
ImageView close_toot = actionBar.getCustomView().findViewById(R.id.close_toot);
|
|
|
|
close_toot.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
2018-02-17 15:28:15 +01:00
|
|
|
TextView toolbarTitle = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
2018-02-17 11:28:52 +01:00
|
|
|
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
|
2019-05-18 11:10:30 +02:00
|
|
|
if (theme == Helper.THEME_LIGHT){
|
2018-11-03 14:45:55 +01:00
|
|
|
Helper.colorizeToolbar(actionBar.getCustomView().findViewById(R.id.toolbar), R.color.black, OwnerStatusActivity.this);
|
|
|
|
}
|
2018-02-17 11:28:52 +01:00
|
|
|
toolbarTitle.setText(getString(R.string.owner_cached_toots));
|
|
|
|
}
|
|
|
|
statuses = new ArrayList<>();
|
2018-02-17 15:28:15 +01:00
|
|
|
RecyclerView lv_status = findViewById(R.id.lv_status);
|
2018-02-17 11:28:52 +01:00
|
|
|
mainLoader = findViewById(R.id.loader);
|
|
|
|
nextElementLoader = findViewById(R.id.loading_next_status);
|
|
|
|
textviewNoAction = findViewById(R.id.no_action);
|
|
|
|
mainLoader.setVisibility(View.VISIBLE);
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
|
|
|
max_id = null;
|
|
|
|
flag_loading = true;
|
|
|
|
firstLoad = true;
|
|
|
|
swiped = false;
|
|
|
|
boolean isOnWifi = Helper.isOnWIFI(OwnerStatusActivity.this);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
2019-06-05 14:35:42 +02:00
|
|
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
2018-12-16 14:29:23 +01:00
|
|
|
statusListAdapter = new StatusListAdapter(OwnerStatusActivity.this, RetrieveFeedsAsyncTask.Type.CACHE_STATUS, userId, isOnWifi, this.statuses);
|
2018-02-17 11:28:52 +01:00
|
|
|
lv_status.setAdapter(statusListAdapter);
|
|
|
|
mLayoutManager = new LinearLayoutManager(OwnerStatusActivity.this);
|
|
|
|
lv_status.setLayoutManager(mLayoutManager);
|
|
|
|
|
2018-02-17 12:35:54 +01:00
|
|
|
|
|
|
|
if( theme == Helper.THEME_DARK){
|
|
|
|
style = R.style.DialogDark;
|
2019-07-23 15:46:18 +02:00
|
|
|
}else if( theme == Helper.THEME_BLACK){
|
|
|
|
style = R.style.DialogBlack;
|
2018-02-17 12:35:54 +01:00
|
|
|
}else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
|
2018-02-17 11:28:52 +01:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2019-06-05 14:35:42 +02:00
|
|
|
Account account = new AccountDAO(OwnerStatusActivity.this,db).getUniqAccount(userId, instance);
|
2019-07-30 11:48:37 +02:00
|
|
|
|
2019-08-02 13:41:08 +02:00
|
|
|
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
2018-02-17 11:28:52 +01:00
|
|
|
|
|
|
|
swipeRefreshLayout = findViewById(R.id.swipeContainer);
|
2018-02-17 14:43:12 +01:00
|
|
|
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, null, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2018-05-11 16:33:16 +02:00
|
|
|
switch (theme){
|
|
|
|
case Helper.THEME_LIGHT:
|
|
|
|
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
|
|
|
R.color.mastodonC2,
|
|
|
|
R.color.mastodonC3);
|
|
|
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(OwnerStatusActivity.this, R.color.white));
|
|
|
|
break;
|
|
|
|
case Helper.THEME_DARK:
|
|
|
|
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4__,
|
|
|
|
R.color.mastodonC4,
|
|
|
|
R.color.mastodonC4);
|
|
|
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(OwnerStatusActivity.this, R.color.mastodonC1_));
|
|
|
|
break;
|
|
|
|
case Helper.THEME_BLACK:
|
|
|
|
swipeRefreshLayout.setColorSchemeResources(R.color.dark_icon,
|
|
|
|
R.color.mastodonC2,
|
|
|
|
R.color.mastodonC3);
|
2018-05-12 12:06:43 +02:00
|
|
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(OwnerStatusActivity.this, R.color.black_3));
|
2018-05-11 16:33:16 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-02-17 11:28:52 +01:00
|
|
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
2018-02-17 14:43:12 +01:00
|
|
|
max_id = null;
|
|
|
|
firstLoad = true;
|
|
|
|
flag_loading = true;
|
|
|
|
swiped = true;
|
|
|
|
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, null, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2018-02-17 11:28:52 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
|
|
|
|
{
|
|
|
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if(dy > 0){
|
|
|
|
int visibleItemCount = mLayoutManager.getChildCount();
|
|
|
|
int totalItemCount = mLayoutManager.getItemCount();
|
|
|
|
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
|
|
|
if(!flag_loading ) {
|
|
|
|
flag_loading = true;
|
2018-02-17 14:43:12 +01:00
|
|
|
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, max_id, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2018-02-17 11:28:52 +01:00
|
|
|
nextElementLoader.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.option_owner_cache, menu);
|
2018-11-03 14:45:55 +01:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
2019-05-18 11:10:30 +02:00
|
|
|
if( theme == Helper.THEME_LIGHT)
|
2018-11-03 14:45:55 +01:00
|
|
|
Helper.colorizeIconMenu(menu, R.color.black);
|
2018-02-17 11:28:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-17 12:35:54 +01:00
|
|
|
private DatePickerDialog.OnDateSetListener iniDateSetListener =
|
|
|
|
new DatePickerDialog.OnDateSetListener() {
|
|
|
|
|
|
|
|
public void onDateSet(DatePicker view, int year,
|
|
|
|
int monthOfYear, int dayOfMonth) {
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.set(year, monthOfYear, dayOfMonth, 0, 0);
|
2018-02-17 14:43:12 +01:00
|
|
|
dateIni = new Date(c.getTimeInMillis());
|
2018-02-17 12:35:54 +01:00
|
|
|
settings_time_from.setText(Helper.shortDateToString(new Date(c.getTimeInMillis())));
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
private DatePickerDialog.OnDateSetListener endDateSetListener =
|
|
|
|
new DatePickerDialog.OnDateSetListener() {
|
|
|
|
|
|
|
|
public void onDateSet(DatePicker view, int year,
|
|
|
|
int monthOfYear, int dayOfMonth) {
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.set(year, monthOfYear, dayOfMonth, 23, 59);
|
2018-02-17 14:43:12 +01:00
|
|
|
|
|
|
|
dateEnd = new Date(c.getTimeInMillis());
|
2018-02-17 12:35:54 +01:00
|
|
|
settings_time_to.setText(Helper.shortDateToString(new Date(c.getTimeInMillis())));
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2018-02-17 11:28:52 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
case R.id.action_sync:
|
|
|
|
Intent backupIntent = new Intent(OwnerStatusActivity.this, BackupStatusInDataBaseService.class);
|
|
|
|
startService(backupIntent);
|
2019-07-23 18:22:52 +02:00
|
|
|
statistics = null;
|
2018-02-17 11:28:52 +01:00
|
|
|
return true;
|
2019-07-23 16:31:40 +02:00
|
|
|
case R.id.action_stats:
|
2018-11-03 14:45:55 +01:00
|
|
|
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) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK){
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
}else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OwnerStatusActivity.this, style);
|
2018-02-17 12:35:54 +01:00
|
|
|
LayoutInflater inflater = this.getLayoutInflater();
|
2019-07-23 18:22:52 +02:00
|
|
|
statsDialogView = inflater.inflate(R.layout.stats_owner_toots, null);
|
2019-07-23 16:31:40 +02:00
|
|
|
dialogBuilder.setView(statsDialogView);
|
|
|
|
dialogBuilder
|
2019-07-23 18:22:52 +02:00
|
|
|
.setTitle(R.string.action_stats)
|
2019-07-23 18:41:19 +02:00
|
|
|
.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
|
2019-07-23 16:31:40 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.create().show();
|
2019-07-23 18:22:52 +02:00
|
|
|
if( statistics == null) {
|
|
|
|
new RetrieveStatsAsyncTask(getApplicationContext(), OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}else{
|
|
|
|
displayStats();
|
|
|
|
}
|
2019-07-23 16:31:40 +02:00
|
|
|
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();
|
2018-02-17 12:35:54 +01:00
|
|
|
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.filter_owner_toots, null);
|
|
|
|
dialogBuilder.setView(dialogView);
|
2018-02-17 14:43:12 +01:00
|
|
|
|
2018-02-17 12:35:54 +01:00
|
|
|
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2018-02-17 15:14:54 +01:00
|
|
|
if( dateIni == null)
|
|
|
|
dateIni = new StatusCacheDAO(OwnerStatusActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
|
|
|
|
if( dateEnd == null)
|
|
|
|
dateEnd = new StatusCacheDAO(OwnerStatusActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
|
2018-02-17 16:09:06 +01:00
|
|
|
if( dateIni == null || dateEnd == null)
|
|
|
|
return true;
|
2018-02-17 14:43:12 +01:00
|
|
|
String dateInitString = Helper.shortDateToString(dateIni);
|
2018-02-17 12:35:54 +01:00
|
|
|
String dateEndString = Helper.shortDateToString(dateEnd);
|
|
|
|
|
2018-02-17 14:43:12 +01:00
|
|
|
//Initializes settings for filter
|
2018-02-17 12:35:54 +01:00
|
|
|
settings_time_from = dialogView.findViewById(R.id.settings_time_from);
|
|
|
|
settings_time_to = dialogView.findViewById(R.id.settings_time_to);
|
|
|
|
|
2018-02-17 14:43:12 +01:00
|
|
|
final CheckBox filter_visibility_public = dialogView.findViewById(R.id.filter_visibility_public);
|
|
|
|
final CheckBox filter_visibility_unlisted = dialogView.findViewById(R.id.filter_visibility_unlisted);
|
|
|
|
final CheckBox filter_visibility_private = dialogView.findViewById(R.id.filter_visibility_private);
|
2018-02-17 15:14:54 +01:00
|
|
|
final CheckBox filter_visibility_direct = dialogView.findViewById(R.id.filter_visibility_direct);
|
2018-02-17 14:43:12 +01:00
|
|
|
|
|
|
|
filter_visibility_public.setChecked(filterToots.isV_public());
|
|
|
|
filter_visibility_unlisted.setChecked(filterToots.isV_unlisted());
|
|
|
|
filter_visibility_private.setChecked(filterToots.isV_private());
|
|
|
|
filter_visibility_direct.setChecked(filterToots.isV_direct());
|
|
|
|
|
|
|
|
final Spinner filter_boost = dialogView.findViewById(R.id.filter_boost);
|
|
|
|
final Spinner filter_replies = dialogView.findViewById(R.id.filter_replies);
|
|
|
|
final Spinner filter_media = dialogView.findViewById(R.id.filter_media);
|
|
|
|
final Spinner filter_pinned = dialogView.findViewById(R.id.filter_pinned);
|
|
|
|
|
|
|
|
filter_boost.setSelection(filterToots.getBoosts().ordinal());
|
|
|
|
filter_replies.setSelection(filterToots.getReplies().ordinal());
|
|
|
|
filter_media.setSelection(filterToots.getMedia().ordinal());
|
|
|
|
filter_pinned.setSelection(filterToots.getPinned().ordinal());
|
|
|
|
|
2018-02-17 15:14:54 +01:00
|
|
|
final EditText filter_keywords = dialogView.findViewById(R.id.filter_keywords);
|
2018-02-17 14:43:12 +01:00
|
|
|
|
2018-02-17 12:35:54 +01:00
|
|
|
settings_time_from.setText(dateInitString);
|
|
|
|
settings_time_to.setText(dateEndString);
|
|
|
|
|
2018-02-17 15:14:54 +01:00
|
|
|
if( filterToots.getFilter() != null)
|
|
|
|
filter_keywords.setText(filterToots.getFilter());
|
2018-02-17 14:43:12 +01:00
|
|
|
|
2018-02-17 12:35:54 +01:00
|
|
|
Calendar c = Calendar.getInstance();
|
2018-02-17 14:43:12 +01:00
|
|
|
c.setTime(dateIni);
|
2018-02-17 12:35:54 +01:00
|
|
|
int yearIni = c.get(Calendar.YEAR);
|
|
|
|
int monthIni = c.get(Calendar.MONTH);
|
|
|
|
int dayIni = c.get(Calendar.DAY_OF_MONTH);
|
|
|
|
|
|
|
|
final DatePickerDialog dateIniPickerDialog = new DatePickerDialog(
|
|
|
|
OwnerStatusActivity.this, style, iniDateSetListener, yearIni, monthIni, dayIni);
|
|
|
|
settings_time_from.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
dateIniPickerDialog.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(
|
|
|
|
OwnerStatusActivity.this, style, endDateSetListener, yearEnd, monthEnd, dayEnd);
|
|
|
|
settings_time_to.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
dateEndPickerDialog.show();
|
|
|
|
}
|
|
|
|
});
|
2018-02-17 14:43:12 +01:00
|
|
|
dialogBuilder
|
|
|
|
.setTitle(R.string.action_filter)
|
|
|
|
.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2018-02-17 15:28:15 +01:00
|
|
|
RelativeLayout no_result = findViewById(R.id.no_result);
|
|
|
|
no_result.setVisibility(View.GONE);
|
|
|
|
|
2018-02-17 14:43:12 +01:00
|
|
|
filterToots.setBoosts(FilterToots.typeFilter.values()[filter_boost.getSelectedItemPosition()]);
|
|
|
|
filterToots.setReplies(FilterToots.typeFilter.values()[filter_replies.getSelectedItemPosition()]);
|
|
|
|
filterToots.setMedia(FilterToots.typeFilter.values()[filter_media.getSelectedItemPosition()]);
|
|
|
|
filterToots.setPinned(FilterToots.typeFilter.values()[filter_pinned.getSelectedItemPosition()]);
|
|
|
|
|
|
|
|
filterToots.setV_public(filter_visibility_public.isChecked());
|
|
|
|
filterToots.setV_unlisted(filter_visibility_unlisted.isChecked());
|
|
|
|
filterToots.setV_private(filter_visibility_private.isChecked());
|
2018-02-17 15:14:54 +01:00
|
|
|
filterToots.setV_direct(filter_visibility_direct.isChecked());
|
2018-02-17 14:43:12 +01:00
|
|
|
|
2018-04-28 16:54:06 +02:00
|
|
|
filterToots.setDateIni(Helper.dateToString(dateIni));
|
|
|
|
filterToots.setDateEnd(Helper.dateToString(dateEnd));
|
2018-02-17 14:43:12 +01:00
|
|
|
|
2018-02-17 15:14:54 +01:00
|
|
|
if( filter_keywords.getText() != null && filter_keywords.getText().toString().trim().length() > 0)
|
|
|
|
filterToots.setFilter(filter_keywords.getText().toString());
|
|
|
|
else
|
|
|
|
filterToots.setFilter(null);
|
2018-02-17 14:43:12 +01:00
|
|
|
swipeRefreshLayout.setRefreshing(true);
|
|
|
|
max_id = null;
|
|
|
|
firstLoad = true;
|
|
|
|
flag_loading = true;
|
|
|
|
swiped = true;
|
|
|
|
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, null, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
2019-07-23 16:31:40 +02:00
|
|
|
dialogBuilder.create().show();
|
2018-02-17 11:28:52 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrieveFeeds(APIResponse apiResponse) {
|
|
|
|
mainLoader.setVisibility(View.GONE);
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
|
|
|
//Discards 404 - error which can often happen due to toots which have been deleted
|
|
|
|
if( apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 ){
|
2018-11-25 10:45:16 +01:00
|
|
|
Toasty.error(OwnerStatusActivity.this, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
2018-02-17 11:28:52 +01:00
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
|
|
|
swiped = false;
|
|
|
|
flag_loading = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int previousPosition = this.statuses.size();
|
|
|
|
List<Status> statuses = apiResponse.getStatuses();
|
|
|
|
max_id = apiResponse.getMax_id();
|
|
|
|
flag_loading = (max_id == null );
|
|
|
|
if( !swiped && firstLoad && (statuses == null || statuses.size() == 0))
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
else
|
|
|
|
textviewNoAction.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if( swiped ){
|
|
|
|
if (previousPosition > 0) {
|
|
|
|
for (int i = 0; i < previousPosition; i++) {
|
|
|
|
this.statuses.remove(0);
|
|
|
|
}
|
|
|
|
statusListAdapter.notifyItemRangeRemoved(0, previousPosition);
|
|
|
|
}
|
|
|
|
swiped = false;
|
|
|
|
}
|
|
|
|
if( statuses != null && statuses.size() > 0) {
|
|
|
|
this.statuses.addAll(statuses);
|
|
|
|
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
2018-02-17 15:28:15 +01:00
|
|
|
}else {
|
2018-02-17 18:08:06 +01:00
|
|
|
if( textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
|
2018-02-17 16:09:06 +01:00
|
|
|
RelativeLayout no_result = findViewById(R.id.no_result);
|
|
|
|
no_result.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2018-02-17 11:28:52 +01:00
|
|
|
}
|
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
|
|
|
firstLoad = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-17 16:09:06 +01:00
|
|
|
private BroadcastReceiver backupFinishedReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
max_id = null;
|
|
|
|
firstLoad = true;
|
|
|
|
flag_loading = true;
|
|
|
|
swiped = true;
|
|
|
|
new RetrieveFeedsAsyncTask(OwnerStatusActivity.this, filterToots, null, OwnerStatusActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
LocalBroadcastManager.getInstance(this)
|
|
|
|
.unregisterReceiver(backupFinishedReceiver);
|
|
|
|
}
|
|
|
|
|
2019-07-23 16:31:40 +02:00
|
|
|
@Override
|
|
|
|
public void onStats(Statistics statistics) {
|
2019-07-23 18:22:52 +02:00
|
|
|
this.statistics = statistics;
|
|
|
|
displayStats();
|
|
|
|
}
|
2019-07-23 16:31:40 +02:00
|
|
|
|
2019-07-23 18:22:52 +02:00
|
|
|
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);
|
2019-07-24 17:48:24 +02:00
|
|
|
TextView tags = statsDialogView.findViewById(R.id.tags);
|
2019-07-23 18:22:52 +02:00
|
|
|
|
2019-07-29 17:03:36 +02:00
|
|
|
ImageButton charts = statsDialogView.findViewById(R.id.charts);
|
2019-07-28 18:13:39 +02:00
|
|
|
charts.setOnClickListener(w ->{
|
|
|
|
Intent intent = new Intent(OwnerStatusActivity.this, OwnerChartsActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2019-07-23 18:22:52 +02:00
|
|
|
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())));
|
|
|
|
|
2019-07-24 17:48:24 +02:00
|
|
|
if( statistics.getTagsTrend() != null && statistics.getTagsTrend().size() > 0 ){
|
|
|
|
Iterator it = statistics.getTagsTrend() .entrySet().iterator();
|
|
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
int i = 1;
|
|
|
|
while (it.hasNext() && i <= 10) {
|
|
|
|
Map.Entry pair = (Map.Entry)it.next();
|
|
|
|
System.out.println(pair.getKey() + " = " + pair.getValue());
|
2019-07-24 17:55:07 +02:00
|
|
|
text.append(i).append(" - ").append(pair.getKey()).append(" → ").append(pair.getValue()).append("\r\n");
|
2019-07-24 17:48:24 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
tags.setText(text.toString());
|
|
|
|
}else{
|
|
|
|
tags.setText(getString(R.string.no_tags));
|
|
|
|
}
|
|
|
|
|
2019-07-23 18:22:52 +02:00
|
|
|
stats_container.setVisibility(View.VISIBLE);
|
|
|
|
loader.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
Toasty.error(OwnerStatusActivity.this,getString(R.string.toast_error),Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2019-07-23 16:31:40 +02:00
|
|
|
}
|
2018-02-17 11:28:52 +01:00
|
|
|
}
|