Skip to content

Commit

Permalink
v4.3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekCometChat committed Jun 19, 2024
1 parent e64538d commit e1d6dff
Show file tree
Hide file tree
Showing 23 changed files with 610 additions and 366 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "com.cometchat.kotlinsampleapp"
minSdk = 21
targetSdk = 34
versionCode = 2
versionName = "4.3.6"
versionCode = 3
versionName = "4.3.11"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
29 changes: 29 additions & 0 deletions app/src/main/assets/SampleUsers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"users": [
{
"uid": "superhero1",
"name": "Iron Man",
"avatar": "https://assets.cometchat.io/sampleapp/users/ironman.png"
},
{
"uid": "superhero2",
"name": "Captain America",
"avatar": "https://assets.cometchat.io/sampleapp/users/captainamerica.png"
},
{
"uid": "superhero3",
"name": "Spiderman",
"avatar": "https://assets.cometchat.io/sampleapp/users/spiderman.png"
},
{
"uid": "superhero4",
"name": "Wolverine",
"avatar": "https://assets.cometchat.io/sampleapp/users/wolverine.png"
},
{
"uid": "superhero5",
"name": "Cyclops",
"avatar": "https://assets.cometchat.io/sampleapp/users/cyclops.png"
}
]
}
189 changes: 142 additions & 47 deletions app/src/main/java/com/cometchat/kotlinsampleapp/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,169 @@ import com.cometchat.chat.core.CometChat
import com.cometchat.chat.exceptions.CometChatException
import com.cometchat.chat.models.Group
import com.cometchat.chat.models.User
import com.cometchat.chatuikit.shared.resources.utils.Utils
import com.cometchat.kotlinsampleapp.constants.StringConstants
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.json.JSONObject
import java.io.IOException

object AppUtils {
private var group: Group? = null
private var user: User? = null
fun fetchDefaultObjects() {
CometChat.getGroup("supergroup", object : CometChat.CallbackListener<Group?>() {
override fun onSuccess(group_: Group?) {
group = group_
}

override fun onError(e: CometChatException?) {}
})
CometChat.getUser("superhero5", object : CometChat.CallbackListener<User?>() {
override fun onSuccess(user_: User?) {
user = user_
}
class AppUtils {
companion object {
private var group: Group? = null
private var user: User? = null
private var userList: MutableList<User> = ArrayList()
fun fetchDefaultObjects() {
CometChat.getGroup("supergroup", object : CometChat.CallbackListener<Group?>() {
override fun onSuccess(group_: Group?) {
group = group_
}

override fun onError(e: CometChatException?) {}
})
}
override fun onError(e: CometChatException?) {}
})
CometChat.getUser("superhero5", object : CometChat.CallbackListener<User?>() {
override fun onSuccess(user_: User?) {
user = user_
}

val defaultGroup: Group?
get() = group
override fun onError(e: CometChatException?) {}
})
}

val defaultUser: User?
get() = user
fun fetchSampleUsers(listener: CometChat.CallbackListener<List<User>>) {
if (userList.isEmpty()) {
val request: Request =
Request.Builder().url(StringConstants.SAMPLE_APP_USERS_URL)
.method("GET", null).build()
val client = OkHttpClient()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
Utils.runOnMainThread {
listener.onError(
CometChatException("11", e.message)
)
}
}

fun switchLightMode() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful && response.body != null) {
try {
userList = processSampleUserList(response.body!!.string())
} catch (e: IOException) {
Utils.runOnMainThread {
listener.onError(
CometChatException("10", e.message)
)
}
}
Utils.runOnMainThread {
listener.onSuccess(
userList
)
}
} else {
Utils.runOnMainThread {
listener.onError(
CometChatException(
"Unexpected code ",
response.code.toString()
)
)
}
}
}
})
} else {
Utils.runOnMainThread {
listener.onSuccess(
userList
)
}
}
}
fun processSampleUserList(jsonString: String?): MutableList<User> {
val users: MutableList<User> = java.util.ArrayList()
try {
val jsonObject = JSONObject(jsonString)
val jsonArray = jsonObject.getJSONArray(StringConstants.KEY_USER)
for (i in 0 until jsonArray.length()) {
val userJson = jsonArray.getJSONObject(i)
val user = User()
user.uid = userJson.getString(StringConstants.UID)
user.name = userJson.getString(StringConstants.NAME)
user.avatar = userJson.getString(StringConstants.AVATAR)
users.add(user)
}
} catch (ignore: java.lang.Exception) {
}
return users
}
fun loadJSONFromAsset(context: Context): String? {
var json: String? = null
try {
val `is` = context.assets.open("SampleUsers.json")
val size = `is`.available()
val buffer = ByteArray(size)
`is`.read(buffer)
`is`.close()
json = String(buffer, charset("UTF-8"))
} catch (ex: IOException) {
ex.printStackTrace()
return null
}
return json
}
val defaultUserList: List<User?>
get() = userList

fun switchDarkMode() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
val defaultGroup: Group?
get() = group

fun isNightMode(context: Context): Boolean {
val currentNightMode =
context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return currentNightMode == Configuration.UI_MODE_NIGHT_YES
}
val defaultUser: User?
get() = user

fun switchLightMode() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}

fun switchDarkMode() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}

fun isNightMode(context: Context): Boolean {
val currentNightMode =
context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return currentNightMode == Configuration.UI_MODE_NIGHT_YES
}

