Ejemplo n.º 1
0
 private void processSelectionOption(int which, TLRPC.TL_messages_stickerSet stickerSet) {
   if (which == 0) {
     StickersQuery.removeStickersSet(
         getParentActivity(), stickerSet.set, (stickerSet.set.flags & 2) == 0 ? 1 : 2);
   } else if (which == 1) {
     StickersQuery.removeStickersSet(getParentActivity(), stickerSet.set, 0);
   } else if (which == 2) {
     try {
       Intent intent = new Intent(Intent.ACTION_SEND);
       intent.setType("text/plain");
       intent.putExtra(
           Intent.EXTRA_TEXT,
           String.format(
               Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name));
       getParentActivity()
           .startActivityForResult(
               Intent.createChooser(
                   intent, LocaleController.getString("StickersShare", R.string.StickersShare)),
               500);
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   } else if (which == 3) {
     try {
       if (Build.VERSION.SDK_INT < 11) {
         android.text.ClipboardManager clipboard =
             (android.text.ClipboardManager)
                 ApplicationLoader.applicationContext.getSystemService(
                     Context.CLIPBOARD_SERVICE);
         clipboard.setText(
             String.format(
                 Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name));
       } else {
         android.content.ClipboardManager clipboard =
             (android.content.ClipboardManager)
                 ApplicationLoader.applicationContext.getSystemService(
                     Context.CLIPBOARD_SERVICE);
         android.content.ClipData clip =
             android.content.ClipData.newPlainText(
                 "label",
                 String.format(
                     Locale.US,
                     "https://telegram.me/addstickers/%s",
                     stickerSet.set.short_name));
         clipboard.setPrimaryClip(clip);
       }
       Toast.makeText(
               getParentActivity(),
               LocaleController.getString("LinkCopied", R.string.LinkCopied),
               Toast.LENGTH_SHORT)
           .show();
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   }
 }
Ejemplo n.º 2
0
 @Override
 public boolean onFragmentCreate() {
   super.onFragmentCreate();
   StickersQuery.checkStickers();
   NotificationCenter.getInstance().addObserver(this, NotificationCenter.stickersDidLoaded);
   updateRows();
   return true;
 }
Ejemplo n.º 3
0
 private void updateRows() {
   rowCount = 0;
   ArrayList<TLRPC.TL_messages_stickerSet> stickerSets = StickersQuery.getStickerSets();
   if (!stickerSets.isEmpty()) {
     stickersStartRow = 0;
     stickersEndRow = stickerSets.size();
     rowCount += stickerSets.size();
   } else {
     stickersStartRow = -1;
     stickersEndRow = -1;
   }
   stickersInfoRow = rowCount++;
   if (listAdapter != null) {
     listAdapter.notifyDataSetChanged();
   }
 }
Ejemplo n.º 4
0
 @Override
 public View getView(int i, View view, ViewGroup viewGroup) {
   int type = getItemViewType(i);
   if (type == 0) {
     if (view == null) {
       view = new StickerSetCell(mContext);
       view.setBackgroundColor(0xffffffff);
       ((StickerSetCell) view)
           .setOnOptionsClick(
               new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
                   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);
                   CharSequence[] items;
                   final int[] options;
                   if ((stickerSet.set.flags & 4) != 0) {
                     options = new int[] {0, 2, 3};
                     items =
                         new CharSequence[] {
                           (stickerSet.set.flags & 2) == 0
                               ? LocaleController.getString(
                                   "StickersHide", R.string.StickersHide)
                               : LocaleController.getString(
                                   "StickersShow", R.string.StickersShow),
                           LocaleController.getString("StickersShare", R.string.StickersShare),
                           LocaleController.getString("StickersCopy", R.string.StickersCopy),
                         };
                   } else {
                     options = new int[] {0, 1, 2, 3};
                     items =
                         new CharSequence[] {
                           (stickerSet.set.flags & 2) == 0
                               ? LocaleController.getString(
                                   "StickersHide", R.string.StickersHide)
                               : LocaleController.getString(
                                   "StickersShow", R.string.StickersShow),
                           LocaleController.getString("StickersRemove", R.string.StickersRemove),
                           LocaleController.getString("StickersShare", R.string.StickersShare),
                           LocaleController.getString("StickersCopy", R.string.StickersCopy),
                         };
                   }
                   builder.setItems(
                       items,
                       new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterface dialog, int which) {
                           processSelectionOption(options[which], stickerSet);
                         }
                       });
                   showDialog(builder.create());
                 }
               });
     }
     ArrayList<TLRPC.TL_messages_stickerSet> arrayList = StickersQuery.getStickerSets();
     ((StickerSetCell) view).setStickersSet(arrayList.get(i), i != arrayList.size() - 1);
   } else if (type == 1) {
     if (view == null) {
       view = new TextInfoPrivacyCell(mContext);
       String text = LocaleController.getString("StickersInfo", R.string.StickersInfo);
       String botName = "@stickers";
       int index = text.indexOf(botName);
       if (index != -1) {
         try {
           SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
           URLSpanNoUnderline spanNoUnderline =
               new URLSpanNoUnderline("@stickers") {
                 @Override
                 public void onClick(View widget) {
                   MessagesController.openByUserName("stickers", StickersActivity.this, 1);
                 }
               };
           stringBuilder.setSpan(
               spanNoUnderline,
               index,
               index + botName.length(),
               Spanned.SPAN_INCLUSIVE_INCLUSIVE);
           ((TextInfoPrivacyCell) view).setText(stringBuilder);
         } catch (Exception e) {
           FileLog.e("tmessages", e);
           ((TextInfoPrivacyCell) view).setText(text);
         }
       } else {
         ((TextInfoPrivacyCell) view).setText(text);
       }
       view.setBackgroundResource(R.drawable.greydivider_bottom);
     }
   }
   return view;
 }