Skip to content

Commit

Permalink
UI fixes and disable adblocking by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Kollnig committed Jun 8, 2020
1 parent 1bb900c commit bdaeebd
Showing 10 changed files with 128 additions and 71 deletions.
15 changes: 0 additions & 15 deletions app/src/main/java/eu/faircode/netguard/ActivityMain.java
Original file line number Diff line number Diff line change
@@ -379,21 +379,6 @@ public void onClick(View view) {
if (!initialized)
prefs.edit().putBoolean("initialized", true).apply();

// Show instructions
/*TrackerList db = TrackerList.getInstance(this);
if (db.count() <= 0) {
int instructionsString =
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) ?
R.string.instructions_monitoring_private_dns :
R.string.instructions_monitoring;
View v = this.getWindow().getDecorView().findViewById(android.R.id.content);
Snackbar s = Snackbar.make(v, instructionsString, Snackbar.LENGTH_INDEFINITE);
s.setAction(R.string.ok, v1 -> s.dismiss());
s.setActionTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
s.show();
}*/

// Fill application list
updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

8 changes: 4 additions & 4 deletions app/src/main/java/eu/faircode/netguard/ActivitySettings.java
Original file line number Diff line number Diff line change
@@ -308,10 +308,10 @@ public boolean onPreferenceClick(Preference preference) {
Log.i(TAG, "Play store install");
cat_advanced.removePreference(pref_block_domains);
cat_advanced.removePreference(pref_rcode);
cat_backup.removePreference(pref_hosts_import);
cat_backup.removePreference(pref_hosts_import_append);
cat_backup.removePreference(pref_hosts_url);
cat_backup.removePreference(pref_hosts_download);
cat_advanced.removePreference(pref_hosts_import);
cat_advanced.removePreference(pref_hosts_import_append);
cat_advanced.removePreference(pref_hosts_url);
cat_advanced.removePreference(pref_hosts_download);

} else {
String last_import = prefs.getString("hosts_last_import", null);
9 changes: 7 additions & 2 deletions app/src/main/java/eu/faircode/netguard/AdapterRule.java
Original file line number Diff line number Diff line change
@@ -557,8 +557,13 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {

// Custom code: show tracker count
int trackerCount = rule.getTrackerCount();
holder.tvDetails.setText(context.getResources().getQuantityString(
R.plurals.n_trackers_found, trackerCount, trackerCount));
if (trackerCount > 0) {
holder.tvDetails.setVisibility(View.VISIBLE);
holder.tvDetails.setText(context.getResources().getQuantityString(
R.plurals.n_trackers_found, trackerCount, trackerCount));
} else {
holder.tvDetails.setVisibility(View.GONE);
}

// Show Wi-Fi screen on condition
holder.llScreenWifi.setVisibility(screen_on ? View.VISIBLE : View.GONE);
24 changes: 23 additions & 1 deletion app/src/main/java/eu/faircode/netguard/Rule.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
Copyright 2015-2019 by Marcel Bokhorst (M66B)
*/

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -31,10 +32,15 @@
import android.os.Build;
import android.os.Process;
import android.util.Log;
import android.view.View;

import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;

import com.google.android.material.snackbar.Snackbar;

import net.kollnig.missioncontrol.R;
import net.kollnig.missioncontrol.data.Pair;
import net.kollnig.missioncontrol.data.TrackerList;

import org.xmlpull.v1.XmlPullParser;
@@ -410,7 +416,23 @@ public static List<Rule> getRules(final boolean all, Context context) {

// Custom code: Load tracking counts
TrackerList trackerList = TrackerList.getInstance(context);
trackerCounts = trackerList.getTrackerCounts();
Pair<Map<Integer, Integer>, Integer> trackerCountsAndTotal = trackerList.getTrackerCountsAndTotal();
trackerCounts = trackerCountsAndTotal.first();
int trackerTotal = trackerCountsAndTotal.second();

if (trackerTotal <= 0
&& context instanceof Activity) {
int instructionsString =
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) ?
R.string.instructions_monitoring_private_dns :
R.string.instructions_monitoring;

View v = ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
Snackbar s = Snackbar.make(v, instructionsString, Snackbar.LENGTH_INDEFINITE);
s.setAction(R.string.ok, v1 -> s.dismiss());
s.setActionTextColor(ContextCompat.getColor(context, R.color.colorPrimary));
s.show();
}

// Sort rule list
final Collator collator = Collator.getInstance(Locale.getDefault());
36 changes: 36 additions & 0 deletions app/src/main/java/net/kollnig/missioncontrol/data/Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* TrackerControl is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TrackerControl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TrackerControl. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2020 Konrad Kollnig, University of Oxford
*/

package net.kollnig.missioncontrol.data;

public class Pair<T, U> {
private final T t;
private final U u;

public Pair(T t, U u) {
this.t = t;
this.u = u;
}

public T first() {
return t;
}

public U second() {
return u;
}
}
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public static TrackerList getInstance(Context c) {
* @return A cursor pointing to the data. Caller must close the cursor.
* Cursor should have app name and leak summation based on a sort type
*/
public synchronized Map<Integer, Integer> getTrackerCounts() {
public synchronized Pair<Map<Integer, Integer>, Integer> getTrackerCountsAndTotal() {
Map<Integer, Set<Tracker>> trackers = new ArrayMap<>();

Cursor cursor = databaseHelper.getHosts();
@@ -101,12 +101,14 @@ public synchronized Map<Integer, Integer> getTrackerCounts() {
cursor.close();

// Reduce to counts
Integer totalTracker = 0;
Map<Integer, Integer> trackerCounts = new ArrayMap<>();
for (Map.Entry<Integer, Set<Tracker>> entry : trackers.entrySet()) {
trackerCounts.put(entry.getKey(), entry.getValue().size());
totalTracker += entry.getValue().size();
}

return trackerCounts;
return new Pair<>(trackerCounts, totalTracker);
}

/**
29 changes: 17 additions & 12 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -16,18 +16,23 @@
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:gravity="center_horizontal"
android:id="@+id/tvDisabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:paddingStart="?listPreferredItemPaddingLeft"
android:paddingEnd="?listPreferredItemPaddingRight"
android:text="@string/msg_disabled"
android:textAppearance="@style/TextMedium"
android:textColor="?attr/colorOff"
android:visibility="gone" />
<LinearLayout
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:gravity="center_horizontal"
android:id="@+id/tvDisabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:paddingStart="?listPreferredItemPaddingLeft"
android:paddingEnd="?listPreferredItemPaddingRight"
android:text="@string/msg_disabled"
android:textAppearance="@style/TextMedium"
android:textColor="?attr/colorOff"
android:visibility="gone" />
</LinearLayout>

<LinearLayout
android:visibility="gone"
10 changes: 6 additions & 4 deletions app/src/main/res/layout/rule.xml
Original file line number Diff line number Diff line change
@@ -22,9 +22,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_toEndOf="@+id/ivIcon"
android:layout_toStartOf="@+id/cbApply"
android:layout_toEndOf="@+id/ivIcon"
android:gravity="bottom"
android:minHeight="46dp"
android:orientation="vertical">

<TextView
@@ -37,19 +38,20 @@
android:singleLine="true"
android:text="@string/tracked_app_name"
android:textColor="?android:textColorPrimary"
android:textSize="16sp"/>
android:textSize="16sp" />

<TextView
android:id="@+id/app_details"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:gravity="bottom"
android:minHeight="20dp"
android:singleLine="true"
android:text="@string/tracked_app_name"
android:textColor="?android:textColorTertiary"
android:text="@string/tracked_app_name"/>
android:textSize="14sp"
android:visibility="gone" />

</LinearLayout>

10 changes: 5 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -112,8 +112,8 @@
<string name="setting_track_usage">Track network usage</string>
<string name="setting_reset_usage">Reset network usage</string>
<string name="setting_show_resolved">Show resolved domain names</string>
<string name="setting_block_domains">Block domain names</string>
<string name="setting_rcode">DNS response code: %s</string>
<string name="setting_block_domains">Enable hosts file</string>
<string name="setting_rcode">Hosts blocking response: %s</string>
<string name="setting_forwarding">Port forwarding</string>
<string name="setting_vpn4">VPN IPv4: %s</string>
<string name="setting_vpn6">VPN IPv6: %s</string>
@@ -172,7 +172,7 @@
<string name="summary_access">Show a status bar notification when an app attempts to access a new internet address (when filtering is disabled, only blocked internet access attempts will be notified)</string>
<string name="summary_filter">Filter IP packets going out of the VPN tunnel. This might result in extra battery usage.</string>
<string name="summary_track_usage">Track the number of bytes sent and received for each app and address. This might result in extra battery usage.</string>
<string name="summary_block_domains">Respond with the configured DNS response code for blocked domain names. This switch is disabled when no hosts file is available.</string>
<string name="summary_block_domains">WARNING: Blocked hosts are not shown in UI.</string>
<string name="summary_rcode">The default value is 3 (NXDOMAIN), which means \'non-existent domain\'.</string>
<string name="summary_validate">Domain name used to validate the internet connection at port 443 (https).</string>
<string name="summary_socks5_enabled">Only TCP traffic will be sent to the proxy server</string>
@@ -486,8 +486,8 @@ Sincerely,\n\n]]></string>
<string name="crash_dialog_text">Sorry. TrackerControl just crashed.. Would you mind sending us an email with details?</string>
<string name="crash_dialog_comment">Any comments?</string>

<string name="instructions_monitoring_private_dns">Toggle the switch and interact with some other apps. Private DNS must be disabled.</string>
<string name="instructions_monitoring">Toggle the switch and interact with some other apps.</string>
<string name="instructions_monitoring_private_dns">Toggle the switch and interact with some apps. Private DNS must be disabled.</string>
<string name="instructions_monitoring">Toggle the switch and interact with some apps.</string>

<string name="afterboot_notification">Restart notification</string>
<string name="disclaimer">Shown information may be incomplete or incorrect.\n\nIf an app stops to work, disable blocking.</string>
52 changes: 26 additions & 26 deletions app/src/main/res/xml-v21/preferences.xml
Original file line number Diff line number Diff line change
@@ -131,6 +131,32 @@
android:key="manage_system"
android:summary="@string/summary_system"
android:title="@string/setting_system" />
<Preference
android:key="hosts_import"
android:title="@string/setting_hosts" />
<Preference
android:key="hosts_import_append"
android:title="@string/setting_hosts_append" />
<EditTextPreference
android:defaultValue="https://www.netguard.me/hosts"
android:hint="https://www.netguard.me/hosts"
android:key="hosts_url"
android:title="@string/setting_hosts_url" />
<Preference
android:dependency="hosts_url"
android:key="hosts_download"
android:title="@string/setting_hosts_download" />
<eu.faircode.netguard.SwitchPreference
android:defaultValue="false"
android:dependency="filter"
android:key="use_hosts"
android:summary="@string/summary_block_domains"
android:title="@string/setting_block_domains" />
<EditTextPreference
android:dependency="filter"
android:inputType="number"
android:key="rcode"
android:summary="@string/summary_rcode" />
<eu.faircode.netguard.SwitchPreference
android:defaultValue="true"
android:key="log_app"
@@ -162,17 +188,6 @@
android:enabled="false"
android:key="reset_usage"
android:title="@string/setting_reset_usage" />
<eu.faircode.netguard.SwitchPreference
android:defaultValue="true"
android:dependency="filter"
android:key="use_hosts"
android:summary="@string/summary_block_domains"
android:title="@string/setting_block_domains" />
<EditTextPreference
android:dependency="filter"
android:inputType="number"
android:key="rcode"
android:summary="@string/summary_rcode" />
<EditTextPreference
inputType="phone"
android:hint="10.1.10.1"
@@ -254,21 +269,6 @@
<Preference
android:key="import"
android:title="@string/setting_import" />
<Preference
android:key="hosts_import"
android:title="@string/setting_hosts" />
<Preference
android:key="hosts_import_append"
android:title="@string/setting_hosts_append" />
<EditTextPreference
android:defaultValue="https://www.netguard.me/hosts"
android:hint="https://www.netguard.me/hosts"
android:key="hosts_url"
android:title="@string/setting_hosts_url" />
<Preference
android:dependency="hosts_url"
android:key="hosts_download"
android:title="@string/setting_hosts_download" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit bdaeebd

Please sign in to comment.