diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-09 12:36:47 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-09 12:36:47 -0600 |
commit | 2e55e5fd051278a949d698f84580bef12c9324d8 (patch) | |
tree | f3a2f33b3af02d8f72dc03034841835a60d01266 /ui/src/main/java/com/wireguard/android/fragment | |
parent | 40ebf8006e46f8857340648d7cea234ed699aed7 (diff) |
global: format code
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/fragment')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java | 68 | ||||
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java | 16 |
2 files changed, 42 insertions, 42 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java index 762efc5d..e2adecc3 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java @@ -34,8 +34,20 @@ import androidx.databinding.DataBindingUtil; @NonNullForAll public class TunnelDetailFragment extends BaseFragment { @Nullable private TunnelDetailFragmentBinding binding; - @Nullable private Timer timer; @Nullable private State lastState = State.TOGGLE; + @Nullable private Timer timer; + + private String formatBytes(final long bytes) { + if (bytes < 1024) + return requireContext().getString(R.string.transfer_bytes, bytes); + else if (bytes < 1024 * 1024) + return requireContext().getString(R.string.transfer_kibibytes, bytes / 1024.0); + else if (bytes < 1024 * 1024 * 1024) + return requireContext().getString(R.string.transfer_mibibytes, bytes / (1024.0 * 1024.0)); + else if (bytes < 1024 * 1024 * 1024 * 1024) + return requireContext().getString(R.string.transfer_gibibytes, bytes / (1024.0 * 1024.0 * 1024.0)); + return requireContext().getString(R.string.transfer_tibibytes, bytes / (1024.0 * 1024.0 * 1024.0) / 1024.0); + } @Override public void onCreate(@Nullable final Bundle savedInstanceState) { @@ -49,27 +61,6 @@ public class TunnelDetailFragment extends BaseFragment { } @Override - public void onStop() { - super.onStop(); - if (timer != null) { - timer.cancel(); - timer = null; - } - } - - @Override - public void onResume() { - super.onResume(); - timer = new Timer(); - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - updateStats(); - } - }, 0, 1000); - } - - @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); @@ -87,6 +78,18 @@ public class TunnelDetailFragment extends BaseFragment { } @Override + public void onResume() { + super.onResume(); + timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + updateStats(); + } + }, 0, 1000); + } + + @Override public void onSelectedTunnelChanged(@Nullable final ObservableTunnel oldTunnel, @Nullable final ObservableTunnel newTunnel) { if (binding == null) return; @@ -100,6 +103,15 @@ public class TunnelDetailFragment extends BaseFragment { } @Override + public void onStop() { + super.onStop(); + if (timer != null) { + timer.cancel(); + timer = null; + } + } + + @Override public void onViewStateRestored(@Nullable final Bundle savedInstanceState) { if (binding == null) { return; @@ -110,18 +122,6 @@ public class TunnelDetailFragment extends BaseFragment { super.onViewStateRestored(savedInstanceState); } - private String formatBytes(final long bytes) { - if (bytes < 1024) - return requireContext().getString(R.string.transfer_bytes, bytes); - else if (bytes < 1024*1024) - return requireContext().getString(R.string.transfer_kibibytes, bytes/1024.0); - else if (bytes < 1024*1024*1024) - return requireContext().getString(R.string.transfer_mibibytes, bytes/(1024.0*1024.0)); - else if (bytes < 1024*1024*1024*1024) - return requireContext().getString(R.string.transfer_gibibytes, bytes/(1024.0*1024.0*1024.0)); - return requireContext().getString(R.string.transfer_tibibytes, bytes/(1024.0*1024.0*1024.0)/1024.0); - } - private void updateStats() { if (binding == null || !isResumed()) return; diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java index 995a2d59..7ed82f1f 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -262,14 +262,6 @@ public class TunnelListFragment extends BaseFragment { }); } - private void showSnackbar(final CharSequence message) { - if (binding != null) { - final Snackbar snackbar = Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG); - snackbar.setAnchorView(binding.createFab); - snackbar.show(); - } - } - private void onTunnelDeletionFinished(final Integer count, @Nullable final Throwable throwable) { final String message; if (throwable == null) { @@ -337,6 +329,14 @@ public class TunnelListFragment extends BaseFragment { }); } + private void showSnackbar(final CharSequence message) { + if (binding != null) { + final Snackbar snackbar = Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG); + snackbar.setAnchorView(binding.createFab); + snackbar.show(); + } + } + private MultiselectableRelativeLayout viewForTunnel(final ObservableTunnel tunnel, final List tunnels) { return (MultiselectableRelativeLayout) binding.tunnelList.findViewHolderForAdapterPosition(tunnels.indexOf(tunnel)).itemView; } |