Пример #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);
     }
   }
 }
Пример #2
0
 @Override
 public void needShowAlert(final String text) {
   if (text == null || getParentActivity() == null) {
     return;
   }
   AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
   builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
   builder.setMessage(text);
   builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
   showAlertDialog(builder);
 }
Пример #3
0
  public AddMemberCell(Context context) {
    super(context);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.addmember);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    addView(
        imageView,
        LayoutHelper.createFrame(
            48,
            48,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
            LocaleController.isRTL ? 0 : 68,
            8,
            LocaleController.isRTL ? 68 : 0,
            0));

    SimpleTextView textView = new SimpleTextView(context);
    textView.setTextColor(0xff212121);
    textView.setTextSize(17);
    textView.setText(LocaleController.getString("AddMember", R.string.AddMember));
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(
        textView,
        LayoutHelper.createFrame(
            LayoutHelper.MATCH_PARENT,
            20,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
            LocaleController.isRTL ? 28 : 129,
            22.5f,
            LocaleController.isRTL ? 129 : 28,
            0));
  }
Пример #4
0
  @Override
  public View createView(Context context, LayoutInflater inflater) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            }
          }
        });

    fragmentView = inflater.inflate(R.layout.identicon_layout, null, false);
    ImageView identiconView = (ImageView) fragmentView.findViewById(R.id.identicon_view);
    TextView textView = (TextView) fragmentView.findViewById(R.id.identicon_text);
    TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id);
    if (encryptedChat != null) {
      IdenticonDrawable drawable = new IdenticonDrawable();
      identiconView.setImageDrawable(drawable);
      drawable.setEncryptedChat(encryptedChat);
      TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id);
      textView.setText(
          AndroidUtilities.replaceTags(
              LocaleController.formatString(
                  "EncryptionKeyDescription",
                  R.string.EncryptionKeyDescription,
                  user.first_name,
                  user.first_name)));
    }

    fragmentView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    return fragmentView;
  }
Пример #5
0
 @Override
 public void needShowProgress() {
   if (getParentActivity() == null
       || getParentActivity().isFinishing()
       || progressDialog != null) {
     return;
   }
   progressDialog = new ProgressDialog(getParentActivity());
   progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
   progressDialog.setCanceledOnTouchOutside(false);
   progressDialog.setCancelable(false);
   progressDialog.show();
 }
Пример #6
0
 @Override
 public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
   if (convertView == null) {
     convertView = new SettingsSectionLayout(mContext);
     convertView.setBackgroundColor(0xffffffff);
   }
   if (searching && searchWas) {
     ((SettingsSectionLayout) convertView)
         .setText(LocaleController.getString("AllContacts", R.string.AllContacts));
   } else {
     ((SettingsSectionLayout) convertView)
         .setText(ContactsController.getInstance().sortedUsersSectionsArray.get(section));
   }
   return convertView;
 }
 private void updateSubtitle() {
   if (actionBar == null) {
     return;
   }
   if (currentChat != null || currentUser == null) {
     return;
   }
   if (currentUser.id / 1000 != 777
       && currentUser.id / 1000 != 333
       && ContactsController.getInstance().contactsDict.get(currentUser.id) == null
       && (ContactsController.getInstance().contactsDict.size() != 0
           || !ContactsController.getInstance().isLoadingContacts())) {
     if (currentUser.phone != null && currentUser.phone.length() != 0) {
       nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
     } else {
       nameTextView.setText(
           ContactsController.formatName(currentUser.first_name, currentUser.last_name));
     }
   } else {
     nameTextView.setText(
         ContactsController.formatName(currentUser.first_name, currentUser.last_name));
   }
   CharSequence printString =
       MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
   if (printString == null || printString.length() == 0) {
     lastPrintString = null;
     setTypingAnimation(false);
     TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
     if (user != null) {
       currentUser = user;
     }
     onlineTextView.setText(LocaleController.formatUserStatus(currentUser));
   } else {
     lastPrintString = printString;
     onlineTextView.setText(printString);
     setTypingAnimation(true);
   }
 }
  @Override
  public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
      if (data == null) {
        return;
      }
      Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
      String name = null;
      if (ringtone != null) {
        Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
        if (rng != null) {
          if (ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
            name = LocaleController.getString("Default", R.string.Default);
          } else {
            name = rng.getTitle(getParentActivity());
          }
          rng.stop();
        }
      }

      SharedPreferences preferences =
          ApplicationLoader.applicationContext.getSharedPreferences(
              "Notifications", Activity.MODE_PRIVATE);
      SharedPreferences.Editor editor = preferences.edit();

      if (requestCode == 12) {
        if (name != null && ringtone != null) {
          editor.putString("sound_" + dialog_id, name);
          editor.putString("sound_path_" + dialog_id, ringtone.toString());
        } else {
          editor.putString("sound_" + dialog_id, "NoSound");
          editor.putString("sound_path_" + dialog_id, "NoSound");
        }
      }
      editor.commit();
      listView.invalidateViews();
    }
  }
