Fix layout bug in immersive mode

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-06-29 22:43:37 +02:00
Родитель da273a43fc
Коммит 3231d98f2c
2 изменённых файлов: 14 добавлений и 16 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}
}