Skip to content

Commit

Permalink
Adding :core:network:light-streamer for #56
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidGarousi committed Mar 17, 2023
1 parent f7d74f4 commit 954c740
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 56 deletions.
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

implementation "com.lightstreamer:ls-android-client:4.2.6"
implementation "com.lightstreamer:ls-log-adapter-java:1.0.2"

implementation "androidx.navigation:navigation-compose:2.5.3"


Expand All @@ -90,6 +87,7 @@ dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'


implementation project(":core:network:light-streamer")
// testImplementation "io.mockk:mockk:1.12.4"
// androidTestImplementation "io.mockk:mockk-android:1.12.4"
}
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ plugins {
}

subprojects {
apply from: "../buildscripts/ktlint.gradle"
apply from: "../buildscripts/detekt.gradle"
apply from: "../buildscripts/git-hooks.gradle"
apply from: "../buildscripts/versionsplugin.gradle"
apply from: "$rootDir/buildscripts/ktlint.gradle"
apply from: "$rootDir/buildscripts/detekt.gradle"
apply from: "$rootDir/buildscripts/git-hooks.gradle"
apply from: "$rootDir/buildscripts/versionsplugin.gradle"
}
1 change: 1 addition & 0 deletions core/network/light-streamer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
44 changes: 44 additions & 0 deletions core/network/light-streamer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'garousi.dev.light_streamer'
compileSdk 33

defaultConfig {
minSdk 23
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

api "com.lightstreamer:ls-android-client:4.2.6"
api "com.lightstreamer:ls-log-adapter-java:1.0.2"

}
Empty file.
21 changes: 21 additions & 0 deletions core/network/light-streamer/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions core/network/light-streamer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,58 +1,14 @@
@file:Suppress("LongParameterList", "TooManyFunctions")

package dev.garousi.stockwatcher.feature.watchlist.data
package garousi.dev.light_streamer.connection

import android.util.Log
import com.lightstreamer.client.ClientListener
import com.lightstreamer.client.LightstreamerClient
import com.lightstreamer.client.Subscription
import com.lightstreamer.client.SubscriptionListener
import javax.inject.Inject

interface LightStreamerConnection {
val lsClient: LightstreamerClient?
var subscriptionListener: SubscriptionListener?
var subscription: Subscription?
fun connect(serverAddress: String, adapterSet: String)
fun disconnect()
fun subscribe(
subscriptionMode: SubscriptionMode,
dataAdapter: String? = null,
requestedSnapshot: String? = null,
requestedMaxFrequency: String? = null,
itemNames: Array<String>,
fieldNames: Array<String>,
): Subscription?

fun subscribe(
subscriptionMode: SubscriptionMode,
dataAdapter: String? = null,
requestedSnapshot: String? = null,
requestedMaxFrequency: String? = null,
itemName: String,
fieldNames: Array<String>,
): Subscription?

fun unsubscribe()
fun subscribeToClient()
fun setSubscription(
subscriptionMode: SubscriptionMode,
itemNames: Array<String>,
fieldNames: Array<String>,
)

fun setSubscription(
subscriptionMode: SubscriptionMode,
itemName: String,
fieldNames: Array<String>,
)

fun setRequestedSnapshot(requestedSnapshot: String?)
fun setRequestedMaxFrequency(requestedMaxFrequency: String?)
}

class LightStreamerConnectionImpl @Inject constructor() : LightStreamerConnection {
import garousi.dev.light_streamer.listeners.EmptyClientListener
import garousi.dev.light_streamer.models.SubscriptionMode

class DefaultLightStreamerConnection : LightStreamerConnection {
override var lsClient: LightstreamerClient? = null
override var subscription: Subscription? = null
override var subscriptionListener: SubscriptionListener? = null
Expand Down Expand Up @@ -161,4 +117,4 @@ class LightStreamerConnectionImpl @Inject constructor() : LightStreamerConnectio
) {
subscription = Subscription(subscriptionMode.name, itemName, fieldNames)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package garousi.dev.light_streamer.connection

import com.lightstreamer.client.LightstreamerClient
import com.lightstreamer.client.Subscription
import com.lightstreamer.client.SubscriptionListener
import garousi.dev.light_streamer.models.SubscriptionMode

interface LightStreamerConnection {
val lsClient: LightstreamerClient?
var subscriptionListener: SubscriptionListener?
var subscription: Subscription?
fun connect(serverAddress: String, adapterSet: String)
fun disconnect()
fun subscribe(
subscriptionMode: SubscriptionMode,
dataAdapter: String? = null,
requestedSnapshot: String? = null,
requestedMaxFrequency: String? = null,
itemNames: Array<String>,
fieldNames: Array<String>,
): Subscription?

fun subscribe(
subscriptionMode: SubscriptionMode,
dataAdapter: String? = null,
requestedSnapshot: String? = null,
requestedMaxFrequency: String? = null,
itemName: String,
fieldNames: Array<String>,
): Subscription?

fun unsubscribe()
fun subscribeToClient()
fun setSubscription(
subscriptionMode: SubscriptionMode,
itemNames: Array<String>,
fieldNames: Array<String>,
)

fun setSubscription(
subscriptionMode: SubscriptionMode,
itemName: String,
fieldNames: Array<String>,
)

fun setRequestedSnapshot(requestedSnapshot: String?)
fun setRequestedMaxFrequency(requestedMaxFrequency: String?)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package garousi.dev.light_streamer.listeners

import com.lightstreamer.client.ClientListener
import com.lightstreamer.client.LightstreamerClient

object EmptyClientListener : ClientListener {
override fun onListenStart(client: LightstreamerClient) = Unit
override fun onListenEnd(client: LightstreamerClient) = Unit
override fun onServerError(errorCode: Int, errorMessage: String) = Unit
override fun onStatusChange(status: String) = Unit
override fun onPropertyChange(property: String) = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package garousi.dev.light_streamer.models

enum class SubscriptionMode {
Merge,
Command,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package garousi.dev.light_streamer.service

import com.lightstreamer.client.ItemUpdate
import kotlinx.coroutines.flow.StateFlow

interface LightStreamerService<T> {
val stream: StateFlow<T>
fun subscribe(vararg params: Any): LightStreamerService<T>
fun unsubscribe()
fun observeSubscriptionUpdates()
fun setFieldsToDto(itemUpdate: ItemUpdate)
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dependencyResolutionManagement {
}
rootProject.name = "Stock Watcher"
include ':app'
include ':core:network:light-streamer'

0 comments on commit 954c740

Please sign in to comment.