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
50 changes: 50 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,30 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

// configure signing
signingConfigs {
release {
storeFile file('key.jks')
storePassword 'password'
keyAlias 'key'
keyPassword 'password'
}
}

signingConfigs {
myConfig {
keyAlias 'key0'
keyPassword 'chatgpt'
storeFile file('key')
storePassword 'chatgpt'
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.myConfig
}
}
compileOptions {
Expand All @@ -45,6 +65,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down Expand Up @@ -80,6 +101,12 @@ dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofit_ver"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_ver"

// okhttp
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'
// okhttp sse
implementation 'com.squareup.okhttp3:okhttp-sse:4.9.3'

// ViewPager2
implementation "androidx.viewpager2:viewpager2:1.0.0"

Expand All @@ -90,5 +117,8 @@ dependencies {
implementation 'androidx.activity:activity-ktx:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.5.5'

// eventbus
implementation 'org.greenrobot:eventbus:3.2.0'

}
tasks.register("prepareKotlinBuildScriptModel"){}
Binary file added app/key
Binary file not shown.
Binary file added app/release/app-release.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.nohjunh.test",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
18 changes: 13 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:name=".App"
Expand All @@ -14,13 +14,21 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Test"
tools:targetApi="31"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".view.settings.SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".view.MainActivity"
android:exported="true"
android:theme="@style/Theme.Test.Splash"
android:windowSoftInputMode="adjustResize"
android:exported="true">
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions app/src/main/java/com/nohjunh/test/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import timber.log.Timber

class App : Application() {

// Context -> Global
init {
instance = this
}

companion object {
private var instance : App? = null
fun context() : Context {
Expand All @@ -20,7 +20,9 @@ class App : Application() {
// Timber setting
override fun onCreate() {
super.onCreate()
Timber.plant(Timber.DebugTree())
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}

}
55 changes: 49 additions & 6 deletions app/src/main/java/com/nohjunh/test/adapter/ContentAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package com.nohjunh.test.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.nohjunh.test.R
import com.nohjunh.test.database.entity.ContentEntity
import timber.log.Timber

class ContentAdapter(val context : Context, private val dataSet : List<ContentEntity>) : RecyclerView.Adapter<ContentAdapter.ViewHolder>() {
class ContentAdapter : RecyclerView.Adapter<ContentAdapter.ViewHolder>() {

private val dataSet: MutableList<ContentEntity> = mutableListOf()

companion object {
private const val Gpt = 1
private const val User = 2
const val Gpt = 1
const val User = 2
private const val STEAM_PAYLOAD = "steam_payload"
}

interface DelChatLayoutClick {
fun onLongClick(view : View, position: Int)
fun onLongClick(view: View, position: Int)
}
var delChatLayoutClick : DelChatLayoutClick? = null

Expand Down Expand Up @@ -47,7 +49,16 @@ class ContentAdapter(val context : Context, private val dataSet : List<ContentEn
delChatLayoutClick?.onLongClick(view, position)
return@setOnLongClickListener true
}
}

override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList<Any>) {
if (payloads.isEmpty()) {
onBindViewHolder(holder, position)
} else {
if (payloads[0].toString() == STEAM_PAYLOAD) {
holder.contentTV.text = dataSet[position].content
}
}
}

override fun getItemCount(): Int {
Expand All @@ -62,4 +73,36 @@ class ContentAdapter(val context : Context, private val dataSet : List<ContentEn
}
}

private val steamBuilder = StringBuilder()

fun addChatGpt(data: String) {
Timber.d("addLast: $data")
steamBuilder.clear()
dataSet.add(ContentEntity(0, data, Gpt))
notifyItemInserted(dataSet.size - 1)
}

fun appendLast(data: String) {
steamBuilder.append(data)
val last = dataSet.size - 1
dataSet[last].content = steamBuilder.toString()
notifyItemChanged(last, STEAM_PAYLOAD)
}

fun addMsg(msg: ContentEntity) {
dataSet.add(msg)
notifyItemInserted(dataSet.size - 1)
}

fun submitList(it: List<ContentEntity>) {
dataSet.clear()
dataSet.addAll(it)
notifyDataSetChanged()
}

fun getLastContent(): String {
return steamBuilder.toString()
}


}
14 changes: 12 additions & 2 deletions app/src/main/java/com/nohjunh/test/database/ChatDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.nohjunh.test.database.dao.ContentDAO
import com.nohjunh.test.database.entity.ContentEntity

@Database(entities = [ContentEntity::class], version = 2)
@Database(entities = [ContentEntity::class], version = 3, exportSchema = false)
abstract class ChatDatabase : RoomDatabase() {

abstract fun contentDAO() : ContentDAO
Expand All @@ -25,11 +27,19 @@ abstract class ChatDatabase : RoomDatabase() {
ChatDatabase::class.java,
"chatDatabase"
)
.fallbackToDestructiveMigration()
// .fallbackToDestructiveMigration()
.addMigrations(MIGRATION_2_3)
.build()
INSTANCE = instance
instance
}
}

private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ContentTable ADD COLUMN type INTEGER NOT NULL DEFAULT 0")
database.execSQL("ALTER TABLE ContentTable ADD COLUMN time INTEGER NOT NULL DEFAULT 0")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@ data class ContentEntity(
@ColumnInfo(name = "gptOrUser")
var gptOrUser : Int

)
) {
@ColumnInfo(name = "type")
var type: Int = 0
@ColumnInfo(name = "time")
var time: Long = 0

companion object {
const val Gpt = 1
const val User = 2

const val TYPE_CONVERSATION = 0
const val TYPE_SYSTEM = 1
}
}
Loading