Skip to content

Commit

Permalink
Use analytics for dev builds and appwrite for prod
Browse files Browse the repository at this point in the history
Tested-by: Pranav Purwar <[email protected]>
Signed-off-by: PranavPurwar <[email protected]>
  • Loading branch information
PranavPurwar committed Jan 5, 2024
1 parent 55397db commit 77d8af8
Show file tree
Hide file tree
Showing 49 changed files with 308 additions and 92 deletions.
14 changes: 13 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("dev.rikka.tools.materialthemebuilder")
id("com.google.gms.google-services")
}

android {
Expand Down Expand Up @@ -102,6 +103,18 @@ android {
buildConfig = true
}

flavorDimensions += "environment"

productFlavors {
create("dev") {
dimension = "environment"
isDefault = true
}
create("prod") {
dimension = "environment"
}
}

splits {
abi {
isEnable = true
Expand Down Expand Up @@ -219,7 +232,6 @@ dependencies {

implementation(projects.buildTools)
implementation(projects.common)
implementation(projects.feature.appwrite)
implementation(projects.feature.completion.java)
implementation(projects.feature.completion.kotlin)
implementation(projects.feature.formatter.googleJavaFormat)
Expand Down
48 changes: 48 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"project_info": {
"project_number": "542725065106",
"project_id": "rewrite-41cf5",
"storage_bucket": "rewrite-41cf5.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:542725065106:android:39543c54d9a91b43d6594b",
"android_client_info": {
"package_name": "org.cosmicide"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBCiJcjNDBlSXJoECELMBQ7WtZwOYPYvP4"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:542725065106:android:174f153f22bc54d0d6594b",
"android_client_info": {
"package_name": "org.cosmicide.rewrite"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBCiJcjNDBlSXJoECELMBQ7WtZwOYPYvP4"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
42 changes: 28 additions & 14 deletions app/src/main/kotlin/org/cosmicide/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
import io.github.rosemoe.sora.langs.textmate.registry.model.ThemeModel
import io.github.rosemoe.sora.langs.textmate.registry.provider.AssetsFileResolver
import org.cosmicide.common.Analytics
import org.cosmicide.common.Prefs
import org.cosmicide.fragment.PluginsFragment
import org.cosmicide.rewrite.common.Analytics
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.rewrite.plugin.api.Hook
import org.cosmicide.rewrite.plugin.api.HookManager
import org.cosmicide.rewrite.plugin.api.PluginLoader
Expand All @@ -44,8 +44,11 @@ import java.io.FileNotFoundException
import java.io.InputStream
import java.lang.ref.WeakReference
import java.math.BigInteger
import java.net.URL
import java.security.MessageDigest
import java.time.ZonedDateTime
import java.util.Locale
import java.util.TimeZone
import java.util.logging.Logger

class App : Application() {
Expand All @@ -67,23 +70,24 @@ class App : Application() {
Log.d("Analytics", "Initializing")
Analytics.init(this@App)
Log.d("Analytics", "Sending event")

Analytics.logEvent(
"app_start",
"time" to ZonedDateTime.now().toString(),
"device" to Build.MODEL,
"sdk" to Build.VERSION.SDK_INT.toString(),
"version_code" to BuildConfig.VERSION_CODE.toString(),
"supported_abis" to Build.SUPPORTED_ABIS.joinToString(", "),
"brand" to Build.BRAND,
"device" to Build.DEVICE,
"user_metrics",
"name" to Prefs.clientName,
"ip" to getPublicIp(),
"theme" to Prefs.appTheme,
"language" to Locale.getDefault().language,
"timezone" to TimeZone.getDefault().id,
"sdk" to Build.VERSION.SDK_INT.toString() + " (" + Build.SUPPORTED_ABIS.joinToString(", ") + ")",
"device" to Build.DEVICE + " " + Build.DEVICE + " " + Build.PRODUCT,
"fingerprint" to Build.FINGERPRINT,
"hardware" to Build.HARDWARE,
"id" to Build.ID,
"model" to Build.MODEL,
"type" to Build.TYPE,
"user" to Build.USER,
"version" to BuildConfig.VERSION_NAME + if (BuildConfig.GIT_COMMIT.isNotEmpty()) " (${BuildConfig.GIT_COMMIT})" else "",
)
Analytics.logEvent(
"app_start",
"time" to ZonedDateTime.now().toString(),
)

Sui.init(packageName)
instance = WeakReference(this)
Expand Down Expand Up @@ -275,6 +279,16 @@ class App : Application() {
})
}


private fun getPublicIp(): String {
return try {
val ip = URL("https://api.ipify.org").readText()
ip
} catch (e: Exception) {
""
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/cosmicide/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import kotlinx.coroutines.launch
import org.cosmicide.databinding.ActivityMainBinding
import org.cosmicide.fragment.InstallResourcesFragment
import org.cosmicide.fragment.ProjectFragment
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs
import org.cosmicide.util.CommonUtils
import org.cosmicide.util.ResourceUtil
import rikka.shizuku.Shizuku
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/cosmicide/adapter/EditorAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.cosmicide.editor.language.KotlinLanguage
import org.cosmicide.editor.language.TsLanguageJava
import org.cosmicide.extension.setFont
import org.cosmicide.model.FileViewModel
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs
import org.cosmicide.util.ProjectHandler
import java.io.File
import kotlin.properties.Delegates
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/cosmicide/editor/IdeEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import io.github.rosemoe.sora.widget.component.EditorDiagnosticTooltipWindow
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
import org.cosmicide.extension.setCompletionLayout
import org.cosmicide.extension.setFont
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs

class IdeEditor @JvmOverloads constructor(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import android.view.View
import android.view.ViewGroup
import io.github.rosemoe.sora.widget.component.EditorCompletionAdapter
import org.cosmicide.databinding.CompletionResultBinding
import org.cosmicide.rewrite.editor.EditorCompletionItem
import org.cosmicide.editor.EditorCompletionItem

class CustomCompletionItemAdapter : EditorCompletionAdapter() {

Expand Down Expand Up @@ -48,4 +48,4 @@ class CustomCompletionItemAdapter : EditorCompletionAdapter() {
binding.resultItemIcon.setImageDrawable(item.icon)
return binding.root
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.appcompat.app.AppCompatDelegate
import io.github.rosemoe.sora.widget.component.DefaultCompletionLayout
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
import org.cosmicide.App
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs

class CustomCompletionLayout : DefaultCompletionLayout() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.cosmicide.editor.formatter

import com.google.googlejavaformat.java.Main
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs
import java.io.OutputStreamWriter
import java.io.PrintWriter
import kotlin.io.path.absolutePathString
Expand Down Expand Up @@ -44,4 +44,4 @@ object GoogleJavaFormat {

return formattedCode
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.cosmicide.editor.formatter

import com.facebook.ktfmt.cli.Main
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs
import kotlin.io.path.createTempFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.readText
Expand All @@ -25,4 +25,4 @@ object ktfmtFormatter {

return formattedCode
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import java.io.File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.cosmicide.completion.java.parser.CompletionProvider
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.rewrite.editor.EditorCompletionItem
import org.cosmicide.common.Prefs
import org.cosmicide.editor.EditorCompletionItem
import java.io.File
import java.net.URI
import java.util.logging.Level
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/cosmicide/extension/editor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import io.github.rosemoe.sora.widget.component.EditorAutoCompletion
import org.cosmicide.R
import org.cosmicide.editor.completion.CustomCompletionItemAdapter
import org.cosmicide.editor.completion.CustomCompletionLayout
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Prefs

/**
* Sets the font and enables highlighting of the current line for the code editor.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/cosmicide/fragment/ChatFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.cosmicide.adapter.ConversationAdapter
import org.cosmicide.chat.ChatProvider
import org.cosmicide.databinding.FragmentChatBinding
import org.cosmicide.extension.getDip
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment

class ChatFragment : BaseBindingFragment<FragmentChatBinding>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.cosmicide.build.BuildReporter
import org.cosmicide.compile.Compiler
import org.cosmicide.databinding.FragmentCompileInfoBinding
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.util.ProjectHandler

/**
Expand Down Expand Up @@ -95,4 +95,4 @@ class CompileInfoFragment : BaseBindingFragment<FragmentCompileInfoBinding>() {
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/org/cosmicide/fragment/EditorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import org.cosmicide.editor.language.KotlinLanguage
import org.cosmicide.model.FileViewModel
import org.cosmicide.project.Language
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.common.Prefs
import org.cosmicide.util.CommonUtils
import org.cosmicide.util.FileFactoryProvider
import org.cosmicide.util.FileIndex
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/org/cosmicide/fragment/GitFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import org.cosmicide.adapter.GitAdapter
import org.cosmicide.adapter.StagingAdapter
import org.cosmicide.databinding.FragmentGitBinding
import org.cosmicide.databinding.GitCommandBinding
import org.cosmicide.rewrite.common.Analytics
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Analytics
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.common.Prefs
import org.cosmicide.util.ProjectHandler
import java.io.OutputStream
import java.io.OutputStreamWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.cosmicide.R
import org.cosmicide.databinding.InstallResourcesFragmentBinding
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.rewrite.util.FileUtil
import org.cosmicide.util.Download
import org.cosmicide.util.ResourceUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.cosmicide.databinding.FragmentNewProjectBinding
import org.cosmicide.model.ProjectViewModel
import org.cosmicide.project.Language
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.rewrite.util.FileUtil
import java.io.File
import java.io.IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.cosmicide.adapter.AvailablePluginAdapter
import org.cosmicide.adapter.PluginAdapter
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.common.Prefs
import org.cosmicide.databinding.FragmentPluginListBinding
import org.cosmicide.databinding.PluginInfoBinding
import org.cosmicide.rewrite.common.Analytics
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.rewrite.plugin.api.Plugin
import org.cosmicide.rewrite.util.FileUtil
import org.cosmicide.util.CommonUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.google.gson.reflect.TypeToken
import org.cosmicide.adapter.PluginAdapter
import org.cosmicide.databinding.FragmentPluginsBinding
import org.cosmicide.databinding.PluginInfoBinding
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.rewrite.plugin.api.Plugin
import org.cosmicide.rewrite.plugin.api.PluginLoader
import org.cosmicide.rewrite.util.FileUtil
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/org/cosmicide/fragment/ProjectFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import org.cosmicide.adapter.ProjectAdapter
import org.cosmicide.databinding.FragmentProjectBinding
import org.cosmicide.model.ProjectViewModel
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.Analytics
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.rewrite.common.Prefs
import org.cosmicide.common.Analytics
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.common.Prefs
import org.cosmicide.rewrite.util.FileUtil
import org.cosmicide.rewrite.util.compressToZip
import org.cosmicide.rewrite.util.unzip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.cosmicide.R
import org.cosmicide.databinding.FragmentCompileInfoBinding
import org.cosmicide.editor.EditorInputStream
import org.cosmicide.project.Project
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment
import org.cosmicide.rewrite.util.MultipleDexClassLoader
import org.cosmicide.util.ProjectHandler
import java.io.OutputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.cosmicide.fragment.settings.FormatterSettings
import org.cosmicide.fragment.settings.GeminiSettings
import org.cosmicide.fragment.settings.GitSettings
import org.cosmicide.fragment.settings.PluginSettingsProvider
import org.cosmicide.rewrite.common.BaseBindingFragment
import org.cosmicide.common.BaseBindingFragment

/**
* Fragment for displaying settings screen.
Expand Down
Loading

0 comments on commit 77d8af8

Please sign in to comment.