示例#1
0
 public static void selectTimeline(
     FragmentActivity activity,
     ActivityRequestCode requestCode,
     Timeline timeline,
     MyAccount currentMyAccount) {
   SelectorDialog selector = new TimelineSelector();
   selector.setRequestCode(requestCode);
   selector.getArguments().putLong(IntentExtra.TIMELINE_ID.key, timeline.getId());
   selector
       .getArguments()
       .putString(IntentExtra.ACCOUNT_NAME.key, currentMyAccount.getAccountName());
   selector.show(activity);
 }
示例#2
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setTitle(R.string.dialog_title_select_timeline);
    Timeline timeline =
        myContext
            .persistentTimelines()
            .fromId(getArguments().getLong(IntentExtra.TIMELINE_ID.key, 0));
    MyAccount currentMyAccount =
        myContext
            .persistentAccounts()
            .fromAccountName(getArguments().getString(IntentExtra.ACCOUNT_NAME.key));

    List<Timeline> timelines =
        myContext
            .persistentTimelines()
            .getFiltered(
                true,
                TriState.fromBoolean(timeline.isCombined()),
                currentMyAccount,
                timeline.getOrigin());
    if (timelines.isEmpty()) {
      returnSelectedTimeline(Timeline.getEmpty(null));
      return;
    } else if (timelines.size() == 1) {
      returnSelectedTimeline(timelines.get(0));
      return;
    }

    final List<TimelineListViewItem> items = new ArrayList<>();
    for (Timeline timeline2 : timelines) {
      TimelineListViewItem viewItem = new TimelineListViewItem(myContext, timeline2);
      items.add(viewItem);
    }
    Collections.sort(
        items, new TimelineListViewItemComparator(R.id.displayedInSelector, true, false));
    removeDuplicates(items);

    setListAdapter(newListAdapter(items));

    getListView()
        .setOnItemClickListener(
            new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                long timelineId =
                    Long.parseLong(((TextView) view.findViewById(R.id.id)).getText().toString());
                returnSelectedTimeline(myContext.persistentTimelines().fromId(timelineId));
              }
            });
  }