diff --git a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java index 4f07cf3e..e76fc21d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java @@ -103,17 +103,43 @@ public class FoldersAdapter extends ArrayAdapter { binding.state.setText(mContext.getString(R.string.state_paused)); binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_black)); } else { - binding.state.setText(getLocalizedState(mContext, folderStatus)); switch(folderStatus.state) { case "idle": + binding.state.setText(mContext.getString(R.string.state_idle)); binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_green)); break; case "scanning": + binding.state.setText(mContext.getString(R.string.state_scanning)); + binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_blue)); + break; case "syncing": + binding.state.setText( + mContext.getString( + R.string.state_syncing, + (folderStatus.globalBytes != 0) + ? Math.round(100 * folderStatus.inSyncBytes / folderStatus.globalBytes) + : 100 + ) + ); binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_blue)); break; case "error": + binding.state.setText( + mContext.getString( + R.string.state_error) + + (!TextUtils.isEmpty(folderStatus.error) + ? " (" + folderStatus.error + ")" + : "" + ) + ); + binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_red)); + break; + case "unknown": + binding.state.setText(mContext.getString(R.string.state_unknown)); + binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_red)); + break; default: + binding.state.setText(folderStatus.state); binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_red)); } } @@ -128,32 +154,6 @@ public class FoldersAdapter extends ArrayAdapter { setTextOrHide(binding.invalid, folderStatus.invalid); } - /** - * Returns the folder's state as a localized string. - */ - private static String getLocalizedState(Context c, FolderStatus folderStatus) { - switch (folderStatus.state) { - case "idle": - return c.getString(R.string.state_idle); - case "scanning": - return c.getString(R.string.state_scanning); - case "syncing": - int percentage = (folderStatus.globalBytes != 0) - ? Math.round(100 * folderStatus.inSyncBytes / folderStatus.globalBytes) - : 100; - return c.getString(R.string.state_syncing, percentage); - case "error": - if (TextUtils.isEmpty(folderStatus.error)) { - return c.getString(R.string.state_error); - } - return c.getString(R.string.state_error) + " (" + folderStatus.error + ")"; - case "unknown": - return c.getString(R.string.state_unknown); - default: - return folderStatus.state; - } - } - /** * Requests updated folder status from the api for all visible items. */