Skip to content

Commit

Permalink
Update: Issue nextcloud#1259, Dismiss keyboard after changing the not…
Browse files Browse the repository at this point in the history
…e title
  • Loading branch information
ScottieKim authored and AndyScherzinger committed Jan 21, 2024
1 parent b0248e6 commit f70ff8a
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -60,12 +63,25 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
return new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.change_note_title)
.setView(dialogView)
.setCancelable(true)
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString()))
.setNegativeButton(R.string.simple_cancel, null)
.setCancelable(false)
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> {
hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken());
listener.onTitleEdited(binding.title.getText().toString());
})
.setNegativeButton(R.string.simple_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken());
}
})
.create();
}

private void hideKeyboard(IBinder windowToken) {
InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Expand Down

0 comments on commit f70ff8a

Please sign in to comment.