2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.drawers;
|
2019-01-14 16:03:10 +01:00
|
|
|
/* Copyright 2019 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2019-01-14 16:03:10 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2019-01-14 16:03:10 +01:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2019-01-14 16:03:10 +01:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
2019-09-27 19:02:37 +02:00
|
|
|
import android.app.Activity;
|
2019-09-30 19:18:44 +02:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2019-01-14 16:03:10 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2019-09-30 19:18:44 +02:00
|
|
|
import android.os.Build;
|
2019-01-14 16:03:10 +01:00
|
|
|
import android.os.Bundle;
|
2020-08-09 17:52:47 +02:00
|
|
|
import android.os.CountDownTimer;
|
2019-09-30 19:18:44 +02:00
|
|
|
import android.text.Html;
|
2019-09-27 19:51:20 +02:00
|
|
|
import android.text.InputType;
|
|
|
|
import android.text.TextWatcher;
|
2019-01-14 16:03:10 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-09-27 19:51:20 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.Button;
|
2019-09-30 19:18:44 +02:00
|
|
|
import android.widget.DatePicker;
|
2019-09-27 19:51:20 +02:00
|
|
|
import android.widget.EditText;
|
2019-09-30 19:18:44 +02:00
|
|
|
import android.widget.ImageButton;
|
2019-01-14 16:03:10 +01:00
|
|
|
import android.widget.ImageView;
|
2019-01-15 14:43:56 +01:00
|
|
|
import android.widget.LinearLayout;
|
2019-01-14 16:03:10 +01:00
|
|
|
import android.widget.TextView;
|
2019-09-30 19:18:44 +02:00
|
|
|
import android.widget.TimePicker;
|
2019-01-14 16:03:10 +01:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
|
|
|
import androidx.cardview.widget.CardView;
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
2020-07-06 11:48:59 +02:00
|
|
|
import androidx.core.app.ActivityOptionsCompat;
|
2019-11-15 16:32:25 +01:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2019-01-14 16:03:10 +01:00
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
import com.bumptech.glide.load.resource.bitmap.FitCenter;
|
|
|
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
2019-11-15 16:32:25 +01:00
|
|
|
import com.bumptech.glide.request.RequestOptions;
|
2019-09-30 19:18:44 +02:00
|
|
|
import com.github.stom79.mytransl.MyTransL;
|
|
|
|
import com.github.stom79.mytransl.client.HttpsConnectionException;
|
|
|
|
import com.github.stom79.mytransl.client.Results;
|
|
|
|
import com.github.stom79.mytransl.translate.Translate;
|
2019-09-28 10:16:47 +02:00
|
|
|
import com.smarteist.autoimageslider.IndicatorAnimations;
|
|
|
|
import com.smarteist.autoimageslider.SliderAnimations;
|
|
|
|
import com.smarteist.autoimageslider.SliderView;
|
2019-01-15 14:43:56 +01:00
|
|
|
import com.varunest.sparkbutton.SparkButton;
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-09-28 10:16:47 +02:00
|
|
|
import java.lang.ref.WeakReference;
|
2019-01-14 16:03:10 +01:00
|
|
|
import java.util.ArrayList;
|
2019-09-30 19:18:44 +02:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.GregorianCalendar;
|
2019-01-14 16:03:10 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.activities.MainActivity;
|
2019-09-29 17:55:10 +02:00
|
|
|
import app.fedilab.android.activities.PixelfedComposeActivity;
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.activities.ShowAccountActivity;
|
|
|
|
import app.fedilab.android.activities.ShowConversationActivity;
|
2019-10-09 18:49:33 +02:00
|
|
|
import app.fedilab.android.activities.SlideMediaActivity;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.activities.TootActivity;
|
2019-09-30 19:18:44 +02:00
|
|
|
import app.fedilab.android.activities.TootInfoActivity;
|
|
|
|
import app.fedilab.android.asynctasks.PostActionAsyncTask;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.asynctasks.PostStatusAsyncTask;
|
2019-09-28 08:49:57 +02:00
|
|
|
import app.fedilab.android.asynctasks.RetrieveContextAsyncTask;
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
|
|
|
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.API;
|
|
|
|
import app.fedilab.android.client.APIResponse;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.client.Entities.Account;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.Entities.Emojis;
|
|
|
|
import app.fedilab.android.client.Entities.Error;
|
|
|
|
import app.fedilab.android.client.Entities.Notification;
|
|
|
|
import app.fedilab.android.client.Entities.Status;
|
2020-03-07 08:46:48 +01:00
|
|
|
import app.fedilab.android.client.Entities.StatusDrawerParams;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.helper.CrossActions;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.helper.MastalabAutoCompleteTextView;
|
2019-11-10 15:05:14 +01:00
|
|
|
import app.fedilab.android.helper.ThemeHelper;
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.interfaces.OnPostActionInterface;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
|
2019-09-28 08:49:57 +02:00
|
|
|
import app.fedilab.android.interfaces.OnRetrieveContextInterface;
|
2019-11-15 16:32:25 +01:00
|
|
|
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
|
2019-09-30 19:18:44 +02:00
|
|
|
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.interfaces.OnRetrieveSearcAccountshInterface;
|
|
|
|
import app.fedilab.android.interfaces.OnRetrieveSearchInterface;
|
2019-09-30 19:18:44 +02:00
|
|
|
import app.fedilab.android.jobs.ScheduledBoostsSyncJob;
|
2019-09-27 19:51:20 +02:00
|
|
|
import app.fedilab.android.sqlite.AccountDAO;
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.sqlite.Sqlite;
|
|
|
|
import app.fedilab.android.sqlite.StatusCacheDAO;
|
2019-09-30 19:18:44 +02:00
|
|
|
import app.fedilab.android.sqlite.StatusStoredDAO;
|
|
|
|
import app.fedilab.android.sqlite.TempMuteDAO;
|
2019-01-14 16:03:10 +01:00
|
|
|
import es.dmoral.toasty.Toasty;
|
2020-08-09 17:52:47 +02:00
|
|
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
2019-05-18 11:10:30 +02:00
|
|
|
|
2019-09-27 19:51:20 +02:00
|
|
|
import static android.content.Context.MODE_PRIVATE;
|
2019-09-30 19:18:44 +02:00
|
|
|
import static app.fedilab.android.activities.BaseMainActivity.mutedAccount;
|
2019-09-27 19:02:37 +02:00
|
|
|
import static app.fedilab.android.activities.BaseMainActivity.social;
|
2019-01-15 11:00:54 +01:00
|
|
|
|
2019-01-14 16:03:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 14/01/2019.
|
|
|
|
* Adapter for pixelfed drawer
|
|
|
|
*/
|
2020-06-16 18:23:13 +02:00
|
|
|
public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements OnPostActionInterface, OnRetrieveEmojiInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface, OnRetrieveSearcAccountshInterface, OnRetrieveContextInterface, OnRetrieveFeedsInterface {
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
private static final int DISPLAYED_STATUS = 1;
|
|
|
|
private final int HIDDEN_STATUS = 0;
|
2021-01-18 19:00:43 +01:00
|
|
|
private final List<Status> statuses;
|
|
|
|
private final PixelfedListAdapter pixelfedListAdapter;
|
|
|
|
private final RetrieveFeedsAsyncTask.Type type;
|
2021-01-19 17:43:51 +01:00
|
|
|
private Context context;
|
2019-09-27 19:51:20 +02:00
|
|
|
private MastalabAutoCompleteTextView comment_content;
|
|
|
|
private String in_reply_to_status;
|
|
|
|
private String visibility;
|
2019-09-30 19:18:44 +02:00
|
|
|
private boolean redraft = false;
|
|
|
|
private Status toot;
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public PixelfedListAdapter(RetrieveFeedsAsyncTask.Type type, List<Status> statuses) {
|
2019-01-14 16:03:10 +01:00
|
|
|
super();
|
|
|
|
this.statuses = statuses;
|
2019-01-15 14:43:56 +01:00
|
|
|
this.type = type;
|
2019-01-14 18:16:45 +01:00
|
|
|
pixelfedListAdapter = this;
|
2019-01-14 16:03:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return statuses.size();
|
|
|
|
}
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
private Status getItemAt(int position) {
|
|
|
|
if (statuses.size() > position)
|
2019-01-14 16:03:10 +01:00
|
|
|
return statuses.get(position);
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-28 08:49:57 +02:00
|
|
|
|
2019-01-14 16:03:10 +01:00
|
|
|
@Override
|
2019-09-28 18:08:07 +02:00
|
|
|
public void onRetrieveContext(APIResponse apiResponse) {
|
2019-11-15 16:32:25 +01:00
|
|
|
if (apiResponse.getError() != null) {
|
2019-01-14 16:03:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-09-28 18:08:07 +02:00
|
|
|
List<Status> statuses = apiResponse.getContext().getDescendants();
|
2019-09-29 15:02:49 +02:00
|
|
|
|
2019-09-27 18:52:42 +02:00
|
|
|
String targetedId = apiResponse.getTargetedId();
|
2019-09-29 15:02:49 +02:00
|
|
|
int position = 0;
|
2019-11-15 16:32:25 +01:00
|
|
|
for (Status tl : this.statuses) {
|
|
|
|
if (tl.getId().equals(targetedId)) {
|
2019-09-29 15:02:49 +02:00
|
|
|
this.statuses.get(position).setCommentsFetched(true);
|
|
|
|
this.statuses.get(position).setComments(statuses);
|
|
|
|
notifyStatusChanged(this.statuses.get(position));
|
2019-09-27 18:52:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-09-29 15:02:49 +02:00
|
|
|
position++;
|
2019-09-27 18:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-28 18:08:07 +02:00
|
|
|
|
2019-09-27 19:51:20 +02:00
|
|
|
@Override
|
|
|
|
public void onPostStatusAction(APIResponse apiResponse) {
|
2019-09-28 08:49:57 +02:00
|
|
|
if (apiResponse.getError() != null) {
|
2020-01-19 10:29:35 +01:00
|
|
|
if (apiResponse.getError().getError().length() < 100) {
|
|
|
|
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
2019-09-28 08:49:57 +02:00
|
|
|
} else {
|
2020-01-19 10:29:35 +01:00
|
|
|
Toasty.error(context, context.getString(R.string.long_api_error, "\ud83d\ude05"), Toast.LENGTH_LONG).show();
|
2019-09-28 08:49:57 +02:00
|
|
|
}
|
2020-01-19 10:29:35 +01:00
|
|
|
return;
|
2019-09-28 08:49:57 +02:00
|
|
|
}
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
|
|
|
|
comment_content = null;
|
|
|
|
if (apiResponse.getError() == null) {
|
|
|
|
boolean display_confirm = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONFIRM, true);
|
|
|
|
if (display_confirm) {
|
|
|
|
Toasty.success(context, context.getString(R.string.toot_sent), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (apiResponse.getError().getStatusCode() == -33)
|
|
|
|
Toasty.info(context, context.getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2019-09-29 15:02:49 +02:00
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
if (apiResponse.getTargetedId() != null && apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0) {
|
2019-09-29 15:23:48 +02:00
|
|
|
int position = 0;
|
2019-11-15 16:32:25 +01:00
|
|
|
for (Status tl : this.statuses) {
|
|
|
|
if (tl.getId().equals(apiResponse.getTargetedId())) {
|
2019-09-29 15:23:48 +02:00
|
|
|
List<Status> comments = this.statuses.get(position).getComments();
|
|
|
|
comments.add(comments.size(), apiResponse.getStatuses().get(0));
|
|
|
|
this.statuses.get(position).setComments(comments);
|
|
|
|
notifyStatusChanged(this.statuses.get(position));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
position++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 19:51:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-28 08:49:57 +02:00
|
|
|
public void onRetrieveSearchAccounts(APIResponse apiResponse) {
|
|
|
|
if (apiResponse.getError() != null)
|
|
|
|
return;
|
2019-09-27 19:51:20 +02:00
|
|
|
|
2019-09-28 08:49:57 +02:00
|
|
|
final List<Account> accounts = apiResponse.getAccounts();
|
|
|
|
if (accounts != null && accounts.size() > 0) {
|
|
|
|
int currentCursorPosition = comment_content.getSelectionStart();
|
|
|
|
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(context, accounts);
|
|
|
|
comment_content.setThreshold(1);
|
|
|
|
comment_content.setAdapter(accountsListAdapter);
|
|
|
|
final String oldContent = comment_content.getText().toString();
|
|
|
|
if (oldContent.length() >= currentCursorPosition) {
|
|
|
|
String[] searchA = oldContent.substring(0, currentCursorPosition).split("@");
|
|
|
|
if (searchA.length > 0) {
|
|
|
|
final String search = searchA[searchA.length - 1];
|
2020-03-07 14:16:28 +01:00
|
|
|
comment_content.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
|
Account account = accounts.get(position);
|
|
|
|
String deltaSearch = "";
|
|
|
|
int searchLength = 15;
|
|
|
|
if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position
|
|
|
|
searchLength = currentCursorPosition;
|
2019-09-28 08:49:57 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
|
|
|
|
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
|
|
|
|
else {
|
|
|
|
if (currentCursorPosition >= oldContent.length())
|
|
|
|
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
|
|
|
|
}
|
|
|
|
if (!search.equals(""))
|
|
|
|
deltaSearch = deltaSearch.replace("@" + search, "");
|
|
|
|
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
|
|
|
|
newContent += deltaSearch;
|
|
|
|
newContent += "@" + account.getAcct() + " ";
|
|
|
|
int newPosition = newContent.length();
|
|
|
|
if (currentCursorPosition < oldContent.length())
|
|
|
|
newContent += oldContent.substring(currentCursorPosition);
|
|
|
|
comment_content.setText(newContent);
|
|
|
|
comment_content.setSelection(newPosition);
|
|
|
|
AccountsSearchAdapter accountsListAdapter1 = new AccountsSearchAdapter(context, new ArrayList<>());
|
|
|
|
comment_content.setThreshold(1);
|
|
|
|
comment_content.setAdapter(accountsListAdapter1);
|
2019-09-28 08:49:57 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-27 19:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-28 08:49:57 +02:00
|
|
|
public void onRetrieveContact(APIResponse apiResponse) {
|
2019-09-27 19:51:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-28 08:49:57 +02:00
|
|
|
public void onRetrieveSearch(APIResponse apiResponse) {
|
|
|
|
if (apiResponse == null || apiResponse.getResults() == null || comment_content == null)
|
|
|
|
return;
|
|
|
|
app.fedilab.android.client.Entities.Results results = apiResponse.getResults();
|
|
|
|
int currentCursorPosition = comment_content.getSelectionStart();
|
|
|
|
final List<String> tags = results.getHashtags();
|
|
|
|
|
|
|
|
if (tags != null && tags.size() > 0) {
|
|
|
|
TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(context, tags);
|
|
|
|
comment_content.setThreshold(1);
|
|
|
|
comment_content.setAdapter(tagsSearchAdapter);
|
|
|
|
final String oldContent = comment_content.getText().toString();
|
|
|
|
if (oldContent.length() < currentCursorPosition)
|
|
|
|
return;
|
|
|
|
String[] searchA = oldContent.substring(0, currentCursorPosition).split("#");
|
|
|
|
if (searchA.length < 1)
|
|
|
|
return;
|
|
|
|
final String search = searchA[searchA.length - 1];
|
2020-03-07 14:16:28 +01:00
|
|
|
comment_content.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
|
if (position >= tags.size())
|
|
|
|
return;
|
|
|
|
String tag = tags.get(position);
|
|
|
|
String deltaSearch = "";
|
|
|
|
int searchLength = 15;
|
|
|
|
if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position
|
|
|
|
searchLength = currentCursorPosition;
|
|
|
|
}
|
|
|
|
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
|
|
|
|
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
|
|
|
|
else {
|
|
|
|
if (currentCursorPosition >= oldContent.length())
|
|
|
|
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
|
2019-09-28 08:49:57 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
|
|
|
|
if (!search.equals(""))
|
|
|
|
deltaSearch = deltaSearch.replace("#" + search, "");
|
|
|
|
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
|
|
|
|
newContent += deltaSearch;
|
|
|
|
newContent += "#" + tag + " ";
|
|
|
|
int newPosition = newContent.length();
|
|
|
|
if (currentCursorPosition < oldContent.length())
|
|
|
|
newContent += oldContent.substring(currentCursorPosition);
|
|
|
|
comment_content.setText(newContent);
|
|
|
|
comment_content.setSelection(newPosition);
|
|
|
|
TagsSearchAdapter tagsSearchAdapter1 = new TagsSearchAdapter(context, new ArrayList<>());
|
|
|
|
comment_content.setThreshold(1);
|
|
|
|
comment_content.setAdapter(tagsSearchAdapter1);
|
2019-09-28 08:49:57 +02:00
|
|
|
});
|
|
|
|
}
|
2019-09-27 19:51:20 +02:00
|
|
|
}
|
|
|
|
|
2019-09-30 19:18:44 +02:00
|
|
|
@Override
|
|
|
|
public void onRetrieveFeeds(APIResponse apiResponse) {
|
|
|
|
if (apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0) {
|
|
|
|
|
2020-04-09 18:57:12 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2019-09-30 19:18:44 +02:00
|
|
|
long id = new StatusStoredDAO(context, db).insertStatus(toot, apiResponse.getStatuses().get(0));
|
|
|
|
Intent intentToot = new Intent(context, PixelfedComposeActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putLong("restored", id);
|
|
|
|
b.putBoolean("removed", true);
|
|
|
|
intentToot.putExtras(b);
|
|
|
|
context.startActivity(intentToot);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public Status getItem(int position) {
|
|
|
|
if (statuses.size() > position && position >= 0)
|
2019-01-14 16:03:10 +01:00
|
|
|
return statuses.get(position);
|
|
|
|
else return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2020-03-28 09:17:54 +01:00
|
|
|
boolean show_account_boosts = false;
|
|
|
|
boolean show_account_replies = false;
|
|
|
|
if (context instanceof ShowAccountActivity) {
|
|
|
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
show_account_boosts = sharedpreferences.getBoolean(Helper.SHOW_ACCOUNT_BOOSTS, true);
|
|
|
|
show_account_replies = sharedpreferences.getBoolean(Helper.SHOW_ACCOUNT_REPLIES, true);
|
|
|
|
}
|
|
|
|
if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS && !Helper.filterToots(statuses.get(position), type, context instanceof ShowAccountActivity, show_account_boosts, show_account_replies)) {
|
2019-01-14 16:03:10 +01:00
|
|
|
return HIDDEN_STATUS;
|
2020-03-28 09:17:54 +01:00
|
|
|
} else {
|
2019-01-14 16:03:10 +01:00
|
|
|
return DISPLAYED_STATUS;
|
2020-03-28 09:17:54 +01:00
|
|
|
}
|
2019-01-14 16:03:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2019-08-19 09:11:23 +02:00
|
|
|
context = parent.getContext();
|
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(this.context);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (viewType == DISPLAYED_STATUS)
|
2019-01-14 16:03:10 +01:00
|
|
|
return new ViewHolderPixelfed(layoutInflater.inflate(R.layout.drawer_pixelfed, parent, false));
|
|
|
|
else
|
|
|
|
return new ViewHolderEmpty(layoutInflater.inflate(R.layout.drawer_empty, parent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("SetJavaScriptEnabled")
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (viewHolder.getItemViewType() != HIDDEN_STATUS) {
|
2019-01-14 18:32:59 +01:00
|
|
|
final ViewHolderPixelfed holder = (ViewHolderPixelfed) viewHolder;
|
|
|
|
final Status status = statuses.get(viewHolder.getAdapterPosition());
|
|
|
|
|
|
|
|
if (status.getAccount() != null && status.getAccount().getAvatar() != null)
|
|
|
|
Glide.with(context)
|
|
|
|
.load(status.getAccount().getAvatar())
|
2020-03-07 14:16:28 +01:00
|
|
|
.apply(new RequestOptions().transform(new FitCenter(), new RoundedCorners(270)))
|
2019-01-15 11:00:54 +01:00
|
|
|
.into(holder.pf_pp);
|
2019-01-14 18:32:59 +01:00
|
|
|
|
2019-09-27 18:52:42 +02:00
|
|
|
|
2019-11-10 15:05:14 +01:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
int iconColor = prefs.getInt("theme_icons_color", -1);
|
2019-11-15 16:32:25 +01:00
|
|
|
if (iconColor == -1) {
|
2019-11-10 15:05:14 +01:00
|
|
|
iconColor = ThemeHelper.getAttColor(context, R.attr.iconColor);
|
|
|
|
}
|
2019-11-29 18:56:38 +01:00
|
|
|
holder.pf_likes.setTextColor(iconColor);
|
2019-11-10 15:05:14 +01:00
|
|
|
int statusColor = prefs.getInt("theme_statuses_color", -1);
|
2019-11-15 16:32:25 +01:00
|
|
|
if (holder.pf_cardview != null && statusColor != -1) {
|
2019-11-10 15:05:14 +01:00
|
|
|
holder.pf_cardview.setCardBackgroundColor(statusColor);
|
2019-11-15 16:32:25 +01:00
|
|
|
} else if (holder.pf_cardview != null) {
|
2019-11-10 15:05:14 +01:00
|
|
|
holder.pf_cardview.setCardBackgroundColor(ThemeHelper.getAttColor(context, R.attr.cardviewColor));
|
|
|
|
}
|
2019-11-29 18:56:38 +01:00
|
|
|
int theme_text_color = prefs.getInt("theme_text_color", -1);
|
|
|
|
if (holder.pf_description != null && theme_text_color != -1) {
|
|
|
|
holder.pf_description.setTextColor(theme_text_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
int theme_text_header_2_line = prefs.getInt("theme_text_header_2_line", -1);
|
|
|
|
if (theme_text_header_2_line == -1) {
|
|
|
|
theme_text_header_2_line = ThemeHelper.getAttColor(context, R.attr.textHeader);
|
|
|
|
}
|
|
|
|
|
|
|
|
holder.pf_username.setTextColor(theme_text_header_2_line);
|
|
|
|
holder.pf_date.setTextColor(theme_text_header_2_line);
|
|
|
|
if (statusColor != -1) {
|
|
|
|
holder.quick_reply_container.setBackgroundColor(statusColor);
|
|
|
|
}
|
2019-11-10 15:05:14 +01:00
|
|
|
|
2019-09-29 15:23:48 +02:00
|
|
|
holder.quick_reply_switch_to_full.setVisibility(View.GONE);
|
2019-09-29 15:02:49 +02:00
|
|
|
if (status.isShortReply()) {
|
|
|
|
holder.quick_reply_container.setVisibility(View.VISIBLE);
|
2019-09-27 18:52:42 +02:00
|
|
|
holder.pixelfed_comments.setVisibility(View.VISIBLE);
|
2019-09-29 15:02:49 +02:00
|
|
|
in_reply_to_status = status.getReblog() != null ? status.getReblog().getId() : status.getId();
|
2019-11-15 16:32:25 +01:00
|
|
|
if (status.isCommentsFetched()) {
|
2020-03-07 08:46:48 +01:00
|
|
|
StatusDrawerParams statusDrawerParams = new StatusDrawerParams();
|
|
|
|
statusDrawerParams.setPosition(0);
|
|
|
|
statusDrawerParams.setTargetedId(status.getId());
|
|
|
|
statusDrawerParams.setOnWifi(true);
|
|
|
|
statusDrawerParams.setStatuses(status.getComments());
|
|
|
|
StatusListAdapter statusListAdapter = new StatusListAdapter(statusDrawerParams);
|
2019-09-29 15:02:49 +02:00
|
|
|
final LinearLayoutManager mLayoutManager;
|
|
|
|
mLayoutManager = new LinearLayoutManager(context);
|
|
|
|
holder.lv_comments.setLayoutManager(mLayoutManager);
|
|
|
|
holder.lv_comments.setAdapter(statusListAdapter);
|
2019-09-29 16:55:59 +02:00
|
|
|
mLayoutManager.scrollToPositionWithOffset(i, 0);
|
2019-11-15 16:32:25 +01:00
|
|
|
} else {
|
2019-09-29 15:02:49 +02:00
|
|
|
status.setCommentsFetched(true);
|
2021-01-19 17:43:51 +01:00
|
|
|
new RetrieveContextAsyncTask(context, false, false, status.getId(), PixelfedListAdapter.this);
|
2019-09-29 15:02:49 +02:00
|
|
|
}
|
2019-11-29 18:56:38 +01:00
|
|
|
InputMethodManager inputMethodManager =
|
|
|
|
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
2020-03-07 14:16:28 +01:00
|
|
|
assert inputMethodManager != null;
|
2019-11-29 18:56:38 +01:00
|
|
|
inputMethodManager.toggleSoftInputFromWindow(
|
|
|
|
holder.quick_reply_text.getApplicationWindowToken(),
|
|
|
|
InputMethodManager.SHOW_FORCED, 0);
|
2019-09-29 15:02:49 +02:00
|
|
|
EditText content_cw = new EditText(context);
|
|
|
|
content_cw.setText(status.getReblog() != null ? status.getReblog().getSpoiler_text() : status.getSpoiler_text());
|
2020-05-23 17:29:12 +02:00
|
|
|
String content = TootActivity.manageMentions(userId, status.getReblog() != null ? status.getReblog() : status);
|
2019-09-29 17:55:10 +02:00
|
|
|
TextWatcher textWatcher = PixelfedComposeActivity.initializeTextWatcher(context, social, holder.quick_reply_text, holder.toot_space_left, null, null, PixelfedListAdapter.this, PixelfedListAdapter.this, PixelfedListAdapter.this);
|
|
|
|
holder.quick_reply_text.addTextChangedListener(textWatcher);
|
2019-09-29 16:55:59 +02:00
|
|
|
holder.quick_reply_text.setText(content);
|
2019-09-29 15:02:49 +02:00
|
|
|
comment_content = holder.quick_reply_text;
|
2019-09-29 16:55:59 +02:00
|
|
|
holder.quick_reply_text.setFocusable(true);
|
|
|
|
holder.quick_reply_text.requestFocus();
|
|
|
|
holder.quick_reply_text.setSelection(content.length()); //Put cursor at the end
|
2019-09-29 15:02:49 +02:00
|
|
|
int newInputType = comment_content.getInputType() & (comment_content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
|
|
|
|
comment_content.setInputType(newInputType);
|
|
|
|
in_reply_to_status = status.getReblog() != null ? status.getReblog().getId() : status.getId();
|
|
|
|
|
2020-04-09 18:57:12 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2019-09-29 15:02:49 +02:00
|
|
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
|
|
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
|
|
|
|
|
|
|
String defaultVisibility = account.isLocked() ? "private" : "public";
|
|
|
|
String settingsVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility);
|
|
|
|
int initialTootVisibility = 0;
|
|
|
|
int ownerTootVisibility = 0;
|
|
|
|
switch (status.getReblog() != null ? status.getReblog().getVisibility() : status.getVisibility()) {
|
|
|
|
case "public":
|
|
|
|
initialTootVisibility = 4;
|
|
|
|
break;
|
|
|
|
case "unlisted":
|
|
|
|
initialTootVisibility = 3;
|
|
|
|
break;
|
|
|
|
case "private":
|
|
|
|
visibility = "private";
|
|
|
|
initialTootVisibility = 2;
|
|
|
|
break;
|
|
|
|
case "direct":
|
|
|
|
visibility = "direct";
|
|
|
|
initialTootVisibility = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (settingsVisibility) {
|
|
|
|
case "public":
|
|
|
|
ownerTootVisibility = 4;
|
|
|
|
break;
|
|
|
|
case "unlisted":
|
|
|
|
ownerTootVisibility = 3;
|
|
|
|
break;
|
|
|
|
case "private":
|
|
|
|
visibility = "private";
|
|
|
|
ownerTootVisibility = 2;
|
|
|
|
break;
|
|
|
|
case "direct":
|
|
|
|
visibility = "direct";
|
|
|
|
ownerTootVisibility = 1;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-06 11:49:59 +02:00
|
|
|
int tootVisibility = Math.min(ownerTootVisibility, initialTootVisibility);
|
2019-09-29 15:02:49 +02:00
|
|
|
switch (tootVisibility) {
|
|
|
|
case 4:
|
|
|
|
visibility = "public";
|
|
|
|
holder.quick_reply_privacy.setImageResource(R.drawable.ic_public_toot);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
visibility = "unlisted";
|
|
|
|
holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_open_toot);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
visibility = "private";
|
|
|
|
holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_outline_toot);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
visibility = "direct";
|
|
|
|
holder.quick_reply_privacy.setImageResource(R.drawable.ic_mail_outline_toot);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
holder.quick_reply_container.setVisibility(View.GONE);
|
|
|
|
holder.pixelfed_comments.setVisibility(View.GONE);
|
2019-09-27 18:52:42 +02:00
|
|
|
}
|
2019-09-29 15:02:49 +02:00
|
|
|
|
|
|
|
|
2019-10-13 17:09:46 +02:00
|
|
|
holder.art_media_play.setVisibility(View.GONE);
|
2020-08-09 17:52:47 +02:00
|
|
|
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
|
|
|
|
|
|
|
|
|
|
|
holder.art_media.setOnClickListener(v -> {
|
2021-01-19 17:43:51 +01:00
|
|
|
if (expand_media || !status.isSensitive() || status.isAttachmentShown()) {
|
2020-08-09 17:52:47 +02:00
|
|
|
Intent intent = new Intent(context, SlideMediaActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
intent.putParcelableArrayListExtra("mediaArray", status.getMedia_attachments());
|
|
|
|
b.putInt("position", 1);
|
|
|
|
b.putInt("bgcolor", context.getResources().getColor(R.color.cyanea_primary_dark));
|
|
|
|
intent.putExtras(b);
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
|
|
|
.makeSceneTransitionAnimation((Activity) context, holder.art_media, status.getMedia_attachments().get(0).getUrl());
|
|
|
|
// start the new activity
|
|
|
|
context.startActivity(intent, options.toBundle());
|
|
|
|
} else {
|
|
|
|
// start the new activity
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2021-01-19 17:43:51 +01:00
|
|
|
} else {
|
2020-08-09 17:52:47 +02:00
|
|
|
status.setAttachmentShown(true);
|
|
|
|
notifyItemChanged(i);
|
|
|
|
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
|
|
|
if (timeout > 0) {
|
|
|
|
new CountDownTimer((timeout * 1000), 1000) {
|
|
|
|
public void onTick(long millisUntilFinished) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onFinish() {
|
|
|
|
status.setAttachmentShown(false);
|
|
|
|
notifyItemChanged(i);
|
|
|
|
}
|
|
|
|
}.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2019-09-29 15:02:49 +02:00
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 1) {
|
2020-08-09 17:52:47 +02:00
|
|
|
SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, status);
|
2019-09-28 10:16:47 +02:00
|
|
|
holder.imageSlider.setSliderAdapter(sliderAdapter);
|
|
|
|
holder.imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM);
|
|
|
|
holder.imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
|
2019-09-29 15:33:59 +02:00
|
|
|
holder.art_media.setVisibility(View.GONE);
|
|
|
|
holder.imageSlider.setVisibility(View.VISIBLE);
|
2020-07-17 17:23:56 +02:00
|
|
|
} else if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) {
|
2019-09-29 15:33:59 +02:00
|
|
|
holder.art_media.setVisibility(View.VISIBLE);
|
|
|
|
holder.imageSlider.setVisibility(View.GONE);
|
2020-05-08 11:34:49 +02:00
|
|
|
if (status.getMedia_attachments().get(0).getType() != null && status.getMedia_attachments().get(0).getType().toLowerCase().equals("video")) {
|
2019-10-13 17:09:46 +02:00
|
|
|
holder.art_media_play.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-09-30 17:56:15 +02:00
|
|
|
String url;
|
2020-05-08 11:34:49 +02:00
|
|
|
if (status.getMedia_attachments().get(0).getPreview_url() != null && status.getMedia_attachments().get(0).getPreview_url().endsWith("no-preview.png")) {
|
2019-09-30 17:56:15 +02:00
|
|
|
url = status.getMedia_attachments().get(0).getUrl();
|
2019-11-15 16:32:25 +01:00
|
|
|
} else {
|
2019-09-30 17:56:15 +02:00
|
|
|
url = status.getMedia_attachments().get(0).getPreview_url();
|
|
|
|
}
|
2021-01-19 17:43:51 +01:00
|
|
|
if (expand_media || !status.isSensitive() || status.isAttachmentShown()) {
|
2020-08-09 17:52:47 +02:00
|
|
|
Glide.with(holder.itemView.getContext())
|
|
|
|
.asBitmap()
|
|
|
|
.load(url)
|
|
|
|
.thumbnail(0.1f)
|
|
|
|
.into(holder.art_media);
|
2021-01-19 17:43:51 +01:00
|
|
|
} else {
|
2020-08-09 17:52:47 +02:00
|
|
|
Glide.with(holder.itemView.getContext())
|
|
|
|
.asBitmap()
|
|
|
|
.load(url)
|
|
|
|
.apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
|
|
|
|
.thumbnail(0.1f)
|
|
|
|
.into(holder.art_media);
|
|
|
|
}
|
2019-09-28 10:16:47 +02:00
|
|
|
}
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-01-15 11:00:54 +01:00
|
|
|
holder.pf_likes.setText(context.getResources().getQuantityString(R.plurals.likes, status.getFavourites_count(), status.getFavourites_count()));
|
2020-03-07 14:16:28 +01:00
|
|
|
holder.pf_pp.setOnClickListener(v -> {
|
|
|
|
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
|
|
|
|
CrossActions.doCrossProfile(context, status.getAccount());
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(context, ShowAccountActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putParcelable("account", status.getAccount());
|
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
2019-01-14 18:32:59 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-27 19:51:20 +02:00
|
|
|
|
|
|
|
holder.quick_reply_switch_to_full.setVisibility(View.GONE);
|
|
|
|
holder.toot_space_left.setVisibility(View.GONE);
|
|
|
|
holder.quick_reply_emoji.setVisibility(View.GONE);
|
|
|
|
holder.quick_reply_privacy.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
holder.quick_reply_button.setOnClickListener(view -> {
|
2019-11-29 18:56:38 +01:00
|
|
|
sendToot(status);
|
|
|
|
status.setShortReply(false);
|
|
|
|
holder.quick_reply_container.setVisibility(View.GONE);
|
2019-09-27 19:51:20 +02:00
|
|
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
2019-09-28 10:16:47 +02:00
|
|
|
assert imm != null;
|
2019-09-27 19:51:20 +02:00
|
|
|
imm.hideSoftInputFromWindow(holder.quick_reply_button.getWindowToken(), 0);
|
|
|
|
});
|
2019-09-30 19:18:44 +02:00
|
|
|
|
2019-01-15 11:00:54 +01:00
|
|
|
holder.pf_description.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE);
|
2019-09-28 18:49:38 +02:00
|
|
|
holder.pf_date.setText(Helper.longDateToString(status.getCreated_at()));
|
2019-09-27 19:51:20 +02:00
|
|
|
holder.quick_reply_text.setHint(R.string.leave_a_comment);
|
|
|
|
holder.quick_reply_button.setText(R.string.post);
|
2020-03-07 14:16:28 +01:00
|
|
|
holder.pf_comment.setOnClickListener(v -> {
|
|
|
|
boolean currentValue = status.isShortReply();
|
|
|
|
for (Status s : statuses) {
|
|
|
|
if (s.isShortReply() && !s.getId().equals(status.getId())) {
|
|
|
|
s.setShortReply(false);
|
|
|
|
notifyStatusChanged(s);
|
2019-09-27 19:51:20 +02:00
|
|
|
}
|
2019-01-14 18:32:59 +01:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
status.setShortReply(!currentValue);
|
|
|
|
if (!status.isShortReply()) {
|
|
|
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
|
|
|
assert imm != null;
|
|
|
|
imm.hideSoftInputFromWindow(holder.quick_reply_text.getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
notifyStatusChanged(status);
|
2019-01-14 18:32:59 +01:00
|
|
|
});
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-09-30 19:18:44 +02:00
|
|
|
|
|
|
|
final View attached = holder.status_more;
|
2020-03-07 14:16:28 +01:00
|
|
|
holder.status_more.setOnClickListener(v -> {
|
|
|
|
PopupMenu popup = new PopupMenu(context, attached);
|
|
|
|
final boolean isOwner = status.getReblog() != null ? status.getReblog().getAccount().getId().equals(userId) : status.getAccount().getId().equals(userId);
|
|
|
|
popup.getMenuInflater()
|
|
|
|
.inflate(R.menu.option_toot, popup.getMenu());
|
|
|
|
if (status.getVisibility().equals("private") || status.getVisibility().equals("direct")) {
|
|
|
|
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
|
|
|
|
}
|
|
|
|
if (status.isBookmarked())
|
|
|
|
popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_remove);
|
|
|
|
else
|
|
|
|
popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_add);
|
|
|
|
if (status.isMuted())
|
|
|
|
popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.unmute_conversation);
|
|
|
|
else
|
|
|
|
popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.mute_conversation);
|
|
|
|
|
|
|
|
|
|
|
|
final String[] stringArrayConf;
|
|
|
|
if (status.getVisibility().equals("direct") || (status.getVisibility().equals("private") && !isOwner))
|
|
|
|
popup.getMenu().findItem(R.id.action_schedule_boost).setVisible(false);
|
|
|
|
if (isOwner) {
|
|
|
|
popup.getMenu().findItem(R.id.action_block).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_report).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
|
|
|
|
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
|
|
|
|
if (social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
2019-09-30 19:18:44 +02:00
|
|
|
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
|
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
} else {
|
2019-09-30 19:18:44 +02:00
|
|
|
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
|
2020-03-07 14:16:28 +01:00
|
|
|
//popup.getMenu().findItem(R.id.action_mute_conversation).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
|
|
|
|
//Same instance
|
|
|
|
if (status.getAccount().getAcct().split("@").length < 2) {
|
|
|
|
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
|
|
|
|
} else { //Both accounts have an instance in acct (pixelfed fix)
|
|
|
|
String instanceAccount = status.getAccount().getAcct().split("@")[1];
|
|
|
|
if (Helper.getLiveInstance(context).compareTo(instanceAccount) == 0) {
|
|
|
|
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
|
|
|
|
}
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
|
|
|
|
}
|
|
|
|
//TODO: fix and display that feature
|
|
|
|
popup.getMenu().findItem(R.id.action_admin).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_custom_sharing).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_copy).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_stats).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_translate).setVisible(false);
|
|
|
|
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
|
|
|
|
|
|
|
|
final SharedPreferences sharedpreferences1 = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences1.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK) {
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
} else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
2019-09-30 19:18:44 +02:00
|
|
|
|
2020-03-07 14:16:28 +01:00
|
|
|
boolean custom_sharing = sharedpreferences1.getBoolean(Helper.SET_CUSTOM_SHARING, false);
|
|
|
|
if (custom_sharing && status.getVisibility().equals("public"))
|
|
|
|
popup.getMenu().findItem(R.id.action_custom_sharing).setVisible(true);
|
|
|
|
if (status.isBookmarked())
|
|
|
|
popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_remove);
|
|
|
|
else
|
|
|
|
popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_add);
|
|
|
|
popup.setOnMenuItemClickListener(item -> {
|
|
|
|
AlertDialog.Builder builderInner;
|
|
|
|
final API.StatusAction doAction;
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_redraft:
|
|
|
|
builderInner = new AlertDialog.Builder(context, style);
|
|
|
|
builderInner.setTitle(stringArrayConf[1]);
|
|
|
|
redraft = true;
|
|
|
|
doAction = API.StatusAction.UNSTATUS;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
|
|
|
else
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent()));
|
|
|
|
break;
|
|
|
|
case R.id.action_schedule_boost:
|
|
|
|
scheduleBoost(status);
|
|
|
|
return true;
|
|
|
|
case R.id.action_info:
|
|
|
|
tootInformation(status);
|
|
|
|
return true;
|
|
|
|
case R.id.action_open_browser:
|
|
|
|
Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
|
|
|
|
return true;
|
|
|
|
case R.id.action_remove:
|
|
|
|
builderInner = new AlertDialog.Builder(context, style);
|
|
|
|
builderInner.setTitle(stringArrayConf[0]);
|
|
|
|
doAction = API.StatusAction.UNSTATUS;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
|
|
|
else
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent()));
|
|
|
|
break;
|
|
|
|
case R.id.action_block_domain:
|
|
|
|
builderInner = new AlertDialog.Builder(context, style);
|
|
|
|
builderInner.setTitle(stringArrayConf[3]);
|
|
|
|
doAction = API.StatusAction.BLOCK_DOMAIN;
|
|
|
|
String domain = status.getAccount().getAcct().split("@")[1];
|
|
|
|
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
|
|
|
|
break;
|
|
|
|
case R.id.action_mute:
|
|
|
|
builderInner = new AlertDialog.Builder(context, style);
|
|
|
|
builderInner.setTitle(stringArrayConf[0]);
|
|
|
|
builderInner.setMessage(status.getAccount().getAcct());
|
|
|
|
doAction = API.StatusAction.MUTE;
|
|
|
|
break;
|
|
|
|
case R.id.action_mute_conversation:
|
|
|
|
if (status.isMuted())
|
|
|
|
doAction = API.StatusAction.UNMUTE_CONVERSATION;
|
|
|
|
else
|
|
|
|
doAction = API.StatusAction.MUTE_CONVERSATION;
|
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
new PostActionAsyncTask(context, doAction, status.getId(), PixelfedListAdapter.this);
|
2020-03-07 14:16:28 +01:00
|
|
|
return true;
|
|
|
|
case R.id.action_bookmark:
|
|
|
|
if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
|
|
|
|
status.setBookmarked(!status.isBookmarked());
|
2020-04-09 18:57:12 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2020-03-07 14:16:28 +01:00
|
|
|
try {
|
|
|
|
if (status.isBookmarked()) {
|
|
|
|
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
|
|
|
|
Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show();
|
2019-09-30 19:18:44 +02:00
|
|
|
} else {
|
2020-03-07 14:16:28 +01:00
|
|
|
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status);
|
|
|
|
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show();
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
notifyStatusChanged(status);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int position = 0;
|
|
|
|
for (Status statustmp : statuses) {
|
|
|
|
if (statustmp.getId().equals(status.getId())) {
|
|
|
|
statuses.remove(status);
|
|
|
|
pixelfedListAdapter.notifyItemRemoved(position);
|
2020-04-09 18:57:12 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2020-03-07 14:16:28 +01:00
|
|
|
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp);
|
|
|
|
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show();
|
|
|
|
break;
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
position++;
|
|
|
|
}
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
return true;
|
|
|
|
case R.id.action_timed_mute:
|
|
|
|
timedMuteAction(status);
|
|
|
|
return true;
|
|
|
|
case R.id.action_block:
|
|
|
|
builderInner = new AlertDialog.Builder(context, style);
|
|
|
|
builderInner.setTitle(stringArrayConf[1]);
|
|
|
|
doAction = API.StatusAction.BLOCK;
|
|
|
|
break;
|
|
|
|
case R.id.action_translate:
|
2021-01-18 19:00:43 +01:00
|
|
|
int translator = sharedpreferences1.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE);
|
2020-03-07 14:16:28 +01:00
|
|
|
if (translator == Helper.TRANS_NONE)
|
|
|
|
Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show();
|
|
|
|
else
|
|
|
|
translateToot(status);
|
|
|
|
return true;
|
|
|
|
case R.id.action_report:
|
|
|
|
builderInner = new AlertDialog.Builder(context, style);
|
|
|
|
builderInner.setTitle(stringArrayConf[2]);
|
|
|
|
doAction = API.StatusAction.REPORT;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
|
|
|
else
|
|
|
|
builderInner.setMessage(Html.fromHtml(status.getContent()));
|
|
|
|
break;
|
|
|
|
case R.id.action_copy_link:
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
|
|
|
|
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
|
|
|
|
if (clipboard != null) {
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show();
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
return true;
|
|
|
|
case R.id.action_share:
|
|
|
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
|
|
|
|
String url;
|
|
|
|
|
|
|
|
if (status.getReblog() != null) {
|
|
|
|
if (status.getReblog().getUri().startsWith("http"))
|
|
|
|
url = status.getReblog().getUri();
|
|
|
|
else
|
|
|
|
url = status.getReblog().getUrl();
|
|
|
|
} else {
|
|
|
|
if (status.getUri().startsWith("http"))
|
|
|
|
url = status.getUri();
|
|
|
|
else
|
|
|
|
url = status.getUrl();
|
|
|
|
}
|
|
|
|
String extra_text;
|
|
|
|
boolean share_details = sharedpreferences1.getBoolean(Helper.SET_SHARE_DETAILS, true);
|
|
|
|
if (share_details) {
|
|
|
|
extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct();
|
|
|
|
if (extra_text.split("@").length == 1)
|
|
|
|
extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context);
|
|
|
|
else
|
|
|
|
extra_text = "@" + extra_text;
|
2020-04-08 15:29:02 +02:00
|
|
|
extra_text += " \uD83D\uDD17 " + url + "\r\n-\n";
|
2020-03-07 14:16:28 +01:00
|
|
|
final String contentToot;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
|
|
|
else
|
|
|
|
contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString();
|
|
|
|
extra_text += contentToot;
|
|
|
|
} else {
|
|
|
|
extra_text = url;
|
|
|
|
}
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Text for report
|
|
|
|
EditText input = null;
|
|
|
|
if (doAction == API.StatusAction.REPORT) {
|
|
|
|
input = new EditText(context);
|
|
|
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
|
input.setLayoutParams(lp);
|
|
|
|
builderInner.setView(input);
|
|
|
|
}
|
|
|
|
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
|
|
|
final EditText finalInput = input;
|
|
|
|
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
|
|
|
|
if (doAction == API.StatusAction.UNSTATUS) {
|
|
|
|
String targetedId = status.getId();
|
2021-01-19 17:43:51 +01:00
|
|
|
new PostActionAsyncTask(context, doAction, targetedId, PixelfedListAdapter.this);
|
2020-03-07 14:16:28 +01:00
|
|
|
if (redraft) {
|
|
|
|
if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) {
|
|
|
|
toot = new Status();
|
|
|
|
toot.setIn_reply_to_id(status.getIn_reply_to_id());
|
|
|
|
toot.setSensitive(status.isSensitive());
|
|
|
|
toot.setMedia_attachments(status.getMedia_attachments());
|
|
|
|
if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0)
|
|
|
|
toot.setSpoiler_text(status.getSpoiler_text().trim());
|
|
|
|
toot.setContent(context, status.getContent());
|
|
|
|
toot.setVisibility(status.getVisibility());
|
|
|
|
if (status.getPoll() != null) {
|
|
|
|
toot.setPoll(status.getPoll());
|
|
|
|
} else if (status.getReblog() != null && status.getReblog().getPoll() != null) {
|
|
|
|
toot.setPoll(status.getPoll());
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2021-01-19 17:43:51 +01:00
|
|
|
new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, PixelfedListAdapter.this);
|
2020-03-07 14:16:28 +01:00
|
|
|
} else {
|
|
|
|
toot = new Status();
|
|
|
|
toot.setSensitive(status.isSensitive());
|
|
|
|
toot.setMedia_attachments(status.getMedia_attachments());
|
|
|
|
if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0)
|
|
|
|
toot.setSpoiler_text(status.getSpoiler_text().trim());
|
|
|
|
toot.setVisibility(status.getVisibility());
|
|
|
|
toot.setContent(context, status.getContent());
|
|
|
|
if (status.getPoll() != null) {
|
|
|
|
toot.setPoll(status.getPoll());
|
|
|
|
} else if (status.getReblog() != null && status.getReblog().getPoll() != null) {
|
|
|
|
toot.setPoll(status.getPoll());
|
|
|
|
}
|
2020-04-09 18:57:12 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2020-03-07 14:16:28 +01:00
|
|
|
long id = new StatusStoredDAO(context, db).insertStatus(toot, null);
|
|
|
|
Intent intentToot = new Intent(context, PixelfedComposeActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putLong("restored", id);
|
|
|
|
b.putBoolean("removed", true);
|
|
|
|
intentToot.putExtras(b);
|
|
|
|
context.startActivity(intentToot);
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
}
|
|
|
|
} else if (doAction == API.StatusAction.REPORT) {
|
|
|
|
String comment = null;
|
|
|
|
if (finalInput.getText() != null)
|
|
|
|
comment = finalInput.getText().toString();
|
2021-01-19 17:43:51 +01:00
|
|
|
new PostActionAsyncTask(context, doAction, status.getId(), status, comment, PixelfedListAdapter.this);
|
2020-03-07 14:16:28 +01:00
|
|
|
} else {
|
|
|
|
String targetedId;
|
|
|
|
if (item.getItemId() == R.id.action_block_domain) {
|
|
|
|
targetedId = status.getAccount().getAcct().split("@")[1];
|
|
|
|
} else {
|
|
|
|
targetedId = status.getAccount().getId();
|
|
|
|
}
|
2021-01-19 17:43:51 +01:00
|
|
|
new PostActionAsyncTask(context, doAction, targetedId, PixelfedListAdapter.this);
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
dialog.dismiss();
|
2019-09-30 19:18:44 +02:00
|
|
|
});
|
2020-03-07 14:16:28 +01:00
|
|
|
builderInner.show();
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
popup.show();
|
2019-09-30 19:18:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-11-15 16:32:25 +01:00
|
|
|
holder.pf_date.setOnClickListener(view -> {
|
2019-09-27 19:02:37 +02:00
|
|
|
Intent intent = new Intent(context, ShowConversationActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
if (status.getReblog() == null)
|
|
|
|
b.putParcelable("status", status);
|
|
|
|
else
|
|
|
|
b.putParcelable("status", status.getReblog());
|
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2019-01-15 14:43:56 +01:00
|
|
|
|
2020-04-09 11:04:38 +02:00
|
|
|
if (status.getAccount().getDisplayNameSpan() != null && status.getAccount().getDisplayNameSpan().toString().trim().length() > 0)
|
|
|
|
holder.pf_username.setText(status.getAccount().getDisplayNameSpan(), TextView.BufferType.SPANNABLE);
|
2019-01-14 18:32:59 +01:00
|
|
|
else
|
2019-01-15 11:00:54 +01:00
|
|
|
holder.pf_username.setText(status.getAccount().getUsername());
|
2019-01-15 14:43:56 +01:00
|
|
|
|
2019-11-10 15:05:14 +01:00
|
|
|
holder.pf_fav.setInActiveImageTintColor(iconColor);
|
|
|
|
holder.pf_share.setInActiveImageTintColor(iconColor);
|
|
|
|
Helper.changeDrawableColor(context, holder.pf_comment, iconColor);
|
2019-11-15 16:32:25 +01:00
|
|
|
Helper.changeDrawableColor(context, holder.status_more, iconColor);
|
2019-11-10 15:05:14 +01:00
|
|
|
Helper.changeDrawableColor(context, R.drawable.ic_pixelfed_favorite_border, iconColor);
|
2019-01-15 14:43:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
holder.pf_fav.pressOnTouch(false);
|
|
|
|
holder.pf_fav.setActiveImage(R.drawable.ic_pixelfed_favorite);
|
|
|
|
holder.pf_fav.setInactiveImage(R.drawable.ic_pixelfed_favorite_border);
|
|
|
|
holder.pf_fav.setDisableCircle(true);
|
|
|
|
holder.pf_fav.setActiveImageTint(R.color.pixelfed_like);
|
|
|
|
holder.pf_fav.setColors(R.color.pixelfed_like, R.color.pixelfed_like);
|
|
|
|
|
2019-01-15 16:36:30 +01:00
|
|
|
holder.pf_share.pressOnTouch(false);
|
2019-09-27 18:03:49 +02:00
|
|
|
holder.pf_share.setActiveImage(R.drawable.ic_repeat_boost);
|
|
|
|
holder.pf_share.setInactiveImage(R.drawable.ic_repeat_boost);
|
2019-01-15 16:36:30 +01:00
|
|
|
holder.pf_share.setDisableCircle(true);
|
|
|
|
holder.pf_share.setActiveImageTint(R.color.boost_icon);
|
|
|
|
holder.pf_share.setColors(R.color.boost_icon, R.color.boost_icon);
|
|
|
|
|
2019-01-15 14:43:56 +01:00
|
|
|
if (!status.isFavAnimated()) {
|
2021-01-18 19:00:43 +01:00
|
|
|
holder.pf_fav.setChecked(status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited()));
|
2019-01-15 14:43:56 +01:00
|
|
|
} else {
|
|
|
|
status.setFavAnimated(false);
|
|
|
|
holder.pf_fav.setChecked(true);
|
|
|
|
holder.pf_fav.setAnimationSpeed(1.0f);
|
|
|
|
holder.pf_fav.playAnimation();
|
|
|
|
}
|
2019-01-15 16:36:30 +01:00
|
|
|
|
|
|
|
if (!status.isBoostAnimated()) {
|
2021-01-18 19:00:43 +01:00
|
|
|
holder.pf_share.setChecked(status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged()));
|
2019-01-15 16:36:30 +01:00
|
|
|
} else {
|
|
|
|
status.setBoostAnimated(false);
|
|
|
|
holder.pf_share.setChecked(true);
|
|
|
|
holder.pf_share.setAnimationSpeed(1.0f);
|
|
|
|
holder.pf_share.playAnimation();
|
|
|
|
}
|
2019-01-15 14:43:56 +01:00
|
|
|
boolean confirmFav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
|
2020-03-07 14:16:28 +01:00
|
|
|
holder.pf_fav.setOnClickListener(v -> {
|
|
|
|
if (!status.isFavourited() && confirmFav)
|
|
|
|
status.setFavAnimated(true);
|
|
|
|
if (!status.isFavourited() && !confirmFav) {
|
|
|
|
status.setFavAnimated(true);
|
|
|
|
notifyStatusChanged(status);
|
2019-01-15 14:43:56 +01:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
CrossActions.doCrossAction(context, type, status, null, (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, pixelfedListAdapter, PixelfedListAdapter.this, true);
|
2019-01-15 14:43:56 +01:00
|
|
|
});
|
2019-01-15 16:36:30 +01:00
|
|
|
boolean confirmBoost = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, false);
|
2020-03-07 14:16:28 +01:00
|
|
|
holder.pf_share.setOnClickListener(v -> {
|
|
|
|
if (!status.isReblogged() && confirmBoost)
|
|
|
|
status.setBoostAnimated(true);
|
|
|
|
if (!status.isReblogged() && !confirmBoost) {
|
|
|
|
status.setBoostAnimated(true);
|
|
|
|
notifyStatusChanged(status);
|
2019-01-15 16:36:30 +01:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
CrossActions.doCrossAction(context, type, status, null, (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, pixelfedListAdapter, PixelfedListAdapter.this, true);
|
2019-01-15 16:36:30 +01:00
|
|
|
});
|
2019-01-14 18:32:59 +01:00
|
|
|
}
|
2019-01-14 16:03:10 +01:00
|
|
|
|
2019-09-30 19:18:44 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void translateToot(Status status) {
|
|
|
|
//Manages translations
|
|
|
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2021-01-18 19:00:43 +01:00
|
|
|
int trans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE);
|
2019-09-30 19:18:44 +02:00
|
|
|
MyTransL.translatorEngine et = MyTransL.translatorEngine.YANDEX;
|
2020-03-07 14:16:28 +01:00
|
|
|
String api_key;
|
2019-09-30 19:18:44 +02:00
|
|
|
|
|
|
|
|
2020-03-07 14:16:28 +01:00
|
|
|
if (trans == Helper.TRANS_DEEPL) {
|
2019-09-30 19:18:44 +02:00
|
|
|
et = MyTransL.translatorEngine.DEEPL;
|
2020-03-08 10:29:06 +01:00
|
|
|
} else if (trans == Helper.TRANS_SYSTRAN) {
|
2019-11-24 16:07:36 +01:00
|
|
|
et = MyTransL.translatorEngine.SYSTRAN;
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
|
|
|
final MyTransL myTransL = MyTransL.getInstance(et);
|
|
|
|
myTransL.setObfuscation(true);
|
|
|
|
if (trans == Helper.TRANS_YANDEX) {
|
|
|
|
api_key = sharedpreferences.getString(Helper.SET_YANDEX_API_KEY, Helper.YANDEX_KEY);
|
|
|
|
myTransL.setYandexAPIKey(api_key);
|
|
|
|
} else if (trans == Helper.TRANS_DEEPL) {
|
|
|
|
api_key = sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, "");
|
|
|
|
myTransL.setDeeplAPIKey(api_key);
|
2019-11-24 16:07:36 +01:00
|
|
|
} else if (trans == Helper.TRANS_SYSTRAN) {
|
|
|
|
api_key = sharedpreferences.getString(Helper.SET_SYSTRAN_API_KEY, "");
|
|
|
|
myTransL.setSystranAPIKey(api_key);
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!status.isTranslated()) {
|
|
|
|
String statusToTranslate;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
|
|
|
statusToTranslate = Html.fromHtml(status.getReblog() != null ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
|
|
|
else
|
|
|
|
statusToTranslate = Html.fromHtml(status.getReblog() != null ? status.getReblog().getContent() : status.getContent()).toString();
|
|
|
|
//TODO: removes the replaceAll once fixed with the lib
|
2021-01-18 19:00:43 +01:00
|
|
|
myTransL.translate(statusToTranslate, MyTransL.getLocale(), new Results() {
|
2019-09-30 19:18:44 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Translate translate) {
|
|
|
|
if (translate.getTranslatedContent() != null) {
|
|
|
|
status.setTranslated(true);
|
|
|
|
status.setTranslationShown(true);
|
|
|
|
status.setContentTranslated(translate.getTranslatedContent());
|
|
|
|
Status.transformTranslation(context, status);
|
2020-06-16 20:09:29 +02:00
|
|
|
//makeEmojis(context, view, status.getContentSpan(), status.getReblog()!=null?status.getReblog().getEmojis():status.getEmojis());
|
2019-09-30 19:18:44 +02:00
|
|
|
notifyStatusChanged(status);
|
|
|
|
} else {
|
|
|
|
Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFail(HttpsConnectionException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
status.setTranslationShown(!status.isTranslationShown());
|
|
|
|
notifyStatusChanged(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void tootInformation(Status status) {
|
|
|
|
Intent intent = new Intent(context, TootInfoActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
if (status.getReblog() != null) {
|
|
|
|
b.putString("toot_id", status.getReblog().getId());
|
|
|
|
b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count());
|
|
|
|
b.putInt("toot_favorites_count", status.getReblog().getFavourites_count());
|
|
|
|
} else {
|
|
|
|
b.putString("toot_id", status.getId());
|
|
|
|
b.putInt("toot_reblogs_count", status.getReblogs_count());
|
|
|
|
b.putInt("toot_favorites_count", status.getFavourites_count());
|
|
|
|
}
|
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
2019-01-14 16:03:10 +01:00
|
|
|
}
|
|
|
|
|
2019-11-29 18:56:38 +01:00
|
|
|
private void sendToot(Status status) {
|
2019-09-27 19:51:20 +02:00
|
|
|
|
|
|
|
if (comment_content.getText() == null) {
|
|
|
|
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (comment_content.getText().toString().trim().length() == 0) {
|
|
|
|
Toasty.error(context, context.getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
String instance = Helper.getLiveInstance(context);
|
|
|
|
String tootContent;
|
|
|
|
tootContent = comment_content.getText().toString().trim();
|
|
|
|
Status toot = new Status();
|
|
|
|
toot.setSensitive(false);
|
2020-04-09 18:57:12 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2019-09-27 19:51:20 +02:00
|
|
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
|
|
|
toot.setVisibility(visibility);
|
|
|
|
toot.setIn_reply_to_id(in_reply_to_status);
|
2019-11-30 08:53:37 +01:00
|
|
|
toot.setContent(context, tootContent);
|
2021-01-19 17:43:51 +01:00
|
|
|
new PostStatusAsyncTask(context, social, account, toot, PixelfedListAdapter.this);
|
2019-11-29 18:56:38 +01:00
|
|
|
status.setQuickReplyPrivacy(null);
|
|
|
|
status.setQuickReplyContent(null);
|
2019-09-27 19:51:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-14 16:03:10 +01:00
|
|
|
@Override
|
|
|
|
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
if (error != null) {
|
|
|
|
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
|
2019-01-14 16:03:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Helper.manageMessageStatusCode(context, statusCode, statusAction);
|
|
|
|
//When muting or blocking an account, its status are removed from the list
|
|
|
|
List<Status> statusesToRemove = new ArrayList<>();
|
2019-09-06 17:55:14 +02:00
|
|
|
if (statusAction == API.StatusAction.MUTE || statusAction == API.StatusAction.BLOCK) {
|
|
|
|
for (Status status : statuses) {
|
|
|
|
if (status.getAccount().getId().equals(targetedId))
|
2019-01-14 16:03:10 +01:00
|
|
|
statusesToRemove.add(status);
|
|
|
|
}
|
|
|
|
statuses.removeAll(statusesToRemove);
|
2019-01-14 18:16:45 +01:00
|
|
|
pixelfedListAdapter.notifyDataSetChanged();
|
2019-09-06 17:55:14 +02:00
|
|
|
} else if (statusAction == API.StatusAction.UNSTATUS) {
|
2019-01-14 16:03:10 +01:00
|
|
|
int position = 0;
|
2019-09-06 17:55:14 +02:00
|
|
|
for (Status status : statuses) {
|
|
|
|
if (status.getId().equals(targetedId)) {
|
2019-01-14 16:03:10 +01:00
|
|
|
statuses.remove(status);
|
2019-01-14 18:16:45 +01:00
|
|
|
pixelfedListAdapter.notifyItemRemoved(position);
|
2020-04-09 18:57:12 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2019-01-14 16:03:10 +01:00
|
|
|
//Remove the status from cache also
|
|
|
|
try {
|
2019-09-06 17:55:14 +02:00
|
|
|
new StatusCacheDAO(context, db).remove(StatusCacheDAO.ARCHIVE_CACHE, status);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2019-01-14 16:03:10 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
position++;
|
|
|
|
}
|
2019-09-06 17:55:14 +02:00
|
|
|
} else if (statusAction == API.StatusAction.PIN || statusAction == API.StatusAction.UNPIN) {
|
2019-01-14 16:03:10 +01:00
|
|
|
int position = 0;
|
2019-09-06 17:55:14 +02:00
|
|
|
for (Status status : statuses) {
|
2019-01-14 16:03:10 +01:00
|
|
|
if (status.getId().equals(targetedId)) {
|
2021-01-18 19:00:43 +01:00
|
|
|
status.setPinned(statusAction == API.StatusAction.PIN);
|
2019-01-14 18:16:45 +01:00
|
|
|
pixelfedListAdapter.notifyItemChanged(position);
|
2019-01-14 16:03:10 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
position++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 19:18:44 +02:00
|
|
|
private void timedMuteAction(Status status) {
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK) {
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
} else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
|
|
|
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
|
|
|
View dialogView = inflater.inflate(R.layout.datetime_picker, new LinearLayout(context), false);
|
|
|
|
dialogBuilder.setView(dialogView);
|
|
|
|
final AlertDialog alertDialog = dialogBuilder.create();
|
|
|
|
final DatePicker datePicker = dialogView.findViewById(R.id.date_picker);
|
|
|
|
final TimePicker timePicker = dialogView.findViewById(R.id.time_picker);
|
|
|
|
timePicker.setIs24HourView(true);
|
|
|
|
Button date_time_cancel = dialogView.findViewById(R.id.date_time_cancel);
|
|
|
|
final ImageButton date_time_previous = dialogView.findViewById(R.id.date_time_previous);
|
|
|
|
final ImageButton date_time_next = dialogView.findViewById(R.id.date_time_next);
|
|
|
|
final ImageButton date_time_set = dialogView.findViewById(R.id.date_time_set);
|
|
|
|
|
|
|
|
//Buttons management
|
2020-03-07 14:16:28 +01:00
|
|
|
date_time_cancel.setOnClickListener(v -> alertDialog.dismiss());
|
|
|
|
date_time_next.setOnClickListener(v -> {
|
|
|
|
datePicker.setVisibility(View.GONE);
|
|
|
|
timePicker.setVisibility(View.VISIBLE);
|
|
|
|
date_time_previous.setVisibility(View.VISIBLE);
|
|
|
|
date_time_next.setVisibility(View.GONE);
|
|
|
|
date_time_set.setVisibility(View.VISIBLE);
|
2019-09-30 19:18:44 +02:00
|
|
|
});
|
2020-03-07 14:16:28 +01:00
|
|
|
date_time_previous.setOnClickListener(v -> {
|
|
|
|
datePicker.setVisibility(View.VISIBLE);
|
|
|
|
timePicker.setVisibility(View.GONE);
|
|
|
|
date_time_previous.setVisibility(View.GONE);
|
|
|
|
date_time_next.setVisibility(View.VISIBLE);
|
|
|
|
date_time_set.setVisibility(View.GONE);
|
2019-09-30 19:18:44 +02:00
|
|
|
});
|
2020-03-07 14:16:28 +01:00
|
|
|
date_time_set.setOnClickListener(v -> {
|
|
|
|
int hour, minute;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
hour = timePicker.getHour();
|
|
|
|
minute = timePicker.getMinute();
|
|
|
|
} else {
|
|
|
|
hour = timePicker.getCurrentHour();
|
|
|
|
minute = timePicker.getCurrentMinute();
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
Calendar calendar = new GregorianCalendar(datePicker.getYear(),
|
|
|
|
datePicker.getMonth(),
|
|
|
|
datePicker.getDayOfMonth(),
|
|
|
|
hour,
|
|
|
|
minute);
|
|
|
|
long time = calendar.getTimeInMillis();
|
|
|
|
if ((time - new Date().getTime()) < 60000) {
|
|
|
|
Toasty.error(context, context.getString(R.string.timed_mute_date_error), Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
//Store the toot as draft first
|
|
|
|
String targeted_id = status.getAccount().getId();
|
|
|
|
Date date_mute = new Date(time);
|
2020-04-09 18:57:12 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
2020-03-07 14:16:28 +01:00
|
|
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
|
|
|
new TempMuteDAO(context, db).insert(account, targeted_id, new Date(time));
|
|
|
|
if (mutedAccount != null && !mutedAccount.contains(account.getId()))
|
|
|
|
mutedAccount.add(targeted_id);
|
|
|
|
else if (mutedAccount == null) {
|
|
|
|
mutedAccount = new ArrayList<>();
|
|
|
|
mutedAccount.add(targeted_id);
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
Toasty.success(context, context.getString(R.string.timed_mute_date, status.getAccount().getAcct(), Helper.dateToString(date_mute)), Toast.LENGTH_LONG).show();
|
|
|
|
alertDialog.dismiss();
|
|
|
|
send_delete_statuses(targeted_id);
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
alertDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void send_delete_statuses(String targetedId) {
|
|
|
|
//Delete in the current timeline
|
|
|
|
List<Status> statusesToRemove = new ArrayList<>();
|
|
|
|
for (Status status : statuses) {
|
|
|
|
if (status.getAccount().getId().equals(targetedId))
|
|
|
|
statusesToRemove.add(status);
|
|
|
|
}
|
|
|
|
statuses.removeAll(statusesToRemove);
|
|
|
|
pixelfedListAdapter.notifyDataSetChanged();
|
|
|
|
//Send an intent to delete in every timelines
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.putString("receive_action", targetedId);
|
|
|
|
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
|
|
|
|
intentBC.putExtras(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void scheduleBoost(Status status) {
|
|
|
|
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK) {
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
} else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog.Builder dialogBuilderBoost = new AlertDialog.Builder(context, style);
|
|
|
|
LayoutInflater inflaterBoost = ((Activity) context).getLayoutInflater();
|
|
|
|
View dialogViewBoost = inflaterBoost.inflate(R.layout.datetime_picker, new LinearLayout(context), false);
|
|
|
|
dialogBuilderBoost.setView(dialogViewBoost);
|
|
|
|
final AlertDialog alertDialogBoost = dialogBuilderBoost.create();
|
|
|
|
|
|
|
|
final DatePicker datePickerBoost = dialogViewBoost.findViewById(R.id.date_picker);
|
|
|
|
final TimePicker timePickerBoost = dialogViewBoost.findViewById(R.id.time_picker);
|
|
|
|
timePickerBoost.setIs24HourView(true);
|
|
|
|
Button date_time_cancelBoost = dialogViewBoost.findViewById(R.id.date_time_cancel);
|
|
|
|
final ImageButton date_time_previousBoost = dialogViewBoost.findViewById(R.id.date_time_previous);
|
|
|
|
final ImageButton date_time_nextBoost = dialogViewBoost.findViewById(R.id.date_time_next);
|
|
|
|
final ImageButton date_time_setBoost = dialogViewBoost.findViewById(R.id.date_time_set);
|
|
|
|
|
|
|
|
//Buttons management
|
2020-03-07 14:16:28 +01:00
|
|
|
date_time_cancelBoost.setOnClickListener(v -> alertDialogBoost.dismiss());
|
|
|
|
date_time_nextBoost.setOnClickListener(v -> {
|
|
|
|
datePickerBoost.setVisibility(View.GONE);
|
|
|
|
timePickerBoost.setVisibility(View.VISIBLE);
|
|
|
|
date_time_previousBoost.setVisibility(View.VISIBLE);
|
|
|
|
date_time_nextBoost.setVisibility(View.GONE);
|
|
|
|
date_time_setBoost.setVisibility(View.VISIBLE);
|
2019-09-30 19:18:44 +02:00
|
|
|
});
|
2020-03-07 14:16:28 +01:00
|
|
|
date_time_previousBoost.setOnClickListener(v -> {
|
|
|
|
datePickerBoost.setVisibility(View.VISIBLE);
|
|
|
|
timePickerBoost.setVisibility(View.GONE);
|
|
|
|
date_time_previousBoost.setVisibility(View.GONE);
|
|
|
|
date_time_nextBoost.setVisibility(View.VISIBLE);
|
|
|
|
date_time_setBoost.setVisibility(View.GONE);
|
2019-09-30 19:18:44 +02:00
|
|
|
});
|
2020-03-07 14:16:28 +01:00
|
|
|
date_time_setBoost.setOnClickListener(v -> {
|
|
|
|
int hour, minute;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
hour = timePickerBoost.getHour();
|
|
|
|
minute = timePickerBoost.getMinute();
|
|
|
|
} else {
|
|
|
|
hour = timePickerBoost.getCurrentHour();
|
|
|
|
minute = timePickerBoost.getCurrentMinute();
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
2020-03-07 14:16:28 +01:00
|
|
|
Calendar calendar = new GregorianCalendar(datePickerBoost.getYear(),
|
|
|
|
datePickerBoost.getMonth(),
|
|
|
|
datePickerBoost.getDayOfMonth(),
|
|
|
|
hour,
|
|
|
|
minute);
|
|
|
|
long time = calendar.getTimeInMillis();
|
|
|
|
if ((time - new Date().getTime()) < 60000) {
|
|
|
|
Toasty.warning(context, context.getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
//Schedules the toot
|
|
|
|
ScheduledBoostsSyncJob.schedule(context, status, time);
|
|
|
|
//Clear content
|
|
|
|
Toasty.info(context, context.getString(R.string.boost_scheduled), Toast.LENGTH_LONG).show();
|
|
|
|
alertDialogBoost.dismiss();
|
2019-09-30 19:18:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
alertDialogBoost.show();
|
|
|
|
}
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public void notifyStatusChanged(Status status) {
|
2019-01-14 18:16:45 +01:00
|
|
|
for (int i = 0; i < pixelfedListAdapter.getItemCount(); i++) {
|
2019-01-14 16:03:10 +01:00
|
|
|
//noinspection ConstantConditions
|
2019-01-14 18:16:45 +01:00
|
|
|
if (pixelfedListAdapter.getItemAt(i) != null && pixelfedListAdapter.getItemAt(i).getId().equals(status.getId())) {
|
2019-01-14 16:03:10 +01:00
|
|
|
try {
|
2019-01-14 18:16:45 +01:00
|
|
|
pixelfedListAdapter.notifyItemChanged(i);
|
2019-01-14 16:03:10 +01:00
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrieveEmoji(Status status, boolean fromTranslation) {
|
2019-09-06 17:55:14 +02:00
|
|
|
if (status != null) {
|
|
|
|
if (!fromTranslation) {
|
|
|
|
status.setEmojiFound(true);
|
|
|
|
} else {
|
|
|
|
status.setEmojiTranslateFound(true);
|
2019-01-14 16:03:10 +01:00
|
|
|
}
|
|
|
|
notifyStatusChanged(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrieveEmoji(Notification notification) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrieveSearchEmoji(List<Emojis> emojis) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:16:28 +01:00
|
|
|
private static class ViewHolderEmpty extends RecyclerView.ViewHolder {
|
2019-11-15 16:32:25 +01:00
|
|
|
ViewHolderEmpty(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:16:28 +01:00
|
|
|
private static class ViewHolderPixelfed extends RecyclerView.ViewHolder {
|
2019-11-15 16:32:25 +01:00
|
|
|
SliderView imageSlider;
|
|
|
|
ImageView art_media, art_media_play, pf_pp, pf_comment;
|
|
|
|
SparkButton pf_fav, pf_share;
|
|
|
|
TextView pf_username, pf_likes, pf_description, pf_date;
|
|
|
|
CardView pf_cardview;
|
|
|
|
LinearLayout pf_bottom_container;
|
|
|
|
LinearLayout pixelfed_comments;
|
|
|
|
RecyclerView lv_comments;
|
|
|
|
|
|
|
|
ConstraintLayout quick_reply_container;
|
|
|
|
MastalabAutoCompleteTextView quick_reply_text;
|
|
|
|
ImageView quick_reply_switch_to_full, status_more;
|
|
|
|
TextView toot_space_left;
|
|
|
|
ImageView quick_reply_emoji;
|
|
|
|
Button quick_reply_button;
|
|
|
|
ImageView quick_reply_privacy;
|
|
|
|
|
|
|
|
ViewHolderPixelfed(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
art_media = itemView.findViewById(R.id.art_media);
|
|
|
|
art_media_play = itemView.findViewById(R.id.art_media_play);
|
|
|
|
imageSlider = itemView.findViewById(R.id.imageSlider);
|
|
|
|
pf_pp = itemView.findViewById(R.id.pf_pp);
|
|
|
|
pf_username = itemView.findViewById(R.id.pf_username);
|
|
|
|
pf_likes = itemView.findViewById(R.id.pf_likes);
|
|
|
|
pf_description = itemView.findViewById(R.id.pf_description);
|
|
|
|
pf_date = itemView.findViewById(R.id.pf_date);
|
|
|
|
pf_fav = itemView.findViewById(R.id.pf_fav);
|
|
|
|
pf_comment = itemView.findViewById(R.id.pf_comment);
|
|
|
|
pf_share = itemView.findViewById(R.id.pf_share);
|
|
|
|
pf_cardview = itemView.findViewById(R.id.pf_cardview);
|
|
|
|
pf_bottom_container = itemView.findViewById(R.id.pf_bottom_container);
|
|
|
|
pixelfed_comments = itemView.findViewById(R.id.pixelfed_comments);
|
|
|
|
lv_comments = itemView.findViewById(R.id.lv_comments);
|
|
|
|
quick_reply_container = itemView.findViewById(R.id.quick_reply_container);
|
|
|
|
status_more = itemView.findViewById(R.id.status_more);
|
|
|
|
quick_reply_text = itemView.findViewById(R.id.quick_reply_text);
|
|
|
|
quick_reply_switch_to_full = itemView.findViewById(R.id.quick_reply_switch_to_full);
|
|
|
|
toot_space_left = itemView.findViewById(R.id.toot_space_left);
|
|
|
|
quick_reply_emoji = itemView.findViewById(R.id.quick_reply_emoji);
|
|
|
|
quick_reply_button = itemView.findViewById(R.id.quick_reply_button);
|
|
|
|
quick_reply_privacy = itemView.findViewById(R.id.quick_reply_privacy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 16:03:10 +01:00
|
|
|
}
|