Skip to content

Commit df28fed

Browse files
committed
Save user agent string edits to database
1 parent b4f2b3a commit df28fed

4 files changed

Lines changed: 154 additions & 4 deletions

File tree

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 5,
5+
"identityHash": "446ac6c5910d731ad6700fac116d9f50",
6+
"entities": [
7+
{
8+
"tableName": "subscriptions",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `calendarId` INTEGER, `url` TEXT NOT NULL, `eTag` TEXT, `displayName` TEXT NOT NULL, `lastModified` INTEGER, `lastSync` INTEGER, `errorMessage` TEXT, `ignoreEmbeddedAlerts` INTEGER NOT NULL, `defaultAlarmMinutes` INTEGER, `defaultAllDayAlarmMinutes` INTEGER, `ignoreDescription` INTEGER NOT NULL DEFAULT 0, `color` INTEGER, `customUserAgent` TEXT)",
10+
"fields": [
11+
{
12+
"fieldPath": "id",
13+
"columnName": "id",
14+
"affinity": "INTEGER",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "calendarId",
19+
"columnName": "calendarId",
20+
"affinity": "INTEGER"
21+
},
22+
{
23+
"fieldPath": "url",
24+
"columnName": "url",
25+
"affinity": "TEXT",
26+
"notNull": true
27+
},
28+
{
29+
"fieldPath": "eTag",
30+
"columnName": "eTag",
31+
"affinity": "TEXT"
32+
},
33+
{
34+
"fieldPath": "displayName",
35+
"columnName": "displayName",
36+
"affinity": "TEXT",
37+
"notNull": true
38+
},
39+
{
40+
"fieldPath": "lastModified",
41+
"columnName": "lastModified",
42+
"affinity": "INTEGER"
43+
},
44+
{
45+
"fieldPath": "lastSync",
46+
"columnName": "lastSync",
47+
"affinity": "INTEGER"
48+
},
49+
{
50+
"fieldPath": "errorMessage",
51+
"columnName": "errorMessage",
52+
"affinity": "TEXT"
53+
},
54+
{
55+
"fieldPath": "ignoreEmbeddedAlerts",
56+
"columnName": "ignoreEmbeddedAlerts",
57+
"affinity": "INTEGER",
58+
"notNull": true
59+
},
60+
{
61+
"fieldPath": "defaultAlarmMinutes",
62+
"columnName": "defaultAlarmMinutes",
63+
"affinity": "INTEGER"
64+
},
65+
{
66+
"fieldPath": "defaultAllDayAlarmMinutes",
67+
"columnName": "defaultAllDayAlarmMinutes",
68+
"affinity": "INTEGER"
69+
},
70+
{
71+
"fieldPath": "ignoreDescription",
72+
"columnName": "ignoreDescription",
73+
"affinity": "INTEGER",
74+
"notNull": true,
75+
"defaultValue": "0"
76+
},
77+
{
78+
"fieldPath": "color",
79+
"columnName": "color",
80+
"affinity": "INTEGER"
81+
},
82+
{
83+
"fieldPath": "customUserAgent",
84+
"columnName": "customUserAgent",
85+
"affinity": "TEXT"
86+
}
87+
],
88+
"primaryKey": {
89+
"autoGenerate": true,
90+
"columnNames": [
91+
"id"
92+
]
93+
}
94+
},
95+
{
96+
"tableName": "credentials",
97+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`subscriptionId` INTEGER NOT NULL, `username` TEXT NOT NULL, `password` TEXT NOT NULL, PRIMARY KEY(`subscriptionId`), FOREIGN KEY(`subscriptionId`) REFERENCES `subscriptions`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
98+
"fields": [
99+
{
100+
"fieldPath": "subscriptionId",
101+
"columnName": "subscriptionId",
102+
"affinity": "INTEGER",
103+
"notNull": true
104+
},
105+
{
106+
"fieldPath": "username",
107+
"columnName": "username",
108+
"affinity": "TEXT",
109+
"notNull": true
110+
},
111+
{
112+
"fieldPath": "password",
113+
"columnName": "password",
114+
"affinity": "TEXT",
115+
"notNull": true
116+
}
117+
],
118+
"primaryKey": {
119+
"autoGenerate": false,
120+
"columnNames": [
121+
"subscriptionId"
122+
]
123+
},
124+
"foreignKeys": [
125+
{
126+
"table": "subscriptions",
127+
"onDelete": "CASCADE",
128+
"onUpdate": "NO ACTION",
129+
"columns": [
130+
"subscriptionId"
131+
],
132+
"referencedColumns": [
133+
"id"
134+
]
135+
}
136+
]
137+
}
138+
],
139+
"setupQueries": [
140+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
141+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '446ac6c5910d731ad6700fac116d9f50')"
142+
]
143+
}
144+
}

