mirror of https://github.com/M66B/NetGuard.git
Ask if sure when clearing network usage, layout improvement
This commit is contained in:
parent
45fe542e91
commit
c464ec1ab5
|
@ -176,25 +176,30 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new AsyncTask<Object, Object, Throwable>() {
|
||||
Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() {
|
||||
@Override
|
||||
protected Throwable doInBackground(Object... objects) {
|
||||
try {
|
||||
DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1);
|
||||
return null;
|
||||
} catch (Throwable ex) {
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
public void onSure() {
|
||||
new AsyncTask<Object, Object, Throwable>() {
|
||||
@Override
|
||||
protected Throwable doInBackground(Object... objects) {
|
||||
try {
|
||||
DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1);
|
||||
return null;
|
||||
} catch (Throwable ex) {
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Throwable ex) {
|
||||
if (ex == null)
|
||||
Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
@Override
|
||||
protected void onPostExecute(Throwable ex) {
|
||||
if (ex == null)
|
||||
Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}.execute();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -32,6 +32,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
@ -109,6 +110,8 @@ public class AdapterAccess extends CursorAdapter {
|
|||
TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
|
||||
ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
|
||||
final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
|
||||
LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic);
|
||||
TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections);
|
||||
TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic);
|
||||
|
||||
// Set values
|
||||
|
@ -160,21 +163,21 @@ public class AdapterAccess extends CursorAdapter {
|
|||
else
|
||||
tvDest.setTextColor(colorOff);
|
||||
|
||||
tvTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('#').append(connections).append(' ');
|
||||
llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
|
||||
if (connections > 0)
|
||||
tvConnections.setText(context.getString(R.string.msg_count, connections));
|
||||
|
||||
if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
|
||||
sb.append(context.getString(R.string.msg_gb,
|
||||
tvTraffic.setText(context.getString(R.string.msg_gb,
|
||||
(sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
|
||||
(received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
|
||||
else if (sent > 1204 * 1024L || received > 1024 * 1024L)
|
||||
sb.append(context.getString(R.string.msg_mb,
|
||||
tvTraffic.setText(context.getString(R.string.msg_mb,
|
||||
(sent > 0 ? sent / (1024 * 1024f) : 0),
|
||||
(received > 0 ? received / (1024 * 1024f) : 0)));
|
||||
else
|
||||
sb.append(context.getString(R.string.msg_kb,
|
||||
tvTraffic.setText(context.getString(R.string.msg_kb,
|
||||
(sent > 0 ? sent / 1024f : 0),
|
||||
(received > 0 ? received / 1024f : 0)));
|
||||
tvTraffic.setText(sb.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -625,6 +625,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
ContentValues cv = new ContentValues();
|
||||
cv.putNull("sent");
|
||||
cv.putNull("received");
|
||||
cv.putNull("connections");
|
||||
db.update("access", cv,
|
||||
(uid < 0 ? null : "uid = ?"),
|
||||
(uid < 0 ? null : new String[]{Integer.toString(uid)}));
|
||||
|
|
|
@ -34,14 +34,32 @@
|
|||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTraffic"
|
||||
<LinearLayout
|
||||
android:id="@+id/llTraffic"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end|right"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextSmall"
|
||||
android:textSize="10sp"
|
||||
android:typeface="monospace" />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvConnections"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextSmall"
|
||||
android:textSize="10sp"
|
||||
android:typeface="monospace" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTraffic"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextSmall"
|
||||
android:textSize="10sp"
|
||||
android:typeface="monospace" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -264,7 +264,7 @@
|
|||
android:text="@string/title_host_blocked"
|
||||
android:textAppearance="@style/TextMedium" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -153,6 +153,7 @@ Your internet traffic is not being sent to a remote VPN server.</string>
|
|||
<string name="msg_kb">%1$7.3f▲ %2$7.3f▼ KB</string>
|
||||
<string name="msg_mb">%1$7.3f▲ %2$7.3f▼ MB</string>
|
||||
<string name="msg_gb">%1$7.3f▲ %2$7.3f▼ GB</string>
|
||||
<string name="msg_count">%dx</string>
|
||||
<string name="msg_filter">Using filtering will cause Android to attribute data and power usage to NetGuard - Android assumes the data and power are being used by NetGuard, rather than the original applications</string>
|
||||
<string name="msg_log_disabled">Traffic logging is disabled, use the switch above to enable logging. Traffic logging might result in extra battery usage.</string>
|
||||
<string name="msg_clear_rules">This will reset the rules and conditions to their default values</string>
|
||||
|
|
Loading…
Reference in New Issue