Пример #9
0
  public String getChangeLog() {
    String changelog = firstPart;
    String added = "% ADDED\n";
    String updated = "% UPDATED\n";
    String removed = "% REMOVED\n";

    if (notifications.isEmpty()) {
      for (TemplateSupport.TemplateNotification notification : notifications) {
        switch (notification.type) {
          case TemplateSupport.ADDEDTEMPLATE:
            added += "- QUESTION: " + notification.question + "\n";
            added += "- KEYS: " + notification.keys + "\n";
            added += "! " + notification.value + "\n";
            break;
          case TemplateSupport.UPDATEDTEMPLATE:
            updated += "- QUESTION: " + notification.question + "\n";
            updated += "- KEYS: " + notification.keys + "\n";
            updated += "! " + notification.value + "\n";
            break;
          case TemplateSupport.REMOVEDTEMPLATE:
            removed += "- QUESTION: " + notification.question + "\n";
            removed += "- KEYS: " + notification.keys + "\n";
            removed += "! " + notification.value + "\n";
            break;
        }
      }
      changelog += added + "\n";
      changelog += updated + "\n";
      changelog += removed + "\n";
    } else {
      changelog +=
          LocaleController.getString("defaultTemplatesUptodate", R.string.defaultTemplatesUptodate);
    }
    changelog += "\n" + lastPart;
    return changelog;
  }
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
      actionBarLayer.setBackOverlay(R.layout.updating_state_layout);

      actionBarLayer.setTitle(
          LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));

      actionBarLayer.setActionBarMenuOnItemClick(
          new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              }
            }
          });

      fragmentView = inflater.inflate(R.layout.settings_layout, container, false);

      listView = (ListView) fragmentView.findViewById(R.id.listView);
      listView.setAdapter(new ListAdapter(getParentActivity()));
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
              if (i == settingsVibrateRow || i == settingsNotificationsRow) {
                if (getParentActivity() == null) {
                  return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setItems(
                    new CharSequence[] {
                      LocaleController.getString("Default", R.string.Default),
                      LocaleController.getString("Enabled", R.string.Enabled),
                      LocaleController.getString("Disabled", R.string.Disabled)
                    },
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        SharedPreferences preferences =
                            ApplicationLoader.applicationContext.getSharedPreferences(
                                "Notifications", Activity.MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        if (i == settingsVibrateRow) {
                          editor.putInt("vibrate_" + dialog_id, which);
                        } else if (i == settingsNotificationsRow) {
                          editor.putInt("notify2_" + dialog_id, which);
                        }
                        editor.commit();
                        if (listView != null) {
                          listView.invalidateViews();
                        }
                        if (i == settingsNotificationsRow) {
                          updateServerNotificationsSettings();
                        }
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
              } else if (i == settingsSoundRow) {
                try {
                  Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                  tmpIntent.putExtra(
                      RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                  tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                  tmpIntent.putExtra(
                      RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                      RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                  SharedPreferences preferences =
                      ApplicationLoader.applicationContext.getSharedPreferences(
                          "Notifications", Activity.MODE_PRIVATE);
                  Uri currentSound = null;

                  String defaultPath = null;
                  Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                  if (defaultUri != null) {
                    defaultPath = defaultUri.getPath();
                  }

                  String path = preferences.getString("sound_path_" + dialog_id, defaultPath);
                  if (path != null && !path.equals("NoSound")) {
                    if (path.equals(defaultPath)) {
                      currentSound = defaultUri;
                    } else {
                      currentSound = Uri.parse(path);
                    }
                  }

                  tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                  getParentActivity().startActivityForResult(tmpIntent, 12);
                } catch (Exception e) {
                  FileLog.e("tmessages", e);
                }
              } else if (i == settingsLedRow) {
                if (getParentActivity() == null) {
                  return;
                }

                LayoutInflater li =
                    (LayoutInflater)
                        getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = li.inflate(R.layout.settings_color_dialog_layout, null, false);
                final ColorPickerView colorPickerView =
                    (ColorPickerView) view.findViewById(R.id.color_picker);

                SharedPreferences preferences =
                    ApplicationLoader.applicationContext.getSharedPreferences(
                        "Notifications", Activity.MODE_PRIVATE);
                if (preferences.contains("color_" + dialog_id)) {
                  colorPickerView.setOldCenterColor(
                      preferences.getInt("color_" + dialog_id, 0xff00ff00));
                } else {
                  if ((int) dialog_id < 0) {
                    colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
                  } else {
                    colorPickerView.setOldCenterColor(
                        preferences.getInt("MessagesLed", 0xff00ff00));
                  }
                }

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
                builder.setView(view);
                builder.setPositiveButton(
                    LocaleController.getString("Set", R.string.Set),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int which) {
                        final SharedPreferences preferences =
                            ApplicationLoader.applicationContext.getSharedPreferences(
                                "Notifications", Activity.MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putInt("color_" + dialog_id, colorPickerView.getColor());
                        editor.commit();
                        listView.invalidateViews();
                      }
                    });
                builder.setNeutralButton(
                    LocaleController.getString("Disabled", R.string.Disabled),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        final SharedPreferences preferences =
                            ApplicationLoader.applicationContext.getSharedPreferences(
                                "Notifications", Activity.MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putInt("color_" + dialog_id, 0);
                        editor.commit();
                        listView.invalidateViews();
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Default", R.string.Default),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        final SharedPreferences preferences =
                            ApplicationLoader.applicationContext.getSharedPreferences(
                                "Notifications", Activity.MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.remove("color_" + dialog_id);
                        editor.commit();
                        listView.invalidateViews();
                      }
                    });
                showAlertDialog(builder);
              }
            }
          });
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
Пример #11
0
  @Override
  public View getItemView(int section, int position, View convertView, ViewGroup parent) {

    TLRPC.User user = null;
    int count = 0;
    if (usersAsSections) {
      if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) {
        ArrayList<TLRPC.TL_contact> arr =
            ContactsController.getInstance()
                .usersSectionsDict
                .get(ContactsController.getInstance().sortedUsersSectionsArray.get(section));
        user = MessagesController.getInstance().getUser(arr.get(position).user_id);
        count = arr.size();
      }
    } else {
      if (section == 0) {
        if (position == 0) {
          if (convertView == null) {
            LayoutInflater li =
                (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = li.inflate(R.layout.contacts_invite_row_layout, parent, false);
            TextView textView = (TextView) convertView.findViewById(R.id.messages_list_row_name);
            textView.setText(LocaleController.getString("InviteFriends", R.string.InviteFriends));
          }
          View divider = convertView.findViewById(R.id.settings_row_divider);
          if (ContactsController.getInstance().contacts.isEmpty()) {
            divider.setVisibility(View.INVISIBLE);
          } else {
            divider.setVisibility(View.VISIBLE);
          }
          return convertView;
        }
        user =
            MessagesController.getInstance()
                .getUser(ContactsController.getInstance().contacts.get(position - 1).user_id);
        count = ContactsController.getInstance().contacts.size();
      }
    }
    if (user != null) {
      if (convertView == null) {
        convertView = new ChatOrUserCell(mContext);
        ((ChatOrUserCell) convertView).usePadding = false;
      }

      ((ChatOrUserCell) convertView).setData(user, null, null, null, null);

      if (ignoreUsers != null) {
        if (ignoreUsers.containsKey(user.id)) {
          ((ChatOrUserCell) convertView).drawAlpha = 0.5f;
        } else {
          ((ChatOrUserCell) convertView).drawAlpha = 1.0f;
        }
      }

      ((ChatOrUserCell) convertView).useSeparator = position != count - 1;

      return convertView;
    }

    TextView textView;
    if (convertView == null) {
      LayoutInflater li =
          (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = li.inflate(R.layout.settings_row_button_layout, parent, false);
      textView = (TextView) convertView.findViewById(R.id.settings_row_text);
    } else {
      textView = (TextView) convertView.findViewById(R.id.settings_row_text);
    }

    View divider = convertView.findViewById(R.id.settings_row_divider);
    ArrayList<ContactsController.Contact> arr =
        ContactsController.getInstance()
            .contactsSectionsDict
            .get(ContactsController.getInstance().sortedContactsSectionsArray.get(section - 1));
    ContactsController.Contact contact = arr.get(position);
    if (divider != null) {
      if (position == arr.size() - 1) {
        divider.setVisibility(View.INVISIBLE);
      } else {
        divider.setVisibility(View.VISIBLE);
      }
    }
    if (contact.first_name != null && contact.last_name != null) {
      textView.setText(contact.first_name + " " + contact.last_name);
    } else if (contact.first_name != null && contact.last_name == null) {
      textView.setText(contact.first_name);
    } else {
      textView.setText(contact.last_name);
    }
    return convertView;
  }
Пример #12
0
  @Override
  public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
      searching = false;
      searchWas = false;

      actionBar.setBackButtonImage(R.drawable.ic_ab_back);
      actionBar.setAllowOverlayTitle(true);
      if (isAlwaysShare) {
        actionBar.setTitle(
            LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
      } else if (isNeverShare) {
        actionBar.setTitle(
            LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
      } else {
        actionBar.setTitle(
            isBroadcast
                ? LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList)
                : LocaleController.getString("NewGroup", R.string.NewGroup));
        actionBar.setSubtitle(
            LocaleController.formatString(
                "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
      }

      actionBar.setActionBarMenuOnItemClick(
          new ActionBar.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              } else if (id == done_button) {
                if (selectedContacts.isEmpty()) {
                  return;
                }
                ArrayList<Integer> result = new ArrayList<>();
                result.addAll(selectedContacts.keySet());
                if (isAlwaysShare || isNeverShare) {
                  if (delegate != null) {
                    delegate.didSelectUsers(result);
                  }
                  finishFragment();
                } else {
                  Bundle args = new Bundle();
                  args.putIntegerArrayList("result", result);
                  args.putBoolean("broadcast", isBroadcast);
                  presentFragment(new GroupCreateFinalActivity(args));
                }
              }
            }
          });
      ActionBarMenu menu = actionBar.createMenu();
      menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

      searchListViewAdapter = new ContactsSearchAdapter(getParentActivity(), null, false);
      searchListViewAdapter.setCheckedMap(selectedContacts);
      searchListViewAdapter.setUseUserCell(true);
      listViewAdapter = new ContactsAdapter(getParentActivity(), true, false, null);
      listViewAdapter.setCheckedMap(selectedContacts);

      fragmentView = new LinearLayout(getParentActivity());
      LinearLayout linearLayout = (LinearLayout) fragmentView;
      linearLayout.setOrientation(LinearLayout.VERTICAL);

      FrameLayout frameLayout = new FrameLayout(getParentActivity());
      linearLayout.addView(frameLayout);
      LinearLayout.LayoutParams layoutParams =
          (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
      layoutParams.gravity = Gravity.TOP;
      frameLayout.setLayoutParams(layoutParams);

      userSelectEditText = new EditText(getParentActivity());
      userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      userSelectEditText.setHintTextColor(0xff979797);
      userSelectEditText.setTextColor(0xff212121);
      userSelectEditText.setInputType(
          InputType.TYPE_TEXT_VARIATION_FILTER
              | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
              | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
      userSelectEditText.setMinimumHeight(AndroidUtilities.dp(54));
      userSelectEditText.setSingleLine(false);
      userSelectEditText.setLines(2);
      userSelectEditText.setMaxLines(2);
      userSelectEditText.setVerticalScrollBarEnabled(true);
      userSelectEditText.setHorizontalScrollBarEnabled(false);
      userSelectEditText.setPadding(0, 0, 0, 0);
      userSelectEditText.setImeOptions(
          EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
      userSelectEditText.setGravity(
          (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
      AndroidUtilities.clearCursorDrawable(userSelectEditText);
      frameLayout.addView(userSelectEditText);
      FrameLayout.LayoutParams layoutParams1 =
          (FrameLayout.LayoutParams) userSelectEditText.getLayoutParams();
      layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
      layoutParams1.leftMargin = AndroidUtilities.dp(10);
      layoutParams1.rightMargin = AndroidUtilities.dp(10);
      layoutParams1.gravity = Gravity.TOP;
      userSelectEditText.setLayoutParams(layoutParams1);

      if (isAlwaysShare) {
        userSelectEditText.setHint(
            LocaleController.getString(
                "AlwaysShareWithPlaceholder", R.string.AlwaysShareWithPlaceholder));
      } else if (isNeverShare) {
        userSelectEditText.setHint(
            LocaleController.getString(
                "NeverShareWithPlaceholder", R.string.NeverShareWithPlaceholder));
      } else {
        userSelectEditText.setHint(
            LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
      }
      if (Build.VERSION.SDK_INT >= 11) {
        userSelectEditText.setTextIsSelectable(false);
      }
      userSelectEditText.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(
                CharSequence charSequence, int start, int count, int after) {
              if (!ignoreChange) {
                beforeChangeIndex = userSelectEditText.getSelectionStart();
                changeString = new SpannableString(charSequence);
              }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (!ignoreChange) {
                boolean search = false;
                int afterChangeIndex = userSelectEditText.getSelectionEnd();
                if (editable.toString().length() < changeString.toString().length()) {
                  String deletedString = "";
                  try {
                    deletedString =
                        changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
                  } catch (Exception e) {
                    FileLog.e("tmessages", e);
                  }
                  if (deletedString.length() > 0) {
                    if (searching && searchWas) {
                      search = true;
                    }
                    Spannable span = userSelectEditText.getText();
                    for (int a = 0; a < allSpans.size(); a++) {
                      XImageSpan sp = allSpans.get(a);
                      if (span.getSpanStart(sp) == -1) {
                        allSpans.remove(sp);
                        selectedContacts.remove(sp.uid);
                      }
                    }
                    if (!isAlwaysShare && !isNeverShare) {
                      actionBar.setSubtitle(
                          LocaleController.formatString(
                              "MembersCount",
                              R.string.MembersCount,
                              selectedContacts.size(),
                              maxCount));
                    }
                    listView.invalidateViews();
                  } else {
                    search = true;
                  }
                } else {
                  search = true;
                }
                if (search) {
                  String text = userSelectEditText.getText().toString().replace("<", "");
                  if (text.length() != 0) {
                    searching = true;
                    searchWas = true;
                    if (listView != null) {
                      listView.setAdapter(searchListViewAdapter);
                      searchListViewAdapter.notifyDataSetChanged();
                      if (android.os.Build.VERSION.SDK_INT >= 11) {
                        listView.setFastScrollAlwaysVisible(false);
                      }
                      listView.setFastScrollEnabled(false);
                      listView.setVerticalScrollBarEnabled(true);
                    }
                    if (emptyTextView != null) {
                      emptyTextView.setText(
                          LocaleController.getString("NoResult", R.string.NoResult));
                    }
                    searchListViewAdapter.searchDialogs(text);
                  } else {
                    searchListViewAdapter.searchDialogs(null);
                    searching = false;
                    searchWas = false;
                    listView.setAdapter(listViewAdapter);
                    listViewAdapter.notifyDataSetChanged();
                    if (android.os.Build.VERSION.SDK_INT >= 11) {
                      listView.setFastScrollAlwaysVisible(true);
                    }
                    listView.setFastScrollEnabled(true);
                    listView.setVerticalScrollBarEnabled(false);
                    emptyTextView.setText(
                        LocaleController.getString("NoContacts", R.string.NoContacts));
                  }
                }
              }
            }
          });

      LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
      emptyTextLayout.setVisibility(View.INVISIBLE);
      emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
      linearLayout.addView(emptyTextLayout);
      layoutParams = (LinearLayout.LayoutParams) emptyTextLayout.getLayoutParams();
      layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
      emptyTextLayout.setLayoutParams(layoutParams);
      emptyTextLayout.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return true;
            }
          });

      emptyTextView = new TextView(getParentActivity());
      emptyTextView.setTextColor(0xff808080);
      emptyTextView.setTextSize(20);
      emptyTextView.setGravity(Gravity.CENTER);
      emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
      emptyTextLayout.addView(emptyTextView);
      layoutParams = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.weight = 0.5f;
      emptyTextView.setLayoutParams(layoutParams);

      FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
      emptyTextLayout.addView(frameLayout2);
      layoutParams = (LinearLayout.LayoutParams) frameLayout2.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.weight = 0.5f;
      frameLayout2.setLayoutParams(layoutParams);

      listView = new LetterSectionsListView(getParentActivity());
      listView.setEmptyView(emptyTextLayout);
      listView.setVerticalScrollBarEnabled(false);
      listView.setDivider(null);
      listView.setDividerHeight(0);
      listView.setFastScrollEnabled(true);
      listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
      listView.setAdapter(listViewAdapter);
      if (Build.VERSION.SDK_INT >= 11) {
        listView.setFastScrollAlwaysVisible(true);
        listView.setVerticalScrollbarPosition(
            LocaleController.isRTL
                ? ListView.SCROLLBAR_POSITION_LEFT
                : ListView.SCROLLBAR_POSITION_RIGHT);
      }
      linearLayout.addView(listView);
      layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      listView.setLayoutParams(layoutParams);
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              TLRPC.User user = null;
              if (searching && searchWas) {
                user = searchListViewAdapter.getItem(i);
              } else {
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (row < 0 || section < 0) {
                  return;
                }
                user = (TLRPC.User) listViewAdapter.getItem(section, row);
              }
              if (user == null) {
                return;
              }

              boolean check = true;
              if (selectedContacts.containsKey(user.id)) {
                check = false;
                try {
                  XImageSpan span = selectedContacts.get(user.id);
                  selectedContacts.remove(user.id);
                  SpannableStringBuilder text =
                      new SpannableStringBuilder(userSelectEditText.getText());
                  text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                  allSpans.remove(span);
                  ignoreChange = true;
                  userSelectEditText.setText(text);
                  userSelectEditText.setSelection(text.length());
                  ignoreChange = false;
                } catch (Exception e) {
                  FileLog.e("tmessages", e);
                }
              } else {
                if (selectedContacts.size() == maxCount) {
                  return;
                }
                ignoreChange = true;
                XImageSpan span = createAndPutChipForUser(user);
                span.uid = user.id;
                ignoreChange = false;
              }
              if (!isAlwaysShare && !isNeverShare) {
                actionBar.setSubtitle(
                    LocaleController.formatString(
                        "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
              }
              if (searching || searchWas) {
                ignoreChange = true;
                SpannableStringBuilder ssb = new SpannableStringBuilder("");
                for (ImageSpan sp : allSpans) {
                  ssb.append("<<");
                  ssb.setSpan(
                      sp,
                      ssb.length() - 2,
                      ssb.length(),
                      SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                userSelectEditText.setText(ssb);
                userSelectEditText.setSelection(ssb.length());
                ignoreChange = false;

                searchListViewAdapter.searchDialogs(null);
                searching = false;
                searchWas = false;
                listView.setAdapter(listViewAdapter);
                listViewAdapter.notifyDataSetChanged();
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                  listView.setFastScrollAlwaysVisible(true);
                }
                listView.setFastScrollEnabled(true);
                listView.setVerticalScrollBarEnabled(false);
                emptyTextView.setText(
                    LocaleController.getString("NoContacts", R.string.NoContacts));
              } else {
                if (view instanceof UserCell) {
                  ((UserCell) view).setChecked(check, true);
                }
              }
            }
          });
      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(userSelectEditText);
              }
              if (listViewAdapter != null) {
                listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {
              if (absListView.isFastScrollEnabled()) {
                AndroidUtilities.clearDrawableAnimation(absListView);
              }
            }
          });
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      int type = getItemViewType(i);
      if (type == 0) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_leftright_row_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail);

        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == settingsVibrateRow) {
          textView.setText(LocaleController.getString("Vibrate", R.string.Vibrate));
          divider.setVisibility(View.VISIBLE);
          SharedPreferences preferences =
              mContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
          int value = preferences.getInt("vibrate_" + dialog_id, 0);
          if (value == 0) {
            detailTextView.setText(LocaleController.getString("Default", R.string.Default));
          } else if (value == 1) {
            detailTextView.setText(LocaleController.getString("Enabled", R.string.Enabled));
          } else if (value == 2) {
            detailTextView.setText(LocaleController.getString("Disabled", R.string.Disabled));
          }
        } else if (i == settingsNotificationsRow) {
          textView.setText(LocaleController.getString("Notifications", R.string.Notifications));
          divider.setVisibility(View.VISIBLE);
          SharedPreferences preferences =
              mContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
          int value = preferences.getInt("notify2_" + dialog_id, 0);
          if (value == 0) {
            detailTextView.setText(LocaleController.getString("Default", R.string.Default));
          } else if (value == 1) {
            detailTextView.setText(LocaleController.getString("Enabled", R.string.Enabled));
          } else if (value == 2) {
            detailTextView.setText(LocaleController.getString("Disabled", R.string.Disabled));
          }
        }
      }
      if (type == 1) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.settings_row_detail_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail);

        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == settingsSoundRow) {
          SharedPreferences preferences =
              mContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
          String name =
              preferences.getString(
                  "sound_" + dialog_id, LocaleController.getString("Default", R.string.Default));
          if (name.equals("NoSound")) {
            detailTextView.setText(LocaleController.getString("NoSound", R.string.NoSound));
          } else {
            detailTextView.setText(name);
          }
          textView.setText(LocaleController.getString("Sound", R.string.Sound));
          divider.setVisibility(View.INVISIBLE);
        }
      } else if (type == 2) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.settings_row_color_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        View colorView = view.findViewById(R.id.settings_color);
        View divider = view.findViewById(R.id.settings_row_divider);
        textView.setText(LocaleController.getString("LedColor", R.string.LedColor));
        SharedPreferences preferences =
            ApplicationLoader.applicationContext.getSharedPreferences(
                "Notifications", Activity.MODE_PRIVATE);

        if (preferences.contains("color_" + dialog_id)) {
          colorView.setBackgroundColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
        } else {
          if ((int) dialog_id < 0) {
            colorView.setBackgroundColor(preferences.getInt("GroupLed", 0xff00ff00));
          } else {
            colorView.setBackgroundColor(preferences.getInt("MessagesLed", 0xff00ff00));
          }
        }
        divider.setVisibility(View.VISIBLE);
      }
      return view;
    }
Пример #14
0
  @SuppressWarnings("unchecked")
  @Override
  public View createView(Context context) {
    actionBar.setBackgroundColor(0xff333333);
    actionBar.setItemsBackground(R.drawable.bar_selector_picker);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    if (selectedAlbum != null) {
      actionBar.setTitle(selectedAlbum.bucketName);
    } else if (type == 0) {
      actionBar.setTitle(
          LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
    } else if (type == 1) {
      actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
    }
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              if (Build.VERSION.SDK_INT < 11) {
                listView.setAdapter(null);
                listView = null;
                listAdapter = null;
              }
              finishFragment();
            }
          }
        });

    if (selectedAlbum == null) {
      ActionBarMenu menu = actionBar.createMenu();
      searchItem =
          menu.addItem(0, R.drawable.ic_ab_search)
              .setIsSearchField(true)
              .setActionBarMenuItemSearchListener(
                  new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {}

                    @Override
                    public boolean canCollapseSearch() {
                      finishFragment();
                      return false;
                    }

                    @Override
                    public void onTextChanged(EditText editText) {
                      if (editText.getText().length() == 0) {
                        searchResult.clear();
                        searchResultKeys.clear();
                        lastSearchString = null;
                        nextSearchBingString = null;
                        giphySearchEndReached = true;
                        searching = false;
                        requestQueue.cancelAll("search");
                        if (type == 0) {
                          emptyView.setText(
                              LocaleController.getString(
                                  "NoRecentPhotos", R.string.NoRecentPhotos));
                        } else if (type == 1) {
                          emptyView.setText(
                              LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
                        }
                        updateSearchInterface();
                      }
                    }

                    @Override
                    public void onSearchPressed(EditText editText) {
                      if (editText.getText().toString().length() == 0) {
                        return;
                      }
                      searchResult.clear();
                      searchResultKeys.clear();
                      nextSearchBingString = null;
                      giphySearchEndReached = true;
                      if (type == 0) {
                        searchBingImages(editText.getText().toString(), 0, 53);
                      } else if (type == 1) {
                        searchGiphyImages(editText.getText().toString(), 0, 53);
                      }
                      lastSearchString = editText.getText().toString();
                      if (lastSearchString.length() == 0) {
                        lastSearchString = null;
                        if (type == 0) {
                          emptyView.setText(
                              LocaleController.getString(
                                  "NoRecentPhotos", R.string.NoRecentPhotos));
                        } else if (type == 1) {
                          emptyView.setText(
                              LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
                        }
                      } else {
                        emptyView.setText(
                            LocaleController.getString("NoResult", R.string.NoResult));
                      }
                      updateSearchInterface();
                    }
                  });
    }

    if (selectedAlbum == null) {
      if (type == 0) {
        searchItem
            .getSearchField()
            .setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
      } else if (type == 1) {
        searchItem
            .getSearchField()
            .setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
      }
    }

    fragmentView = new FrameLayout(context);

    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(0xff000000);

    listView = new GridView(context);
    listView.setPadding(
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4));
    listView.setClipToPadding(false);
    listView.setDrawSelectorOnTop(true);
    listView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setNumColumns(GridView.AUTO_FIT);
    listView.setVerticalSpacing(AndroidUtilities.dp(4));
    listView.setHorizontalSpacing(AndroidUtilities.dp(4));
    listView.setSelector(R.drawable.list_selector);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (selectedAlbum != null && selectedAlbum.isVideo) {
              if (i < 0 || i >= selectedAlbum.photos.size()) {
                return;
              }
              if (delegate.didSelectVideo(selectedAlbum.photos.get(i).path)) {
                finishFragment();
              }
            } else {
              ArrayList<Object> arrayList;
              if (selectedAlbum != null) {
                arrayList = (ArrayList) selectedAlbum.photos;
              } else {
                if (searchResult.isEmpty() && lastSearchString == null) {
                  arrayList = (ArrayList) recentImages;
                } else {
                  arrayList = (ArrayList) searchResult;
                }
              }
              if (i < 0 || i >= arrayList.size()) {
                return;
              }
              PhotoViewer.getInstance().setParentActivity(getParentActivity());
              PhotoViewer.getInstance()
                  .openPhotoForSelect(
                      arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this, chatActivity);
            }
          }
        });

    if (selectedAlbum == null) {
      listView.setOnItemLongClickListener(
          new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(
                AdapterView<?> parent, View view, int position, long id) {
              if (searchResult.isEmpty() && lastSearchString == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
                builder.setPositiveButton(
                    LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                        recentImages.clear();
                        if (listAdapter != null) {
                          listAdapter.notifyDataSetChanged();
                        }
                        MessagesStorage.getInstance().clearWebRecent(type);
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
                return true;
              }
              return false;
            }
          });
    }

    emptyView = new TextView(context);
    emptyView.setTextColor(0xff808080);
    emptyView.setTextSize(20);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    if (selectedAlbum != null) {
      emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
    } else {
      if (type == 0) {
        emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
      } else if (type == 1) {
        emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
      }
    }
    frameLayout.addView(emptyView);
    layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
    emptyView.setLayoutParams(layoutParams);
    emptyView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    if (selectedAlbum == null) {
      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {
              if (visibleItemCount != 0
                  && firstVisibleItem + visibleItemCount > totalItemCount - 2
                  && !searching) {
                if (type == 0 && nextSearchBingString != null) {
                  searchBingImages(lastSearchString, searchResult.size(), 54);
                } else if (type == 1 && !giphySearchEndReached) {
                  searchGiphyImages(
                      searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
                }
              }
            }
          });

      progressView = new FrameLayout(context);
      progressView.setVisibility(View.GONE);
      frameLayout.addView(progressView);
      layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
      layoutParams.width = LayoutHelper.MATCH_PARENT;
      layoutParams.height = LayoutHelper.MATCH_PARENT;
      layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
      progressView.setLayoutParams(layoutParams);

      ProgressBar progressBar = new ProgressBar(context);
      progressView.addView(progressBar);
      layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
      layoutParams.width = LayoutHelper.WRAP_CONTENT;
      layoutParams.height = LayoutHelper.WRAP_CONTENT;
      layoutParams.gravity = Gravity.CENTER;
      progressBar.setLayoutParams(layoutParams);

      updateSearchInterface();
    }

    pickerBottomLayout = new PickerBottomLayout(context);
    frameLayout.addView(pickerBottomLayout);
    layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    layoutParams.gravity = Gravity.BOTTOM;
    pickerBottomLayout.setLayoutParams(layoutParams);
    pickerBottomLayout.cancelButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            delegate.actionButtonPressed(true);
            finishFragment();
          }
        });
    pickerBottomLayout.doneButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            sendSelectedPhotos();
          }
        });
    if (singlePhoto) {
      pickerBottomLayout.setVisibility(View.GONE);
    }

    listView.setEmptyView(emptyView);
    pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);

    return fragmentView;
  }
