Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Make chat with AI feature an experiment and add add about, donate inf…
Browse files Browse the repository at this point in the history
…o in About section of settings

Signed-off-by: PranavPurwar <[email protected]>
  • Loading branch information
PranavPurwar committed Aug 27, 2023
1 parent ed2001d commit 6916fe2
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 291 deletions.
1 change: 1 addition & 0 deletions app/src/main/kotlin/org/cosmicide/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MainActivity : AppCompatActivity() {
if (themeInt == R.style.Theme_CosmicIde)
DynamicColors.applyToActivityIfAvailable(this)
enableEdgeToEdge()
isImmersive = true
return super.onCreateView(parent, name, context, attrs)
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/cosmicide/extension/context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.core.content.ContextCompat

fun Context.copyToClipboard(text: String) {
val clipboard = ContextCompat.getSystemService(this, ClipboardManager::class.java)!!
clipboard.setPrimaryClip(ClipData.newPlainText("", text))
clipboard.setPrimaryClip(ClipData.newPlainText("version", text))
}

fun Context.getDip(input: Float): Float {
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/kotlin/org/cosmicide/fragment/ChatFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {
setupUI(view.context)
setOnClickListeners()
setupRecyclerView()
binding.messageText.requestFocus()
}

private fun setupUI(context: Context) {
Expand All @@ -66,6 +67,12 @@ class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {
parentFragmentManager.popBackStack()
}
binding.toolbar.setOnMenuItemClickListener {

if (it.itemId == R.id.clear) {
conversationAdapter.clear()
binding.recyclerview.invalidate()
return@setOnMenuItemClickListener false
}
val modelName = when (it.itemId) {
R.id.model_bard -> {
model = Models.BARD
Expand Down Expand Up @@ -105,9 +112,6 @@ class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {
else -> return@setOnMenuItemClickListener false
}

if (it.itemId == R.id.clear) {
conversationAdapter.clear()
}
binding.toolbar.title = modelName
true
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/kotlin/org/cosmicide/fragment/EditorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import org.cosmicide.util.FileIndex
import org.cosmicide.util.ProjectHandler
import java.io.File


class EditorFragment : BaseBindingFragment<FragmentEditorBinding>() {
private lateinit var fileIndex: FileIndex
private val fileViewModel by activityViewModels<FileViewModel>()
Expand Down Expand Up @@ -235,6 +234,11 @@ class EditorFragment : BaseBindingFragment<FragmentEditorBinding>() {
editorAdapter.saveAll()
binding.drawer.open()
}

if (Prefs.experimentsEnabled) {
menu.findItem(R.id.action_chat).isVisible = true
}

setOnMenuItemClickListener {
getCurrentFragment()?.save()
when (it.itemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,123 @@

package org.cosmicide.fragment.settings

import android.annotation.SuppressLint
import android.content.ClipboardManager
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.util.Log
import android.widget.EditText
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentTransaction
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import de.Maxr1998.modernpreferences.PreferenceScreen
import de.Maxr1998.modernpreferences.helpers.expandText
import de.Maxr1998.modernpreferences.helpers.onClick
import de.Maxr1998.modernpreferences.helpers.pref
import de.Maxr1998.modernpreferences.helpers.singleChoice
import de.Maxr1998.modernpreferences.preferences.choice.SelectionItem
import de.Maxr1998.modernpreferences.preferences.choice.SingleChoiceDialogPreference
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.cosmicide.BuildConfig
import org.cosmicide.R
import org.cosmicide.extension.copyToClipboard
import org.cosmicide.fragment.InstallResourcesFragment
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.rewrite.util.FileUtil
import org.cosmicide.util.CommonUtils.isShizukuGranted
import org.cosmicide.util.ResourceUtil
import rikka.shizuku.Shizuku
import rikka.shizuku.ShizukuRemoteProcess

class AboutSettings(private val activity: FragmentActivity) : SettingsProvider {
@SuppressLint("PrivateResource")
override fun provideSettings(builder: PreferenceScreen.Builder) {
builder.apply {
singleChoice(
"donate",
listOf(SelectionItem("paypal", "PayPal"), SelectionItem("patreon", "Patreon"))
) {
title = "Donate"
summary = "Donate to the developer"

selectionChangeListener =
SingleChoiceDialogPreference.OnSelectionChangeListener { preference, selection ->
when (selection) {
"paypal" -> {
activity.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.paypal.com/paypalme/PranavPurwar")
)
)
}

"patreon" -> {
activity.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.patreon.com/cosmicide")
)
)
}
}
true
}
}
expandText("about") {
title = "About"
summary =
"Cosmic IDE is a free and open-source IDE for Android. It is licensed under the GNU General Public License v3.0."
}

pref("version") {
title = "App version"
summary =
BuildConfig.VERSION_NAME + if (BuildConfig.DEBUG) " (${BuildConfig.GIT_COMMIT})" else ""

var count = 0
onClick {
activity.copyToClipboard(summary.toString())
count++
if (count == 7) {
val editor = PreferenceManager.getDefaultSharedPreferences(activity).edit()
if (Prefs.experimentsEnabled) {
editor.putBoolean("experiments_enabled", false)
Toast.makeText(
activity,
"You are no longer a developer",
Toast.LENGTH_LONG
).show()
} else {
editor.putBoolean("experiments_enabled", true)
Toast.makeText(activity, "You are a developer", Toast.LENGTH_LONG)
.show()
}
editor.apply()
}
val handler = Handler(Looper.myLooper()!!)
handler.postDelayed({ count = 0 }, 1000)
// We don't wanna show the copy to clipboard dialog multiple times
if (count == 1) {
val clipboardManager =
ContextCompat.getSystemService(activity, ClipboardManager::class.java)!!
val clip = clipboardManager.primaryClip?.getItemAt(0)?.text
if (clip == summary) {
return@onClick true
}
activity.copyToClipboard(summary.toString())
}
true
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@

<item
android:id="@+id/action_chat"
android:title="@string/action_chat" />
android:title="@string/action_chat"
android:visible="false" />

<item
android:id="@+id/action_git"
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/org/cosmicide/rewrite/common/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ object Prefs {
val kotlinRealtimeErrors: Boolean
get() = prefs.getBoolean("kotlin_realtime_errors", false)

val experimentsEnabled: Boolean
get() = prefs.getBoolean("experiments_enabled", false)


val editorFont: String
get() = prefs.getString("editor_font", "") ?: ""
Expand Down
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ include(":kotlinc")
include(":util")
include(":jgit")
include(":feature:code-navigation")
include(":datadir")
include(":zip")
include(":datadir")
1 change: 0 additions & 1 deletion zip/.gitignore

This file was deleted.

61 changes: 0 additions & 61 deletions zip/build.gradle.kts

This file was deleted.

Empty file removed zip/consumer-rules.pro
Empty file.
21 changes: 0 additions & 21 deletions zip/proguard-rules.pro

This file was deleted.

31 changes: 0 additions & 31 deletions zip/src/androidTest/java/dev/pranav/zip/ExampleInstrumentedTest.kt

This file was deleted.

10 changes: 0 additions & 10 deletions zip/src/main/AndroidManifest.xml

This file was deleted.

37 changes: 0 additions & 37 deletions zip/src/main/cpp/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 6916fe2

Please sign in to comment.