emotionhero/app/src/main/java/com/rubenvandeven/emotionhero/EndingActivity.java

92 lines
3.1 KiB
Java

package com.rubenvandeven.emotionhero;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.json.JSONException;
import org.json.JSONObject;
import cz.msebera.android.httpclient.Header;
public class EndingActivity extends AppCompatActivity {
Player player;
TextView textLoading;
TextView textFailure;
TextView textSuccess;
TextView textRank;
TextView rank;
ImageView logoEmotionHero;
ProgressBar scoreProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_ending);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("The End?");
textLoading = (TextView) findViewById(R.id.textLoading);
textFailure = (TextView) findViewById(R.id.textFailure);
textSuccess = (TextView) findViewById(R.id.textSuccess);
textRank = (TextView) findViewById(R.id.textRank);
rank = (TextView) findViewById(R.id.rank);
logoEmotionHero = (ImageView) findViewById(R.id.logoEmotionHero);
scoreProgressBar = (ProgressBar) findViewById(R.id.scoreProgressBar);
player = Player.getInstance(this);
player.api.get("/me", null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
try {
int rank = response.getInt("rank");
setRank(rank);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, String response, Throwable throwable) {
throwable.printStackTrace();
ApiRestClient.handleOnFailure(statusCode, headers, response, throwable);
// Log.e("API", response == null ? "NULL" : response);
Toast.makeText(getApplicationContext(), "Something went wrong when loading results", Toast.LENGTH_LONG).show();
scoreProgressBar.setVisibility(View.GONE);
}
});
}
public void setRank(int rank) {
textLoading.setVisibility(View.GONE);
scoreProgressBar.setVisibility(View.GONE);
if(rank == 1) {
textSuccess.setVisibility(View.VISIBLE);
// logoEmotionHero.setVisibility(View.VISIBLE);
} else {
textFailure.setVisibility(View.VISIBLE);
}
this.rank.setText(""+rank);
this.rank.setVisibility(View.VISIBLE);
this.textRank.setVisibility(View.VISIBLE);
}
}