Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.WPMediaUtils;
import org.wordpress.android.util.WPPermissionUtils;
import org.wordpress.android.util.FormatUtils;
import org.wordpress.android.util.extensions.CompatExtensionsKt;
import org.wordpress.android.util.extensions.ContextExtensionsKt;
import org.wordpress.android.util.extensions.ViewExtensionsKt;
Expand Down Expand Up @@ -144,6 +145,8 @@
private SeekBar mImageSizeSeekBarView;
private Spinner mAlignmentSpinnerView;
private FloatingActionButton mFabView;
private TextView mFileSizeView;

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on field Note

Missing null annotation
private TextView mFileSizeLabelView;

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on field Note

Missing null annotation

private AlertDialog mDeleteMediaConfirmationDialog;

Expand Down Expand Up @@ -256,6 +259,8 @@
mImageSizeSeekBarView = findViewById(R.id.image_size_seekbar);
mAlignmentSpinnerView = findViewById(org.wordpress.android.editor.R.id.alignment_spinner);
mFabView = findViewById(R.id.fab_button);
mFileSizeView = findViewById(R.id.text_file_size);
mFileSizeLabelView = findViewById(R.id.text_file_size_label);

int mediaId;
if (savedInstanceState != null) {
Expand Down Expand Up @@ -642,6 +647,24 @@
TextView txtFileType = findViewById(R.id.text_filetype);
txtFileType.setText(StringUtils.notNullStr(mMedia.getFileExtension()).toUpperCase(Locale.ROOT));

// Display file size if available
if (mMedia.getFileSize() > 0) {
final String[] units = new String[] {
getString(R.string.file_size_in_bytes),
getString(R.string.file_size_in_kilobytes),
getString(R.string.file_size_in_megabytes),
getString(R.string.file_size_in_gigabytes),
getString(R.string.file_size_in_terabytes)
};
Comment on lines +652 to +658
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code references string resources (file_size_in_bytes, file_size_in_kilobytes, etc.) that are not defined in the strings.xml file. This will cause a compilation error or runtime crash.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings are defined in the strings file...

Image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aside: is it typical to use lowercase for kB, but uppercase for MB, GB, TB? The divergence seems odd to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lowercase kB is even more odd now that I note that the server-provided values for WPCOM sites in #22220 return KB. I suggest we update the string from kBKB. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll update it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String formattedSize = FormatUtils.formatFileSize(mMedia.getFileSize(), units);
mFileSizeView.setText(formattedSize);
findViewById(R.id.layout_file_size).setVisibility(View.VISIBLE);
findViewById(R.id.divider_file_size).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.layout_file_size).setVisibility(View.GONE);
findViewById(R.id.divider_file_size).setVisibility(View.GONE);
}

showImageDimensions(mMedia.getWidth(), mMedia.getHeight());

String uploadDate = null;
Expand Down
30 changes: 30 additions & 0 deletions WordPress/src/main/res/layout/media_settings_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,36 @@
android:layout_width="match_parent"
android:layout_height="1dp" />

<!-- file size -->
<LinearLayout
android:id="@+id/layout_file_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:orientation="vertical"
android:visibility="gone">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_file_size_label"
style="@style/MediaSettings.Label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_edit_file_size_caption" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_file_size"
style="@style/MediaSettings.Value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="2.5 MB" />
</LinearLayout>

<View
android:id="@+id/divider_file_size"
style="@style/MediaSettings.Divider"
android:layout_width="match_parent"
android:layout_height="1dp" />

<!-- dimensions -->
<LinearLayout
android:layout_width="match_parent"
Expand Down
3 changes: 2 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<string name="media_edit_url_caption">URL</string>
<string name="media_edit_filename_caption">File Name</string>
<string name="media_edit_filetype_caption">File Type</string>
<string name="media_edit_file_size_caption">File Size</string>
<string name="media_edit_image_dimensions_caption">Image Dimensions</string>
<string name="media_edit_video_dimensions_caption">Video Dimensions</string>
<string name="media_edit_duration_caption">Duration</string>
Expand Down Expand Up @@ -728,7 +729,7 @@

