Commit 053cddb4 authored by Roger Barton's avatar Roger Barton
Browse files

Language choice fully implemented

Only flaw is that when changing language user may have to restart app for certain strings to display correctly
parent 9c440235
......@@ -7,7 +7,7 @@ android {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
......
......@@ -17,11 +17,12 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:name=".MyApplication"
android:theme="@style/AppThemeLight">
<activity
android:name=".SettingsActivity"
android:label=""
android:configChanges="layoutDirection|locale"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
......@@ -29,7 +30,7 @@
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:configChanges="keyboardHidden|orientation|layoutDirection|screenSize|locale"
android:label="@string/app_name"
android:theme="@style/AppThemeLight"
android:windowSoftInputMode="adjustNothing">
......@@ -42,7 +43,7 @@
</activity>
<activity
android:name=".LoginActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:configChanges="keyboardHidden|orientation|layoutDirection|screenSize|locale"
android:label=""
android:windowSoftInputMode="stateVisible">
<meta-data
......@@ -51,6 +52,7 @@
</activity>
<activity
android:name=".EventDetailActivity"
android:configChanges="orientation|layoutDirection|locale"
android:theme="@style/AppThemeLight">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
......@@ -58,6 +60,7 @@
</activity>
<activity android:name=".BarcodeIdActivity"
android:screenOrientation="portrait"
android:configChanges="layoutDirection|locale"
android:parentActivityName=".MainActivity">
</activity>
......
package ch.amiv.android_app;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
......@@ -71,8 +72,11 @@ public class BarcodeIdActivity extends AppCompatActivity {
* Will generate a barcode bitmap and apply it to the barcodeImageview. Note: barcode will not fill whole constraint as the width of the bars is determined in pixels, to prevent distortion
*/
public void GenerateBarcode(){
if(UserInfo.current == null || (UserInfo.current.nethz.isEmpty() && UserInfo.current.email.isEmpty()))
if(UserInfo.current == null || (UserInfo.current.nethz.isEmpty() && UserInfo.current.email.isEmpty())){
Snackbar.make(swipeRefreshLayout, R.string.not_logged_in, Snackbar.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
return;
}
//prioritise nethz as this is shorter
String encode = UserInfo.current.nethz.isEmpty() ? UserInfo.current.email : UserInfo.current.nethz;
......
......@@ -128,8 +128,8 @@ public class EventDetailActivity extends AppCompatActivity {
}
//Link up variables with UI elements from the layout xml
((TextView) findViewById(R.id.eventTitle)).setText(Events.eventInfos.get(eventIndex).title_en);
((TextView)findViewById(R.id.eventDetail)).setText(Events.eventInfos.get(eventIndex).description_en);
((TextView) findViewById(R.id.eventTitle)).setText(Events.eventInfos.get(eventIndex).GetTitle(getResources()));
((TextView)findViewById(R.id.eventDetail)).setText(Events.eventInfos.get(eventIndex).GetDescription(getResources()));
scrollView = findViewById(R.id.scrollView_event);
posterProgress = findViewById(R.id.progressBar);
posterImage = findViewById(R.id.eventPoster);
......@@ -307,14 +307,14 @@ public class EventDetailActivity extends AppCompatActivity {
});
//Interpret notification to show from the signup
String notification = "";
int notification = 0;
if(Events.eventInfos.get(eventIndex).accepted) {
if(Events.eventInfos.get(eventIndex).confirmed)
notification = "Successfully Registered";
notification = R.string.register_success;
else
notification = "Registered, please confirm with mail";
notification = R.string.register_success_confirm_required;
} else
notification = "Added to Waiting List";
notification = R.string.added_to_waiting_list;
Snackbar.make(scrollView, notification, Snackbar.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
......
......@@ -66,8 +66,8 @@ public class EventDetailFragment extends Fragment {
TextView content = getView().findViewById(R.id.eventDetail);
final ImageView poster = getView().findViewById(R.id.eventPoster);
title.setText(Events.eventInfos.get(eventIndex).title_en);
content.setText(Events.eventInfos.get(eventIndex).description_en);
title.setText(Events.eventInfos.get(eventIndex).GetTitle(getResources()));
content.setText(Events.eventInfos.get(eventIndex).GetDescription(getResources()));
String posterUrl = "https://www.amiv.ethz.ch/sites/all/themes/amiv15/logo.png";
ImageRequest posterRequest = new ImageRequest(posterUrl,
......
package ch.amiv.android_app;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.Log;
......@@ -10,6 +11,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
/**
* This is all the data about one event AND the current users signup data about that event
......@@ -17,12 +19,12 @@ import java.util.Date;
public class EventInfo {
//region - ====Variables====
public String _id;
public String title_de;
public String title_en;
public String catchphrase_de;
public String catchphrase_en;
public String description_de;
public String description_en;
private String title_de;
private String title_en;
private String catchphrase_de;
private String catchphrase_en;
private String description_de;
private String description_en;
public String location;
public String price;
public String priority;
......@@ -161,10 +163,10 @@ public class EventInfo {
if(infos != null && infos.size() > 0)
return infos;
DateFormat dateFormat = new SimpleDateFormat("dd - MMM - yyyy HH:mm");
DateFormat dateFormat = new SimpleDateFormat("dd - MMM - yyyy HH:mm", r.getConfiguration().locale);
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(!price.isEmpty()) infos.add(new String[]{ r.getString(R.string.price), (price.equalsIgnoreCase("0") ? r.getString(R.string.price_free) : price + " CHF")});
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)});
......@@ -175,6 +177,31 @@ public class EventInfo {
return infos;
}
public String GetTitle (Resources res)
{
Locale locale = res.getConfiguration().locale;
if(res.getConfiguration().locale.equals(Locale.GERMAN) && !title_de.isEmpty())
return title_de;
else
return title_en;
}
public String GetDescription(Resources res)
{
if(res.getConfiguration().locale.equals(Locale.GERMAN) && !description_de.isEmpty())
return description_de;
else
return description_en;
}
public String GetCatchphrase(Resources res)
{
if(res.getConfiguration().locale.equals(Locale.GERMAN) && !catchphrase_de.isEmpty())
return catchphrase_de;
else
return catchphrase_en;
}
public boolean IsSignedUp ()
{
return !signup_id.isEmpty();
......
package ch.amiv.android_app;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -37,6 +39,7 @@ public final class Events {
public static void AddSignupArray(JSONArray json) {
boolean[] hasUpdatedEvent = new boolean[eventInfos.size()];
signupLoop:
for (int i = 0; i < json.length(); i++) {
try {
JSONObject signup = json.getJSONObject(i);
......@@ -46,8 +49,10 @@ public final class Events {
if (!hasUpdatedEvent[j] && event.equals(eventInfos.get(j)._id)) {
Events.eventInfos.get(j).AddSignup(signup);
hasUpdatedEvent[j] = true;
continue signupLoop;
}
}
Log.e("events", "Received signup for event that does not exist locally, event id:" + signup.getString("event"));
}
}
catch (JSONException e){
......
......@@ -121,8 +121,8 @@ public class EventsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
final EventInfoHolder eventInfoHolder = (EventInfoHolder)holder;
final int eventIndex = holder.getAdapterPosition() - 1;
final EventInfo e = Events.eventInfos.get(eventIndex);
eventInfoHolder.titleField.setText(e.title_en);
eventInfoHolder.catchphraseField.setText(e.catchphrase_en);
eventInfoHolder.titleField.setText(e.GetTitle(activity.getResources()));
eventInfoHolder.catchphraseField.setText(e.GetCatchphrase(activity.getResources()));
eventInfoHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -145,7 +145,7 @@ public class EventsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
else {
eventInfoHolder.statusImage.setVisibility(View.GONE);
eventInfoHolder.placesField.setVisibility(View.VISIBLE);
eventInfoHolder.placesField.setText((e.spots == 0 ? "" : "" + (e.spots - e.signup_count)));
eventInfoHolder.placesField.setText("" + Math.max(0, e.spots - e.signup_count));
}
break;
}
......
package ch.amiv.android_app;
import android.app.Application;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import java.util.Locale;
public class MyApplication extends Application
{
private Locale locale = null;
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (locale != null)
{
newConfig.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
}
@Override
public void onCreate()
{
super.onCreate();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getBaseContext().getResources().getConfiguration();
String lang = settings.getString(getString(R.string.pref_lang_key), "");
if (!lang.isEmpty() && !config.locale.getLanguage().equals(lang))
{
locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
}
}
\ No newline at end of file
......@@ -166,6 +166,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
//update summary
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, newValue);
//Restart app to apply language
Intent i = getActivity().getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getActivity().getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
return true;
}
});
......
<resources>
<!-- Titles -->
<string name="title">AMIV</string>
<string name="app_name">AMIV</string>
<string name="title_home">Home</string>
<string name="title_blitz">blitz</string>
......@@ -13,9 +14,10 @@
<!-- Language -->
<string name="pref_lang_title">Language - Sprache</string>
<string name="pref_lang_key">lang</string>
<string-array name="pref_lang_list_values">
<item>Deutsch</item>
<item>English</item>
<item>Deutsch</item>
</string-array>
<string-array name="pref_lang_list_entries">
<item>en</item>
......@@ -38,13 +40,17 @@
<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>
<string name="available_places">Restliche Plätze</string>
<string name="price_free">Gratis</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="register_success">Anmeldung Erfolgreich</string>
<string name="register_success_confirm_required">Angemeldet, bitte mit mail bestätigen</string>
<string name="added_to_waiting_list">Auf Warteliste gesetzt</string>
<string name="no_internet">Kein Internet</string>
<string name="requires_internet">Benötigt Internet</string>
......@@ -54,6 +60,38 @@
<string name="error_image_load">Fehler aufgetreten</string>
<string name="snack_error_retry">Fehler aufgetreten, bitte erneut versuchen</string>
<string name="pref_food_title">Essen Preferenz</string>
<string name="pref_food_key">food</string>
<string-array name="pref_food_list_values">
<item>Alles</item>
<item>Vegitarisch</item>
<item>Nichts</item>
</string-array>
<string-array name="pref_food_list_entries">
<item>all</item>
<item>veg</item>
<item>nothing</item>
</string-array>
<string name="pref_sbb_title">ÖV Abo</string>
<string name="pref_sbb_key">sbb_list</string>
<string-array name="pref_sbb_list_values">
<item>GA</item>
<item>Gleis7</item>
<item>Halx Tax</item>
<item>Kein Abo</item>
</string-array>
<string-array name="pref_sbb_list_entries">
<item>GA</item>
<item>G7</item>
<item>HT</item>
<item>NA</item>
</string-array>
<string name="pref_notifications_title">Benachrichtigungen</string>
<string name="pref_notifications_desc">Erhalte benachrichtigungen über events</string>
<string name="pref_notifications_key">notif_enabled</string>
......
<resources>
<!-- Titles -->
<string name="title">AMIV</string>
<string name="app_name">AMIV</string>
<string name="title_home">Home</string>
<string name="title_blitz">blitz</string>
......@@ -40,12 +41,16 @@
<string name="location">Location</string>
<string name="waiting_list_size">Waiting List Size</string>
<string name="available_places">Available Places</string>
<string name="price_free">Free</string>
<!-- Event Registering -->
<string name="register_title">Register</string>
<string name="register_end">Register End</string>
<string name="register_start">Register Start</string>
<string name="already_registered">Already Registered</string>
<string name="register_success">Successfully Registered</string>
<string name="register_success_confirm_required">Registered, please confirm with mail</string>
<string name="added_to_waiting_list">Added to Waiting List</string>
<string name="no_internet">No Internet</string>
<string name="requires_internet">Requires Internet</string>
......@@ -53,14 +58,14 @@
<!-- Errors -->
<string name="error_image_load">Error loading image</string>
<string name="snack_error_retry">An error occured, please retry</string>
<string name="snack_error_retry">An error occurred, please retry</string>
<!-- Settings -->
<string name="pref_food_title">Food Preference</string>
<string name="pref_food_key">food</string>
<string-array name="pref_food_list_values">
<item>Everything</item>
<item>Vegitarian</item>
<item>Vegetarian</item>
<item>Nothing</item>
</string-array>
<string-array name="pref_food_list_entries">
......
TODO list
=========
Bugs
====
interpret event dates, register start end, sort by date, advertise dates to hide/show
Features
========
Sort events upcoming and attended events, hide unattended old events
show event date in infos, if start end are not equal then show both, formatting
prevent refreshing events on rotate/slide, remove from onresume
......
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