Added back button on game activity

This commit is contained in:
luca0N! 2021-03-03 22:18:11 -03:00
parent fb2d81550c
commit e8c2504a33
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 178 additions and 161 deletions

View File

@ -33,6 +33,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.View; import android.view.View;
import android.view.MenuItem;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -40,6 +41,7 @@ import android.widget.TextView;
import java.io.IOException; import java.io.IOException;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import butterknife.BindView; import butterknife.BindView;
@ -79,6 +81,10 @@ public class TriviaGameActivity extends BaseActivity
setContentView(R.layout.activity_trivia_game); setContentView(R.layout.activity_trivia_game);
ButterKnife.bind(this); ButterKnife.bind(this);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
actionBar.setDisplayHomeAsUpEnabled(true);
if (savedInstanceState != null) { if (savedInstanceState != null) {
this.game = (TriviaGame) savedInstanceState.getSerializable(STATE_TRIVIA_GAME); this.game = (TriviaGame) savedInstanceState.getSerializable(STATE_TRIVIA_GAME);
} else { } else {
@ -118,6 +124,17 @@ public class TriviaGameActivity extends BaseActivity
} }
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onTriviaQuestionsDownloaded(String json) { public void onTriviaQuestionsDownloaded(String json) {
if (json == null) { if (json == null) {
onNetworkError(); onNetworkError();