Skip to content

Commit 64fd10d

Browse files
authored
Migrate Feedback module from Java to Kt (#5985)
* Rename `.java` to `.kt` * Migrated FeedbackContentCreator to kotlin * Rename FeedbackDialog from `java` to `kt` * Migrated Feedback Dialog from `java` to `kt` * Renamed OnFeedbackSubmitCallback to kotlij * Migrated OnFeedbackSubmitCallback to kotlin * Fixed: TestCase Failure * Fixed Test : Changed Private Modifier to Public * Suppressed deprecated and added TODO for lint * Linked Deprecation with Github Issue * Rename Feedback from java to kt * Migrated Feedback Data Class to Kotlin * Modified the data class to var for mutuability
1 parent 015c5d5 commit 64fd10d

File tree

10 files changed

+252
-387
lines changed

10 files changed

+252
-387
lines changed

app/src/main/java/fr/free/nrw/commons/feedback/FeedbackContentCreator.java

Lines changed: 0 additions & 120 deletions
This file was deleted.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package fr.free.nrw.commons.feedback
2+
3+
import android.content.Context
4+
import fr.free.nrw.commons.R
5+
import fr.free.nrw.commons.auth.getUserName
6+
import fr.free.nrw.commons.feedback.model.Feedback
7+
import fr.free.nrw.commons.utils.LangCodeUtils.getLocalizedResources
8+
import java.text.SimpleDateFormat
9+
import java.util.Date
10+
import java.util.Locale
11+
import java.util.TimeZone
12+
13+
class FeedbackContentCreator(context: Context, feedback: Feedback) {
14+
private var sectionTitleBuilder = StringBuilder()
15+
private var sectionTextBuilder = StringBuilder()
16+
init {
17+
// Localization is not needed here
18+
// because this ends up on a page where developers read the feedback,
19+
// so English is the most convenient.
20+
21+
//Get the UTC Date and Time and add it to the Title
22+
val dateFormat = SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ENGLISH)
23+
dateFormat.timeZone = TimeZone.getTimeZone("UTC")
24+
val utcFormattedDate = dateFormat.format(Date())
25+
26+
// Construct the feedback section title
27+
sectionTitleBuilder.append("Feedback from ")
28+
sectionTitleBuilder.append(getUserName(context))
29+
sectionTitleBuilder.append(" for version ")
30+
sectionTitleBuilder.append(feedback.version)
31+
sectionTitleBuilder.append(" on ")
32+
sectionTitleBuilder.append(utcFormattedDate)
33+
34+
// Construct the feedback section text
35+
sectionTextBuilder = StringBuilder()
36+
sectionTextBuilder.append("\n")
37+
sectionTextBuilder.append(feedback.title)
38+
sectionTextBuilder.append("\n")
39+
sectionTextBuilder.append("\n")
40+
if (feedback.apiLevel != null) {
41+
sectionTextBuilder.append("* ")
42+
sectionTextBuilder.append(
43+
getLocalizedResources(
44+
context,
45+
Locale.ENGLISH
46+
).getString(R.string.api_level)
47+
)
48+
sectionTextBuilder.append(": ")
49+
sectionTextBuilder.append(feedback.apiLevel)
50+
sectionTextBuilder.append("\n")
51+
}
52+
if (feedback.androidVersion != null) {
53+
sectionTextBuilder.append("* ")
54+
sectionTextBuilder.append(
55+
getLocalizedResources(
56+
context,
57+
Locale.ENGLISH
58+
).getString(R.string.android_version)
59+
)
60+
sectionTextBuilder.append(": ")
61+
sectionTextBuilder.append(feedback.androidVersion)
62+
sectionTextBuilder.append("\n")
63+
}
64+
if (feedback.deviceManufacturer != null) {
65+
sectionTextBuilder.append("* ")
66+
sectionTextBuilder.append(
67+
getLocalizedResources(
68+
context,
69+
Locale.ENGLISH
70+
).getString(R.string.device_manufacturer)
71+
)
72+
sectionTextBuilder.append(": ")
73+
sectionTextBuilder.append(feedback.deviceManufacturer)
74+
sectionTextBuilder.append("\n")
75+
}
76+
if (feedback.deviceModel != null) {
77+
sectionTextBuilder.append("* ")
78+
sectionTextBuilder.append(
79+
getLocalizedResources(
80+
context,
81+
Locale.ENGLISH
82+
).getString(R.string.device_model)
83+
)
84+
sectionTextBuilder.append(": ")
85+
sectionTextBuilder.append(feedback.deviceModel)
86+
sectionTextBuilder.append("\n")
87+
}
88+
if (feedback.device != null) {
89+
sectionTextBuilder.append("* ")
90+
sectionTextBuilder.append(
91+
getLocalizedResources(
92+
context,
93+
Locale.ENGLISH
94+
).getString(R.string.device_name)
95+
)
96+
sectionTextBuilder.append(": ")
97+
sectionTextBuilder.append(feedback.device)
98+
sectionTextBuilder.append("\n")
99+
}
100+
if (feedback.networkType != null) {
101+
sectionTextBuilder.append("* ")
102+
sectionTextBuilder.append(
103+
getLocalizedResources(
104+
context,
105+
Locale.ENGLISH
106+
).getString(R.string.network_type)
107+
)
108+
sectionTextBuilder.append(": ")
109+
sectionTextBuilder.append(feedback.networkType)
110+
sectionTextBuilder.append("\n")
111+
}
112+
sectionTextBuilder.append("~~~~")
113+
sectionTextBuilder.append("\n")
114+
}
115+
116+
fun getSectionText(): String {
117+
return sectionTextBuilder.toString()
118+
}
119+
120+
fun getSectionTitle(): String {
121+
return sectionTitleBuilder.toString()
122+
}
123+
}

app/src/main/java/fr/free/nrw/commons/feedback/FeedbackDialog.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)