mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 19:29:30 +00:00
No cell service hint during registration.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.thoughtcrime.securesms.registration.fragments;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -36,7 +38,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class EnterCodeFragment extends BaseRegistrationFragment {
|
||||
public final class EnterCodeFragment extends BaseRegistrationFragment
|
||||
implements SignalStrengthPhoneStateListener.Callback
|
||||
{
|
||||
|
||||
private static final String TAG = Log.tag(EnterCodeFragment.class);
|
||||
|
||||
@@ -47,8 +51,11 @@ public final class EnterCodeFragment extends BaseRegistrationFragment {
|
||||
private CallMeCountDownView callMeCountDown;
|
||||
private View wrongNumber;
|
||||
private View noCodeReceivedHelp;
|
||||
private View serviceWarning;
|
||||
private boolean autoCompleting;
|
||||
|
||||
private PhoneStateListener signalStrengthListener;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_registration_enter_code, container, false);
|
||||
@@ -67,6 +74,9 @@ public final class EnterCodeFragment extends BaseRegistrationFragment {
|
||||
callMeCountDown = view.findViewById(R.id.call_me_count_down);
|
||||
wrongNumber = view.findViewById(R.id.wrong_number);
|
||||
noCodeReceivedHelp = view.findViewById(R.id.no_code);
|
||||
serviceWarning = view.findViewById(R.id.cell_service_warning);
|
||||
|
||||
signalStrengthListener = new SignalStrengthPhoneStateListener(this, this);
|
||||
|
||||
connectKeyboard(verificationCodeView, keyboard);
|
||||
|
||||
@@ -319,4 +329,40 @@ public final class EnterCodeFragment extends BaseRegistrationFragment {
|
||||
getString(R.string.RegistrationActivity_code_support_subject),
|
||||
body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoCellSignalPresent() {
|
||||
if (serviceWarning.getVisibility() == View.VISIBLE) {
|
||||
return;
|
||||
}
|
||||
serviceWarning.setVisibility(View.VISIBLE);
|
||||
serviceWarning.animate()
|
||||
.alpha(1)
|
||||
.setListener(null)
|
||||
.start();
|
||||
|
||||
scrollView.postDelayed(() -> {
|
||||
if (serviceWarning.getVisibility() == View.VISIBLE) {
|
||||
scrollView.smoothScrollTo(0, serviceWarning.getBottom());
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCellSignalPresent() {
|
||||
if (serviceWarning.getVisibility() != View.VISIBLE) {
|
||||
return;
|
||||
}
|
||||
serviceWarning.animate()
|
||||
.alpha(0)
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override public void onAnimationEnd(Animator animation) {
|
||||
serviceWarning.setVisibility(View.GONE);
|
||||
}
|
||||
@Override public void onAnimationStart(Animator animation) {}
|
||||
@Override public void onAnimationCancel(Animator animation) {}
|
||||
@Override public void onAnimationRepeat(Animator animation) {}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,73 @@
|
||||
package org.thoughtcrime.securesms.registration.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.util.Debouncer;
|
||||
|
||||
final class SignalStrengthPhoneStateListener extends PhoneStateListener
|
||||
implements DefaultLifecycleObserver
|
||||
{
|
||||
private static final String TAG = Log.tag(SignalStrengthPhoneStateListener.class);
|
||||
|
||||
private final Callback callback;
|
||||
private final Debouncer debouncer = new Debouncer(1000);
|
||||
|
||||
SignalStrengthPhoneStateListener(@NonNull LifecycleOwner lifecycleOwner, @NonNull Callback callback) {
|
||||
this.callback = callback;
|
||||
|
||||
lifecycleOwner.getLifecycle().addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
||||
if (signalStrength == null) return;
|
||||
|
||||
if (isLowLevel(signalStrength)) {
|
||||
Log.w(TAG, "No cell signal detected");
|
||||
debouncer.publish(callback::onNoCellSignalPresent);
|
||||
} else {
|
||||
Log.i(TAG, "Cell signal detected");
|
||||
debouncer.clear();
|
||||
callback.onCellSignalPresent();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLowLevel(@NonNull SignalStrength signalStrength) {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
return signalStrength.getLevel() == 0;
|
||||
} else {
|
||||
//noinspection deprecation: False lint warning, deprecated by 29, but this else block is for < 23
|
||||
return signalStrength.getGsmSignalStrength() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
void onNoCellSignalPresent();
|
||||
|
||||
void onCellSignalPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(@NonNull LifecycleOwner owner) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) ApplicationDependencies.getApplication().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
telephonyManager.listen(this, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
||||
Log.i(TAG, "Listening to cell phone signal strength changes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(@NonNull LifecycleOwner owner) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) ApplicationDependencies.getApplication().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
telephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
||||
Log.i(TAG, "Stopped listening to cell phone signal strength changes");
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="14dp"
|
||||
android:height="14dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/core_ultramarine"
|
||||
android:pathData="M10.75,6h2.5l-0.5,7.5h-1.5ZM12,2.5A9.5,9.5 0,1 0,21.5 12,9.511 9.511,0 0,0 12,2.5M12,1A11,11 0,1 1,1 12,11 11,0 0,1 12,1ZM13.5,16.5A1.5,1.5 0,1 0,12 18,1.5 1.5,0 0,0 13.5,16.5Z"/>
|
||||
</vector>
|
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="8dp" />
|
||||
|
||||
<solid android:color="@color/core_grey_02" />
|
||||
</shape>
|
@@ -88,6 +88,48 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/verify_header" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/cell_service_warning"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:alpha="0"
|
||||
android:background="@drawable/registration_no_cell_service_warning_border"
|
||||
android:gravity="center"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="@string/RegistrationActivity_make_sure_your_phone_has_a_cellular_signal"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/no_code"
|
||||
tools:alpha="1"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:layout_margin="2dp"
|
||||
android:background="@drawable/ic_error_outline_14_ultramarine"
|
||||
android:importantForAccessibility="no" />
|
||||
|
||||
<TextView
|
||||
style="@style/Signal.Text.Body.Registration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/RegistrationActivity_make_sure_your_phone_has_a_cellular_signal"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/core_ultramarine"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
@@ -1509,6 +1509,7 @@
|
||||
<string name="RegistrationActivity_enter_your_phone_number_to_get_started">Enter your phone number to get started</string>
|
||||
<string name="RegistrationActivity_you_will_receive_a_verification_code">You will receive a verification code. Carrier rates may apply.</string>
|
||||
<string name="RegistrationActivity_enter_the_code_we_sent_to_s">Enter the code we sent to %s</string>
|
||||
<string name="RegistrationActivity_make_sure_your_phone_has_a_cellular_signal">Make sure your phone has a cellular signal to receive your SMS or call</string>
|
||||
|
||||
<string name="RegistrationActivity_phone_number_description">Phone number</string>
|
||||
<string name="RegistrationActivity_country_code_description">Country code</string>
|
||||
|
Reference in New Issue
Block a user