mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-29 15:51:17 +00:00
FoldersAdapter: Merge getLocalizedState into updateFolderStatusView
This commit is contained in:
parent
f679ca2cc5
commit
8873111510
1 changed files with 27 additions and 27 deletions
|
@ -103,17 +103,43 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
|
||||||
binding.state.setText(mContext.getString(R.string.state_paused));
|
binding.state.setText(mContext.getString(R.string.state_paused));
|
||||||
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_black));
|
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_black));
|
||||||
} else {
|
} else {
|
||||||
binding.state.setText(getLocalizedState(mContext, folderStatus));
|
|
||||||
switch(folderStatus.state) {
|
switch(folderStatus.state) {
|
||||||
case "idle":
|
case "idle":
|
||||||
|
binding.state.setText(mContext.getString(R.string.state_idle));
|
||||||
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_green));
|
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_green));
|
||||||
break;
|
break;
|
||||||
case "scanning":
|
case "scanning":
|
||||||
|
binding.state.setText(mContext.getString(R.string.state_scanning));
|
||||||
|
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_blue));
|
||||||
|
break;
|
||||||
case "syncing":
|
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));
|
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_blue));
|
||||||
break;
|
break;
|
||||||
case "error":
|
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:
|
default:
|
||||||
|
binding.state.setText(folderStatus.state);
|
||||||
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_red));
|
binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_red));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,32 +154,6 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
|
||||||
setTextOrHide(binding.invalid, folderStatus.invalid);
|
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.
|
* Requests updated folder status from the api for all visible items.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue