Skip to content

Commit

Permalink
Merge branch 'gablau-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
glynhudson committed Apr 14, 2017
2 parents 5cd0367 + 3ef6146 commit e147694
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/emoncms/myapps/EmonApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public String addAccount() {
}

public void addFirstPage() {
MyElectricSettings defaultPage = new MyElectricSettings(0,"My Electric",-1,-1,"1","0","£");
MyElectricSettings defaultPage = new MyElectricSettings(0,"My Electric",-1,-1,"1","0","£","");
int id = EmonDatabaseHelper.getInstance(this).addPage(currentAccount,defaultPage);
defaultPage.setId(id);
if (currentAccount.equals(currentAccount)) {
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/org/emoncms/myapps/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
Expand All @@ -33,6 +38,7 @@
import org.emoncms.myapps.settings.AccountSettingsActivity;
import org.emoncms.myapps.settings.SettingsActivity;


/**
* Handles navigation, account changing and pager
*/
Expand Down Expand Up @@ -141,8 +147,7 @@ protected void onCreate(Bundle savedInstanceState) {

EmonApplication.get().addAccountChangeListener(this);


}
}

@Override
protected void onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ private void updateTextFields() {
try {
if (powerCostSymbol.equals("0"))
powerCostSymbol = Currency.getInstance(Locale.getDefault()).getSymbol();
if (powerCostSymbol.equals("custom"))
powerCostSymbol = myElectricSettings.getCustomCurrencySymbol();
} catch (IllegalArgumentException e) {
powerCostSymbol = "£";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
settings = getIntent().getExtras().getParcelable("settings");
} else {
String defaultName = getResources().getString(R.string.settings_title_page_name_default);
settings = new MyElectricSettings(0,defaultName,-1,-1,"1", "0","£");
settings = new MyElectricSettings(0,defaultName,-1,-1,"1", "0","£","");
}

setContentView(R.layout.activity_ms_settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MyElectricSettingsFragment extends Fragment {
Spinner currencyPreference;
Spinner scalePreference;
EditText unitCostPreference;
EditText customCurrencyPreference;
Handler mHandler = new Handler();
SharedPreferences sp;

Expand Down Expand Up @@ -79,15 +80,15 @@ public View onCreateView(LayoutInflater inflater,
namePreference = (EditText) result.findViewById(R.id.page_name);
currencyPreference = (Spinner) result.findViewById(R.id.currency);
unitCostPreference = (EditText) result.findViewById(R.id.costUnit);
customCurrencyPreference = (EditText) result.findViewById(R.id.customCurrency);

ArrayAdapter<CharSequence> costUnitArray = ArrayAdapter.createFromResource(result.getContext(),R.array.me_cost_text, R.layout.support_simple_spinner_dropdown_item);
currencyPreference.setAdapter(costUnitArray);
currencyPreference.setSelection(costSymbolToIndex(settings.getCostSymbol()));

unitCostPreference.setText(""+settings.getUnitCost());



customCurrencyPreference.setText(settings.getCustomCurrencySymbol());

namePreference.setText(settings.getName());
return(result);
Expand Down Expand Up @@ -167,7 +168,9 @@ private void savePage() {
String[] symbolArray = getActivity().getResources().getStringArray(R.array.me_cost_values);

String currencySymbol = symbolArray[currencyPreference.getSelectedItemPosition()];

settings.setCostSymbol(currencySymbol);
settings.setCustomCurrencySymbol(customCurrencyPreference.getText().toString());


Log.w("settings", "Setting Cost Symbol to " + currencySymbol);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/emoncms/myapps/UpgradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void upgradeToMultiAccount(Activity mActivity, SharedPreferences s

accountPrefs.commit();

MyElectricSettings settings = new MyElectricSettings(0, "My Electric", Integer.parseInt(powerFeed), Integer.parseInt(useFeed), scaleValue, unitCost, costSymbol);
MyElectricSettings settings = new MyElectricSettings(0, "My Electric", Integer.parseInt(powerFeed), Integer.parseInt(useFeed), scaleValue, unitCost, costSymbol, "");
EmonApplication.get().addPage(settings);

AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void setFormatting() {
barChart.getDescription().setEnabled(false);
barChart.setNoDataText("");
barChart.setTouchEnabled(false);
barChart.setExtraBottomOffset(4);
barChart.setExtraBottomOffset(2);

XAxis xAxis2 = barChart.getXAxis();
xAxis2.setPosition(XAxis.XAxisPosition.BOTTOM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MyElectricSettings implements Parcelable {
private String unitCost;
private String costSymbol;
private String powerScale;
private String customCurrencySymbol;
private float powerScaleFloat;
private float unitCostFloat;
private boolean deleted = false;
Expand All @@ -37,10 +38,11 @@ public static MyElectricSettings fromJson(int id, JSONObject jsonObject) throws
jsonObject.getInt("useFeedId"),
jsonObject.getString("powerScale"),
jsonObject.getString("unitCost"),
jsonObject.getString("costSymbol"));
jsonObject.getString("costSymbol"),
jsonObject.getString("customCurrencySymbol"));
}

public MyElectricSettings(int id, String name, int powerFeedId, int useFeedId, String powerScale, String unitCost, String costSymbol) {
public MyElectricSettings(int id, String name, int powerFeedId, int useFeedId, String powerScale, String unitCost, String costSymbol, String customCurrencySymbol) {
this.id = id;
this.name = name;
this.powerFeedId = powerFeedId;
Expand All @@ -50,6 +52,7 @@ public MyElectricSettings(int id, String name, int powerFeedId, int useFeedId, S
this.powerScale = powerScale;
this.powerScaleFloat = stringToFloat(powerScale);
this.unitCostFloat = stringToFloat(unitCost);
this.customCurrencySymbol = customCurrencySymbol;
}

public MyElectricSettings(Parcel in) {
Expand All @@ -60,6 +63,7 @@ public MyElectricSettings(Parcel in) {
this.powerScale = in.readString();
this.unitCost = in.readString();
this.costSymbol = in.readString();
this.customCurrencySymbol = in.readString();
this.powerScaleFloat = stringToFloat(powerScale);
this.unitCostFloat = stringToFloat(unitCost);
}
Expand Down Expand Up @@ -113,6 +117,10 @@ public String getCostSymbol() {
return costSymbol;
}

public String getCustomCurrencySymbol() {
return customCurrencySymbol;
}

public void setUseFeedId(int useFeedId) {
this.useFeedId = useFeedId;
}
Expand All @@ -129,6 +137,10 @@ public void setCostSymbol(String costSymbol) {
this.costSymbol = costSymbol;
}

public void setCustomCurrencySymbol(String customCurrencySymbol) {
this.customCurrencySymbol = customCurrencySymbol;
}

public void setUnitCost(String unitCost) {

this.unitCost = unitCost;
Expand All @@ -154,6 +166,7 @@ public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(powerScale);
parcel.writeString(unitCost);
parcel.writeString(costSymbol);
parcel.writeString(customCurrencySymbol);
}

public String toJson() throws Exception {
Expand All @@ -164,6 +177,7 @@ public String toJson() throws Exception {
jsonObject.put("powerScale",powerScale);
jsonObject.put("unitCost",unitCost);
jsonObject.put("costSymbol",costSymbol);
jsonObject.put("customCurrencySymbol",customCurrencySymbol);
return jsonObject.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;

import org.emoncms.myapps.BuildConfig;
import org.emoncms.myapps.MainActivity;
import org.emoncms.myapps.R;

Expand All @@ -21,6 +23,10 @@ public class AppSettingsFragment extends PreferenceFragment implements SharedPre
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.main_preferences);

Preference mypref = findPreference("appinfo");
mypref.setTitle(getString(R.string.settings_title_app_information)+" "+ BuildConfig.VERSION_NAME);

}

@Override
Expand All @@ -40,8 +46,6 @@ public void onPause() {
@Override
public void onActivityCreated(Bundle savesInstanceState) {
super.onActivityCreated(savesInstanceState);


}

@Override
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout-land/page_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_title_myelectric_custom_currency"
android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
android:id="@+id/customCurrency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="3" />

</LinearLayout>
</ScrollView>
12 changes: 12 additions & 0 deletions app/src/main/res/layout/page_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@
android:id="@+id/currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_title_myelectric_custom_currency"
android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
android:id="@+id/customCurrency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="3" />
</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@
<string name="settings_title_page_name_default">Neue Seite</string>
<string name="menu_add_page">Seite Hinzufügen</string>

<string name="custom">custom</string>
<string name="settings_title_myelectric_custom_currency">Custom currency</string>
<string name="settings_title_app_information">APP VERSION: </string>

</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,9 @@
<string name="settings_title_page_name">Nom de la page</string>
<string name="settings_title_page_name_default">Nouvelle page</string>
<string name="menu_add_page">Ajouter une page</string>

<string name="custom">custom</string>
<string name="settings_title_myelectric_custom_currency">Custom currency</string>
<string name="settings_title_app_information">APP VERSION: </string>
</resources>

20 changes: 12 additions & 8 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@
<string name="qr_code_fail">QR code non valido</string>
<string name="barcode_scan_instructions">Eseguire la scansione del codice a barre nella pagina dell\'account di emoncms.</string>

<string name="monday_initial">lu</string>
<string name="tuesday_initial">ma</string>
<string name="wednesday_initial">me</string>
<string name="thursday_initial">gi</string>
<string name="friday_initial">ve</string>
<string name="saturday_initial">sa</string>
<string name="sunday_initial">do</string>
<string name="monday_initial">Lu</string>
<string name="tuesday_initial">Ma</string>
<string name="wednesday_initial">Me</string>
<string name="thursday_initial">Gi</string>
<string name="friday_initial">Ve</string>
<string name="saturday_initial">Sa</string>
<string name="sunday_initial">Do</string>

<string name="system_locale">Lingua di Sistema</string>
<string name="dollars">Dollari</string>
<string name="pounds">Sterline</string>
<string name="euros">Euro</string>
<string name="yen">Yen</string>
<string name="custom">Personalizzata</string>

<string name="kwh_elapsed">kWh consumati</string>
<string name="wh_elapsed">Watt ora consumati</string>
Expand Down Expand Up @@ -93,6 +94,7 @@

<string name="settings_title_myelectric_feeds">Feed</string>
<string name="settings_title_myelectric_currency">Valuta</string>
<string name="settings_title_myelectric_custom_currency">Valuta personalizzata</string>
<string name="settings_title_myelectric_page_name">Nome Pagina</string>
<string name="settings_title_myelectric_power_feed">Feed potenza (Watts)</string>
<string name="settings_title_myelectric_kwh_feed">Grafico a barre (kWh)</string>
Expand All @@ -106,10 +108,12 @@
<string name="cancel">ANNULLA</string>
<string name="settings_confirm_delete_account">Sei sicuro di voler cancellare questo account? Tutte le impostazioni andranno perse.</string>
<string name="settings_confirm_delete_page">Sei sicuro di voler cancellare questa pagina?"</string>
<string name="settings_title_accounts">CONTI</string>
<string name="settings_title_accounts">ACCOUNT</string>
<string name="settings_title_add_account">Aggiungi Account</string>
<string name="settings_title_page_name">Nome Pagina</string>
<string name="settings_title_page_name_default">Nuova pagina</string>
<string name="menu_add_page">Aggiungi pagina</string>

<string name="settings_title_app_information">VERSIONE APP: </string>
</resources>

4 changes: 4 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@
<string name="menu_add_page">Pagina toevoegen</string>
<string name="settings_title_page_name_default">Pagina toevoegen</string>

<string name="custom">custom</string>
<string name="settings_title_myelectric_custom_currency">Custom currency</string>
<string name="settings_title_app_information">APP VERSION: </string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<item>@string/pounds</item>
<item>@string/euros</item>
<item>@string/yen</item>
<item>@string/custom</item>
</string-array>

<string-array name="me_cost_values" translatable="false">
Expand All @@ -23,6 +24,7 @@
<item>£</item>
<item>€</item>
<item>¥</item>
<item>custom</item>
</string-array>

<string-array name="day_of_week_initials">
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<string name="pounds">Pounds</string>
<string name="euros">Euros</string>
<string name="yen">Yen</string>
<string name="custom">Custom</string>

<string name="kwh_elapsed">kWh elapsed</string>
<string name="wh_elapsed">Watt hours elapsed</string>
Expand Down Expand Up @@ -127,6 +128,7 @@
<string name="settings_title_page_name_default">New page</string>
<string name="settings_title_myelectric_feeds">Feeds</string>
<string name="settings_title_myelectric_currency">Currency</string>
<string name="settings_title_myelectric_custom_currency">Custom currency</string>
<string name="settings_title_myelectric_page_name">Page Name</string>
<string name="settings_title_myelectric_power_feed">Power feed (Watts)</string>
<string name="settings_title_myelectric_kwh_feed">"Bar graph feed (kWh)</string>
Expand All @@ -141,5 +143,8 @@
<string name="no_camera_found">No camera found for barcode scanning.</string>
<string name="menu_add_page">Add Page</string>

<string name="settings_title_app_information">APP VERSION: </string>



</resources>
Loading

0 comments on commit e147694

Please sign in to comment.