Пример #15
0
  @Override
  public View getItemView(int section, int position, View convertView, ViewGroup parent) {
    int type = getItemViewType(section, position);
    if (type == 4) {
      if (convertView == null) {
        convertView = new DividerCell(mContext);
        convertView.setPadding(
            AndroidUtilities.dp(LocaleController.isRTL ? 28 : 72),
            0,
            AndroidUtilities.dp(LocaleController.isRTL ? 72 : 28),
            0);
      }
    } else if (type == 3) {
      if (convertView == null) {
        convertView = new GreySectionCell(mContext);
        ((GreySectionCell) convertView)
            .setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase());
      }
    } else if (type == 2) {
      if (convertView == null) {
        convertView = new TextCell(mContext);
      }
      TextCell actionCell = (TextCell) convertView;
      if (needPhonebook) {
        actionCell.setTextAndIcon(
            LocaleController.getString("InviteFriends", R.string.InviteFriends),
            R.drawable.menu_invite);
      } else if (isAdmin) {
        actionCell.setTextAndIcon(
            LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink),
            R.drawable.menu_invite);
      } else {
        if (position == 0) {
          actionCell.setTextAndIcon(
              LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup);
        } else if (position == 1) {
          actionCell.setTextAndIcon(
              LocaleController.getString("NewSecretChat", R.string.NewSecretChat),
              R.drawable.menu_secret);
        } else if (position == 2) {
          actionCell.setTextAndIcon(
              LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList),
              R.drawable.menu_broadcast);
        }
      }
    } else if (type == 1) {
      if (convertView == null) {
        convertView = new TextCell(mContext);
      }
      ContactsController.Contact contact =
          ContactsController.getInstance().phoneBookContacts.get(position);
      if (contact.first_name != null && contact.last_name != null) {
        if (isContainUTF8(contact.display_name)) {
          ((TextCell) convertView).setText(contact.display_name);
        } else {
          ((TextCell) convertView).setText(contact.first_name + " " + contact.last_name);
        }
      } else if (contact.first_name != null && contact.last_name == null) {
        ((TextCell) convertView).setText(contact.first_name);
      } else {
        ((TextCell) convertView).setText(contact.last_name);
      }
    } else if (type == 0) {
      if (convertView == null) {
        convertView = new UserCell(mContext, 58);
        ((UserCell) convertView).setStatusColors(0xffa8a8a8, 0xff3b84c0);
      }

      ArrayList<TLRPC.TL_contact> arr =
          ContactsController.getInstance()
              .usersSectionsDict
              .get(
                  ContactsController.getInstance()
                      .sortedUsersSectionsArray
                      .get(section - (onlyUsers && !isAdmin ? 0 : 1)));
      TLRPC.User user = MessagesController.getInstance().getUser(arr.get(position).user_id);
      if (isContainUTF8(user.first_name) || isContainUTF8(user.last_name)) {
        ((UserCell) convertView).setData(user, user.last_name + user.first_name, null, 0);
      } else {
        ((UserCell) convertView).setData(user, null, null, 0);
      }

      if (checkedMap != null) {
        ((UserCell) convertView)
            .setChecked(checkedMap.containsKey(user.id), !scrolling && Build.VERSION.SDK_INT > 10);
      }
      if (ignoreUsers != null) {
        if (ignoreUsers.containsKey(user.id)) {
          ViewProxy.setAlpha(convertView, 0.5f);
        } else {
          ViewProxy.setAlpha(convertView, 1.0f);
        }
      }
    }
    return convertView;
  }
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setCustomView(R.layout.settings_do_action_layout);
      Button cancelButton = (Button) actionBarLayer.findViewById(R.id.cancel_button);
      cancelButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              finishFragment();
            }
          });
      doneButton = actionBarLayer.findViewById(R.id.done_button);
      doneButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              boolean done;
              TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
              if (wallPaper != null
                  && wallPaper.id != 1000001
                  && wallPaper instanceof TLRPC.TL_wallPaper) {
                int width = AndroidUtilities.displaySize.x;
                int height = AndroidUtilities.displaySize.y;
                if (width > height) {
                  int temp = width;
                  width = height;
                  height = temp;
                }
                TLRPC.PhotoSize size =
                    FileLoader.getClosestPhotoSizeWithSize(
                        wallPaper.sizes, Math.min(width, height));
                String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
                File f =
                    new File(
                        FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE),
                        fileName);
                File toFile =
                    new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
                try {
                  done = Utilities.copyFile(f, toFile);
                } catch (Exception e) {
                  done = false;
                  FileLog.e("tmessages", e);
                }
              } else {
                if (selectedBackground == -1) {
                  File fromFile =
                      new File(
                          ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
                  File toFile =
                      new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
                  done = fromFile.renameTo(toFile);
                } else {
                  done = true;
                }
              }

              if (done) {
                SharedPreferences preferences =
                    ApplicationLoader.applicationContext.getSharedPreferences(
                        "mainconfig", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putInt("selectedBackground", selectedBackground);
                editor.putInt("selectedColor", selectedColor);
                editor.commit();
                ApplicationLoader.cachedWallpaper = null;
              }
              finishFragment();
            }
          });

      cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
      TextView textView = (TextView) doneButton.findViewById(R.id.done_button_text);
      textView.setText(LocaleController.getString("Set", R.string.Set).toUpperCase());

      fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
      listAdapter = new ListAdapter(getParentActivity());

      progressBar = (ProgressBar) fragmentView.findViewById(R.id.action_progress);
      backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image);
      listView = (HorizontalListView) fragmentView.findViewById(R.id.listView);
      listView.setAdapter(listAdapter);
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              if (i == 0) {
                if (getParentActivity() == null) {
                  return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items =
                    new CharSequence[] {
                      LocaleController.getString("FromCamera", R.string.FromCamera),
                      LocaleController.getString("FromGalley", R.string.FromGalley),
                      LocaleController.getString("Cancel", R.string.Cancel)
                    };

                builder.setItems(
                    items,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                        try {
                          if (i == 0) {
                            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File image = Utilities.generatePicturePath();
                            if (image != null) {
                              takePictureIntent.putExtra(
                                  MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                              currentPicturePath = image.getAbsolutePath();
                            }
                            startActivityForResult(takePictureIntent, 10);
                          } else if (i == 1) {
                            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                            photoPickerIntent.setType("image/*");
                            startActivityForResult(photoPickerIntent, 11);
                          }
                        } catch (Exception e) {
                          FileLog.e("tmessages", e);
                        }
                      }
                    });
                showAlertDialog(builder);
              } else {
                TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
                selectedBackground = wallPaper.id;
                listAdapter.notifyDataSetChanged();
                processSelectedBackground();
              }
            }
          });

      processSelectedBackground();
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
Пример #17
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;
 }
Пример #18
0
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setDisplayUseLogoEnabled(true, R.drawable.ic_ab_logo);
      actionBarLayer.setTitle(LocaleController.getString("AppName", R.string.AppName));

      actionBarLayer.setActionBarMenuOnItemClick(
          new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == done_button) {
                onNextAction();
              }
            }
          });

      ActionBarMenu menu = actionBarLayer.createMenu();
      View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout);
      TextView doneTextView = (TextView) doneItem.findViewById(R.id.done_button);
      doneTextView.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());

      fragmentView = inflater.inflate(R.layout.login_layout, container, false);

      views[0] = (SlideView) fragmentView.findViewById(R.id.login_page1);
      views[1] = (SlideView) fragmentView.findViewById(R.id.login_page2);
      views[2] = (SlideView) fragmentView.findViewById(R.id.login_page3);

      try {
        if (views[0] == null || views[1] == null || views[2] == null) {
          FrameLayout parent = (FrameLayout) ((ScrollView) fragmentView).getChildAt(0);
          for (int a = 0; a < views.length; a++) {
            if (views[a] == null) {
              views[a] = (SlideView) parent.getChildAt(a);
            }
          }
        }
      } catch (Exception e) {
        FileLog.e("tmessages", e);
      }

      actionBarLayer.setTitle(views[0].getHeaderName());

      Bundle savedInstanceState = loadCurrentState();
      if (savedInstanceState != null) {
        currentViewNum = savedInstanceState.getInt("currentViewNum", 0);
      }
      for (int a = 0; a < views.length; a++) {
        SlideView v = views[a];
        if (v != null) {
          if (savedInstanceState != null) {
            v.restoreStateParams(savedInstanceState);
          }
          v.delegate = this;
          v.setVisibility(currentViewNum == a ? View.VISIBLE : View.GONE);
        }
      }
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
Пример #19
0
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
      actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
      if (isBroadcast) {
        actionBarLayer.setTitle(
            LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
      } else {
        actionBarLayer.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
      }
      actionBarLayer.setSubtitle(
          LocaleController.formatString(
              "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));

      actionBarLayer.setActionBarMenuOnItemClick(
          new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              } else if (id == done_button) {
                if (!selectedContacts.isEmpty()) {
                  ArrayList<Integer> result = new ArrayList<Integer>();
                  result.addAll(selectedContacts.keySet());
                  Bundle args = new Bundle();
                  args.putIntegerArrayList("result", result);
                  args.putBoolean("broadcast", isBroadcast);
                  presentFragment(new GroupCreateFinalActivity(args));
                }
              }
            }
          });

      ActionBarMenu menu = actionBarLayer.createMenu();
      View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout);
      TextView doneTextView = (TextView) doneItem.findViewById(R.id.done_button);
      doneTextView.setText(LocaleController.getString("Next", R.string.Next));

      searching = false;
      searchWas = false;

      fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

      emptyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
      emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
      emptyTextView.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return true;
            }
          });
      userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
      userSelectEditText.setHint(
          LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
      if (Build.VERSION.SDK_INT >= 11) {
        userSelectEditText.setTextIsSelectable(false);
      }
      userSelectEditText.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(
                CharSequence charSequence, int start, int count, int after) {
              if (!ignoreChange) {
                beforeChangeIndex = userSelectEditText.getSelectionStart();
                changeString = new SpannableString(charSequence);
              }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (!ignoreChange) {
                boolean search = false;
                int afterChangeIndex = userSelectEditText.getSelectionEnd();
                if (editable.toString().length() < changeString.toString().length()) {
                  String deletedString = "";
                  try {
                    deletedString =
                        changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
                  } catch (Exception e) {
                    FileLog.e("tmessages", e);
                  }
                  if (deletedString.length() > 0) {
                    if (searching && searchWas) {
                      search = true;
                    }
                    Spannable span = userSelectEditText.getText();
                    for (int a = 0; a < allSpans.size(); a++) {
                      XImageSpan sp = allSpans.get(a);
                      if (span.getSpanStart(sp) == -1) {
                        allSpans.remove(sp);
                        selectedContacts.remove(sp.uid);
                      }
                    }
                    actionBarLayer.setSubtitle(
                        LocaleController.formatString(
                            "MembersCount",
                            R.string.MembersCount,
                            selectedContacts.size(),
                            maxCount));
                    listView.invalidateViews();
                  } else {
                    search = true;
                  }
                } else {
                  search = true;
                }
                if (search) {
                  String text = userSelectEditText.getText().toString().replace("<", "");
                  if (text.length() != 0) {
                    searchDialogs(text);
                    searching = true;
                    searchWas = true;
                    emptyTextView.setText(
                        LocaleController.getString("NoResult", R.string.NoResult));
                    listViewAdapter.notifyDataSetChanged();
                  } else {
                    searchResult = null;
                    searchResultNames = null;
                    searching = false;
                    searchWas = false;
                    emptyTextView.setText(
                        LocaleController.getString("NoContacts", R.string.NoContacts));
                    listViewAdapter.notifyDataSetChanged();
                  }
                }
              }
            }
          });

      listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
      listView.setEmptyView(emptyTextView);
      listView.setVerticalScrollBarEnabled(false);

      listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              TLRPC.User user;
              int section = listViewAdapter.getSectionForPosition(i);
              int row = listViewAdapter.getPositionInSectionForPosition(i);
              if (searching && searchWas) {
                user = searchResult.get(row);
              } else {
                ArrayList<TLRPC.TL_contact> arr =
                    ContactsController.getInstance()
                        .usersSectionsDict
                        .get(
                            ContactsController.getInstance().sortedUsersSectionsArray.get(section));
                user = MessagesController.getInstance().getUser(arr.get(row).user_id);
                listView.invalidateViews();
              }
              if (selectedContacts.containsKey(user.id)) {
                XImageSpan span = selectedContacts.get(user.id);
                selectedContacts.remove(user.id);
                SpannableStringBuilder text =
                    new SpannableStringBuilder(userSelectEditText.getText());
                text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                allSpans.remove(span);
                ignoreChange = true;
                userSelectEditText.setText(text);
                userSelectEditText.setSelection(text.length());
                ignoreChange = false;
              } else {
                if (selectedContacts.size() == maxCount) {
                  return;
                }
                ignoreChange = true;
                XImageSpan span = createAndPutChipForUser(user);
                span.uid = user.id;
                ignoreChange = false;
              }
              actionBarLayer.setSubtitle(
                  LocaleController.formatString(
                      "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
              if (searching || searchWas) {
                searching = false;
                searchWas = false;
                emptyTextView.setText(
                    LocaleController.getString("NoContacts", R.string.NoContacts));

                ignoreChange = true;
                SpannableStringBuilder ssb = new SpannableStringBuilder("");
                for (ImageSpan sp : allSpans) {
                  ssb.append("<<");
                  ssb.setSpan(
                      sp,
                      ssb.length() - 2,
                      ssb.length(),
                      SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                userSelectEditText.setText(ssb);
                userSelectEditText.setSelection(ssb.length());
                ignoreChange = false;

                listViewAdapter.notifyDataSetChanged();
              } else {
                listView.invalidateViews();
              }
            }
          });

      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(userSelectEditText);
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {}
          });
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
Пример #20
0
    @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
      TLRPC.User user;
      int size;

      if (searchWas && searching) {
        user = MessagesController.getInstance().getUser(searchResult.get(position).id);
        size = searchResult.size();
      } else {
        ArrayList<TLRPC.TL_contact> arr =
            ContactsController.getInstance()
                .usersSectionsDict
                .get(ContactsController.getInstance().sortedUsersSectionsArray.get(section));
        user = MessagesController.getInstance().getUser(arr.get(position).user_id);
        size = arr.size();
      }

      if (convertView == null) {
        LayoutInflater li =
            (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = li.inflate(R.layout.group_create_row_layout, parent, false);
      }
      ContactListRowHolder holder = (ContactListRowHolder) convertView.getTag();
      if (holder == null) {
        holder = new ContactListRowHolder(convertView);
        convertView.setTag(holder);
      }

      ImageView checkButton = (ImageView) convertView.findViewById(R.id.settings_row_check_button);
      if (selectedContacts.containsKey(user.id)) {
        checkButton.setImageResource(R.drawable.btn_check_on_holo_light);
      } else {
        checkButton.setImageResource(R.drawable.btn_check_off_holo_light);
      }

      View divider = convertView.findViewById(R.id.settings_row_divider);
      if (position == size - 1) {
        divider.setVisibility(View.INVISIBLE);
      } else {
        divider.setVisibility(View.VISIBLE);
      }

      if (searchWas && searching) {
        holder.nameTextView.setText(searchResultNames.get(position));
      } else {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        if (name.length() == 0) {
          if (user.phone != null && user.phone.length() != 0) {
            name = PhoneFormat.getInstance().format("+" + user.phone);
          } else {
            name = LocaleController.getString("HiddenName", R.string.HiddenName);
          }
        }
        holder.nameTextView.setText(name);
      }

      TLRPC.FileLocation photo = null;
      if (user.photo != null) {
        photo = user.photo.photo_small;
      }
      int placeHolderId = AndroidUtilities.getUserAvatarForId(user.id);
      holder.avatarImage.setImage(photo, "50_50", placeHolderId);

      holder.messageTextView.setText(LocaleController.formatUserStatus(user));
      if (user.status != null
          && user.status.expires > ConnectionsManager.getInstance().getCurrentTime()) {
        holder.messageTextView.setTextColor(0xff357aa8);
      } else {
        holder.messageTextView.setTextColor(0xff808080);
      }

      return convertView;
    }
