Last active
December 6, 2019 09:30
-
-
Save ssaurel/9bf7a346b5a679a6309c3adc4eca2981 to your computer and use it in GitHub Desktop.
Bitcoin Price Watcher on the SSaurel's Blog
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
private void launchTimer() { | |
timer = new Timer(); | |
timer.schedule(new TimerTask() { | |
@Override | |
public void run() { | |
loadBitcoinPrice(new Callback() { | |
@Override | |
public void onResponse(Call call, Response response) throws IOException { | |
String str = response.body().string(); | |
parseBitcoinPrice(str); | |
} | |
@Override | |
public void onFailure(Call call, IOException ioe) { } | |
}); | |
} | |
}, 0, PERIOD); | |
} | |
private void cancelTimer() { | |
if (timer != null) { | |
timer.cancel(); | |
} | |
} | |
private void loadBitcoinPrice(Callback callback) { | |
Request request = new Request.Builder().url(BITCOIN_PRICE_ENDPOINT).build(); | |
client.newCall(request).enqueue(callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment