@@ -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 )
0 commit comments