Пример #1
0
  private void performSearch(String query) {
    ArrayList<Preference> nextEntries = null;

    JSONArray users = social.getSearchUsers(query, 20);

    if (users != null) {
      nextEntries = new ArrayList<>();

      NicedPreferences.NiceListPreference lp;

      for (int inx = 0; inx < users.length(); inx++) {
        JSONObject user = Json.getObject(users, inx);

        String pfid = Json.getString(user, "pfid");
        String name = Json.getString(user, "name");
        String icon = Json.getString(user, "icon");
        String type = Json.getString(user, "type");

        if ((pfid == null) || (name == null) || (icon == null) || (type == null)) continue;
        if (name.isEmpty()) continue;

        lp = new NicedPreferences.NiceListPreference(Simple.getActContext());

        String veryfied = Json.getBoolean(user, "very") ? " (" + "verified" + ")" : "";

        lp.setTitle(name + veryfied);
        lp.setIcon(SimpleRequest.readDrawable(icon));
        lp.setOrder(1000001 + inx);
        lp.setSlug(user);
        lp.setOnPreferenceChangeListener(searchResultClick);

        if (Simple.equals(type, "like")) {
          lp.setEntryValues(R.array.pref_social_newlikes_keys);
          lp.setEntries(R.array.pref_social_newlikes_vals);
        } else {
          lp.setEntryValues(R.array.pref_social_newfriends_keys);
          lp.setEntries(R.array.pref_social_newfriends_vals);
        }

        lp.setValue("inactive");

        getPreferenceScreen().addPreference(lp);
        nextEntries.add(lp);
      }
    }

    if (lastEntries != null) {
      for (Preference nukeme : lastEntries) {
        getPreferenceScreen().removePreference(nukeme);
      }
    }

    lastEntries = nextEntries;
  }
Пример #2
0
  public void registerLikes(Context context, boolean initial) {
    if (!social.hasLikes()) return;

    NicedPreferences.NiceInfoPreference ip;
    NicedPreferences.NiceListPreference lp;

    if (initial) {
      ip = new NicedPreferences.NiceInfoPreference(context);
      ip.setTitle(R.string.pref_social_likes);
      ip.setSummary(likesSummary);
      ip.setEnabled(enabled);
      ip.setOrder(20000);

      preferences.add(ip);

      lp = new NicedPreferences.NiceListPreference(context);

      lp.setKey(keyprefix + ".newlikes.default");
      lp.setTitle(R.string.pref_social_autolikes);
      lp.setEntryValues(R.array.pref_social_newlikes_keys);
      lp.setEntries(R.array.pref_social_newlikes_vals);
      lp.setDefaultValue("folder");
      lp.setEnabled(enabled);
      lp.setOrder(20001);

      preferences.add(lp);
    }

    String likesname = keyprefix + ".like.name.";
    String likesmode = keyprefix + ".like.mode.";

    Map<String, Object> likespref = Simple.getAllPreferences(likesname);

    for (Map.Entry<String, ?> entry : likespref.entrySet()) {
      Object fnobj = entry.getValue();

      if (!(fnobj instanceof String)) continue;

      String fpfid = entry.getKey().substring(likesname.length());
      String fname = (String) fnobj;

      if (knownpfids.contains(fpfid)) continue;
      knownpfids.add(fpfid);

      lp = new NicedPreferences.NiceListPreference(context);
      lp.setKey(likesmode + fpfid);
      lp.setTitle(fname);
      lp.setIcon(social.getProfileDrawable(fpfid, true));
      lp.setEntryValues(R.array.pref_social_newlikes_keys);
      lp.setEntries(R.array.pref_social_newlikes_vals);
      lp.setEnabled(enabled);

      final NicedPreferences.NiceListPreference lpfinal = lp;

      lp.setOnLongClick(
          new Runnable() {
            @Override
            public void run() {
              onLongClick(lpfinal);
            }
          });

      //
      // Updated items get first.
      //

      lp.setOrder(29999 - preferences.size());

      preferences.add(lp);

      if (!initial) getPreferenceScreen().addPreference(lp);
    }
  }