Explicitly show connection type

pull/147/head
M66B 6 years ago
parent 0e74e4d801
commit 1435671aa0

@ -32,15 +32,13 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import java.io.IOException; import java.io.IOException;
@ -55,6 +53,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private SwitchCompat swEnabled; private SwitchCompat swEnabled;
private SwitchCompat swUpdates; private SwitchCompat swUpdates;
private TextView tvConnectionType;
private SwitchCompat swMetered; private SwitchCompat swMetered;
private Spinner spDownload; private Spinner spDownload;
@ -98,6 +97,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swEnabled = view.findViewById(R.id.swEnabled); swEnabled = view.findViewById(R.id.swEnabled);
swUpdates = view.findViewById(R.id.swUpdates); swUpdates = view.findViewById(R.id.swUpdates);
tvConnectionType = view.findViewById(R.id.tvConnectionType);
swMetered = view.findViewById(R.id.swMetered); swMetered = view.findViewById(R.id.swMetered);
spDownload = view.findViewById(R.id.spDownload); spDownload = view.findViewById(R.id.spDownload);
@ -411,8 +411,6 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest.Builder builder = new NetworkRequest.Builder(); NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
// Removed because of Android VPN service
// builder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
cm.registerNetworkCallback(builder.build(), networkCallback); cm.registerNetworkCallback(builder.build(), networkCallback);
} }
@ -427,39 +425,26 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override @Override
public void onAvailable(Network network) { public void onAvailable(Network network) {
getActivity().invalidateOptionsMenu(); showConnectionType();
} }
@Override @Override
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) { public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
getActivity().invalidateOptionsMenu(); showConnectionType();
} }
@Override @Override
public void onLost(Network network) { public void onLost(Network network) {
getActivity().invalidateOptionsMenu(); showConnectionType();
} }
}; };
@Override public void showConnectionType() {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_options, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
Boolean metered = Helper.isMetered(getContext(), false); Boolean metered = Helper.isMetered(getContext(), false);
MenuItem menuMetered = menu.findItem(R.id.menu_metered); tvConnectionType.setVisibility(metered == null ? View.GONE : View.VISIBLE);
menuMetered.setVisible(metered != null); if (metered != null)
if (metered != null) { tvConnectionType.setText(metered ? R.string.title_legend_metered : R.string.title_legend_unmetered);
menuMetered.setIcon(
metered ? R.drawable.baseline_attach_money_24 : R.drawable.baseline_money_off_24);
menuMetered.setTitle(
metered ? R.string.title_legend_metered : R.string.title_legend_unmetered);
}
super.onPrepareOptionsMenu(menu);
} }
@Override @Override

@ -638,48 +638,6 @@
app:layout_constraintStart_toEndOf="@id/ivClosing" app:layout_constraintStart_toEndOf="@id/ivClosing"
app:layout_constraintTop_toTopOf="@id/ivClosing" /> app:layout_constraintTop_toTopOf="@id/ivClosing" />
<ImageView
android:id="@+id/ivMetered"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="24dp"
android:src="@drawable/baseline_attach_money_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvClosing" />
<TextView
android:id="@+id/tvMetered"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:text="@string/title_legend_metered"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toBottomOf="@id/ivMetered"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivMetered"
app:layout_constraintTop_toTopOf="@id/ivMetered" />
<ImageView
android:id="@+id/ivUnmetered"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="24dp"
android:src="@drawable/baseline_money_off_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMetered" />
<TextView
android:id="@+id/tvUnmetered"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:text="@string/title_legend_unmetered"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toBottomOf="@id/ivUnmetered"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivUnmetered"
app:layout_constraintTop_toTopOf="@id/ivUnmetered" />
<TextView <TextView
android:id="@+id/tvDownloadFetch" android:id="@+id/tvDownloadFetch"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -690,7 +648,7 @@
android:textAppearance="@android:style/TextAppearance.Small" android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintBottom_toBottomOf="@+id/tvDownloadFetchLegend" app:layout_constraintBottom_toBottomOf="@+id/tvDownloadFetchLegend"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUnmetered" /> app:layout_constraintTop_toBottomOf="@id/tvClosing" />
<ImageView <ImageView
android:id="@+id/ivDownloadFetch" android:id="@+id/ivDownloadFetch"

@ -89,6 +89,20 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSectionConnection" /> app:layout_constraintTop_toBottomOf="@id/tvSectionConnection" />
<TextView
android:id="@+id/tvConnectionType"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="60dp"
android:text="Connection is unmetered"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorConnection" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swMetered" android:id="@+id/swMetered"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -98,7 +112,7 @@
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:text="@string/title_advanced_metered" android:text="@string/title_advanced_metered"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorConnection" app:layout_constraintTop_toBottomOf="@id/tvConnectionType"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<TextView <TextView

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_metered"
android:icon="@drawable/baseline_attach_money_24"
android:title=""
app:showAsAction="always" />
</menu>
Loading…
Cancel
Save