Skip to content

Commit

Permalink
feat: Small improvements & deprecate custom schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
aikrq committed Nov 3, 2024
1 parent 539bb4a commit ca9bf81
Show file tree
Hide file tree
Showing 26 changed files with 15 additions and 234 deletions.
27 changes: 0 additions & 27 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("dev.rikka.tools.materialthemebuilder")
id("com.google.gms.google-services")
}

Expand Down Expand Up @@ -147,32 +146,6 @@ fun getGitCommit(): String {
}
}

materialThemeBuilder {
themes {
for ((name, color) in listOf(
"Pyro" to "#EF7A35",
"indigo" to "#3F51B5",
"flamingo" to "#E91E63",
"mint" to "#009688",
"emerald" to "#4CAF50",
"azure" to "#2196F3",
)) {
create(name) {
primaryColor = color
lightThemeFormat = "Theme.CosmicIde.%s.Light"
lightThemeParent = "Theme.CosmicIde"
darkThemeFormat = "Theme.CosmicIde.%s.Dark"
darkThemeParent = "Theme.CosmicIde"

isDynamicColors = false
}
}
}

generatePaletteAttributes = true
packageName = "org.cosmicide"
}

configurations.all {
resolutionStrategy.force("com.squareup.okhttp3:okhttp:4.12.0")
resolutionStrategy.force("com.google.guava:guava:33.1.0-android")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CosmicIde.Flamingo.Light"
android:theme="@style/Theme.CosmicIde"
tools:targetApi="34">

<provider
Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/org/cosmicide/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ class App : Application() {

if (Prefs.isInitialized) {
applyThemeBasedOnConfiguration()
setTheme(CommonUtils.getAccent(Prefs.appTheme))
}
}

Expand Down
18 changes: 0 additions & 18 deletions app/src/main/kotlin/org/cosmicide/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,9 @@ import rikka.shizuku.ShizukuProvider

class MainActivity : AppCompatActivity() {

var themeInt = 0
private lateinit var binding: ActivityMainBinding
val shizukuPermissionCode = 1

override fun onCreateView(
parent: View?,
name: String,
context: Context,
attrs: AttributeSet
): View? {
val accent = Prefs.appAccent

themeInt = CommonUtils.getAccent(accent)
setTheme(themeInt)

if (themeInt == R.style.Theme_CosmicIde)
DynamicColors.applyToActivityIfAvailable(this)

return super.onCreateView(parent, name, context, attrs)
}

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class CompileInfoFragment : BaseBindingFragment<FragmentCompileInfoBinding>() {
parentFragmentManager.commit {
add(R.id.fragment_container, ProjectOutputFragment())
addToBackStack(null)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}
}
4 changes: 0 additions & 4 deletions app/src/main/kotlin/org/cosmicide/fragment/EditorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ class EditorFragment : BaseBindingFragment<FragmentEditorBinding>() {
parentFragmentManager.commit {
add(R.id.fragment_container, ChatFragment())
addToBackStack(null)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
true
}
Expand All @@ -395,7 +394,6 @@ class EditorFragment : BaseBindingFragment<FragmentEditorBinding>() {
parentFragmentManager.commit {
add(R.id.fragment_container, GitFragment())
addToBackStack(null)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
true
}
Expand Down Expand Up @@ -604,15 +602,13 @@ class EditorFragment : BaseBindingFragment<FragmentEditorBinding>() {
parentFragmentManager.commit {
add(R.id.fragment_container, CompileInfoFragment())
addToBackStack(null)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}

private fun navigateToSettingsFragment() {
parentFragmentManager.commit {
add(R.id.fragment_container, SettingsFragment())
addToBackStack(null)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/org/cosmicide/fragment/GitFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class GitFragment : BaseBindingFragment<FragmentGitBinding>() {
parentFragmentManager.popBackStack()
parentFragmentManager.commit {
replace(R.id.fragment_container, SettingsFragment()).addToBackStack(null)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}.setNegativeButton("No") { _, _ ->
parentFragmentManager.popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class InstallResourcesFragment : BaseBindingFragment<InstallResourcesFragmentBin
withContext(Dispatchers.Main) {
parentFragmentManager.commit {
replace(R.id.fragment_container, ProjectFragment())
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class NewProjectFragment : BaseBindingFragment<FragmentNewProjectBinding>() {
if (success) {
parentFragmentManager.commit {
remove(this@NewProjectFragment)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
}
}
}
Expand Down Expand Up @@ -104,7 +103,6 @@ class NewProjectFragment : BaseBindingFragment<FragmentNewProjectBinding>() {
parentFragmentManager.commit {
add(R.id.fragment_container, EditorFragment.newInstance(project))
addToBackStack(null)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/kotlin/org/cosmicide/fragment/ProjectFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class ProjectFragment : BaseBindingFragment<FragmentProjectBinding>(),
parentFragmentManager.commit {
replace(R.id.fragment_container, SettingsFragment())
addToBackStack(null)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
true
}
Expand Down Expand Up @@ -262,7 +261,6 @@ class ProjectFragment : BaseBindingFragment<FragmentProjectBinding>(),
setPositiveButton("Ok") { _, _ ->
parentFragmentManager.commit {
replace(R.id.fragment_container, SettingsFragment())
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}
show()
Expand Down Expand Up @@ -403,7 +401,6 @@ class ProjectFragment : BaseBindingFragment<FragmentProjectBinding>(),
parentFragmentManager.commit {
add(R.id.fragment_container, NewProjectFragment())
addToBackStack(null)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}

Expand All @@ -415,7 +412,6 @@ class ProjectFragment : BaseBindingFragment<FragmentProjectBinding>(),
}
})
addToBackStack(null)
setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ProjectOutputFragment : BaseBindingFragment<FragmentCompileInfoBinding>()
if (isRunning) {
parentFragmentManager.commit {
replace(R.id.fragment_container, ProjectOutputFragment())
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
}
}
text.insert(text.cursor.rightLine, text.cursor.rightColumn, "--- Stopped ---\n")
Expand All @@ -57,7 +56,6 @@ class ProjectOutputFragment : BaseBindingFragment<FragmentCompileInfoBinding>()
R.id.cancel -> {
parentFragmentManager.commit {
remove(this@ProjectOutputFragment)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
}
true
}
Expand All @@ -74,7 +72,6 @@ class ProjectOutputFragment : BaseBindingFragment<FragmentCompileInfoBinding>()
binding.toolbar.setNavigationOnClickListener {
parentFragmentManager.commit {
remove(this@ProjectOutputFragment)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ class AboutSettings(private val activity: FragmentActivity) : SettingsProvider {

activity.supportFragmentManager.commit {
replace(R.id.fragment_container, InstallResourcesFragment())
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ class AppearanceSettings(private val activity: MainActivity) : SettingsProvider
private val themeItems: List<SelectionItem>
get() = themeValues.zip(themeOptions).map { SelectionItem(it.first, it.second, null) }

private val accentItems = listOf(
SelectionItem("default", "default", null),
SelectionItem("pyro", "pyro", null),
SelectionItem("indigo", "indigo", null),
SelectionItem("flamingo", "flamingo", null),
SelectionItem("mint", "mint", null),
SelectionItem("emerald", "emerald", null),
)

override fun provideSettings(builder: PreferenceScreen.Builder) {
builder.apply {
icon = ResourcesCompat.getDrawable(
Expand Down Expand Up @@ -69,23 +60,6 @@ class AppearanceSettings(private val activity: MainActivity) : SettingsProvider
}
}
}

singleChoice(PreferenceKeys.APP_ACCENT, accentItems) {
initialSelection = accentItems.first().key
title = "Choose Accent Color"
defaultOnSelectionChange {
if (activity.themeInt != CommonUtils.getAccent(it)) {
val intent = Intent(
activity,
MainActivity::class.java
).apply {
action = Intent.ACTION_VIEW
}
activity.finishAffinity()
activity.startActivity(intent)
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class PluginSettingsProvider(private val activity: FragmentActivity) : SettingsP
activity.supportFragmentManager.commit {
add(R.id.fragment_container, PluginListFragment())
addToBackStack(null)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
true
}
Expand All @@ -52,7 +51,6 @@ class PluginSettingsProvider(private val activity: FragmentActivity) : SettingsP
activity.supportFragmentManager.commit {
add(R.id.fragment_container, PluginsFragment())
addToBackStack(null)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
}
true
}
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/kotlin/org/cosmicide/util/CommonUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ object CommonUtils {
.usePlugin(HtmlPlugin.create())
.build()

fun getAccent(accent: String): Int {
return when (accent) {
"default" -> R.style.Theme_CosmicIde
"pyro" -> R.style.Theme_CosmicIde_Pyro
"indigo" -> R.style.Theme_CosmicIde_Indigo
"flamingo" -> R.style.Theme_CosmicIde_Flamingo
"mint" -> R.style.Theme_CosmicIde_Mint
"emerald" -> R.style.Theme_CosmicIde_Emerald
else -> R.style.Theme_CosmicIde
}
}

fun Activity.isShizukuGranted(): Boolean {
if (Shizuku.pingBinder().not()) {
Log.d("Shizuku", "Shizuku not installed")
Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/org/cosmicide/util/PreferenceKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ object PreferenceKeys {

// Appearance
const val APP_THEME = "app_theme"
const val APP_ACCENT = "app_accent"

// Compiler
const val COMPILER_USE_FJFS = "use_fast_jar_file_system"
Expand Down
13 changes: 3 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
~ Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorSurfaceContainerLow"
android:orientation="vertical">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
android:background="?colorSurfaceContainerLow" />
49 changes: 0 additions & 49 deletions app/src/main/res/values-night/themes_custom.xml

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/main/res/values-v27/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
~ Cosmic IDE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see <https://www.gnu.org/licenses/>.
-->

<resources xmlns:tools="http://schemas.android.com/tools">

<style name="Theme.CosmicIde.BaseV27" parent="Theme.CosmicIde.Base">
<item name="android:enforceNavigationBarContrast" tools:targetApi="q">false</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/values-v31/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
<style name="Theme.CosmicIde" parent="Theme.CosmicIde.BaseV31" />

<style name="Theme.CosmicIde.Start" parent="Theme.SplashScreen">
<!-- Android framework -->
<item name="android:navigationBarColor">@color/logo_background</item>
<item name="android:statusBarColor">@color/logo_background</item>

<item name="windowSplashScreenBackground">@color/logo_background</item>
<item name="android:splashScreenTheme">@style/Theme.CosmicIde.Flamingo</item>
<item name="windowSplashScreenIconBackgroundColor">?attr/colorSurface</item>
<item name="postSplashScreenTheme">@style/Theme.CosmicIde.Pyro</item>
<item name="postSplashScreenTheme">@style/Theme.CosmicIde</item>
</style>
</resources>
Loading

0 comments on commit ca9bf81

Please sign in to comment.