app/src/main/java/at/bitfire/icsdroid/db/entity/Subscription.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ data class Subscription(
5050
val ignoreDescription: Boolean = false,
5151

5252
/** The color that represents the subscription. */
53-
val color: Int? = null
53+
val color: Int? = null,
54+
55+
/** The user given user agent string to use for HTTP requests. */
56+
val customUserAgent: String? = null
5457
) {
5558
constructor(json: JSONObject): this(
5659
url = json.getString(JSON_URL).toUri(),
@@ -64,6 +67,7 @@ data class Subscription(
6467
defaultAllDayAlarmMinutes = json.getStringOrNull(JSON_DEFAULT_ALL_DAY_ALARM)?.toLongOrNull(),
6568
ignoreDescription = json.getStringOrNull(JSON_IGNORE_DESCRIPTION).toBoolean(),
6669
color = json.getStringOrNull(JSON_COLOR)?.toIntOrNull(),
70+
customUserAgent = json.getStringOrNull(CUSTOM_USER_AGENT),
6771
)
6872

6973
/**
@@ -90,6 +94,7 @@ data class Subscription(
9094
defaultAllDayAlarmMinutes?.let { put(JSON_DEFAULT_ALL_DAY_ALARM, it) }
9195
put(JSON_IGNORE_DESCRIPTION, ignoreDescription)
9296
color?.let { put(JSON_COLOR, it) }
97+
customUserAgent?.let { put(CUSTOM_USER_AGENT, it) }
9398
}
9499

95100

@@ -105,6 +110,7 @@ data class Subscription(
105110
const val JSON_DEFAULT_ALL_DAY_ALARM = "defaultAllDayAlarmMinutes"
106111
const val JSON_IGNORE_DESCRIPTION = "ignoreDescription"
107112
const val JSON_COLOR = "color"
113+
const val CUSTOM_USER_AGENT = "customUserAgent"
108114
}
109115

110116
}

app/src/main/java/at/bitfire/icsdroid/model/EditSubscriptionModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class EditSubscriptionModel @AssistedInject constructor(
105105
setUrl(subscription.url.toString())
106106
setTitle(subscription.displayName)
107107
setColor(subscription.color)
108-
// setCustomUserAgent(subscription.customUserAgent)
108+
setCustomUserAgent(subscription.customUserAgent)
109109
setIgnoreAlerts(subscription.ignoreEmbeddedAlerts)
110110
setDefaultAlarmMinutes(subscription.defaultAlarmMinutes?.toString())
111111
setDefaultAllDayAlarmMinutes(subscription.defaultAllDayAlarmMinutes?.toString())
@@ -135,7 +135,7 @@ class EditSubscriptionModel @AssistedInject constructor(
135135
val newSubscription = subscription.copy(
136136
displayName = title ?: subscription.displayName,
137137
color = color,
138-
// customUserAgent = customUserAgent,
138+
customUserAgent = customUserAgent,
139139
defaultAlarmMinutes = defaultAlarmMinutes,
140140
defaultAllDayAlarmMinutes = defaultAllDayAlarmMinutes,
141141
ignoreEmbeddedAlerts = ignoreAlerts,

app/src/main/java/at/bitfire/icsdroid/model/SubscriptionSettingsUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SubscriptionSettingsUseCase @Inject constructor() {
9191
uiState.url == subscription.url.toString()
9292
&& uiState.title == subscription.displayName
9393
&& uiState.color == subscription.color
94-
// && uiState.customUserAgent == subscription.customUserAgent
94+
&& uiState.customUserAgent == subscription.customUserAgent
9595
&& uiState.ignoreAlerts == subscription.ignoreEmbeddedAlerts
9696
&& uiState.defaultAlarmMinutes == subscription.defaultAlarmMinutes
9797
&& uiState.defaultAllDayAlarmMinutes == subscription.defaultAllDayAlarmMinutes

0 commit comments

Comments
 (0)