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

Side by Side Diff: src/org/adblockplus/sbrowser/contentblocker/MainPreferences.java

Issue 29339199: Issue 3846 - Add notification for users using an old SBrowser version (Closed)
Patch Set: Created March 31, 2016, 1:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 11 matching lines...) Expand all
22 import java.io.InputStreamReader; 22 import java.io.InputStreamReader;
23 23
24 import org.adblockplus.sbrowser.contentblocker.engine.Engine; 24 import org.adblockplus.sbrowser.contentblocker.engine.Engine;
25 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; 25 import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
26 import org.adblockplus.adblockplussbrowser.R; 26 import org.adblockplus.adblockplussbrowser.R;
27 27
28 import android.app.AlertDialog; 28 import android.app.AlertDialog;
29 import android.app.ProgressDialog; 29 import android.app.ProgressDialog;
30 import android.content.DialogInterface; 30 import android.content.DialogInterface;
31 import android.content.DialogInterface.OnClickListener; 31 import android.content.DialogInterface.OnClickListener;
32 import android.content.Intent;
32 import android.content.SharedPreferences; 33 import android.content.SharedPreferences;
34 import android.net.Uri;
33 import android.os.Bundle; 35 import android.os.Bundle;
34 import android.preference.PreferenceActivity; 36 import android.preference.PreferenceActivity;
35 import android.preference.PreferenceManager; 37 import android.preference.PreferenceManager;
36 import android.text.Html; 38 import android.text.Html;
37 import android.util.Log; 39 import android.util.Log;
38 40
39 public class MainPreferences extends PreferenceActivity implements 41 public class MainPreferences extends PreferenceActivity implements
40 EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceC hangeListener 42 EngineService.OnEngineCreatedCallback, SharedPreferences.OnSharedPreferenceC hangeListener
41 { 43 {
42 private static final String TAG = MainPreferences.class.getSimpleName(); 44 private static final String TAG = MainPreferences.class.getSimpleName();
45 private static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser";
43 private ProgressDialog progressDialog = null; 46 private ProgressDialog progressDialog = null;
44 private Engine engine = null; 47 private Engine engine = null;
45 private AlertDialog setupDialog = null; 48 private AlertDialog setupDialog = null;
46 49
47 @Override 50 @Override
48 public void onCreate(Bundle savedInstanceState) 51 public void onCreate(Bundle savedInstanceState)
49 { 52 {
50 super.onCreate(savedInstanceState); 53 super.onCreate(savedInstanceState);
51 PreferenceManager.setDefaultValues(this, R.layout.preferences_main, false); 54 PreferenceManager.setDefaultValues(this, R.layout.preferences_main, false);
52 55
(...skipping 15 matching lines...) Expand all
68 super.onStart(); 71 super.onStart();
69 EngineService.startService(this, this); 72 EngineService.startService(this, this);
70 } 73 }
71 74
72 @Override 75 @Override
73 protected void onStop() 76 protected void onStop()
74 { 77 {
75 super.onStop(); 78 super.onStop();
76 } 79 }
77 80
81 private void checkForCompatibleSBrowser()
82 {
83 if (!Engine.hasCompatibleSBrowserInstalled(this.getApplicationContext()))
84 {
85 final AlertDialog d = new AlertDialog.Builder(this)
86 .setCancelable(false)
87 .setTitle(R.string.sbrowser_dialog_title)
88 .setMessage(Html.fromHtml(this.readTextFile(R.raw.sbrowser_dialog)))
89 .setNeutralButton(R.string.sbrowser_dialog_button, new OnClickListener ()
90 {
91 @Override
92 public void onClick(DialogInterface dialog, int which)
93 {
94 try
95 {
96 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market:/ /details?id="
97 + SBROWSER_APP_ID)));
98 }
99 catch (final Throwable t)
100 {
101 startActivity(new Intent(Intent.ACTION_VIEW, Uri
102 .parse("https://play.google.com/store/apps/details?id=" + SB ROWSER_APP_ID)));
103 }
104 }
105 }).create();
106 d.show();
107 }
108 else
109 {
110 this.checkAAStatus();
Felix Dahlke 2016/04/01 08:54:53 Unless I'm missing something, this has nothing to
René Jeschke 2016/04/10 22:03:25 Well, yeah, those methods aren't really named corr
Felix Dahlke 2016/04/11 13:53:48 Well, all the logic would be in the caller and non
René Jeschke 2016/04/12 09:10:04 Na, the thing is ... the method need to _exit_ to
Felix Dahlke 2016/04/12 11:44:46 OK I see, didn't realise that `checkAAStatus` is c
René Jeschke 2016/04/12 13:32:39 Done.
111 }
112 }
113
114 private void checkAAStatus()
115 {
116 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this);
117 final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown);
118 final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false);
119 if (!aaInfoShown)
120 {
121 final AlertDialog d = new AlertDialog.Builder(this)
122 .setCancelable(false)
123 .setTitle(R.string.aa_dialog_title)
124 .setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog)))
125 .setNeutralButton(R.string.aa_dialog_button, new OnClickListener()
126 {
127 @Override
128 public void onClick(DialogInterface dialog, int which)
129 {
130 prefs.edit()
131 .putBoolean(keyAaInfoShown, true)
132 .commit();
133 MainPreferences.this.checkSetupStatus();
134 }
135 }).create();
136 d.show();
137 }
138 else
139 {
140 this.checkSetupStatus();
Felix Dahlke 2016/04/01 08:54:53 Same as above.
René Jeschke 2016/04/10 22:03:25 See above.
141 }
142 }
143
78 private void checkSetupStatus() 144 private void checkSetupStatus()
79 { 145 {
80 final boolean applicationActivated = PreferenceManager.getDefaultSharedPrefe rences(this) 146 final boolean applicationActivated = PreferenceManager.getDefaultSharedPrefe rences(this)
81 .getBoolean(this.getString(R.string.key_application_activated), false); 147 .getBoolean(this.getString(R.string.key_application_activated), false);
82 148
83 if (!applicationActivated) 149 if (!applicationActivated)
84 { 150 {
85 Log.d(TAG, "Showing setup dialog"); 151 Log.d(TAG, "Showing setup dialog");
86 this.setupDialog = new AlertDialog.Builder(this) 152 this.setupDialog = new AlertDialog.Builder(this)
87 .setCancelable(false) 153 .setCancelable(false)
(...skipping 15 matching lines...) Expand all
103 @Override 169 @Override
104 public void onEngineCreated(Engine engine, boolean success) 170 public void onEngineCreated(Engine engine, boolean success)
105 { 171 {
106 Log.d(TAG, "onEngineCreated: " + success); 172 Log.d(TAG, "onEngineCreated: " + success);
107 this.engine = success ? engine : null; 173 this.engine = success ? engine : null;
108 if (this.progressDialog != null) 174 if (this.progressDialog != null)
109 { 175 {
110 this.progressDialog.dismiss(); 176 this.progressDialog.dismiss();
111 this.progressDialog = null; 177 this.progressDialog = null;
112 178
113 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferen ces(this); 179 this.checkForCompatibleSBrowser();
114 final String keyAaInfoShown = this.getString(R.string.key_aa_info_shown);
115 final boolean aaInfoShown = prefs.getBoolean(keyAaInfoShown, false);
116 if (!aaInfoShown)
117 {
118 AlertDialog d = new AlertDialog.Builder(this)
119 .setCancelable(false)
120 .setTitle(R.string.aa_dialog_title)
121 .setMessage(Html.fromHtml(this.readTextFile(R.raw.aa_dialog)))
122 .setNeutralButton(R.string.aa_dialog_button, new OnClickListener()
123 {
124 @Override
125 public void onClick(DialogInterface dialog, int which)
126 {
127 prefs.edit()
128 .putBoolean(keyAaInfoShown, true)
129 .commit();
130 MainPreferences.this.checkSetupStatus();
131 }
132 }).create();
133 d.show();
134 }
135 else
136 {
137 this.checkSetupStatus();
138 }
139 } 180 }
140 } 181 }
141 182
142 @Override 183 @Override
143 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key) 184 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str ing key)
144 { 185 {
145 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin e != null) 186 if (this.getString(R.string.key_automatic_updates).equals(key) && this.engin e != null)
146 { 187 {
147 this.engine.connectivityChanged(); 188 this.engine.connectivityChanged();
148 } 189 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 r.close(); 225 r.close();
185 } 226 }
186 } 227 }
187 catch (IOException e) 228 catch (IOException e)
188 { 229 {
189 Log.e(TAG, "Resource reading failed for: " + id, e); 230 Log.e(TAG, "Resource reading failed for: " + id, e);
190 return "..."; 231 return "...";
191 } 232 }
192 } 233 }
193 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld