2015-05-21 23:27:27 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2015-05-21 23:27:27 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2015-05-21 23:27:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
import android.Manifest;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2020-06-25 17:29:04 +02:00
|
|
|
import android.app.Activity;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.content.Context;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.content.DialogInterface;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.content.Intent;
|
2020-06-25 17:29:04 +02:00
|
|
|
import android.content.pm.PackageManager;
|
2015-12-09 19:27:52 +01:00
|
|
|
import android.graphics.Canvas;
|
2020-06-25 17:29:04 +02:00
|
|
|
import android.os.Build;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.Spanned;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.view.MotionEvent;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.FrameLayout;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.widget.LinearLayout;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.widget.TextView;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.collection.LongSparseArray;
|
|
|
|
import androidx.recyclerview.widget.DefaultItemAnimator;
|
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.internal.Streams;
|
|
|
|
import com.google.gson.stream.JsonWriter;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2020-06-25 17:29:04 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2020-06-25 17:29:04 +02:00
|
|
|
import org.telegram.messenger.MediaDataController;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.messenger.R;
|
2020-06-25 17:29:04 +02:00
|
|
|
import org.telegram.messenger.SendMessagesHelper;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
2015-12-09 19:27:52 +01:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.ActionBar.BackDrawable;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Cells.RadioColorCell;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Cells.ShadowSectionCell;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Cells.StickerSetCell;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.ui.Cells.TextCheckCell;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Cells.TextInfoPrivacyCell;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Cells.TextSettingsCell;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.Components.Bulletin;
|
2020-12-23 08:48:30 +01:00
|
|
|
import org.telegram.ui.Components.BulletinFactory;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.Components.NumberTextView;
|
2015-12-09 19:27:52 +01:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.Components.ReorderingBulletinLayout;
|
|
|
|
import org.telegram.ui.Components.ReorderingHintDrawable;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.StickersAlert;
|
2020-04-24 11:21:58 +02:00
|
|
|
import org.telegram.ui.Components.TrendingStickersAlert;
|
|
|
|
import org.telegram.ui.Components.TrendingStickersLayout;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.URLSpanNoUnderline;
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.StringWriter;
|
2015-05-21 23:27:27 +02:00
|
|
|
import java.util.ArrayList;
|
2020-06-25 17:29:04 +02:00
|
|
|
import java.util.Date;
|
2020-03-30 14:00:09 +02:00
|
|
|
import java.util.List;
|
2015-05-21 23:27:27 +02:00
|
|
|
import java.util.Locale;
|
2020-06-25 17:29:04 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
import kotlin.Unit;
|
|
|
|
import tw.nekomimi.nekogram.BottomBuilder;
|
|
|
|
import tw.nekomimi.nekogram.utils.AlertUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.FileUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.ShareUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.StickersUtil;
|
|
|
|
import tw.nekomimi.nekogram.utils.UIUtil;
|
2019-05-14 14:08:05 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public class StickersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
private static final int MENU_ARCHIVE = 0;
|
|
|
|
private static final int MENU_DELETE = 1;
|
2020-06-25 17:29:04 +02:00
|
|
|
private static final int MENU_EXPORT = 5;
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
private RecyclerListView listView;
|
2015-05-21 23:27:27 +02:00
|
|
|
private ListAdapter listAdapter;
|
2019-05-14 14:08:05 +02:00
|
|
|
@SuppressWarnings("FieldCanBeLocal")
|
|
|
|
private LinearLayoutManager layoutManager;
|
2020-03-30 14:00:09 +02:00
|
|
|
private DefaultItemAnimator itemAnimator;
|
|
|
|
private ItemTouchHelper itemTouchHelper;
|
|
|
|
private NumberTextView selectedCountTextView;
|
2020-06-04 18:47:15 +02:00
|
|
|
private TrendingStickersAlert trendingStickersAlert;
|
2020-03-30 14:00:09 +02:00
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
private ActionBarMenuItem exportMenuItem;
|
2020-03-30 14:00:09 +02:00
|
|
|
private ActionBarMenuItem archiveMenuItem;
|
|
|
|
private ActionBarMenuItem deleteMenuItem;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
private int activeReorderingRequests;
|
2015-12-09 19:27:52 +01:00
|
|
|
private boolean needReorder;
|
2020-03-30 14:00:09 +02:00
|
|
|
private final int currentType;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int suggestRow;
|
2019-08-22 01:53:26 +02:00
|
|
|
private int loopRow;
|
2020-03-30 14:00:09 +02:00
|
|
|
private int loopInfoRow;
|
2016-10-11 13:57:01 +02:00
|
|
|
private int featuredRow;
|
2020-03-30 14:00:09 +02:00
|
|
|
private int stickersBotInfo;
|
2016-10-11 13:57:01 +02:00
|
|
|
private int masksRow;
|
|
|
|
private int masksInfoRow;
|
|
|
|
private int archivedRow;
|
|
|
|
private int archivedInfoRow;
|
2015-05-21 23:27:27 +02:00
|
|
|
private int stickersStartRow;
|
|
|
|
private int stickersEndRow;
|
2016-10-11 13:57:01 +02:00
|
|
|
private int stickersShadowRow;
|
2015-05-21 23:27:27 +02:00
|
|
|
private int rowCount;
|
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
public class TouchHelperCallback extends ItemTouchHelper.Callback {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLongPressDragEnabled() {
|
2020-03-30 14:00:09 +02:00
|
|
|
return listAdapter.hasSelected();
|
2015-12-09 19:27:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
|
|
|
if (viewHolder.getItemViewType() != 0) {
|
|
|
|
return makeMovementFlags(0, 0);
|
|
|
|
}
|
|
|
|
return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
|
|
|
|
if (source.getItemViewType() != target.getItemViewType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
listAdapter.swapElements(source.getAdapterPosition(), target.getAdapterPosition());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
|
|
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (actionState == ItemTouchHelper.ACTION_STATE_IDLE) {
|
|
|
|
sendReorder();
|
|
|
|
} else {
|
2015-12-09 19:27:52 +01:00
|
|
|
listView.cancelClickRunnables(false);
|
|
|
|
viewHolder.itemView.setPressed(true);
|
|
|
|
}
|
|
|
|
super.onSelectedChanged(viewHolder, actionState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
|
|
|
super.clearView(recyclerView, viewHolder);
|
|
|
|
viewHolder.itemView.setPressed(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public StickersActivity(int type) {
|
|
|
|
super();
|
|
|
|
currentType = type;
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
private File stickersFile;
|
|
|
|
|
|
|
|
public StickersActivity(File stickersFile) {
|
|
|
|
this(MediaDataController.TYPE_IMAGE);
|
|
|
|
this.stickersFile = stickersFile;
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2019-07-18 15:01:39 +02:00
|
|
|
MediaDataController.getInstance(currentAccount).checkStickers(currentType);
|
|
|
|
if (currentType == MediaDataController.TYPE_IMAGE) {
|
|
|
|
MediaDataController.getInstance(currentAccount).checkFeaturedStickers();
|
2020-03-30 14:00:09 +02:00
|
|
|
MediaDataController.getInstance(currentAccount).checkStickers(MediaDataController.TYPE_MASK);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.stickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.archivedStickersCountDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.featuredStickersDidLoad);
|
2015-05-21 23:27:27 +02:00
|
|
|
updateRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.stickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.archivedStickersCountDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.featuredStickersDidLoad);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
private int menu_other = 2;
|
|
|
|
private int menu_export = 3;
|
|
|
|
private int menu_import = 4;
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2020-03-30 14:00:09 +02:00
|
|
|
actionBar.setBackButtonDrawable(new BackDrawable(false));
|
2015-05-21 23:27:27 +02:00
|
|
|
actionBar.setAllowOverlayTitle(true);
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentType == MediaDataController.TYPE_IMAGE) {
|
2017-07-08 18:32:04 +02:00
|
|
|
actionBar.setTitle(LocaleController.getString("StickersName", R.string.StickersName));
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("Masks", R.string.Masks));
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (onBackPressed()) {
|
|
|
|
finishFragment();
|
|
|
|
}
|
2020-06-25 17:29:04 +02:00
|
|
|
} else if (id == MENU_EXPORT || id == MENU_ARCHIVE || id == MENU_DELETE) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (!needReorder) {
|
|
|
|
if (activeReorderingRequests == 0) {
|
|
|
|
listAdapter.processSelectionMenu(id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendReorder();
|
|
|
|
}
|
2020-06-25 17:29:04 +02:00
|
|
|
} else if (id == menu_export) {
|
|
|
|
exportStickers();
|
|
|
|
} else if (id == menu_import) {
|
|
|
|
try {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
getParentActivity().requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (Throwable ignore) {
|
|
|
|
}
|
|
|
|
DocumentSelectActivity fragment = new DocumentSelectActivity(false);
|
|
|
|
fragment.setMaxSelectedFiles(1);
|
|
|
|
fragment.setAllowPhoto(false);
|
|
|
|
fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files, String caption, boolean notify, int scheduleDate) {
|
|
|
|
activity.finishFragment();
|
|
|
|
processStickersFile(new File(files.get(0)), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startDocumentSelectActivity() {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
|
|
|
|
ActionBarMenuItem otherItem = menu.addItem(menu_other, R.drawable.ic_ab_other);
|
|
|
|
|
|
|
|
otherItem.addSubItem(menu_export, R.drawable.baseline_file_download_24, LocaleController.getString("ExportStickers", R.string.ExportStickers));
|
|
|
|
otherItem.addSubItem(menu_import, R.drawable.baseline_playlist_add_24, LocaleController.getString("ImportStickers", R.string.ImportStickers));
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
final ActionBarMenu actionMode = actionBar.createActionMode();
|
|
|
|
selectedCountTextView = new NumberTextView(actionMode.getContext());
|
|
|
|
selectedCountTextView.setTextSize(18);
|
|
|
|
selectedCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
selectedCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
|
|
|
|
actionMode.addView(selectedCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 72, 0, 0, 0));
|
|
|
|
selectedCountTextView.setOnTouchListener((v, event) -> true);
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
exportMenuItem = actionMode.addItemWithWidth(MENU_EXPORT, R.drawable.baseline_file_download_24, AndroidUtilities.dp(54));
|
|
|
|
archiveMenuItem = actionMode.addItemWithWidth(MENU_ARCHIVE, R.drawable.baseline_archive_24, AndroidUtilities.dp(54));
|
|
|
|
deleteMenuItem = actionMode.addItemWithWidth(MENU_DELETE, R.drawable.baseline_delete_24, AndroidUtilities.dp(54));
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
listAdapter = new ListAdapter(context, MediaDataController.getInstance(currentAccount).getStickerSets(currentType));
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
2017-03-31 01:58:05 +02:00
|
|
|
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
listView = new RecyclerListView(context);
|
2016-01-11 18:19:48 +01:00
|
|
|
listView.setFocusable(true);
|
2016-06-24 12:27:15 +02:00
|
|
|
listView.setTag(7);
|
2020-03-30 14:00:09 +02:00
|
|
|
layoutManager = new LinearLayoutManager(context) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void calculateExtraLayoutSpace(@NonNull RecyclerView.State state, @NonNull int[] extraLayoutSpace) {
|
|
|
|
extraLayoutSpace[1] = listView.getHeight();
|
|
|
|
}
|
|
|
|
};
|
2015-12-09 19:27:52 +01:00
|
|
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
listView.setLayoutManager(layoutManager);
|
2020-03-30 14:00:09 +02:00
|
|
|
itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
|
2015-12-09 19:27:52 +01:00
|
|
|
itemTouchHelper.attachToRecyclerView(listView);
|
2020-03-30 14:00:09 +02:00
|
|
|
itemAnimator = (DefaultItemAnimator) listView.getItemAnimator();
|
|
|
|
itemAnimator.setSupportsChangeAnimations(false);
|
2015-12-09 19:27:52 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
listView.setAdapter(listAdapter);
|
2019-01-23 18:03:33 +01:00
|
|
|
listView.setOnItemClickListener((view, position) -> {
|
|
|
|
if (position >= stickersStartRow && position < stickersEndRow && getParentActivity() != null) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (!listAdapter.hasSelected()) {
|
|
|
|
final TLRPC.TL_messages_stickerSet stickerSet = listAdapter.stickerSets.get(position - stickersStartRow);
|
|
|
|
ArrayList<TLRPC.Document> stickers = stickerSet.documents;
|
|
|
|
if (stickers == null || stickers.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
showDialog(new StickersAlert(getParentActivity(), StickersActivity.this, null, stickerSet, null));
|
|
|
|
} else {
|
|
|
|
listAdapter.toggleSelected(position);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (position == featuredRow) {
|
2020-04-24 11:21:58 +02:00
|
|
|
final TrendingStickersLayout.Delegate trendingDelegate = new TrendingStickersLayout.Delegate() {
|
|
|
|
@Override
|
|
|
|
public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet, boolean primary) {
|
|
|
|
MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 2, StickersActivity.this, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
|
|
|
|
MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 0, StickersActivity.this, false, false);
|
|
|
|
}
|
|
|
|
};
|
2020-06-04 18:47:15 +02:00
|
|
|
trendingStickersAlert = new TrendingStickersAlert(context, this, new TrendingStickersLayout(context, trendingDelegate));
|
|
|
|
trendingStickersAlert.show();
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (position == archivedRow) {
|
|
|
|
presentFragment(new ArchivedStickersActivity(currentType));
|
|
|
|
} else if (position == masksRow) {
|
2019-07-18 15:01:39 +02:00
|
|
|
presentFragment(new StickersActivity(MediaDataController.TYPE_MASK));
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (position == suggestRow) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("SuggestStickers", R.string.SuggestStickers));
|
2019-12-31 14:08:08 +01:00
|
|
|
String[] items = new String[]{
|
2019-01-23 18:03:33 +01:00
|
|
|
LocaleController.getString("SuggestStickersAll", R.string.SuggestStickersAll),
|
|
|
|
LocaleController.getString("SuggestStickersInstalled", R.string.SuggestStickersInstalled),
|
|
|
|
LocaleController.getString("SuggestStickersNone", R.string.SuggestStickersNone),
|
|
|
|
};
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(getParentActivity());
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
builder.setView(linearLayout);
|
|
|
|
|
|
|
|
for (int a = 0; a < items.length; a++) {
|
|
|
|
RadioColorCell cell = new RadioColorCell(getParentActivity());
|
|
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
|
|
cell.setTextAndValue(items[a], SharedConfig.suggestStickers == a);
|
|
|
|
linearLayout.addView(cell);
|
|
|
|
cell.setOnClickListener(v -> {
|
|
|
|
Integer which = (Integer) v.getTag();
|
|
|
|
SharedConfig.setSuggestStickers(which);
|
|
|
|
listAdapter.notifyItemChanged(suggestRow);
|
|
|
|
builder.getDismissRunnable().run();
|
|
|
|
});
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
showDialog(builder.create());
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (position == loopRow) {
|
|
|
|
SharedConfig.toggleLoopStickers();
|
2020-03-30 14:00:09 +02:00
|
|
|
listAdapter.notifyItemChanged(loopRow, ListAdapter.UPDATE_LOOP_STICKERS);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
listView.setOnItemLongClickListener((view, position) -> {
|
|
|
|
if (!listAdapter.hasSelected() && position >= stickersStartRow && position < stickersEndRow) {
|
|
|
|
listAdapter.toggleSelected(position);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
if (stickersFile != null) {
|
|
|
|
|
|
|
|
processStickersFile(stickersFile, true);
|
|
|
|
stickersFile = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
public void processStickersFile(File file, boolean exitOnFail) {
|
|
|
|
|
|
|
|
if (!file.isFile() || !file.getName().endsWith("nekox-stickers.json")) {
|
|
|
|
|
|
|
|
showError("not a stickers file", exitOnFail);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (file.length() > 3 * 1024 * 1024L) {
|
|
|
|
|
|
|
|
showError("file too large", exitOnFail);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog pro = new AlertDialog(getParentActivity(), 1);
|
|
|
|
pro.show();
|
2020-03-30 14:00:09 +02:00
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
UIUtil.runOnIoDispatcher(() -> {
|
|
|
|
|
|
|
|
JsonObject stickerObj = new Gson().fromJson(FileUtil.readUtf8String(file), JsonObject.class);
|
|
|
|
|
|
|
|
StickersUtil.importStickers(stickerObj, this, pro);
|
|
|
|
|
|
|
|
UIUtil.runOnUIThread(() -> {
|
|
|
|
|
|
|
|
pro.dismiss();
|
|
|
|
|
|
|
|
MediaDataController.getInstance(currentAccount).checkStickers(currentType);
|
|
|
|
updateRows();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showError(String msg, boolean exitOnFail) {
|
|
|
|
|
|
|
|
AlertUtil.showSimpleAlert(getParentActivity(), LocaleController.getString("InvalidStickersFile", R.string.InvalidStickersFile) + msg, (__) -> {
|
|
|
|
|
|
|
|
if (exitOnFail) finishFragment();
|
|
|
|
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void exportStickers() {
|
|
|
|
|
|
|
|
BottomBuilder builder = new BottomBuilder(getParentActivity());
|
|
|
|
|
2020-06-28 12:05:29 +02:00
|
|
|
builder.addTitle(LocaleController.getString("ExportStickers", R.string.ExportStickers), true);
|
2020-06-25 17:29:04 +02:00
|
|
|
|
|
|
|
AtomicBoolean exportSets = new AtomicBoolean(true);
|
|
|
|
AtomicBoolean exportArchived = new AtomicBoolean(true);
|
|
|
|
|
|
|
|
final AtomicReference<TextView> exportButton = new AtomicReference<>();
|
|
|
|
|
|
|
|
builder.addCheckItems(new String[]{
|
|
|
|
LocaleController.getString("StickerSets", R.string.StickerSets),
|
|
|
|
LocaleController.getString("ArchivedStickers", R.string.ArchivedStickers)
|
|
|
|
}, (__) -> true, false, (index, text, cell) -> {
|
|
|
|
|
|
|
|
boolean export;
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
|
|
|
case 0: {
|
|
|
|
|
|
|
|
export = exportSets.get();
|
|
|
|
exportSets.set(export = !export);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
|
|
|
|
export = exportArchived.get();
|
|
|
|
exportArchived.set(export = !export);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cell.setChecked(export);
|
|
|
|
|
|
|
|
if (!exportSets.get() && !exportArchived.get()) {
|
|
|
|
|
|
|
|
exportButton.get().setEnabled(false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
exportButton.get().setEnabled(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.addCancelButton();
|
|
|
|
|
|
|
|
exportButton.set(builder.addButton(LocaleController.getString("Export", R.string.ExportStickers), (it) -> {
|
|
|
|
|
|
|
|
exportStickersFinal(exportSets.get(), exportArchived.get());
|
|
|
|
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
builder.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void exportStickersFinal(boolean exportSets, boolean exportArchived) {
|
|
|
|
|
|
|
|
AlertDialog pro = new AlertDialog(getParentActivity(), 3);
|
|
|
|
|
|
|
|
pro.setCanCacnel(false);
|
|
|
|
|
|
|
|
pro.show();
|
|
|
|
|
|
|
|
UIUtil.runOnIoDispatcher(() -> {
|
|
|
|
|
|
|
|
Activity ctx = getParentActivity();
|
|
|
|
|
|
|
|
JsonObject exportObj = StickersUtil.exportStickers(currentAccount, exportSets, exportArchived);
|
|
|
|
|
|
|
|
File cacheFile = new File(ApplicationLoader.applicationContext.getCacheDir(), new Date().toLocaleString() + ".nekox-stickers.json");
|
|
|
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
|
|
|
jsonWriter.setLenient(true);
|
|
|
|
jsonWriter.setIndent(" ");
|
|
|
|
try {
|
|
|
|
Streams.write(exportObj, jsonWriter);
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FileUtil.writeUtf8String(stringWriter.toString(), cacheFile);
|
|
|
|
|
|
|
|
UIUtil.runOnUIThread(() -> {
|
|
|
|
|
|
|
|
pro.dismiss();
|
|
|
|
|
|
|
|
ShareUtil.shareFile(ctx, cacheFile);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBackPressed() {
|
|
|
|
if (listAdapter.hasSelected()) {
|
|
|
|
listAdapter.clearSelected();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (id == NotificationCenter.stickersDidLoad) {
|
2020-03-30 14:00:09 +02:00
|
|
|
final int type = (int) args[0];
|
|
|
|
if (type == currentType) {
|
2016-10-11 13:57:01 +02:00
|
|
|
updateRows();
|
2020-03-30 14:00:09 +02:00
|
|
|
} else if (currentType == MediaDataController.TYPE_IMAGE && type == MediaDataController.TYPE_MASK) {
|
|
|
|
listAdapter.notifyItemChanged(masksRow);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.featuredStickersDidLoad) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyItemChanged(0);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.archivedStickersCountDidLoad) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if ((Integer) args[0] == currentType) {
|
|
|
|
updateRows();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
private void sendReorder() {
|
|
|
|
if (!needReorder) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
MediaDataController.getInstance(currentAccount).calcNewHash(currentType);
|
2015-12-09 19:27:52 +01:00
|
|
|
needReorder = false;
|
2020-03-30 14:00:09 +02:00
|
|
|
activeReorderingRequests++;
|
2015-12-09 19:27:52 +01:00
|
|
|
TLRPC.TL_messages_reorderStickerSets req = new TLRPC.TL_messages_reorderStickerSets();
|
2019-07-18 15:01:39 +02:00
|
|
|
req.masks = currentType == MediaDataController.TYPE_MASK;
|
2020-03-30 14:00:09 +02:00
|
|
|
for (int a = 0; a < listAdapter.stickerSets.size(); a++) {
|
|
|
|
req.order.add(listAdapter.stickerSets.get(a).set.id);
|
2015-12-09 19:27:52 +01:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> activeReorderingRequests--));
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.stickersDidLoad, currentType);
|
2015-12-09 19:27:52 +01:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private void updateRows() {
|
2020-03-30 14:00:09 +02:00
|
|
|
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
|
|
|
|
final List<TLRPC.TL_messages_stickerSet> newList = mediaDataController.getStickerSets(currentType);
|
|
|
|
|
|
|
|
DiffUtil.DiffResult diffResult = null;
|
|
|
|
|
|
|
|
if (listAdapter != null) {
|
|
|
|
if (!isPaused) {
|
|
|
|
diffResult = DiffUtil.calculateDiff(new DiffUtil.Callback() {
|
|
|
|
|
|
|
|
final List<TLRPC.TL_messages_stickerSet> oldList = listAdapter.stickerSets;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOldListSize() {
|
|
|
|
return oldList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getNewListSize() {
|
|
|
|
return newList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
|
|
|
return oldList.get(oldItemPosition).set.id == newList.get(newItemPosition).set.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
|
|
|
final TLRPC.StickerSet oldSet = oldList.get(oldItemPosition).set;
|
|
|
|
final TLRPC.StickerSet newSet = newList.get(newItemPosition).set;
|
|
|
|
return TextUtils.equals(oldSet.title, newSet.title) && oldSet.count == newSet.count;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
listAdapter.setStickerSets(newList);
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
rowCount = 0;
|
2019-08-22 01:53:26 +02:00
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentType == MediaDataController.TYPE_IMAGE) {
|
2018-07-30 04:07:02 +02:00
|
|
|
suggestRow = rowCount++;
|
2019-08-22 01:53:26 +02:00
|
|
|
loopRow = rowCount++;
|
2020-03-30 14:00:09 +02:00
|
|
|
loopInfoRow = rowCount++;
|
2020-03-31 04:37:01 +02:00
|
|
|
featuredRow = -1;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
suggestRow = -1;
|
2019-08-22 01:53:26 +02:00
|
|
|
loopRow = -1;
|
2020-03-30 14:00:09 +02:00
|
|
|
loopInfoRow = -1;
|
|
|
|
featuredRow = -1;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
if (mediaDataController.getArchivedStickersCount(currentType) != 0) {
|
|
|
|
final boolean inserted = archivedRow == -1;
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
archivedRow = rowCount++;
|
2020-03-30 14:00:09 +02:00
|
|
|
archivedInfoRow = currentType == MediaDataController.TYPE_MASK ? rowCount++ : -1;
|
|
|
|
|
|
|
|
if (listAdapter != null && inserted) {
|
|
|
|
listAdapter.notifyItemRangeInserted(archivedRow, archivedInfoRow != -1 ? 2 : 1);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
final int oldArchivedRow = archivedRow;
|
|
|
|
final int oldArchivedInfoRow = archivedInfoRow;
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
archivedRow = -1;
|
|
|
|
archivedInfoRow = -1;
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
if (listAdapter != null && oldArchivedRow != -1) {
|
|
|
|
listAdapter.notifyItemRangeRemoved(oldArchivedRow, oldArchivedInfoRow != -1 ? 2 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentType == MediaDataController.TYPE_IMAGE) {
|
|
|
|
masksRow = rowCount++;
|
|
|
|
stickersBotInfo = rowCount++;
|
|
|
|
} else {
|
|
|
|
masksRow = -1;
|
|
|
|
stickersBotInfo = -1;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
final int stickerSetsCount = newList.size();
|
|
|
|
if (stickerSetsCount > 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersStartRow = rowCount;
|
2020-03-30 14:00:09 +02:00
|
|
|
rowCount += stickerSetsCount;
|
|
|
|
stickersEndRow = rowCount;
|
|
|
|
|
|
|
|
if (currentType != MediaDataController.TYPE_MASK) {
|
|
|
|
stickersShadowRow = rowCount++;
|
|
|
|
masksInfoRow = -1;
|
|
|
|
} else {
|
|
|
|
masksInfoRow = rowCount++;
|
|
|
|
stickersShadowRow = -1;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
} else {
|
|
|
|
stickersStartRow = -1;
|
|
|
|
stickersEndRow = -1;
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersShadowRow = -1;
|
2020-03-30 14:00:09 +02:00
|
|
|
masksInfoRow = -1;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (listAdapter != null) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (diffResult != null) {
|
|
|
|
final int startRow = stickersStartRow >= 0 ? stickersStartRow : rowCount;
|
|
|
|
listAdapter.notifyItemRangeChanged(0, startRow);
|
|
|
|
diffResult.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
|
|
@Override
|
|
|
|
public void onInserted(int position, int count) {
|
|
|
|
listAdapter.notifyItemRangeInserted(startRow + position, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoved(int position, int count) {
|
|
|
|
listAdapter.notifyItemRangeRemoved(startRow + position, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMoved(int fromPosition, int toPosition) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChanged(int position, int count, @Nullable Object payload) {
|
|
|
|
listAdapter.notifyItemRangeChanged(startRow + position, count);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
public static final int UPDATE_LOOP_STICKERS = 0;
|
|
|
|
public static final int UPDATE_SELECTION = 1;
|
|
|
|
public static final int UPDATE_REORDERABLE = 2;
|
|
|
|
public static final int UPDATE_DIVIDER = 3;
|
|
|
|
|
|
|
|
private final LongSparseArray<Boolean> selectedItems = new LongSparseArray<>();
|
|
|
|
private final List<TLRPC.TL_messages_stickerSet> stickerSets = new ArrayList<>();
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private Context mContext;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
public ListAdapter(Context context, List<TLRPC.TL_messages_stickerSet> stickerSets) {
|
2015-12-09 19:27:52 +01:00
|
|
|
mContext = context;
|
2020-03-30 14:00:09 +02:00
|
|
|
this.stickerSets.addAll(stickerSets);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setStickerSets(List<TLRPC.TL_messages_stickerSet> stickerSets) {
|
|
|
|
this.stickerSets.clear();
|
|
|
|
this.stickerSets.addAll(stickerSets);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-09 19:27:52 +01:00
|
|
|
public int getItemCount() {
|
2015-05-21 23:27:27 +02:00
|
|
|
return rowCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
2015-12-09 19:27:52 +01:00
|
|
|
if (i >= stickersStartRow && i < stickersEndRow) {
|
2020-03-30 14:00:09 +02:00
|
|
|
return stickerSets.get(i - stickersStartRow).set.id;
|
|
|
|
} else if (i == suggestRow || i == loopInfoRow || i == archivedRow || i == archivedInfoRow || i == featuredRow || i == stickersBotInfo || i == masksRow) {
|
2015-12-09 19:27:52 +01:00
|
|
|
return Integer.MIN_VALUE;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
private void processSelectionMenu(int which) {
|
2020-06-25 17:29:04 +02:00
|
|
|
if (which == MENU_EXPORT || which == MENU_ARCHIVE || which == MENU_DELETE) {
|
2020-03-30 14:00:09 +02:00
|
|
|
final ArrayList<TLRPC.StickerSet> stickerSetList = new ArrayList<>(selectedItems.size());
|
|
|
|
|
|
|
|
for (int i = 0, size = stickerSets.size(); i < size; i++) {
|
|
|
|
final TLRPC.StickerSet stickerSet = stickerSets.get(i).set;
|
|
|
|
if (selectedItems.get(stickerSet.id, false)) {
|
|
|
|
stickerSetList.add(stickerSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:29:04 +02:00
|
|
|
if (which == MENU_EXPORT) {
|
|
|
|
|
|
|
|
AlertDialog pro = new AlertDialog(getParentActivity(), 3);
|
|
|
|
pro.setCanCacnel(false);
|
|
|
|
pro.show();
|
|
|
|
|
|
|
|
UIUtil.runOnIoDispatcher(() -> {
|
|
|
|
|
|
|
|
JsonObject exportObj = StickersUtil.exportStickers(stickerSetList);
|
|
|
|
|
|
|
|
File cacheFile = new File(ApplicationLoader.applicationContext.getCacheDir(), new Date().toLocaleString() + ".nekox-stickers.json");
|
|
|
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
|
|
|
jsonWriter.setLenient(true);
|
|
|
|
jsonWriter.setIndent(" ");
|
|
|
|
try {
|
|
|
|
Streams.write(exportObj, jsonWriter);
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FileUtil.writeUtf8String(stringWriter.toString(), cacheFile);
|
|
|
|
|
|
|
|
UIUtil.runOnUIThread(() -> {
|
|
|
|
pro.dismiss();
|
|
|
|
ShareUtil.shareFile(getParentActivity(), cacheFile);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
final int count = stickerSetList.size();
|
|
|
|
|
|
|
|
switch (count) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
for (int i = 0, size = stickerSets.size(); i < size; i++) {
|
|
|
|
final TLRPC.TL_messages_stickerSet stickerSet = stickerSets.get(i);
|
|
|
|
if (selectedItems.get(stickerSet.set.id, false)) {
|
|
|
|
processSelectionOption(which, stickerSet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listAdapter.clearSelected();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
|
|
|
|
final String buttonText;
|
|
|
|
if (which == MENU_DELETE) {
|
|
|
|
builder.setTitle(LocaleController.formatString("DeleteStickerSetsAlertTitle", R.string.DeleteStickerSetsAlertTitle, LocaleController.formatPluralString("StickerSets", count)));
|
|
|
|
builder.setMessage(LocaleController.formatString("DeleteStickersAlertMessage", R.string.DeleteStickersAlertMessage, count));
|
|
|
|
buttonText = LocaleController.getString("Delete", R.string.Delete);
|
|
|
|
} else {
|
|
|
|
builder.setTitle(LocaleController.formatString("ArchiveStickerSetsAlertTitle", R.string.ArchiveStickerSetsAlertTitle, LocaleController.formatPluralString("StickerSets", count)));
|
|
|
|
builder.setMessage(LocaleController.formatString("ArchiveStickersAlertMessage", R.string.ArchiveStickersAlertMessage, count));
|
|
|
|
buttonText = LocaleController.getString("Archive", R.string.Archive);
|
|
|
|
}
|
|
|
|
builder.setPositiveButton(buttonText, (dialog, which1) -> {
|
|
|
|
listAdapter.clearSelected();
|
|
|
|
MediaDataController.getInstance(currentAccount).toggleStickerSets(stickerSetList, currentType, which == MENU_DELETE ? 0 : 1, StickersActivity.this, true);
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
|
|
|
|
final AlertDialog dialog = builder.create();
|
|
|
|
showDialog(dialog);
|
|
|
|
if (which == MENU_DELETE) {
|
|
|
|
final TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void processSelectionOption(int which, TLRPC.TL_messages_stickerSet stickerSet) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (which == MENU_ARCHIVE) {
|
|
|
|
MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, !stickerSet.set.archived ? 1 : 2, StickersActivity.this, true, true);
|
|
|
|
} else if (which == MENU_DELETE) {
|
|
|
|
MediaDataController.getInstance(currentAccount).toggleStickerSet(getParentActivity(), stickerSet, 0, StickersActivity.this, true, true);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (which == 2) {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setType("text/plain");
|
2018-07-30 04:07:02 +02:00
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, String.format(Locale.US, "https://" + MessagesController.getInstance(currentAccount).linkPrefix + "/addstickers/%s", stickerSet.set.short_name));
|
2015-06-29 19:12:11 +02:00
|
|
|
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("StickersShare", R.string.StickersShare)), 500);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
} else if (which == 3) {
|
|
|
|
try {
|
2016-06-24 12:27:15 +02:00
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
2018-07-30 04:07:02 +02:00
|
|
|
android.content.ClipData clip = android.content.ClipData.newPlainText("label", String.format(Locale.US, "https://" + MessagesController.getInstance(currentAccount).linkPrefix + "/addstickers/%s", stickerSet.set.short_name));
|
2016-06-24 12:27:15 +02:00
|
|
|
clipboard.setPrimaryClip(clip);
|
2020-12-23 08:48:30 +01:00
|
|
|
BulletinFactory.createCopyLinkBulletin(StickersActivity.this).show();
|
2015-06-29 19:12:11 +02:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
} else if (which == 4) {
|
|
|
|
final int index = stickerSets.indexOf(stickerSet);
|
|
|
|
if (index >= 0) {
|
|
|
|
listAdapter.toggleSelected(stickersStartRow + index);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
2015-12-09 19:27:52 +01:00
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2016-10-11 13:57:01 +02:00
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0:
|
|
|
|
int row = position - stickersStartRow;
|
2020-03-30 14:00:09 +02:00
|
|
|
final StickerSetCell stickerSetCell = (StickerSetCell) holder.itemView;
|
|
|
|
stickerSetCell.setStickersSet(stickerSets.get(row), row != stickerSets.size() - 1);
|
|
|
|
stickerSetCell.setChecked(selectedItems.get(getItemId(position), false), false);
|
|
|
|
stickerSetCell.setReorderable(hasSelected(), false);
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-03-30 14:00:09 +02:00
|
|
|
final TextInfoPrivacyCell infoPrivacyCell = (TextInfoPrivacyCell) holder.itemView;
|
|
|
|
if (position == stickersBotInfo) {
|
|
|
|
infoPrivacyCell.setText(addStickersBotSpan(LocaleController.getString("StickersBotInfo", R.string.StickersBotInfo)));
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (position == archivedInfoRow) {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentType == MediaDataController.TYPE_IMAGE) {
|
2020-03-30 14:00:09 +02:00
|
|
|
infoPrivacyCell.setText(LocaleController.getString("ArchivedStickersInfo", R.string.ArchivedStickersInfo));
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
infoPrivacyCell.setText(LocaleController.getString("ArchivedMasksInfo", R.string.ArchivedMasksInfo));
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
} else if (position == loopInfoRow) {
|
|
|
|
infoPrivacyCell.setText(LocaleController.getString("LoopAnimatedStickersInfo", R.string.LoopAnimatedStickersInfo));
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (position == masksInfoRow) {
|
2020-03-30 14:00:09 +02:00
|
|
|
infoPrivacyCell.setText(LocaleController.getString("MasksInfo", R.string.MasksInfo));
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-03-30 14:00:09 +02:00
|
|
|
final TextSettingsCell settingsCell = (TextSettingsCell) holder.itemView;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (position == featuredRow) {
|
2020-03-30 14:00:09 +02:00
|
|
|
final int count = MediaDataController.getInstance(currentAccount).getFeaturedStickerSets().size();
|
|
|
|
settingsCell.setTextAndValue(LocaleController.getString("FeaturedStickers", R.string.FeaturedStickers), count > 0 ? Integer.toString(count) : "", true);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (position == archivedRow) {
|
2020-03-30 14:00:09 +02:00
|
|
|
final int count = MediaDataController.getInstance(currentAccount).getArchivedStickersCount(currentType);
|
|
|
|
final String value = count > 0 ? Integer.toString(count) : "";
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentType == MediaDataController.TYPE_IMAGE) {
|
2020-03-30 14:00:09 +02:00
|
|
|
settingsCell.setTextAndValue(LocaleController.getString("ArchivedStickers", R.string.ArchivedStickers), value, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
settingsCell.setTextAndValue(LocaleController.getString("ArchivedMasks", R.string.ArchivedMasks), value, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else if (position == masksRow) {
|
2020-03-30 14:00:09 +02:00
|
|
|
final int type = MediaDataController.TYPE_MASK;
|
|
|
|
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
|
|
|
|
final int count = mediaDataController.getStickerSets(type).size() + mediaDataController.getArchivedStickersCount(type);
|
|
|
|
settingsCell.setTextAndValue(LocaleController.getString("Masks", R.string.Masks), count > 0 ? Integer.toString(count) : "", false);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (position == suggestRow) {
|
|
|
|
String value;
|
|
|
|
switch (SharedConfig.suggestStickers) {
|
|
|
|
case 0:
|
|
|
|
value = LocaleController.getString("SuggestStickersAll", R.string.SuggestStickersAll);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
value = LocaleController.getString("SuggestStickersInstalled", R.string.SuggestStickersInstalled);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
value = LocaleController.getString("SuggestStickersNone", R.string.SuggestStickersNone);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
settingsCell.setTextAndValue(LocaleController.getString("SuggestStickers", R.string.SuggestStickers), value, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (position == stickersShadowRow) {
|
|
|
|
holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-08-22 01:53:26 +02:00
|
|
|
case 4:
|
|
|
|
if (position == loopRow) {
|
|
|
|
TextCheckCell cell = (TextCheckCell) holder.itemView;
|
|
|
|
cell.setTextAndCheck(LocaleController.getString("LoopAnimatedStickers", R.string.LoopAnimatedStickers), SharedConfig.loopStickers, true);
|
|
|
|
}
|
|
|
|
break;
|
2015-12-09 19:27:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List payloads) {
|
|
|
|
if (payloads.isEmpty()) {
|
|
|
|
onBindViewHolder(holder, position);
|
|
|
|
} else {
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0:
|
|
|
|
if (position >= stickersStartRow && position < stickersEndRow) {
|
|
|
|
final StickerSetCell stickerSetCell = (StickerSetCell) holder.itemView;
|
|
|
|
if (payloads.contains(UPDATE_SELECTION)) {
|
|
|
|
stickerSetCell.setChecked(selectedItems.get(getItemId(position), false));
|
|
|
|
}
|
|
|
|
if (payloads.contains(UPDATE_REORDERABLE)) {
|
|
|
|
stickerSetCell.setReorderable(hasSelected());
|
|
|
|
}
|
|
|
|
if (payloads.contains(UPDATE_DIVIDER)) {
|
|
|
|
stickerSetCell.setNeedDivider(position - stickersStartRow != stickerSets.size() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (payloads.contains(UPDATE_LOOP_STICKERS) && position == loopRow) {
|
|
|
|
((TextCheckCell) holder.itemView).setChecked(SharedConfig.loopStickers);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
int type = holder.getItemViewType();
|
2019-08-22 01:53:26 +02:00
|
|
|
return type == 0 || type == 2 || type == 4;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
@Override
|
2020-03-30 14:00:09 +02:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
2015-12-09 19:27:52 +01:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view = null;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
2017-12-08 18:35:59 +01:00
|
|
|
view = new StickerSetCell(mContext, 1);
|
2017-03-31 01:58:05 +02:00
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2020-03-30 14:00:09 +02:00
|
|
|
final StickerSetCell stickerSetCell = (StickerSetCell) view;
|
|
|
|
stickerSetCell.setOnReorderButtonTouchListener((v, event) -> {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
itemTouchHelper.startDrag(listView.getChildViewHolder(stickerSetCell));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
stickerSetCell.setOnOptionsClick(v -> {
|
2019-01-23 18:03:33 +01:00
|
|
|
StickerSetCell cell = (StickerSetCell) v.getParent();
|
|
|
|
final TLRPC.TL_messages_stickerSet stickerSet = cell.getStickersSet();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(stickerSet.set.title);
|
|
|
|
final int[] options;
|
2020-03-30 14:00:09 +02:00
|
|
|
final CharSequence[] items;
|
|
|
|
final int[] icons;
|
|
|
|
if (stickerSet.set.official) {
|
|
|
|
options = new int[]{MENU_ARCHIVE, 4};
|
|
|
|
items = new CharSequence[]{
|
|
|
|
LocaleController.getString("StickersHide", R.string.StickersHide),
|
|
|
|
LocaleController.getString("StickersReorder", R.string.StickersReorder)
|
|
|
|
};
|
2020-06-25 17:29:04 +02:00
|
|
|
icons = new int[]{R.drawable.baseline_archive_24, R.drawable.msg_reorder};
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
options = new int[]{MENU_ARCHIVE, 3, 4, 2, MENU_DELETE};
|
|
|
|
items = new CharSequence[]{
|
|
|
|
LocaleController.getString("StickersHide", R.string.StickersHide),
|
|
|
|
LocaleController.getString("StickersCopy", R.string.StickersCopy),
|
|
|
|
LocaleController.getString("StickersReorder", R.string.StickersReorder),
|
|
|
|
LocaleController.getString("StickersShare", R.string.StickersShare),
|
|
|
|
LocaleController.getString("StickersRemove", R.string.StickersRemove),
|
|
|
|
};
|
|
|
|
icons = new int[]{
|
2020-06-25 17:29:04 +02:00
|
|
|
R.drawable.baseline_archive_24,
|
|
|
|
R.drawable.baseline_link_24,
|
2020-03-30 14:00:09 +02:00
|
|
|
R.drawable.msg_reorder,
|
2020-06-25 17:29:04 +02:00
|
|
|
R.drawable.baseline_forward_24,
|
|
|
|
R.drawable.baseline_delete_24
|
2020-03-30 14:00:09 +02:00
|
|
|
};
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
builder.setItems(items, icons, (dialog, which) -> processSelectionOption(options[which], stickerSet));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
final AlertDialog dialog = builder.create();
|
|
|
|
showDialog(dialog);
|
|
|
|
|
|
|
|
if (options[options.length - 1] == MENU_DELETE) {
|
|
|
|
dialog.setItemColor(items.length - 1, Theme.getColor(Theme.key_dialogTextRed2), Theme.getColor(Theme.key_dialogRedIcon));
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
});
|
2015-12-09 19:27:52 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-05-21 23:27:27 +02:00
|
|
|
view = new TextInfoPrivacyCell(mContext);
|
2017-03-31 01:58:05 +02:00
|
|
|
view.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-03-31 01:58:05 +02:00
|
|
|
view = new TextSettingsCell(mContext);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
view = new ShadowSectionCell(mContext);
|
2015-12-09 19:27:52 +01:00
|
|
|
break;
|
2019-08-22 01:53:26 +02:00
|
|
|
case 4:
|
|
|
|
view = new TextCheckCell(mContext);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
break;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
if (i >= stickersStartRow && i < stickersEndRow) {
|
|
|
|
return 0;
|
2020-03-30 14:00:09 +02:00
|
|
|
} else if (i == stickersBotInfo || i == archivedInfoRow || i == loopInfoRow || i == masksInfoRow) {
|
2015-05-21 23:27:27 +02:00
|
|
|
return 1;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (i == featuredRow || i == archivedRow || i == masksRow || i == suggestRow) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return 2;
|
2020-03-30 14:00:09 +02:00
|
|
|
} else if (i == stickersShadowRow) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return 3;
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (i == loopRow) {
|
|
|
|
return 4;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
public void swapElements(int fromIndex, int toIndex) {
|
|
|
|
if (fromIndex != toIndex) {
|
|
|
|
needReorder = true;
|
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
final MediaDataController mediaDataController = MediaDataController.getInstance(currentAccount);
|
|
|
|
|
|
|
|
final int index1 = fromIndex - stickersStartRow;
|
|
|
|
final int index2 = toIndex - stickersStartRow;
|
|
|
|
|
|
|
|
swapListElements(stickerSets, index1, index2);
|
|
|
|
swapListElements(mediaDataController.getStickerSets(currentType), index1, index2);
|
|
|
|
|
2015-12-09 19:27:52 +01:00
|
|
|
notifyItemMoved(fromIndex, toIndex);
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
if (fromIndex == stickersEndRow - 1 || toIndex == stickersEndRow - 1) {
|
|
|
|
notifyItemRangeChanged(fromIndex, UPDATE_DIVIDER);
|
|
|
|
notifyItemRangeChanged(toIndex, UPDATE_DIVIDER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void swapListElements(List<TLRPC.TL_messages_stickerSet> list, int index1, int index2) {
|
|
|
|
final TLRPC.TL_messages_stickerSet set1 = list.get(index1);
|
|
|
|
list.set(index1, list.get(index2));
|
|
|
|
list.set(index2, set1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void toggleSelected(int position) {
|
|
|
|
final long id = getItemId(position);
|
|
|
|
selectedItems.put(id, !selectedItems.get(id, false));
|
|
|
|
notifyItemChanged(position, UPDATE_SELECTION);
|
|
|
|
checkActionMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearSelected() {
|
|
|
|
selectedItems.clear();
|
|
|
|
notifyStickersItemsChanged(UPDATE_SELECTION);
|
|
|
|
checkActionMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasSelected() {
|
|
|
|
return selectedItems.indexOfValue(true) != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getSelectedCount() {
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0, size = selectedItems.size(); i < size; i++) {
|
|
|
|
if (selectedItems.valueAt(i)) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkActionMode() {
|
|
|
|
final int selectedCount = listAdapter.getSelectedCount();
|
|
|
|
final boolean actionModeShowed = actionBar.isActionModeShowed();
|
|
|
|
if (selectedCount > 0) {
|
|
|
|
checkActionModeIcons();
|
|
|
|
selectedCountTextView.setNumber(selectedCount, actionModeShowed);
|
|
|
|
if (!actionModeShowed) {
|
|
|
|
actionBar.showActionMode();
|
|
|
|
notifyStickersItemsChanged(UPDATE_REORDERABLE);
|
|
|
|
if (!SharedConfig.stickersReorderingHintUsed) {
|
|
|
|
SharedConfig.setStickersReorderingHintUsed(true);
|
|
|
|
final String stickersReorderHint = LocaleController.getString("StickersReorderHint", R.string.StickersReorderHint);
|
|
|
|
Bulletin.make(parentLayout, new ReorderingBulletinLayout(mContext, stickersReorderHint), ReorderingHintDrawable.DURATION * 2 + 250).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (actionModeShowed) {
|
|
|
|
actionBar.hideActionMode();
|
|
|
|
notifyStickersItemsChanged(UPDATE_REORDERABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkActionModeIcons() {
|
|
|
|
if (hasSelected()) {
|
|
|
|
boolean canDelete = true;
|
|
|
|
for (int i = 0, size = stickerSets.size(); i < size; i++) {
|
|
|
|
if (selectedItems.get(stickerSets.get(i).set.id, false)) {
|
|
|
|
if (stickerSets.get(i).set.official) {
|
|
|
|
canDelete = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final int visibility = canDelete ? View.VISIBLE : View.GONE;
|
|
|
|
if (deleteMenuItem.getVisibility() != visibility) {
|
|
|
|
deleteMenuItem.setVisibility(visibility);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void notifyStickersItemsChanged(Object payload) {
|
|
|
|
notifyItemRangeChanged(stickersStartRow, stickersEndRow - stickersStartRow, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
private CharSequence addStickersBotSpan(String text) {
|
|
|
|
final String botName = "@stickers";
|
|
|
|
final int index = text.indexOf(botName);
|
|
|
|
if (index != -1) {
|
|
|
|
try {
|
|
|
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
|
|
|
|
URLSpanNoUnderline urlSpan = new URLSpanNoUnderline("@stickers") {
|
|
|
|
@Override
|
|
|
|
public void onClick(View widget) {
|
|
|
|
MessagesController.getInstance(currentAccount).openByUserName("stickers", StickersActivity.this, 3);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
stringBuilder.setSpan(urlSpan, index, index + botName.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
return stringBuilder;
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
@Override
|
2020-04-24 11:21:58 +02:00
|
|
|
public ArrayList<ThemeDescription> getThemeDescriptions() {
|
|
|
|
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{StickerSetCell.class, TextSettingsCell.class, TextCheckCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultIcon));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_BACKGROUND, null, null, null, null, Theme.key_actionBarActionModeDefault));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_TOPBACKGROUND, null, null, null, null, Theme.key_actionBarActionModeDefaultTop));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultSelector));
|
|
|
|
themeDescriptions.add(new ThemeDescription(selectedCountTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultIcon));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{TextInfoPrivacyCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText4));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_LINKCOLOR, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteLinkText));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{StickerSetCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{StickerSetCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_USEBACKGROUNDDRAWABLE | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, new Class[]{StickerSetCell.class}, new String[]{"optionsButton"}, null, null, null, Theme.key_stickers_menuSelector));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{StickerSetCell.class}, new String[]{"optionsButton"}, null, null, null, Theme.key_stickers_menu));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{StickerSetCell.class}, new String[]{"reorderButton"}, null, null, null, Theme.key_stickers_menu));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOX, new Class[]{StickerSetCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{StickerSetCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkboxCheck));
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
if (trendingStickersAlert != null) {
|
|
|
|
themeDescriptions.addAll(trendingStickersAlert.getThemeDescriptions());
|
|
|
|
}
|
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
return themeDescriptions;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|