Esempio n. 1
0
  public void doShortcut() {

    setContentView(R.layout.activity_setup_widget);
    setupAppBar(R.id.toolbar, "New shortcut", true, true);
    header = getLayoutInflater().inflate(R.layout.shortcut_header, null);
    ListView list = (ListView) findViewById(R.id.subs);

    list.addHeaderView(header);

    final ArrayList<String> sorted = UserSubscriptions.getSubscriptionsForShortcut(Shortcut.this);
    final SubChooseAdapter adapter =
        new SubChooseAdapter(this, sorted, UserSubscriptions.getAllSubreddits(this));
    list.setAdapter(adapter);

    (header.findViewById(R.id.sort)).clearFocus();
    ((EditText) header.findViewById(R.id.sort))
        .addTextChangedListener(
            new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

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

              @Override
              public void afterTextChanged(Editable editable) {
                final String result = editable.toString();
                adapter.getFilter().filter(result);
              }
            });
  }
Esempio n. 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    overrideRedditSwipeAnywhere();

    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_createmulti);
    setupAppBar(R.id.toolbar, "", true, true);

    findViewById(R.id.add)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                showSelectDialog();
              }
            });
    title = (EditText) findViewById(R.id.name);

    subs = new ArrayList<>();
    if (getIntent().hasExtra(EXTRA_MULTI)) {
      String multi = getIntent().getExtras().getString(EXTRA_MULTI);
      old = multi;
      title.setText(multi.replace("%20", " "));
      for (MultiReddit multiReddit : UserSubscriptions.getMultireddits()) {
        if (multiReddit.getDisplayName().equals(multi)) {
          for (MultiSubreddit sub : multiReddit.getSubreddits()) {
            subs.add(sub.getDisplayName().toLowerCase());
          }
        }
      }
    }
    recyclerView = (RecyclerView) findViewById(R.id.subslist);

    findViewById(R.id.delete).setVisibility(View.GONE); // todo make this work
    findViewById(R.id.ok)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (title.getText().toString().isEmpty()) {
                  new AlertDialogWrapper.Builder(CreateMulti.this)
                      .setTitle(R.string.multireddit_title_empty)
                      .setMessage(R.string.multireddit_title_empty_msg)
                      .setPositiveButton(
                          R.string.btn_ok,
                          new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                              title.requestFocus();
                            }
                          })
                      .show();
                } else if (subs.size() == 0) {
                  new AlertDialogWrapper.Builder(CreateMulti.this)
                      .setTitle(R.string.multireddit_no_subs)
                      .setMessage(R.string.multireddit_no_subs_msg)
                      .setPositiveButton(
                          R.string.btn_ok,
                          new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                            }
                          })
                      .show();
                } else {
                  new SaveMulti().execute();
                }
              }
            });
    adapter = new CustomAdapter(subs);
    //  adapter.setHasStableIds(true);

    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
  }
Esempio n. 3
0
 public MultiredditPosts(String multireddit) {
   posts = new ArrayList<>();
   this.multiReddit = UserSubscriptions.getMultiredditByDisplayName(multireddit);
 }
Esempio n. 4
0
  public void showSelectDialog() {
    ArrayList<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(this));
    sorted.addAll(subs);
    final List<String> s2 = new ArrayList<>(subs);
    all = new String[sorted.size()];
    boolean[] checked = new boolean[all.length];

    int i = 0;
    for (String s : sorted) {
      if (!(s.equals("all") || !s.equals("frontpage")) || !s.contains("+")) {
        all[i] = s;
        if (s2.contains(s)) {
          checked[i] = true;
        }
        i++;
      }
    }

    List<String> list = new ArrayList<>();

    for (String s : all) {
      if (s != null && s.length() > 0) {
        list.add(s);
      }
    }

    all = list.toArray(new String[list.size()]);

    final ArrayList<String> toCheck = new ArrayList<>();

    toCheck.addAll(subs);
    new AlertDialogWrapper.Builder(this)
        .setMultiChoiceItems(
            all,
            checked,
            new DialogInterface.OnMultiChoiceClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if (!isChecked) {
                  toCheck.remove(all[which]);
                } else {
                  toCheck.add(all[which]);
                }
                Log.v(LogUtil.getTag(), "Done with " + all[which]);
              }
            })
        .setTitle(R.string.multireddit_selector)
        .setPositiveButton(
            getString(R.string.btn_add).toUpperCase(),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                subs = toCheck;
                Log.v(LogUtil.getTag(), subs.size() + "SIZE ");
                adapter = new CustomAdapter(subs);
                recyclerView.setAdapter(adapter);
              }
            })
        .setNegativeButton(
            R.string.reorder_add_subreddit,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                new MaterialDialog.Builder(CreateMulti.this)
                    .title(R.string.reorder_add_subreddit)
                    .inputRangeRes(2, 21, R.color.md_red_500)
                    .alwaysCallInputCallback()
                    .input(
                        getString(R.string.reorder_subreddit_name),
                        null,
                        false,
                        new MaterialDialog.InputCallback() {
                          @Override
                          public void onInput(MaterialDialog dialog, CharSequence raw) {
                            input =
                                raw.toString()
                                    .replaceAll("\\s", ""); // remove whitespace from input
                          }
                        })
                    .positiveText(R.string.btn_add)
                    .onPositive(
                        new MaterialDialog.SingleButtonCallback() {
                          @Override
                          public void onClick(MaterialDialog dialog, DialogAction which) {
                            new AsyncGetSubreddit().execute(input);
                          }
                        })
                    .negativeText(R.string.btn_cancel)
                    .onNegative(
                        new MaterialDialog.SingleButtonCallback() {
                          @Override
                          public void onClick(MaterialDialog dialog, DialogAction which) {}
                        })
                    .show();
              }
            })
        .show();
  }