Search in sources :

Example 16 with Notification

use of com.keylesspalace.tusky.entity.Notification in project Tusky by Vavassor.

the class NotificationsFragment method onReblog.

@Override
public void onReblog(final boolean reblog, final int position) {
    final Notification notification = notifications.get(position).asRight();
    final Status status = notification.getStatus();
    Objects.requireNonNull(status, "Reblog on notification without status");
    timelineCases.reblog(status.getId(), reblog).observeOn(AndroidSchedulers.mainThread()).to(autoDisposable(from(this))).subscribe((newStatus) -> setReblogForStatus(status.getId(), reblog), (t) -> Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.getId(), t));
}
Also used : Status(com.keylesspalace.tusky.entity.Status) Notification(com.keylesspalace.tusky.entity.Notification)

Example 17 with Notification

use of com.keylesspalace.tusky.entity.Notification in project Tusky by Vavassor.

the class NotificationsFragment method onReply.

public void onReply(int position) {
    Notification notification = adapter.getItem(position);
    super.reply(notification.status);
}
Also used : Notification(com.keylesspalace.tusky.entity.Notification)

Example 18 with Notification

use of com.keylesspalace.tusky.entity.Notification in project Tusky by Vavassor.

the class PushNotificationClient method onMessageReceived.

private void onMessageReceived(final Context context, String message) {
    Log.v(TAG, "Notification received: " + message);
    Gson gson = new GsonBuilder().registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()).registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter()).create();
    Notification notification = gson.fromJson(message, Notification.class);
    NotificationMaker.make(context, NOTIFY_ID, notification);
}
Also used : StringWithEmojiTypeAdapter(com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) SpannedTypeAdapter(com.keylesspalace.tusky.json.SpannedTypeAdapter) Gson(com.google.gson.Gson) StringWithEmoji(com.keylesspalace.tusky.json.StringWithEmoji) Notification(com.keylesspalace.tusky.entity.Notification)

Example 19 with Notification

use of com.keylesspalace.tusky.entity.Notification in project Tusky by tuskyapp.

the class NotificationsFragment method onLoadMore.

@Override
public void onLoadMore(int position) {
    // check bounds before accessing list,
    if (notifications.size() >= position && position > 0) {
        Notification previous = notifications.get(position - 1).getAsRightOrNull();
        Notification next = notifications.get(position + 1).getAsRightOrNull();
        if (previous == null || next == null) {
            Log.e(TAG, "Failed to load more, invalid placeholder position: " + position);
            return;
        }
        sendFetchNotificationsRequest(previous.getId(), next.getId(), FetchEnd.MIDDLE, position);
        NotificationViewData notificationViewData = new NotificationViewData.Placeholder(true);
        notifications.setPairedItem(position, notificationViewData);
        adapter.updateItemWithNotify(position, notificationViewData, false);
    } else {
        Log.d(TAG, "error loading more");
    }
}
Also used : NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) Notification(com.keylesspalace.tusky.entity.Notification)

Example 20 with Notification

use of com.keylesspalace.tusky.entity.Notification in project Tusky by tuskyapp.

the class NotificationsFragment method onReblog.

@Override
public void onReblog(final boolean reblog, final int position) {
    final Notification notification = notifications.get(position).getAsRight();
    final Status status = notification.getStatus();
    timelineCases.reblogWithCallback(status, reblog, new Callback<Status>() {

        @Override
        public void onResponse(@NonNull Call<Status> call, @NonNull retrofit2.Response<Status> response) {
            if (response.isSuccessful()) {
                status.setReblogged(reblog);
                if (status.getReblog() != null) {
                    status.getReblog().setReblogged(reblog);
                }
                NotificationViewData.Concrete viewdata = (NotificationViewData.Concrete) notifications.getPairedItem(position);
                StatusViewData.Builder viewDataBuilder = new StatusViewData.Builder(viewdata.getStatusViewData());
                viewDataBuilder.setReblogged(reblog);
                NotificationViewData.Concrete newViewData = new NotificationViewData.Concrete(viewdata.getType(), viewdata.getId(), viewdata.getAccount(), viewDataBuilder.createStatusViewData(), viewdata.isExpanded());
                notifications.setPairedItem(position, newViewData);
                adapter.updateItemWithNotify(position, newViewData, false);
            }
        }

        @Override
        public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
            Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.getId(), t);
        }
    });
}
Also used : Status(com.keylesspalace.tusky.entity.Status) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) Notification(com.keylesspalace.tusky.entity.Notification) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData)

Aggregations

Notification (com.keylesspalace.tusky.entity.Notification)27 Status (com.keylesspalace.tusky.entity.Status)11 NotificationViewData (com.keylesspalace.tusky.viewdata.NotificationViewData)8 Either (com.keylesspalace.tusky.util.Either)5 StatusViewData (com.keylesspalace.tusky.viewdata.StatusViewData)4 AccountEntity (com.keylesspalace.tusky.db.AccountEntity)3 AccountManager (com.keylesspalace.tusky.db.AccountManager)2 Activity (android.app.Activity)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 SparseBooleanArray (android.util.SparseBooleanArray)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1