Skip to content

Commit 66448a2

Browse files
authored
Merge pull request #11 from norkator/feature/translation-improvements
Translation improvements
2 parents 02311fc + 7a24fdd commit 66448a2

File tree

17 files changed

+553
-265
lines changed

17 files changed

+553
-265
lines changed

app/src/main/java/com/nitramite/apcupsdmonitor/CustomUpsAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.nitramite.apcupsdmonitor;
22

33
import android.app.Activity;
4-
import android.util.Log;
54
import android.view.LayoutInflater;
65
import android.view.View;
76
import android.view.ViewGroup;
@@ -50,8 +49,8 @@ public View getView(int position, View view, ViewGroup parent) {
5049
name.setText(upsArrayList.get(position).getUPS_NAME());
5150

5251
model.setText(upsArrayList.get(position).getMODEL());
53-
lineVoltageOnly.setText(upsArrayList.get(position).getLineVoltageOnlyStr());
54-
batteryVoltageOnly.setText(upsArrayList.get(position).getBatteryVoltageOnlyStr());
52+
lineVoltageOnly.setText(upsArrayList.get(position).getLineVoltageOnlyStr(rowView.getContext()));
53+
batteryVoltageOnly.setText(upsArrayList.get(position).getBatteryVoltageOnlyStr(rowView.getContext()));
5554

5655
// Set status (Always shown)
5756
status.setText(upsArrayList.get(position).getSTATUS());
@@ -64,7 +63,8 @@ public View getView(int position, View view, ViewGroup parent) {
6463

6564
// Set battery charge level
6665
chargePB.setValue(upsArrayList.get(position).getBatteryChargeLevelInteger());
67-
percentageTv.setText(String.valueOf(upsArrayList.get(position).getBatteryChargeLevelInteger()) + "%");
66+
String getBatteryChargeLevelInteger = upsArrayList.get(position).getBatteryChargeLevelInteger() + "%";
67+
percentageTv.setText(getBatteryChargeLevelInteger);
6868

6969
return rowView;
7070
}

app/src/main/java/com/nitramite/apcupsdmonitor/MainMenu.java

Lines changed: 47 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,14 @@ private void directionRightEdit(final int swipePosition) {
214214

215215
private void deleteItemConfirmationDialog(final int swipePosition) {
216216
new AlertDialog.Builder(MainMenu.this)
217-
.setTitle("Delete item")
218-
.setMessage("Are you sure you want to delete this UPS item?")
219-
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
220-
@Override
221-
public void onClick(DialogInterface dialog, int which) {
222-
databaseHelper.deleteUps(upsArrayList.get(swipePosition).UPS_ID);
223-
MainMenu.this.getUpsData();
224-
}
217+
.setTitle(R.string.delete_item)
218+
.setMessage(R.string.delete_item_message)
219+
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
220+
databaseHelper.deleteUps(upsArrayList.get(swipePosition).UPS_ID);
221+
MainMenu.this.getUpsData();
225222
})
226-
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
227-
@Override
228-
public void onClick(DialogInterface dialog, int which) {
229-
// Return
230-
}
223+
.setNegativeButton(android.R.string.no, (dialog, which) -> {
224+
// Return
231225
})
232226
.setIcon(R.mipmap.logo)
233227
.show();
@@ -242,9 +236,9 @@ public void noUpsConfigured() {
242236
runOnUiThread(() -> {
243237
closeProgressDialog();
244238
new AlertDialog.Builder(MainMenu.this)
245-
.setTitle("No UPS devices")
246-
.setMessage("To configure your first UPS device, close this dialog and click right bottom corner add UPS floating button.")
247-
.setNegativeButton("Close", (dialogInterface, i) -> {
239+
.setTitle(R.string.no_ups_devices_title)
240+
.setMessage(R.string.no_ups_devices_message)
241+
.setNegativeButton(R.string.close, (dialogInterface, i) -> {
248242
})
249243
.setIcon(R.mipmap.logo)
250244
.show();
@@ -259,23 +253,18 @@ public void run() {
259253
closeProgressDialog();
260254
new AlertDialog.Builder(MainMenu.this)
261255
.setIcon(R.mipmap.logo)
262-
.setMessage("Trust host " + hostName + " with following key finger print: " + "\n\n" + hostFingerPrint)
256+
.setMessage(getString(R.string.trust_host) + " " + hostName + " " + getString(R.string.with_following_key_fingerprint) + "\n\n" + hostFingerPrint)
263257
.setCancelable(false)
264-
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
265-
public void onClick(DialogInterface dialog, int id) {
266-
ContentValues contentValues = new ContentValues();
267-
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_NAME, hostName);
268-
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_FINGER_PRINT, hostFingerPrint);
269-
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_KEY, hostKey);
270-
databaseHelper.insertUpdateUps(upsId, contentValues);
271-
startConnectorTask(); // Load again
272-
}
273-
})
274-
.setNegativeButton("No", new DialogInterface.OnClickListener() {
275-
public void onClick(DialogInterface dialog, int id) {
276-
genericSuccessDialog("Note", "You must either accept host fingerprint or disable strict host key checking from app settings");
277-
}
258+
.setPositiveButton(R.string.yes, (dialog, id) -> {
259+
ContentValues contentValues = new ContentValues();
260+
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_NAME, hostName);
261+
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_FINGER_PRINT, hostFingerPrint);
262+
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_KEY, hostKey);
263+
databaseHelper.insertUpdateUps(upsId, contentValues);
264+
startConnectorTask(); // Load again
278265
})
266+
.setNegativeButton(R.string.no, (dialog, id) ->
267+
genericSuccessDialog(getString(R.string.note), getString(R.string.host_fingerprint_message)))
279268
.show();
280269
}
281270
});
@@ -314,18 +303,10 @@ public void onMissingPreferences() {
314303
// Generic use success dialog
315304
private void checkYourPreferencesDialog() {
316305
new AlertDialog.Builder(MainMenu.this)
317-
.setTitle("Missing settings")
318-
.setMessage("SSH Connection properties are not set yet or not set properly. Check your preferences. " +
319-
"You must provide at least server address, username and either password or private key depending on your server ssh setup.")
320-
.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
321-
public void onClick(DialogInterface dialog, int which) {
322-
startActivityForResult(new Intent(MainMenu.this, Preferences.class), 200);
323-
}
324-
})
325-
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
326-
@Override
327-
public void onClick(DialogInterface dialogInterface, int i) {
328-
}
306+
.setTitle(R.string.missing_settings)
307+
.setMessage(R.string.ssh_connection_properties_not_set_message)
308+
.setPositiveButton(R.string.open_settings, (dialog, which) -> startActivityForResult(new Intent(MainMenu.this, Preferences.class), 200))
309+
.setNegativeButton(R.string.close, (dialogInterface, i) -> {
329310
})
330311
.setIcon(R.mipmap.logo)
331312
.show();
@@ -347,27 +328,23 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
347328