fun changeIconTintToWhite(context: Context?, imageView: ImageView) {
imageView.setImageTintList(
ColorStateList.valueOf(
fun changeIconTintToWhite(context: Context?, imageView: ImageView) {
imageView.imageTintList = ColorStateList.valueOf(
ContextCompat.getColor(
context!!,
R.color.white
)
)
)
}
}

fun changeIconTintToBlack(context: Context?, imageView: ImageView) {
imageView.setImageTintList(
ColorStateList.valueOf(
fun changeIconTintToBlack(context: Context?, imageView: ImageView) {
imageView.imageTintList = ColorStateList.valueOf(
ContextCompat.getColor(
context!!,
R.color.black
)
)
)
}
}

fun changeTextColorToWhite(context: Context?, textView: TextView) {
textView.setTextColor(ContextCompat.getColor(context!!, R.color.white))
}
fun changeTextColorToWhite(context: Context?, textView: TextView) {
textView.setTextColor(ContextCompat.getColor(context!!, R.color.white))
}

fun changeTextColorToBlack(context: Context?, textView: TextView) {
textView.setTextColor(ContextCompat.getColor(context!!, R.color.black))
fun changeTextColorToBlack(context: Context?, textView: TextView) {
textView.setTextColor(ContextCompat.getColor(context!!, R.color.black))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.cometchat.chat.core.CometChat
import com.cometchat.chatuikit.calls.CometChatCallActivity
import com.cometchat.chatuikit.shared.resources.theme.CometChatTheme
import com.cometchat.chatuikit.shared.resources.theme.Palette
import com.cometchat.kotlinsampleapp.AppUtils.isNightMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.isNightMode

class Application : Application() {

Expand All @@ -31,7 +31,7 @@ class Application : Application() {
private fun addCallListener() {
val LISTENER_ID = System.currentTimeMillis().toString() + ""
CometChat.addCallListener(LISTENER_ID, object : CometChat.CallListener() {
override fun onIncomingCallReceived(call: Call?) {
override fun onIncomingCallReceived(call: Call) {
CometChatCallActivity.launchIncomingCallScreen(applicationContext, call, null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.cometchat.chatuikit.shared.resources.utils.Utils
import com.cometchat.kotlinsampleapp.AppUtils.changeIconTintToBlack
import com.cometchat.kotlinsampleapp.AppUtils.changeIconTintToWhite
import com.cometchat.kotlinsampleapp.AppUtils.isNightMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeIconTintToBlack
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeIconTintToWhite
import com.cometchat.kotlinsampleapp.AppUtils.Companion.isNightMode
import com.cometchat.kotlinsampleapp.R
import com.cometchat.kotlinsampleapp.constants.StringConstants
import com.cometchat.kotlinsampleapp.databinding.ActivityComponentListBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import com.cometchat.chat.core.CometChat
import com.cometchat.chat.exceptions.CometChatException
import com.cometchat.chat.models.User
import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit
import com.cometchat.kotlinsampleapp.AppUtils.changeTextColorToBlack
import com.cometchat.kotlinsampleapp.AppUtils.changeTextColorToWhite
import com.cometchat.kotlinsampleapp.AppUtils.fetchDefaultObjects
import com.cometchat.kotlinsampleapp.AppUtils.isNightMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeTextColorToBlack
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeTextColorToWhite
import com.cometchat.kotlinsampleapp.AppUtils.Companion.fetchDefaultObjects
import com.cometchat.kotlinsampleapp.AppUtils.Companion.isNightMode
import com.cometchat.kotlinsampleapp.R
import com.cometchat.kotlinsampleapp.databinding.ActivityCreateUserBinding
import com.google.android.material.snackbar.Snackbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit
import com.cometchat.chatuikit.shared.resources.theme.CometChatTheme
import com.cometchat.chatuikit.shared.resources.theme.Palette
import com.cometchat.chatuikit.shared.resources.utils.Utils
import com.cometchat.kotlinsampleapp.AppUtils.changeIconTintToBlack
import com.cometchat.kotlinsampleapp.AppUtils.changeIconTintToWhite
import com.cometchat.kotlinsampleapp.AppUtils.isNightMode
import com.cometchat.kotlinsampleapp.AppUtils.switchDarkMode
import com.cometchat.kotlinsampleapp.AppUtils.switchLightMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeIconTintToBlack
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeIconTintToWhite
import com.cometchat.kotlinsampleapp.AppUtils.Companion.isNightMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.switchDarkMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.switchLightMode
import com.cometchat.kotlinsampleapp.R
import com.cometchat.kotlinsampleapp.constants.StringConstants
import com.cometchat.kotlinsampleapp.databinding.ActivityHomeBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import com.cometchat.chat.core.CometChat
import com.cometchat.chat.exceptions.CometChatException
import com.cometchat.chat.models.User
import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit
import com.cometchat.kotlinsampleapp.AppUtils.changeTextColorToBlack
import com.cometchat.kotlinsampleapp.AppUtils.changeTextColorToWhite
import com.cometchat.kotlinsampleapp.AppUtils.fetchDefaultObjects
import com.cometchat.kotlinsampleapp.AppUtils.isNightMode
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeTextColorToBlack
import com.cometchat.kotlinsampleapp.AppUtils.Companion.changeTextColorToWhite
import com.cometchat.kotlinsampleapp.AppUtils.Companion.fetchDefaultObjects
import com.cometchat.kotlinsampleapp.AppUtils.Companion.isNightMode
import com.cometchat.kotlinsampleapp.R
import com.cometchat.kotlinsampleapp.databinding.ActivityLoginBinding
import com.google.android.material.textfield.TextInputEditText
Expand Down
Loading

0 comments on commit e1d6dff

Please sign in to comment.