@ -16,6 +16,12 @@ import android.support.annotation.NonNull;
@@ -16,6 +16,12 @@ import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog ;
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.app.BrowserApp ;
import acr.browser.lightning.dialog.BrowserDialog ;
@ -40,7 +46,6 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
@@ -40,7 +46,6 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
private static final String SETTINGS_IDENTIFYINGHEADERS = "remove_identifying_headers" ;
private Activity mActivity ;
private Handler mMessageHandler ;
@Override
public void onCreate ( Bundle savedInstanceState ) {
@ -103,29 +108,6 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
@@ -103,29 +108,6 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
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
@ -152,19 +134,22 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
@@ -152,19 +134,22 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
AlertDialog . Builder builder = new AlertDialog . Builder ( mActivity ) ;
builder . setTitle ( getResources ( ) . getString ( R . string . title_clear_history ) ) ;
Dialog dialog = builder . setMessage ( getResources ( ) . getString ( R . string . dialog_history ) )
. setPositiveButton ( getResources ( ) . getString ( R . string . action_yes ) ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface arg0 , int arg1 ) {
BrowserApp . getIOThread ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
clearHistory ( ) ;
}
} ) ;
}
} )
. setNegativeButton ( getResources ( ) . getString ( R . string . action_no ) , null ) . show ( ) ;
. setPositiveButton ( getResources ( ) . getString ( R . string . action_yes ) ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface arg0 , int arg1 ) {
clearHistory ( )
. subscribeOn ( Schedulers . io ( ) )
. observeOn ( Schedulers . main ( ) )
. subscribe ( new CompletableOnSubscribe ( ) {
@Override
public void onComplete ( ) {
Utils . showSnackbar ( getActivity ( ) , R . string . message_clear_history ) ;
}
} ) ;
}
} )
. setNegativeButton ( getResources ( ) . getString ( R . string . action_no ) , null ) . show ( ) ;
BrowserDialog . setDialogSize ( mActivity , dialog ) ;
}
@ -172,19 +157,22 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
@@ -172,19 +157,22 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
AlertDialog . Builder builder = new AlertDialog . Builder ( mActivity ) ;
builder . setTitle ( getResources ( ) . getString ( R . string . title_clear_cookies ) ) ;
builder . setMessage ( getResources ( ) . getString ( R . string . dialog_cookies ) )
. setPositiveButton ( getResources ( ) . getString ( R . string . action_yes ) ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface arg0 , int arg1 ) {
BrowserApp . getTaskThread ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
clearCookies ( ) ;
}
} ) ;
}
} )
. setNegativeButton ( getResources ( ) . getString ( R . string . action_no ) , null ) . show ( ) ;
. setPositiveButton ( getResources ( ) . getString ( R . string . action_yes ) ,
new DialogInterface . OnClickListener ( ) {
@Override
public void onClick ( DialogInterface arg0 , int arg1 ) {
clearCookies ( )
. subscribeOn ( Schedulers . io ( ) )
. observeOn ( Schedulers . main ( ) )
. subscribe ( new CompletableOnSubscribe ( ) {
@Override
public void onComplete ( ) {
Utils . showSnackbar ( getActivity ( ) , R . string . message_cookies_cleared ) ;
}
} ) ;
}
} )
. setNegativeButton ( getResources ( ) . getString ( R . string . action_no ) , null ) . show ( ) ;
}
private void clearCache ( ) {
@ -194,14 +182,34 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
@@ -194,14 +182,34 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
Utils . showSnackbar ( mActivity , R . string . message_cache_cleared ) ;
}
private void clearHistory ( ) {
WebUtils . clearHistory ( getActivity ( ) ) ;
mMessageHandler . sendEmptyMessage ( 1 ) ;
@NonNull
private Completable clearHistory ( ) {
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 ( ) {
WebUtils . clearCookies ( getActivity ( ) ) ;
mMessageHandler . sendEmptyMessage ( 2 ) ;
@NonNull
private Completable clearCookies ( ) {
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 ( ) {