Skip to content

Commit

Permalink
Finalizing
Browse files Browse the repository at this point in the history
  • Loading branch information
AndraxDev committed Mar 28, 2024
1 parent 565f5fd commit 4b6bf06
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .idea/deploymentTargetSelector.xml

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

9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,19 @@
</activity>

<activity
android:name=".ui.debug.DebugActivity"
android:name=".ui.activities.LogsActivity"
android:exported="false"
android:theme="@style/UI.Fade"
android:launchMode="singleTask">
</activity>

<activity
android:name=".ui.debug.DebugActivity"
android:exported="true"
android:theme="@style/UI.Fade"
android:launchMode="singleTask">
</activity>

<activity
android:name=".ui.permission.MicrophonePermissionActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class Preferences private constructor(private var preferences: SharedPreferences
* @return experimental UI mode
*/
fun getExperimentalUI() : Boolean {
return getGlobalBoolean("experimentalUI", false)
return getGlobalBoolean("experimentalUI", true)
}

/**
Expand Down Expand Up @@ -367,6 +367,20 @@ class Preferences private constructor(private var preferences: SharedPreferences
putGlobalString("custom_host", host)
}

/**
* Get debug mode
* */
fun getDebugMode() : Boolean {
return getGlobalBoolean("debug_mode", false)
}

/**
* Set debug mode
* */
fun setDebugMode(state: Boolean) {
putGlobalBoolean("debug_mode", state)
}

/**
* Retrieves system message. System messages allow you to make ChatGPT more reliable.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**************************************************************************
* Copyright (c) 2023-2024 Dmytro Ostapenko. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**************************************************************************/

package org.teslasoft.assistant.ui.activities

import android.content.Intent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**************************************************************************
* Copyright (c) 2023-2024 Dmytro Ostapenko. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**************************************************************************/

package org.teslasoft.assistant.ui.activities

import android.content.res.Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**************************************************************************
* Copyright (c) 2023-2024 Dmytro Ostapenko. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**************************************************************************/

package org.teslasoft.assistant.ui.activities

import android.content.res.Configuration
import android.os.Bundle
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.FragmentActivity
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.teslasoft.assistant.R
import org.teslasoft.assistant.preferences.Logger
import org.teslasoft.assistant.preferences.Preferences

class LogsActivity : FragmentActivity() {

private var btnClearLog: MaterialButton? = null

private var btnBack: MaterialButton? = null

private var activityLogsTitle: TextView? = null

private var textLog: TextView? = null

private var logType = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_logs)

btnClearLog = findViewById(R.id.btn_clear_log)
btnBack = findViewById(R.id.btn_back)
activityLogsTitle = findViewById(R.id.activity_logs_title)
textLog = findViewById(R.id.text_log)

try {
logType = intent.extras?.getString("type").toString()

when (logType) {
"crash" -> {
activityLogsTitle?.text = "Crash log"
textLog?.text = Logger.getCrashLog(this)
}

"ads" -> {
activityLogsTitle?.text = "Ads log"
textLog?.text = Logger.getAdsLog(this)
}

"event" -> {
activityLogsTitle?.text = "Event log"
textLog?.text = Logger.getEventLog(this)
}

else -> finish()
}
} catch (e: Exception) {
finish()
}

btnClearLog?.setOnClickListener {
MaterialAlertDialogBuilder(this)
.setTitle("Clear log")
.setMessage("Are you sure you want to clear this log?")
.setPositiveButton("Yes") { _, _ ->
when (logType) {
"crash" -> {
Logger.clearCrashLog(this)
textLog?.text = Logger.getCrashLog(this)
}

"ads" -> {
Logger.clearAdsLog(this)
textLog?.text = Logger.getAdsLog(this)
}

"event" -> {
Logger.clearEventLog(this)
textLog?.text = Logger.getEventLog(this)
}
}
}
.setNegativeButton("No") { _, _ -> }
.show()
}

btnBack?.setOnClickListener {
finish()
}

