Skip to content

Commit ab1be7f

Browse files
authored
Merge branch 'trunk' into fix/CMM-754-bug-when-loading-bog-images-in-high-res
2 parents 0248cb3 + 801cd5d commit ab1be7f

File tree

14 files changed

+481
-16
lines changed

14 files changed

+481
-16
lines changed

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

Lines changed: 27 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,28 @@ 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 if (mMedia.getFileSizeFormatted() != null) {
664+
mFileSizeView.setText(mMedia.getFileSizeFormatted());
665+
findViewById(R.id.layout_file_size).setVisibility(View.VISIBLE);
666+
findViewById(R.id.divider_file_size).setVisibility(View.VISIBLE);
667+
} else {
668+
findViewById(R.id.layout_file_size).setVisibility(View.GONE);
669+
findViewById(R.id.divider_file_size).setVisibility(View.GONE);
670+
}
671+
645672
showImageDimensions(mMedia.getWidth(), mMedia.getHeight());
646673

647674
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>

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
agp = '8.7.3'
3-
airbnb-lottie = '6.6.7'
3+
airbnb-lottie = '6.6.9'
44
android-desugar = '2.1.5'
55
android-installreferrer = '2.2'
66
android-security-lint = '1.0.3'
@@ -20,7 +20,7 @@ androidx-core = '1.16.0'
2020
androidx-credentials = '1.2.0'
2121
androidx-exifinterface = '1.4.1'
2222
androidx-fragment = '1.8.9'
23-
androidx-lifecycle = '2.9.3'
23+
androidx-lifecycle = '2.9.4'
2424
androidx-navigation = '2.9.4'
2525
androidx-paging = '2.1.2'
2626
androidx-percentlayout = '1.0.0'
@@ -51,7 +51,7 @@ checkstyle = '10.17.0'
5151
coil = '2.7.0'
5252
commons-fileupload = '1.5'
5353
detekt = '1.23.8'
54-
dependency-analysis = '2.19.0'
54+
dependency-analysis = '3.0.4'
5555
facebook-react = '0.73.3'
5656
facebook-shimmer = '0.5.0'
5757
fastlane-screengrab = '2.1.1'

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ 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;
62+
@Nullable @Column private String mFileSizeFormatted;
6163

