Search in sources :

Example 1 with BadgeDrawableBuilder

use of com.ichi2.ui.BadgeDrawableBuilder in project Anki-Android by ankidroid.

the class DeckPicker method displaySyncBadge.

@VisibleForTesting
protected void displaySyncBadge(Menu menu) {
    MenuItem syncMenu = menu.findItem(R.id.action_sync);
    SyncStatus syncStatus = SyncStatus.getSyncStatus(this::getCol);
    switch(syncStatus) {
        case BADGE_DISABLED:
        case NO_CHANGES:
        case INCONCLUSIVE:
            BadgeDrawableBuilder.removeBadge(syncMenu);
            syncMenu.setTitle(R.string.button_sync);
            break;
        case HAS_CHANGES:
            // Light orange icon
            new BadgeDrawableBuilder(getResources()).withColor(ContextCompat.getColor(this, R.color.badge_warning)).replaceBadge(syncMenu);
            syncMenu.setTitle(R.string.button_sync);
            break;
        case NO_ACCOUNT:
        case FULL_SYNC:
            if (syncStatus == SyncStatus.NO_ACCOUNT) {
                syncMenu.setTitle(R.string.sync_menu_title_no_account);
            } else if (syncStatus == SyncStatus.FULL_SYNC) {
                syncMenu.setTitle(R.string.sync_menu_title_full_sync);
            }
            // Orange-red icon with exclamation mark
            new BadgeDrawableBuilder(getResources()).withText('!').withColor(ContextCompat.getColor(this, R.color.badge_error)).replaceBadge(syncMenu);
            break;
        default:
            Timber.w("Unhandled sync status: %s", syncStatus);
            syncMenu.setTitle(R.string.sync_title);
            break;
    }
}
Also used : SyncStatus(com.ichi2.utils.SyncStatus) MenuItem(android.view.MenuItem) BadgeDrawableBuilder(com.ichi2.ui.BadgeDrawableBuilder) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 2 with BadgeDrawableBuilder

use of com.ichi2.ui.BadgeDrawableBuilder in project AnkiChinaAndroid by ankichinateam.

the class DeckPickerFragment method displaySyncBadge.

private void displaySyncBadge(Menu menu) {
    MenuItem syncMenu = menu.findItem(R.id.action_sync);
    SyncStatus syncStatus = SyncStatus.getSyncStatus(getAnkiActivity()::getCol);
    Timber.d("SyncStatus:" + syncStatus);
    switch(syncStatus) {
        case BADGE_DISABLED:
        case NO_CHANGES:
        case INCONCLUSIVE:
            BadgeDrawableBuilder.removeBadge(syncMenu);
            syncMenu.setTitle(R.string.sync_menu_title);
            break;
        case HAS_CHANGES:
            // Light orange icon
            new BadgeDrawableBuilder(getResources()).withColor(ContextCompat.getColor(getAnkiActivity(), R.color.badge_warning)).replaceBadge(syncMenu);
            syncMenu.setTitle(R.string.sync_menu_title);
            break;
        case NO_ACCOUNT:
        case FULL_SYNC:
            if (syncStatus == SyncStatus.NO_ACCOUNT) {
                syncMenu.setTitle(R.string.sync_menu_title_no_account);
            } else if (syncStatus == SyncStatus.FULL_SYNC) {
                syncMenu.setTitle(R.string.sync_menu_title_full_sync);
            }
            // Orange-red icon with exclamation mark
            new BadgeDrawableBuilder(getResources()).withText('!').withColor(ContextCompat.getColor(getAnkiActivity(), R.color.badge_error)).replaceBadge(syncMenu);
            break;
        default:
            Timber.w("Unhandled sync status: %s", syncStatus);
            syncMenu.setTitle(R.string.sync_title);
            break;
    }
}
Also used : SyncStatus(com.ichi2.utils.SyncStatus) MenuItem(android.view.MenuItem) BadgeDrawableBuilder(com.ichi2.ui.BadgeDrawableBuilder)

Aggregations

MenuItem (android.view.MenuItem)2 BadgeDrawableBuilder (com.ichi2.ui.BadgeDrawableBuilder)2 SyncStatus (com.ichi2.utils.SyncStatus)2 VisibleForTesting (androidx.annotation.VisibleForTesting)1