Skip to content

Commit 2b1f0e9

Browse files
committed
rename functions
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 6b6a461 commit 2b1f0e9

20 files changed

Lines changed: 60 additions & 59 deletions

‎app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadLocalDeletionWorker.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class AutoUploadLocalDeletionWorker(
122122
): Notification {
123123
val notificationContent = context.getString(
124124
R.string.autoupload_delete_uploaded_notif_ended_content,
125-
HumanReadableFormatter.bytesToHumanReadable(spaceFreed),
125+
HumanReadableFormatter.formatBytes(spaceFreed),
126126
context.resources.getQuantityString(
127127
R.plurals.autoupload_delete_uploaded_notif_ended_content_files,
128128
filesRemoved.toInt(),

‎app/src/main/java/com/nextcloud/client/player/ui/audio/AudioFileFragment.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ open class AudioFileFragment :
133133
}
134134

135135
private fun PlaybackFile.getDetailsText(): String = listOfNotNull(
136-
contentLength.takeIf { it > 0 }?.let { HumanReadableFormatter.bytesToHumanReadable(it) },
136+
contentLength.takeIf { it > 0 }?.let { HumanReadableFormatter.formatBytes(it) },
137137
lastModified.takeIf { it > 0 }?.let(::getLastModifiedText)
138138
).joinToString(DETAILS_SEPARATOR)
139139

‎app/src/main/java/com/nextcloud/ui/ChooseStorageLocationDialogFragment.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class ChooseStorageLocationDialogFragment :
121121
return String.format(
122122
getString(R.string.file_migration_free_space),
123123
typeString,
124-
HumanReadableFormatter.bytesToHumanReadable(usedSpace),
125-
HumanReadableFormatter.bytesToHumanReadable(totalSpace)
124+
HumanReadableFormatter.formatBytes(usedSpace),
125+
HumanReadableFormatter.formatBytes(totalSpace)
126126
)
127127
} ?: typeString
128128
}

‎app/src/main/java/com/nextcloud/ui/fileInfo/ImageDetailInfo.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class ImageDetailInfo(private val fragment: FileInfoFragment, private val viewTh
181181
}
182182

