Added initial theme change checks

This commit is contained in:
luca0N! 2021-03-17 19:10:48 -03:00
parent 3acbd9a4c7
commit 687fe7b7c2
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
4 changed files with 28 additions and 2 deletions

View File

@ -24,6 +24,7 @@ Contact us at <joguitos+pluck@luca0n.com>.
package com.luca0n.joguitos.pluck.activities;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
@ -39,6 +40,7 @@ import com.luca0n.joguitos.pluck.util.UiUtil;
@SuppressLint("Registered")
public class BaseActivity extends AppCompatActivity {
public static final int REQUEST_ACTIVITY_CLOSED = 1;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -63,9 +65,24 @@ public class BaseActivity extends AppCompatActivity {
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent extras){
switch (requestCode){
case REQUEST_ACTIVITY_CLOSED:
if (resultCode == Activity.RESULT_OK){
// Check if the theme changed.
recreate();
}
break;
default:
super.onActivityResult(requestCode, resultCode, extras);
break;
}
}
private void onSettings() {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
startActivityForResult(intent, REQUEST_ACTIVITY_CLOSED);
}
private void onAbout() {

View File

@ -131,7 +131,7 @@ public class MainActivity extends BaseActivity {
.category(category)
.difficulty(difficulty)
.build());
startActivity(intent);
startActivityForResult(intent, BaseActivity.REQUEST_ACTIVITY_CLOSED);
});
// Create a String array that holds all options for spinnerNumber.
@ -193,6 +193,10 @@ public class MainActivity extends BaseActivity {
.show();
}
break;
case BaseActivity.REQUEST_ACTIVITY_CLOSED:
// Check if the theme changed.
recreate();
break;
default:
super.onActivityResult(requestCode, resultCode, extras);
break;

View File

@ -23,6 +23,7 @@ Contact us at <joguitos+pluck@luca0n.com>.
package com.luca0n.joguitos.pluck.activities;
import android.app.Activity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
@ -98,6 +99,8 @@ public class TriviaGameActivity extends BaseActivity
setContentView(R.layout.activity_trivia_game);
ButterKnife.bind(this);
setResult(Activity.RESULT_OK);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
actionBar.setDisplayHomeAsUpEnabled(true);

View File

@ -23,6 +23,7 @@ Contact us at <joguitos+pluck@luca0n.com>.
package com.luca0n.joguitos.pluck.settings;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
@ -46,6 +47,7 @@ public class SettingsActivity extends AppCompatActivity {
.beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
setResult(Activity.RESULT_OK);
}
@Override