Skip to content

Commit 00526be

Browse files
Compatibilty updates for ical4j 4.x (#2260)
1 parent d624963 commit 00526be

8 files changed

Lines changed: 185 additions & 235 deletions

File tree

app/src/androidTest/java/at/techbee/jtx/SyncContentProviderTest.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -820,33 +820,33 @@ class SyncContentProviderTest {
820820

821821
// insert 2 icalobjects
822822
val parentCV = ContentValues().apply {
823-
put(at.techbee.jtx.JtxContract.JtxICalObject.SUMMARY, "summary")
824-
put(at.techbee.jtx.JtxContract.JtxICalObject.COMPONENT, at.techbee.jtx.JtxContract.JtxICalObject.Component.VJOURNAL.name)
825-
put(at.techbee.jtx.JtxContract.JtxICalObject.UID, "AAA")
826-
put(at.techbee.jtx.JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, defaultCollectionId)
823+
put(JtxContract.JtxICalObject.SUMMARY, "summary")
824+
put(JtxContract.JtxICalObject.COMPONENT, JtxContract.JtxICalObject.Component.VJOURNAL.name)
825+
put(JtxContract.JtxICalObject.UID, "AAA")
826+
put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, defaultCollectionId)
827827
}
828-
mContentResolver?.insert(at.techbee.jtx.JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(defaultTestAccount), parentCV)
828+
mContentResolver?.insert(JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(defaultTestAccount), parentCV)
829829
val childCV = ContentValues().apply {
830-
put(at.techbee.jtx.JtxContract.JtxICalObject.SUMMARY, "summary")
831-
put(at.techbee.jtx.JtxContract.JtxICalObject.COMPONENT, at.techbee.jtx.JtxContract.JtxICalObject.Component.VJOURNAL.name)
832-
put(at.techbee.jtx.JtxContract.JtxICalObject.UID, "BBB")
833-
put(at.techbee.jtx.JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, defaultCollectionId)
830+
put(JtxContract.JtxICalObject.SUMMARY, "summary")
831+
put(JtxContract.JtxICalObject.COMPONENT, JtxContract.JtxICalObject.Component.VJOURNAL.name)
832+
put(JtxContract.JtxICalObject.UID, "BBB")
833+
put(JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID, defaultCollectionId)
834834
}
835-
val childUri = mContentResolver?.insert(at.techbee.jtx.JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(defaultTestAccount), childCV)
835+
val childUri = mContentResolver?.insert(JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(defaultTestAccount), childCV)
836836

837837
// link one of them to the other with PARENT reltype
838838
val parentRelCV = ContentValues().apply {
839-
put(at.techbee.jtx.JtxContract.JtxRelatedto.ICALOBJECT_ID, childUri?.lastPathSegment)
840-
put(at.techbee.jtx.JtxContract.JtxRelatedto.TEXT, "AAA")
841-
put(at.techbee.jtx.JtxContract.JtxRelatedto.RELTYPE, at.techbee.jtx.JtxContract.JtxRelatedto.Reltype.PARENT.name)
839+
put(JtxContract.JtxRelatedto.ICALOBJECT_ID, childUri?.lastPathSegment)
840+
put(JtxContract.JtxRelatedto.TEXT, "AAA")
841+
put(JtxContract.JtxRelatedto.RELTYPE, JtxContract.JtxRelatedto.Reltype.PARENT.name)
842842
}
843843
mContentResolver?.insert(JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(defaultTestAccount), parentRelCV)
844844

845845
// check child to parent
846846
mContentResolver?.query(
847-
at.techbee.jtx.JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(defaultTestAccount),
848-
arrayOf(at.techbee.jtx.JtxContract.JtxRelatedto.ICALOBJECT_ID, at.techbee.jtx.JtxContract.JtxRelatedto.TEXT, at.techbee.jtx.JtxContract.JtxRelatedto.RELTYPE),
849-
"${at.techbee.jtx.JtxContract.JtxRelatedto.ICALOBJECT_ID} = ?",
847+
JtxContract.JtxRelatedto.CONTENT_URI.asSyncAdapter(defaultTestAccount),
848+
arrayOf(JtxContract.JtxRelatedto.ICALOBJECT_ID, JtxContract.JtxRelatedto.TEXT, JtxContract.JtxRelatedto.RELTYPE),
849+
"${JtxContract.JtxRelatedto.ICALOBJECT_ID} = ?",
850850
arrayOf(childUri?.lastPathSegment),
851851
null
852852
).use {
@@ -861,7 +861,7 @@ class SyncContentProviderTest {
861861
it?.getString(1)
862862
) // TEXT (UID)
863863
assertEquals(
864-
at.techbee.jtx.JtxContract.JtxRelatedto.Reltype.PARENT.name,
864+
JtxContract.JtxRelatedto.Reltype.PARENT.name,
865865
it?.getString(2)
866866
)
867867
}

app/src/main/java/at/techbee/jtx/contract/JtxContract.kt

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import at.techbee.jtx.contract.JtxContract.JtxICalObject.GEO_LAT
2727
import at.techbee.jtx.contract.JtxContract.JtxICalObject.GEO_LONG
2828
import at.techbee.jtx.contract.JtxContract.JtxICalObject.TZ_ALLDAY
2929
import net.fortuna.ical4j.model.ParameterList
30-
import net.fortuna.ical4j.model.Property
3130
import net.fortuna.ical4j.model.PropertyList
3231
import net.fortuna.ical4j.model.parameter.XParameter
3332
import net.fortuna.ical4j.model.property.XProperty
@@ -36,7 +35,6 @@ import java.util.logging.Level
3635
import java.util.logging.Logger
3736

3837

39-
@Suppress("unused")
4038
object JtxContract {
4139

4240
private val logger
@@ -101,8 +99,8 @@ object JtxContract {
10199
* @param [string] that should be parsed
102100
* @return The list of XProperty parsed from the string
103101
*/
104-
fun getXPropertyListFromJson(string: String): PropertyList<Property> {
105-
val propertyList = PropertyList<Property>()
102+
fun getXPropertyListFromJson(string: String): PropertyList {
103+
val propertyList = PropertyList()
106104

107105
if (string.isBlank())
108106
return propertyList
@@ -136,7 +134,10 @@ object JtxContract {
136134
return null
137135

138136
val jsonObject = JSONObject()
139-
parameters.forEach { parameter ->
137+
138+
// Note: probably the contract should be separated from methods that do things, especially if they depend on ical4j
139+
140+
parameters.all.forEach { parameter ->
140141
jsonObject.put(parameter.name, parameter.value)
141142
}
142143
return if (jsonObject.length() == 0)
@@ -151,12 +152,14 @@ object JtxContract {
151152
* @param [propertyList] The PropertyList that should be transformed into a Json String
152153
* @return The generated Json object as a [String]
153154
*/
154-
fun getJsonStringFromXProperties(propertyList: PropertyList<*>?): String? {
155+
fun getJsonStringFromXProperties(propertyList: PropertyList?): String? {
155156
if (propertyList == null)
156157
return null
157158

159+
// Note: probably the contract should be separated from methods that do things, especially if they depend on ical4j
160+
158161
val jsonObject = JSONObject()
159-
propertyList.forEach { property ->
162+
propertyList.all.forEach { property ->
160163
jsonObject.put(property.name, property.value)
161164
}
162165
return if (jsonObject.length() == 0)
@@ -181,7 +184,7 @@ object JtxContract {
181184
stringList.forEach {
182185
try {
183186
longList.add(it.toLong())
184-
} catch (e: NumberFormatException) {
187+
} catch (_: NumberFormatException) {
185188
logger.log(Level.WARNING, "String could not be cast to Long ($it)")
186189
return@forEach
187190
}
@@ -190,7 +193,6 @@ object JtxContract {
190193
}
191194

192195

193-
@Suppress("unused")
194196
object JtxICalObject {
195197

196198
/** The name of the the content URI for IcalObjects.
@@ -208,7 +210,7 @@ object JtxContract {
208210
val VIEW_INTENT_URI: Uri by lazy { "content://$VIEW_INTENT_HOST/$CONTENT_URI_PATH".toUri() }
209211

210212
/* Convenience function to directly build the content URI to view a specific ICalObject in jtx Board by its ID */
211-
fun getViewIntentUriFor(iCalObjectId: Long) = Uri.withAppendedPath(VIEW_INTENT_URI, iCalObjectId.toString())
213+
fun getViewIntentUriFor(iCalObjectId: Long): Uri = Uri.withAppendedPath(VIEW_INTENT_URI, iCalObjectId.toString())
212214

213215

214216

@@ -648,7 +650,6 @@ object JtxContract {
648650
}
649651

650652

651-
@Suppress("unused")
652653
object JtxAttendee {
653654

654655
/** The name of the the table for Attendees that are linked to an ICalObject.
@@ -807,19 +808,16 @@ object JtxContract {
807808
}
808809

809810
/** This enum class defines the possible values for the attribute [JtxAttendee] for the Component VJOURNAL */
810-
@Suppress("unused")
811811
enum class PartstatJournal {
812812
`NEEDS-ACTION`, ACCEPTED, DECLINED
813813
}
814814

815815
/** This enum class defines the possible values for the attribute [JtxAttendee] for the Component VTODO */
816-
@Suppress("unused")
817816
enum class PartstatTodo {
818817
`NEEDS-ACTION`, ACCEPTED, DECLINED, TENTATIVE, DELEGATED, COMPLETED, `IN-PROCESS`
819818
}
820819
}
821820

822-
@Suppress("unused")
823821
object JtxCategory {
824822

825823
/** The name of the the table for Categories that are linked to an ICalObject.
@@ -869,7 +867,7 @@ object JtxContract {
869867
const val OTHER = "other"
870868
}
871869

872-
@Suppress("unused")
870+
873871
object JtxComment {
874872

875873
/** The name of the the table for Comments that are linked to an ICalObject.
@@ -927,7 +925,7 @@ object JtxContract {
927925
}
928926

929927

930-
@Suppress("unused")
928+
931929
object JtxOrganizer {
932930
/** The name of the the table for Organizer that are linked to an ICalObject.
933931
* [https://tools.ietf.org/html/rfc5545#section-3.8.4.3]
@@ -1006,7 +1004,7 @@ object JtxContract {
10061004

10071005
}
10081006

1009-
@Suppress("unused")
1007+
10101008
object JtxRelatedto {
10111009

10121010
/** The name of the the table for Relationships (related-to) that are linked to an ICalObject.
@@ -1076,7 +1074,7 @@ object JtxContract {
10761074

10771075
}
10781076

1079-
@Suppress("unused")
1077+
10801078
object JtxResource {
10811079
/** The name of the the table for Resources that are linked to an ICalObject.
10821080
* [https://tools.ietf.org/html/rfc5545#section-3.8.1.10]*/
@@ -1126,7 +1124,7 @@ object JtxContract {
11261124

11271125
}
11281126

1129-
@Suppress("unused")
1127+
11301128
object JtxCollection {
11311129

11321130
/** The name of the the table for Collections
@@ -1250,7 +1248,7 @@ object JtxContract {
12501248
}
12511249

12521250

1253-
@Suppress("unused")
1251+
12541252
object JtxAttachment {
12551253

12561254
/** The name of the the table for Attachments that are linked to an ICalObject.*/
@@ -1314,7 +1312,7 @@ object JtxContract {
13141312
}
13151313

13161314

1317-
@Suppress("unused")
1315+
13181316
object JtxAlarm {
13191317

13201318
/** The name of the the table for Alarms that are linked to an ICalObject.*/
@@ -1448,19 +1446,17 @@ object JtxContract {
14481446
const val TRIGGER_RELATIVE_DURATION = "triggerRelativeDuration"
14491447

14501448
/** This enum class defines the possible values for the attribute [TRIGGER_RELATIVE_TO] for the Component VALARM */
1451-
@Suppress("unused")
14521449
enum class AlarmRelativeTo {
14531450
START, END
14541451
}
14551452

14561453
/** This enum class defines the possible values for the attribute [ACTION] for the Component VALARM */
1457-
@Suppress("unused")
14581454
enum class AlarmAction {
14591455
AUDIO, DISPLAY, EMAIL
14601456
}
14611457
}
14621458

1463-
@Suppress("unused")
1459+
14641460
object JtxUnknown {
14651461

14661462
/** The name of the the table for Unknown properties that are linked to an ICalObject.*/

0 commit comments

Comments
 (0)