团队冲刺第二阶段06

继续完善扩展试图、缩略试图,修改问题。

private void initListView () {
    list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    list.setItemsCanFocus(false);

    list.setOnItemLongClickListener((arg0, view, position, arg3) -> {
      if (getActionMode() != null) {
        return false;
      }
      mainActivity.startSupportActionMode(new ModeCallback());
      toggleListViewItem(view, position);
      setCabTitle();
      return true;
    });

    list.setOnItemClickListener((arg0, view, position, arg3) -> {
      if (getActionMode() == null) {
        editNote(listAdapter.getItem(position), view);
        return;
      }
     
      toggleListViewItem(view, position);
      setCabTitle();
    });

    listRoot.setOnViewTouchedListener(this);
  }

  

private void toggleListViewItem (View view, int position) {
    Note note = listAdapter.getItem(position);
    LinearLayout cardLayout = view.findViewById(R.id.card_layout);
    if (!getSelectedNotes().contains(note)) {
      getSelectedNotes().add(note);
      listAdapter.addSelectedItem(position);
      cardLayout.setBackgroundColor(getResources().getColor(R.color.list_bg_selected));
    } else {
      getSelectedNotes().remove(note);
      listAdapter.removeSelectedItem(position);
      listAdapter.restoreDrawable(note, cardLayout);
    }
    prepareActionModeMenu();

    if (getSelectedNotes().isEmpty()) {
      finishActionMode();
    }

  }

  

posted @ 2020-05-26 22:33  吃饭要排队  阅读(88)  评论(0编辑  收藏  举报