Android Open Source - GroupGoal Config Helper






From Project

Back to project page GroupGoal.

License

The source code is released under:

GNU General Public License

If you think the Android project GroupGoal listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cs121.groupgoal;
/*from w  ww  . j  av  a2 s.  com*/
import com.parse.ConfigCallback;
import com.parse.ParseConfig;
import com.parse.ParseException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ConfigHelper {
  private ParseConfig config;
  private long configLastFetchedTime;

  public void fetchConfigIfNeeded() {
    final long configRefreshInterval = 60 * 60; // 1 hour

    if (config == null ||
        System.currentTimeMillis() - configLastFetchedTime > configRefreshInterval) {
      // Set the config to current, just to load the cache
      config = ParseConfig.getCurrentConfig();

      // Set the current time, to flag that the operation started and prevent double fetch
      ParseConfig.getInBackground(new ConfigCallback() {
        @Override
        public void done(ParseConfig parseConfig, ParseException e) {
          if (e == null) {
            // Retrieved successfully
            config = parseConfig;
            configLastFetchedTime = System.currentTimeMillis();
          } else {
            // Fetch failed, reset the time
            configLastFetchedTime = 0;
          }
        }
      });
    }
  }

  public List<Float> getSearchDistanceAvailableOptions() {
    final List<Float> defaultOptions = Arrays.asList(250.0f, 1000.0f, 2000.0f, 5000.0f);

    List<Number> options = config.getList("availableFilterDistances");
    if (options == null) {
      return defaultOptions;
    }

    List<Float> typedOptions = new ArrayList<Float>();
    for (Number option : options) {
      typedOptions.add(option.floatValue());
    }

    return typedOptions;
  }

  public int getPostMaxCharacterCount () {
    int value = config.getInt("postMaxCharacterCount", 140);
    return value;
  }
}




Java Source Code List

android.UnusedStub.java
com.cs121.groupgoal.Application.java
com.cs121.groupgoal.CommentActivity.java
com.cs121.groupgoal.Comment.java
com.cs121.groupgoal.ConfigHelper.java
com.cs121.groupgoal.DatePickerDialogFragment.java
com.cs121.groupgoal.DispatchActivity.java
com.cs121.groupgoal.GoalAdapter.java
com.cs121.groupgoal.GoalPost.java
com.cs121.groupgoal.InviteActivity.java
com.cs121.groupgoal.LoginActivity.java
com.cs121.groupgoal.MainActivity.java
com.cs121.groupgoal.MyFriendsActivity.java
com.cs121.groupgoal.NotificationsActivity.java
com.cs121.groupgoal.PostActivity.java
com.cs121.groupgoal.SignUpActivity.java
com.cs121.groupgoal.StartGuideActivity.java
com.cs121.groupgoal.TimePickerDialogFragment.java
com.cs121.groupgoal.UpcomingGoalsActivity.java
com.cs121.groupgoal.UserProfileActivity.java
com.cs121.groupgoal.ViewAttendeesActivity.java
com.cs121.groupgoal.ViewGoal.java
com.cs121.groupgoal.WelcomeActivity.java