@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.about_menu_option:
        Navigation.findNavController(requireView())
            .navigate(MainFragmentDirections.actionMainFragmentToAboutAnySoftKeyboardFragment());
        return true;
      case R.id.tweaks_menu_option:
        Navigation.findNavController(requireView())
            .navigate(MainFragmentDirections.actionMainFragmentToMainTweaksFragment());
        return true;
      case R.id.backup_prefs:
        mDialogController.showDialog(R.id.backup_prefs);
        return true;
      case R.id.restore_prefs:
        mDialogController.showDialog(R.id.restore_prefs);
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
@Test
  public void testCompleteOperation() throws Exception {
    final var shadowApplication = Shadows.shadowOf((Application) getApplicationContext());
    final MainFragment fragment = startFragment();
    final FragmentActivity activity = fragment.getActivity();

    fragment.onOptionsItemSelected(
        Shadows.shadowOf(activity).getOptionsMenu().findItem(R.id.backup_prefs));
    TestRxSchedulers.foregroundFlushAllJobs();

    Assert.assertNotSame(
        GeneralDialogTestUtil.NO_DIALOG, GeneralDialogTestUtil.getLatestShownDialog());

    Assert.assertTrue(
        GeneralDialogTestUtil.getLatestShownDialog()
            .getButton(DialogInterface.BUTTON_POSITIVE)
            .callOnClick());
    TestRxSchedulers.foregroundAdvanceBy(1);
    // this will open the System's file chooser
    ShadowActivity.IntentForResult fileRequest =
        shadowApplication.getNextStartedActivityForResult();
    Assert.assertNotNull(fileRequest);
    Assert.assertEquals(Intent.ACTION_CREATE_DOCUMENT, fileRequest.intent.getAction());
    final var backupFile = Files.createTempFile("ask-backup", ".xml");
    Shadows.shadowOf(activity.getContentResolver())
        .registerOutputStream(
            Uri.fromFile(backupFile.toFile()), new FileOutputStream(backupFile.toFile()));
    Intent resultData = new Intent();
    resultData.setData(Uri.fromFile(backupFile.toFile()));
    Shadows.shadowOf(activity).receiveResult(fileRequest.intent, Activity.RESULT_OK, resultData);
    TestRxSchedulers.drainAllTasks();
    // back up was done
    Assert.assertEquals(
        getApplicationContext().getText(R.string.prefs_providers_operation_success),
        GeneralDialogTestUtil.getTitleFromDialog(GeneralDialogTestUtil.getLatestShownDialog()));
    // verifying that progress-dialog was shown
    Assert.assertNotNull(
        TestRxSchedulers.blockingGet(
            Observable.fromIterable(ShadowDialog.getShownDialogs())
                .filter(dialog -> !dialog.isShowing())
                .filter(
                    dialog -> dialog.findViewById(R.id.progress_dialog_message_text_view) != null)
                .lastOrError()));
    // closing dialog
    Assert.assertTrue(
        GeneralDialogTestUtil.getLatestShownDialog()
            .getButton(DialogInterface.BUTTON_POSITIVE)
            .callOnClick());
    Assert.assertSame(
        GeneralDialogTestUtil.NO_DIALOG, GeneralDialogTestUtil.getLatestShownDialog());

    // good!
    ShadowDialog.getShownDialogs().clear();

    Shadows.shadowOf(activity.getContentResolver())
        .registerInputStream(
            Uri.fromFile(backupFile.toFile()), new FileInputStream(backupFile.toFile()));
    // now, restoring
    fragment.onOptionsItemSelected(
        Shadows.shadowOf(activity).getOptionsMenu().findItem(R.id.restore_prefs));
    TestRxSchedulers.foregroundFlushAllJobs();
    Assert.assertTrue(
        GeneralDialogTestUtil.getLatestShownDialog()
            .getButton(DialogInterface.BUTTON_POSITIVE)
            .callOnClick());
    TestRxSchedulers.foregroundAdvanceBy(1);
    // this will open the System's file chooser
    fileRequest = shadowApplication.getNextStartedActivityForResult();
    Assert.assertNotNull(fileRequest);
    Assert.assertEquals(Intent.ACTION_OPEN_DOCUMENT, fileRequest.intent.getAction());
    resultData = new Intent();
    resultData.setData(Uri.fromFile(backupFile.toFile()));
    Shadows.shadowOf(activity).receiveResult(fileRequest.intent, Activity.RESULT_OK, resultData);
    TestRxSchedulers.drainAllTasks();
    // back up was done
    Assert.assertEquals(
        getApplicationContext().getText(R.string.prefs_providers_operation_success),
        GeneralDialogTestUtil.getTitleFromDialog(GeneralDialogTestUtil.getLatestShownDialog()));
    // verifying that progress-dialog was shown
    Assert.assertNotNull(
        TestRxSchedulers.blockingGet(
            Observable.fromIterable(ShadowDialog.getShownDialogs())
                .filter(dialog -> !dialog.isShowing())
                .filter(
                    dialog -> dialog.findViewById(R.id.progress_dialog_message_text_view) != null)
                .lastOrError()));
    // closing dialog
    Assert.assertTrue(
        GeneralDialogTestUtil.getLatestShownDialog()
            .getButton(DialogInterface.BUTTON_POSITIVE)
            .callOnClick());
    Assert.assertSame(
        GeneralDialogTestUtil.NO_DIALOG, GeneralDialogTestUtil.getLatestShownDialog());
  }