Commit 287fe196 authored by Aniket's avatar Aniket

fixes #648

parent d9f9adb6
...@@ -9,6 +9,7 @@ import android.support.v4.app.Fragment; ...@@ -9,6 +9,7 @@ import android.support.v4.app.Fragment;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.fragment.server_config.LoginFragment; import chat.rocket.android.fragment.server_config.LoginFragment;
import chat.rocket.android.fragment.server_config.RetryLoginFragment; import chat.rocket.android.fragment.server_config.RetryLoginFragment;
import chat.rocket.android.helper.BackStackHelper;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.core.interactors.SessionInteractor; import chat.rocket.core.interactors.SessionInteractor;
import chat.rocket.persistence.realm.repositories.RealmSessionRepository; import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
...@@ -93,10 +94,15 @@ public class LoginActivity extends AbstractFragmentActivity implements LoginCont ...@@ -93,10 +94,15 @@ public class LoginActivity extends AbstractFragmentActivity implements LoginCont
@Override @Override
protected boolean onBackPress() { protected boolean onBackPress() {
LoginFragment loginFragment = (LoginFragment) getSupportFragmentManager() if (BackStackHelper.FRAGMENT_TAG.equals("internal")) {
.findFragmentById(getLayoutContainerForFragment()); super.onBackPress();
Context loginActivityContext = this; BackStackHelper.FRAGMENT_TAG = "login";
loginFragment.goBack(loginActivityContext); } else if (BackStackHelper.FRAGMENT_TAG.equals("login")) {
LoginFragment loginFragment = (LoginFragment) getSupportFragmentManager()
.findFragmentById(getLayoutContainerForFragment());
Context loginActivityContext = this;
loginFragment.goBack(loginActivityContext);
}
return true; return true;
} }
} }
...@@ -6,39 +6,41 @@ import android.support.v4.app.Fragment; ...@@ -6,39 +6,41 @@ import android.support.v4.app.Fragment;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.fragment.AbstractFragment; import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.helper.BackStackHelper;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
public abstract class AbstractServerConfigFragment extends AbstractFragment { public abstract class AbstractServerConfigFragment extends AbstractFragment {
public static final String KEY_HOSTNAME = "hostname"; public static final String KEY_HOSTNAME = "hostname";
protected String hostname; protected String hostname;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle args = getArguments(); Bundle args = getArguments();
if (args == null) { if (args == null) {
finish(); finish();
return; return;
}
hostname = args.getString(KEY_HOSTNAME);
if (TextUtils.isEmpty(hostname)) {
finish();
}
} }
hostname = args.getString(KEY_HOSTNAME); protected void showFragment(Fragment fragment) {
if (TextUtils.isEmpty(hostname)) { getFragmentManager().beginTransaction()
finish(); .add(R.id.content, fragment)
.commit();
}
protected void showFragmentWithBackStack(Fragment fragment) {
BackStackHelper.FRAGMENT_TAG = "internal";
getFragmentManager().beginTransaction()
.add(R.id.content, fragment)
.addToBackStack(null)
.commit();
} }
}
protected void showFragment(Fragment fragment) {
getFragmentManager().beginTransaction()
.add(R.id.content, fragment)
.commit();
}
protected void showFragmentWithBackStack(Fragment fragment) {
getFragmentManager().beginTransaction()
.add(R.id.content, fragment)
.addToBackStack(null)
.commit();
}
} }
package chat.rocket.android.helper;
/**
* Created by whocares on 28/12/17.
*/
public class BackStackHelper {
public static String FRAGMENT_TAG = "login";
}
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