Created
October 26, 2015 14:46
-
-
Save anonymous/14b3d8c7a6bf98e2941e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arranca en el show() del screen. Cada vez que se muestra el lobby, va a checkTimer() | |
@Override | |
public void show() { | |
[..] | |
checkTimer(); | |
super.show(); | |
} | |
// Chequeo si ya tengo llenas las monedas (>30). En ese caso, el timer se inhabilita. | |
private void checkTimer() { | |
if (mProfile.coins >= Constants.INITIAL_GENERIC_COINS) { | |
// do not update timer | |
mRunningTimer = false; | |
} else { | |
mRunningTimer = true; | |
} | |
} | |
// En el render, llamo a al metodo que actualiza el reloj cada 1 segundo. | |
private void updateTimer() { | |
if (!mRunningTimer) { | |
return; | |
} | |
// hago un TTL para ver si existe la variable | |
JedisService.ttl(Constants.VAR_TTL + mProfile.emailId, | |
new Callback<String>() { | |
@Override | |
public void onCallback(String pCallbackValue) { | |
int ttl = Integer.valueOf(pCallbackValue); | |
LogUtil.i("TTL: " + ttl); | |
// The command returns -2 if the key does not exist. | |
// The command returns -1 if the key exists but has no associated expire. | |
if (ttl < 0 | |
&& mProfile.coins < Constants.INITIAL_GENERIC_COINS) { | |
// ttl expired or didn't exist | |
mProfile.coins = Constants.INITIAL_GENERIC_COINS; | |
mRunningTimer = false; | |
} else { | |
// ACA VIENE LA LOGICA DE MARTIN QUE NO COMPRENDO | |
// PARA SIMPLIFICAR, QUISE HACER QUE SE SUMEN MONEDAS CADA 1 MINUTO EN VEZ DE CADA HORA | |
// int min = Tools.secondsToMinutes(ttl); | |
int min = ttl; | |
LogUtil.i("min: " + min); | |
mProfile.coins = Math.min(mProfile.coins | |
+ (Constants.INIT_TIME - min) | |
* Constants.WIN_MATCH_COINS, | |
Constants.INITIAL_GENERIC_COINS); | |
if (mProfile.coins < Constants.INITIAL_GENERIC_COINS) { | |
initTimer(); // setex; | |
} else { | |
mRunningTimer = false; | |
} | |
} | |
mCoinsLabel.setText("" + mProfile.coins); | |
mProfile.saveLocal(); | |
mProfile.saveInRedis(); | |
LogUtil.i("COINS: " + mProfile.coins); | |
} | |
}); | |
} | |
// Este método hace el setex, otras inicializaciones y pone a correr el updateTimer() | |
public void initTimer() { | |
LogUtil.i("initTimer()"); | |
LogUtil.i("Coins: " + mProfile.coins); | |
int initTime = Constants.INIT_TIME; | |
mTimerLabel.setText(Tools.timeConversion(initTime) + ""); | |
JedisService.setex(Constants.VAR_TTL + mProfile.emailId, initTime, "1", | |
new Callback<String>() { | |
@Override | |
public void onCallback(String pCallbackValue) { | |
mRunningTimer = true; | |
} | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment