fedilab-Android-App/app/src/main/java/app/fedilab/android/activities/OwnerNotificationActivity.java

523 lines
25 KiB
Java
Raw Normal View History

2019-08-25 17:21:34 +02:00
/* 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;
2019-11-13 12:54:01 +01:00
import android.graphics.drawable.ColorDrawable;
2019-08-25 17:21:34 +02:00
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.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.List;
import app.fedilab.android.R;
2019-08-26 17:47:00 +02:00
import app.fedilab.android.asynctasks.RetrieveNotificationStatsAsyncTask;
2019-08-25 17:21:34 +02:00
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;
2019-08-26 17:47:00 +02:00
import app.fedilab.android.client.Entities.StatisticsNotification;
2019-08-25 17:21:34 +02:00
import app.fedilab.android.drawers.NotificationsListAdapter;
import app.fedilab.android.helper.FilterNotifications;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnRetrieveCacheNotificationsInterface;
2019-08-26 17:47:00 +02:00
import app.fedilab.android.interfaces.OnRetrieveNotificationStatsInterface;
2019-08-25 17:21:34 +02:00
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
*/
2019-08-26 17:47:00 +02:00
public class OwnerNotificationActivity extends BaseActivity implements OnRetrieveCacheNotificationsInterface, OnRetrieveNotificationStatsInterface {
2019-08-25 17:21:34 +02:00
2019-11-15 16:32:25 +01:00
LinearLayoutManager mLayoutManager;
2019-08-25 17:21:34 +02:00
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;
private int style;
private Button settings_time_from, settings_time_to;
private FilterNotifications filterNotifications;
private Date dateIni, dateEnd;
private View statsDialogView;
2019-08-26 17:47:00 +02:00
private StatisticsNotification statistics;
2019-11-15 16:32:25 +01:00
private DatePickerDialog.OnDateSetListener iniDateSetListener =
new DatePickerDialog.OnDateSetListener() {
2019-08-25 17:21:34 +02:00
2019-11-15 16:32:25 +01:00
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())));
}
};
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);
}
};
2019-08-25 17:21:34 +02:00
@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);
2019-09-06 17:55:14 +02:00
switch (theme) {
2019-08-25 17:21:34 +02:00
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
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);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
2019-09-06 17:55:14 +02:00
if (actionBar != null) {
2019-11-13 12:54:01 +01:00
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(OwnerNotificationActivity.this, R.color.cyanea_primary)));
2019-08-25 17:21:34 +02:00
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);
2019-08-25 18:31:14 +02:00
toolbarTitle.setText(getString(R.string.owner_cached_notifications));
2019-08-25 17:21:34 +02:00
}
notifications = new ArrayList<>();
RecyclerView lv_notifications = findViewById(R.id.lv_notifications);
2019-09-06 17:55:14 +02:00
mainLoader = findViewById(R.id.loader);
2019-08-25 17:21:34 +02:00
nextElementLoader = findViewById(R.id.loading_next_status);
2019-09-06 17:55:14 +02:00
textviewNoAction = findViewById(R.id.no_action);
2019-08-25 17:21:34 +02:00
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);
2019-09-06 17:55:14 +02:00
notificationsListAdapter = new NotificationsListAdapter(isOnWifi, behaviorWithAttachments, this.notifications);
2019-08-25 17:21:34 +02:00
lv_notifications.setAdapter(notificationsListAdapter);
mLayoutManager = new LinearLayoutManager(OwnerNotificationActivity.this);
lv_notifications.setLayoutManager(mLayoutManager);
2019-09-06 17:55:14 +02:00
if (theme == Helper.THEME_DARK) {
2019-08-25 17:21:34 +02:00
style = R.style.DialogDark;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2019-08-25 17:21:34 +02:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2019-08-25 17:21:34 +02:00
style = R.style.Dialog;
}
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
2019-09-06 17:55:14 +02:00
Account account = new AccountDAO(OwnerNotificationActivity.this, db).getUniqAccount(userId, instance);
2019-08-25 17:21:34 +02:00
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
swipeRefreshLayout = findViewById(R.id.swipeContainer);
2019-11-12 19:22:14 +01:00
int c1 = getResources().getColor(R.color.cyanea_accent);
int c2 = getResources().getColor(R.color.cyanea_primary_dark);
int c3 = getResources().getColor(R.color.cyanea_primary);
2019-11-12 19:08:05 +01:00
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(c3);
swipeRefreshLayout.setColorSchemeColors(
c1, c2, c1
);
2019-08-25 17:21:34 +02:00
new RetrieveNotificationsCacheAsyncTask(OwnerNotificationActivity.this, filterNotifications, null, OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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() {
2019-09-06 17:55:14 +02:00
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
2019-08-25 17:21:34 +02:00
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
2019-09-06 17:55:14 +02:00
if (dy > 0) {
2019-08-25 17:21:34 +02:00
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
2019-09-06 17:55:14 +02:00
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
2019-08-25 17:21:34 +02:00
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
2019-11-09 14:35:45 +01:00
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
2019-08-25 17:21:34 +02:00
getMenuInflater().inflate(R.menu.option_owner_cache, menu);
return true;
}
@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;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2019-08-25 17:21:34 +02:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2019-08-25 17:21:34 +02:00
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OwnerNotificationActivity.this, style);
LayoutInflater inflater = this.getLayoutInflater();
2019-08-25 18:31:14 +02:00
statsDialogView = inflater.inflate(R.layout.stats_owner_notifications, null);
2019-08-25 17:21:34 +02:00
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();
2019-09-06 17:55:14 +02:00
if (statistics == null) {
new RetrieveNotificationStatsAsyncTask(getApplicationContext(), OwnerNotificationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
2019-08-25 17:21:34 +02:00
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;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2019-08-25 17:21:34 +02:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2019-08-25 17:21:34 +02:00
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();
2019-09-06 17:55:14 +02:00
if (dateIni == null)
2019-08-25 17:21:34 +02:00
dateIni = new NotificationCacheDAO(OwnerNotificationActivity.this, db).getSmallerDate();
2019-09-06 17:55:14 +02:00
if (dateEnd == null)
2019-08-25 17:21:34 +02:00
dateEnd = new NotificationCacheDAO(OwnerNotificationActivity.this, db).getGreaterDate();
2019-09-06 17:55:14 +02:00
if (dateIni == null || dateEnd == null)
2019-08-25 17:21:34 +02:00
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);
2019-08-26 17:47:00 +02:00
settings_time_from.setText(dateInitString);
settings_time_to.setText(dateEndString);
2019-08-25 17:21:34 +02:00
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());
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();
}
})
2019-11-11 09:34:13 +01:00
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
2019-08-25 17:21:34 +02:00
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialogBuilder.create().show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onDestroy() {
super.onDestroy();
LocalBroadcastManager.getInstance(this)
.unregisterReceiver(backupFinishedReceiver);
}
2019-09-06 17:55:14 +02:00
private void displayStats() {
if (statsDialogView != null) {
2019-08-25 17:21:34 +02:00
ScrollView stats_container = statsDialogView.findViewById(R.id.stats_container);
RelativeLayout loader = statsDialogView.findViewById(R.id.loader);
2019-08-26 17:47:00 +02:00
TextView total_notifications = statsDialogView.findViewById(R.id.total_notifications);
2019-08-25 17:21:34 +02:00
TextView number_boosts = statsDialogView.findViewById(R.id.number_boosts);
2019-08-26 17:47:00 +02:00
TextView number_favourites = statsDialogView.findViewById(R.id.number_favourites);
TextView number_mentions = statsDialogView.findViewById(R.id.number_mentions);
TextView number_follows = statsDialogView.findViewById(R.id.number_follows);
TextView number_polls = statsDialogView.findViewById(R.id.number_polls);
2019-08-25 17:21:34 +02:00
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-08-26 17:47:00 +02:00
2019-08-25 17:21:34 +02:00
ImageButton charts = statsDialogView.findViewById(R.id.charts);
2019-09-06 17:55:14 +02:00
charts.setOnClickListener(w -> {
2019-08-26 18:27:23 +02:00
Intent intent = new Intent(OwnerNotificationActivity.this, OwnerNotificationChartsActivity.class);
2019-08-25 17:21:34 +02:00
startActivity(intent);
});
2019-08-26 17:47:00 +02:00
total_notifications.setText(String.valueOf(statistics.getTotal_notification()));
number_boosts.setText(String.valueOf(statistics.getNumber_reblog()));
number_favourites.setText(String.valueOf(statistics.getNumber_favourite()));
number_mentions.setText(String.valueOf(statistics.getNumber_mentions()));
number_follows.setText(String.valueOf(statistics.getNumber_follow()));
number_polls.setText(String.valueOf(statistics.getNumber_poll()));
2019-08-25 17:21:34 +02:00
first_toot_date.setText(Helper.dateToString(statistics.getFirstTootDate()));
last_toot_date.setText(Helper.dateToString(statistics.getLastTootDate()));
DecimalFormat df = new DecimalFormat("#.##");
2019-08-26 17:47:00 +02:00
frequency.setText(getString(R.string.notification_per_day, df.format(statistics.getFrequency())));
2019-08-25 17:21:34 +02:00
stats_container.setVisibility(View.VISIBLE);
loader.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
} else {
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
2019-08-25 17:21:34 +02:00
}
}
@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
2019-09-06 17:55:14 +02:00
if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) {
Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
2019-08-25 17:21:34 +02:00
swipeRefreshLayout.setRefreshing(false);
swiped = false;
flag_loading = false;
return;
}
int previousPosition = this.notifications.size();
List<Notification> notifications = apiResponse.getNotifications();
max_id = apiResponse.getMax_id();
2019-09-06 17:55:14 +02:00
flag_loading = (max_id == null);
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
2019-08-25 17:21:34 +02:00
textviewNoAction.setVisibility(View.VISIBLE);
else
textviewNoAction.setVisibility(View.GONE);
2019-09-06 17:55:14 +02:00
if (swiped) {
2019-08-25 17:21:34 +02:00
if (previousPosition > 0) {
for (int i = 0; i < previousPosition; i++) {
this.notifications.remove(0);
}
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
}
swiped = false;
}
2019-09-06 17:55:14 +02:00
if (notifications != null && notifications.size() > 0) {
2019-08-25 17:21:34 +02:00
this.notifications.addAll(notifications);
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
2019-09-06 17:55:14 +02:00
} else {
if (textviewNoAction.getVisibility() != View.VISIBLE && firstLoad) {
2019-08-25 17:21:34 +02:00
RelativeLayout no_result = findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);
}
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
}
2019-08-26 17:47:00 +02:00
@Override
public void onStats(StatisticsNotification statistics) {
this.statistics = statistics;
displayStats();
}
2019-08-25 17:21:34 +02:00
}