Esempio n. 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;
  }
Esempio n. 2
0
  public void registerAll(Context context) {
    super.registerAll(context);

    manualSearch = social.canSearchUsers();

    NicedPreferences.NiceDisplayTextPreference dp;
    NicedPreferences.NiceSearchPreference sp;
    NicedPreferences.NiceListPreference lp;

    categoryPref = new NicedPreferences.NiceInfoPreference(context);
    categoryPref.setTitle(R.string.pref_social_account);
    categoryPref.setSummary(accountSummary);
    categoryPref.setEnabled(enabled);

    preferences.add(categoryPref);

    userPref = new NicedPreferences.NiceDisplayTextPreference(context);
    userPref.setTitle(R.string.pref_social_user);
    userPref.setEnabled(enabled);

    preferences.add(userPref);

    expirationPref = new NicedPreferences.NiceDisplayTextPreference(context);
    expirationPref.setTitle(R.string.pref_social_validuntil);
    expirationPref.setEnabled(enabled);

    preferences.add(expirationPref);

    loginPref = new NicedPreferences.NiceDisplayTextPreference(context);

    loginPref.setTitle(
        social.isLoggedIn() ? R.string.pref_social_logout : R.string.pref_social_login);

    loginPref.setText(
        Simple.getTrans(
            social.isLoggedIn()
                ? R.string.pref_social_isloggedin
                : R.string.pref_social_isloggedout));

    loginPref.setEnabled(enabled);

    loginPref.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            if (social.isLoggedIn()) {
              social.logout();
            } else {
              social.login();
            }

            return false;
          }
        });

    preferences.add(loginPref);

    Simple.removeSharedPref("social." + social.getPlatform() + ".mode");

    lp = new NicedPreferences.NiceListPreference(context);
    lp.setKey("social." + social.getPlatform() + ".owner.mode");
    lp.setTitle("Anzeige");
    lp.setEntryValues(R.array.pref_social_newfriends_keys);
    lp.setEntries(R.array.pref_social_newfriends_vals);
    lp.setDefaultValue("feed+folder");
    lp.setEnabled(enabled);

    preferences.add(lp);

    if (GlobalConfigs.BetaFlag) {
      apicallsPref = new NicedPreferences.NiceDisplayTextPreference(context);
      apicallsPref.setTitle("API Calls");
      apicallsPref.setEnabled(enabled);

      preferences.add(apicallsPref);

      dp = new NicedPreferences.NiceDisplayTextPreference(context);
      dp.setTitle("Etwas testen");
      dp.setEnabled(enabled);

      dp.setOnPreferenceClickListener(
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              social.getTest();

              return false;
            }
          });

      preferences.add(dp);
    }

    //
    // Define preference order.
    //

    int order = 1;

    for (Preference pref : preferences) {
      pref.setOrder(order++);
    }

    //
    // Preset all current friends and likes preferences.
    //

    social.reconfigureFriendsAndLikes();

    registerFriends(context, true);
    registerLikes(context, true);

    //
    // Manual search.
    //

    if (manualSearch) {
      sp = new NicedPreferences.NiceSearchPreference(context);

      sp.setTitle("Suchen");
      sp.setOrder(1000000);

      sp.setSearchCallback(
          new NicedPreferences.NiceSearchPreference.SearchCallback() {
            @Override
            public void onSearchCancel(String prefkey) {}

            @Override
            public void onSearchRequest(String prefkey, String query) {
              performSearch(query);
            }
          });

      preferences.add(sp);
    }

    monitorPrefs.run();
  }
Esempio n. 3
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);
    }
  }