Make OfflineFragment suitable for small screens.

This commit is contained in:
akwizgran
2022-11-30 10:44:39 +00:00
parent bd430a1009
commit 1911b3dd97
2 changed files with 72 additions and 78 deletions

View File

@@ -16,13 +16,12 @@ import org.briarproject.nullsafety.ParametersNotNullByDefault;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import static android.view.View.FOCUS_DOWN;
import static org.briarproject.briar.android.AppModule.getAndroidComponent; import static org.briarproject.briar.android.AppModule.getAndroidComponent;
import static org.briarproject.briar.android.util.UiUtils.hideViewOnSmallScreen;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -35,8 +34,6 @@ public class OfflineFragment extends Fragment {
protected MailboxViewModel viewModel; protected MailboxViewModel viewModel;
private NestedScrollView scrollView;
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
@@ -54,7 +51,6 @@ public class OfflineFragment extends Fragment {
View v = inflater View v = inflater
.inflate(R.layout.fragment_offline, container, false); .inflate(R.layout.fragment_offline, container, false);
scrollView = (NestedScrollView) v;
Button checkButton = v.findViewById(R.id.checkButton); Button checkButton = v.findViewById(R.id.checkButton);
checkButton.setOnClickListener(view -> { checkButton.setOnClickListener(view -> {
Intent i = new Intent(requireContext(), TransportsActivity.class); Intent i = new Intent(requireContext(), TransportsActivity.class);
@@ -69,8 +65,7 @@ public class OfflineFragment extends Fragment {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// Scroll down in case the screen is small, so the button is visible hideViewOnSmallScreen(requireView().findViewById(R.id.iconView));
scrollView.post(() -> scrollView.fullScroll(FOCUS_DOWN));
} }
protected void onTryAgainClicked() { protected void onTryAgainClicked() {

View File

@@ -1,10 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fillViewport="true"> android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -44,40 +49,34 @@
android:id="@+id/textView" android:id="@+id/textView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_large"
android:layout_marginHorizontal="@dimen/margin_xlarge" android:layout_marginHorizontal="@dimen/margin_xlarge"
android:layout_marginTop="@dimen/margin_xlarge"
android:layout_marginBottom="@dimen/margin_large"
android:text="@string/tor_offline_description" android:text="@string/tor_offline_description"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
app:layout_constraintBottom_toTopOf="@+id/checkButton" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/titleView" /> app:layout_constraintTop_toBottomOf="@+id/titleView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<Button <Button
android:id="@+id/checkButton" android:id="@+id/checkButton"
style="@style/BriarButtonOutline.Neutral" style="@style/BriarButtonOutline.Neutral"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp" android:text="@string/tor_offline_button_check" />
android:text="@string/tor_offline_button_check"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button <Button
android:id="@+id/button" android:id="@+id/button"
style="@style/BriarButton" style="@style/BriarButton"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_large" android:layout_marginHorizontal="16dp"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:text="@string/try_again_button" android:text="@string/try_again_button" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView>