diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java index c0af71953..53ff89b0c 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.java @@ -75,6 +75,8 @@ import com.nextcloud.talk.models.json.rooms.RoomOverall; import com.nextcloud.talk.models.json.rooms.RoomsOverall; import com.nextcloud.talk.presenters.MentionAutocompletePresenter; import com.nextcloud.talk.utils.ApiUtils; +import com.nextcloud.talk.utils.DisplayUtils; +import com.nextcloud.talk.utils.KeyboardUtils; import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.glide.GlideApp; @@ -416,6 +418,10 @@ public class ChatController extends BaseController implements MessagesListAdapte if (mentionAutocomplete != null && mentionAutocomplete.isPopupShowing()) { mentionAutocomplete.dismissPopup(); } + + if (getActivity() != null) { + new KeyboardUtils(getActivity(), getView()); + } } @Override diff --git a/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java b/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java index 0e6e68e86..abd584987 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/KeyboardUtils.java @@ -18,7 +18,6 @@ package com.nextcloud.talk.utils; import android.app.Activity; import android.graphics.Rect; -import android.os.Build; import android.view.View; import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; @@ -42,19 +41,19 @@ public class KeyboardUtils { //get screen height and calculate the difference with the useable area from the r int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels; + int diff = height - r.bottom; - //if it could be a keyboard add the padding to the view - if (diff != 0) { + if (diff > 0) { // if the use-able screen height differs from the total screen height we assume that it shows a keyboard now //check if the padding is 0 (if yes set the padding for the keyboard) if (contentView.getPaddingBottom() != diff) { //set the padding of the contentView for the keyboard - contentView.setPadding(0, 0, 0, diff); + contentView.setPadding(0, 0, 0, diff); } } else { - //check if the padding is != 0 (if yes reset the padding) - if (contentView.getPaddingBottom() != 0) { + //check if the padding is != initialBottomPadding (if yes reset the padding) + if (contentView.getPaddingBottom() != 0) { //reset the padding of the contentView contentView.setPadding(0, 0, 0, 0); } @@ -66,10 +65,7 @@ public class KeyboardUtils { this.decorView = act.getWindow().getDecorView(); this.contentView = contentView; - //only required on newer android versions. it was working on API level 19 - if (Build.VERSION.SDK_INT >= 19) { - decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); - } + decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); } /** @@ -85,14 +81,10 @@ public class KeyboardUtils { } public void enable() { - if (Build.VERSION.SDK_INT >= 19) { - decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); - } + decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); } public void disable() { - if (Build.VERSION.SDK_INT >= 19) { - decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener); - } + decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener); } }