Skip to content

Commit 3e7e021

Browse files
authored
CMM 628 add filesize to the media screen (#22216)
* Creating the field in MediaModel * Filling the field in rs requests * Adding the field to the db * Adding field to the UI * Minor refactor * Updating kB to KB
1 parent 4560f1f commit 3e7e021

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.wordpress.android.util.ToastUtils;
9696
import org.wordpress.android.util.WPMediaUtils;
9797
import org.wordpress.android.util.WPPermissionUtils;
98+
import org.wordpress.android.util.FormatUtils;
9899
import org.wordpress.android.util.extensions.CompatExtensionsKt;
99100
import org.wordpress.android.util.extensions.ContextExtensionsKt;
100101
import org.wordpress.android.util.extensions.ViewExtensionsKt;
@@ -144,6 +145,8 @@ public class MediaSettingsActivity extends BaseAppCompatActivity
144145
private SeekBar mImageSizeSeekBarView;
145146
private Spinner mAlignmentSpinnerView;
146147
private FloatingActionButton mFabView;
148+
private TextView mFileSizeView;
149+
private TextView mFileSizeLabelView;
147150

148151
private AlertDialog mDeleteMediaConfirmationDialog;
149152

@@ -256,6 +259,8 @@ public void handleOnBackPressed() {
256259
mImageSizeSeekBarView = findViewById(R.id.image_size_seekbar);
257260
mAlignmentSpinnerView = findViewById(org.wordpress.android.editor.R.id.alignment_spinner);
258261
mFabView = findViewById(R.id.fab_button);
262+
mFileSizeView = findViewById(R.id.text_file_size);
263+
mFileSizeLabelView = findViewById(R.id.text_file_size_label);
259264

260265
int mediaId;
261266
if (savedInstanceState != null) {
@@ -642,6 +647,24 @@ private void showMetaData() {
642647
TextView txtFileType = findViewById(R.id.text_filetype);
643648
txtFileType.setText(StringUtils.notNullStr(mMedia.getFileExtension()).toUpperCase(Locale.ROOT));
644649

650+
// Display file size if available
651+
if (mMedia.getFileSize() > 0) {
652+
final String[] units = new String[] {
653+
getString(R.string.file_size_in_bytes),
654+
getString(R.string.file_size_in_kilobytes),
655+
getString(R.string.file_size_in_megabytes),
656+
getString(R.string.file_size_in_gigabytes),
657+
getString(R.string.file_size_in_terabytes)
658+
};
659+
String formattedSize = FormatUtils.formatFileSize(mMedia.getFileSize(), units);
660+
mFileSizeView.setText(formattedSize);
661+
findViewById(R.id.layout_file_size).setVisibility(View.VISIBLE);
662+
findViewById(R.id.divider_file_size).setVisibility(View.VISIBLE);
663+
} else {
664+
findViewById(R.id.layout_file_size).setVisibility(View.GONE);
665+
findViewById(R.id.divider_file_size).setVisibility(View.GONE);
666+
}
667+
645668
showImageDimensions(mMedia.getWidth(), mMedia.getHeight());
646669

647670
String uploadDate = null;

WordPress/src/main/res/layout/media_settings_activity.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,36 @@
413413
android:layout_width="match_parent"
414414
android:layout_height="1dp" />
415415

416+
<!-- file size -->
417+
<LinearLayout
418+
android:id="@+id/layout_file_size"
419+
android:layout_width="match_parent"
420+
android:layout_height="wrap_content"
421+
android:focusable="true"
422+
android:orientation="vertical"
423+
android:visibility="gone">
424+
425+
<com.google.android.material.textview.MaterialTextView
426+
android:id="@+id/text_file_size_label"
427+
style="@style/MediaSettings.Label"
428+
android:layout_width="wrap_content"
429+
android:layout_height="wrap_content"
430+
android:text="@string/media_edit_file_size_caption" />
431+
432+
<com.google.android.material.textview.MaterialTextView
433+
android:id="@+id/text_file_size"
434+
style="@style/MediaSettings.Value"
435+
android:layout_width="wrap_content"
436+
android:layout_height="wrap_content"
437+
tools:text="2.5 MB" />
438+
</LinearLayout>
439+
440+
<View
441+
android:id="@+id/divider_file_size"
442+
style="@style/MediaSettings.Divider"
443+
android:layout_width="match_parent"
444+
android:layout_height="1dp" />
445+
416446
<!-- dimensions -->
417447
<LinearLayout
418448
android:layout_width="match_parent"

WordPress/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
<string name="media_edit_url_caption">URL</string>
209209
<string name="media_edit_filename_caption">File Name</string>
210210
<string name="media_edit_filetype_caption">File Type</string>
211+
<string name="media_edit_file_size_caption">File Size</string>
211212
<string name="media_edit_image_dimensions_caption">Image Dimensions</string>
212213
<string name="media_edit_video_dimensions_caption">Video Dimensions</string>
213214
<string name="media_edit_duration_caption">Duration</string>
@@ -728,7 +729,7 @@
728729

729730
<!-- these represent a formatted amount along with a measuring unit, i.e. 10 B, or 132 kB, or 10.2 MB, 1,037.76 kB etc. -->
730731
<string name="file_size_in_bytes">%s B</string>
731-
<string name="file_size_in_kilobytes">%s kB</string>
732+
<string name="file_size_in_kilobytes">%s KB</string>
732733
<string name="file_size_in_megabytes">%s MB</string>
733734
<string name="file_size_in_gigabytes">%s GB</string>
734735
<string name="file_size_in_terabytes">%s TB</string>

libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/MediaModel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static MediaUploadState fromString(@Nullable String stringState) {
5858
@Nullable @Column private String mFilePath;
5959
@Nullable @Column private String mFileExtension;
6060
@Nullable @Column private String mMimeType;
61+
@Column private long mFileSize;
6162

6263
// Descriptive strings
6364
@Nullable @Column private String mTitle;
@@ -141,6 +142,7 @@ public MediaModel() {
141142
this.mFilePath = null;
142143
this.mFileExtension = null;
143144
this.mMimeType = null;
145+
this.mFileSize = 0;
144146
this.mTitle = null;
145147
this.mCaption = "";
146148
this.mDescription = "";
@@ -331,6 +333,7 @@ && getLocalSiteId() == otherMedia.getLocalSiteId() && getLocalPostId() == otherM
331333
&& getMediaId() == otherMedia.getMediaId() && getPostId() == otherMedia.getPostId()
332334
&& getAuthorId() == otherMedia.getAuthorId() && getWidth() == otherMedia.getWidth()
333335
&& getHeight() == otherMedia.getHeight() && getLength() == otherMedia.getLength()
336+
&& getFileSize() == otherMedia.getFileSize()
334337
&& getHorizontalAlignment() == otherMedia.getHorizontalAlignment()
335338
&& getVerticalAlignment() == otherMedia.getVerticalAlignment()
336339
&& getVideoPressProcessingDone() == otherMedia.getVideoPressProcessingDone()
@@ -478,6 +481,14 @@ public String getMimeType() {
478481
return mMimeType;
479482
}
480483

484+
public void setFileSize(long fileSize) {
485+
mFileSize = fileSize;
486+
}
487+
488+
public long getFileSize() {
489+
return mFileSize;
490+
}
491+
481492
public void setTitle(@Nullable String title) {
482493
mTitle = title;
483494
}

libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/media/MediaRSApiRestClient.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,21 +417,26 @@ class MediaRSApiRestClient @Inject constructor(
417417

418418
// Parse the media details
419419
when (val parsedType = this@toMediaModel.mediaDetails.parseAsMimeType(this@toMediaModel.mimeType)) {
420-
is MediaDetailsPayload.Audio -> length = parsedType.v1.length.toInt()
420+
is MediaDetailsPayload.Audio -> {
421+
length = parsedType.v1.length.toInt()
422+
fileSize = parsedType.v1.fileSize.toLong()
423+
}
421424
is MediaDetailsPayload.Image -> {
422425
fileName = parseFileNameFromPath(parsedType.v1.file)
423426
width = parsedType.v1.width.toInt()
424427
height = parsedType.v1.height.toInt()
425428
thumbnailUrl = parsedType.v1.sizes?.get("thumbnail")?.sourceUrl
426429
fileUrlMediumSize = parsedType.v1.sizes?.get("medium")?.sourceUrl
427430
fileUrlLargeSize = parsedType.v1.sizes?.get("large")?.sourceUrl
431+
fileSize = parsedType.v1.fileSize.toLong()
428432
}
429433
is MediaDetailsPayload.Video -> {
430434
width = parsedType.v1.width.toInt()
431435
height = parsedType.v1.height.toInt()
432436
length = parsedType.v1.length.toInt()
437+
fileSize = parsedType.v1.fileSize.toLong()
433438
}
434-
is MediaDetailsPayload.Document,
439+
is MediaDetailsPayload.Document -> fileSize = parsedType.v1.fileSize.toLong()
435440
null -> {}
436441
}
437442

libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ open class WellSqlConfig : DefaultWellConfig {
4141
annotation class AddOn
4242

4343
override fun getDbVersion(): Int {
44-
return 209
44+
return 210
4545
}
4646

4747
override fun getDbName(): String {
@@ -2080,6 +2080,10 @@ open class WellSqlConfig : DefaultWellConfig {
20802080
208 -> {
20812081
db.execSQL("DROP TABLE IF EXISTS EncryptedLogModel")
20822082
}
2083+
2084+
209 -> {
2085+
db.execSQL("ALTER TABLE MediaModel ADD FILE_SIZE INTEGER")
2086+
}
20832087
}
20842088
}
20852089
db.setTransactionSuccessful()

0 commit comments

Comments
 (0)