Skip to content

Commit

Permalink
check and show notification bell
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Sep 24, 2024
1 parent 4ecdf79 commit 3c42bc5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private void startComposeActivity(ComposeDestination destination, int titleId) {
startActivity(composeActivity);
}

private void startActivity(Class<? extends Activity> activity) {
void startActivity(Class<? extends Activity> activity) {
startActivity(new Intent(getApplicationContext(), activity));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -395,6 +398,7 @@ protected void onPostCreate(Bundle savedInstanceState) {

upgradeNotificationForInstantUpload();
checkOutdatedServer();
checkNotifications();
}

private Activity getActivity() {
Expand Down Expand Up @@ -425,6 +429,24 @@ private void checkOutdatedServer() {
DisplayUtils.showServerOutdatedSnackbar(this, Snackbar.LENGTH_LONG);
}
}

private void checkNotifications() {
new Thread(() -> {
try {
RemoteOperationResult<List<Notification>> 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) {
Expand Down Expand Up @@ -1153,6 +1175,8 @@ protected void onResume() {
}
//show in-app review dialog to user
inAppReviewHelper.showInAppReview(this);

checkNotifications();

Log_OC.v(TAG, "onResume() end");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/layout/toolbar_standard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<com.google.android.material.button.MaterialButton
android:id="@+id/notification_button"
style="@style/Widget.AppTheme.Button.IconButton"
android:layout_width="48dp"
android:layout_height="48dp"
app:cornerRadius="@dimen/button_corner_radius"
app:iconSize="20dp"
app:icon="@drawable/ic_notification"
app:iconTint="@color/fontAppbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/switch_account_button"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/switch_account_button"
style="@style/Widget.AppTheme.Button.IconButton"
Expand Down

0 comments on commit 3c42bc5

Please sign in to comment.