Hide up/down speed when unsupported/zero

Refs #489
This commit is contained in:
M66B 2017-03-23 10:37:57 +01:00
parent 013adfc738
commit cb52caa8b1
2 changed files with 8 additions and 1 deletions

View File

@ -454,7 +454,10 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> im
holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE);
// Show traffic statistics
holder.tvStatistics.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? View.GONE : View.VISIBLE);
holder.tvStatistics.setVisibility(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ||
(rule.upspeed == 0 && rule.downspeed == 0)
? View.GONE : View.VISIBLE);
holder.tvStatistics.setText(context.getString(R.string.msg_mbday, rule.upspeed, rule.downspeed));
// Show related

View File

@ -410,6 +410,10 @@ public class Rule {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
long up = TrafficStats.getUidTxBytes(rule.info.applicationInfo.uid);
long down = TrafficStats.getUidRxBytes(rule.info.applicationInfo.uid);
if (up == TrafficStats.UNSUPPORTED)
up = 0;
if (down == TrafficStats.UNSUPPORTED)
down = 0;
rule.totalbytes = up + down;
rule.upspeed = (float) up * 24 * 3600 * 1000 / 1024f / 1024f / now;
rule.downspeed = (float) down * 24 * 3600 * 1000 / 1024f / 1024f / now;