Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions alodb-android-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("com.android.application") version "8.2.2" apply false
id("com.android.library") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.22" apply false
id("com.google.devtools.ksp") version "1.9.22-1.0.17" apply false
}
4 changes: 4 additions & 0 deletions alodb-android-sdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
41 changes: 41 additions & 0 deletions alodb-android-sdk/sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.serialization")
id("com.google.devtools.ksp") version "1.9.22-1.0.17"
}

android {
namespace = "com.alodb.sample"
compileSdk = 34

defaultConfig {
applicationId = "com.alodb.sample"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation(project(":sdk"))
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
ksp("androidx.room:room-compiler:2.6.1")
}
20 changes: 20 additions & 0 deletions alodb-android-sdk/sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".SampleApp"
android:allowBackup="false"
android:label="AloDB Sample"
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.alodb.sample

import androidx.room.Database
import androidx.room.RoomDatabase

@Database(
entities = [TransactionEntity::class, CampaignEntity::class],
version = 1,
exportSchema = false,
)
abstract class AppDatabase : RoomDatabase()
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.alodb.sample

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView

class ChatAdapter(
private val messages: MutableList<ChatMessage>,
) : RecyclerView.Adapter<ChatAdapter.ViewHolder>() {

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val cardBubble: MaterialCardView = view.findViewById(R.id.cardBubble)
val tvMessage: TextView = view.findViewById(R.id.tvMessage)
val tvQueryTitle: TextView = view.findViewById(R.id.tvQueryTitle)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_chat_message, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val msg = messages[position]
val lp = holder.cardBubble.layoutParams as FrameLayout.LayoutParams
val isUser = msg.type == ChatMessage.Type.USER

val ctx = holder.itemView.context
if (isUser) {
lp.gravity = Gravity.END
holder.cardBubble.setCardBackgroundColor(ContextCompat.getColor(ctx, R.color.bubble_user))
holder.tvMessage.setTextColor(ContextCompat.getColor(ctx, R.color.text_user))
} else {
lp.gravity = Gravity.START
holder.cardBubble.setCardBackgroundColor(ContextCompat.getColor(ctx, R.color.bubble_bot))
holder.tvMessage.setTextColor(ContextCompat.getColor(ctx, R.color.text_bot))
}
holder.cardBubble.layoutParams = lp

when (msg.type) {
ChatMessage.Type.BOT_QUERY_RESULT -> {
holder.tvQueryTitle.visibility = View.VISIBLE
holder.tvQueryTitle.text = msg.queryTitle ?: "Sorgu Sonucu"
holder.tvQueryTitle.setTextColor(ContextCompat.getColor(ctx, R.color.text_query_title))
holder.tvMessage.text = formatQueryResults(msg.queryResults)
holder.tvMessage.textSize = 13f
}

ChatMessage.Type.BOT_THINKING -> {
holder.tvQueryTitle.visibility = View.GONE
holder.tvMessage.text = msg.text
holder.tvMessage.textSize = 15f
}

ChatMessage.Type.BOT_ERROR -> {
holder.tvQueryTitle.visibility = View.GONE
holder.tvMessage.text = msg.text
holder.tvMessage.setTextColor(ContextCompat.getColor(ctx, R.color.text_error))
holder.tvMessage.textSize = 14f
}

else -> {
holder.tvQueryTitle.visibility = View.GONE
holder.tvMessage.text = msg.text
holder.tvMessage.textSize = 15f
}
}
}

override fun getItemCount(): Int = messages.size

private fun formatQueryResults(rows: List<Map<String, Any?>>?): String {
if (rows.isNullOrEmpty()) return "Sonuç bulunamadı."

val sb = StringBuilder()
val columns = rows.first().keys.toList()

for ((i, row) in rows.withIndex()) {
if (i > 0) sb.append("\n─────────────\n")
for (col in columns) {
val value = row[col]?.toString() ?: "—"
sb.append("$col: $value\n")
}
}
return sb.toString().trimEnd()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.alodb.sample

data class ChatMessage(
val type: Type,
val text: String,
val queryResults: List<Map<String, Any?>>? = null,
val queryTitle: String? = null,
) {
enum class Type {
USER,
BOT_TEXT,
BOT_THINKING,
BOT_QUERY_RESULT,
BOT_ERROR,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.alodb.sample

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "transactions")
data class TransactionEntity(
@PrimaryKey val id: Long,
val amount: Double,
val merchant: String,
val category: String,
@ColumnInfo(name = "created_at") val createdAt: String,
)

@Entity(tableName = "campaigns")
data class CampaignEntity(
@PrimaryKey val id: Long,
val title: String,
val category: String,
val discount: Int,
@ColumnInfo(name = "expires_at") val expiresAt: String,
)
Loading