use of org.prebid.mobile.drprebid.managers.SettingsManager in project prebid-mobile-android by prebid.
the class InputDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (getActivity() != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
if (getArguments() != null && getArguments().containsKey(Constants.Params.INPUT_TITLE)) {
String title = getArguments().getString(Constants.Params.INPUT_TITLE);
builder.setTitle(title);
}
final View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_input, null, false);
builder.setView(view);
mInput = view.findViewById(R.id.field_input);
if (getArguments() != null && getArguments().containsKey(Constants.Params.INPUT_TYPE)) {
int type = getArguments().getInt(Constants.Params.INPUT_TYPE, -1);
SettingsManager settingsManager = SettingsManager.getInstance(getActivity());
switch(type) {
case Constants.Params.TYPE_AD_UNIT_ID:
mInput.setText(settingsManager.getAdServerSettings().getAdUnitId());
break;
case Constants.Params.TYPE_BID_PRICE:
mInput.setText(String.valueOf(settingsManager.getAdServerSettings().getBidPrice()));
break;
case Constants.Params.TYPE_ACCOUNT_ID:
mInput.setText(settingsManager.getPrebidServerSettings().getAccountId());
break;
case Constants.Params.TYPE_CONFIG_ID:
mInput.setText(settingsManager.getPrebidServerSettings().getConfigId());
break;
}
}
if (getArguments() != null && getArguments().containsKey(Constants.Params.INPUT_FORMAT)) {
int format = getArguments().getInt(Constants.Params.INPUT_FORMAT, Constants.Params.FORMAT_TEXT);
switch(format) {
case Constants.Params.FORMAT_TEXT:
mInput.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case Constants.Params.FORMAT_INT:
mInput.setInputType(InputType.TYPE_CLASS_NUMBER);
break;
case Constants.Params.FORMAT_FLOAT:
mInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
break;
default:
mInput.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
ImageButton scanButton = view.findViewById(R.id.button_scan);
if (getArguments() != null && getArguments().getBoolean(Constants.Params.INPUT_SHOW_QR_SCANNER, true)) {
scanButton.setVisibility(View.VISIBLE);
scanButton.setOnClickListener(v -> openCaptureActivity());
} else {
scanButton.setVisibility(View.GONE);
}
builder.setPositiveButton(R.string.action_accept, (dialog, which) -> {
if (getArguments() != null && getArguments().containsKey(Constants.Params.INPUT_TYPE)) {
int type = getArguments().getInt(Constants.Params.INPUT_TYPE, -1);
mSettingsViewModel = ViewModelProviders.of(getActivity()).get(SettingsViewModel.class);
String text = mInput.getText().toString();
SettingsManager settingsManager = SettingsManager.getInstance(getActivity());
switch(type) {
case Constants.Params.TYPE_AD_UNIT_ID:
mSettingsViewModel.setAdUnitId(text);
settingsManager.setAdUnitId(text);
break;
case Constants.Params.TYPE_BID_PRICE:
if (TextUtils.isEmpty(text)) {
mSettingsViewModel.setBidPrice(0.0f);
settingsManager.setBidPrice(0.0f);
} else {
float value = Float.valueOf(text);
mSettingsViewModel.setBidPrice(value);
settingsManager.setBidPrice(value);
}
break;
case Constants.Params.TYPE_ACCOUNT_ID:
mSettingsViewModel.setAccountId(text);
settingsManager.setAccountId(text);
break;
case Constants.Params.TYPE_CONFIG_ID:
mSettingsViewModel.setConfigId(text);
settingsManager.setConfigId(text);
break;
}
}
dismiss();
});
builder.setNegativeButton(R.string.action_cancel, (dialog, which) -> dismiss());
return builder.create();
}
return super.onCreateDialog(savedInstanceState);
}
use of org.prebid.mobile.drprebid.managers.SettingsManager in project prebid-mobile-android by prebid.
the class PrebidServerDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (getActivity() != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.prebid_server);
View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_prebid_server_selection, null, false);
builder.setView(view);
mServerGroup = view.findViewById(R.id.group_server);
mCustomServerField = view.findViewById(R.id.field_custom_server);
mServerGroup.setOnCheckedChangeListener((group, checkedId) -> {
switch(checkedId) {
case R.id.radio_appnexus:
mCustomServerField.setVisibility(View.GONE);
break;
case R.id.radio_rubicon:
mCustomServerField.setVisibility(View.GONE);
break;
case R.id.radio_custom:
mCustomServerField.setVisibility(View.VISIBLE);
break;
}
});
fillValues();
builder.setPositiveButton(R.string.action_accept, (dialog, which) -> {
SettingsManager settingsManager = SettingsManager.getInstance(getActivity());
mSettingsViewModel = ViewModelProviders.of(getActivity()).get(SettingsViewModel.class);
switch(mServerGroup.getCheckedRadioButtonId()) {
case R.id.radio_appnexus:
settingsManager.setPrebidServer(PrebidServer.APPNEXUS);
settingsManager.setPrebidServerCustomUrl("");
mSettingsViewModel.setPrebidServer(PrebidServer.APPNEXUS);
break;
case R.id.radio_rubicon:
settingsManager.setPrebidServer(PrebidServer.RUBICON);
settingsManager.setPrebidServerCustomUrl("");
mSettingsViewModel.setPrebidServer(PrebidServer.RUBICON);
break;
case R.id.radio_custom:
settingsManager.setPrebidServer(PrebidServer.CUSTOM);
settingsManager.setPrebidServerCustomUrl(mCustomServerField.getText().toString());
mSettingsViewModel.setPrebidServer(PrebidServer.CUSTOM);
break;
}
dismiss();
});
builder.setNegativeButton(R.string.action_cancel, (dialog, which) -> dismiss());
return builder.create();
}
return super.onCreateDialog(savedInstanceState);
}
Aggregations