fedilab-Android-App/app/src/common/java/app/fedilab/android/drawers/StatusListAdapter.java

89 lines
4.0 KiB
Java
Raw Normal View History

2020-07-13 19:19:53 +02:00
package app.fedilab.android.drawers;
2020-07-13 18:55:02 +02:00
/* Copyright 2020 Thomas Schneider
2020-07-13 18:39:33 +02:00
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
2020-07-13 19:19:53 +02:00
import android.content.Intent;
2020-07-13 18:39:33 +02:00
import android.os.AsyncTask;
2020-07-13 19:19:53 +02:00
import android.os.Bundle;
2020-07-13 18:39:33 +02:00
import android.view.inputmethod.InputMethodManager;
2020-07-13 19:12:05 +02:00
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.EmojiPopup;
import com.vanniktech.emoji.one.EmojiOneProvider;
2020-07-13 19:19:53 +02:00
import app.fedilab.android.activities.OwnerNotificationChartsActivity;
2020-07-13 18:39:33 +02:00
import app.fedilab.android.asynctasks.PostActionAsyncTask;
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.android.client.API;
import app.fedilab.android.client.Entities.Reaction;
import app.fedilab.android.client.Entities.StatusDrawerParams;
2020-07-15 15:19:19 +02:00
import app.fedilab.android.client.Entities.Status;
2020-07-13 18:39:33 +02:00
import static android.content.Context.INPUT_METHOD_SERVICE;
2020-07-13 18:55:02 +02:00
public class StatusListAdapter extends BaseStatusListAdapter {
public StatusListAdapter(StatusDrawerParams statusDrawerParams) {
super(statusDrawerParams);
}
2020-07-17 16:55:04 +02:00
public void statusAddReactionClick(Status status, ViewHolder holder){
2020-07-13 18:55:02 +02:00
EmojiManager.install(new EmojiOneProvider());
final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(holder.status_add_reaction).setOnEmojiPopupDismissListener(() -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(holder.status_add_reaction.getWindowToken(), 0);
}).setOnEmojiClickListener((emoji, imageView) -> {
String emojiStr = imageView.getUnicode();
boolean alreadyAdded = false;
for (Reaction reaction : status.getReactions()) {
if (reaction.getName().compareTo(emojiStr) == 0) {
alreadyAdded = true;
reaction.setCount(reaction.getCount() - 1);
if (reaction.getCount() == 0) {
status.getReactions().remove(reaction);
2020-07-13 18:39:33 +02:00
}
notifyStatusChanged(status);
2020-07-13 18:55:02 +02:00
break;
2020-07-13 18:39:33 +02:00
}
}
2020-07-13 18:55:02 +02:00
if (!alreadyAdded) {
Reaction reaction = new Reaction();
reaction.setMe(true);
reaction.setCount(1);
reaction.setName(emojiStr);
status.getReactions().add(0, reaction);
2020-07-13 18:39:33 +02:00
notifyStatusChanged(status);
}
2020-07-13 18:55:02 +02:00
API.StatusAction statusAction;
if (type == RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS) {
statusAction = alreadyAdded ? API.StatusAction.REMOVE_REACTION : API.StatusAction.ADD_REACTION;
2020-07-13 18:39:33 +02:00
} else {
2020-07-13 18:55:02 +02:00
statusAction = alreadyAdded ? API.StatusAction.REMOVE_PLEROMA_REACTION : API.StatusAction.ADD_PLEROMA_REACTION;
2020-07-13 18:39:33 +02:00
}
2020-07-13 19:12:05 +02:00
new PostActionAsyncTask(context, statusAction, status.getId(), null, emojiStr, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
2020-07-13 18:55:02 +02:00
})
.build(holder.fake_edittext);
emojiPopup.toggle();
2020-07-13 18:39:33 +02:00
}
2020-07-15 15:19:19 +02:00
protected void notificationCharts(Status status){
2020-07-13 19:19:53 +02:00
Intent intent = new Intent(context, OwnerNotificationChartsActivity.class);
Bundle b = new Bundle();
b.putString("status_id", status.getReblog() != null ? status.getReblog().getId() : status.getId());
intent.putExtras(b);
context.startActivity(intent);
}
2020-07-13 18:55:02 +02:00
}