Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to kotlin: changed initializing; updated README #19

Merged
merged 8 commits into from
Jun 10, 2024
341 changes: 169 additions & 172 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions personalizatio-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'signing'
}

version='1.8.17'
version='2.0.0'

android {
compileSdkVersion 34
Expand Down Expand Up @@ -37,7 +37,7 @@ android {

sourceSets {
main {
java.srcDirs = ['src/main/java']
main.java.srcDirs = ['src/main/kotlin']
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ tasks.register('sourcesJar', Jar) {
}

tasks.register('javadoc', Javadoc) {
source = fileTree(dir: 'src/main/java', include: '**/*.kt')
source = fileTree(dir: 'src/main/kotlin', include: '**/*.kt')
classpath += files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
failOnError false
options.encoding = 'UTF-8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ open class SDK {
/**
* @param shopId Shop key
*/
public fun initialize(context: Context, shopId: String, apiUrl: String, tag: String, preferencesKey: String, stream: String) {
fun initialize(context: Context, shopId: String, apiUrl: String, tag: String, preferencesKey: String, stream: String) {
this.api = Api.getApi(apiUrl)

this.context = context
Expand Down Expand Up @@ -349,14 +349,6 @@ open class SDK {
onMessageListener = listener
}

fun initialize(context: Context?, shop_id: String?) {
throw IllegalStateException("You need make static initialize method!")
}

fun initialize(context: Context?, shop_id: String?, stream: String?) {
throw IllegalStateException("You need make static initialize method!")
}

/**
* Быстрый поиск
*
Expand Down Expand Up @@ -513,14 +505,14 @@ open class SDK {
* https://reference.api.rees46.com/?shell#price-drop
*
* @param id Идентификатор товара
* @param current_price Текущая цена
* @param currentPrice Текущая цена
* @param email Email, если есть
* @param phone Телефон, если есть
*/
fun subscribeForPriceDrop(id: String, current_price: Double, email: String?, phone: String?, listener: OnApiCallbackListener? = null) {
fun subscribeForPriceDrop(id: String, currentPrice: Double, email: String? = null, phone: String? = null, listener: OnApiCallbackListener? = null) {
val params = Params()
params.put(Params.Parameter.ITEM, id)
params.put(Params.Parameter.PRICE, current_price.toString())
params.put(Params.Parameter.PRICE, currentPrice.toString())
if (email != null) {
params.put(InternalParameter.EMAIL, email)
}
Expand All @@ -534,14 +526,14 @@ open class SDK {
* Отписывает на снижение цены
* https://reference.api.rees46.com/?shell#price-drop
*
* @param item_ids Идентификаторы товара
* @param itemIds Идентификаторы товара
* @param email Email, если есть
* @param phone Телефон, если есть
*/
fun unsubscribeForPriceDrop(item_ids: Array<String>, email: String?, phone: String?, listener: OnApiCallbackListener? = null) {
fun unsubscribeForPriceDrop(itemIds: Array<String>, email: String? = null, phone: String? = null, listener: OnApiCallbackListener? = null) {
val params = JSONObject()
try {
params.put("item_ids", java.lang.String.join(", ", *item_ids))
params.put("item_ids", java.lang.String.join(", ", *itemIds))
if (email != null) {
params.put(InternalParameter.EMAIL.value, email)
}
Expand All @@ -562,11 +554,7 @@ open class SDK {
* @param email Email, если есть
* @param phone Телефон, если есть
*/
fun subscribeForBackInStock(id: String, email: String?, phone: String?, listener: OnApiCallbackListener? = null) {
subscribeForBackInStock(id, null, email, phone, listener)
}

fun subscribeForBackInStock(id: String, properties: JSONObject?, email: String?, phone: String?, listener: OnApiCallbackListener?) {
fun subscribeForBackInStock(id: String, email: String? = null, phone: String? = null, properties: JSONObject? = null, listener: OnApiCallbackListener? = null) {
val params = Params()
params.put(Params.Parameter.ITEM, id)
if (properties != null) {
Expand All @@ -585,15 +573,15 @@ open class SDK {
* Отписывает на наличие товара
* https://reference.api.rees46.com/?shell#back-in-stock
*
* @param item_ids Идентификатор товара
* @param itemIds Идентификатор товара
* @param email Email, если есть
* @param phone Телефон, если есть
*/
@JvmOverloads
fun unsubscribeForBackInStock(item_ids: Array<String>, email: String?, phone: String?, listener: OnApiCallbackListener? = null) {
fun unsubscribeForBackInStock(itemIds: Array<String>, email: String? = null, phone: String? = null, listener: OnApiCallbackListener? = null) {
val params = JSONObject()
try {
params.put("item_ids", java.lang.String.join(", ", *item_ids))
params.put("item_ids", java.lang.String.join(", ", *itemIds))
if (email != null) {
params.put(InternalParameter.EMAIL.value, email)
}
Expand Down Expand Up @@ -836,10 +824,6 @@ open class SDK {
return instance!!
}

fun isInstanced() : Boolean {
return instance != null
}

fun userAgent(): String {
return "Personalizatio SDK " + BuildConfig.FLAVOR.uppercase(Locale.getDefault()) + ", v" + BuildConfig.VERSION_NAME
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ interface Api {
return ApiImpl(baseUrl)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ class ApiImpl(
companion object {
private var sourceTimeDuration = 172800 * 1000 // 2 days
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ sealed class ApiMethod(val type: String, val method: String) {
class POST(method: String): ApiMethod(type = "POST", method = method)

class GET(method: String): ApiMethod(type = "GET", method = method)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import org.json.JSONObject

abstract class OnApiCallbackListener {
open fun onSuccess(response: JSONObject?) {}
fun onSuccess(response: JSONArray) {}
open fun onSuccess(response: JSONArray) {}
open fun onError(code: Int, msg: String?) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ data class Source(private var type: String?, private var id: String?, var time:
return Source(type, id, time)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ internal class PausableProgressBar @JvmOverloads constructor(
companion object {
private const val DEFAULT_PROGRESS_DURATION = 2000
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ internal class StoriesProgressView : LinearLayout {
if (current < 0 || current >= progressBars.size) return
progressBars[current].resumeProgress()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@ class StoryDialog(storiesView: StoriesView, stories: List<Story>, startPosition:
return stories.size
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ class Personaclick private constructor() : SDK() {
protected const val PREFERENCES_KEY: String = "personaclick.sdk"
protected val API_URL: String = if (BuildConfig.DEBUG) "http://192.168.1.8:8080/" else "https://api.personaclick.com/"

fun getInstance() : SDK {
return SDK.getInstance()
}

/**
* Initialize api
* @param context application context
* @param shopId Shop key
*/
fun initialize(context: Context, shopId: String) {
if (!isInstanced()) {
getInstance().initialize(context, shopId, API_URL, TAG, PREFERENCES_KEY, "android")
}
getInstance().initialize(context, shopId, API_URL, TAG, PREFERENCES_KEY, "android")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ class REES46 private constructor() : SDK() {
protected const val PREFERENCES_KEY: String = "rees46.sdk"
protected val API_URL: String = if (BuildConfig.DEBUG) "http://dev.api.rees46.com:8000/" else "https://api.rees46.ru/"

fun getInstance() : SDK {
return SDK.getInstance()
}

/**
* Initialize api
* @param context application context
* @param shopId Shop key
*/
fun initialize(context: Context, shopId: String, apiHost: String?) {
if (!isInstanced()) {
val apiUrl = apiHost?.let { "https://$it/" } ?: API_URL
getInstance().initialize(context, shopId, apiUrl, TAG, PREFERENCES_KEY, "android")
}
fun initialize(context: Context, shopId: String, apiHost: String? = null) {
val apiUrl = apiHost?.let { "https://$it/" } ?: API_URL

val sdk = getInstance()
sdk.initialize(context, shopId, apiUrl, TAG, PREFERENCES_KEY, "android")

// Дефолтное отображение сообщения без кастомизации
getInstance().setOnMessageListener(object : OnMessageListener {
sdk.setOnMessageListener(object : OnMessageListener {
@SuppressLint("StaticFieldLeak")
override fun onMessage(data: Map<String, String>) {
object : AsyncTask<String?, Void?, Bitmap?>() {
Expand All @@ -59,16 +63,17 @@ class REES46 private constructor() : SDK() {
intent.putExtra(NOTIFICATION_TYPE, data["type"])
intent.putExtra(NOTIFICATION_ID, data["id"])

val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)
val pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)

val notificationBuilder = NotificationCompat.Builder(context, "notification_channel")
.setLargeIcon(result)
.setStyle(NotificationCompat.BigTextStyle().bigText(data["body"]))
.setContentTitle(data["title"])
.setContentText(data["body"])
.setSmallIcon(android.R.drawable.stat_notify_chat)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setLargeIcon(result)
.setStyle(NotificationCompat.BigTextStyle().bigText(data["body"]))
.setContentTitle(data["title"])
.setContentText(data["body"])
.setSmallIcon(android.R.drawable.stat_notify_chat)
.setAutoCancel(true)
.setContentIntent(pendingIntent)

val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0, notificationBuilder.build())
Expand Down
24 changes: 3 additions & 21 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ publishing {
}
repositories {
maven {
name = "sonatype"
name = "GitHubPackages"

def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
url = uri("https://maven.pkg.github.com/rees46/rees46-android-sdk")

credentials {
username ossrhUsername
Expand All @@ -112,24 +110,8 @@ publishing {
}
}

def sonatypeIds = [rees46: sonatype_rees46, personaclick: sonatype_personaclick]

afterEvaluate {
nexusPublishing {
repositories {
android.libraryVariants.all { variant ->
if (variant.buildType.name == "debug") return

"${variant.flavorName}Sonatype" {
stagingProfileId = sonatypeIds[variant.flavorName]
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
}


android.libraryVariants.all { variant ->
if(variant == 'release') {
Expand Down
Loading