|
|
@ -16,6 +16,12 @@ import android.support.annotation.NonNull; |
|
|
|
import android.support.v7.app.AlertDialog; |
|
|
|
import android.support.v7.app.AlertDialog; |
|
|
|
import android.webkit.WebView; |
|
|
|
import android.webkit.WebView; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.anthonycr.bonsai.Completable; |
|
|
|
|
|
|
|
import com.anthonycr.bonsai.CompletableAction; |
|
|
|
|
|
|
|
import com.anthonycr.bonsai.CompletableOnSubscribe; |
|
|
|
|
|
|
|
import com.anthonycr.bonsai.CompletableSubscriber; |
|
|
|
|
|
|
|
import com.anthonycr.bonsai.Schedulers; |
|
|
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.R; |
|
|
|
import acr.browser.lightning.R; |
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
import acr.browser.lightning.dialog.BrowserDialog; |
|
|
|
import acr.browser.lightning.dialog.BrowserDialog; |
|
|
@ -40,7 +46,6 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme |
|
|
|
private static final String SETTINGS_IDENTIFYINGHEADERS = "remove_identifying_headers"; |
|
|
|
private static final String SETTINGS_IDENTIFYINGHEADERS = "remove_identifying_headers"; |
|
|
|
|
|
|
|
|
|
|
|
private Activity mActivity; |
|
|
|
private Activity mActivity; |
|
|
|
private Handler mMessageHandler; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
@ -103,29 +108,6 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme |
|
|
|
|
|
|
|
|
|
|
|
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); |
|
|
|
cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); |
|
|
|
|
|
|
|
|
|
|
|
mMessageHandler = new MessageHandler(mActivity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class MessageHandler extends Handler { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Activity mHandlerContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MessageHandler(Activity context) { |
|
|
|
|
|
|
|
this.mHandlerContext = context; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void handleMessage(@NonNull Message msg) { |
|
|
|
|
|
|
|
switch (msg.what) { |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
Utils.showSnackbar(mHandlerContext, R.string.message_clear_history); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 2: |
|
|
|
|
|
|
|
Utils.showSnackbar(mHandlerContext, R.string.message_cookies_cleared); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
super.handleMessage(msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -156,10 +138,13 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme |
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface arg0, int arg1) { |
|
|
|
public void onClick(DialogInterface arg0, int arg1) { |
|
|
|
BrowserApp.getIOThread().execute(new Runnable() { |
|
|
|
clearHistory() |
|
|
|
|
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
|
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
|
|
|
|
.subscribe(new CompletableOnSubscribe() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void onComplete() { |
|
|
|
clearHistory(); |
|
|
|
Utils.showSnackbar(getActivity(), R.string.message_clear_history); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -176,10 +161,13 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme |
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface arg0, int arg1) { |
|
|
|
public void onClick(DialogInterface arg0, int arg1) { |
|
|
|
BrowserApp.getTaskThread().execute(new Runnable() { |
|
|
|
clearCookies() |
|
|
|
|
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
|
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
|
|
|
|
.subscribe(new CompletableOnSubscribe() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void onComplete() { |
|
|
|
clearCookies(); |
|
|
|
Utils.showSnackbar(getActivity(), R.string.message_cookies_cleared); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -194,14 +182,34 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme |
|
|
|
Utils.showSnackbar(mActivity, R.string.message_cache_cleared); |
|
|
|
Utils.showSnackbar(mActivity, R.string.message_cache_cleared); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void clearHistory() { |
|
|
|
@NonNull |
|
|
|
WebUtils.clearHistory(getActivity()); |
|
|
|
private Completable clearHistory() { |
|
|
|
mMessageHandler.sendEmptyMessage(1); |
|
|
|
return Completable.create(new CompletableAction() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSubscribe(@NonNull CompletableSubscriber subscriber) { |
|
|
|
|
|
|
|
Activity activity = getActivity(); |
|
|
|
|
|
|
|
if (activity != null) { |
|
|
|
|
|
|
|
WebUtils.clearHistory(activity); |
|
|
|
|
|
|
|
subscriber.onComplete(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
subscriber.onError(new RuntimeException("Activity was null in clearHistory")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void clearCookies() { |
|
|
|
@NonNull |
|
|
|
WebUtils.clearCookies(getActivity()); |
|
|
|
private Completable clearCookies() { |
|
|
|
mMessageHandler.sendEmptyMessage(2); |
|
|
|
return Completable.create(new CompletableAction() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSubscribe(@NonNull CompletableSubscriber subscriber) { |
|
|
|
|
|
|
|
Activity activity = getActivity(); |
|
|
|
|
|
|
|
if (activity != null) { |
|
|
|
|
|
|
|
WebUtils.clearCookies(activity); |
|
|
|
|
|
|
|
subscriber.onComplete(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
subscriber.onError(new RuntimeException("Activity was null in clearCookies")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void clearWebStorage() { |
|
|
|
private void clearWebStorage() { |
|
|
|