Skip to content

Commit

Permalink
OLDE mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AndraxDev committed Mar 13, 2024
1 parent f5fc489 commit 86ea78b
Show file tree
Hide file tree
Showing 55 changed files with 1,060 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

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

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "org.teslasoft.assistant"
minSdk 26
targetSdk 34
versionCode 304
versionName "3.4"
versionCode 305
versionName "3.5"
externalNativeBuild {
cmake {
cppFlags ''
Expand All @@ -34,8 +34,8 @@ android {

debug {
debuggable true
minifyEnabled true
shrinkResources true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
multiDexEnabled true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ class Preferences private constructor(private var preferences: SharedPreferences
putBoolean("function_calling", mode)
}

/**
* Set amoled pitch black mode
*
* @param mode amoled pitch black mode
* */
fun setAmoledPitchBlack(mode: Boolean) {
putGlobalBoolean("amoled_pitch_black", mode)
}

/**
* Get amoled pitch black mode
*
* @return amoled pitch black mode
* */
fun getAmoledPitchBlack() : Boolean {
return getGlobalBoolean("amoled_pitch_black", false)
}

/**
* Retrieves the imagine command status from the shared preferences.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.teslasoft.assistant.ui.activities
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.os.Handler
Expand All @@ -27,12 +28,18 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.res.ResourcesCompat

import androidx.fragment.app.FragmentActivity

import com.google.android.material.button.MaterialButton
import com.google.android.material.elevation.SurfaceColors

import org.teslasoft.assistant.R
import org.teslasoft.assistant.preferences.Preferences
import org.teslasoft.assistant.ui.fragments.tabs.ChatsListFragment
import org.teslasoft.assistant.ui.fragments.tabs.PromptsFragment

class AboutActivity : FragmentActivity() {

Expand All @@ -45,6 +52,10 @@ class AboutActivity : FragmentActivity() {
private var btnDonate: LinearLayout? = null
private var btnGithub: LinearLayout? = null

private var actions: ConstraintLayout? = null
private var system: ConstraintLayout? = null
private var links: LinearLayout? = null

private var activateEasterEggCounter: Int = 0

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -61,8 +72,14 @@ class AboutActivity : FragmentActivity() {
btnDonate = findViewById(R.id.btn_donate)
btnGithub = findViewById(R.id.btn_github)

actions = findViewById(R.id.common_actions)
system = findViewById(R.id.system_info)
links = findViewById(R.id.links)

appIcon?.setImageResource(R.drawable.assistant)

reloadAmoled()

appVer?.setOnClickListener {
if (activateEasterEggCounter == 0) {
Handler(Looper.getMainLooper()).postDelayed({
Expand Down Expand Up @@ -135,4 +152,43 @@ class AboutActivity : FragmentActivity() {
startActivity(i)
}
}

override fun onResume() {
super.onResume()
reloadAmoled()
}

private fun reloadAmoled() {
if (isDarkThemeEnabled() && Preferences.getPreferences(this, "").getAmoledPitchBlack()) {
window.navigationBarColor = ResourcesCompat.getColor(resources, R.color.amoled_window_background, theme)
window.statusBarColor = ResourcesCompat.getColor(resources, R.color.amoled_window_background, theme)
window.setBackgroundDrawableResource(R.color.amoled_window_background)

appIcon?.setBackgroundResource(R.drawable.btn_accent_50_amoled)

actions?.setBackgroundResource(R.drawable.btn_accent_24_amoled)
system?.setBackgroundResource(R.drawable.btn_accent_24_amoled)
links?.setBackgroundResource(R.drawable.btn_accent_24_amoled)
} else {
window.navigationBarColor = ResourcesCompat.getColor(resources, R.color.window_background, theme)
window.statusBarColor = ResourcesCompat.getColor(resources, R.color.window_background, theme)
window.setBackgroundDrawableResource(R.color.window_background)

appIcon?.setBackgroundResource(R.drawable.btn_accent_50)

actions?.setBackgroundResource(R.drawable.btn_accent_24)
system?.setBackgroundResource(R.drawable.btn_accent_24)
links?.setBackgroundResource(R.drawable.btn_accent_24)
}
}

private fun isDarkThemeEnabled(): Boolean {
return when (resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> true
Configuration.UI_MODE_NIGHT_NO -> false
Configuration.UI_MODE_NIGHT_UNDEFINED -> false
else -> false
}
}
}
159 changes: 144 additions & 15 deletions app/src/main/java/org/teslasoft/assistant/ui/activities/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.Configuration.KEYBOARD_QWERTY
import android.graphics.drawable.Drawable
import android.media.MediaPlayer
Expand Down Expand Up @@ -53,6 +54,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.FragmentActivity
import com.aallam.openai.api.audio.SpeechRequest
Expand Down Expand Up @@ -131,6 +133,7 @@ class ChatActivity : FragmentActivity() {
private var fileContents: ByteArray? = null
private var actionBar: ConstraintLayout? = null
private var btnBack: ImageButton? = null
private var keyboardFrame: ConstraintLayout? = null

// Init chat
private var messages: ArrayList<HashMap<String, Any>> = arrayListOf()
Expand Down Expand Up @@ -226,6 +229,121 @@ class ChatActivity : FragmentActivity() {
}
}

override fun onResume() {
super.onResume()
reloadAmoled()
}

private fun reloadAmoled() {
if (isDarkThemeEnabled() && Preferences.getPreferences(this, chatId).getAmoledPitchBlack()) {
window.setBackgroundDrawableResource(R.color.amoled_window_background)
window.statusBarColor = ResourcesCompat.getColor(resources, R.color.amoled_accent_50, theme)
window.navigationBarColor = ResourcesCompat.getColor(resources, R.color.amoled_accent_100, theme)
keyboardFrame?.setBackgroundColor(ResourcesCompat.getColor(resources, R.color.amoled_accent_100, theme))
actionBar?.setBackgroundColor(ResourcesCompat.getColor(resources, R.color.amoled_accent_50, theme))
activityTitle?.setBackgroundColor(ResourcesCompat.getColor(resources, R.color.amoled_accent_50, theme))
btnBack?.background = getAmoledAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v4_amoled
)!!, this
)

btnExport?.background = getAmoledAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v4_amoled
)!!, this
)

btnSettings?.background = getAmoledAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v4_amoled
)!!, this
)

messageInput?.background = getAmoledAccentDrawableV2(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_selector_v6_amoled
)!!, this
)

btnMicro?.background = getAmoledAccentDrawableV2(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v5_amoled
)!!, this
)

btnSend?.background = getAmoledAccentDrawableV2(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v5_amoled
)!!, this
)
} else {
window.setBackgroundDrawableResource(R.color.window_background)
window.statusBarColor = SurfaceColors.SURFACE_4.getColor(this)
window.navigationBarColor = SurfaceColors.SURFACE_5.getColor(this)
keyboardFrame?.setBackgroundColor(SurfaceColors.SURFACE_5.getColor(this))
actionBar?.setBackgroundColor(SurfaceColors.SURFACE_4.getColor(this))
activityTitle?.setBackgroundColor(SurfaceColors.SURFACE_4.getColor(this))
btnBack?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v4
)!!, this
)

btnExport?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v4
)!!, this
)

btnSettings?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v4
)!!, this
)

messageInput?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_selector_v6
)!!, this
)

btnMicro?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v5
)!!, this
)

btnSend?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.drawable.btn_accent_tonal_v5
)!!, this
)
}
}

private fun isDarkThemeEnabled(): Boolean {
return when (resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> true
Configuration.UI_MODE_NIGHT_NO -> false
Configuration.UI_MODE_NIGHT_UNDEFINED -> false
else -> false
}
}

// Init TTS
private var tts: TextToSpeech? = null
private val ttsListener: TextToSpeech.OnInitListener =
Expand Down Expand Up @@ -285,18 +403,16 @@ class ChatActivity : FragmentActivity() {
setContentView(R.layout.activity_chat)
languageIdentifier = LanguageIdentification.getClient()

reloadAmoled()

val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)

window.statusBarColor = SurfaceColors.SURFACE_4.getColor(this)
window.navigationBarColor = SurfaceColors.SURFACE_4.getColor(this)

val chatActivityTitle: TextView = findViewById(R.id.chat_activity_title)
val keyboardInput: LinearLayout = findViewById(R.id.keyboard_input)

chatActivityTitle.setBackgroundColor(SurfaceColors.SURFACE_4.getColor(this))
keyboardInput.setBackgroundColor(SurfaceColors.SURFACE_4.getColor(this))
keyboardInput.setBackgroundColor(SurfaceColors.SURFACE_5.getColor(this))

initChatId()

Expand Down Expand Up @@ -379,6 +495,7 @@ class ChatActivity : FragmentActivity() {
btnExport = findViewById(R.id.btn_export)
actionBar = findViewById(R.id.action_bar)
btnBack = findViewById(R.id.btn_back)
keyboardFrame = findViewById(R.id.keyboard_frame)

btnExport?.setImageResource(R.drawable.ic_upload)
btnBack?.setImageResource(R.drawable.ic_back)
Expand Down Expand Up @@ -413,13 +530,6 @@ class ChatActivity : FragmentActivity() {
)!!, this
)

actionBar?.background = getDarkAccentDrawable(
AppCompatResources.getDrawable(
this,
R.color.accent_100
)!!, this
)

btnBack?.setOnClickListener {
finish()
}
Expand All @@ -443,10 +553,28 @@ class ChatActivity : FragmentActivity() {
return drawable
}

private fun getAmoledAccentDrawable(drawable: Drawable, context: Context) : Drawable {
DrawableCompat.setTint(DrawableCompat.wrap(drawable), getAmoledSurfaceColor(context))
return drawable
}

private fun getAmoledAccentDrawableV2(drawable: Drawable, context: Context) : Drawable {
DrawableCompat.setTint(DrawableCompat.wrap(drawable), getAmoledSurfaceColorV2(context))
return drawable
}

private fun getSurfaceColor(context: Context) : Int {
return SurfaceColors.SURFACE_4.getColor(context)
}

private fun getAmoledSurfaceColor(context: Context) : Int {
return ResourcesCompat.getColor(context.resources, R.color.amoled_accent_50, null)
}

private fun getAmoledSurfaceColorV2(context: Context) : Int {
return ResourcesCompat.getColor(context.resources, R.color.amoled_accent_300, null)
}

private fun initLogic() {
btnMicro?.setOnClickListener {
if (Preferences.getPreferences(this, chatId).getAudioModel() == "google") {
Expand Down Expand Up @@ -517,10 +645,11 @@ class ChatActivity : FragmentActivity() {
}

btnSettings?.setOnClickListener {
val i = Intent(
this,
SettingsActivity::class.java
).setAction(Intent.ACTION_VIEW)
val i = if (Preferences.getPreferences(this, chatId).getExperimentalUI()) {
Intent(this, SettingsV2Activity::class.java).setAction(Intent.ACTION_VIEW)
} else {
Intent(this, SettingsActivity::class.java).setAction(Intent.ACTION_VIEW)
}

i.putExtra("chatId", chatId)

Expand Down
Loading

0 comments on commit 86ea78b

Please sign in to comment.