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;
}
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());
}
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;
}
Aggregations