Пример #21
0
  @Override
  public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("Stickers", R.string.Stickers));
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            }
          }
        });

    listAdapter = new ListAdapter(context);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(0xfff0f0f0);

    ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDrawSelectorOnTop(true);
    frameLayout.addView(
        listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i >= stickersStartRow && i < stickersEndRow && getParentActivity() != null) {
              final TLRPC.TL_messages_stickerSet stickerSet = StickersQuery.getStickerSets().get(i);
              ArrayList<TLRPC.Document> stickers = stickerSet.documents;
              if (stickers == null || stickers.isEmpty()) {
                return;
              }
              StickersAlert alert = new StickersAlert(getParentActivity(), stickerSet);
              alert.setButton(
                  AlertDialog.BUTTON_NEGATIVE,
                  LocaleController.getString("Close", R.string.Close),
                  (Message) null);
              if ((stickerSet.set.flags & 4) == 0) {
                alert.setButton(
                    AlertDialog.BUTTON_NEUTRAL,
                    LocaleController.getString("StickersRemove", R.string.StickersRemove),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        StickersQuery.removeStickersSet(getParentActivity(), stickerSet.set, 0);
                      }
                    });
              }
              setVisibleDialog(alert);
              alert.show();
            }
          }
        });

    return fragmentView;
  }
