Skip to content

Commit 78091ee

Browse files
authored
Merge branch 'main' into bookmark_enhancement
2 parents ed5f3fc + d32ab15 commit 78091ee

File tree

7 files changed

+308
-71
lines changed

7 files changed

+308
-71
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Android CI Comment
2+
3+
on: [pull_request_target]
4+
5+
permissions:
6+
issues: write
7+
8+
jobs:
9+
comment:
10+
name: Comment on PR with APK links
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout base branch
14+
uses: actions/checkout@v3
15+
with:
16+
ref: ${{ github.base_ref }}
17+
18+
- name: Download Run ID Artifact
19+
uses: actions/download-artifact@v4
20+
with:
21+
name: run-id
22+
23+
- name: Read Run ID
24+
id: read-run-id
25+
run: echo "RUN_ID=$(cat run_id.txt)" >> $GITHUB_ENV
26+
27+
- name: Comment on PR with APK download links
28+
env:
29+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
uses: actions/github-script@v6
31+
with:
32+
script: |
33+
try {
34+
const token = process.env.GH_TOKEN;
35+
if (!token) {
36+
throw new Error('GITHUB_TOKEN is not set.');
37+
}
38+
39+
const runId = "${{ env.RUN_ID }}";
40+
if (!runId) {
41+
throw new Error('Run ID not found.');
42+
}
43+
44+
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
run_id: runId
48+
});
49+
50+
if (!artifacts || artifacts.length === 0) {
51+
console.log('No artifacts found for this workflow run.');
52+
return;
53+
}
54+
55+
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK");
56+
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK");
57+
58+
if (!betaArtifact || !prodArtifact) {
59+
console.log('Could not find both Beta and Prod APK artifacts.');
60+
console.log('Available artifacts:', artifacts.map(a => a.name).join(', '));
61+
return;
62+
}
63+
64+
const betaDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${runId}/artifacts/${betaArtifact.id}`;
65+
const prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${runId}/artifacts/${prodArtifact.id}`;
66+
67+
const commentBody = `
68+
📱 **APK for pull request is ready to see the changes** 📱
69+
- [Download Beta APK](${betaDownloadUrl})
70+
- [Download Prod APK](${prodDownloadUrl})
71+
`;
72+
73+
await github.rest.issues.createComment({
74+
issue_number: context.issue.number,
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
body: commentBody
78+
});
79+
80+
console.log('Successfully posted comment with APK download links');
81+
} catch (error) {
82+
console.error('Error in PR comment creation:', error);
83+
core.setFailed(`Workflow failed: ${error.message}`);
84+
}

.github/workflows/android.yml

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Android CI
33
on: [push, pull_request, workflow_dispatch]
44

55
permissions:
6-
pull-requests: write
76
contents: read
87
actions: read
98

