Skip to content

Commit

Permalink
Merge pull request #11 from norkator/feature/translation-improvements
Browse files Browse the repository at this point in the history
Translation improvements
  • Loading branch information
norkator authored Oct 4, 2020
2 parents 02311fc + 7a24fdd commit 66448a2
Show file tree
Hide file tree
Showing 17 changed files with 553 additions and 265 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.nitramite.apcupsdmonitor;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -50,8 +49,8 @@ public View getView(int position, View view, ViewGroup parent) {
name.setText(upsArrayList.get(position).getUPS_NAME());

model.setText(upsArrayList.get(position).getMODEL());
lineVoltageOnly.setText(upsArrayList.get(position).getLineVoltageOnlyStr());
batteryVoltageOnly.setText(upsArrayList.get(position).getBatteryVoltageOnlyStr());
lineVoltageOnly.setText(upsArrayList.get(position).getLineVoltageOnlyStr(rowView.getContext()));
batteryVoltageOnly.setText(upsArrayList.get(position).getBatteryVoltageOnlyStr(rowView.getContext()));

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

// Set battery charge level
chargePB.setValue(upsArrayList.get(position).getBatteryChargeLevelInteger());
percentageTv.setText(String.valueOf(upsArrayList.get(position).getBatteryChargeLevelInteger()) + "%");
String getBatteryChargeLevelInteger = upsArrayList.get(position).getBatteryChargeLevelInteger() + "%";
percentageTv.setText(getBatteryChargeLevelInteger);

return rowView;
}
Expand Down
121 changes: 47 additions & 74 deletions app/src/main/java/com/nitramite/apcupsdmonitor/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,14 @@ private void directionRightEdit(final int swipePosition) {

private void deleteItemConfirmationDialog(final int swipePosition) {
new AlertDialog.Builder(MainMenu.this)
.setTitle("Delete item")
.setMessage("Are you sure you want to delete this UPS item?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
databaseHelper.deleteUps(upsArrayList.get(swipePosition).UPS_ID);
MainMenu.this.getUpsData();
}
.setTitle(R.string.delete_item)
.setMessage(R.string.delete_item_message)
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
databaseHelper.deleteUps(upsArrayList.get(swipePosition).UPS_ID);
MainMenu.this.getUpsData();
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Return
}
.setNegativeButton(android.R.string.no, (dialog, which) -> {
// Return
})
.setIcon(R.mipmap.logo)
.show();
Expand All @@ -242,9 +236,9 @@ public void noUpsConfigured() {
runOnUiThread(() -> {
closeProgressDialog();
new AlertDialog.Builder(MainMenu.this)
.setTitle("No UPS devices")
.setMessage("To configure your first UPS device, close this dialog and click right bottom corner add UPS floating button.")
.setNegativeButton("Close", (dialogInterface, i) -> {
.setTitle(R.string.no_ups_devices_title)
.setMessage(R.string.no_ups_devices_message)
.setNegativeButton(R.string.close, (dialogInterface, i) -> {
})
.setIcon(R.mipmap.logo)
.show();
Expand All @@ -259,23 +253,18 @@ public void run() {
closeProgressDialog();
new AlertDialog.Builder(MainMenu.this)
.setIcon(R.mipmap.logo)
.setMessage("Trust host " + hostName + " with following key finger print: " + "\n\n" + hostFingerPrint)
.setMessage(getString(R.string.trust_host) + " " + hostName + " " + getString(R.string.with_following_key_fingerprint) + "\n\n" + hostFingerPrint)
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_NAME, hostName);
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_FINGER_PRINT, hostFingerPrint);
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_KEY, hostKey);
databaseHelper.insertUpdateUps(upsId, contentValues);
startConnectorTask(); // Load again
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
genericSuccessDialog("Note", "You must either accept host fingerprint or disable strict host key checking from app settings");
}
.setPositiveButton(R.string.yes, (dialog, id) -> {
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_NAME, hostName);
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_FINGER_PRINT, hostFingerPrint);
contentValues.put(DatabaseHelper.UPS_SERVER_HOST_KEY, hostKey);
databaseHelper.insertUpdateUps(upsId, contentValues);
startConnectorTask(); // Load again
})
.setNegativeButton(R.string.no, (dialog, id) ->
genericSuccessDialog(getString(R.string.note), getString(R.string.host_fingerprint_message)))
.show();
}
});
Expand Down Expand Up @@ -314,18 +303,10 @@ public void onMissingPreferences() {
// Generic use success dialog
private void checkYourPreferencesDialog() {
new AlertDialog.Builder(MainMenu.this)
.setTitle("Missing settings")
.setMessage("SSH Connection properties are not set yet or not set properly. Check your preferences. " +
"You must provide at least server address, username and either password or private key depending on your server ssh setup.")
.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startActivityForResult(new Intent(MainMenu.this, Preferences.class), 200);
}
})
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
.setTitle(R.string.missing_settings)
.setMessage(R.string.ssh_connection_properties_not_set_message)
.setPositiveButton(R.string.open_settings, (dialog, which) -> startActivityForResult(new Intent(MainMenu.this, Preferences.class), 200))
.setNegativeButton(R.string.close, (dialogInterface, i) -> {
})
.setIcon(R.mipmap.logo)
.show();
Expand All @@ -347,27 +328,23 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

