Skip to content

Commit 8aba1ab

Browse files
0.2.4
1 parent 1d1fd67 commit 8aba1ab

28 files changed

+831
-34
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ Then need to add implementation of QuickBlox UIKit and QuickBlox SDK to dependen
7777

7878
```
7979
dependencies {
80-
implementation "com.quickblox:android-ui-kit:0.2.3"
81-
implementation "com.quickblox:android-ai-answer-assistant:1.0.1"
82-
implementation "com.quickblox:android-ai-translate:1.0.0"
80+
implementation "com.quickblox:android-ui-kit:0.2.4"
8381
8482
implementation 'com.quickblox:quickblox-android-sdk-messages:4.1.1'
8583
implementation 'com.quickblox:quickblox-android-sdk-chat:4.1.1'
@@ -331,4 +329,4 @@ To use your own theme you just need to set it. This method must be called before
331329

332330
```
333331
QuickBloxUiKit.setTheme(CustomUiKitTheme())
334-
```
332+
```

ui-kit/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ext {
1010
qbSdkVersion = '4.1.1'
1111

1212
uiKitVersionCode = 1
13-
uiKitVersionName = "0.2.3"
13+
uiKitVersionName = "0.2.4"
1414
}
1515

1616
android {
@@ -71,6 +71,7 @@ dependencies {
7171
// QuickBlox AI
7272
api "com.quickblox:android-ai-answer-assistant:1.0.1"
7373
api "com.quickblox:android-ai-translate:1.0.0"
74+
api "com.quickblox:android-ai-editing-assistant:1.0.0"
7475

7576
implementation 'androidx.fragment:fragment-ktx:1.5.6'
7677
implementation 'androidx.core:core-ktx:1.9.0'

ui-kit/src/androidTest/java/com/quickblox/android_ui_kit/BaseTest.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ import com.quickblox.core.exception.QBResponseException
1818
import com.quickblox.users.QBUsers
1919
import com.quickblox.users.model.QBUser
2020

21-
const val APP_ID = ""
22-
const val AUTH_KEY = ""
23-
const val AUTH_SECRET = ""
24-
const val ACCOUNT_KEY = ""
21+
const val APP_ID = "75949"
22+
const val AUTH_KEY = "DdS7zxMEm5Q7DaS"
23+
const val AUTH_SECRET = "g88RhdOjnDOqFkv"
24+
const val ACCOUNT_KEY = "uK_8uinNyz8-npTNB6tx"
2525

26-
const val USER_LOGIN = ""
27-
const val USER_ID = 0
28-
const val USER_PASSWORD = ""
26+
const val USER_LOGIN = "qwe11"
27+
const val USER_ID = 109364779
28+
const val USER_PASSWORD = "quickblox"
2929

30-
const val OPPONENT_LOGIN = ""
31-
const val OPPONENT_ID = 0
32-
const val OPPONENT_PASSWORD = ""
30+
const val OPPONENT_LOGIN = "qwe22"
31+
const val OPPONENT_ID = 109364799
32+
const val OPPONENT_PASSWORD = "quickblox"
3333

34-
const val USER_OPPONENT_ID_1 = 0
35-
const val USER_OPPONENT_ID_2 = 0
34+
const val USER_OPPONENT_ID_1 = 109364799
35+
const val USER_OPPONENT_ID_2 = 131163237
3636

3737
open class BaseTest {
3838
private var loggedUser: QBUser? = null

ui-kit/src/main/java/com/quickblox/android_ui_kit/QuickBloxUiKit.kt

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package com.quickblox.android_ui_kit
66

77
import android.content.Context
88
import android.util.Log
9+
import com.quickblox.android_ai_editing_assistant.QBAIRephrase
910
import com.quickblox.android_ai_translate.Languages
1011
import com.quickblox.android_ai_translate.QBAITranslate
1112
import com.quickblox.android_ai_translate.exception.QBAITranslateException
@@ -26,6 +27,7 @@ object QuickBloxUiKit {
2627
private var theme: UiKitTheme = LightUIKitTheme()
2728
private var enabledAIAnswerAssistant = true
2829
private var enabledAITranslate = true
30+
private var enabledAIRephrase = true
2931
private var openAIToken: String = ""
3032
private var proxyServerURL: String = ""
3133

@@ -48,6 +50,7 @@ object QuickBloxUiKit {
4850
if (dependency == null) {
4951
dependency = DependencyImpl(context)
5052
}
53+
QBAIRephrase.init(context)
5154
AppLifecycleManager.init()
5255

5356
val defaultLanguage = getDefaultLanguage()
@@ -122,7 +125,7 @@ object QuickBloxUiKit {
122125
throw RuntimeException("The AI Answer assistant is disabled")
123126
}
124127

125-
if (openAIToken.isNotBlank() && proxyServerURL.isNotBlank()) {
128+
if (isExistAITokenAndProxyServer()) {
126129
throw RuntimeException("Error initialization. There are Open AI Token and Proxy Server Url. The AI Answer Assistant should be initialized by Open AI Token or QuickBlox Token")
127130
}
128131

@@ -135,7 +138,55 @@ object QuickBloxUiKit {
135138
throw RuntimeException("The AI Answer assistant is disabled")
136139
}
137140

138-
if (openAIToken.isNotBlank() && proxyServerURL.isNotBlank()) {
141+
if (isExistAITokenAndProxyServer()) {
142+
throw RuntimeException("Error initialization. There are Open AI Token and Proxy Server Url. The AI Answer Assistant should be initialized by Open AI Token or QuickBlox Token")
143+
}
144+
145+
return proxyServerURL.isNotBlank()
146+
}
147+
148+
fun enableAIRephraseWithOpenAIToken(openAIToken: String) {
149+
if (openAIToken.isBlank()) {
150+
throw RuntimeException("The openAIToken shouldn't be empty")
151+
}
152+
this.openAIToken = openAIToken
153+
this.proxyServerURL = ""
154+
enabledAIRephrase = true
155+
}
156+
157+
fun enableAIRephraseWithQuickBloxToken(proxyServerURL: String) {
158+
if (proxyServerURL.isBlank()) {
159+
throw RuntimeException("The proxyServerURL shouldn't be empty")
160+
}
161+
this.openAIToken = ""
162+
this.proxyServerURL = proxyServerURL
163+
enabledAIRephrase = true
164+
}
165+
166+
fun disableAIRephrase() {
167+
enabledAIRephrase = false
168+
}
169+
170+
fun isAIRephraseEnabledByOpenAIToken(): Boolean {
171+
val isNotEnabledAIRephrase = !isEnabledAIRephrase()
172+
if (isNotEnabledAIRephrase) {
173+
throw RuntimeException("The AI Answer assistant is disabled")
174+
}
175+
176+
if (isExistAITokenAndProxyServer()) {
177+
throw RuntimeException("Error initialization. There are Open AI Token and Proxy Server Url. The AI Rephrase should be initialized by Open AI Token or QuickBlox Token")
178+
}
179+
180+
return openAIToken.isNotBlank()
181+
}
182+
183+
fun isAIRephraseEnabledByQuickBloxToken(): Boolean {
184+
val isNotEnabledAIRephrase = !isEnabledAIRephrase()
185+
if (isNotEnabledAIRephrase) {
186+
throw RuntimeException("The AI Answer assistant is disabled")
187+
}
188+
189+
if (isExistAITokenAndProxyServer()) {
139190
throw RuntimeException("Error initialization. There are Open AI Token and Proxy Server Url. The AI Answer Assistant should be initialized by Open AI Token or QuickBlox Token")
140191
}
141192

@@ -170,7 +221,7 @@ object QuickBloxUiKit {
170221
throw RuntimeException("The AI Translate is disabled")
171222
}
172223

173-
if (openAIToken.isNotBlank() && proxyServerURL.isNotBlank()) {
224+
if (isExistAITokenAndProxyServer()) {
174225
throw RuntimeException("Error initialization. There are Open AI Token and Proxy Server Url. The AI Translate should be initialized by Open AI Token or QuickBlox Token")
175226
}
176227

@@ -183,13 +234,17 @@ object QuickBloxUiKit {
183234
throw RuntimeException("The AI Translate is disabled")
184235
}
185236

186-
if (openAIToken.isNotBlank() && proxyServerURL.isNotBlank()) {
237+
if (isExistAITokenAndProxyServer()) {
187238
throw RuntimeException("Error initialization. There are Open AI Token and Proxy Server Url. The AI Translate should be initialized by Open AI Token or QuickBlox Token")
188239
}
189240

190241
return proxyServerURL.isNotBlank()
191242
}
192243

244+
private fun isExistAITokenAndProxyServer(): Boolean {
245+
return openAIToken.isNotBlank() && proxyServerURL.isNotBlank()
246+
}
247+
193248
fun getProxyServerURL(): String {
194249
return proxyServerURL
195250
}
@@ -205,4 +260,8 @@ object QuickBloxUiKit {
205260
fun isEnabledAITranslate(): Boolean {
206261
return enabledAITranslate
207262
}
263+
264+
fun isEnabledAIRephrase(): Boolean {
265+
return enabledAIRephrase
266+
}
208267
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Created by Injoit on 11.8.2023.
3+
* Copyright © 2023 Quickblox. All rights reserved.
4+
*
5+
*/
6+
7+
package com.quickblox.android_ui_kit.data.dto.ai
8+
9+
class AIRephraseDTO {
10+
var toneName: String = ""
11+
var smileCode: String = ""
12+
var originalText = ""
13+
var rephrasedText = ""
14+
}

ui-kit/src/main/java/com/quickblox/android_ui_kit/data/repository/ai/AIRepositoryImpl.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
package com.quickblox.android_ui_kit.data.repository.ai
88

9+
import com.quickblox.android_ui_kit.data.repository.mapper.AIRephraseMapper
910
import com.quickblox.android_ui_kit.data.repository.mapper.AITranslateMapper
1011
import com.quickblox.android_ui_kit.data.source.ai.AIDataSource
1112
import com.quickblox.android_ui_kit.data.source.exception.AIDataSourceException
13+
import com.quickblox.android_ui_kit.domain.entity.AIRephraseToneEntity
1214
import com.quickblox.android_ui_kit.domain.entity.implementation.message.AITranslateIncomingChatMessageEntity
1315
import com.quickblox.android_ui_kit.domain.entity.message.IncomingChatMessageEntity
1416
import com.quickblox.android_ui_kit.domain.exception.repository.AIRepositoryException
@@ -39,4 +41,35 @@ class AIRepositoryImpl(private val aiDataSource: AIDataSource) : AIRepository {
3941
throw AIRepositoryException(exception.message ?: "Unexpected Exception")
4042
}
4143
}
44+
45+
override fun rephraseByOpenAIToken(toneEntity: AIRephraseToneEntity): AIRephraseToneEntity {
46+
try {
47+
val requestDTO = AIRephraseMapper.entityToDto(toneEntity)
48+
val resultDTO = aiDataSource.rephraseByOpenAIToken(requestDTO)
49+
val resultEntity = AIRephraseMapper.dtoToEntity(resultDTO)
50+
return resultEntity
51+
} catch (exception: AIDataSourceException) {
52+
throw AIRepositoryException(exception.message ?: "Unexpected Exception")
53+
}
54+
}
55+
56+
override fun rephraseByQuickBloxToken(toneEntity: AIRephraseToneEntity, token: String): AIRephraseToneEntity {
57+
try {
58+
val requestDTO = AIRephraseMapper.entityToDto(toneEntity)
59+
val resultDTO = aiDataSource.rephraseByQuickBloxToken(requestDTO, token)
60+
val resultEntity = AIRephraseMapper.dtoToEntity(resultDTO)
61+
return resultEntity
62+
} catch (exception: AIDataSourceException) {
63+
throw AIRepositoryException(exception.message ?: "Unexpected Exception")
64+
}
65+
}
66+
67+
override fun getAllRephraseTones(): List<AIRephraseToneEntity> {
68+
try {
69+
val results = aiDataSource.getAllRephraseTones()
70+
return AIRephraseMapper.dtosToEntities(results)
71+
} catch (exception: AIDataSourceException) {
72+
throw AIRepositoryException(exception.message ?: "Unexpected Exception")
73+
}
74+
}
4275
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Created by Injoit on 11.8.2023.
3+
* Copyright © 2023 Quickblox. All rights reserved.
4+
*
5+
*/
6+
7+
package com.quickblox.android_ui_kit.data.repository.mapper
8+
9+
import android.text.TextUtils
10+
import com.quickblox.android_ui_kit.ExcludeFromCoverage
11+
import com.quickblox.android_ui_kit.data.dto.ai.AIRephraseDTO
12+
import com.quickblox.android_ui_kit.domain.entity.AIRephraseToneEntity
13+
import com.quickblox.android_ui_kit.domain.entity.implementation.AIRephraseToneEntityImpl
14+
import com.quickblox.android_ui_kit.domain.exception.repository.MappingException
15+
16+
@ExcludeFromCoverage
17+
object AIRephraseMapper {
18+
fun dtosToEntities(dtos: List<AIRephraseDTO>): List<AIRephraseToneEntity> {
19+
val entities = mutableListOf<AIRephraseToneEntity>()
20+
21+
dtos.forEach { dto ->
22+
val entity = dtoToEntity(dto)
23+
entities.add(entity)
24+
}
25+
26+
return entities
27+
}
28+
29+
fun dtoToEntity(dto: AIRephraseDTO): AIRephraseToneEntity {
30+
val toneName = dto.toneName
31+
if (TextUtils.isEmpty(toneName)) {
32+
throw MappingException("toneName should not be blank")
33+
}
34+
35+
val smileCode = dto.smileCode
36+
val entity = AIRephraseToneEntityImpl(toneName, smileCode)
37+
entity.setRephrasedText(dto.rephrasedText)
38+
entity.setOriginalText(dto.originalText)
39+
40+
return entity
41+
}
42+
43+
fun entityToDto(rephraseEntity: AIRephraseToneEntity): AIRephraseDTO {
44+
val dto = AIRephraseDTO()
45+
dto.toneName = rephraseEntity.getName()
46+
dto.smileCode = rephraseEntity.getSmileCode()
47+
dto.rephrasedText = rephraseEntity.getRephrasedText()
48+
dto.originalText = rephraseEntity.getOriginalText()
49+
50+
return dto
51+
}
52+
}

ui-kit/src/main/java/com/quickblox/android_ui_kit/data/source/ai/AIDataSource.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package com.quickblox.android_ui_kit.data.source.ai
88

9+
import com.quickblox.android_ui_kit.data.dto.ai.AIRephraseDTO
910
import com.quickblox.android_ui_kit.data.dto.ai.AITranslateDTO
1011

1112
interface AIDataSource {
@@ -14,4 +15,8 @@ interface AIDataSource {
1415
translateDTO: AITranslateDTO,
1516
token: String,
1617
): AITranslateDTO
18+
19+
fun rephraseByOpenAIToken(rephraseDTO: AIRephraseDTO): AIRephraseDTO
20+
fun rephraseByQuickBloxToken(rephraseDTO: AIRephraseDTO, token: String): AIRephraseDTO
21+
fun getAllRephraseTones(): List<AIRephraseDTO>
1722
}

0 commit comments

Comments
 (0)