Skip to content

Commit

Permalink
Add option to skip photo during registration.
Browse files Browse the repository at this point in the history
Issue #79.
  • Loading branch information
mik3y committed May 28, 2014
1 parent db1847e commit dc298eb
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
Expand Down Expand Up @@ -93,7 +94,11 @@ protected void onPostExecute(Boolean result) {
// User already exists.
mUsername.setError("This username is not available.");
} else {
showGetPhoto();
if (mCore.getConfiguration().getTakePhotosDuringRegistration()) {
showGetPhoto();
} else {
doRegister();
}
}
}

Expand All @@ -106,8 +111,19 @@ protected User doInBackground(Void... params) {
Log.d(TAG, "Registering...");
final String imagePath = mCameraFragment.getLastFilename();
try {
return api.createUser(mUsername.getText().toString(), mEmail.getText().toString(),
final long startTime = SystemClock.elapsedRealtime();
final User user = api.createUser(mUsername.getText().toString(),
mEmail.getText().toString(),
null, imagePath);

// Make sure we're showing the progress bar for at least
// 2s; the flashing is jarring / hard to read otherwise.
final long duration = SystemClock.elapsedRealtime() - startTime;
if (duration < 2000) {
SystemClock.sleep(2000 - duration);
}

return user;
} catch (BackendException e) {
// TODO: Highlight field errors.
Log.w(TAG, "Registration failed: " + e.toString());
Expand Down
8 changes: 8 additions & 0 deletions kegtab/src/main/java/org/kegbot/app/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public boolean onPreferenceClick(Preference preference) {
}
}

public static class AccessFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_access);
}
}

public static class KegeratorFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ public void setEnableAutoTakePhoto(boolean value) {
setBoolean(ConfigKey.AUTO_TAKE_PHOTOS, value);
}

public boolean getTakePhotosDuringRegistration() {
return getBoolean(ConfigKey.TAKE_PHOTOS_DURING_REGISTRATION);
}

public void setTakePhotosDuringRegistration(boolean value) {
setBoolean(ConfigKey.TAKE_PHOTOS_DURING_REGISTRATION, value);
}

public boolean getEnableCameraSounds() {
return getBoolean(ConfigKey.ENABLE_CAMERA_SOUNDS);
}
Expand Down
1 change: 1 addition & 0 deletions kegtab/src/main/java/org/kegbot/app/config/ConfigKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum ConfigKey {
CACHE_CREDENTIALS(TRUE),
RUN_CORE(TRUE),
ENABLE_AUTOMATIC_FLOW_START(TRUE),
TAKE_PHOTOS_DURING_REGISTRATION(FALSE),

FLOW_MINIMUM_VOLUME_ML("10"),
FLOW_IDLE_TIMEOUT_SECONDS("90"),
Expand Down
1 change: 1 addition & 0 deletions kegtab/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<string name="drinker_select_new_account_description">Register for and begin pouring with a new account.</string>
<string name="drinker_select_button_guest">Pour As Guest</string>
<string name="drinker_select_guest_description">Pour without linking to an account.</string>
<string name="settings_access_header">Access</string>


</resources>
55 changes: 55 additions & 0 deletions kegtab/src/main/res/xml/settings_access.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright 2014 Bevbot LLC <info@bevbot.com>
~
~ This file is part of the Kegtab package from the Kegbot project. For
~ more information on Kegtab or Kegbot, see <http://kegbot.org/>.
~
~ Kegtab is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 2.
~
~ Kegtab is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with Kegtab. If not, see <http://www.gnu.org/licenses/>.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="Registration">
<CheckBoxPreference
android:defaultValue="true"
android:key="config:ALLOW_REGISTRATION"
android:summaryOff="New users cannot register from the main screen"
android:summaryOn="New users can register from the main screen"
android:title="Allow New User Registration">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="config:TAKE_PHOTOS_DURING_REGISTRATION"
android:summaryOff="Photos will be skipped during registration"
android:summaryOn="User may take an account photo during registration"
android:title="Take Photo During Registration"
android:dependency="config:ALLOW_REGISTRATION">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="config:ALLOW_MANUAL_LOGIN"
android:summaryOff="Drinkers must use an RFID or other token to log in"
android:summaryOn="Drinkers can log in by tapping on the main screen"
android:title="Allow On-Screen Login">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="config:CACHE_CREDENTIALS"
android:summaryOff="Authentication tokens will always be checked against the server"
android:summaryOn="Authentication tokens will be locally cached"
android:title="Cache Credentials">
</CheckBoxPreference>
</PreferenceCategory>

</PreferenceScreen>
4 changes: 4 additions & 0 deletions kegtab/src/main/res/xml/settings_headers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
android:fragment="org.kegbot.app.SettingsActivity$GeneralFragment"
android:title="@string/settings_general_header"
/>
<header
android:fragment="org.kegbot.app.SettingsActivity$AccessFragment"
android:title="@string/settings_access_header"
/>
<header
android:fragment="org.kegbot.app.SettingsActivity$KegeratorFragment"
android:title="@string/settings_kegerator_header"
Expand Down
21 changes: 0 additions & 21 deletions kegtab/src/main/res/xml/settings_kegerator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,6 @@
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="User Interface">
<CheckBoxPreference
android:defaultValue="true"
android:key="config:ALLOW_REGISTRATION"
android:summaryOff="New users cannot register from the main screen"
android:summaryOn="New users can register from the main screen"
android:title="Allow New User Registration">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="config:ALLOW_MANUAL_LOGIN"
android:summaryOff="Drinkers must use an RFID or other token to log in"
android:summaryOn="Drinkers can log in by tapping on the main screen"
android:title="Allow On-Screen Login">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="config:CACHE_CREDENTIALS"
android:summaryOff="Authentication tokens will always be checked against the server"
android:summaryOn="Authentication tokens will be locally cached"
android:title="Cache Credentials">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="config:ATTRACT_MODE"
Expand Down

0 comments on commit dc298eb

Please sign in to comment.