348329
@Override
349330
public void onConnectionError() {
350-
runOnUiThread(new Runnable() {
351-
@Override
352-
public void run() {
353-
closeProgressDialog();
354-
genericErrorDialog("Error", "Connection error. Verify your address, port, username, password/private key.\n\n" +
355-
"If target is remove server, ensure that it has specified port available (port forwarding).\n\n" +
356-
"Target server has apcupsd daemon running and for example command '" + sharedPreferences.getString(Constants.SP_STATUS_COMMAND, "sudo apcaccess status") + "' is working.\n\n" +
357-
"In case you are using direct APCUPSD TCP port connection, see setup tutorial for testing connection."
358-
);
359-
}
331+
runOnUiThread(() -> {
332+
closeProgressDialog();
333+
genericErrorDialog(getString(R.string.error),
334+
getString(R.string.connection_error_one) + "\n\n" +
335+
getString(R.string.connection_error_two) + "\n\n" +
336+
getString(R.string.connection_error_three) + " '" + sharedPreferences.getString(Constants.SP_STATUS_COMMAND, "sudo apcaccess status") + "' " +
337+
getString(R.string.connection_error_four) +
338+
getString(R.string.connection_error_five)
339+
);
360340
});
361341
}
362342

363343
@Override
364344
public void onCommandError(final String errorStr) {
365-
runOnUiThread(new Runnable() {
366-
@Override
367-
public void run() {
368-
closeProgressDialog();
369-
genericErrorDialog("Error", "Command error. Result: " + errorStr);
370-
}
345+
runOnUiThread(() -> {
346+
closeProgressDialog();
347+
genericErrorDialog(getString(R.string.error), getString(R.string.command_error_result) + " " + errorStr);
371348
});
372349
}
373350

@@ -397,7 +374,7 @@ private void genericSuccessDialog(final String title, final String description)
397374
new AlertDialog.Builder(MainMenu.this)
398375
.setTitle(title)
399376
.setMessage(description)
400-
.setPositiveButton("Close", (dialog, which) -> {
377+
.setPositiveButton(R.string.close, (dialog, which) -> {
401378
})
402379
.setIcon(R.mipmap.ic_launcher_round)
403380
.show();
@@ -409,21 +386,17 @@ private void genericErrorDialog(final String title, final String description) {
409386
new AlertDialog.Builder(MainMenu.this)
410387
.setTitle(title)
411388
.setMessage(description)
412-
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
413-
public void onClick(DialogInterface dialog, int which) {
414-
}
389+
.setPositiveButton(R.string.close, (dialog, which) -> {
415390
})
416-
.setNeutralButton("Copy content", new DialogInterface.OnClickListener() {
417-
public void onClick(DialogInterface dialog, int which) {
418-
try {
419-
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
420-
ClipData clip = ClipData.newPlainText("", description);
421-
assert clipboard != null;
422-
clipboard.setPrimaryClip(clip);
423-
Toast.makeText(MainMenu.this, "Content copied to clipboard", Toast.LENGTH_SHORT).show();
424-
} catch (IndexOutOfBoundsException e) {
425-
Toast.makeText(MainMenu.this, "There was nothing to copy", Toast.LENGTH_LONG).show();
426-
}
391+
.setNeutralButton(R.string.copy_content, (dialog, which) -> {
392+
try {
393+
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
394+
ClipData clip = ClipData.newPlainText("", description);
395+
assert clipboard != null;
396+
clipboard.setPrimaryClip(clip);
397+
Toast.makeText(MainMenu.this, R.string.content_copied, Toast.LENGTH_SHORT).show();
398+
} catch (IndexOutOfBoundsException e) {
399+
Toast.makeText(MainMenu.this, R.string.nothing_to_copy, Toast.LENGTH_LONG).show();
427400
}
428401
})
429402
.setIcon(R.drawable.ic_error_small)

app/src/main/java/com/nitramite/apcupsdmonitor/StatusService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void onTaskCompleted() {
5050
Log.i(TAG, "onTaskCompleted");
5151
try {
5252
if (databaseHelper.isAnyUpsDown()) {
53-
showNotification(context, "Warning", "Non online status change detected!");
53+
showNotification(context, context.getString(R.string.warning), context.getString(R.string.non_online_status_change_detected));
5454
}
5555
} catch (NullPointerException ignored) {
5656
}

app/src/main/java/com/nitramite/apcupsdmonitor/UPS.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.nitramite.apcupsdmonitor;
22

3+
import android.content.Context;
34
import android.util.Log;
45

56
// UPS Object
@@ -162,57 +163,57 @@ public Boolean isOnline() {
162163
this.getSTATUS().equals("UPS OL CHRG"); // UPSC
163164
}
164165

165-
public String getLineVoltageStr() {
166-
return (this.LINE_VOLTAGE == null ? "-" : this.LINE_VOLTAGE + " line voltage");
166+
public String getLineVoltageStr(Context context) {
167+
return (this.LINE_VOLTAGE == null ? "-" : this.LINE_VOLTAGE + " " + context.getString(R.string.ups_line_voltage));
167168
}
168169

169-
public String getLineVoltageOnlyStr() {
170-
return (this.LINE_VOLTAGE == null ? "-" : this.LINE_VOLTAGE.replace("Volts line voltage", "").replace("Volts", "").replace(" ", "") + "V");
170+
public String getLineVoltageOnlyStr(Context context) {
171+
return (this.LINE_VOLTAGE == null ? "-" : this.LINE_VOLTAGE.replace(context.getString(R.string.ups_volts_line_voltage), "").replace("Volts", "").replace(" ", "") + "V");
171172
}
172173

173174

174-
public String getLoadPercentStr() {
175-
return (this.LOAD_PERCENT == null ? "Not available" : LOAD_PERCENT + " of load");
175+
public String getLoadPercentStr(Context context) {
176+
return (this.LOAD_PERCENT == null ? context.getString(R.string.ups_not_available) : LOAD_PERCENT + " " + context.getString(R.string.ups_of_load));
176177
}
177178

178179
public Integer getLoadPercentInteger() {
179180
return (this.LOAD_PERCENT == null ? null : Integer.parseInt(LOAD_PERCENT.replace(" ", "").split("\\.")[0]));
180181
}
181182

182183

183-
public String getBatteryChargeLevelStr() {
184-
return (this.BATTERY_CHARGE_LEVEL == null ? "N/A Charge level" : BATTERY_CHARGE_LEVEL + " battery charge");
184+
public String getBatteryChargeLevelStr(Context context) {
185+
return (this.BATTERY_CHARGE_LEVEL == null ? context.getString(R.string.ups_na_charge_level) : BATTERY_CHARGE_LEVEL + " " + context.getString(R.string.ups_battery_charge));
185186
}
186187

187188
public Integer getBatteryChargeLevelInteger() {
188189
return (this.BATTERY_CHARGE_LEVEL == null ? -1 : Integer.parseInt(BATTERY_CHARGE_LEVEL.replace(" ", "").split("\\.")[0]));
189190
}
190191

191192

192-
public String getBATTERY_TIME_LEFT() {
193-
return (this.BATTERY_TIME_LEFT == null ? "Battery time left N/A" : "Battery time left: " + this.BATTERY_TIME_LEFT);
193+
public String getBATTERY_TIME_LEFT(Context context) {
194+
return (this.BATTERY_TIME_LEFT == null ? context.getString(R.string.ups_battery_time_left_na) : context.getString(R.string.ups_battery_time_left) + ": " + this.BATTERY_TIME_LEFT);
194195
}
195196

196197

197-
public String getLastTransferReasonStr() {
198-
return (this.LAST_TRANSFER_REASON == null ? "Last transfer reason N/A" : "Last: " + this.LAST_TRANSFER_REASON);
198+
public String getLastTransferReasonStr(Context context) {
199+
return (this.LAST_TRANSFER_REASON == null ? context.getString(R.string.ups_last_transfer_reason_na) : context.getString(R.string.ups_last) + ": " + this.LAST_TRANSFER_REASON);
199200
}
200201

201202

202-
public String getBatteryVoltageOnlyStr() {
203+
public String getBatteryVoltageOnlyStr(Context context) {
203204
return (BATTERY_VOLTAGE == null ? "N/A" : BATTERY_VOLTAGE.replace("Volts", "").replace(" ", "") + "V");
204205
}
205206

206-
public String getBATTERY_DATE() {
207-
return (BATTERY_DATE == null ? "Battery date N/A" : "Battery date " + BATTERY_DATE);
207+
public String getBATTERY_DATE(Context context) {
208+
return (BATTERY_DATE == null ? context.getString(R.string.ups_battery_date_na) : context.getString(R.string.ups_battery_date) + " " + BATTERY_DATE);
208209
}
209210

210211
public String getFIRMWARE() {
211212
return (this.FIRMWARE == null ? "N/A" : this.FIRMWARE);
212213
}
213214

214-
public String getSTART_TIME() {
215-
return (this.START_TIME == null ? "Start time N/A" : "Start time: " + this.START_TIME);
215+
public String getSTART_TIME(Context context) {
216+
return (this.START_TIME == null ? context.getString(R.string.ups_start_time_na) : context.getString(R.string.ups_start_time) + ": " + this.START_TIME);
216217
}
217218

218219
public String getLAST_SECONDS_ON_BATTERY() {

0 commit comments

Comments
 (0)