Added airplane mode warning

This commit is contained in:
M66B 2022-04-22 08:42:32 +02:00
parent fde0e11769
commit d910d78e6d
4 changed files with 75 additions and 1 deletions

View File

@ -255,6 +255,7 @@ import me.everything.android.ui.overscroll.adapters.RecyclerViewOverScrollDecorA
public class FragmentMessages extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private ViewGroup view;
private SwipeRefreshLayoutEx swipeRefresh;
private TextView tvAirplane;
private TextView tvSupport;
private ImageButton ibHintSupport;
private ImageButton ibHintSwipe;
@ -276,6 +277,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private TextViewAutoCompleteAction etSearch;
private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait;
private Group grpAirplane;
private Group grpSupport;
private Group grpHintSupport;
private Group grpHintSwipe;
@ -512,6 +514,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
// Get controls
swipeRefresh = view.findViewById(R.id.swipeRefresh);
tvAirplane = view.findViewById(R.id.tvAirplane);
tvSupport = view.findViewById(R.id.tvSupport);
ibHintSupport = view.findViewById(R.id.ibHintSupport);
ibHintSwipe = view.findViewById(R.id.ibHintSwipe);
@ -534,6 +537,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
grpAirplane = view.findViewById(R.id.grpAirplane);
grpSupport = view.findViewById(R.id.grpSupport);
grpHintSupport = view.findViewById(R.id.grpHintSupport);
grpHintSwipe = view.findViewById(R.id.grpHintSwipe);
@ -565,6 +569,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
});
grpAirplane.setVisibility(View.GONE);
tvAirplane.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
v.getContext().startActivity(intent);
}
});
grpSupport.setVisibility(View.GONE);
tvSupport.setOnClickListener(new View.OnClickListener() {
@Override
@ -4396,6 +4410,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
cm.registerNetworkCallback(builder.build(), networkCallback);
updateAirplaneMode(ConnectionHelper.airplaneMode(getContext()));
getContext().registerReceiver(airplanemode, new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean compact = prefs.getBoolean("compact", false);
int zoom = prefs.getInt("view_zoom", compact ? 0 : 1);
@ -4455,6 +4472,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.unregisterOnSharedPreferenceChangeListener(this);
getContext().unregisterReceiver(airplanemode);
ConnectivityManager cm = Helper.getSystemService(getContext(), ConnectivityManager.class);
cm.unregisterNetworkCallback(networkCallback);
@ -4497,11 +4516,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return;
if (!rvMessage.isComputingLayout())
adapter.checkInternet();
updateAirplaneMode(ConnectionHelper.airplaneMode(getContext()));
}
});
}
};
private BroadcastReceiver airplanemode = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
boolean on = intent.getBooleanExtra("state", false);
updateAirplaneMode(on);
}
};
private void updateAirplaneMode(boolean on) {
on = on && !ConnectionHelper.getNetworkState(getContext()).isConnected();
grpAirplane.setVisibility(on ? View.VISIBLE : View.GONE);
}
private boolean checkDoze() {
if (viewType != AdapterMessage.ViewType.UNIFIED)
return false;

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M10,19l-2,1.5V22l3.5,-1 3.5,1v-1.5L13,19v-5.5l8,2.5v-2l-8,-5V3.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,2.67 10,3.5V9l-8,5v2l8,-2.5V19z"/>
</vector>

View File

@ -16,6 +16,30 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<eu.faircode.email.FixedTextView
android:id="@+id/tvAirplane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:drawableStart="@drawable/twotone_flight_24"
android:drawablePadding="6dp"
android:drawableTint="?android:attr/textColorPrimary"
android:padding="6dp"
android:text="@string/title_hint_airplane"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/vSeparatorAirplane"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAirplane" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSupport"
android:layout_width="wrap_content"
@ -26,7 +50,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/vSeparatorAirplane" />
<View
android:id="@+id/vSeparatorSupport"
@ -399,6 +423,12 @@
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/action_messages" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAirplane"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvAirplane,vSeparatorAirplane" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpSupport"
android:layout_width="0dp"

View File

@ -1778,6 +1778,7 @@
<string name="title_hint_folder_actions">Long press a folder for options, like adding a folder to the navigation menu for quick access</string>
<string name="title_hint_folder_sync">To limit battery and network usage not all folders and not all messages will be synchronized by default</string>
<string name="title_hint_airplane">Airplane mode is on</string>
<string name="title_hint_support">If you have a question or a problem, please use the support menu to get help</string>
<string name="title_hint_message_actions">Swipe left to trash; Swipe right to archive (if available); The swipe actions can be configured in the account settings</string>
<string name="title_hint_message_selection">Long press a message to start selecting multiple messages; Hold and swipe up or down to select more messages</string>