183183
fun gatherMetadata(file: OCFile): ImageMetadata {
184-
val fileSize = HumanReadableFormatter.bytesToHumanReadable(file.fileLength)
184+
val fileSize = HumanReadableFormatter.formatBytes(file.fileLength)
185185
val timestamp = maxOf(file.modificationTimestamp, file.creationTimestamp)
186186
return if (file.isDown) {
187187
gatherLocalMetadata(file, fileSize, timestamp)

‎app/src/main/java/com/nextcloud/utils/HumanReadableFormatter.kt‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ import java.util.Locale
1515

1616
object HumanReadableFormatter {
1717

18+
private const val BITS_PER_UNIT = 10
19+
1820
@JvmStatic
19-
fun bytesToHumanReadable(bytes: Long): String {
21+
fun formatBytes(bytes: Long): String {
2022
if (bytes < 0) {
2123
return MainApp.string(R.string.common_pending)
2224
}
2325

24-
val unitIndex = ((63 - java.lang.Long.numberOfLeadingZeros(bytes)) / 10)
25-
.coerceIn(0, ByteUnit.entries.lastIndex)
26+
val highestSetBit = Long.SIZE_BITS - 1 - bytes.countLeadingZeroBits()
27+
val unitIndex = (highestSetBit / BITS_PER_UNIT).coerceIn(0, ByteUnit.entries.lastIndex)
2628
val unit = ByteUnit.entries[unitIndex]
27-
val size = bytes.toDouble() / (1L shl (10 * unitIndex))
29+
val size = bytes.toDouble() / (1L shl (BITS_PER_UNIT * unitIndex))
2830

29-
return "${String.format(Locale.ROOT, "%.${unit.decimals}f", size)} ${unit.suffix}"
31+
val pattern = "%.${unit.decimals}f"
32+
val formattedSize = String.format(Locale.ROOT, pattern, size)
33+
return "$formattedSize ${unit.suffix}"
3034
}
3135

3236
@JvmStatic
33-
fun unixTimeToHumanReadable(milliseconds: Long): String =
34-
DateFormat.getDateTimeInstance().format(Date(milliseconds))
37+
fun formatDateTime(milliseconds: Long): String = DateFormat.getDateTimeInstance().format(Date(milliseconds))
3538
}

‎app/src/main/java/com/nextcloud/utils/extensions/FileExtensions.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import java.nio.file.Path
2020
private const val TAG = "FileExtensions"
2121

2222
fun OCFile?.logFileSize(tag: String) {
23-
val size = HumanReadableFormatter.bytesToHumanReadable(this?.fileLength ?: -1)
23+
val size = HumanReadableFormatter.formatBytes(this?.fileLength ?: -1)
2424
val rawByte = this?.fileLength ?: -1
2525
Log_OC.d(tag, "onSaveInstanceState: $size, raw byte $rawByte")
2626
}
@@ -48,7 +48,7 @@ fun File?.getSmallThumbnail(): Bitmap? = ThumbnailsCacheManager.getBitmapFromDis
4848
fun File?.getSmallThumbnailKey(): String = ThumbnailsCacheManager.PREFIX_THUMBNAIL + hashCode()
4949

5050
fun File?.logFileSize(tag: String) {
51-
val size = HumanReadableFormatter.bytesToHumanReadable(this?.length() ?: -1)
51+
val size = HumanReadableFormatter.formatBytes(this?.length() ?: -1)
5252
val rawByte = this?.length() ?: -1
5353
Log_OC.d(tag, "onSaveInstanceState: $size, raw byte $rawByte")
5454
}

‎app/src/main/java/com/owncloud/android/ui/activities/adapter/ActivityAndVersionListAdapter.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ActivityAndVersionListAdapter(
7171
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
7272
if (holder is VersionViewHolder) {
7373
val fileVersion = values[position] as FileVersion
74-
holder.binding.size.text = HumanReadableFormatter.bytesToHumanReadable(fileVersion.fileLength)
74+
holder.binding.size.text = HumanReadableFormatter.formatBytes(fileVersion.fileLength)
7575
holder.binding.time.text = DateFormat.format("HH:mm", Date(fileVersion.modifiedTimestamp).time)
7676
holder.binding.restore.setOnClickListener { versionListInterface.onRestoreClicked(fileVersion) }
7777
} else {

‎app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
import com.owncloud.android.ui.fragment.albums.AlbumsFragment;
104104
import com.owncloud.android.ui.navigation.NavigatorActivity;
105105
import com.owncloud.android.ui.navigation.NavigatorScreen;
106-
import com.owncloud.android.ui.trashbin.TrashbinFragment;
107106
import com.owncloud.android.utils.BitmapUtils;
108107
import com.owncloud.android.utils.DisplayUtils;
109108
import com.owncloud.android.utils.DrawableUtil;
@@ -941,12 +940,12 @@ private void setQuotaInformation(long usedSpace, long totalSpace, int relative,
941940
if (GetUserInfoRemoteOperation.SPACE_UNLIMITED == quotaValue) {
942941
mQuotaTextPercentage.setText(String.format(
943942
getString(R.string.drawer_quota_unlimited),
944-
HumanReadableFormatter.bytesToHumanReadable(usedSpace)));
943+
HumanReadableFormatter.formatBytes(usedSpace)));
945944
} else {
946945
mQuotaTextPercentage.setText(String.format(
947946
getString(R.string.drawer_quota),
948-
HumanReadableFormatter.bytesToHumanReadable(usedSpace),
949-
HumanReadableFormatter.bytesToHumanReadable(totalSpace)));
947+
HumanReadableFormatter.formatBytes(usedSpace),
948+
HumanReadableFormatter.formatBytes(totalSpace)));
950949
}
951950

952951
mQuotaProgressBar.setProgress(relative);

‎app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ShareActivity :
122122
with(binding) {
123123
shareFileName.text = getString(R.string.share_file, file.fileName)
124124
viewThemeUtils.platform.colorViewBackground(shareHeaderDivider)
125-
shareFileSize.text = HumanReadableFormatter.bytesToHumanReadable(file.fileLength)
125+
shareFileSize.text = HumanReadableFormatter.formatBytes(file.fileLength)
126126
}
127127
}
128128

@@ -150,7 +150,7 @@ class ShareActivity :
150150
val length = (result.data.first() as? RemoteFile)?.length ?: return@launch
151151
file.fileLength = length
152152
withContext(Dispatchers.Main) {
153-
binding.shareFileSize.text = HumanReadableFormatter.bytesToHumanReadable(length)
153+
binding.shareFileSize.text = HumanReadableFormatter.formatBytes(length)
154154
}
155155
}
156156
}

‎app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncViewHolder.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class InternalTwoWaySyncViewHolder(val binding: InternalTwoWaySyncViewHolderBind
2626
internalTwoWaySyncAdapter: InternalTwoWaySyncAdapter
2727
) {
2828
binding.run {
29-
size.text = HumanReadableFormatter.bytesToHumanReadable(folder.fileLength)
29+
size.text = HumanReadableFormatter.formatBytes(folder.fileLength)
3030
name.text = folder.decryptedFileName
3131

3232
if (folder.internalFolderSyncResult.isEmpty()) {

0 commit comments

Comments
 (0)