|
@@ -24,15 +24,10 @@
|
|
|
|
|
|
package com.owncloud.android.ui.activity;
|
|
|
|
|
|
-import android.graphics.PorterDuff;
|
|
|
import android.os.Bundle;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
-import android.widget.ImageView;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.ProgressBar;
|
|
|
-import android.widget.TextView;
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
import com.nextcloud.client.account.User;
|
|
@@ -41,6 +36,7 @@ import com.nextcloud.client.jobs.NotificationWork;
|
|
|
import com.nextcloud.client.network.ClientFactory;
|
|
|
import com.nextcloud.java.util.Optional;
|
|
|
import com.owncloud.android.R;
|
|
|
+import com.owncloud.android.databinding.NotificationsLayoutBinding;
|
|
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
|
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
|
@@ -61,12 +57,6 @@ import javax.inject.Inject;
|
|
|
|
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
-import androidx.recyclerview.widget.RecyclerView;
|
|
|
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
-import butterknife.BindString;
|
|
|
-import butterknife.BindView;
|
|
|
-import butterknife.ButterKnife;
|
|
|
-import butterknife.Unbinder;
|
|
|
|
|
|
/**
|
|
|
* Activity displaying all server side stored notification items.
|
|
@@ -75,33 +65,7 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
|
|
|
private static final String TAG = NotificationsActivity.class.getSimpleName();
|
|
|
|
|
|
- @BindView(R.id.empty_list_view)
|
|
|
- public LinearLayout emptyContentContainer;
|
|
|
-
|
|
|
- public SwipeRefreshLayout swipeListRefreshLayout;
|
|
|
-
|
|
|
- public SwipeRefreshLayout swipeEmptyListRefreshLayout;
|
|
|
-
|
|
|
- @BindView(R.id.empty_list_view_text)
|
|
|
- public TextView emptyContentMessage;
|
|
|
-
|
|
|
- @BindView(R.id.empty_list_view_headline)
|
|
|
- public TextView emptyContentHeadline;
|
|
|
-
|
|
|
- @BindView(R.id.empty_list_icon)
|
|
|
- public ImageView emptyContentIcon;
|
|
|
-
|
|
|
- @BindView(android.R.id.list)
|
|
|
- public RecyclerView recyclerView;
|
|
|
-
|
|
|
- @BindString(R.string.notifications_no_results_headline)
|
|
|
- public String noResultsHeadline;
|
|
|
-
|
|
|
- @BindString(R.string.notifications_no_results_message)
|
|
|
- public String noResultsMessage;
|
|
|
-
|
|
|
- private Unbinder unbinder;
|
|
|
-
|
|
|
+ private NotificationsLayoutBinding binding;
|
|
|
private NotificationListAdapter adapter;
|
|
|
private Snackbar snackbar;
|
|
|
private OwnCloudClient client;
|
|
@@ -114,8 +78,8 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
Log_OC.v(TAG, "onCreate() start");
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
- setContentView(R.layout.notifications_layout);
|
|
|
- unbinder = ButterKnife.bind(this);
|
|
|
+ binding = NotificationsLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ setContentView(binding.getRoot());
|
|
|
|
|
|
optionalUser = getUser();
|
|
|
|
|
@@ -137,26 +101,27 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
|
|
|
updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_notifications));
|
|
|
|
|
|
- swipeEmptyListRefreshLayout = findViewById(R.id.swipe_containing_empty);
|
|
|
- swipeListRefreshLayout = findViewById(R.id.swipe_containing_list);
|
|
|
- ThemeUtils.colorSwipeRefreshLayout(this, swipeListRefreshLayout);
|
|
|
- ThemeUtils.colorSwipeRefreshLayout(this, swipeEmptyListRefreshLayout);
|
|
|
+ ThemeUtils.colorSwipeRefreshLayout(this, binding.swipeContainingList);
|
|
|
+ ThemeUtils.colorSwipeRefreshLayout(this, binding.swipeContainingEmpty);
|
|
|
|
|
|
// setup drawer
|
|
|
setupDrawer(R.id.nav_notifications);
|
|
|
|
|
|
if (!optionalUser.isPresent()) {
|
|
|
// show error
|
|
|
- runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
|
|
|
+ runOnUiThread(() -> setEmptyContent(
|
|
|
+ getString(R.string.notifications_no_results_headline),
|
|
|
+ getString(R.string.account_not_found))
|
|
|
+ );
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- swipeListRefreshLayout.setOnRefreshListener(() -> {
|
|
|
+ binding.swipeContainingList.setOnRefreshListener(() -> {
|
|
|
setLoadingMessage();
|
|
|
fetchAndSetData();
|
|
|
});
|
|
|
|
|
|
- swipeEmptyListRefreshLayout.setOnRefreshListener(() -> {
|
|
|
+ binding.swipeContainingEmpty.setOnRefreshListener(() -> {
|
|
|
setLoadingMessage();
|
|
|
fetchAndSetData();
|
|
|
});
|
|
@@ -174,8 +139,9 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
String pushUrl = getResources().getString(R.string.push_server_url);
|
|
|
|
|
|
if (pushUrl.isEmpty()) {
|
|
|
- snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_not_implemented,
|
|
|
- Snackbar.LENGTH_INDEFINITE);
|
|
|
+ snackbar = Snackbar.make(binding.emptyList.emptyListView,
|
|
|
+ R.string.push_notifications_not_implemented,
|
|
|
+ Snackbar.LENGTH_INDEFINITE);
|
|
|
} else {
|
|
|
final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
|
|
final String accountName = optionalUser.isPresent() ? optionalUser.get().getAccountName() : "";
|
|
@@ -183,14 +149,16 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
UserAccountManager.ACCOUNT_USES_STANDARD_PASSWORD);
|
|
|
|
|
|
if (usesOldLogin) {
|
|
|
- snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_old_login,
|
|
|
- Snackbar.LENGTH_INDEFINITE);
|
|
|
+ snackbar = Snackbar.make(binding.emptyList.emptyListView,
|
|
|
+ R.string.push_notifications_old_login,
|
|
|
+ Snackbar.LENGTH_INDEFINITE);
|
|
|
} else {
|
|
|
String pushValue = arbitraryDataProvider.getValue(accountName, PushUtils.KEY_PUSH);
|
|
|
|
|
|
if (pushValue == null || pushValue.isEmpty()) {
|
|
|
- snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
|
|
|
- Snackbar.LENGTH_INDEFINITE);
|
|
|
+ snackbar = Snackbar.make(binding.emptyList.emptyListView,
|
|
|
+ R.string.push_notifications_temp_error,
|
|
|
+ Snackbar.LENGTH_INDEFINITE);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -217,21 +185,16 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
setupPushWarning();
|
|
|
}
|
|
|
|
|
|
- public void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- unbinder.unbind();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* sets up the UI elements and loads all notification items.
|
|
|
*/
|
|
|
private void setupContent() {
|
|
|
- emptyContentIcon.setImageResource(R.drawable.ic_notification);
|
|
|
+ binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_notification);
|
|
|
setLoadingMessage();
|
|
|
|
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
|
|
|
|
|
- recyclerView.setLayoutManager(layoutManager);
|
|
|
+ binding.list.setLayoutManager(layoutManager);
|
|
|
|
|
|
fetchAndSetData();
|
|
|
}
|
|
@@ -239,14 +202,18 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
@VisibleForTesting
|
|
|
public void populateList(List<Notification> notifications) {
|
|
|
adapter.setNotificationItems(notifications);
|
|
|
+ binding.loadingContent.setVisibility(View.GONE);
|
|
|
|
|
|
if (notifications.size() > 0) {
|
|
|
- swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
|
|
- swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
+ binding.swipeContainingEmpty.setVisibility(View.GONE);
|
|
|
+ binding.swipeContainingList.setVisibility(View.VISIBLE);
|
|
|
} else {
|
|
|
- setEmptyContent(noResultsHeadline, noResultsMessage);
|
|
|
- swipeListRefreshLayout.setVisibility(View.GONE);
|
|
|
- swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
+ setEmptyContent(
|
|
|
+ getString(R.string.notifications_no_results_headline),
|
|
|
+ getString(R.string.notifications_no_results_message)
|
|
|
+ );
|
|
|
+ binding.swipeContainingList.setVisibility(View.GONE);
|
|
|
+ binding.swipeContainingEmpty.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -263,7 +230,7 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
|
|
|
if (adapter == null) {
|
|
|
adapter = new NotificationListAdapter(client, this);
|
|
|
- recyclerView.setAdapter(adapter);
|
|
|
+ binding.list.setAdapter(adapter);
|
|
|
}
|
|
|
|
|
|
RemoteOperation getRemoteNotificationOperation = new GetNotificationsRemoteOperation();
|
|
@@ -276,7 +243,7 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
} else {
|
|
|
Log_OC.d(TAG, result.getLogMessage());
|
|
|
// show error
|
|
|
- runOnUiThread(() -> setEmptyContent(noResultsHeadline, result.getLogMessage()));
|
|
|
+ runOnUiThread(() -> setEmptyContent(getString(R.string.notifications_no_results_headline), result.getLogMessage()));
|
|
|
}
|
|
|
|
|
|
hideRefreshLayoutLoader();
|
|
@@ -287,8 +254,8 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
|
|
|
private void hideRefreshLayoutLoader() {
|
|
|
runOnUiThread(() -> {
|
|
|
- swipeListRefreshLayout.setRefreshing(false);
|
|
|
- swipeEmptyListRefreshLayout.setRefreshing(false);
|
|
|
+ binding.swipeContainingList.setRefreshing(false);
|
|
|
+ binding.swipeContainingEmpty.setRefreshing(false);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -302,48 +269,40 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
boolean retval = true;
|
|
|
|
|
|
- switch (item.getItemId()) {
|
|
|
- case android.R.id.home:
|
|
|
- if (isDrawerOpen()) {
|
|
|
- closeDrawer();
|
|
|
- } else {
|
|
|
- openDrawer();
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case R.id.action_empty_notifications:
|
|
|
- new DeleteAllNotificationsTask(client, this).execute();
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- retval = super.onOptionsItemSelected(item);
|
|
|
- break;
|
|
|
+ int itemId = item.getItemId();
|
|
|
+ if (itemId == android.R.id.home) {
|
|
|
+ if (isDrawerOpen()) {
|
|
|
+ closeDrawer();
|
|
|
+ } else {
|
|
|
+ openDrawer();
|
|
|
+ }
|
|
|
+ } else if (itemId == R.id.action_empty_notifications) {
|
|
|
+ new DeleteAllNotificationsTask(client, this).execute();
|
|
|
+ } else {
|
|
|
+ retval = super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
private void setLoadingMessage() {
|
|
|
- emptyContentHeadline.setText(R.string.notifications_loading_activity);
|
|
|
- emptyContentMessage.setText("");
|
|
|
- emptyContentIcon.setVisibility(View.GONE);
|
|
|
+ binding.swipeContainingEmpty.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
@VisibleForTesting
|
|
|
public void setEmptyContent(String headline, String message) {
|
|
|
- if (emptyContentContainer != null && emptyContentMessage != null) {
|
|
|
- emptyContentHeadline.setText(headline);
|
|
|
- emptyContentMessage.setText(message);
|
|
|
- emptyContentMessage.setVisibility(View.VISIBLE);
|
|
|
- emptyContentIcon.setImageResource(R.drawable.ic_notification);
|
|
|
- emptyContentIcon.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
+ binding.emptyList.emptyListViewHeadline.setText(headline);
|
|
|
+ binding.emptyList.emptyListViewText.setText(message);
|
|
|
+ binding.emptyList.emptyListIcon.setImageResource(R.drawable.ic_notification);
|
|
|
+
|
|
|
+ binding.loadingContent.setVisibility(View.GONE);
|
|
|
+ binding.emptyList.emptyListViewText.setVisibility(View.VISIBLE);
|
|
|
+ binding.emptyList.emptyListIcon.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
-
|
|
|
setDrawerMenuItemChecked(R.id.nav_notifications);
|
|
|
}
|
|
|
|
|
@@ -360,9 +319,10 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
adapter.removeNotification(holder);
|
|
|
|
|
|
if (adapter.getItemCount() == 0) {
|
|
|
- setEmptyContent(noResultsHeadline, noResultsMessage);
|
|
|
- swipeListRefreshLayout.setVisibility(View.GONE);
|
|
|
- swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
+ setEmptyContent(getString(R.string.notifications_no_results_headline), getString(R.string.notifications_no_results_message));
|
|
|
+ binding.swipeContainingList.setVisibility(View.GONE);
|
|
|
+ binding.loadingContent.setVisibility(View.GONE);
|
|
|
+ binding.swipeContainingEmpty.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -370,9 +330,10 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
|
|
|
public void onRemovedAllNotifications(boolean isSuccess) {
|
|
|
if (isSuccess) {
|
|
|
adapter.removeAllNotifications();
|
|
|
- setEmptyContent(noResultsHeadline, noResultsMessage);
|
|
|
- swipeListRefreshLayout.setVisibility(View.GONE);
|
|
|
- swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
+ setEmptyContent(getString(R.string.notifications_no_results_headline), getString(R.string.notifications_no_results_message));
|
|
|
+ binding.loadingContent.setVisibility(View.GONE);
|
|
|
+ binding.swipeContainingList.setVisibility(View.GONE);
|
|
|
+ binding.swipeContainingEmpty.setVisibility(View.VISIBLE);
|
|
|
} else {
|
|
|
DisplayUtils.showSnackMessage(this, getString(R.string.clear_notifications_failed));
|
|
|
}
|