Commit 4805173f authored by Roger Barton's avatar Roger Barton
Browse files

Refactoring Intro

parent fdd64418
......@@ -19,7 +19,7 @@ import android.widget.TextView;
import ch.amiv.android_app.R;
import ch.amiv.android_app.ui.NonSwipeableViewPager;
import ch.amiv.android_app.ui.PrefDetailView;
import ch.amiv.android_app.ui.EnumViewGenerator;
import ch.amiv.android_app.util.Util;
public class IntroActivity extends AppCompatActivity {
......@@ -173,18 +173,26 @@ public class IntroActivity extends AppCompatActivity {
return;
//Setup Next Page
if(page == Page.EVENT_PREF){//Setup pref values XXXXX Check this
if(page == Page.EVENT_PREF){//Setup pref values
TextView foodLabel = findViewById(R.id.foodPrefText);
String foodValue = Settings.GetPref(Settings.foodPrefKey, getApplicationContext());
if(foodLabel != null)
if(foodLabel != null) {
if(foodValue.isEmpty())
foodLabel.setText(R.string.tap_to_set);
else
foodLabel.setText(foodValue);
}
TextView sbbLabel = findViewById(R.id.sbbPrefText);
String sbbValue = Settings.GetPref(Settings.sbbPrefKey, getApplicationContext());
if(sbbLabel != null)
if(sbbLabel != null) {
if(sbbValue.isEmpty())
sbbLabel.setText(R.string.tap_to_set);
else
sbbLabel.setText(sbbValue);
}
}
}
// Callbacks for when the page changes to refresh the progress dots
ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
......@@ -253,7 +261,8 @@ public class IntroActivity extends AppCompatActivity {
if(resultCode == RESULT_OK) {
if(hasLoggedIn){
SetPage(Page.EDIT_PROFILE, true);
Snackbar.make(viewPager, "Fetching Profile", 1000).show();
RefreshPageUI(Page.EDIT_PROFILE);
btnNext.setVisibility(View.INVISIBLE);
Requests.FetchUserData(getApplicationContext(), viewPager, new Requests.OnDataReceivedCallback() {
@Override
public void OnDataReceived() {
......@@ -308,11 +317,15 @@ public class IntroActivity extends AppCompatActivity {
//endregion
//region---Profile---
/**
* Use this to fill in the profile text fields once the userInfo has been received
* Use this to fill/show in the profile text fields once the userInfo has been received
*/
private void SetProfileUI(){
findViewById(R.id.loadingCircle).setVisibility(View.GONE);
findViewById(R.id.scrollView).setVisibility(View.VISIBLE);
RefreshPageUI(Page.EDIT_PROFILE);
//fill in values for the profile fields
if(rfidField == null)
rfidField = findViewById(R.id.rfidField);
rfidField.setText(UserInfo.current.rfid);
......@@ -322,27 +335,25 @@ public class IntroActivity extends AppCompatActivity {
* Use this to update the profile info and submit to the server
*/
private void UpdateProfile(){
String newRfid = rfidField.getText().toString();
if(newRfid.isEmpty() || newRfid.equalsIgnoreCase(UserInfo.current.rfid))
return;
UserInfo.current.rfid = newRfid;
if(UserInfo.current.SetRFID(rfidField.getText().toString()))
Requests.PatchUserData(getApplicationContext());
}
//endregion
//region---Prefs---
/**
* This changes the page to edit the food pref, UI content is generated using EnumViewGenerator
*/
public void EditFoodPrefs(View view){
SetPage(Page.PREF_DETAIL, true);
final PrefDetailView.OnButtonIndexClicked onClick = new PrefDetailView.OnButtonIndexClicked() {
final EnumViewGenerator.OnButtonIndexClicked onClick = new EnumViewGenerator.OnButtonIndexClicked() {
@Override
public void OnClick(int enumIndex) {//use length-1 when other is used
if(enumIndex < 0)
return;
SetPage(Page.EVENT_PREF, false);
//Set the event pref
String value = getResources().getStringArray(R.array.pref_food_list_values)[enumIndex];
Settings.SetPref(Settings.foodPrefKey, value, getApplicationContext());
if(enumIndex == getResources().getStringArray(R.array.pref_food_list_values).length -1 && findViewById(R.id.otherField) != null) {
......@@ -352,11 +363,13 @@ public class IntroActivity extends AppCompatActivity {
TextView label = findViewById(R.id.foodPrefText);
if(label != null)
label.setText(getResources().getStringArray(R.array.pref_food_list_values)[enumIndex]);
btnNext.setOnClickListener(onNextClick);
btnNext.setOnClickListener(onNextClick);//reset next button
}
};
PrefDetailView.InitialiseList(this, R.string.pref_food_title, onClick, getResources().getStringArray(R.array.pref_food_list_values), true);
EnumViewGenerator.InitialiseEnumList(this, R.string.pref_food_title, onClick, getResources().getStringArray(R.array.pref_food_list_values), true);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -368,7 +381,7 @@ public class IntroActivity extends AppCompatActivity {
public void EditSBBPrefs(View view){
SetPage(Page.PREF_DETAIL, true);
final PrefDetailView.OnButtonIndexClicked onClick = new PrefDetailView.OnButtonIndexClicked() {
final EnumViewGenerator.OnButtonIndexClicked onClick = new EnumViewGenerator.OnButtonIndexClicked() {
@Override
public void OnClick(int enumIndex) {//use length-1 when other is used
if(enumIndex < 0)
......@@ -381,11 +394,13 @@ public class IntroActivity extends AppCompatActivity {
TextView label = findViewById(R.id.sbbPrefText);
if(label != null)
label.setText(getResources().getStringArray(R.array.pref_sbb_list_values)[enumIndex]);
btnNext.setOnClickListener(onNextClick);
}
};
PrefDetailView.InitialiseList(this, R.string.pref_sbb_title, onClick, getResources().getStringArray(R.array.pref_sbb_list_values), false);
EnumViewGenerator.InitialiseEnumList(this, R.string.pref_sbb_title, onClick, getResources().getStringArray(R.array.pref_sbb_list_values), false);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......
......@@ -96,6 +96,15 @@ public class Settings {
CheckInitSharedPrefs(context);
sharedPrefs.edit().clear().commit();
}
/**
* Note:only for string prefs
* @return True if the pref is at the default value
*/
public static boolean IsPrefDefault(String[] key, Context context){
return GetPref(key, context).equals(key[1]);
}
//endregion
//region ---Auth---
......
......@@ -127,6 +127,18 @@ public class UserInfo implements Serializable{
PersistentStorage.SaveUserInfo(context);
}
/**
* Will set the rfid if it is valid. Valid if it has 6 chars
* @return If the given rfid was valid/different to the current
*/
public boolean SetRFID (String newRFID){
if(newRFID == null || newRFID.length() != 6 || newRFID.equalsIgnoreCase(UserInfo.current.rfid))
return false;
rfid = newRFID;
return true;
}
public static void LogoutUser(Context context){
if(Settings.IsEmailOnlyLogin(context)) {
Settings.SetToken("", context);
......
......@@ -11,18 +11,19 @@ import android.widget.TextView;
import ch.amiv.android_app.R;
public class PrefDetailView {
public class EnumViewGenerator {
public interface OnButtonIndexClicked {
void OnClick(int enumIndex);
}
public static void InitialiseList(final Activity activity, int header, final OnButtonIndexClicked onClick, String[] titles, boolean addOtherField){
public static void InitialiseEnumList(final Activity activity, int header, final OnButtonIndexClicked onClick, String[] titles, boolean addOtherField){
TextView titleView = activity.findViewById(R.id.title);
titleView.setText(header);
ViewGroup parent = activity.findViewById(R.id.listParent);
parent.removeAllViews();
//Add list of options as buttons as children of the list parent (Linear layout)
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
for (int i = 0; i < titles.length + (addOtherField ? -1:0); i++) {
Button btn = (Button) inflater.inflate(R.layout.core_intro_pref_button, null);
......@@ -38,6 +39,7 @@ public class PrefDetailView {
});
}
//add other text field, show the save button other is tapped
if(addOtherField){
EditText text = LayoutInflater.from(parent.getContext()).inflate(R.layout.core_intro_pref_other_field, parent).findViewById(R.id.otherField);
text.setHint(titles[titles.length-1]);
......
......@@ -37,10 +37,22 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
<ProgressBar
android:id="@+id/loadingCircle"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/line" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/line">
......
......@@ -38,6 +38,7 @@
<string name="intro_rfid_hint">Eine 6-stellige Zahl auf der Rückseite Ihrer Legi</string>
<string name="rfid_no">RFID Nr.</string>
<string name="intro_profile_title">Bitte Ihre Daten Aktualisieren</string>
<string name="intro_event_prefs_title">Wähle Deine Event Präferenzen</string>
<!-- Login -->
<string name="login_title">Login</string>
......@@ -194,7 +195,7 @@
<string name="skip">Überspringen</string>
<string name="lets_go">Los Geht\'s</string>
<string name="other">Anderes</string>
<string name="intro_event_prefs_title">Wähle Deine Event Präferenzen</string>
<string name="tap_to_set">Setzen</string>
</resources>
......@@ -47,6 +47,7 @@
<string name="rfid_no">RFID No.</string>
<string name="intro_rfid_hint">A 6-Digit number on the back of your Legi</string>
<string name="intro_profile_title">Please Update Your Info</string>
<string name="intro_event_prefs_title">Set Your Event Preferences</string>
<!-- Login -->
<string name="login_title">Login</string>
......@@ -204,6 +205,6 @@
<string name="skip">Skip</string>
<string name="lets_go">Let\'s Go</string>
<string name="other">Other</string>
<string name="intro_event_prefs_title">Set Your Event Preferences</string>
<string name="tap_to_set">Tap to set</string>
</resources>
Supports Markdown
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