|
|
@@ -1,46 +1,28 @@
|
|
|
|
package ru.vtosters.lite.ui.fragments.tgstickers;
|
|
|
|
package ru.vtosters.lite.ui.fragments.tgstickers;
|
|
|
|
|
|
|
|
|
|
|
|
import static android.widget.Toast.LENGTH_SHORT;
|
|
|
|
|
|
|
|
import static android.widget.Toast.makeText;
|
|
|
|
|
|
|
|
import static ru.vtosters.lite.tgs.TGPref.setTGBotKey;
|
|
|
|
|
|
|
|
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
|
|
|
|
|
|
|
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
|
|
|
|
|
|
|
import static ru.vtosters.lite.utils.ThemesUtils.getAccentColor;
|
|
|
|
|
|
|
|
import static ru.vtosters.lite.utils.ThemesUtils.getSTextAttr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.res.ColorStateList;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.*;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
|
|
|
|
|
|
|
|
|
|
|
import com.aefyr.tsg.g2.TelegramStickersService;
|
|
|
|
import com.aefyr.tsg.g2.TelegramStickersService;
|
|
|
|
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersGrabber;
|
|
|
|
import com.aefyr.tsg.g2.stickersgrabber.TelegramStickersGrabber;
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
import com.vk.core.dialogs.alert.VkAlertDialog;
|
|
|
|
import com.vk.core.dialogs.alert.VkAlertDialog;
|
|
|
|
import com.vk.navigation.Navigator;
|
|
|
|
import com.vk.navigation.Navigator;
|
|
|
|
import com.vtosters.lite.R;
|
|
|
|
import com.vtosters.lite.R;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ru.vtosters.lite.tgs.TGPref;
|
|
|
|
import ru.vtosters.lite.tgs.TGPref;
|
|
|
|
import ru.vtosters.lite.ui.adapters.StickerPackAdapter;
|
|
|
|
import ru.vtosters.lite.ui.adapters.StickerPackAdapter;
|
|
|
|
import ru.vtosters.lite.ui.components.StickerTouchHelperCallback;
|
|
|
|
import ru.vtosters.lite.ui.components.StickerTouchHelperCallback;
|
|
|
@@ -48,6 +30,8 @@ import ru.vtosters.lite.ui.fragments.BaseToolbarFragment;
|
|
|
|
import ru.vtosters.lite.utils.AndroidUtils;
|
|
|
|
import ru.vtosters.lite.utils.AndroidUtils;
|
|
|
|
import ru.vtosters.lite.utils.ThemesUtils;
|
|
|
|
import ru.vtosters.lite.utils.ThemesUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
|
|
public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
public final static String ACTION_RELOAD = "com.vtosters.lite.action.RELOAD_TGS_LIST";
|
|
|
|
public final static String ACTION_RELOAD = "com.vtosters.lite.action.RELOAD_TGS_LIST";
|
|
|
|
|
|
|
|
|
|
|
@@ -84,7 +68,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreateMenu(Menu menu) {
|
|
|
|
protected void onCreateMenu(Menu menu) {
|
|
|
|
var item = menu.add(0, 0, 0, "");
|
|
|
|
var item = menu.add(0, 0, 0, "");
|
|
|
|
item.setIcon(R.drawable.ic_settings_24)
|
|
|
|
item.setIcon(ThemesUtils.recolorDrawable(AndroidUtils.getGlobalContext().getDrawable(R.drawable.ic_settings_24)))
|
|
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
|
|
|
|
|
|
|
|
|
|
super.onCreateMenu(menu);
|
|
|
|
super.onCreateMenu(menu);
|
|
|
@@ -98,7 +82,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
|
|
|
|
|
|
|
|
private void openMenu(String toast) {
|
|
|
|
private void openMenu(String toast) {
|
|
|
|
if (toast != null) {
|
|
|
|
if (toast != null) {
|
|
|
|
makeText(getContext(), toast, LENGTH_SHORT).show();
|
|
|
|
Toast.makeText(getContext(), toast, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var intent = new Navigator(StickersPreferencesFragment.class, new Bundle()).b(getContext());
|
|
|
|
var intent = new Navigator(StickersPreferencesFragment.class, new Bundle()).b(getContext());
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
@@ -138,7 +122,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2, -2);
|
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2, -2);
|
|
|
|
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
|
|
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
|
|
params.setMargins(0, 0, 0, dp2px(12f));
|
|
|
|
params.setMargins(0, 0, 0, AndroidUtils.dp2px(12f));
|
|
|
|
layout.addView(mAddStickerPack, params);
|
|
|
|
layout.addView(mAddStickerPack, params);
|
|
|
|
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
return layout;
|
|
|
@@ -173,13 +157,13 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
LinearLayout linearLayout = new LinearLayout(getContext());
|
|
|
|
LinearLayout linearLayout = new LinearLayout(getContext());
|
|
|
|
|
|
|
|
|
|
|
|
final EditText editText = new EditText(getContext());
|
|
|
|
final EditText editText = new EditText(getContext());
|
|
|
|
editText.setHintTextColor(getSTextAttr());
|
|
|
|
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
|
|
|
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
|
|
|
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
|
|
|
|
|
|
|
|
|
|
|
linearLayout.addView(editText);
|
|
|
|
linearLayout.addView(editText);
|
|
|
|
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
|
|
|
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
|
|
|
margin.setMargins(dp2px(24f), 0, dp2px(24f), 0);
|
|
|
|
margin.setMargins(AndroidUtils.dp2px(24f), 0, AndroidUtils.dp2px(24f), 0);
|
|
|
|
editText.setLayoutParams(margin);
|
|
|
|
editText.setLayoutParams(margin);
|
|
|
|
|
|
|
|
|
|
|
|
new VkAlertDialog.Builder(getContext())
|
|
|
|
new VkAlertDialog.Builder(getContext())
|
|
|
@@ -191,7 +175,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
if (!pack.startsWith("https://")) {
|
|
|
|
if (!pack.startsWith("https://")) {
|
|
|
|
pack = "https://" + pack;
|
|
|
|
pack = "https://" + pack;
|
|
|
|
} else if (!pack.contains("addstickers")) {
|
|
|
|
} else if (!pack.contains("addstickers")) {
|
|
|
|
sendToast(AndroidUtils.getString("invalid_pack_link"));
|
|
|
|
AndroidUtils.sendToast(AndroidUtils.getString("invalid_pack_link"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pack = parsePack(pack);
|
|
|
|
pack = parsePack(pack);
|
|
|
|
mService.requestPackDownload(pack, new File(getContext().getFilesDir(), new File("VT-Stickers", pack).getAbsolutePath()));
|
|
|
|
mService.requestPackDownload(pack, new File(getContext().getFilesDir(), new File("VT-Stickers", pack).getAbsolutePath()));
|
|
|
@@ -231,13 +215,13 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
LinearLayout linearLayout = new LinearLayout(getContext());
|
|
|
|
LinearLayout linearLayout = new LinearLayout(getContext());
|
|
|
|
|
|
|
|
|
|
|
|
final EditText editText = new EditText(getContext());
|
|
|
|
final EditText editText = new EditText(getContext());
|
|
|
|
editText.setHintTextColor(getSTextAttr());
|
|
|
|
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
|
|
|
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
|
|
|
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
|
|
|
|
|
|
|
|
|
|
|
linearLayout.addView(editText);
|
|
|
|
linearLayout.addView(editText);
|
|
|
|
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
|
|
|
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
|
|
|
margin.setMargins(dp2px(24f), 0, dp2px(24f), 0);
|
|
|
|
margin.setMargins(AndroidUtils.dp2px(24f), 0, AndroidUtils.dp2px(24f), 0);
|
|
|
|
editText.setLayoutParams(margin);
|
|
|
|
editText.setLayoutParams(margin);
|
|
|
|
|
|
|
|
|
|
|
|
new VkAlertDialog.Builder(getContext())
|
|
|
|
new VkAlertDialog.Builder(getContext())
|
|
|
@@ -245,7 +229,7 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
.setMessage(requireContext().getString(R.string.stickersapi6))
|
|
|
|
.setMessage(requireContext().getString(R.string.stickersapi6))
|
|
|
|
.setView(linearLayout)
|
|
|
|
.setView(linearLayout)
|
|
|
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
|
|
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
|
|
|
setTGBotKey(editText.getText().toString());
|
|
|
|
TGPref.setTGBotKey(editText.getText().toString());
|
|
|
|
if (r != null) r.run();
|
|
|
|
if (r != null) r.run();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel,
|
|
|
|
.setNegativeButton(android.R.string.cancel,
|
|
|
@@ -277,8 +261,8 @@ public class StickersFragment extends BaseToolbarFragment {
|
|
|
|
public void onKeyChecked(boolean ok) {
|
|
|
|
public void onKeyChecked(boolean ok) {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
progressDialog.dismiss();
|
|
|
|
if (!ok) {
|
|
|
|
if (!ok) {
|
|
|
|
makeText(context, requireContext().getString(R.string.stickersapi2), LENGTH_SHORT).show();
|
|
|
|
Toast.makeText(context, requireContext().getString(R.string.stickersapi2), Toast.LENGTH_SHORT).show();
|
|
|
|
setTGBotKey(null);
|
|
|
|
TGPref.setTGBotKey(null);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mService.setBotKey(TGPref.getTGBotKey());
|
|
|
|
mService.setBotKey(TGPref.getTGBotKey());
|
|
|
|