This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
implement settings screen #13
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c4ee2fa
feat(settings): Introduce settings feature
aikrq 9acaf3e
build(deps): bump org.jetbrains.kotlin.android from 1.8.0 to 1.8.20
dependabot[bot] b10e99f
build(deps): bump org.jetbrains.kotlin:kotlin-reflect
dependabot[bot] cd6fd86
build(deps): bump com.squareup:kotlinpoet from 1.12.0 to 1.13.0
dependabot[bot] 48b1810
build(deps): bump org.jetbrains.kotlinx:kotlinx-coroutines-android
dependabot[bot] bf83cdb
build(deps): bump org.jetbrains.kotlin:kotlin-scripting-compiler
dependabot[bot] b035ce6
style: use inter font as default font
aikrq 94da83c
feat(prefs): implement prefs class
aikrq 93dc8fd
Merge branch 'main' into main
aikrq f607401
fix: handle all exceptions when retrieving value from preferences
aikrq 0dd47cb
fix(codacy): fixes `UndocumentedPublicClass` issue
aikrq a3bc3ba
refactor: move prefs class to common
aikrq 35363ef
feat: Update use of FastJarFs and compiler version based on user pref…
aikrq 37cfd6b
fix(settings): Set BuildConfig's version name variable to the version…
aikrq aef74dc
Merge branch 'main' into main
PranavPurwar 72f8924
Merge branch 'main' into main
PranavPurwar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/org/cosmicide/rewrite/fragment/PreferencesFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.cosmicide.rewrite.fragment | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.animation.AnimationUtils | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.cosmicide.rewrite.R | ||
import org.cosmicide.rewrite.BuildConfig | ||
|
||
/** | ||
* A [PreferenceFragmentCompat] subclass to display the preferences UI. | ||
*/ | ||
class PreferencesFragment : PreferenceFragmentCompat() { | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
setPreferencesFromResource(R.xml.settings, rootKey) | ||
|
||
findPreference<Preference>("version")?.run { | ||
summary = BuildConfig.VERSION_NAME | ||
} | ||
} | ||
|
||
override fun onCreateRecyclerView(inflater: LayoutInflater, parent: ViewGroup, savedInstanceState: Bundle?): RecyclerView { | ||
val recyclerView = super.onCreateRecyclerView(inflater, parent, savedInstanceState) | ||
recyclerView.layoutAnimation = AnimationUtils.loadLayoutAnimation(requireContext(), R.anim.preference_layout_fall_down) | ||
return recyclerView | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/src/main/java/org/cosmicide/rewrite/fragment/SettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.cosmicide.rewrite.fragment | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import org.cosmicide.rewrite.common.BaseBindingFragment | ||
import org.cosmicide.rewrite.databinding.FragmentSettingsBinding | ||
|
||
/** | ||
* Fragment for displaying settings screen. | ||
*/ | ||
class SettingsFragment : BaseBindingFragment<FragmentSettingsBinding>() { | ||
|
||
override fun getViewBinding() = FragmentSettingsBinding.inflate(layoutInflater) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:duration="300"> | ||
|
||
<translate | ||
android:fromYDelta="15%" | ||
android:interpolator="@android:interpolator/linear_out_slow_in" | ||
android:toYDelta="0" /> | ||
|
||
<alpha | ||
android:fromAlpha="0" | ||
android:interpolator="@android:interpolator/linear_out_slow_in" | ||
android:toAlpha="1" /> | ||
|
||
</set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:animation="@anim/preference_item_fall_down" | ||
android:animationOrder="normal" | ||
android:delay="5%" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:transitionGroup="true" | ||
tools:context=".fragment.SettingsFragment"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<com.google.android.material.appbar.MaterialToolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
app:navigationIcon="@drawable/baseline_arrow_back_ios_24" | ||
app:title="Settings" /> | ||
|
||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/settings_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:name="org.cosmicide.rewrite.fragment.PreferencesFragment" | ||
android:transitionGroup="true" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<bool name="config_materialPreferenceIconSpaceReserved">false</bool> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string-array name="java_version_entries"> | ||
<item>8</item> | ||
<item>11</item> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about other version? For ex if you just want to use text blocks and want compatibility with Java 16, you can just use it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, i will add every java version from 8 to 17. |
||
<item>17</item> | ||
</string-array> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<PreferenceCategory | ||
android:title="Editor"> | ||
|
||
<SeekBarPreference | ||
android:key="font_size" | ||
android:title="Font Size" | ||
android:summary="Set the font size for the editor" | ||
android:defaultValue="14" | ||
android:min="12" | ||
android:max="22" /> | ||
|
||
</PreferenceCategory> | ||
|
||
<PreferenceCategory | ||
android:title="Compiler"> | ||
|
||
<SwitchPreference | ||
android:key="use_fastjarfs" | ||
android:title="Use fast implementation for Jar FS" | ||
android:summary="This experimental mode may speed up compilation time, but use with caution" | ||
android:defaultValue="false" /> | ||
|
||
<ListPreference | ||
android:key="java_version" | ||
android:title="Java Version" | ||
android:summary="Select the version of Java to use for compilation" | ||
android:entries="@array/java_version_entries" | ||
android:entryValues="@array/java_version_entries" | ||
android:defaultValue="17" /> | ||
|
||
</PreferenceCategory> | ||
|
||
<PreferenceCategory | ||
android:title="About"> | ||
|
||
<Preference | ||
android:key="version" | ||
android:title="Version" /> | ||
|
||
</PreferenceCategory> | ||
|
||
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
common/src/main/java/org/cosmicide/rewrite/common/Prefs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.cosmicide.rewrite.common | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.preference.PreferenceManager | ||
|
||
/** | ||
* A utility object to access shared preferences easily. | ||
*/ | ||
object Prefs { | ||
private lateinit var prefs: SharedPreferences | ||
|
||
/** | ||
* The font size selected by the user. | ||
*/ | ||
val editorFontSize: Float | ||
get() { | ||
return try { | ||
prefs.getString("font_size", "12")?.toFloat() ?: 12f | ||
} catch (e: Exception) { | ||
12f | ||
} | ||
} | ||
|
||
/** | ||
* The Java version selected by the user. | ||
*/ | ||
val compilerJavaVersion: Int | ||
get() { | ||
return try { | ||
prefs.getString("java_version", "17")?.toInt() ?: 17 | ||
} catch (e: Exception) { | ||
17 | ||
} | ||
} | ||
|
||
/** | ||
* The FastJarFs selected by user. | ||
*/ | ||
val useFastJarFs: Boolean | ||
get() = prefs.getBoolean("use_fastjarfs", false) | ||
|
||
/** | ||
* Initializes shared preferences. | ||
* @param context The context of the application. | ||
*/ | ||
fun init(context: Context) { | ||
prefs = PreferenceManager.getDefaultSharedPreferences(context) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCachedFont would be better here i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the getCachedFont method, the font will not be loaded since it is not cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It checks if its cached and sets it. atleast in emulator, it loads properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested on a real device? When using the
getCachedFont()
method on my device, the font simply didn't load.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it did work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check last artifact (not pr's artifact)