diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 2bfaf8ce8636..8eaaa3179866 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -583,7 +583,7 @@ private void startComposeActivity(ComposeDestination destination, int titleId) { startActivity(composeActivity); } - private void startActivity(Class activity) { + void startActivity(Class activity) { startActivity(new Intent(getApplicationContext(), activity)); } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index af3361fc5d4b..a2bc0ab7a7ca 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -83,6 +83,8 @@ import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation; import com.owncloud.android.lib.resources.files.SearchRemoteOperation; +import com.owncloud.android.lib.resources.notifications.GetNotificationsRemoteOperation; +import com.owncloud.android.lib.resources.notifications.models.Notification; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.DownloadType; @@ -308,6 +310,7 @@ private void initUI() { setupHomeSearchToolbarWithSortAndListButtons(); mMenuButton.setOnClickListener(v -> openDrawer()); mSwitchAccountButton.setOnClickListener(v -> showManageAccountsDialog()); + mNotificationButton.setOnClickListener(v -> startActivity(NotificationsActivity.class)); fastScrollUtils.fixAppBarForFastScroll(binding.appbar.appbar, binding.rootLayout); } @@ -395,6 +398,7 @@ protected void onPostCreate(Bundle savedInstanceState) { upgradeNotificationForInstantUpload(); checkOutdatedServer(); + checkNotifications(); } private Activity getActivity() { @@ -425,6 +429,24 @@ private void checkOutdatedServer() { DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG); } } + + private void checkNotifications() { + new Thread(() -> { + try { + RemoteOperationResult> result = new GetNotificationsRemoteOperation() + .execute(clientFactory.createNextcloudClient(accountManager.getUser())); + + if (result.isSuccess() && !result.getResultData().isEmpty()) { + runOnUiThread(() -> mNotificationButton.setVisibility(View.VISIBLE)); + } else { + runOnUiThread(() -> mNotificationButton.setVisibility(View.GONE)); + } + + } catch (ClientFactory.CreationException e) { + Log_OC.e(TAG, "Could not fetch notifications!"); + } + }).start(); + } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { @@ -1153,6 +1175,8 @@ protected void onResume() { } //show in-app review dialog to user inAppReviewHelper.showInAppReview(this); + + checkNotifications(); Log_OC.v(TAG, "onResume() end"); } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java index 943aad8b25ce..9fc0b540340f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java @@ -52,6 +52,7 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable protected MaterialButton mMenuButton; protected MaterialTextView mSearchText; protected MaterialButton mSwitchAccountButton; + protected MaterialButton mNotificationButton; private AppBarLayout mAppBar; private RelativeLayout mDefaultToolbar; @@ -82,6 +83,7 @@ private void setupToolbar(boolean isHomeSearchToolbarShow, boolean showSortListB mMenuButton = findViewById(R.id.menu_button); mSearchText = findViewById(R.id.search_text); mSwitchAccountButton = findViewById(R.id.switch_account_button); + mNotificationButton = findViewById(R.id.notification_button); if (showSortListButtonGroup) { findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE); diff --git a/app/src/main/res/layout/toolbar_standard.xml b/app/src/main/res/layout/toolbar_standard.xml index cc434e6124dc..06adb9a67e34 100644 --- a/app/src/main/res/layout/toolbar_standard.xml +++ b/app/src/main/res/layout/toolbar_standard.xml @@ -197,10 +197,23 @@ android:textSize="16sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toRightOf="@id/menu_button" - app:layout_constraintRight_toLeftOf="@id/switch_account_button" + app:layout_constraintRight_toLeftOf="@id/notification_button" app:layout_constraintTop_toTopOf="parent" tools:text="Search in Nextcloud" /> + +