mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Localize folder states.
This commit is contained in:
parent
8d781844a2
commit
60815355ca
3 changed files with 27 additions and 1 deletions
|
@ -24,6 +24,7 @@ import org.json.JSONArray;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -664,6 +665,24 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
|||
}.execute(mUrl, GetTask.URI_MODEL, mApiKey, "folder", folderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the folder's state as a localized string.
|
||||
*
|
||||
* @param state One of idle, scanning, cleaning or syncing.
|
||||
*/
|
||||
public static String getLocalizedState(Context c, String state) {
|
||||
switch (state) {
|
||||
case "idle": return c.getString(R.string.state_idle);
|
||||
case "scanning": return c.getString(R.string.state_scanning);
|
||||
case "cleaning": return c.getString(R.string.state_cleaning);
|
||||
case "syncing": return c.getString(R.string.state_syncing);
|
||||
}
|
||||
if (BuildConfig.DEBUG) {
|
||||
throw new AssertionError("Unexpected folder state");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates or creates the given device, depending on whether it already exists.
|
||||
*
|
||||
|
|
|
@ -50,7 +50,8 @@ public class FoldersAdapter extends ArrayAdapter<RestApi.Folder>
|
|||
int percentage = (model.globalBytes != 0)
|
||||
? (int) Math.floor(100 * model.inSyncBytes / model.globalBytes)
|
||||
: 100;
|
||||
state.setText(getContext().getString(R.string.folder_progress_format, model.state,
|
||||
state.setText(getContext().getString(R.string.folder_progress_format,
|
||||
RestApi.getLocalizedState(getContext(), model.state),
|
||||
percentage));
|
||||
items.setText(getContext()
|
||||
.getString(R.string.files, model.inSyncFiles, model.globalFiles));
|
||||
|
|
|
@ -303,4 +303,10 @@ If this error persists, try restarting your device.</string>
|
|||
<item>Tb/s</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Possible folder states -->
|
||||
<string name="state_idle">Idle</string>
|
||||
<string name="state_scanning">Scanning</string>
|
||||
<string name="state_cleaning">Cleaning</string>
|
||||
<string name="state_syncing">Syncing</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue