Skip to content

Commit

Permalink
Merge pull request #69 in ANDROID/content-blocker from master to prod
Browse files Browse the repository at this point in the history
* commit 'c04d3c05e9ec7972a0e8da52e56eac66c4bd9789':
  Add sl localization
  Add ABPVN filter
  Sync switch and filter state
  • Loading branch information
Alexey Dmitrievskiy committed Dec 19, 2019
2 parents 80b0a3b + c04d3c0 commit e259ee3
Show file tree
Hide file tree
Showing 11 changed files with 1,154 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .twosky.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"no": "Norwegian",
"be": "Беларуская",
"bn": "Bengali",
"ms": "Malay"
"ms": "Malay",
"sl": "Slovenščina"
},
"localizable_files": [
"adguard_cb/main/res/values/strings*.xml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DbHelper extends SQLiteOpenHelper {

private static final Logger LOG = LoggerFactory.getLogger(DbHelper.class);

private static final int DB_VERSION = 24;
private static final int DB_VERSION = 25;
private static final String DB_NAME = "adguard.db";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ This file is part of AdGuard Content Blocker (https://github.com/AdguardTeam/Con
import com.adguard.android.contentblocker.commons.TextStatistics;
import com.adguard.android.contentblocker.commons.concurrent.DispatcherThreadPool;
import com.adguard.android.contentblocker.commons.io.IoUtils;
import com.adguard.android.contentblocker.commons.network.InternetUtils;
import com.adguard.android.contentblocker.commons.network.NetworkUtils;
import com.adguard.android.contentblocker.db.DbHelper;
import com.adguard.android.contentblocker.db.FilterListDao;
Expand Down Expand Up @@ -242,7 +241,7 @@ public void setUserRules(String userRules) {
@Override
public void clearUserRules() {
setUserRules(StringUtils.EMPTY);
preferencesService.setDisabledUserRules(new HashSet<String>());
preferencesService.setDisabledUserRules(new HashSet<>());
}

@Override
Expand Down Expand Up @@ -293,7 +292,7 @@ public void setWhiteList(String whitelist) {
@Override
public void clearWhiteList() {
setWhiteList(StringUtils.EMPTY);
preferencesService.setDisabledWhitelistRules(new HashSet<String>());
preferencesService.setDisabledWhitelistRules(new HashSet<>());
}

@Override
Expand All @@ -317,8 +316,6 @@ public void enableWhitelistRule(String ruleText, boolean enabled) {

@Override
public void applyNewSettings() {
setShowUsefulAds(preferencesService.isShowUsefulAds());

List<String> rules = getAllEnabledRules();

List<String> userRules = StringHelperUtils.splitAndTrim(preferencesService.getUserRules(), "\n");
Expand Down Expand Up @@ -606,7 +603,7 @@ private void importRules(String download) {
return;
}

LOG.info("{} user rules downloaded from {}", rules.length);
LOG.info("{} user rules downloaded from {}", rules.length, url);

final List<String> rulesList = new ArrayList<>(rules.length);
for (String rule : rules) {
Expand Down Expand Up @@ -636,12 +633,7 @@ private void importRules(String download) {
notificationService.showToast(message);

if (onImportListener != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
onImportListener.onSuccess();
}
});
activity.runOnUiThread(() -> onImportListener.onSuccess());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ This file is part of AdGuard Content Blocker (https://github.com/AdguardTeam/Con
*/
public interface PreferencesService {

String PREF_SHOW_USEFUL_ADS = "pref_show_useful_ads";
String KEY_AUTOUPDATE_FILTERS = "auto_update_filters";
String KEY_UPDATE_OVER_WIFI = "update_over_wifi";
String KEY_LAST_UPDATE_CHECK_DATE = "last_update_check_date";
Expand Down Expand Up @@ -137,16 +136,6 @@ public interface PreferencesService {
*/
void setLastImportUrl(String url);

/**
* Set whether we should show useful ads
*/
void setShowUsefulAds(boolean value);

/**
* Whether we should show useful ads
*/
boolean isShowUsefulAds();

/**
* Sets filter rules count
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void setUserRuleItems(String userRules) {
@Override
public Set<String> getDisabledUserRules() {
Set<String> valueSet = sharedPreferences.getStringSet(KEY_DISABLED_USER_RULES, null);
return valueSet != null ? new HashSet<>(valueSet) : new HashSet<String>();
return valueSet != null ? new HashSet<>(valueSet) : new HashSet<>();
}

@Override
Expand Down Expand Up @@ -139,18 +139,6 @@ public void setLastImportUrl(String url) {
editor.apply();
}

@Override
public void setShowUsefulAds(boolean value) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(PREF_SHOW_USEFUL_ADS, value);
editor.apply();
}

@Override
public boolean isShowUsefulAds() {
return sharedPreferences.getBoolean(PREF_SHOW_USEFUL_ADS, false);
}

@Override
public void setFilterRuleCount(int ruleCount) {
SharedPreferences.Editor editor = sharedPreferences.edit();
Expand Down Expand Up @@ -213,7 +201,7 @@ public void setWhitelist(String whitelist) {

@Override
public Set<String> getDisabledWhitelistRules() {
return sharedPreferences.getStringSet(KEY_DISABLED_WHITELIST, new HashSet<String>());
return sharedPreferences.getStringSet(KEY_DISABLED_WHITELIST, new HashSet<>());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.adguard.android.contentblocker.ServiceLocator;
import com.adguard.android.contentblocker.R;
import com.adguard.android.contentblocker.service.FilterService;
import com.adguard.android.contentblocker.service.PreferencesService;
import com.adguard.android.contentblocker.ui.utils.ApplyAndRefreshTask;
import com.adguard.android.contentblocker.ui.utils.NavigationHelper;
import com.adguard.android.contentblocker.ui.utils.ProgressDialogUtils;

Expand Down Expand Up @@ -65,7 +64,10 @@ protected void onCreate(Bundle savedInstanceState) {

final CheckBox showUsefulAdsView = findViewById(R.id.show_useful_ads_checkbox);
showUsefulAdsView.setChecked(filterService.isShowUsefulAds());
showUsefulAdsView.setOnCheckedChangeListener((compoundButton, enable) -> filterService.setShowUsefulAds(enable));
showUsefulAdsView.setOnCheckedChangeListener((compoundButton, enable) -> {
filterService.setShowUsefulAds(enable);
new ApplyAndRefreshTask(filterService, this).execute();
});

findViewById(R.id.show_useful_ads_wrapper).setOnClickListener(view ->
showUsefulAdsView.setChecked(!showUsefulAdsView.isChecked()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ This file is part of AdGuard Content Blocker (https://github.com/AdguardTeam/Con
import android.widget.TextView;

import com.adguard.android.contentblocker.R;
import com.adguard.android.contentblocker.ServiceLocator;
import com.adguard.android.contentblocker.model.FilterList;
import com.adguard.android.contentblocker.service.FilterService;
import com.adguard.android.contentblocker.service.PreferencesService;

import java.util.Date;

Expand Down Expand Up @@ -99,11 +97,6 @@ public void onClick(View v) {
FilterList filterList = (FilterList) v.getTag();
filterService.updateFilterEnabled(filterList, !filterList.isEnabled());
((CheckBox) v.findViewById(R.id.checkbox)).setChecked(filterList.isEnabled());

if (filterList.getFilterId() == FilterService.SHOW_USEFUL_ADS_FILTER_ID) {
PreferencesService preferencesService = ServiceLocator.getInstance(context.getApplicationContext()).getPreferencesService();
preferencesService.setShowUsefulAds(filterList.isEnabled());
}
new ApplyAndRefreshTask(filterService, context).execute();
}

Expand Down
Loading

0 comments on commit e259ee3

Please sign in to comment.