diff --git a/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java b/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java
index 0cb6d4f..d39eff2 100644
--- a/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java
+++ b/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java
@@ -20,17 +20,24 @@
import java.util.concurrent.TimeUnit;
import android.annotation.SuppressLint;
-import android.content.Context;
+import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
+import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
+import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
import com.icecream.snorlax.BuildConfig;
import com.icecream.snorlax.R;
@@ -41,6 +48,7 @@
import butterknife.ButterKnife;
import butterknife.Unbinder;
import rx.Observable;
+import timber.log.Timber;
public class HomeActivity extends AppCompatActivity {
@@ -52,6 +60,7 @@ public class HomeActivity extends AppCompatActivity {
FloatingActionButton mFab;
private Unbinder mUnbinder;
+ private AlertDialog mAboutDialog;
@Override
protected void onCreate(Bundle savedStateInstanceState) {
@@ -69,10 +78,10 @@ protected void onCreate(Bundle savedStateInstanceState) {
.map(enabled -> getPackageManager().getLaunchIntentForPackage(BuildConfig.XPOSED_ID))
.map(intent -> {
if (intent != null) {
- return Snackbar.make(mFab, R.string.xposed_disabled, Snackbar.LENGTH_LONG).setAction(R.string.enable, v -> startActivity(intent));
+ return Snackbar.make(mFab, R.string.error_xposed_disabled, Snackbar.LENGTH_LONG).setAction(R.string.enable, v -> startActivity(intent));
}
else {
- return Snackbar.make(mFab, R.string.xposed_missing, Snackbar.LENGTH_LONG);
+ return Snackbar.make(mFab, R.string.error_xposed_missing, Snackbar.LENGTH_LONG);
}
})
.subscribe(Snackbar::show);
@@ -84,7 +93,7 @@ protected void onCreate(Bundle savedStateInstanceState) {
.map(click -> getPackageManager().getLaunchIntentForPackage(BuildConfig.POKEMON_GO_ID))
.doOnNext(intent -> {
if (intent == null) {
- Snackbar.make(mFab, R.string.pokemon_missing, Snackbar.LENGTH_LONG).show();
+ Snackbar.make(mFab, R.string.error_pokemon_missing, Snackbar.LENGTH_LONG).show();
}
})
.filter(intent -> intent != null)
@@ -110,34 +119,95 @@ protected void onDestroy() {
mUnbinder.unbind();
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_home, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.about:
+ showAbout();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ @SuppressLint("InflateParams")
+ private void showAbout() {
+ View view = getLayoutInflater().inflate(R.layout.about_dialog, null, false);
+
+ TextView version = (TextView) view.findViewById(R.id.version);
+ version.setText(getString(R.string.about_version, BuildConfig.VERSION_NAME));
+
+ TextView author = (TextView) view.findViewById(R.id.author);
+ author.setText(getString(R.string.about_author));
+
+ TextView github = (TextView) view.findViewById(R.id.github);
+ github.setText(getString(R.string.about_github));
+
+ TextView thanks = (TextView) view.findViewById(R.id.thanks);
+ thanks.setText(getString(R.string.about_thanks));
+
+ mAboutDialog = new AlertDialog.Builder(this, R.style.Snorlax_Dialog)
+ .setTitle(R.string.app_name)
+ .setView(view)
+ .setPositiveButton("Github", (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_repository)))))
+ .setCancelable(true)
+ .show();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ if (mAboutDialog != null && mAboutDialog.isShowing()) {
+ mAboutDialog.dismiss();
+ }
+ }
+
public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
- @SuppressWarnings("deprecation")
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- //Note: this will throw security exception on Nougat
- getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.preferences);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- // Remove dividers
setDivider(new ColorDrawable(Color.TRANSPARENT));
setDividerHeight(0);
}
@Override
@SuppressLint("SetWorldReadable")
- @SuppressWarnings("ResultOfMethodCallIgnored")
public void onPause() {
super.onPause();
+ // Workaround since Google enforce security on Nougat on getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE);
File sharedPrefsDir = new File(getActivity().getApplicationInfo().dataDir, "shared_prefs");
File sharedPrefsFile = new File(sharedPrefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");
if (sharedPrefsFile.exists()) {
- sharedPrefsFile.setReadable(true, false);
+ try {
+ if (!sharedPrefsFile.setReadable(true, false)) {
+ showReadableError();
+ return;
+ }
+ Timber.d("Set MODE_WORLD_READABLE successfully");
+ }
+ catch (SecurityException exception) {
+ showReadableError();
+ }
+ }
+ }
+
+ private void showReadableError() {
+ if (getActivity() != null) {
+ Toast.makeText(getActivity(), R.string.error_readable, Toast.LENGTH_LONG).show();
}
}
}
diff --git a/app/src/main/res/drawable/dialog.xml b/app/src/main/res/drawable/dialog.xml
new file mode 100644
index 0000000..a0297bb
--- /dev/null
+++ b/app/src/main/res/drawable/dialog.xml
@@ -0,0 +1,15 @@
+
+