Search in sources :

Example 1 with BookAction

use of com.orgzly.android.db.entity.BookAction in project orgzly-android by orgzly.

the class TestUtils method sync.

public Map<String, BookNamesake> sync() {
    try {
        Map<String, BookNamesake> nameGroups = SyncService.groupAllNotebooksByName(dataRepository);
        for (BookNamesake group : nameGroups.values()) {
            BookAction action = SyncService.syncNamesake(dataRepository, group);
            dataRepository.setBookLastActionAndSyncStatus(group.getBook().getBook().getId(), action, group.getStatus().toString());
        }
        return nameGroups;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : BookAction(com.orgzly.android.db.entity.BookAction) BookNamesake(com.orgzly.android.sync.BookNamesake) IOException(java.io.IOException)

Example 2 with BookAction

use of com.orgzly.android.db.entity.BookAction in project orgzly-android by orgzly.

the class SyncStatusBroadcastReceiver method createSyncFailedNotification.

private void createSyncFailedNotification(Context context, SyncStatus status) {
    PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannels.SYNC_FAILED).setAutoCancel(true).setSmallIcon(R.drawable.ic_logo_for_notification).setContentTitle(context.getString(R.string.syncing_failed_title)).setColor(ContextCompat.getColor(context, R.color.notification)).setContentIntent(openAppPendingIntent);
    if (status.type == SyncStatus.Type.FAILED) {
        builder.setContentText(status.message);
    } else {
        // FIXME: ANR reported
        List<BookView> books = dataRepository.getBooks();
        StringBuilder sb = new StringBuilder();
        for (BookView book : books) {
            BookAction action = book.getBook().getLastAction();
            if (action != null && action.getType() == BookAction.Type.ERROR) {
                sb.append(book.getBook().getName()).append(": ").append(action.getMessage()).append("\n");
            }
        }
        String message = sb.toString().trim();
        if (message.length() == 0) {
            /* no error, don't show the notification */
            return;
        }
        builder.setContentText(message);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    }
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Notifications.SYNC_FAILED_ID, builder.build());
}
Also used : BookAction(com.orgzly.android.db.entity.BookAction) NotificationManager(android.app.NotificationManager) NotificationCompat(androidx.core.app.NotificationCompat) BookView(com.orgzly.android.db.entity.BookView) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) MainActivity(com.orgzly.android.ui.main.MainActivity)

Example 3 with BookAction

use of com.orgzly.android.db.entity.BookAction in project orgzly-android by orgzly.

the class BookUtils method replaceWithLastActionError.

private static CharSequence replaceWithLastActionError(Context context, Book book, CharSequence str) {
    BookAction action = book.getLastAction();
    if (action != null && action.getType() == BookAction.Type.ERROR) {
        SpannableStringBuilder builder = new SpannableStringBuilder(action.getMessage());
        /* Get error color attribute. */
        int color = ExtensionsKt.styledAttributes(context, new int[] { R.attr.text_error_color }, arr -> arr.getColor(0, 0));
        /* Set error color. */
        builder.setSpan(new ForegroundColorSpan(color), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return builder;
    }
    return str;
}
Also used : BookAction(com.orgzly.android.db.entity.BookAction) ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

BookAction (com.orgzly.android.db.entity.BookAction)3 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 NotificationCompat (androidx.core.app.NotificationCompat)1 BookView (com.orgzly.android.db.entity.BookView)1 BookNamesake (com.orgzly.android.sync.BookNamesake)1 MainActivity (com.orgzly.android.ui.main.MainActivity)1 IOException (java.io.IOException)1