1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 19:31:30 +00:00

Use bytes per second instead of bits per second.

This commit is contained in:
Felix Ableitner 2015-06-15 16:19:46 +02:00
parent b1c9206e75
commit e2e10a8794
4 changed files with 14 additions and 13 deletions

View file

@ -87,8 +87,8 @@ public class RestApiTest extends AndroidTestCase {
@SmallTest @SmallTest
public void testGetReadableTransferRate() { public void testGetReadableTransferRate() {
assertEquals("1 Mib/s", RestApi.readableTransferRate(getContext(), 1048576)); assertEquals("1 MiB/s", RestApi.readableTransferRate(getContext(), 8388608L));
assertEquals("1 Gib/s", RestApi.readableTransferRate(getContext(), 1073741824)); assertEquals("1 GiB/s", RestApi.readableTransferRate(getContext(), 8589934592L));
} }
@MediumTest @MediumTest

View file

@ -30,8 +30,8 @@ public class DevicesAdapterTest extends AndroidTestCase {
mDevice.deviceID = "123-456-789"; mDevice.deviceID = "123-456-789";
mConnection.completion = 100; mConnection.completion = 100;
mConnection.inBits = 1048576; mConnection.inBits = 8388608L;
mConnection.outBits = 1073741824; mConnection.outBits = 8589934592L;
} }
@ -57,8 +57,8 @@ public class DevicesAdapterTest extends AndroidTestCase {
assertEquals(getContext().getString(R.string.device_up_to_date), assertEquals(getContext().getString(R.string.device_up_to_date),
((TextView) v.findViewById(R.id.status)).getText().toString()); ((TextView) v.findViewById(R.id.status)).getText().toString());
assertEquals("1 Mib/s", ((TextView) v.findViewById(R.id.download)).getText().toString()); assertEquals("1 MiB/s", ((TextView) v.findViewById(R.id.download)).getText().toString());
assertEquals("1 Gib/s", ((TextView) v.findViewById(R.id.upload)).getText().toString()); assertEquals("1 GiB/s", ((TextView) v.findViewById(R.id.upload)).getText().toString());
} }
} }

View file

@ -577,9 +577,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public static String readableTransferRate(Context context, long bits) { public static String readableTransferRate(Context context, long bits) {
final String[] units = context.getResources().getStringArray(R.array.transfer_rate_units); final String[] units = context.getResources().getStringArray(R.array.transfer_rate_units);
if (bits <= 0) return "0 " + units[0]; if (bits <= 0) return "0 " + units[0];
int digitGroups = (int) (Math.log10(bits) / Math.log10(1024)); long bytes = bits / 8;
int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024));
return new DecimalFormat("#,##0.#") return new DecimalFormat("#,##0.#")
.format(bits / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; .format(bytes / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
} }
/** /**

View file

@ -425,11 +425,11 @@ Please report any problems you encounter via Github.</string>
<!-- Strings representing units for transfer rates, from smallest to largest --> <!-- Strings representing units for transfer rates, from smallest to largest -->
<string-array name="transfer_rate_units"> <string-array name="transfer_rate_units">
<item>b/s</item> <item>B/s</item>
<item>Kib/s</item> <item>KiB/s</item>
<item>Mib/s</item> <item>MiB/s</item>
<item>Gib/s</item> <item>GiB/s</item>
<item>Tib/s</item> <item>TiB/s</item>
</string-array> </string-array>
<!-- Possible folder states --> <!-- Possible folder states -->