/** * Returns the View of the adapter. * * @param position Position of the element. * @param convertView The View to convert. * @param parent The parent of the view to be conveted. * @return The new View respecting the layout. */ @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(mContext); View userView = inflater.inflate(R.layout.add_user_layout, parent, false); TextView textViewUserName = (TextView) userView.findViewById(R.id.textViewUserName); ImageView imageUser = (ImageView) userView.findViewById(R.id.imageUser); CheckBox checkBox = (CheckBox) userView.findViewById(R.id.checkboxUser); User user = mUsers.get(position).getKey(); textViewUserName.setText(user.getName()); imageUser.setImageBitmap( GraphicTransforms.getCroppedCircleBitmap( user.getImage(), mContext.getResources().getInteger(R.integer.groupImageDiameter))); boolean b = mUsers.get(position).getValue(); checkBox.setChecked(b); final int pos = position; checkBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (mOriginalUsers.contains(mUsers.get(pos).getKey())) { buttonView.setChecked(true); } else { mUsers.get(pos).setValue(isChecked); // Cannot remove the first user if (mRemoveWhenUnchecked && !isChecked && pos != 0) { mUsers.remove(pos); ListAdapterUsersCheckBox.this.notifyDataSetChanged(); } // Cannot remove the first user, need to recheck the box if (mRemoveWhenUnchecked && pos == 0) { buttonView.setChecked(!isChecked); } } } }); return userView; }
/** * Method automatically called on the creation of the activity * * @param savedInstanceState the previous instance of the activity */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group_info); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Group Information"); getSupportActionBar().setDisplayShowTitleEnabled(true); Intent intent = getIntent(); if (!intent.hasExtra(SearchGroupActivity.MODE_KEY)) { throw new MissingIntentExtraException( "Mode extra is missing from intent in GroupInfoActivity"); } int indexMode = intent.getIntExtra(SearchGroupActivity.MODE_KEY, 0); if (indexMode < 0 || indexMode >= SearchGroupActivity.Mode.values().length) { throw new IllegalIntentExtraException( "Mode extra must be between 0 and " + (SearchGroupActivity.Mode.values().length - 1) + " in GroupInfoActivity"); } mMode = SearchGroupActivity.Mode.values()[indexMode]; mGroup = Objects.requireNonNull( YieldsApplication.getInfoGroup(), "The group in YieldsApplication cannot be null when GroupInfoActivity is created"); ImageView imageView = (ImageView) findViewById(R.id.imageViewGroup); int size = getResources().getInteger(R.integer.largeGroupImageDiameter); imageView.setImageBitmap(Bitmap.createScaledBitmap(mGroup.getImage(), size, size, false)); TextView textViewName = (TextView) findViewById(R.id.textViewGroupName); textViewName.setText(mGroup.getName()); List<Group.Tag> tags = mGroup.getTagList(); TextView textViewTags = (TextView) findViewById(R.id.textViewTags); if (mGroup.getType() == Group.GroupType.PRIVATE) { textViewTags.setVisibility(View.GONE); } else if (tags.isEmpty()) { textViewTags.setText(getString(R.string.noTags)); } else if (tags.size() == 1) { String text = "Tag : " + tags.get(0).getText(); textViewTags.setText(text); } else { StringBuilder builder = new StringBuilder("Tags : "); for (int i = 0; i < MAX_TAGS && i < tags.size(); i++) { if (i != 0) { builder.append(", "); } builder.append(tags.get(i).getText()); } textViewTags.setText(builder.toString()); } checkButtons(); LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayoutUsersAndNodes); for (final User user : mGroup.getUsers()) { LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); View userView = inflater.inflate(R.layout.user_layout_separator, layout, false); TextView textViewUserName = (TextView) userView.findViewById(R.id.textViewUserName); ImageView imageUser = (ImageView) userView.findViewById(R.id.imageUser); textViewUserName.setText(user.getName()); imageUser.setImageBitmap( GraphicTransforms.getCroppedCircleBitmap( user.getImage(), getApplicationContext().getResources().getInteger(R.integer.groupImageDiameter))); userView.setClickable(true); userView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { YieldsApplication.setUserSearched(user); Intent intent = new Intent(GroupInfoActivity.this, UserInfoActivity.class); startActivity(intent); } }); layout.addView(userView); } for (final Group group : mGroup.getNodes()) { LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); View groupView = inflater.inflate(R.layout.user_layout_separator, layout, false); TextView textViewUserName = (TextView) groupView.findViewById(R.id.textViewUserName); ImageView imageUser = (ImageView) groupView.findViewById(R.id.imageUser); textViewUserName.setText(group.getName()); imageUser.setImageBitmap( GraphicTransforms.getCroppedCircleBitmap( group.getImage(), getApplicationContext().getResources().getInteger(R.integer.groupImageDiameter))); groupView.setClickable(true); groupView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { YieldsApplication.setInfoGroup(group); Intent intent = new Intent(GroupInfoActivity.this, GroupInfoActivity.class); intent.putExtra(SearchGroupActivity.MODE_KEY, 0); startActivity(intent); } }); layout.addView(groupView); } }