Commit 117d7489 authored by Nguyen Cong's avatar Nguyen Cong

fix lost text when turn off then turn on screen, hide keyboard when change room chat

parent 13837af2
...@@ -36,6 +36,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity { ...@@ -36,6 +36,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
if (savedInstanceState == null) { if (savedInstanceState == null) {
handleIntent(getIntent()); handleIntent(getIntent());
} }
ConnectivityManager.getInstance(getApplicationContext()).keepAliveServer();
updateHostnameIfNeeded(rocketChatCache.getSelectedServerHostname());
updateRoomIdIfNeeded(rocketChatCache.getSelectedRoomId());
} }
@Override @Override
...@@ -148,10 +152,6 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity { ...@@ -148,10 +152,6 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
ConnectivityManager.getInstance(getApplicationContext()).keepAliveServer();
updateHostnameIfNeeded(rocketChatCache.getSelectedServerHostname());
updateRoomIdIfNeeded(rocketChatCache.getSelectedRoomId());
subscribeToConfigChanges(); subscribeToConfigChanges();
} }
......
...@@ -15,6 +15,7 @@ import chat.rocket.android.api.MethodCallHelper; ...@@ -15,6 +15,7 @@ import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.fragment.chatroom.HomeFragment; import chat.rocket.android.fragment.chatroom.HomeFragment;
import chat.rocket.android.fragment.chatroom.RoomFragment; import chat.rocket.android.fragment.chatroom.RoomFragment;
import chat.rocket.android.fragment.sidebar.SidebarMainFragment; import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import chat.rocket.android.helper.KeyboardHelper;
import chat.rocket.core.interactors.CanCreateRoomInteractor; import chat.rocket.core.interactors.CanCreateRoomInteractor;
import chat.rocket.core.interactors.RoomInteractor; import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.interactors.SessionInteractor; import chat.rocket.core.interactors.SessionInteractor;
...@@ -51,7 +52,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -51,7 +52,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override @Override
protected void onPause() { protected void onPause() {
if (presenter != null) { if (presenter != null) {
presenter.release(); // presenter.release();
} }
super.onPause(); super.onPause();
...@@ -172,6 +173,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -172,6 +173,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
public void showRoom(String hostname, String roomId) { public void showRoom(String hostname, String roomId) {
showFragment(RoomFragment.create(hostname, roomId)); showFragment(RoomFragment.create(hostname, roomId));
closeSidebarIfNeeded(); closeSidebarIfNeeded();
//TODO: Hide keyboard
KeyboardHelper.hideSoftKeyboard(this);
} }
@Override @Override
......
package chat.rocket.android.helper;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
public class KeyboardHelper {
public static void hideSoftKeyboard(Activity activity) {
if (activity.getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
}
public static void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
public static void toggleKeyBoard(Context context) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment