private void updateVisibleRows(int mask) {
   if (listView == null) {
     return;
   }
   int count = listView.getChildCount();
   for (int a = 0; a < count; a++) {
     View child = listView.getChildAt(a);
     if (child instanceof ChatOrUserCell) {
       ((ChatOrUserCell) child).update(mask);
     }
   }
 }
Ejemplo n.º 2
0
 @Override
 public void didReceivedNotification(int id, Object... args) {
   if (id == NotificationCenter.contactsDidLoaded) {
     if (listViewAdapter != null) {
       listViewAdapter.notifyDataSetChanged();
     }
   } else if (id == NotificationCenter.updateInterfaces) {
     int mask = (Integer) args[0];
     if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0
         || (mask & MessagesController.UPDATE_MASK_NAME) != 0
         || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
       if (listView != null) {
         listView.invalidateViews();
       }
     }
   } else if (id == NotificationCenter.chatDidCreated) {
     AndroidUtilities.RunOnUIThread(
         new Runnable() {
           @Override
           public void run() {
             removeSelfFromStack();
           }
         });
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
      fragmentView = inflater.inflate(R.layout.group_create_final_layout, container, false);

      final ImageButton button2 =
          (ImageButton) fragmentView.findViewById(R.id.settings_change_avatar_button);
      button2.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {

              AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);

              CharSequence[] items;

              if (avatar != null) {
                items =
                    new CharSequence[] {
                      LocaleController.getString("FromCamera", R.string.FromCamera),
                      LocaleController.getString("FromGalley", R.string.FromGalley),
                      LocaleController.getString("DeletePhoto", R.string.DeletePhoto)
                    };
              } else {
                items =
                    new CharSequence[] {
                      LocaleController.getString("FromCamera", R.string.FromCamera),
                      LocaleController.getString("FromGalley", R.string.FromGalley)
                    };
              }

              builder.setItems(
                  items,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                      if (i == 0) {
                        avatarUpdater.openCamera();
                      } else if (i == 1) {
                        avatarUpdater.openGallery();
                      } else if (i == 2) {
                        avatar = null;
                        uploadedAvatar = null;
                        avatarImage.setImage(avatar, "50_50", R.drawable.group_blue);
                      }
                    }
                  });
              builder.show().setCanceledOnTouchOutside(true);
            }
          });

      avatarImage = (BackupImageView) fragmentView.findViewById(R.id.settings_avatar_image);

      nameTextView = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
      nameTextView.setHint(
          LocaleController.getString(
              "EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder));
      if (nameToSet != null) {
        nameTextView.setText(nameToSet);
        nameToSet = null;
      }
      listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
      listView.setAdapter(new ListAdapter(parentActivity));
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
Ejemplo n.º 4
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;
  }