<!-- 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. -->
<string name="file_size_in_bytes">%s B</string>
<string name="file_size_in_kilobytes">%s kB</string>
<string name="file_size_in_kilobytes">%s KB</string>
<string name="file_size_in_megabytes">%s MB</string>
<string name="file_size_in_gigabytes">%s GB</string>
<string name="file_size_in_terabytes">%s TB</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static MediaUploadState fromString(@Nullable String stringState) {
@Nullable @Column private String mFilePath;
@Nullable @Column private String mFileExtension;
@Nullable @Column private String mMimeType;
@Column private long mFileSize;

// Descriptive strings
@Nullable @Column private String mTitle;
Expand Down Expand Up @@ -141,6 +142,7 @@ public MediaModel() {
this.mFilePath = null;
this.mFileExtension = null;
this.mMimeType = null;
this.mFileSize = 0;
this.mTitle = null;
this.mCaption = "";
this.mDescription = "";
Expand Down Expand Up @@ -331,6 +333,7 @@ && getLocalSiteId() == otherMedia.getLocalSiteId() && getLocalPostId() == otherM
&& getMediaId() == otherMedia.getMediaId() && getPostId() == otherMedia.getPostId()
&& getAuthorId() == otherMedia.getAuthorId() && getWidth() == otherMedia.getWidth()
&& getHeight() == otherMedia.getHeight() && getLength() == otherMedia.getLength()
&& getFileSize() == otherMedia.getFileSize()
&& getHorizontalAlignment() == otherMedia.getHorizontalAlignment()
&& getVerticalAlignment() == otherMedia.getVerticalAlignment()
&& getVideoPressProcessingDone() == otherMedia.getVideoPressProcessingDone()
Expand Down Expand Up @@ -478,6 +481,14 @@ public String getMimeType() {
return mMimeType;
}

public void setFileSize(long fileSize) {
mFileSize = fileSize;
}

public long getFileSize() {
return mFileSize;
}

public void setTitle(@Nullable String title) {
mTitle = title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,21 +417,26 @@ class MediaRSApiRestClient @Inject constructor(

// Parse the media details
when (val parsedType = this@toMediaModel.mediaDetails.parseAsMimeType(this@toMediaModel.mimeType)) {
is MediaDetailsPayload.Audio -> length = parsedType.v1.length.toInt()
is MediaDetailsPayload.Audio -> {
length = parsedType.v1.length.toInt()
fileSize = parsedType.v1.fileSize.toLong()
}
is MediaDetailsPayload.Image -> {
fileName = parseFileNameFromPath(parsedType.v1.file)
width = parsedType.v1.width.toInt()
height = parsedType.v1.height.toInt()
thumbnailUrl = parsedType.v1.sizes?.get("thumbnail")?.sourceUrl
fileUrlMediumSize = parsedType.v1.sizes?.get("medium")?.sourceUrl
fileUrlLargeSize = parsedType.v1.sizes?.get("large")?.sourceUrl
fileSize = parsedType.v1.fileSize.toLong()
}
is MediaDetailsPayload.Video -> {
width = parsedType.v1.width.toInt()
height = parsedType.v1.height.toInt()
length = parsedType.v1.length.toInt()
fileSize = parsedType.v1.fileSize.toLong()
}
is MediaDetailsPayload.Document,
is MediaDetailsPayload.Document -> fileSize = parsedType.v1.fileSize.toLong()
null -> {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class WellSqlConfig : DefaultWellConfig {
annotation class AddOn

override fun getDbVersion(): Int {
return 209
return 210
}

override fun getDbName(): String {
Expand Down Expand Up @@ -2080,6 +2080,10 @@ open class WellSqlConfig : DefaultWellConfig {
208 -> {
db.execSQL("DROP TABLE IF EXISTS EncryptedLogModel")
}

209 -> {
db.execSQL("ALTER TABLE MediaModel ADD FILE_SIZE INTEGER")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tested how the library creates the DB column, it looks like even it being a long variable, WellSql uses an INTEGER. So, I've just followed the approach to avoid side problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "library" in this context?

Copy link
Contributor Author

@adalpari adalpari Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WellSql. The library used to manage MySql DB.

}
}
}
db.setTransactionSuccessful()
Expand Down