Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java

Issue 29356560: Issue 4522 - Leaking and stacking dialogs in MainPreferences (Closed)
Patch Set: Created Oct. 11, 2016, 9:55 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
===================================================================
--- a/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
+++ b/src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java
@@ -21,16 +21,17 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.adblockplus.sbrowser.contentblocker.engine.Engine;
import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
import org.adblockplus.adblockplussbrowser.R;
import android.app.AlertDialog;
+import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceActivity;
@@ -38,19 +39,19 @@ import android.preference.PreferenceMana
import android.text.Html;
import android.util.Log;
public class MainPreferences extends PreferenceActivity implements
EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceChangeListener
{
private static final String TAG = MainPreferences.class.getSimpleName();
private static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser";
- private ProgressDialog progressDialog = null;
private Engine engine = null;
- private AlertDialog setupDialog = null;
+ private Dialog dialog;
+ private int dialogTitleResId;
private SharedPreferences getSharedPreferences()
{
return PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
}
@Override
public void onCreate(Bundle savedInstanceState)
@@ -80,38 +81,51 @@ public class MainPreferences extends Pre
.clear()
.commit();
}
}
@Override
protected void onStart()
{
- this.progressDialog = ProgressDialog.show(this,
- this.getString(R.string.initialization_title),
+ this.dialogTitleResId = R.string.initialization_title;
+ this.dialog = ProgressDialog.show(this,
+ this.getString(this.dialogTitleResId),
this.getString(R.string.initialization_message));
super.onStart();
this.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
EngineService.startService(this.getApplicationContext(), this);
}
@Override
protected void onStop()
{
super.onStop();
this.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+ this.dismissDialog();
+ }
+
+ private void dismissDialog()
+ {
+ if (this.dialog != null)
+ {
+ this.dialogTitleResId = 0;
+ this.dialog.dismiss();
+ this.dialog = null;
+ }
}
private void checkForCompatibleSBrowserAndProceed()
{
if (!Engine.hasCompatibleSBrowserInstalled(this.getApplicationContext()))
{
- final AlertDialog d = new AlertDialog.Builder(this)
+ this.dialogTitleResId = R.string.sbrowser_dialog_title;
+ this.dialog = new AlertDialog.Builder(this)
.setCancelable(false)
- .setTitle(R.string.sbrowser_dialog_title)
+ .setTitle(this.dialogTitleResId)
.setMessage(Html.fromHtml(this.readTextFile(R.raw.sbrowser_dialog)))
.setNeutralButton(R.string.sbrowser_dialog_button, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
try
{
@@ -120,88 +134,89 @@ public class MainPreferences extends Pre
}
catch (final Throwable t)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("https://play.google.com/store/apps/details?id=" + SBROWSER_APP_ID)));
}
}
}).create();
- d.show();
+ this.dialog.show();
}
else
{
this.checkAAStatusAndProceed();
}
}
private void checkAAStatusAndProceed()
{
final SharedPreferences prefs = this.getSharedPreferences();
final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown);
final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false);
if (!aaInfoShown)
{
- final AlertDialog d = new AlertDialog.Builder(this)
+ this.dialogTitleResId = R.string.aa_dialog_title;
+ this.dialog = new AlertDialog.Builder(this)
.setCancelable(false)
- .setTitle(R.string.aa_dialog_title)
+ .setTitle(this.dialogTitleResId)
.setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog)))
.setNeutralButton(R.string.aa_dialog_button, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
prefs.edit()
.putBoolean(keyAaInfoShown, true)
.commit();
MainPreferences.this.checkSetupStatus();
}
}).create();
- d.show();
+ this.dialog.show();
}
else
{
this.checkSetupStatus();
}
}
private void checkSetupStatus()
{
final boolean applicationActivated = this.getSharedPreferences()
.getBoolean(this.getString(R.string.key_application_activated), false);
if (!applicationActivated)
{
Log.d(TAG, "Showing setup dialog");
- this.setupDialog = new AlertDialog.Builder(this)
+ this.dialogTitleResId = R.string.setup_dialog_title;
+ this.dialog = new AlertDialog.Builder(this)
.setCancelable(false)
- .setTitle(R.string.setup_dialog_title)
+ .setTitle(this.dialogTitleResId)
.setMessage(Html.fromHtml(this.readTextFile(R.raw.setup_dialog)))
.setNeutralButton(R.string.setup_dialog_button, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Engine.openSBrowserSettings(MainPreferences.this);
}
})
.create();
- this.setupDialog.show();
+ this.dialog.show();
}
}
@Override
public void onEngineCreated(Engine engine, boolean success)
{
Log.d(TAG, "onEngineCreated: " + success);
this.engine = success ? engine : null;
- if (this.progressDialog != null)
+ if (this.dialogTitleResId == R.string.initialization_title)
{
- this.progressDialog.dismiss();
- this.progressDialog = null;
+ this.dismissDialog();
this.checkForCompatibleSBrowserAndProceed();
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
@@ -213,20 +228,19 @@ public class MainPreferences extends Pre
{
boolean enabled = sharedPreferences.getBoolean(key, true);
final String id = "url:" + this.engine.getPrefsDefault(Engine.SUBSCRIPTIONS_EXCEPTIONSURL);
Log.d(TAG, "Acceptable ads " + (enabled ? "enabled" : "disabled"));
this.engine.changeSubscriptionState(id, enabled);
}
else if (this.getString(R.string.key_application_activated).equals(key))
{
- if (this.setupDialog != null)
+ if (this.dialogTitleResId == R.string.setup_dialog_title)
{
- this.setupDialog.dismiss();
- this.setupDialog = null;
+ this.dismissDialog();
}
}
}
private String readTextFile(int id)
{
try
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld