Skip to content

Commit

Permalink
Merge pull request #17 from Teknasyon-Teknoloji/feature/refactor
Browse files Browse the repository at this point in the history
[refactor]: refactor sdk init
  • Loading branch information
baranoguz authored Sep 15, 2021
2 parents 0b20908 + b2ac591 commit 20ca5ef
Show file tree
Hide file tree
Showing 79 changed files with 1,037 additions and 1,171 deletions.
42 changes: 19 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Or Maven
import com.teknasyon.desk360.helper.Desk360Config
import com.teknasyon.desk360.helper.Desk360SDKManager
import com.teknasyon.desk360.helper.Platform
import com.teknasyon.desk360.helper.Desk360SDK
```

```
Expand All @@ -131,14 +131,13 @@ import com.teknasyon.desk360.helper.Platform
)
.build()
val desk360Client = desk360SDKManager.initialize("ticket id", "firebase notification token", "device id")
desk360SDKManager.initialize("firebase notification token", "device id")
desk360Client.start(this)
Desk360SDK.start()
| Parameters | Description |
| ------------ | ------------------------------------------------------------ |
| token | your firebase token |
| ticketId | ticket id from firebase message body
| deviceId | your Android device id
| appKey | desk360 Api Key will provided when you get the license
| appVersion | your application's version number
Expand Down Expand Up @@ -201,7 +200,7 @@ val bundle = intent.extras
val hermes = bundle?.getString("hermes")
hermes?.let {
val targetId = Desk360Constants.getTicketId(hermes)
val targetId = Desk360SDK.getTicketId(hermes)
}
}
Expand All @@ -217,7 +216,7 @@ override fun onMessageReceived(remoteMessage: RemoteMessage) {
val hermes = remoteMessage.data["hermes"]
hermes?.let {
val targetId = Desk360Constants.getTicketId(hermes)
val targetId = Desk360SDK.getTicketId(hermes)
}
```
Expand All @@ -241,13 +240,12 @@ Example (In your firebaseMessagingService class) :
.setCustomJsonObject("for custom data")
.build()
val desk360Client = desk360SDKManager.initialize(
_ticketId = "targetId from notification body",
_notificationToken = "your firebase token",
_deviceId = "your Android device id"
desk360SDKManager.initialize(
notificationToken = "your firebase token",
deviceId = "your Android device id"
)
val intent = desk360Client.getIntent(this)
val intent = Desk360SDK.getIntent(this)
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)
} ?: run {
PendingIntent.getActivity(this, 0, Intent(this, YourStartingActivity::class.java), PendingIntent.FLAG_ONE_SHOT)
Expand All @@ -265,13 +263,12 @@ Example (In your firebaseMessagingService class) :
.setCustomJsonObject("for custom data")
.build()
val desk360Client = desk360SDKManager.initialize(
_ticketId = "targetId from notification body",
_notificationToken = "your firebase token",
_deviceId = "your Android device id"
)
desk360SDKManager.initialize(
notificationToken = "your firebase token",
deviceId = "your Android device id"
)
desk360Client.start(this)
Desk360SDK.start()
finish()
```
Expand All @@ -288,13 +285,12 @@ If your app will not use notification then you must set token "" and for targetI
.setCustomJsonObject("for custom data")
.build()
val desk360Client = desk360SDKManager.initialize(
_ticketId = "targetId from notification body",
_notificationToken = "your firebase token",
_deviceId = "your Android device id"
)
desk360SDKManager.initialize(
notificationToken = "your firebase token",
deviceId = "your Android device id"
)
desk360Client.start(this)
Desk360SDK.start()
finish()
```
### Language
Expand Down
2 changes: 1 addition & 1 deletion desk360/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'maven-publish'
def sdkArtifactId = 'desk360-android-sdk'
def sdkGroupId = 'com.github.Teknasyon-Teknoloji'
def sdkVersionName = "1.0.3"
def sdkVersionName = "1.0.4"

android {
compileSdkVersion 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.teknasyon.desk360.connection

import android.util.Log
import com.teknasyon.desk360.helper.Desk360Config
import com.teknasyon.desk360.helper.Desk360Constants
import com.teknasyon.desk360.helper.Desk360SDK
import com.teknasyon.desk360.helper.Platform
import com.teknasyon.desk360.helper.ResponseListener
import com.teknasyon.desk360.model.Desk360Register
Expand Down Expand Up @@ -37,13 +37,13 @@ abstract class BaseCallback<T> : Callback<T> {
"expired_at" -> {
cloneRequest = call.clone()
val register = Desk360Register()
register.app_key = Desk360Constants.manager?.appKey
register.app_key = Desk360SDK.manager?.appKey
register.device_id =
Desk360Config.instance.getDesk360Preferences()?.adId
register.app_platform =
if (Desk360Constants.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
register.app_version = Desk360Constants.manager?.appVersion
register.language_code = Desk360Constants.manager?.languageCode
if (Desk360SDK.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
register.app_version = Desk360SDK.manager?.appVersion
register.language_code = Desk360SDK.manager?.languageCode

Desk360RetrofitFactory.instance.desk360Service.register(register)
.enqueue(object : Callback<Desk360RegisterResponse> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.teknasyon.desk360.connection

import com.teknasyon.desk360.BuildConfig
import com.teknasyon.desk360.helper.Desk360Constants
import com.teknasyon.desk360.helper.Desk360SDK
import com.teknasyon.desk360.helper.Environment
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -37,13 +37,14 @@ class Desk360RetrofitFactory private constructor() {
retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.baseUrl(Desk360Constants.baseURL)
.baseUrl(baseURL)
.build()

desk360Service = retrofit!!.create(Desk360Service::class.java)
}

companion object {
private var baseURL = "https://teknasyon.desk360.com/"
private var INSTANCE: Desk360RetrofitFactory? = null
val instance: Desk360RetrofitFactory
get() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
package com.teknasyon.desk360.helper

import android.content.Context
import android.content.Intent
import com.teknasyon.desk360.view.activity.Desk360SplashActivity

/**
* customer-specific information is kept
*/
class Desk360Client {
var ticketId: String? = ""
var notificationToken: String? = ""
var deviceId: String? = ""

fun start(context: Context) {
context.startActivity(getIntent(context))
}

fun getIntent(context: Context): Intent {
return Intent(context, Desk360SplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

putExtra(Desk360SplashActivity.EXTRA_APP_ID, context.applicationInfo.processName)
putExtra(Desk360SplashActivity.EXTRA_TARGET_ID, ticketId)
putExtra(Desk360SplashActivity.EXTRA_TOKEN, notificationToken)
putExtra(Desk360SplashActivity.EXTRA_DEVICE_TOKEN, deviceId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ open class Desk360Config {
return desk360Preferences
}


companion object {
var INSTANCE: Desk360Config? = null
private var desk360Preferences: Desk360Preferences? = null
Expand Down
120 changes: 0 additions & 120 deletions desk360/src/main/java/com/teknasyon/desk360/helper/Desk360Constants.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@ import java.util.*

object Desk360Helper {

/**
* Generates request model for Desk360 SDK Config Information
* @return Desk360ConfigRequestModel
* @see Desk360ConfigRequestModel
*/
fun createDesk360ConfigRequestModel() = Desk360ConfigRequestModel().apply {
language_code = Desk360Constants.manager?.languageCode.toString()
language_code = Desk360SDK.manager?.languageCode.toString()
language_code_tag = getLanguageTag()
country_code = Desk360Constants.manager?.countryCode?.toUpperCase()
country_code = Desk360SDK.manager?.countryCode?.toUpperCase()
}

/**
* Generates request model for Desk360 SDK registration
* @return Desk360Register
* @see Desk360Register
*/
fun createDesk360RegisterRequestModel() = Desk360Register().apply {
app_key = Desk360Constants.manager?.appKey
app_key = Desk360SDK.manager?.appKey
device_id = Desk360Config.instance.getDesk360Preferences()?.adId
app_platform =
if (Desk360Constants.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
app_version = Desk360Constants.manager?.appVersion
language_code = Desk360Constants.manager?.languageCode
if (Desk360SDK.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
app_version = Desk360SDK.manager?.appVersion
language_code = Desk360SDK.manager?.languageCode
}

private fun getLanguageTag() =
if (Desk360Constants.manager?.languageCode.isNullOrEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
if (Desk360SDK.manager?.languageCode.isNullOrEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
Locale.getDefault().toLanguageTag().toLowerCase()
else
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import androidx.appcompat.view.ContextThemeWrapper
import com.teknasyon.desk360.R

class Desk360Loading(context: Context, attrs: AttributeSet) : ProgressBar(
if (Desk360Constants.currentType?.data?.first_screen?.button_style_id in listOf(1, 2, 3, 5)) {
if (Desk360SDK.config?.data?.first_screen?.button_style_id in listOf(1, 2, 3, 5)) {
ContextThemeWrapper(context, R.style.LightAccent)
} else {
ContextThemeWrapper(context, R.style.DarkAccent)
}, attrs
) {
init {

when (Desk360Constants.currentType?.data?.ticket_detail_screen?.button_style_id) {
when (Desk360SDK.config?.data?.ticket_detail_screen?.button_style_id) {
1, 2, 3, 5 -> {
this.setBackgroundResource(R.drawable.light_theme_button_bg)
}
Expand Down
Loading

0 comments on commit 20ca5ef

Please sign in to comment.