Пример #22
0
  @Override
  public View createView(Context context, LayoutInflater inflater) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            } else if (id == done_button) {
              if (firstNameField.getText().length() != 0) {
                saveName();
                finishFragment();
              }
            }
          }
        });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
    if (user == null) {
      user = UserConfig.getCurrentUser();
    }

    fragmentView = new LinearLayout(context);
    fragmentView.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    ((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
    fragmentView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    firstNameField = new EditText(context);
    firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    firstNameField.setHintTextColor(0xff979797);
    firstNameField.setTextColor(0xff212121);
    firstNameField.setMaxLines(1);
    firstNameField.setLines(1);
    firstNameField.setSingleLine(true);
    firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    firstNameField.setInputType(
        InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
    AndroidUtilities.clearCursorDrawable(firstNameField);
    ((LinearLayout) fragmentView).addView(firstNameField);
    LinearLayout.LayoutParams layoutParams =
        (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(24);
    layoutParams.height = AndroidUtilities.dp(36);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
    firstNameField.setLayoutParams(layoutParams);
    firstNameField.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_NEXT) {
              lastNameField.requestFocus();
              lastNameField.setSelection(lastNameField.length());
              return true;
            }
            return false;
          }
        });

    lastNameField = new EditText(context);
    lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    lastNameField.setHintTextColor(0xff979797);
    lastNameField.setTextColor(0xff212121);
    lastNameField.setMaxLines(1);
    lastNameField.setLines(1);
    lastNameField.setSingleLine(true);
    lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    lastNameField.setInputType(
        InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
    AndroidUtilities.clearCursorDrawable(lastNameField);
    ((LinearLayout) fragmentView).addView(lastNameField);
    layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(16);
    layoutParams.height = AndroidUtilities.dp(36);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
    lastNameField.setLayoutParams(layoutParams);
    lastNameField.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
              doneButton.performClick();
              return true;
            }
            return false;
          }
        });

    if (user != null) {
      firstNameField.setText(user.first_name);
      firstNameField.setSelection(firstNameField.length());
      lastNameField.setText(user.last_name);
    }

    return fragmentView;
  }