Scroll fragments down on small screens to make bottom buttons visible

This commit is contained in:
Torsten Grote
2022-02-10 09:46:43 -03:00
parent e9d3f600fa
commit 888aea4b37
2 changed files with 13 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.Toast;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
@@ -25,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider;
import static android.content.Intent.ACTION_SEND;
import static android.content.Intent.EXTRA_TEXT;
import static android.view.View.FOCUS_DOWN;
import static android.widget.Toast.LENGTH_LONG;
import static org.briarproject.briar.android.AppModule.getAndroidComponent;
@@ -40,6 +42,7 @@ public class SetupDownloadFragment extends Fragment {
private MailboxViewModel viewModel;
private CameraPermissionManager permissionManager;
private ScrollView scrollView;
private final ActivityResultLauncher<String[]> permissionLauncher =
registerForActivityResult(new RequestMultiplePermissions(), r -> {
@@ -65,6 +68,7 @@ public class SetupDownloadFragment extends Fragment {
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_mailbox_setup_download,
container, false);
scrollView = v.findViewById(R.id.scrollView);
permissionManager = new CameraPermissionManager(requireActivity(),
permissionLauncher::launch);
@@ -85,6 +89,8 @@ public class SetupDownloadFragment extends Fragment {
public void onStart() {
super.onStart();
requireActivity().setTitle(R.string.mailbox_setup_title);
// Scroll down in case the screen is small, so the button is visible
scrollView.post(() -> scrollView.fullScroll(FOCUS_DOWN));
// Permissions may have been granted manually while we were stopped
permissionManager.resetPermissions();
}

View File

@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ScrollView;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
@@ -14,6 +15,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import static android.view.View.FOCUS_DOWN;
import static org.briarproject.briar.android.util.UiUtils.showFragment;
@MethodsNotNullByDefault
@@ -22,6 +24,8 @@ public class SetupIntroFragment extends Fragment {
static final String TAG = SetupIntroFragment.class.getName();
private ScrollView scrollView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@@ -29,6 +33,7 @@ public class SetupIntroFragment extends Fragment {
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_mailbox_setup_intro,
container, false);
scrollView = v.findViewById(R.id.scrollView);
Button button = v.findViewById(R.id.continueButton);
button.setOnClickListener(view -> {
FragmentManager fm = getParentFragmentManager();
@@ -42,6 +47,8 @@ public class SetupIntroFragment extends Fragment {
public void onStart() {
super.onStart();
requireActivity().setTitle(R.string.mailbox_setup_title);
// Scroll down in case the screen is small, so the button is visible
scrollView.post(() -> scrollView.fullScroll(FOCUS_DOWN));
}
}