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) { // Yay, retrieved successfully config = parseConfig; configLastFetchedTime = System.currentTimeMillis(); } else { // Fetch failed, reset the time configLastFetchedTime = 0; } } }); } }
public static void refreshConfig() { long currentTime = System.currentTimeMillis(); if (currentTime - lastFetchedTime > configRefreshInterval) { lastFetchedTime = currentTime; ParseConfig.getInBackground(new ConfigCallback() { @Override public void done(ParseConfig config, ParseException e) { if (e == null) { Log.d(TAG, "Fetched config from server."); } else { Log.e(TAG, "Failed to fetch config from server. Using Cached Config."); } cachedConfig = ParseConfig.getCurrentConfig(); Log.d(TAG,"Config is "+cachedConfig.toString()); } }); } }
@Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); Parse.initialize(this, Constants.getConstant(this, R.string.PARSE_APP_ID), Constants.getConstant(this, R.string.PARSE_CLIENT_KEY)); Fabric.with(this, new Crashlytics()); Crashlytics.getInstance().setDebugMode(false); Crashlytics.log(Log.INFO, StarterApplication.class.getName(), "Starting Application - " + System.currentTimeMillis()); NewsCatFileUtil.getInstance(this); UserPrefUtil.getInstance(this); ParseConfig.getInBackground(new ConfigCallback() { @Override public void done(ParseConfig config, ParseException e) { ConfigService.getInstance(); ConfigService.getInstance().setInstance(StarterApplication.this); } }); }
public static boolean forceUpdate(Context context){ try { int updateVersion = ParseConfig.get().getInt("FORCE_UPDATE_VERSION", -1); return updateVersion > 0 && Util.getAppVersionCode(context) <= updateVersion; } catch (Exception e){ return false; } }
private ConfigService() { if (isConfigAvailable()) { ParseConfig config = ParseConfig.getCurrentConfig(); setConfigVersion(config.getNumber("version")); setTheHinduElementsFromConfig(config); setTOIElementsFromConfig(config); setIndianExpressElementsFromConfig(config); setFirstPostElementsFromConfig(config); } else { setTheHinduElementsFromConstants(); setTOIElementsFromConstants(); setIndianExpressElementsFromConstants(); setFirstPostElementsFromConstants(); } }
private void setIndianExpressElementsFromConfig(ParseConfig config) { setIndianExpressBody(config.getString("tie_body")); setIndianExpressHead(config.getString("tie_head")); setIndianExpressImage(config.getString("tie_image")); setIndianExpressBusinessBody(config.getString("tie_business_body")); setIndianExpressBusinessHead(config.getString("tie_business_head")); setIndianExpressBusinessImage(config.getString("tie_business_image")); }
@NonNull @CheckReturnValue public static Single<ParseConfig> getConfig() { return RxTask.single(() -> ParseConfig.getInBackground()); }
private boolean isConfigAvailable() { return (ParseConfig.getCurrentConfig() != null); }
private void setTheHinduElementsFromConfig(ParseConfig config) { setTheHinduBody(config.getString("th_body")); setTheHinduHead(config.getString("th_head")); setTheHinduImageFirst(config.getString("th_image_1")); setTheHinduImageSecond(config.getString("th_image_2")); }
private void setTOIElementsFromConfig(ParseConfig config) { setTOIBody(config.getString("toi_body")); setTOIHead(config.getString("toi_head")); setTOIImageFirst(config.getString("toi_image_1")); setTOIImageSecond(config.getString("toi_image_2")); }
private void setFirstPostElementsFromConfig(ParseConfig config) { setFirstPostBody(config.getString("fp_body")); setFirstPostHead(config.getString("fp_head")); setFirstPostImage(config.getString("fp_image")); }