Add activity #274
This commit is contained in:
parent
723bb4e02f
commit
679e614334
|
@ -246,6 +246,12 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
/>
|
/>
|
||||||
|
<activity android:name="app.fedilab.android.activities.OwnerNotificationActivity"
|
||||||
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
|
android:configChanges="orientation|screenSize"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:launchMode="singleTask"
|
||||||
|
/>
|
||||||
<activity android:name="app.fedilab.android.activities.LanguageActivity"
|
<activity android:name="app.fedilab.android.activities.LanguageActivity"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden"
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
|
|
|
@ -1207,6 +1207,11 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
if( adminItem != null){
|
if( adminItem != null){
|
||||||
adminItem.setVisible(false);
|
adminItem.setVisible(false);
|
||||||
}
|
}
|
||||||
|
MenuItem notificationArchive = navigationView.getMenu().findItem(R.id.nav_archive_notifications);
|
||||||
|
if( notificationArchive != null){
|
||||||
|
notificationArchive.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
boolean display_admin_menu = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ADMIN_MENU + userId + instance, false);
|
boolean display_admin_menu = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ADMIN_MENU + userId + instance, false);
|
||||||
if( !display_admin_menu){
|
if( !display_admin_menu){
|
||||||
|
@ -1423,7 +1428,11 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
}else if( extras.getInt(Helper.INTENT_ACTION) == Helper.BACKUP_INTENT){
|
}else if( extras.getInt(Helper.INTENT_ACTION) == Helper.BACKUP_INTENT){
|
||||||
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
|
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
|
||||||
startActivity(myIntent);
|
startActivity(myIntent);
|
||||||
}else if( extras.getInt(Helper.INTENT_ACTION) == Helper.SEARCH_TAG){
|
}else if( extras.getInt(Helper.INTENT_ACTION) == Helper.BACKUP_NOTIFICATION_INTENT){
|
||||||
|
Intent myIntent = new Intent(BaseMainActivity.this, OwnerNotificationActivity.class);
|
||||||
|
startActivity(myIntent);
|
||||||
|
}
|
||||||
|
else if( extras.getInt(Helper.INTENT_ACTION) == Helper.SEARCH_TAG){
|
||||||
new SyncTimelinesAsyncTask(BaseMainActivity.this, -1, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new SyncTimelinesAsyncTask(BaseMainActivity.this, -1, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
} else if( extras.getInt(Helper.INTENT_ACTION) == Helper.REFRESH_TIMELINE){
|
} else if( extras.getInt(Helper.INTENT_ACTION) == Helper.REFRESH_TIMELINE){
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
@ -1678,6 +1687,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
|
Intent myIntent = new Intent(BaseMainActivity.this, OwnerStatusActivity.class);
|
||||||
startActivity(myIntent);
|
startActivity(myIntent);
|
||||||
return false;
|
return false;
|
||||||
|
}else if( id == R.id.nav_archive_notifications) {
|
||||||
|
Intent myIntent = new Intent(BaseMainActivity.this, OwnerNotificationActivity.class);
|
||||||
|
startActivity(myIntent);
|
||||||
|
return false;
|
||||||
}else if(id == R.id.nav_drag_timelines){
|
}else if(id == R.id.nav_drag_timelines){
|
||||||
Intent intent = new Intent(getApplicationContext(), ReorderTimelinesActivity.class);
|
Intent intent = new Intent(getApplicationContext(), ReorderTimelinesActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
|
@ -0,0 +1,573 @@
|
||||||
|
/* 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.activities;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.DatePicker;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.asynctasks.RetrieveNotificationsCacheAsyncTask;
|
||||||
|
import app.fedilab.android.client.APIResponse;
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
import app.fedilab.android.client.Entities.Notification;
|
||||||
|
import app.fedilab.android.client.Entities.Statistics;
|
||||||
|
import app.fedilab.android.drawers.NotificationsListAdapter;
|
||||||
|
import app.fedilab.android.helper.FilterNotifications;
|
||||||
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.interfaces.OnRetrieveCacheNotificationsInterface;
|
||||||
|
import app.fedilab.android.interfaces.OnRetrieveStatsInterface;
|
||||||
|
import app.fedilab.android.services.BackupNotificationInDataBaseService;
|
||||||
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
import app.fedilab.android.sqlite.NotificationCacheDAO;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 24/08/2019.
|
||||||
|
* Show owner's notifications
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class OwnerNotificationActivity extends BaseActivity implements OnRetrieveStatsInterface, OnRetrieveCacheNotificationsInterface {
|
||||||
|
|
||||||
|
|
||||||
|
private ImageView pp_actionBar;
|
||||||
|
private NotificationsListAdapter notificationsListAdapter;
|
||||||
|
private String max_id;
|
||||||
|
private List<Notification> notifications;
|
||||||
|
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||||
|
private boolean firstLoad;
|
||||||
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
private boolean swiped;
|
||||||
|
private boolean flag_loading;
|
||||||
|
LinearLayoutManager mLayoutManager;
|
||||||
|
private int style;
|
||||||
|
private Button settings_time_from, settings_time_to;
|
||||||
|
private FilterNotifications filterNotifications;
|
||||||
|
private Date dateIni, dateEnd;
|
||||||
|
private View statsDialogView;
|
||||||
|
private Statistics statistics;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
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:
|
||||||
|
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
setContentView(R.layout.activity_ower_notifications);
|
||||||
|
|
||||||
|
filterNotifications = new FilterNotifications();
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(this)
|
||||||
|
.registerReceiver(backupFinishedReceiver,
|
||||||
|
new IntentFilter(Helper.INTENT_BACKUP_FINISH));
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
if( theme == Helper.THEME_BLACK)
|
||||||
|
toolbar.setBackgroundColor(ContextCompat.getColor(OwnerNotificationActivity.this, R.color.black));
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
if( actionBar != null ){
|
||||||
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
assert inflater != null;
|
||||||
|
View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(getApplicationContext()), false);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TextView toolbarTitle = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
||||||
|
pp_actionBar = actionBar.getCustomView().findViewById(R.id.pp_actionBar);
|
||||||
|
if (theme == Helper.THEME_LIGHT){
|
||||||
|
Helper.colorizeToolbar(actionBar.getCustomView().findViewById(R.id.toolbar), R.color.black, OwnerNotificationActivity.this);
|
||||||
|
}
|
||||||
|
toolbarTitle.setText(getString(R.string.owner_cached_toots));
|
||||||
|
}
|
||||||
|
notifications = new ArrayList<>();
|
||||||
|
RecyclerView lv_notifications = findViewById(R.id.lv_notifications);
|
||||||
|
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(OwnerNotificationActivity.this);
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||||
|
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||||
|
notificationsListAdapter = new NotificationsListAdapter(isOnWifi, behaviorWithAttachments,this.notifications);
|
||||||
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
|
mLayoutManager = new LinearLayoutManager(OwnerNotificationActivity.this);
|
||||||
|
lv_notifications.setLayoutManager(mLayoutManager);
|
||||||
|
|
||||||
|
|
||||||
|
if( theme == Helper.THEME_DARK){
|
||||||
|
style = R.style.DialogDark;
|
||||||
|
}else if( theme == Helper.THEME_BLACK){
|
||||||
|
style = R.style.DialogBlack;
|
||||||
|
}else {
|
||||||
|
style = R.style.Dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
Account account = new AccountDAO(OwnerNotificationActivity.this,db).getUniqAccount(userId, instance);
|
||||||
|
|
||||||
|
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||||
|
|
||||||
|
swipeRefreshLayout = findViewById(R.id.swipeContainer);
|
||||||
|
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, null, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
switch (theme){
|
||||||
|
case Helper.THEME_LIGHT:
|
||||||
|
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
||||||
|
R.color.mastodonC2,
|
||||||
|
R.color.mastodonC3);
|
||||||
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(OwnerNotificationActivity.this, R.color.white));
|
||||||
|
break;
|
||||||
|
case Helper.THEME_DARK:
|
||||||
|
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4__,
|
||||||
|
R.color.mastodonC4,
|
||||||
|
R.color.mastodonC4);
|
||||||
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(OwnerNotificationActivity.this, R.color.mastodonC1_));
|
||||||
|
break;
|
||||||
|
case Helper.THEME_BLACK:
|
||||||
|
swipeRefreshLayout.setColorSchemeResources(R.color.dark_icon,
|
||||||
|
R.color.mastodonC2,
|
||||||
|
R.color.mastodonC3);
|
||||||
|
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(OwnerNotificationActivity.this, R.color.black_3));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
max_id = null;
|
||||||
|
firstLoad = true;
|
||||||
|
flag_loading = true;
|
||||||
|
swiped = true;
|
||||||
|
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, null, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
public void onScrolled(@NotNull 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;
|
||||||
|
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, max_id, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
nextElementLoader.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.option_owner_cache, menu);
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
if( theme == Helper.THEME_LIGHT)
|
||||||
|
Helper.colorizeIconMenu(menu, R.color.black);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
dateIni = new Date(c.getTimeInMillis());
|
||||||
|
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);
|
||||||
|
|
||||||
|
dateEnd = new Date(c.getTimeInMillis());
|
||||||
|
settings_time_to.setText(Helper.shortDateToString(new Date(c.getTimeInMillis())));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
@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(OwnerNotificationActivity.this, BackupNotificationInDataBaseService.class);
|
||||||
|
startService(backupIntent);
|
||||||
|
statistics = null;
|
||||||
|
return true;
|
||||||
|
case R.id.action_stats:
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, 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(OwnerNotificationActivity.this, style);
|
||||||
|
LayoutInflater inflater = this.getLayoutInflater();
|
||||||
|
statsDialogView = inflater.inflate(R.layout.stats_owner_toots, null);
|
||||||
|
dialogBuilder.setView(statsDialogView);
|
||||||
|
dialogBuilder
|
||||||
|
.setTitle(R.string.action_stats)
|
||||||
|
.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogBuilder.create().show();
|
||||||
|
if( statistics == null) {
|
||||||
|
new RetrieveNotificationsCacheAsyncTask(getApplicationContext(), null, null, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}else{
|
||||||
|
displayStats();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.action_filter:
|
||||||
|
sharedpreferences = getSharedPreferences(Helper.APP_PREFS, 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(OwnerNotificationActivity.this, style);
|
||||||
|
inflater = this.getLayoutInflater();
|
||||||
|
View dialogView = inflater.inflate(R.layout.filter_owner_notifications, new LinearLayout(getApplicationContext()), false);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
|
||||||
|
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
if( dateIni == null)
|
||||||
|
dateIni = new NotificationCacheDAO(OwnerNotificationActivity.this, db).getSmallerDate();
|
||||||
|
if( dateEnd == null)
|
||||||
|
dateEnd = new NotificationCacheDAO(OwnerNotificationActivity.this, db).getGreaterDate();
|
||||||
|
if( dateIni == null || dateEnd == null)
|
||||||
|
return true;
|
||||||
|
String dateInitString = Helper.shortDateToString(dateIni);
|
||||||
|
String dateEndString = Helper.shortDateToString(dateEnd);
|
||||||
|
|
||||||
|
//Initializes settings for filter
|
||||||
|
settings_time_from = dialogView.findViewById(R.id.settings_time_from);
|
||||||
|
settings_time_to = dialogView.findViewById(R.id.settings_time_to);
|
||||||
|
|
||||||
|
final CheckBox filter_boosts = dialogView.findViewById(R.id.filter_boosts);
|
||||||
|
final CheckBox filter_fav = dialogView.findViewById(R.id.filter_fav);
|
||||||
|
final CheckBox filter_mention = dialogView.findViewById(R.id.filter_mention);
|
||||||
|
final CheckBox filter_follow = dialogView.findViewById(R.id.filter_follow);
|
||||||
|
final CheckBox filter_poll = dialogView.findViewById(R.id.filter_poll);
|
||||||
|
|
||||||
|
filter_boosts.setChecked(filterNotifications.isBoost());
|
||||||
|
filter_fav.setChecked(filterNotifications.isFavorite());
|
||||||
|
filter_mention.setChecked(filterNotifications.isMention());
|
||||||
|
filter_follow.setChecked(filterNotifications.isFollow());
|
||||||
|
filter_poll.setChecked(filterNotifications.isPoll());
|
||||||
|
|
||||||
|
final Spinner filter_boost = dialogView.findViewById(R.id.filter_boost);
|
||||||
|
|
||||||
|
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(dateIni);
|
||||||
|
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(
|
||||||
|
OwnerNotificationActivity.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(
|
||||||
|
OwnerNotificationActivity.this, style, endDateSetListener, yearEnd, monthEnd, dayEnd);
|
||||||
|
settings_time_to.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dateEndPickerDialog.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogBuilder
|
||||||
|
.setTitle(R.string.action_filter)
|
||||||
|
.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
RelativeLayout no_result = findViewById(R.id.no_result);
|
||||||
|
no_result.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
filterNotifications.setBoost(filter_boosts.isChecked());
|
||||||
|
filterNotifications.setFavorite(filter_fav.isChecked());
|
||||||
|
filterNotifications.setMention(filter_mention.isChecked());
|
||||||
|
filterNotifications.setFollow(filter_follow.isChecked());
|
||||||
|
filterNotifications.setPoll(filter_poll.isChecked());
|
||||||
|
|
||||||
|
|
||||||
|
swipeRefreshLayout.setRefreshing(true);
|
||||||
|
max_id = null;
|
||||||
|
firstLoad = true;
|
||||||
|
flag_loading = true;
|
||||||
|
swiped = true;
|
||||||
|
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, null, OwnerNotificationActivity.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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogBuilder.create().show();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private BroadcastReceiver backupFinishedReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
max_id = null;
|
||||||
|
firstLoad = true;
|
||||||
|
flag_loading = true;
|
||||||
|
swiped = true;
|
||||||
|
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, null, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
LocalBroadcastManager.getInstance(this)
|
||||||
|
.unregisterReceiver(backupFinishedReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
TextView tags = statsDialogView.findViewById(R.id.tags);
|
||||||
|
|
||||||
|
ImageButton charts = statsDialogView.findViewById(R.id.charts);
|
||||||
|
charts.setOnClickListener(w ->{
|
||||||
|
Intent intent = new Intent(OwnerNotificationActivity.this, OwnerChartsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
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())));
|
||||||
|
|
||||||
|
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());
|
||||||
|
text.append(i).append(" - ").append(pair.getKey()).append(" → ").append(pair.getValue()).append("\r\n");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
tags.setText(text.toString());
|
||||||
|
}else{
|
||||||
|
tags.setText(getString(R.string.no_tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
stats_container.setVisibility(View.VISIBLE);
|
||||||
|
loader.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
Toasty.error(getApplicationContext(),getString(R.string.toast_error),Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRetrieveNotifications(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 ){
|
||||||
|
Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
swiped = false;
|
||||||
|
flag_loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int previousPosition = this.notifications.size();
|
||||||
|
List<Notification> notifications = apiResponse.getNotifications();
|
||||||
|
max_id = apiResponse.getMax_id();
|
||||||
|
flag_loading = (max_id == null );
|
||||||
|
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
else
|
||||||
|
textviewNoAction.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if( swiped ){
|
||||||
|
if (previousPosition > 0) {
|
||||||
|
for (int i = 0; i < previousPosition; i++) {
|
||||||
|
this.notifications.remove(0);
|
||||||
|
}
|
||||||
|
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
|
||||||
|
}
|
||||||
|
swiped = false;
|
||||||
|
}
|
||||||
|
if( notifications != null && notifications.size() > 0) {
|
||||||
|
this.notifications.addAll(notifications);
|
||||||
|
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
|
||||||
|
}else {
|
||||||
|
if( textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
|
||||||
|
RelativeLayout no_result = findViewById(R.id.no_result);
|
||||||
|
no_result.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
firstLoad = false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
/* 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 java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.API;
|
||||||
|
import app.fedilab.android.client.APIResponse;
|
||||||
|
import app.fedilab.android.client.Entities.Notification;
|
||||||
|
import app.fedilab.android.helper.FilterNotifications;
|
||||||
|
import app.fedilab.android.interfaces.OnRetrieveCacheNotificationsInterface;
|
||||||
|
import app.fedilab.android.sqlite.NotificationCacheDAO;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 28/04/2019
|
||||||
|
* Retrieves notifications on the instance
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RetrieveNotificationsCacheAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
|
||||||
|
private APIResponse apiResponse;
|
||||||
|
private String max_id;
|
||||||
|
private OnRetrieveCacheNotificationsInterface listener;
|
||||||
|
private WeakReference<Context> contextReference;
|
||||||
|
private FilterNotifications filterNotifications;
|
||||||
|
|
||||||
|
public RetrieveNotificationsCacheAsyncTask(Context context, FilterNotifications filterNotifications, String max_id, OnRetrieveCacheNotificationsInterface onRetrieveNotificationsInterface){
|
||||||
|
this.contextReference = new WeakReference<>(context);
|
||||||
|
this.max_id = max_id;
|
||||||
|
this.listener = onRetrieveNotificationsInterface;
|
||||||
|
this.filterNotifications = filterNotifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
API api;
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
List<Notification> notifications = new NotificationCacheDAO(contextReference.get(), db).getNotificationsFromID(filterNotifications, max_id);
|
||||||
|
apiResponse = new APIResponse();
|
||||||
|
apiResponse.setNotifications(notifications);
|
||||||
|
if( notifications != null && notifications.size() > 0 ) {
|
||||||
|
apiResponse.setMax_id(notifications.get(notifications.size() - 1).getId());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
listener.onRetrieveNotifications(apiResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
/* 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.helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 24/08/2019.
|
||||||
|
* Helper class for filtering notifications
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FilterNotifications {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private boolean favorite = true;
|
||||||
|
private boolean boost = true;
|
||||||
|
private boolean follow = true;
|
||||||
|
private boolean poll = true;
|
||||||
|
private boolean mention = true;
|
||||||
|
|
||||||
|
|
||||||
|
private String dateIni = null;
|
||||||
|
private String dateEnd = null;
|
||||||
|
|
||||||
|
public boolean isFavorite() {
|
||||||
|
return favorite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFavorite(boolean favorite) {
|
||||||
|
this.favorite = favorite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBoost() {
|
||||||
|
return boost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoost(boolean boost) {
|
||||||
|
this.boost = boost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFollow() {
|
||||||
|
return follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFollow(boolean follow) {
|
||||||
|
this.follow = follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPoll() {
|
||||||
|
return poll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoll(boolean poll) {
|
||||||
|
this.poll = poll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMention() {
|
||||||
|
return mention;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMention(boolean mention) {
|
||||||
|
this.mention = mention;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDateIni() {
|
||||||
|
return dateIni;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateIni(String dateIni) {
|
||||||
|
this.dateIni = dateIni;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDateEnd() {
|
||||||
|
return dateEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateEnd(String dateEnd) {
|
||||||
|
this.dateEnd = dateEnd;
|
||||||
|
}
|
||||||
|
}
|
|
@ -313,6 +313,7 @@ public class Helper {
|
||||||
public static final int SEARCH_REMOTE = 9;
|
public static final int SEARCH_REMOTE = 9;
|
||||||
public static final int RELOAD_MYVIDEOS = 10;
|
public static final int RELOAD_MYVIDEOS = 10;
|
||||||
public static final int REFRESH_TIMELINE = 11;
|
public static final int REFRESH_TIMELINE = 11;
|
||||||
|
public static final int BACKUP_NOTIFICATION_INTENT = 12;
|
||||||
//Settings
|
//Settings
|
||||||
public static final int TOOTS_PER_PAGE = 20;
|
public static final int TOOTS_PER_PAGE = 20;
|
||||||
public static final int ACCOUNTS_PER_PAGE = 20;
|
public static final int ACCOUNTS_PER_PAGE = 20;
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* Copyright 2017 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.APIResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 24/08/2019.
|
||||||
|
* Interface when notifications have been retrieved
|
||||||
|
*/
|
||||||
|
public interface OnRetrieveCacheNotificationsInterface {
|
||||||
|
void onRetrieveNotifications(APIResponse apiResponse);
|
||||||
|
}
|
|
@ -143,7 +143,7 @@ public class BackupNotificationInDataBaseService extends IntentService {
|
||||||
}
|
}
|
||||||
message = getString(R.string.data_backup_success, String.valueOf(backupNotifications.size()));
|
message = getString(R.string.data_backup_success, String.valueOf(backupNotifications.size()));
|
||||||
Intent mainActivity = new Intent(BackupNotificationInDataBaseService.this, MainActivity.class);
|
Intent mainActivity = new Intent(BackupNotificationInDataBaseService.this, MainActivity.class);
|
||||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_INTENT);
|
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.BACKUP_NOTIFICATION_INTENT);
|
||||||
String title = getString(R.string.data_backup_toots, account.getAcct());
|
String title = getString(R.string.data_backup_toots, account.getAcct());
|
||||||
if(finalToastMessage) {
|
if(finalToastMessage) {
|
||||||
Helper.notify_user(getApplicationContext(), account, mainActivity, BitmapFactory.decodeResource(getResources(),
|
Helper.notify_user(getApplicationContext(), account, mainActivity, BitmapFactory.decodeResource(getResources(),
|
||||||
|
|
|
@ -33,6 +33,7 @@ import app.fedilab.android.client.Entities.Notification;
|
||||||
import app.fedilab.android.client.Entities.Statistics;
|
import app.fedilab.android.client.Entities.Statistics;
|
||||||
import app.fedilab.android.client.Entities.Status;
|
import app.fedilab.android.client.Entities.Status;
|
||||||
import app.fedilab.android.client.Entities.Tag;
|
import app.fedilab.android.client.Entities.Tag;
|
||||||
|
import app.fedilab.android.helper.FilterNotifications;
|
||||||
import app.fedilab.android.helper.FilterToots;
|
import app.fedilab.android.helper.FilterToots;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
|
|
||||||
|
@ -94,6 +95,58 @@ public class NotificationCacheDAO {
|
||||||
return last_id;
|
return last_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all cached notifications in db after filter
|
||||||
|
* @return stored notifications List<Notification>
|
||||||
|
*/
|
||||||
|
public List<Notification> getNotificationsFromID(FilterNotifications filterNotifications, String max_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);
|
||||||
|
//That the basic selection for all toots
|
||||||
|
StringBuilder selection = new StringBuilder( Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
|
||||||
|
if( max_id != null)
|
||||||
|
selection.append(" AND " + Sqlite.COL_NOTIFICATION_ID + " < '").append(max_id).append("'");
|
||||||
|
//BOOST
|
||||||
|
if(filterNotifications.isBoost() || filterNotifications.isFavorite() || filterNotifications.isFollow() ||filterNotifications.isMention() || filterNotifications.isPoll() ){
|
||||||
|
selection.append(" AND ( ");
|
||||||
|
if (filterNotifications.isBoost() ) {
|
||||||
|
selection.append(Sqlite.COL_TYPE + "='boost' OR ");
|
||||||
|
}
|
||||||
|
if (filterNotifications.isPoll() ) {
|
||||||
|
selection.append(Sqlite.COL_TYPE + "='poll' OR ");
|
||||||
|
}
|
||||||
|
if (filterNotifications.isFollow() ) {
|
||||||
|
selection.append(Sqlite.COL_TYPE + "='follow' OR ");
|
||||||
|
}
|
||||||
|
if (filterNotifications.isMention() ) {
|
||||||
|
selection.append(Sqlite.COL_TYPE + "='mention' OR ");
|
||||||
|
}
|
||||||
|
if (filterNotifications.isFavorite() ) {
|
||||||
|
selection.append(Sqlite.COL_TYPE + "='favorite' OR ");
|
||||||
|
}
|
||||||
|
String selectionStr = selection.toString().substring(0, selection.toString().length()-3);
|
||||||
|
selection = new StringBuilder(selectionStr);
|
||||||
|
selection.append(") ");
|
||||||
|
}
|
||||||
|
if( filterNotifications.getDateIni() != null)
|
||||||
|
selection.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(filterNotifications.getDateIni()).append("'");
|
||||||
|
|
||||||
|
if( filterNotifications.getDateEnd() != null)
|
||||||
|
selection.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(filterNotifications.getDateEnd()).append("'");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Cursor c = db.query(Sqlite.TABLE_NOTIFICATION_CACHE, null, selection.toString(), null, null, null, Sqlite.COL_CREATED_AT + " DESC", "40");
|
||||||
|
return cursorToListNotifications(c);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------- INSERTIONS -------
|
//------- INSERTIONS -------
|
||||||
/**
|
/**
|
||||||
* Insert a status in database
|
* Insert a status in database
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.drawerlayout.widget.DrawerLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/drawer_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
>
|
||||||
|
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context="app.fedilab.android.activities.OwnerStatusActivity">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/appBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
>
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
app:layout_scrollFlags="scroll|enterAlways"
|
||||||
|
app:popupTheme="?attr/popupOverlay"/>
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/main_app_container"
|
||||||
|
android:paddingLeft="@dimen/fab_margin"
|
||||||
|
android:paddingRight="@dimen/fab_margin"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
|
tools:context="app.fedilab.android.activities.OwnerStatusActivity"
|
||||||
|
>
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:id="@+id/swipeContainer"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/lv_notifications"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
|
/>
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/no_action"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:padding="10dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textStyle="italic|bold"
|
||||||
|
android:typeface="serif"
|
||||||
|
android:text="@string/owner_cached_toots_empty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/no_result"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:padding="10dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textStyle="italic|bold"
|
||||||
|
android:typeface="serif"
|
||||||
|
android:text="@string/filter_no_result"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<!-- 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>
|
||||||
|
<!-- Loader for next status -->
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/loading_next_status"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_gravity="bottom|center_horizontal"
|
||||||
|
android:gravity="bottom|center_horizontal"
|
||||||
|
android:layout_height="20dp">
|
||||||
|
<ProgressBar
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:indeterminate="true" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
||||||
|
</androidx.drawerlayout.widget.DrawerLayout>
|
|
@ -0,0 +1,98 @@
|
||||||
|
<?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>.
|
||||||
|
-->
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
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">
|
||||||
|
<LinearLayout
|
||||||
|
style="?attr/shapeBorder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingBottom="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<TextView
|
||||||
|
android:text="@string/settings_time_from"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<Button
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:id="@+id/settings_time_from"
|
||||||
|
style="?attr/borderlessColored"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:text="@string/settings_time_to"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<Button
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
style="?attr/borderlessColored"
|
||||||
|
android:id="@+id/settings_time_to"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/filter_boosts"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/reblog"
|
||||||
|
android:checked="true"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/filter_fav"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/favourite"
|
||||||
|
android:checked="true"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/filter_mention"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/mention"
|
||||||
|
android:checked="true"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/filter_follow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/follow"
|
||||||
|
android:checked="true"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/filter_poll"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="@string/poll"
|
||||||
|
android:checked="true"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
|
@ -39,6 +39,10 @@
|
||||||
android:id="@+id/nav_archive"
|
android:id="@+id/nav_archive"
|
||||||
android:icon="@drawable/ic_archive"
|
android:icon="@drawable/ic_archive"
|
||||||
android:title="@string/owner_cached_toots" />
|
android:title="@string/owner_cached_toots" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_archive_notifications"
|
||||||
|
android:icon="@drawable/ic_archive"
|
||||||
|
android:title="@string/owner_cached_notifications" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_bookmarks"
|
android:id="@+id/nav_bookmarks"
|
||||||
android:icon="@drawable/ic_bookmark_menu"
|
android:icon="@drawable/ic_bookmark_menu"
|
||||||
|
|
|
@ -442,6 +442,7 @@
|
||||||
<string name="action_sync">Synchronize</string>
|
<string name="action_sync">Synchronize</string>
|
||||||
<string name="action_filter">Filter</string>
|
<string name="action_filter">Filter</string>
|
||||||
<string name="owner_cached_toots">Your toots</string>
|
<string name="owner_cached_toots">Your toots</string>
|
||||||
|
<string name="owner_cached_notifications">Your notifications</string>
|
||||||
<string name="v_public">Public</string>
|
<string name="v_public">Public</string>
|
||||||
<string name="v_unlisted">Unlisted</string>
|
<string name="v_unlisted">Unlisted</string>
|
||||||
<string name="v_private">Private</string>
|
<string name="v_private">Private</string>
|
||||||
|
|
Loading…
Reference in New Issue