Unverified Commit 8407c568 authored by Leonardo Aramaki's avatar Leonardo Aramaki Committed by GitHub

Merge pull request #634 from aniketsingh03/patch-1

[FIX] Dissmiss keyboard on clicking submit button in server url fragment
parents df81ef04 53378ec5
...@@ -6,6 +6,7 @@ import android.support.annotation.Nullable; ...@@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout; import android.support.constraint.ConstraintLayout;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView; import android.widget.TextView;
import chat.rocket.android.BuildConfig; import chat.rocket.android.BuildConfig;
...@@ -21,90 +22,99 @@ import chat.rocket.android.service.ConnectivityManager; ...@@ -21,90 +22,99 @@ import chat.rocket.android.service.ConnectivityManager;
*/ */
public class InputHostnameFragment extends AbstractFragment implements InputHostnameContract.View { public class InputHostnameFragment extends AbstractFragment implements InputHostnameContract.View {
private InputHostnameContract.Presenter presenter; private InputHostnameContract.Presenter presenter;
private ConstraintLayout container; private ConstraintLayout container;
private View waitingView; private View waitingView;
public InputHostnameFragment() {} public InputHostnameFragment() {
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) { @Override
super.onCreate(savedInstanceState); public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context appContext = getContext().getApplicationContext();
presenter = new InputHostnamePresenter(new RocketChatCache(appContext), ConnectivityManager.getInstance(appContext)); Context appContext = getContext().getApplicationContext();
} presenter = new InputHostnamePresenter(new RocketChatCache(appContext), ConnectivityManager.getInstance(appContext));
}
@Override
protected int getLayout() { @Override
return R.layout.fragment_input_hostname; protected int getLayout() {
} return R.layout.fragment_input_hostname;
}
@Override
protected void onSetupView() { @Override
setupVersionInfo(); protected void onSetupView() {
setupVersionInfo();
container = rootView.findViewById(R.id.container);
waitingView = rootView.findViewById(R.id.waiting); container = rootView.findViewById(R.id.container);
rootView.findViewById(R.id.btn_connect).setOnClickListener(view -> handleConnect()); waitingView = rootView.findViewById(R.id.waiting);
} rootView.findViewById(R.id.btn_connect).setOnClickListener(view -> handleConnect());
}
private void setupVersionInfo() {
TextView versionInfoView = (TextView) rootView.findViewById(R.id.version_info); private void setupVersionInfo() {
versionInfoView.setText(getString(R.string.version_info_text, BuildConfig.VERSION_NAME)); TextView versionInfoView = (TextView) rootView.findViewById(R.id.version_info);
} versionInfoView.setText(getString(R.string.version_info_text, BuildConfig.VERSION_NAME));
}
private void handleConnect() {
presenter.connectTo(getHostname()); private void handleConnect() {
} hideSoftKeyboard();
presenter.connectTo(getHostname());
@Override }
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); private void hideSoftKeyboard() {
presenter.bindView(this); InputMethodManager inputManager = (InputMethodManager)
} getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
@Override InputMethodManager.HIDE_NOT_ALWAYS);
public void onDestroyView() { }
presenter.release();
super.onDestroyView(); @Override
} public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
private String getHostname() { presenter.bindView(this);
final TextView editor = (TextView) rootView.findViewById(R.id.editor_hostname); }
return TextUtils.or(TextUtils.or(editor.getText(), editor.getHint()), "").toString().toLowerCase(); @Override
} public void onDestroyView() {
presenter.release();
private void showError(String errString) { super.onDestroyView();
Snackbar.make(rootView, errString, Snackbar.LENGTH_LONG).show(); }
}
private String getHostname() {
@Override final TextView editor = (TextView) rootView.findViewById(R.id.editor_hostname);
public void showLoader() {
container.setVisibility(View.GONE); return TextUtils.or(TextUtils.or(editor.getText(), editor.getHint()), "").toString().toLowerCase();
waitingView.setVisibility(View.VISIBLE); }
}
private void showError(String errString) {
@Override Snackbar.make(rootView, errString, Snackbar.LENGTH_LONG).show();
public void hideLoader() { }
waitingView.setVisibility(View.GONE);
container.setVisibility(View.VISIBLE); @Override
} public void showLoader() {
container.setVisibility(View.GONE);
@Override waitingView.setVisibility(View.VISIBLE);
public void showInvalidServerError() { }
showError(getString(R.string.input_hostname_invalid_server_message));
} @Override
public void hideLoader() {
@Override waitingView.setVisibility(View.GONE);
public void showConnectionError() { container.setVisibility(View.VISIBLE);
showError(getString(R.string.connection_error_try_later)); }
}
@Override
@Override public void showInvalidServerError() {
public void showHome() { showError(getString(R.string.input_hostname_invalid_server_message));
LaunchUtil.showMainActivity(getContext()); }
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
} @Override
public void showConnectionError() {
showError(getString(R.string.connection_error_try_later));
}
@Override
public void showHome() {
LaunchUtil.showMainActivity(getContext());
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
} }
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