@Override
public void onConnectionError() {
runOnUiThread(new Runnable() {
@Override
public void run() {
closeProgressDialog();
genericErrorDialog("Error", "Connection error. Verify your address, port, username, password/private key.\n\n" +
"If target is remove server, ensure that it has specified port available (port forwarding).\n\n" +
"Target server has apcupsd daemon running and for example command '" + sharedPreferences.getString(Constants.SP_STATUS_COMMAND, "sudo apcaccess status") + "' is working.\n\n" +
"In case you are using direct APCUPSD TCP port connection, see setup tutorial for testing connection."
);
}
runOnUiThread(() -> {
closeProgressDialog();
genericErrorDialog(getString(R.string.error),
getString(R.string.connection_error_one) + "\n\n" +
getString(R.string.connection_error_two) + "\n\n" +
getString(R.string.connection_error_three) + " '" + sharedPreferences.getString(Constants.SP_STATUS_COMMAND, "sudo apcaccess status") + "' " +
getString(R.string.connection_error_four) +
getString(R.string.connection_error_five)
);
});
}

@Override
public void onCommandError(final String errorStr) {
runOnUiThread(new Runnable() {
@Override
public void run() {
closeProgressDialog();
genericErrorDialog("Error", "Command error. Result: " + errorStr);
}
runOnUiThread(() -> {
closeProgressDialog();
genericErrorDialog(getString(R.string.error), getString(R.string.command_error_result) + " " + errorStr);
});
}

Expand Down Expand Up @@ -397,7 +374,7 @@ private void genericSuccessDialog(final String title, final String description)
new AlertDialog.Builder(MainMenu.this)
.setTitle(title)
.setMessage(description)
.setPositiveButton("Close", (dialog, which) -> {
.setPositiveButton(R.string.close, (dialog, which) -> {
})
.setIcon(R.mipmap.ic_launcher_round)
.show();
Expand All @@ -409,21 +386,17 @@ private void genericErrorDialog(final String title, final String description) {
new AlertDialog.Builder(MainMenu.this)
.setTitle(title)
.setMessage(description)
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
.setPositiveButton(R.string.close, (dialog, which) -> {
})
.setNeutralButton("Copy content", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("", description);
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toast.makeText(MainMenu.this, "Content copied to clipboard", Toast.LENGTH_SHORT).show();
} catch (IndexOutOfBoundsException e) {
Toast.makeText(MainMenu.this, "There was nothing to copy", Toast.LENGTH_LONG).show();
}
.setNeutralButton(R.string.copy_content, (dialog, which) -> {
try {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("", description);
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toast.makeText(MainMenu.this, R.string.content_copied, Toast.LENGTH_SHORT).show();
} catch (IndexOutOfBoundsException e) {
Toast.makeText(MainMenu.this, R.string.nothing_to_copy, Toast.LENGTH_LONG).show();
}
})
.setIcon(R.drawable.ic_error_small)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onTaskCompleted() {
Log.i(TAG, "onTaskCompleted");
try {
if (databaseHelper.isAnyUpsDown()) {
showNotification(context, "Warning", "Non online status change detected!");
showNotification(context, context.getString(R.string.warning), context.getString(R.string.non_online_status_change_detected));
}
} catch (NullPointerException ignored) {
}
Expand Down
35 changes: 18 additions & 17 deletions app/src/main/java/com/nitramite/apcupsdmonitor/UPS.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nitramite.apcupsdmonitor;

import android.content.Context;
import android.util.Log;

// UPS Object
Expand Down Expand Up @@ -162,57 +163,57 @@ public Boolean isOnline() {
this.getSTATUS().equals("UPS OL CHRG"); // UPSC
}

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

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


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

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


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

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


public String getBATTERY_TIME_LEFT() {
return (this.BATTERY_TIME_LEFT == null ? "Battery time left N/A" : "Battery time left: " + this.BATTERY_TIME_LEFT);
public String getBATTERY_TIME_LEFT(Context context) {
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);
}


public String getLastTransferReasonStr() {
return (this.LAST_TRANSFER_REASON == null ? "Last transfer reason N/A" : "Last: " + this.LAST_TRANSFER_REASON);
public String getLastTransferReasonStr(Context context) {
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);
}


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

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

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

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

public String getLAST_SECONDS_ON_BATTERY() {
Expand Down
Loading

0 comments on commit 66448a2

Please sign in to comment.