Commit 9c440235 authored by Roger Barton's avatar Roger Barton
Browse files

Refined settings and added changing of locale, translations, still bugged

Still need to select correct text from jsons according to locale
parent c49ed8dc
......@@ -228,7 +228,7 @@ public class EventDetailActivity extends AppCompatActivity {
}, 0, 0, ImageView.ScaleType.CENTER_INSIDE, Bitmap.Config.ARGB_8888,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Snackbar.make(posterImage, "Error loading image", Snackbar.LENGTH_SHORT).show();
Snackbar.make(posterImage, R.string.error_image_load, Snackbar.LENGTH_SHORT).show();
posterProgress.setVisibility(View.GONE);
swipeRefreshLayout.setRefreshing(false);
}
......@@ -252,7 +252,7 @@ public class EventDetailActivity extends AppCompatActivity {
LinearLayout linear = findViewById(R.id.register_details_list);
linear.removeAllViews();
ArrayList<String[]> infos = Events.eventInfos.get(eventIndex).GetInfos();
ArrayList<String[]> infos = Events.eventInfos.get(eventIndex).GetInfos(getResources());
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
for (int i = 0; i < infos.size(); i++) {
//Create a view from the xml and then add it as a child of the listview
......@@ -271,7 +271,7 @@ public class EventDetailActivity extends AppCompatActivity {
public void RegisterForEvent(View view)
{
if(!Requests.CheckConnection(getApplicationContext())) {
Snackbar.make(view, "Requires Internet", Snackbar.LENGTH_LONG).show();
Snackbar.make(view, R.string.requires_internet, Snackbar.LENGTH_LONG).show();
return;
}
......@@ -322,7 +322,7 @@ public class EventDetailActivity extends AppCompatActivity {
}
else {
Log.e("request", "Request returned null response.");
Snackbar.make(scrollView, "Error occured, please try again", Snackbar.LENGTH_SHORT).show();
Snackbar.make(scrollView, R.string.snack_error_retry, Snackbar.LENGTH_SHORT).show();
}
return super.parseNetworkResponse(response);
}
......@@ -332,7 +332,7 @@ public class EventDetailActivity extends AppCompatActivity {
if(volleyError != null && volleyError.networkResponse != null) {
Log.e("request", "status code: " + volleyError.networkResponse.statusCode + "\n" + new String(volleyError.networkResponse.data));
if(volleyError.networkResponse.statusCode == 422) {
Snackbar.make(scrollView, "Already Registered", Snackbar.LENGTH_SHORT).show();
Snackbar.make(scrollView, R.string.already_registered, Snackbar.LENGTH_SHORT).show();
}
}
else
......@@ -367,10 +367,10 @@ public class EventDetailActivity extends AppCompatActivity {
private void UpdateRegisterButton() {
if (Events.eventInfos.get(eventIndex).IsSignedUp()) {
registerButton.setEnabled(false);
registerButton.setText("Already Registered");
registerButton.setText(R.string.already_registered);
} else {
registerButton.setEnabled(true);
registerButton.setText("Register");
registerButton.setText(R.string.register_title);
}
}
......
package ch.amiv.android_app;
import android.content.res.Resources;
import android.util.Log;
import org.json.JSONException;
......@@ -156,20 +157,20 @@ public class EventInfo {
* Choose the key value pairs to be displayed in the event info section when viewing the event in detail
* @return
*/
public ArrayList<String[]> GetInfos(){
public ArrayList<String[]> GetInfos(Resources r){
if(infos != null && infos.size() > 0)
return infos;
DateFormat dateFormat = new SimpleDateFormat("yyyy - MMM - dd HH:mm");
if(time_start != null) infos.add(new String[]{"Start", dateFormat.format(time_start)});
if(time_end != null) infos.add(new String[]{"End", dateFormat.format(time_end)});
if(!price.isEmpty()) infos.add(new String[]{"Price", (price.equalsIgnoreCase("0") ? "Free" : price)});
if(!location.isEmpty()) infos.add(new String[]{"Location", location});
if(time_register_start != null) infos.add(new String[]{"Register Start", dateFormat.format(time_register_start)});
if(time_register_end != null) infos.add(new String[]{"Register End", dateFormat.format(time_register_end)});
infos.add(new String[]{"Available Places", (spots == 0 ? "-" : "" + Math.max(0, spots - signup_count))});
DateFormat dateFormat = new SimpleDateFormat("dd - MMM - yyyy HH:mm");
if(time_start != null) infos.add(new String[]{ r.getString(R.string.start_time), dateFormat.format(time_start)});
if(time_end != null) infos.add(new String[]{ r.getString(R.string.end_time), dateFormat.format(time_end)});
if(!price.isEmpty()) infos.add(new String[]{ r.getString(R.string.price), (price.equalsIgnoreCase("0") ? "Free" : price)});
if(!location.isEmpty()) infos.add(new String[]{ r.getString(R.string.location), location});
if(time_register_start != null) infos.add(new String[]{ r.getString(R.string.register_start), dateFormat.format(time_register_start)});
if(time_register_end != null) infos.add(new String[]{ r.getString(R.string.register_end), dateFormat.format(time_register_end)});
infos.add(new String[]{ r.getString(R.string.available_places), (spots <= 0 ? "-" : "" + Math.max(0, spots - signup_count))});
if(spots - signup_count < 0)
infos.add(new String[]{"Waiting List Size", "" + (signup_count - spots)});
infos.add(new String[]{ r.getString(R.string.waiting_list_size), "" + (signup_count - spots)});
return infos;
}
......
......@@ -53,7 +53,7 @@ public class EventsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
public EventsListAdapter(Activity activity_) {
headerList.add("New Events");
headerList.add(activity_.getResources().getString(R.string.new_events_title));
//headerList.add("Attended Events"); //XXX Add sorting of old events, where checkin or confirmed is true
activity = activity_;
}
......
......@@ -74,7 +74,7 @@ public class LoginActivity extends AppCompatActivity {
final String password = passwordField.getText().toString();
if(username.isEmpty()) {
Snackbar.make(submitButton, "Please fill in all fields", Snackbar.LENGTH_SHORT).show();
Snackbar.make(submitButton, R.string.snack_fill_all_fields, Snackbar.LENGTH_SHORT).show();
return;
}
......@@ -95,7 +95,7 @@ public class LoginActivity extends AppCompatActivity {
ReturnToCallingActivity(true);
}
else{
Snackbar.make(userField, "An error occured, please retry", Snackbar.LENGTH_SHORT).show();
Snackbar.make(userField, R.string.snack_error_retry, Snackbar.LENGTH_SHORT).show();
SetSubmitButtonState(true, false);
}
......@@ -123,12 +123,12 @@ public class LoginActivity extends AppCompatActivity {
protected VolleyError parseNetworkError(final VolleyError volleyError) { //see comments at parseNetworkResponse()
if(volleyError != null && volleyError.networkResponse != null)
{
Snackbar.make(userField, "Invalid Login Details", Snackbar.LENGTH_SHORT).show();
Snackbar.make(userField, R.string.invalid_login, Snackbar.LENGTH_SHORT).show();
Log.e("request", "status code: " + volleyError.networkResponse.statusCode + "\n" + new String(volleyError.networkResponse.data));
}
else
{
Snackbar.make(userField, "No Internet", Snackbar.LENGTH_SHORT).show();
Snackbar.make(userField, R.string.no_internet, Snackbar.LENGTH_SHORT).show();
Log.e("request", "Request returned null response.");
}
......@@ -149,7 +149,7 @@ public class LoginActivity extends AppCompatActivity {
if(wasSent)
SetSubmitButtonState(false, false);
else
Snackbar.make(userField, "No Internet", Snackbar.LENGTH_SHORT).show();
Snackbar.make(userField, R.string.no_internet, Snackbar.LENGTH_SHORT).show();
}
/**
......@@ -162,7 +162,7 @@ public class LoginActivity extends AppCompatActivity {
@Override
public void run() {
submitButton.setEnabled(enable);
submitButton.setText(enable ? "Submit" : (loginSuccess ? "Success" : "Please Wait"));
submitButton.setText(enable ? R.string.login_title : (loginSuccess ? R.string.success : R.string.wait));
}
});
}
......
......@@ -168,7 +168,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
{
if(Settings.IsLoggedIn(getApplicationContext())) {
drawerNavigation.getMenu().findItem(R.id.nav_login)
.setTitle("Logout")
.setTitle(R.string.logout_title)
.setChecked(false);
if(UserInfo.current != null)
{
......@@ -179,9 +179,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
else
{
drawerNavigation.getMenu().findItem(R.id.nav_login)
.setTitle("Login")
.setTitle(R.string.login_title)
.setChecked(false);
drawer_title.setText("Not Logged In");
drawer_title.setText(R.string.not_logged_in);
drawer_subtitle.setText("");
}
}
......
......@@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
......@@ -18,9 +19,11 @@ import android.preference.RingtonePreference;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.text.TextUtils;
import android.transition.ChangeBounds;
import android.view.MenuItem;
import java.util.List;
import java.util.Locale;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
......@@ -51,10 +54,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
......@@ -87,15 +87,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
};
/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
......@@ -121,6 +112,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit();
}
/**
......@@ -146,34 +138,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
return super.onMenuItemSelected(featureId, item);
}
/**
* {@inheritDoc}
*/
@Override
public boolean onIsMultiPane() {
return isXLargeTablet(this);
}
/**
* {@inheritDoc}
*/
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.pref_headers, target);
}
/**
* This method stops fragment injection in malicious applications.
* Make sure to deny any unknown fragments here.
*/
protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
|| DataSyncPreferenceFragment.class.getName().equals(fragmentName)
|| NotificationPreferenceFragment.class.getName().equals(fragmentName);
}
/**
* This fragment shows general preferences only. It is used when the
* activity is showing a two-pane settings UI.
......@@ -183,75 +147,33 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
addPreferencesFromResource(R.xml.pref_settings);
setHasOptionsMenu(true);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("example_text"));
bindPreferenceSummaryToValue(findPreference("lang_list"));
}
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_food_key)));
bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_sbb_key)));
@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);
}
}
Preference langPref = findPreference(getString(R.string.pref_lang_key));
langPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
//CHange local/language
Resources res = getResources();
Configuration conf = res.getConfiguration();
conf.locale = new Locale(newValue.toString());
res.updateConfiguration(conf, res.getDisplayMetrics());
/**
* This fragment shows notification preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class NotificationPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_notification);
setHasOptionsMenu(true);
//update summary
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, newValue);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone"));
}
@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);
}
}
return true;
}
});
/**
* This fragment shows data and sync preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class DataSyncPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_data_sync);
setHasOptionsMenu(true);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("sync_frequency"));
sBindPreferenceSummaryToValueListener.onPreferenceChange(langPref,
PreferenceManager.getDefaultSharedPreferences(langPref.getContext())
.getString(langPref.getKey(), ""));
}
@Override
......
......@@ -92,7 +92,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="Event Title"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="30sp" />
......@@ -118,7 +118,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="Info"
android:text="@string/info_title"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="30sp" />
......@@ -139,7 +139,7 @@
android:enabled="true"
android:onClick="RegisterForEvent"
android:paddingBottom="16dp"
android:text="Register" />
android:text="@string/register_title" />
</LinearLayout>
......
......@@ -63,7 +63,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Please enter your login details"
android:text="@string/login_prompt"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view" />
......@@ -81,7 +81,8 @@
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/passwordField"
......@@ -98,7 +99,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/usernameField" />
app:layout_constraintTop_toBottomOf="@+id/usernameField"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/submitLoginButton"
......@@ -115,7 +117,8 @@
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordField" />
app:layout_constraintTop_toBottomOf="@+id/passwordField"
tools:ignore="HardcodedText" />
</android.support.constraint.ConstraintLayout>
......
......@@ -30,7 +30,7 @@
android:id="@+id/eventTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Event Title"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<TextView
......@@ -44,7 +44,7 @@
android:id="@+id/registerHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register"
android:text="@string/register_title"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textSize="18sp" />
......
......@@ -12,7 +12,7 @@
android:layout_weight="1"
android:paddingLeft="12dp"
android:paddingTop="8dp"
android:text="Header"
android:text=""
android:textSize="24sp"
android:textStyle="bold" />
......
......@@ -17,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Key"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textSize="18sp" />
......@@ -27,7 +27,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="8dp"
android:text="Value"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="16sp" />
</LinearLayout>
......
......@@ -25,7 +25,6 @@
android:layout_gravity="center"
android:layout_marginEnd="16dp"
android:antialias="true"
android:contentDescription="Logo"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:scaleType="fitCenter"
......
......@@ -7,23 +7,23 @@
<item
android:id="@+id/nav_login"
android:icon="@drawable/ic_menu_account"
android:title="Login" />
android:title="@string/login_title" />
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_menu_settings"
android:title="Settings" />
android:title="@string/settings_title" />
</group>
<item android:title="Apps">
<item android:title="@string/apps_title">
<menu>
<item
android:id="@+id/nav_checkin"
android:icon="@drawable/ic_menu_camera"
android:title="Check-in" />
android:title="@string/check_in_title" />
<item
android:id="@+id/nav_barcode_id"
android:icon="@drawable/ic_menu_gallery"
android:title="Barcode ID" />
android:title="@string/barcode_id_title" />
</menu>
</item>
</menu>
<resources>
<!-- Titles -->
<string name="app_name">AMIV</string>
<string name="title_home">Home</string>
<string name="title_blitz">blitz</string>
<string name="title_notifications">Benachrichtigungen</string>
<string name="settings_title">Einstellungen</string>
<string name="apps_title">Apps</string>
<string name="check_in_title">Check-in</string>
<string name="barcode_id_title">Barcode ID</string>
<string name="info_title">Info</string>
<string name="new_events_title">Neue Events</string>
<!-- Language -->
<string name="pref_lang_title">Language - Sprache</string>
<string-array name="pref_lang_list_values">
<item>Deutsch</item>
<item>English</item>
</string-array>
<string-array name="pref_lang_list_entries">
<item>en</item>
<item>de</item>
</string-array>
<!-- Login -->
<string name="login_title">Login</string>
<string name="login_prompt">Bitte geben Sie Ihre Zugangsdaten ein</string>
<string name="not_logged_in">Nicht Eingeloggt</string>
<string name="invalid_login">Ungültige Login Daten</string>
<string name="logout_title">Log out</string>
<string name="wait">Bitte Warten</string>
<string name="success">Erfolg</string>
<!-- Event Infos -->
<string name="start_time">Start</string>
<string name="end_time">Ende</string>
<string name="price">Preis</string>
<string name="location">Ort</string>
<string name="waiting_list_size">Wartelistengröße</string>
<string name="available_places">Available Places</string>
<!-- Event Registering -->
<string name="register_title">Anmelden</string>
<string name="register_end">Anmelden bis</string>
<string name="register_start">Anmelden ab</string>
<string name="already_registered">Schon Angemeldet</string>
<string name="no_internet">Kein Internet</string>
<string name="requires_internet">Benötigt Internet</string>
<string name="snack_fill_all_fields">BItte füllen sie alle Felder ein</string>
<!-- Errors -->
<string name="error_image_load">Fehler aufgetreten</string>
<string name="snack_error_retry">Fehler aufgetreten, bitte erneut versuchen</string>
<!-- Settings, some are still from template -->
<string name="pref_header_general">Allgemeine Einstellungen</string>
<string name="pref_title_social_recommendations">Enable social recommendations</string>
<string name="pref_description_social_recommendations">Recommendations for people to contact based on your message history</string>
<string name="pref_title_display_name">Display name</string>
<string name="pref_default_display_name">John Smith</string>
<!-- Notifications Settings -->
<string name="pref_header_notifications">Notifications</string>
<string name="pref_title_new_message_notifications">New message notifications</string>
<string name="pref_title_ringtone">Ringtone</string>
<string name="pref_ringtone_silent">Silent</string>
<string name="pref_title_vibrate">Vibrate</string>