Commit f7e1e0c7 authored by Roger Barton's avatar Roger Barton
Browse files

Started adding new SettingsActivity,

Renamed current SettingsActivity to SettingsActivity_old
fetches/loads event/jobs list on app start automatically
parent 6067d8fe
Pipeline #8619 passed with stages
in 11 minutes and 40 seconds
...@@ -142,6 +142,6 @@ ...@@ -142,6 +142,6 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<activity android:name=".util.ui.EnumEditActivity" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -13,7 +13,7 @@ import android.view.View; ...@@ -13,7 +13,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
/** /**
* This is used by the SettingsActivity * This is used by the SettingsActivity_old
*/ */
public abstract class AppCompatPreferenceActivity extends PreferenceActivity { public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
......
...@@ -3,7 +3,7 @@ package ch.amiv.android_app.core; ...@@ -3,7 +3,7 @@ package ch.amiv.android_app.core;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
/** /**
* A class to simplify refreshing a recyclerview, used in events and jobs list for example * A class to simplify refreshing a recyclerview, used in events and jobInfos list for example
*/ */
public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
......
...@@ -26,7 +26,7 @@ import ch.amiv.android_app.events.EventsListAdapter; ...@@ -26,7 +26,7 @@ import ch.amiv.android_app.events.EventsListAdapter;
import ch.amiv.android_app.jobs.JobListAdapter; import ch.amiv.android_app.jobs.JobListAdapter;
/** /**
* This class is a fragment for a list screen used in the main activity by the page viewer for events, jobs, it will use the given page position to tell which one it is * This class is a fragment for a list screen used in the main activity by the page viewer for events, jobInfos, it will use the given page position to tell which one it is
* NOTE: This fragment will lose its connection to the parent activity, when the app is resumed, use MainActivity.instance as the activity and context * NOTE: This fragment will lose its connection to the parent activity, when the app is resumed, use MainActivity.instance as the activity and context
*/ */
public class ListFragment extends Fragment { public class ListFragment extends Fragment {
......
...@@ -122,9 +122,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -122,9 +122,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
bottomNavigation = findViewById(R.id.bottomNav); bottomNavigation = findViewById(R.id.bottomNav);
bottomNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); bottomNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
Settings.LoadEvents(getApplicationContext());
Settings.LoadJobs(getApplicationContext());
InitialisePageView(); InitialisePageView();
if(!Settings.LoadEvents(getApplicationContext()))
Request.FetchEventList(getApplicationContext(), pages.get(ListFragment.PageType.EVENTS).onEventsListUpdatedCallback, null, "");
if(!Settings.LoadJobs(getApplicationContext()))
Request.FetchJobList(MainActivity.instance, pages.get(ListFragment.PageType.EVENTS).onJobsListUpdatedCallback, null, "");
//fetch the user info if we are logged in, there exists a token from the previous session, should be cached. //fetch the user info if we are logged in, there exists a token from the previous session, should be cached.
......
package ch.amiv.android_app.core; package ch.amiv.android_app.core;
import android.annotation.TargetApi; import android.support.v7.app.AppCompatActivity;
import android.content.Intent; import android.os.Bundle;
import android.media.Ringtone;
import android.media.RingtoneManager; import ch.amiv.android_app.R;
import android.net.Uri; import ch.amiv.android_app.util.Util;
import android.os.Build;
import android.os.Bundle; public class SettingsActivity extends AppCompatActivity {
import android.preference.ListPreference;
import android.preference.Preference; @Override
import android.preference.PreferenceActivity; protected void onCreate(Bundle savedInstanceState) {
import android.preference.PreferenceFragment; super.onCreate(savedInstanceState);
import android.preference.PreferenceManager; setContentView(R.layout.core_settings);
import android.preference.RingtonePreference;
import android.support.v4.app.NavUtils; Util.SetupToolbar(this, true);
import android.support.v7.app.ActionBar;
import android.text.TextUtils; }
import android.view.MenuItem; }
import ch.amiv.android_app.R;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
public class SettingsActivity extends AppCompatPreferenceActivity {
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
// using RingtoneManager.
if (TextUtils.isEmpty(stringValue)) {
// Empty values correspond to 'silent' (no ringtone).
preference.setSummary(R.string.pref_ringtone_silent);
} else {
Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), Uri.parse(stringValue));
if (ringtone == null) {
// Clear the summary if there was a lookup error.
preference.setSummary(null);
} else {
// Set the summary to reflect the new ringtone display
// name.
String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
}
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
};
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit();
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
return super.onMenuItemSelected(featureId, item);
}
/**
* This fragment shows general preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class GeneralPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_settings);
setHasOptionsMenu(true);
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_food_key)));
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_sbb_key)));
Preference langPref = findPreference(getString(R.string.pref_lang_key));
langPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Settings.SetLanguage(newValue.toString(), getContext());
//update summary
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, newValue);
//Restart app to apply language
Intent intent = getActivity().getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
}
});
sBindPreferenceSummaryToValueListener.onPreferenceChange(langPref,
PreferenceManager.getDefaultSharedPreferences(langPref.getContext())
.getString(langPref.getKey(), ""));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
}
package ch.amiv.android_app.core;
import android.annotation.TargetApi;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.text.TextUtils;
import android.view.MenuItem;
import ch.amiv.android_app.R;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
public class SettingsActivity_old extends AppCompatPreferenceActivity {
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
// using RingtoneManager.
if (TextUtils.isEmpty(stringValue)) {
// Empty values correspond to 'silent' (no ringtone).
preference.setSummary(R.string.pref_ringtone_silent);
} else {
Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), Uri.parse(stringValue));
if (ringtone == null) {
// Clear the summary if there was a lookup error.
preference.setSummary(null);
} else {
// Set the summary to reflect the new ringtone display
// name.
String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
}
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
};
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit();
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
return super.onMenuItemSelected(featureId, item);
}
/**
* This fragment shows general preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class GeneralPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_settings);
setHasOptionsMenu(true);
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_food_key)));
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_sbb_key)));
Preference langPref = findPreference(getString(R.string.pref_lang_key));
langPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Settings.SetLanguage(newValue.toString(), getContext());
//update summary
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, newValue);
//Restart app to apply language
Intent intent = getActivity().getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
}
});
sBindPreferenceSummaryToValueListener.onPreferenceChange(langPref,
PreferenceManager.getDefaultSharedPreferences(langPref.getContext())
.getString(langPref.getKey(), ""));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
startActivity(new Intent(getActivity(), SettingsActivity_old.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
}
...@@ -268,6 +268,7 @@ public class EventDetailActivity extends AppCompatActivity { ...@@ -268,6 +268,7 @@ public class EventDetailActivity extends AppCompatActivity {
((TextView) findViewById(R.id.eventDetail)).setText(event.GetDescription(getResources())); ((TextView) findViewById(R.id.eventDetail)).setText(event.GetDescription(getResources()));
LoadEventImage(isRefreshing); LoadEventImage(isRefreshing);
AddRegisterInfos(); AddRegisterInfos();
AddRegisterForms();
} }
UpdateRegisterButton(); UpdateRegisterButton();
...@@ -370,6 +371,91 @@ public class EventDetailActivity extends AppCompatActivity { ...@@ -370,6 +371,91 @@ public class EventDetailActivity extends AppCompatActivity {
} }
} }
//XXXXX
/**
* This generates the list of event addit fields to be filled in
*/
private void AddRegisterForms()
{
LinearLayout linear = findViewById(R.id.register_form_list);
linear.removeAllViews();
final AdditField[] fields = event.additional_fields;
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
for (int i = 0; i < event.additional_fields.length; i++) {
//Create a view from the xml and then add it as a child of the listview
LinearLayout layout = null;
if(fields[i].type == AdditField.FieldType.STRING)
{
if(fields[i].possibleValues != null && fields[i].possibleValues.length == 0) //Text field
{
layout = (LinearLayout) inflater.inflate(R.layout.core_main_list_item_keyval, linear, false);
((TextView) layout.findViewById(R.id.keyField )).setText(fields[i].title(getApplicationContext()));
((TextView) layout.findViewById(R.id.valueField)).setText(fields[i].currentValue);
//XXXXX
final AdditField currentField = fields[i];
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Open keyboard and type in field. Or pop up
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Title");
// Set up the input
final EditText input = new EditText(getApplicationContext());
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
builder.setView(input);
// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
currentField.currentValue = input.getText().toString();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
});
}
else //enum field
{
layout = (LinearLayout) inflater.inflate(R.layout.core_main_list_item_keyval, linear, false);
((TextView) layout.findViewById(R.id.keyField )).setText(fields[i].title(getApplicationContext()));
((TextView) layout.findViewById(R.id.valueField)).setText(fields[i].currentValue);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Launch pref enum activity with the addit field
}
});
}
}
else if (fields[i].type == AdditField.FieldType.BOOLEAN){
//To be impemented
layout = null;
}
else if (fields[i].type == AdditField.FieldType.INTEGER){
//To be implemented
layout = null;
}
if(layout != null) {
linear.addView(layout);
}
}
}
/** /**
* Will send a request to register the user for the event the activity is showing * Will send a request to register the user for the event the activity is showing
*/ */
......
package ch.amiv.android_app.util.ui;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import ch.amiv.android_app.R;