mirror of https://github.com/M66B/NetGuard.git
Swipe to refresh
This commit is contained in:
parent
c84d8b262c
commit
37b765aff6
|
@ -10,6 +10,7 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Uri;
|
||||
import android.net.VpnService;
|
||||
|
@ -19,6 +20,7 @@ import android.preference.PreferenceManager;
|
|||
import android.provider.Settings;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
@ -47,6 +49,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
private static final String TAG = "NetGuard.Main";
|
||||
|
||||
private boolean running = false;
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private RuleAdapter adapter = null;
|
||||
private MenuItem menuSearch = null;
|
||||
private MenuItem menuNetwork = null;
|
||||
|
@ -77,10 +80,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
||||
getSupportActionBar().setCustomView(view);
|
||||
|
||||
// Disabled warning
|
||||
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
|
||||
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
|
||||
|
||||
// On/off switch
|
||||
SwitchCompat swEnabled = (SwitchCompat) view.findViewById(R.id.swEnabled);
|
||||
swEnabled.setChecked(enabled);
|
||||
|
@ -110,11 +109,33 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
}
|
||||
});
|
||||
|
||||
// Listen for preference changes
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
// Disabled warning
|
||||
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
|
||||
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
|
||||
|
||||
// Application list
|
||||
RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
|
||||
rvApplication.setHasFixedSize(true);
|
||||
rvApplication.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new RuleAdapter(ActivityMain.this);
|
||||
rvApplication.setAdapter(adapter);
|
||||
|
||||
// Fill application list
|
||||
fillApplicationList();
|
||||
updateApplicationList();
|
||||
|
||||
// Refresh application list
|
||||
swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
|
||||
swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
|
||||
swipeRefresh.setProgressBackgroundColorSchemeResource(R.color.colorPrimary);
|
||||
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
updateApplicationList();
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for preference changes
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
// Listen for connectivity updates
|
||||
IntentFilter ifConnectivity = new IntentFilter();
|
||||
|
@ -164,7 +185,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "Received " + intent);
|
||||
Util.logExtras(TAG, intent);
|
||||
fillApplicationList();
|
||||
updateApplicationList();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -182,11 +203,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
}
|
||||
};
|
||||
|
||||
private void fillApplicationList() {
|
||||
// Get recycler view
|
||||
final RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
|
||||
rvApplication.setHasFixedSize(true);
|
||||
rvApplication.setLayoutManager(new LinearLayoutManager(this));
|
||||
private void updateApplicationList() {
|
||||
|
||||
// Get/set application list
|
||||
new AsyncTask<Object, Object, List<Rule>>() {
|
||||
|
@ -200,8 +217,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
if (running) {
|
||||
if (menuSearch != null)
|
||||
MenuItemCompat.collapseActionView(menuSearch);
|
||||
adapter = new RuleAdapter(result, ActivityMain.this);
|
||||
rvApplication.setAdapter(adapter);
|
||||
if (adapter != null) {
|
||||
adapter.clear();
|
||||
adapter.addAll(result);
|
||||
}
|
||||
if (swipeRefresh != null)
|
||||
swipeRefresh.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
|
@ -289,10 +310,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
menu_network();
|
||||
return true;
|
||||
|
||||
case R.id.menu_refresh:
|
||||
fillApplicationList();
|
||||
return true;
|
||||
|
||||
case R.id.menu_whitelist_wifi:
|
||||
menu_whitelist_wifi(prefs);
|
||||
return true;
|
||||
|
@ -333,13 +350,13 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
|
||||
private void menu_whitelist_wifi(SharedPreferences prefs) {
|
||||
prefs.edit().putBoolean("whitelist_wifi", !prefs.getBoolean("whitelist_wifi", true)).apply();
|
||||
fillApplicationList();
|
||||
updateApplicationList();
|
||||
SinkholeService.reload("wifi", this);
|
||||
}
|
||||
|
||||
private void menu_whitelist_other(SharedPreferences prefs) {
|
||||
prefs.edit().putBoolean("whitelist_other", !prefs.getBoolean("whitelist_other", true)).apply();
|
||||
fillApplicationList();
|
||||
updateApplicationList();
|
||||
SinkholeService.reload("other", this);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
private Context context;
|
||||
private int colorText;
|
||||
private int colorAccent;
|
||||
private List<Rule> listAll;
|
||||
private List<Rule> listSelected;
|
||||
private List<Rule> listAll = new ArrayList<>();
|
||||
private List<Rule> listSelected = new ArrayList<>();
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public View view;
|
||||
|
@ -67,7 +67,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
}
|
||||
}
|
||||
|
||||
public RuleAdapter(List<Rule> listRule, Context context) {
|
||||
public RuleAdapter(Context context) {
|
||||
this.context = context;
|
||||
colorAccent = ContextCompat.getColor(context, R.color.colorAccent);
|
||||
TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary});
|
||||
|
@ -76,9 +76,19 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
} finally {
|
||||
ta.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
listAll.clear();
|
||||
listSelected.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addAll(List<Rule> listRule) {
|
||||
listAll = listRule;
|
||||
listSelected = new ArrayList<>();
|
||||
listSelected.addAll(listRule);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,10 +21,16 @@
|
|||
android:textColor="@color/colorAccent"
|
||||
android:visibility="gone" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/rvApplication"
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarStyle="outsideInset"
|
||||
android:scrollbars="vertical" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/rvApplication"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarStyle="outsideInset"
|
||||
android:scrollbars="vertical" />
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
android:id="@+id/menu_network"
|
||||
android:title="@string/menu_network"
|
||||
netguard:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/menu_refresh"
|
||||
android:title="@string/menu_refresh" />
|
||||
<item
|
||||
android:id="@+id/menu_whitelist_wifi"
|
||||
android:checkable="true"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">البحث عن تطبيقات</string>
|
||||
<string name="menu_network">فتح إعدادات الشبكة</string>
|
||||
<string name="menu_refresh">تحديث التطبيقات</string>
|
||||
<string name="menu_whitelist_wifi">حظر الواي فاي بشكل افتراضي</string>
|
||||
<string name="menu_whitelist_other">حظر الشبكة بشكل افتراضي</string>
|
||||
<string name="menu_dark">استخدام الثيم الداكن</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">Recherche application</string>
|
||||
<string name="menu_network">Ouvrir les paramètres réseaux</string>
|
||||
<string name="menu_refresh">Actualiser les applications</string>
|
||||
<string name="menu_whitelist_wifi">Blocage Wi-Fi par défaut</string>
|
||||
<string name="menu_whitelist_other">Blocage données mobiles par défaut</string>
|
||||
<string name="menu_dark">Utiliser le thème sombre</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">Cerca applicazione</string>
|
||||
<string name="menu_network">Apri impostazioni di rete</string>
|
||||
<string name="menu_refresh">Aggiorna la lista</string>
|
||||
<string name="menu_whitelist_wifi">Blocca Wi-Fi di default</string>
|
||||
<string name="menu_whitelist_other">Block rete di dati di default</string>
|
||||
<string name="menu_dark">Usa il tema scuro</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">Zoek naar applicatie</string>
|
||||
<string name="menu_network">Open netwerkinstellingen</string>
|
||||
<string name="menu_refresh">Ververs applicatielijst</string>
|
||||
<string name="menu_whitelist_wifi">Blokkeer Wi-Fi standaard</string>
|
||||
<string name="menu_whitelist_other">Blokkeer mobiel standaard</string>
|
||||
<string name="menu_dark">Gebruik donker thema</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">Cauta aplicatii</string>
|
||||
<string name="menu_network">Deschide setari retea</string>
|
||||
<string name="menu_refresh">Actualizeaza lista de aplicatii</string>
|
||||
<string name="menu_whitelist_wifi">Blocheaza implicit Wi-Fi</string>
|
||||
<string name="menu_whitelist_other">Blocheaza implicit date mobile</string>
|
||||
<string name="menu_dark">Foloseste tema intunecata</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">Hľadať aplikáciu</string>
|
||||
<string name="menu_network">Otvoriť nastavenia sietí</string>
|
||||
<string name="menu_refresh">Obnoviť zoznam aplikácií</string>
|
||||
<string name="menu_whitelist_wifi">Predvolene blokovať Wi-Fi</string>
|
||||
<string name="menu_whitelist_other">Predvolene blokovať mobilné dáta</string>
|
||||
<string name="menu_dark">Použiť tmavú tému</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<string name="menu_search">搜索应用</string>
|
||||
<string name="menu_network">打开网络设置</string>
|
||||
<string name="menu_refresh">刷新应用列表</string>
|
||||
<string name="menu_whitelist_wifi">默认阻止Wi-Fi网络</string>
|
||||
<string name="menu_whitelist_other">默认阻止移动网络</string>
|
||||
<string name="menu_dark">使用暗色主题</string>
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
<string name="menu_search">Search for application</string>
|
||||
<string name="menu_network">Open network settings</string>
|
||||
<string name="menu_refresh">Refresh application list</string>
|
||||
<string name="menu_whitelist_wifi">Block Wi-Fi by default</string>
|
||||
<string name="menu_whitelist_other">Block mobile by default</string>
|
||||
<string name="menu_dark">Use dark theme</string>
|
||||
|
|
Loading…
Reference in New Issue