6264
// Descriptive strings
6365
@Nullable @Column private String mTitle;
@@ -141,6 +143,8 @@ public MediaModel() {
141143
this.mFilePath = null;
142144
this.mFileExtension = null;
143145
this.mMimeType = null;
146+
this.mFileSize = 0;
147+
this.mFileSizeFormatted = null;
144148
this.mTitle = null;
145149
this.mCaption = "";
146150
this.mDescription = "";
@@ -331,6 +335,7 @@ && getLocalSiteId() == otherMedia.getLocalSiteId() && getLocalPostId() == otherM
331335
&& getMediaId() == otherMedia.getMediaId() && getPostId() == otherMedia.getPostId()
332336
&& getAuthorId() == otherMedia.getAuthorId() && getWidth() == otherMedia.getWidth()
333337
&& getHeight() == otherMedia.getHeight() && getLength() == otherMedia.getLength()
338+
&& getFileSize() == otherMedia.getFileSize()
334339
&& getHorizontalAlignment() == otherMedia.getHorizontalAlignment()
335340
&& getVerticalAlignment() == otherMedia.getVerticalAlignment()
336341
&& getVideoPressProcessingDone() == otherMedia.getVideoPressProcessingDone()
@@ -478,6 +483,23 @@ public String getMimeType() {
478483
return mMimeType;
479484
}
480485

486+
public void setFileSize(long fileSize) {
487+
mFileSize = fileSize;
488+
}
489+
490+
public long getFileSize() {
491+
return mFileSize;
492+
}
493+
494+
public void setFileSizeFormatted(@Nullable String fileSizeFormatted) {
495+
mFileSizeFormatted = fileSizeFormatted;
496+
}
497+
498+
@Nullable
499+
public String getFileSizeFormatted() {
500+
return mFileSizeFormatted;
501+
}
502+
481503
public void setTitle(@Nullable String title) {
482504
mTitle = title;
483505
}

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

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package org.wordpress.android.fluxc.network.rest.wpapi.taxonomy
2+
3+
import kotlinx.coroutines.CoroutineScope
4+
import kotlinx.coroutines.launch
5+
import org.wordpress.android.fluxc.Dispatcher
6+
import org.wordpress.android.fluxc.generated.TaxonomyActionBuilder
7+
import org.wordpress.android.fluxc.model.SiteModel
8+
import org.wordpress.android.fluxc.model.TermModel
9+
import org.wordpress.android.fluxc.model.TermsModel
10+
import org.wordpress.android.fluxc.module.FLUXC_SCOPE
11+
import org.wordpress.android.fluxc.network.rest.wpapi.rs.WpApiClientProvider
12+
import org.wordpress.android.fluxc.store.TaxonomyStore
13+
import org.wordpress.android.fluxc.store.TaxonomyStore.DEFAULT_TAXONOMY_TAG
14+
import org.wordpress.android.fluxc.store.TaxonomyStore.FetchTermsResponsePayload
15+
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyError
16+
import org.wordpress.android.fluxc.store.TaxonomyStore.TaxonomyErrorType
17+
import org.wordpress.android.fluxc.utils.AppLogWrapper
18+
import org.wordpress.android.util.AppLog
19+
import rs.wordpress.api.kotlin.WpRequestResult
20+
import uniffi.wp_api.CategoryListParams
21+
import uniffi.wp_api.TagListParams
22+
import javax.inject.Inject
23+
import javax.inject.Named
24+
import javax.inject.Singleton
25+
26+
@Singleton
27+
class TaxonomyRsApiRestClient @Inject constructor(
28+
@Named(FLUXC_SCOPE) private val scope: CoroutineScope,
29+
private val dispatcher: Dispatcher,
30+
private val appLogWrapper: AppLogWrapper,
31+
private val wpApiClientProvider: WpApiClientProvider,
32+
) {
33+
fun fetchPostCategories(site: SiteModel) {
34+
scope.launch {
35+
val client = wpApiClientProvider.getWpApiClient(site)
36+
37+
val categoriesResponse = client.request { requestBuilder ->
38+
requestBuilder.categories().listWithEditContext(
39+
CategoryListParams()
40+
)
41+
}
42+
43+
val termsResponsePayload = when (categoriesResponse) {
44+
is WpRequestResult.Success -> {
45+
appLogWrapper.d(AppLog.T.POSTS, "Fetched categories list: ${categoriesResponse.response.data.size}")
46+
createTermsResponsePayload(
47+
categoriesResponse.response.data.map { category ->
48+
TermModel(
49+
category.id.toInt(),
50+
site.id,
51+
category.id,
52+
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY,
53+
category.name,
54+
category.slug,
55+
category.description,
56+
0,
57+
category.count.toInt()
58+
)
59+
},
60+
site,
61+
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY
62+
)
63+
}
64+
65+
else -> {
66+
appLogWrapper.e(AppLog.T.POSTS, "Fetch categories list failed: $categoriesResponse")
67+
FetchTermsResponsePayload(
68+
TaxonomyError(TaxonomyErrorType.GENERIC_ERROR, ""),
69+
TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY
70+
)
71+
}
72+
}
73+
notifyTermsFetched(termsResponsePayload)
74+
}
75+
}
76+
77+
fun fetchPostTags(site: SiteModel) {
78+
scope.launch {
79+
val client = wpApiClientProvider.getWpApiClient(site)
80+
81+
val tagsResponse = client.request { requestBuilder ->
82+
requestBuilder.tags().listWithEditContext(
83+
TagListParams()
84+
)
85+
}
86+
87+
val termsResponsePayload = when (tagsResponse) {
88+
is WpRequestResult.Success -> {
89+
appLogWrapper.d(AppLog.T.POSTS, "Fetched tags list: ${tagsResponse.response.data.size}")
90+
createTermsResponsePayload(
91+
tagsResponse.response.data.map { tag ->
92+
TermModel(
93+
tag.id.toInt(),
94+
site.id,
95+
tag.id,
96+
DEFAULT_TAXONOMY_TAG,
97+
tag.name,
98+
tag.slug,
99+
tag.description,
100+
0,
101+
tag.count.toInt()
102+
)
103+
},
104+
site,
105+
DEFAULT_TAXONOMY_TAG
106+
)
107+
}
108+
109+
else -> {
110+
appLogWrapper.e(AppLog.T.POSTS, "Fetch tags list failed: $tagsResponse")
111+
FetchTermsResponsePayload(
112+
TaxonomyError(TaxonomyErrorType.GENERIC_ERROR, ""),
113+
DEFAULT_TAXONOMY_TAG
114+
)
115+
}
116+
}
117+
notifyTermsFetched(termsResponsePayload)
118+
}
119+
}
120+
121+
private fun notifyTermsFetched(
122+
payload: FetchTermsResponsePayload,
123+
) {
124+
dispatcher.dispatch(TaxonomyActionBuilder.newFetchedTermsAction(payload))
125+
}
126+
127+
private fun createTermsResponsePayload(
128+
terms: List<TermModel>,
129+
site: SiteModel,
130+
taxonomyName: String
131+
): FetchTermsResponsePayload = FetchTermsResponsePayload(
132+
TermsModel(terms),
133+
site,
134+
taxonomyName
135+
)
136+
}

libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaResponseUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class MediaResponseUtils
5959
from.thumbnails?.let { if (!TextUtils.isEmpty(it.medium)) it.medium else null },
6060
null,
6161
from.thumbnails?.let { if (!TextUtils.isEmpty(it.large)) it.large else null },
62-
MediaWPComRestResponse.DELETED_STATUS == from.status
63-
)
62+
MediaWPComRestResponse.DELETED_STATUS == from.status,
63+
).apply {
64+
fileSizeFormatted = from.size
65+
}
6466
}

libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaWPComRestResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ public static class Thumbnails {
4747
@Nullable public String videopress_guid;
4848
public boolean videopress_processing_done;
4949
@Nullable public String status;
50+
@Nullable public String size;
5051
}

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

Lines changed: 6 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,11 @@ 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+
db.execSQL("ALTER TABLE MediaModel ADD FILE_SIZE_FORMATTED TEXT")
2087+
}
20832088
}
20842089
}
20852090
db.setTransactionSuccessful()

0 commit comments

Comments
 (0)