Skip to content

Commit 6b113ef

Browse files
authored
fix: remove callbacks and fixes segment issue (#7)
* fix: removes callbacks * fix: removes unused type * fix: removes unused import
1 parent 6477c02 commit 6b113ef

11 files changed

Lines changed: 189 additions & 68 deletions

File tree

android/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
id("com.vanniktech.maven.publish") version "0.31.0"
1111
}
1212

13-
version = "1.0.0"
13+
version = "1.1.0"
1414
val groupId = "com.formbricks"
1515
val artifactId = "android"
1616

android/proguard-rules.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
-keep class com.formbricks.android.Formbricks { *; }
3636
-keep class com.formbricks.android.helper.FormbricksConfig { *; }
3737
-keep class com.formbricks.android.model.error.SDKError { *; }
38-
-keep interface com.formbricks.android.FormbricksCallback { *; }
3938

4039
# Keep StringConcatFactory and related classes
4140
-keep class java.lang.invoke.StringConcatFactory { *; }

android/src/main/java/com/formbricks/android/Formbricks.kt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,10 @@ import com.formbricks.android.helper.FormbricksConfig
1010
import com.formbricks.android.logger.Logger
1111
import com.formbricks.android.manager.SurveyManager
1212
import com.formbricks.android.manager.UserManager
13-
import com.formbricks.android.model.enums.SuccessType
1413
import com.formbricks.android.model.error.SDKError
1514
import com.formbricks.android.webview.FormbricksFragment
1615
import java.lang.RuntimeException
1716

