|
@@ -25,7 +25,6 @@ package com.owncloud.android.ui.activity;
|
|
|
import android.accounts.Account;
|
|
|
import android.accounts.AuthenticatorException;
|
|
|
import android.accounts.OperationCanceledException;
|
|
|
-import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.PorterDuff;
|
|
|
import android.os.Bundle;
|
|
@@ -42,7 +41,6 @@ import android.widget.LinearLayout;
|
|
|
import android.widget.ProgressBar;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.authentication.AccountUtils;
|
|
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
|
@@ -69,7 +67,7 @@ import butterknife.ButterKnife;
|
|
|
import butterknife.Unbinder;
|
|
|
|
|
|
/**
|
|
|
- * Activity displaying all server side stored activity items.
|
|
|
+ * Activity displaying all server side stored notification items.
|
|
|
*/
|
|
|
public class NotificationsActivity extends FileActivity {
|
|
|
|
|
@@ -107,6 +105,8 @@ public class NotificationsActivity extends FileActivity {
|
|
|
|
|
|
private NotificationListAdapter adapter;
|
|
|
private Snackbar snackbar = null;
|
|
|
+ private OwnCloudClient client;
|
|
|
+ private Account currentAccount;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -116,14 +116,17 @@ public class NotificationsActivity extends FileActivity {
|
|
|
setContentView(R.layout.notifications_layout);
|
|
|
unbinder = ButterKnife.bind(this);
|
|
|
|
|
|
- String account;
|
|
|
- Account currentAccount;
|
|
|
- if (getIntent() != null && getIntent().getExtras() != null &&
|
|
|
- (account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT)) != null &&
|
|
|
- (currentAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext())) != null &&
|
|
|
- !account.equalsIgnoreCase(currentAccount.name)) {
|
|
|
- AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account);
|
|
|
- setAccount(AccountUtils.getCurrentOwnCloudAccount(this));
|
|
|
+ currentAccount = getAccount();
|
|
|
+
|
|
|
+ // use account from intent (opened via android notification can have a different account than current one)
|
|
|
+ if (getIntent() != null && getIntent().getExtras() != null) {
|
|
|
+ String account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
|
|
+
|
|
|
+ if (account != null && (currentAccount == null || !account.equalsIgnoreCase(currentAccount.name))) {
|
|
|
+ AccountUtils.setCurrentOwnCloudAccount(this, account);
|
|
|
+ setAccount(AccountUtils.getCurrentOwnCloudAccount(this));
|
|
|
+ currentAccount = getAccount();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// setup toolbar
|
|
@@ -136,6 +139,12 @@ public class NotificationsActivity extends FileActivity {
|
|
|
setupDrawer(R.id.nav_notifications);
|
|
|
ThemeUtils.setColoredTitle(getSupportActionBar(), getString(R.string.drawer_item_notifications), this);
|
|
|
|
|
|
+ if (currentAccount == null) {
|
|
|
+ // show error
|
|
|
+ runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
swipeListRefreshLayout.setOnRefreshListener(() -> {
|
|
|
setLoadingMessage();
|
|
|
fetchAndSetData();
|
|
@@ -157,30 +166,26 @@ public class NotificationsActivity extends FileActivity {
|
|
|
snackbar.show();
|
|
|
}
|
|
|
} else {
|
|
|
- Context context = getApplicationContext();
|
|
|
- String pushUrl = context.getResources().getString(R.string.push_server_url);
|
|
|
+ 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);
|
|
|
} else {
|
|
|
- Account account = AccountUtils.getCurrentOwnCloudAccount(context);
|
|
|
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
|
|
|
|
|
- if (account != null) {
|
|
|
- boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(account.name,
|
|
|
+ boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(currentAccount.name,
|
|
|
AccountUtils.ACCOUNT_USES_STANDARD_PASSWORD);
|
|
|
|
|
|
- if (usesOldLogin) {
|
|
|
- snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_old_login,
|
|
|
- Snackbar.LENGTH_INDEFINITE);
|
|
|
- } else {
|
|
|
- String pushValue = arbitraryDataProvider.getValue(account.name, PushUtils.KEY_PUSH);
|
|
|
+ if (usesOldLogin) {
|
|
|
+ snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_old_login,
|
|
|
+ Snackbar.LENGTH_INDEFINITE);
|
|
|
+ } else {
|
|
|
+ String pushValue = arbitraryDataProvider.getValue(currentAccount.name, PushUtils.KEY_PUSH);
|
|
|
|
|
|
- if (pushValue == null || pushValue.isEmpty()) {
|
|
|
- snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
|
|
|
- Snackbar.LENGTH_INDEFINITE);
|
|
|
- }
|
|
|
+ if (pushValue == null || pushValue.isEmpty()) {
|
|
|
+ snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
|
|
|
+ Snackbar.LENGTH_INDEFINITE);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -221,7 +226,7 @@ public class NotificationsActivity extends FileActivity {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * sets up the UI elements and loads all activity items.
|
|
|
+ * sets up the UI elements and loads all notification items.
|
|
|
*/
|
|
|
private void setupContent() {
|
|
|
emptyContentIcon.setImageResource(R.drawable.ic_notification_light_grey);
|
|
@@ -229,14 +234,22 @@ public class NotificationsActivity extends FileActivity {
|
|
|
PorterDuff.Mode.SRC_IN);
|
|
|
setLoadingMessage();
|
|
|
|
|
|
- adapter = new NotificationListAdapter(this);
|
|
|
+ try {
|
|
|
+ OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, this);
|
|
|
+ client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, this);
|
|
|
+ client.setOwnCloudVersion(AccountUtils.getServerVersion(currentAccount));
|
|
|
+
|
|
|
+ hideRefreshLayoutLoader();
|
|
|
+ } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
|
|
|
+ IOException | OperationCanceledException | AuthenticatorException e) {
|
|
|
+ Log_OC.e(TAG, "Error initializing client", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ adapter = new NotificationListAdapter(client, this);
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
|
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
|
|
- DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
|
|
|
- recyclerView.getContext(),
|
|
|
- layoutManager.getOrientation()
|
|
|
- );
|
|
|
+ DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, layoutManager.getOrientation());
|
|
|
|
|
|
recyclerView.setLayoutManager(layoutManager);
|
|
|
recyclerView.addItemDecoration(dividerItemDecoration);
|
|
@@ -256,49 +269,31 @@ public class NotificationsActivity extends FileActivity {
|
|
|
}
|
|
|
|
|
|
private void fetchAndSetData() {
|
|
|
- final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
|
|
|
- final Context context = MainApp.getAppContext();
|
|
|
-
|
|
|
Thread t = new Thread(() -> {
|
|
|
- try {
|
|
|
- if (currentAccount != null) {
|
|
|
- OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, context);
|
|
|
- OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
|
|
- getClientFor(ocAccount, MainApp.getAppContext());
|
|
|
- mClient.setOwnCloudVersion(AccountUtils.getServerVersion(currentAccount));
|
|
|
-
|
|
|
- RemoteOperation getRemoteNotificationOperation = new GetRemoteNotificationsOperation();
|
|
|
- final RemoteOperationResult result = getRemoteNotificationOperation.execute(mClient);
|
|
|
-
|
|
|
- if (result.isSuccess() && result.getNotificationData() != null) {
|
|
|
- final List<Notification> notifications = result.getNotificationData();
|
|
|
-
|
|
|
- runOnUiThread(() -> {
|
|
|
- populateList(notifications);
|
|
|
- if (notifications.size() > 0) {
|
|
|
- swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
|
|
- swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
- setEmptyContent(noResultsHeadline, noResultsMessage);
|
|
|
- swipeListRefreshLayout.setVisibility(View.GONE);
|
|
|
- swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
- });
|
|
|
+ RemoteOperation getRemoteNotificationOperation = new GetRemoteNotificationsOperation();
|
|
|
+ final RemoteOperationResult result = getRemoteNotificationOperation.execute(client);
|
|
|
+
|
|
|
+ if (result.isSuccess() && result.getNotificationData() != null) {
|
|
|
+ final List<Notification> notifications = result.getNotificationData();
|
|
|
+
|
|
|
+ runOnUiThread(() -> {
|
|
|
+ populateList(notifications);
|
|
|
+ if (notifications.size() > 0) {
|
|
|
+ swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
|
|
+ swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
} else {
|
|
|
- Log_OC.d(TAG, result.getLogMessage());
|
|
|
- // show error
|
|
|
- runOnUiThread(() -> setEmptyContent(noResultsHeadline, result.getLogMessage()));
|
|
|
+ setEmptyContent(noResultsHeadline, noResultsMessage);
|
|
|
+ swipeListRefreshLayout.setVisibility(View.GONE);
|
|
|
+ swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
-
|
|
|
- hideRefreshLayoutLoader();
|
|
|
- } else {
|
|
|
- // show error
|
|
|
- runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
|
|
|
- }
|
|
|
- } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | IOException |
|
|
|
- OperationCanceledException | AuthenticatorException e) {
|
|
|
- Log_OC.e(TAG, "Error fetching notification data", e);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Log_OC.d(TAG, result.getLogMessage());
|
|
|
+ // show error
|
|
|
+ runOnUiThread(() -> setEmptyContent(noResultsHeadline, result.getLogMessage()));
|
|
|
}
|
|
|
+
|
|
|
+ hideRefreshLayoutLoader();
|
|
|
});
|
|
|
|
|
|
t.start();
|
|
@@ -345,8 +340,10 @@ public class NotificationsActivity extends FileActivity {
|
|
|
if (emptyContentContainer != null && emptyContentMessage != null) {
|
|
|
emptyContentHeadline.setText(headline);
|
|
|
emptyContentMessage.setText(message);
|
|
|
+ emptyContentMessage.setVisibility(View.VISIBLE);
|
|
|
|
|
|
emptyContentProgressBar.setVisibility(View.GONE);
|
|
|
+ emptyContentIcon.setImageResource(R.drawable.ic_notification_light_grey);
|
|
|
emptyContentIcon.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
}
|