Просмотр исходного кода

Merge pull request #1912 from nextcloud/NotificationActivity

Notification activity: account can be null
Tobias Kaminsky 7 лет назад
Родитель
Сommit
419eb04dc3

+ 47 - 60
src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java

@@ -1,4 +1,4 @@
-/**
+/*
  * Nextcloud Android client application
  *
  * @author Andy Scherzinger
@@ -127,21 +127,15 @@ public class NotificationsActivity extends FileActivity {
         setupDrawer(R.id.nav_notifications);
         ThemeUtils.setColoredTitle(getSupportActionBar(), getString(R.string.drawer_item_notifications));
 
-        swipeListRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
-            @Override
-            public void onRefresh() {
-                setLoadingMessage();
-                fetchAndSetData();
-            }
+        swipeListRefreshLayout.setOnRefreshListener(() -> {
+            setLoadingMessage();
+            fetchAndSetData();
         });
 
-        swipeEmptyListRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
-            @Override
-            public void onRefresh() {
-                setLoadingMessage();
-                fetchAndSetData();
+        swipeEmptyListRefreshLayout.setOnRefreshListener(() -> {
+            setLoadingMessage();
+            fetchAndSetData();
 
-            }
         });
 
         setupPushWarning();
@@ -164,18 +158,20 @@ public class NotificationsActivity extends FileActivity {
                 Account account = AccountUtils.getCurrentOwnCloudAccount(context);
                 ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
 
-                boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(account.name,
-                        AccountUtils.ACCOUNT_USES_STANDARD_PASSWORD);
+                if (account != null) {
+                    boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(account.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 (pushValue == null || pushValue.isEmpty()) {
-                        snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
+                    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 (pushValue == null || pushValue.isEmpty()) {
+                            snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
+                                    Snackbar.LENGTH_INDEFINITE);
+                        }
                     }
                 }
             }
@@ -254,11 +250,10 @@ public class NotificationsActivity extends FileActivity {
         final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
         final Context context = MainApp.getAppContext();
 
-        Thread t = new Thread(new Runnable() {
-            public void run() {
-                OwnCloudAccount ocAccount;
-                try {
-                    ocAccount = new OwnCloudAccount(currentAccount, context);
+        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));
@@ -269,41 +264,36 @@ public class NotificationsActivity extends FileActivity {
                     if (result.isSuccess() && result.getNotificationData() != null) {
                         final List<Notification> notifications = result.getNotificationData();
 
-                        runOnUiThread(new Runnable() {
-                            @Override
-                            public void run() {
-                                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);
-                                }
+                        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);
                             }
                         });
                     } else {
                         Log_OC.d(TAG, result.getLogMessage());
                         // show error
-                        runOnUiThread(new Runnable() {
-                            @Override
-                            public void run() {
-                                setEmptyContent(noResultsHeadline, result.getLogMessage());
-                            }
-                        });
+                        runOnUiThread(() -> setEmptyContent(noResultsHeadline, result.getLogMessage()));
                     }
 
                     hideRefreshLayoutLoader();
-                } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
-                    Log_OC.e(TAG, "Account not found", e);
-                } catch (IOException e) {
-                    Log_OC.e(TAG, "IO error", e);
-                } catch (OperationCanceledException e) {
-                    Log_OC.e(TAG, "Operation has been canceled", e);
-                } catch (AuthenticatorException e) {
-                    Log_OC.e(TAG, "Authentication Exception", e);
+                } else {
+                    // show error
+                    runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
                 }
+            } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
+                Log_OC.e(TAG, "Account not found", e);
+            } catch (IOException e) {
+                Log_OC.e(TAG, "IO error", e);
+            } catch (OperationCanceledException e) {
+                Log_OC.e(TAG, "Operation has been canceled", e);
+            } catch (AuthenticatorException e) {
+                Log_OC.e(TAG, "Authentication Exception", e);
             }
         });
 
@@ -312,12 +302,9 @@ public class NotificationsActivity extends FileActivity {
     }
 
     private void hideRefreshLayoutLoader() {
-        runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                swipeListRefreshLayout.setRefreshing(false);
-                swipeEmptyListRefreshLayout.setRefreshing(false);
-            }
+        runOnUiThread(() -> {
+            swipeListRefreshLayout.setRefreshing(false);
+            swipeEmptyListRefreshLayout.setRefreshing(false);
         });
     }
 

+ 2 - 0
src/main/res/values/strings.xml

@@ -727,6 +727,8 @@
     <string name="send">Send</string>
     <string name="share">Share</string>
     <string name="link">Link</string>
+  
+    <string name="account_not_found">Account not found!</string>
 
     <string name="screenshot_01_gridView">A safe home for all your data</string>
     <string name="screenshot_02_listView">Browse and share your files easily</string>