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