Commit 59049f54 authored by Yusuke Iwaki's avatar Yusuke Iwaki

Stop using raw string "hostname" passing directly to param for Activity/Fragment

parent 38486d85
......@@ -36,7 +36,7 @@ public class LaunchUtil {
public static void showLoginActivity(Context context, String hostname) {
Intent intent = new Intent(context, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("hostname", hostname);
intent.putExtra(LoginActivity.KEY_HOSTNAME, hostname);
context.startActivity(intent);
}
}
......@@ -18,6 +18,7 @@ import chat.rocket.android.service.ConnectivityManager;
* Activity for Login, Sign-up, and Retry connecting...
*/
public class LoginActivity extends AbstractFragmentActivity {
public static final String KEY_HOSTNAME = "hostname";
private String hostname;
private RealmObjectObserver<Session> sessionObserver;
......@@ -37,7 +38,7 @@ public class LoginActivity extends AbstractFragmentActivity {
return;
}
hostname = intent.getStringExtra("hostname");
hostname = intent.getStringExtra(KEY_HOSTNAME);
if (TextUtils.isEmpty(hostname)) {
finish();
return;
......@@ -98,7 +99,7 @@ public class LoginActivity extends AbstractFragmentActivity {
if (args == null) {
args = new Bundle();
}
args.putString("hostname", hostname);
args.putString(LoginActivity.KEY_HOSTNAME, hostname);
fragment.setArguments(args);
}
......
......@@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import chat.rocket.android.R;
import chat.rocket.android.activity.LoginActivity;
import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.helper.TextUtils;
......@@ -21,7 +22,7 @@ abstract class AbstractServerConfigFragment extends AbstractFragment {
return;
}
hostname = args.getString("hostname");
hostname = args.getString(LoginActivity.KEY_HOSTNAME);
if (TextUtils.isEmpty(hostname)) {
finish();
return;
......
......@@ -179,11 +179,11 @@ public class SidebarMainFragment extends AbstractFragment {
private void setupAddChannelButton() {
rootView.findViewById(R.id.btn_add_channel).setOnClickListener(view -> {
showAddRoomDialog(new AddChannelDialogFragment());
showAddRoomDialog(AddChannelDialogFragment.create(hostname));
});
rootView.findViewById(R.id.btn_add_direct_message).setOnClickListener(view -> {
showAddRoomDialog(new AddDirectMessageDialogFragment());
showAddRoomDialog(AddDirectMessageDialogFragment.create(hostname));
});
}
......@@ -193,9 +193,6 @@ public class SidebarMainFragment extends AbstractFragment {
}
private void showAddRoomDialog(DialogFragment dialog) {
Bundle args = new Bundle();
args.putString("hostname", hostname);
dialog.setArguments(args);
dialog.show(getFragmentManager(), AbstractAddRoomDialogFragment.class.getSimpleName());
}
......
......@@ -21,9 +21,7 @@ public abstract class AbstractAddRoomDialogFragment extends RxAppCompatDialogFra
protected MethodCallHelper methodCall;
protected String hostname;
protected
@LayoutRes
abstract int getLayout();
protected @LayoutRes abstract int getLayout();
protected abstract void onSetupDialog();
......
package chat.rocket.android.fragment.sidebar.dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;
......@@ -17,6 +18,15 @@ public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment {
public AddChannelDialogFragment() {
}
public static AddChannelDialogFragment create(String hostname) {
Bundle args = new Bundle();
args.putString("hostname", hostname);
AddChannelDialogFragment fragment = new AddChannelDialogFragment();
fragment.setArguments(args);
return fragment;
}
@Override
protected int getLayout() {
return R.layout.dialog_add_channel;
......
package chat.rocket.android.fragment.sidebar.dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
......@@ -18,7 +19,13 @@ import chat.rocket.android.realm_helper.RealmAutoCompleteAdapter;
* add Direct Message.
*/
public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragment {
public AddDirectMessageDialogFragment() {
public static AddDirectMessageDialogFragment create(String hostname) {
Bundle args = new Bundle();
args.putString("hostname", hostname);
AddDirectMessageDialogFragment fragment = new AddDirectMessageDialogFragment();
fragment.setArguments(args);
return fragment;
}
@Override
......
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