reloadAmoled()
}

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)
} 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)
}
}

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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,40 @@ import android.animation.AnimatorListenerAdapter
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.Configuration
import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import android.widget.ImageButton
import android.window.OnBackInvokedDispatcher
import androidx.activity.OnBackPressedCallback

import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager

import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.elevation.SurfaceColors
import com.google.android.material.navigation.NavigationBarView

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


class MainActivity : FragmentActivity() {
private var navigationBar: BottomNavigationView? = null
private var fragmentChats: ConstraintLayout? = null
private var fragmentPrompts: ConstraintLayout? = null
private var fragmentTips: ConstraintLayout? = null
private var btnDebugger: MaterialButton? = null
private var debuggerWindow: ConstraintLayout? = null
private var btnCloseDebugger: ImageButton? = null
private var btnInitiateCrash: MaterialButton? = null

private var selectedTab: Int = 1
private var isAnimating = false
Expand Down Expand Up @@ -78,13 +83,18 @@ class MainActivity : FragmentActivity() {
fragmentPrompts = findViewById(R.id.fragment_prompts)
fragmentTips = findViewById(R.id.fragment_tips)
root = findViewById(R.id.root)
btnDebugger = findViewById(R.id.btn_open_debugger)
debuggerWindow = findViewById(R.id.debugger_window)
btnCloseDebugger = findViewById(R.id.btn_close_debugger)
btnInitiateCrash = findViewById(R.id.btn_initiate_crash)

btnDebugger?.visibility = View.GONE
debuggerWindow?.visibility = View.GONE

frameChats = supportFragmentManager.findFragmentById(R.id.fragment_chats_)
framePrompts = supportFragmentManager.findFragmentById(R.id.fragment_prompts_)
frameTips = supportFragmentManager.findFragmentById(R.id.fragment_tips_)



Thread {
DeviceInfoProvider.assignInstallationId(this)

Expand Down Expand Up @@ -144,6 +154,28 @@ class MainActivity : FragmentActivity() {
if (savedInstanceState != null) {
onRestoredState(savedInstanceState)
}

val preferences = Preferences.getPreferences(this, "")

if (preferences.getDebugTestAds() && !preferences.getDebugMode()) {
preferences.setDebugMode(true)
recreate()
}

if (preferences.getDebugMode()) {
btnDebugger?.visibility = View.VISIBLE
btnDebugger?.setOnClickListener {
debuggerWindow?.visibility = View.VISIBLE
}

btnCloseDebugger?.setOnClickListener {
debuggerWindow?.visibility = View.GONE
}

btnInitiateCrash?.setOnClickListener {
throw RuntimeException("Test crash")
}
}
}
}.start()
}
Expand All @@ -160,12 +192,26 @@ class MainActivity : FragmentActivity() {
window.setBackgroundDrawableResource(R.color.amoled_window_background)
root?.setBackgroundColor(ResourcesCompat.getColor(resources, R.color.amoled_window_background, theme))
navigationBar!!.setBackgroundColor(SurfaceColors.SURFACE_0.getColor(this))

val drawable = GradientDrawable()
drawable.shape = GradientDrawable.RECTANGLE
drawable.setColor(ResourcesCompat.getColor(resources, R.color.amoled_window_background, theme))
drawable.alpha = 220

debuggerWindow?.background = drawable
} else {
window.navigationBarColor = SurfaceColors.SURFACE_3.getColor(this)
window.statusBarColor = SurfaceColors.SURFACE_0.getColor(this)
window.setBackgroundDrawableResource(R.color.window_background)
root?.setBackgroundColor(SurfaceColors.SURFACE_0.getColor(this))
navigationBar!!.setBackgroundColor(SurfaceColors.SURFACE_3.getColor(this))

val drawable = GradientDrawable()
drawable.shape = GradientDrawable.RECTANGLE
drawable.setColor(SurfaceColors.SURFACE_0.getColor(this))
drawable.alpha = 220

debuggerWindow?.background = drawable
}

(frameChats as ChatsListFragment).reloadAmoled()
Expand Down
Loading

0 comments on commit 4b6bf06

Please sign in to comment.