18-
@Keep
19-
interface FormbricksCallback {
20-
fun onSurveyStarted()
21-
fun onSurveyFinished()
22-
fun onSurveyClosed()
23-
fun onPageCommitVisible()
24-
fun onError(error: Exception)
25-
fun onSuccess(successType: SuccessType)
26-
}
27-
28-
2917
@Keep
3018
object Formbricks {
3119
internal lateinit var applicationContext: Context
@@ -37,8 +25,6 @@ object Formbricks {
3725
private var fragmentManager: FragmentManager? = null
3826
internal var isInitialized = false
3927

40-
var callback: FormbricksCallback? = null
41-
4228
/**
4329
* Initializes the Formbricks SDK with the given [Context] config [FormbricksConfig].
4430
* This method is mandatory to be called, and should be only once per application lifecycle.
@@ -62,7 +48,6 @@ object Formbricks {
6248
fun setup(context: Context, config: FormbricksConfig, forceRefresh: Boolean = false) {
6349
if (isInitialized && !forceRefresh) {
6450
val error = SDKError.sdkIsAlreadyInitialized
65-
callback?.onError(error)
6651
Logger.e(error)
6752
return
6853
}
@@ -97,14 +82,12 @@ object Formbricks {
9782
fun setUserId(userId: String) {
9883
if (!isInitialized) {
9984
val error = SDKError.sdkIsNotInitialized
100-
callback?.onError(error)
10185
Logger.e(error)
10286
return
10387
}
10488

10589
if(UserManager.userId != null) {
10690
val error = RuntimeException("A userId is already set ${UserManager.userId} - please call logout first before setting a new one")
107-
callback?.onError(error)
10891
Logger.e(error)
10992
return
11093
}
@@ -124,7 +107,6 @@ object Formbricks {
124107
fun setAttribute(attribute: String, key: String) {
125108
if (!isInitialized) {
126109
val error = SDKError.sdkIsNotInitialized
127-
callback?.onError(error)
128110
Logger.e(error)
129111
return
130112
}
@@ -143,7 +125,6 @@ object Formbricks {
143125
fun setAttributes(attributes: Map<String, String>) {
144126
if (!isInitialized) {
145127
val error = SDKError.sdkIsNotInitialized
146-
callback?.onError(error)
147128
Logger.e(error)
148129
return
149130
}
@@ -162,7 +143,6 @@ object Formbricks {
162143
fun setLanguage(language: String) {
163144
if (!isInitialized) {
164145
val error = SDKError.sdkIsNotInitialized
165-
callback?.onError(error)
166146
Logger.e(error)
167147
return
168148
}
@@ -182,14 +162,12 @@ object Formbricks {
182162
fun track(action: String) {
183163
if (!isInitialized) {
184164
val error = SDKError.sdkIsNotInitialized
185-
callback?.onError(error)
186165
Logger.e(error)
187166
return
188167
}
189168

190169
if (!isInternetAvailable()) {
191170
val error = SDKError.connectionIsNotAvailable
192-
callback?.onError(error)
193171
Logger.e(error)
194172
return
195173
}
@@ -209,12 +187,10 @@ object Formbricks {
209187
fun logout() {
210188
if (!isInitialized) {
211189
val error = SDKError.sdkIsNotInitialized
212-
callback?.onError(error)
213190
Logger.e(error)
214191
return
215192
}
216193

217-
callback?.onSuccess(SuccessType.LOGOUT_SUCCESS)
218194
UserManager.logout()
219195
}
220196

@@ -236,7 +212,6 @@ object Formbricks {
236212
internal fun showSurvey(id: String) {
237213
if (fragmentManager == null) {
238214
val error = SDKError.fragmentManagerIsNotSet
239-
callback?.onError(error)
240215
Logger.e(error)
241216
return
242217
}

android/src/main/java/com/formbricks/android/manager/SurveyManager.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.formbricks.android.logger.Logger
99
import com.formbricks.android.model.environment.EnvironmentDataHolder
1010
import com.formbricks.android.model.environment.Survey
1111
import com.formbricks.android.model.error.SDKError
12-
import com.formbricks.android.model.enums.SuccessType
1312
import com.formbricks.android.model.user.Display
1413
import com.google.gson.Gson
1514
import kotlinx.coroutines.CoroutineScope
@@ -60,7 +59,6 @@ object SurveyManager {
6059
try {
6160
Gson().fromJson(json, EnvironmentDataHolder::class.java)
6261
} catch (e: Exception) {
63-
Formbricks.callback?.onError(e)
6462
Logger.e(RuntimeException("Unable to retrieve environment data from the local storage."))
6563
null
6664
}
@@ -118,11 +116,9 @@ object SurveyManager {
118116
startRefreshTimer(environmentDataHolder?.expiresAt())
119117
filterSurveys()
120118
hasApiError = false
121-
Formbricks.callback?.onSuccess(SuccessType.GET_ENVIRONMENT_SUCCESS)
122119
} catch (e: Exception) {
123120
hasApiError = true
124121
val error = SDKError.unableToRefreshEnvironment
125-
Formbricks.callback?.onError(error)
126122
Logger.e(error)
127123
startErrorTimer()
128124
}
@@ -143,7 +139,8 @@ object SurveyManager {
143139
}
144140

145141
if (firstSurveyWithActionClass == null) {
146-
Formbricks.callback?.onError(SDKError.surveyNotFoundError)
142+
val error = SDKError.surveyNotFoundError
143+
Logger.e(error)
147144
return
148145
}
149146

@@ -154,7 +151,6 @@ object SurveyManager {
154151

155152
if (languageCode == null) {
156153
val error = RuntimeException("Survey “${firstSurveyWithActionClass.name}” is not available in language “$currentLanguage”. Skipping.")
157-
Formbricks.callback?.onError(error)
158154
Logger.e(error)
159155
return
160156
}
@@ -177,7 +173,8 @@ object SurveyManager {
177173
}, Date(System.currentTimeMillis() + timeout.toLong() * 1000))
178174
}
179175
} else {
180-
Formbricks.callback?.onError(SDKError.surveyNotDisplayedError)
176+
val error = SDKError.surveyNotDisplayedError
177+
Logger.e(error)
181178
}
182179
}
183180

@@ -192,7 +189,6 @@ object SurveyManager {
192189
fun postResponse(surveyId: String?) {
193190
val id = surveyId.guard {
194191
val error = SDKError.missingSurveyId
195-
Formbricks.callback?.onError(error)
196192
Logger.e(error)
197193
return
198194
}
@@ -206,7 +202,6 @@ object SurveyManager {
206202
fun onNewDisplay(surveyId: String?) {
207203
val id = surveyId.guard {
208204
val error = SDKError.missingSurveyId
209-
Formbricks.callback?.onError(error)
210205
Logger.e(error)
211206
return
212207
}
@@ -269,7 +264,6 @@ object SurveyManager {
269264

270265
else -> {
271266
val error = SDKError.invalidDisplayOption
272-
Formbricks.callback?.onError(error)
273267
Logger.e(error)
274268
false
275269
}

android/src/main/java/com/formbricks/android/manager/UserManager.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.formbricks.android.extensions.guard
99
import com.formbricks.android.extensions.lastDisplayAt
1010
import com.formbricks.android.logger.Logger
1111
import com.formbricks.android.model.error.SDKError
12-
import com.formbricks.android.model.enums.SuccessType
1312
import com.formbricks.android.model.user.Display
1413
import com.formbricks.android.network.queue.UpdateQueue
1514
import com.google.gson.Gson
@@ -147,10 +146,8 @@ object UserManager {
147146
UpdateQueue.current.reset()
148147
SurveyManager.filterSurveys()
149148
startSyncTimer()
150-
Formbricks.callback?.onSuccess(SuccessType.SET_USER_SUCCESS)
151149
} catch (e: Exception) {
152150
val error = SDKError.unableToPostResponse
153-
Formbricks.callback?.onError(error)
154151
Logger.e(error)
155152
}
156153
}
@@ -164,7 +161,6 @@ object UserManager {
164161

165162
if (!isUserIdDefined) {
166163
val error = SDKError.noUserIdSetError
167-
Formbricks.callback?.onError(error)
168164
Logger.e(error)
169165
}
170166

0 commit comments

Comments
 (0)