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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also added prefs object class.
- Loading branch information
Showing
20 changed files
with
236 additions
and
7 deletions.
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> | ||
<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