Skip to content

Commit 173506c

Browse files
committed
Add fetch API key button to settings screen
1 parent 7d22f44 commit 173506c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

app/src/main/java/org/galaxyproject/sampletracker/ui/settings/SettingsActivity.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* Allows to modify user and project settings.
30-
*
30+
*
3131
* @author Pavel Sveda <[email protected]>
3232
*/
3333
@ContentView(R.layout.act_settings)
@@ -37,9 +37,12 @@ public static final Intent showIntent() {
3737
return new Intent(GalaxyApplication.get(), SettingsActivity.class);
3838
}
3939

40+
private static final int API_KEY_REQUEST = 1;
41+
4042
@Inject private SettingsController mSettingsController;
4143
@Inject private GalaxyRestAdapter mGalaxyRestAdapter;
4244
@InjectView(R.id.key) private EditText mKeyField;
45+
@InjectView(R.id.key_fetch) private Button mKeyFetchButton;
4346
@InjectView(R.id.project_id) private EditText mProjectIdField;
4447
@InjectView(R.id.server_url) private EditText mServerUrlField;
4548
@InjectView(R.id.save) private Button mSaveButton;
@@ -52,6 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
5255
mKeyField.addTextChangedListener(this);
5356
mProjectIdField.addTextChangedListener(this);
5457
mServerUrlField.addTextChangedListener(this);
58+
mKeyFetchButton.setOnClickListener(this);
5559
mSaveButton.setOnClickListener(this);
5660

5761
mKeyField.setText(mSettingsController.loadApiKey());
@@ -68,6 +72,15 @@ protected void onCreate(Bundle savedInstanceState) {
6872
}
6973
}
7074

75+
@Override
76+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
77+
if (requestCode == API_KEY_REQUEST && resultCode == RESULT_OK && data != null && data.hasExtra(ApiKeyFetchActivity.EXTRA_API_KEY)) {
78+
mKeyFetchButton.setText(data.getStringExtra(ApiKeyFetchActivity.EXTRA_API_KEY));
79+
} else {
80+
super.onActivityResult(requestCode, resultCode, data);
81+
}
82+
}
83+
7184
@Override
7285
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
7386
}
@@ -84,6 +97,9 @@ public void afterTextChanged(Editable s) {
8497
@Override
8598
public void onClick(View v) {
8699
switch (v.getId()) {
100+
case R.id.key_fetch:
101+
startActivityForResult(ApiKeyFetchActivity.showIntent(), API_KEY_REQUEST);
102+
break;
87103
case R.id.save:
88104
doSave();
89105
break;

app/src/main/res/layout/act_settings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
android:inputType="textVisiblePassword"
2020
/>
2121

22+
<Button
23+
android:id="@+id/key_fetch"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_gravity="right"
27+
android:text="@string/settings_key_fetch"
28+
/>
29+
2230
<TextView
2331
android:layout_width="wrap_content"
2432
android:layout_height="wrap_content"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<string name="settings_title">Settings</string>
2525
<string name="settings_key">API access key</string>
2626
<string name="settings_key_hint">Please enter API key</string>
27+
<string name="settings_key_fetch">Fetch API key</string>
2728
<string name="settings_project_id">ID of current project</string>
2829
<string name="settings_project_id_hint">Please enter project ID</string>
2930
<string name="settings_galaxy_server_url">Galaxy server</string>

0 commit comments

Comments
 (0)