@@ -107,64 +106,14 @@ jobs:
107106
with:
108107
name: prodDebugAPK
109108
path: app/build/outputs/apk/prod/debug/app-*.apk
110-
111-
- name: Comment on PR with APK download links
109+
110+
- name: Store Workflow Run ID
112111
if: github.event_name == 'pull_request'
113-
uses: actions/github-script@v6
112+
run: echo "${{ github.run_id }}" > run_id.txt
113+
114+
- name: Upload Run ID as Artifact
115+
if: github.event_name == 'pull_request'
116+
uses: actions/upload-artifact@v4
114117
with:
115-
github-token: ${{secrets.GITHUB_TOKEN}}
116-
script: |
117-
try {
118-
const token = process.env.GITHUB_TOKEN;
119-
if (!token) {
120-
throw new Error('GITHUB_TOKEN is not set. Please check workflow permissions.');
121-
}
122-
123-
124-
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
125-
owner: context.repo.owner,
126-
repo: context.repo.repo,
127-
run_id: context.runId
128-
});
129-
130-
if (!artifacts || artifacts.length === 0) {
131-
console.log('No artifacts found for this workflow run.');
132-
return;
133-
}
134-
135-
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK");
136-
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK");
137-
138-
if (!betaArtifact || !prodArtifact) {
139-
console.log('Could not find both Beta and Prod APK artifacts.');
140-
console.log('Available artifacts:', artifacts.map(a => a.name).join(', '));
141-
return;
142-
}
143-
144-
const betaDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${betaArtifact.id}`;
145-
const prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${prodArtifact.id}`;
146-
147-
const commentBody = `
148-
📱 **APK for pull request is ready to see the changes** 📱
149-
- [Download Beta APK](${betaDownloadUrl})
150-
- [Download Prod APK](${prodDownloadUrl})
151-
`;
152-
153-
await github.rest.issues.createComment({
154-
issue_number: context.issue.number,
155-
owner: context.repo.owner,
156-
repo: context.repo.repo,
157-
body: commentBody
158-
});
159-
160-
console.log('Successfully posted comment with APK download links');
161-
} catch (error) {
162-
console.error('Error in PR comment creation:', error);
163-
if (error.message.includes('GITHUB_TOKEN')) {
164-
core.setFailed('Missing or invalid GITHUB_TOKEN. Please check repository secrets configuration.');
165-
} else if (error.status === 403) {
166-
core.setFailed('Permission denied. Please check workflow permissions in repository settings.');
167-
} else {
168-
core.setFailed(`Workflow failed: ${error.message}`);
169-
}
170-
}
118+
name: run-id
119+
path: run_id.txt

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ dependencies {
175175
testImplementation "androidx.work:work-testing:$work_version"
176176

177177
//Glide
178-
implementation 'com.github.bumptech.glide:glide:4.12.0'
179-
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
178+
implementation 'com.github.bumptech.glide:glide:4.16.0'
179+
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'
180180
kaptTest "androidx.databinding:databinding-compiler:8.0.2"
181181
kaptAndroidTest "androidx.databinding:databinding-compiler:8.0.2"
182182

app/src/main/java/fr/free/nrw/commons/Media.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,41 @@ class Media constructor(
9090
captions = captions,
9191
)
9292

93+
constructor(
94+
captions: Map<String, String>,
95+
categories: List<String>?,
96+
filename: String?,
97+
fallbackDescription: String?,
98+
author: String?,
99+
user: String?,
100+
dateUploaded: Date? = Date(),
101+
license: String? = null,
102+
licenseUrl: String? = null,
103+
imageUrl: String? = null,
104+
thumbUrl: String? = null,
105+
coordinates: LatLng? = null,
106+
descriptions: Map<String, String> = emptyMap(),
107+
depictionIds: List<String> = emptyList(),
108+
categoriesHiddenStatus: Map<String, Boolean> = emptyMap()
109+
) : this(
110+
pageId = UUID.randomUUID().toString(),
111+
filename = filename,
112+
fallbackDescription = fallbackDescription,
113+
dateUploaded = dateUploaded,
114+
author = author,
115+
user = user,
116+
categories = categories,
117+
captions = captions,
118+
license = license,
119+
licenseUrl = licenseUrl,
120+
imageUrl = imageUrl,
121+
thumbUrl = thumbUrl,
122+
coordinates = coordinates,
123+
descriptions = descriptions,
124+
depictionIds = depictionIds,
125+
categoriesHiddenStatus = categoriesHiddenStatus
126+
)
127+
93128
/**
94129
* Gets media display title
95130
* @return Media title

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import android.view.KeyEvent
1616
import android.view.LayoutInflater
1717
import android.view.View
1818
import android.view.ViewGroup
19+
import android.view.ViewTreeObserver
1920
import android.view.ViewTreeObserver.OnGlobalLayoutListener
2021
import android.widget.ArrayAdapter
2122
import android.widget.Button
@@ -405,9 +406,14 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
405406
* Gets the height of the frame layout as soon as the view is ready and updates aspect ratio
406407
* of the picture.
407408
*/
408-
view.post {
409-
frameLayoutHeight = binding.mediaDetailFrameLayout.measuredHeight
410-
updateAspectRatio(binding.mediaDetailScrollView.width)
409+
view.post{
410+
val width = binding.mediaDetailScrollView.width
411+
if (width > 0) {
412+
frameLayoutHeight = binding.mediaDetailFrameLayout.measuredHeight
413+
updateAspectRatio(width)
414+
} else {
415+
view.postDelayed({ updateAspectRatio(binding.root.width) }, 1)
416+
}
411417
}
412418

413419
return view

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,12 @@ public void onCreate(Bundle savedInstanceState) {
185185
* or a fragment
186186
*/
187187
private void initProvider() {
188-
if (getParentFragment() != null) {
188+
if (getParentFragment() instanceof MediaDetailProvider) {
189189
provider = (MediaDetailProvider) getParentFragment();
190-
} else {
190+
} else if (getActivity() instanceof MediaDetailProvider) {
191191
provider = (MediaDetailProvider) getActivity();
192+
} else {
193+
throw new ClassCastException("Parent must implement MediaDetailProvider");
192194
}
193195
}
194196

0 commit comments

Comments
 (0)