diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c99c4de..58e8551 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -48,4 +48,5 @@ dependencies { implementation("androidx.navigation:navigation-ui-ktx:2.7.7") implementation("com.google.code.gson:gson:2.11.0") implementation("androidx.recyclerview:recyclerview:1.3.2") + implementation("androidx.preference:preference:1.2.1") } \ No newline at end of file diff --git a/app/src/androidTest/java/eu/ottop/yamlauncher/ExampleInstrumentedTest.kt b/app/src/androidTest/java/eu/ottop/yamlauncher/ExampleInstrumentedTest.kt deleted file mode 100644 index fbc5179..0000000 --- a/app/src/androidTest/java/eu/ottop/yamlauncher/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package eu.ottop.yamlauncher - -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("eu.ottop.yamlauncher", appContext.packageName) - } -} \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 4f4383c..0d12d3e 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -3,6 +3,7 @@ package eu.ottop.yamlauncher import android.annotation.SuppressLint import android.content.Context import android.content.Intent +import android.content.SharedPreferences import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherApps import android.os.Build @@ -24,6 +25,7 @@ import android.widget.TextClock import android.widget.TextView import android.widget.Toast import androidx.activity.OnBackPressedCallback +import androidx.activity.viewModels import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout @@ -31,6 +33,7 @@ import androidx.constraintlayout.widget.ConstraintSet import androidx.core.content.res.ResourcesCompat import androidx.core.view.children import androidx.core.view.marginLeft +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView import eu.ottop.yamlauncher.databinding.ActivityMainBinding import kotlinx.coroutines.CoroutineScope @@ -43,7 +46,7 @@ import kotlin.math.abs import java.lang.reflect.Method -class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, AppMenuAdapter.OnShortcutListener, AppMenuAdapter.OnItemLongClickListener { +class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener, AppMenuAdapter.OnItemClickListener, AppMenuAdapter.OnShortcutListener, AppMenuAdapter.OnItemLongClickListener { private lateinit var binding: ActivityMainBinding private lateinit var gestureDetector: GestureDetector @@ -78,6 +81,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap private var cameraSwipeEnabled = true private var contactsSwipeEnabled = true + private lateinit var preferences: SharedPreferences + @SuppressLint("ClickableViewAccessibility") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -85,6 +90,10 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap setContentView(binding.root) setSupportActionBar(null) + preferences = PreferenceManager.getDefaultSharedPreferences(this) + + preferences.registerOnSharedPreferenceChangeListener(this) + searchView = findViewById(R.id.searchView) launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps @@ -98,8 +107,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap constraintLayout = findViewById(R.id.clock_layout) + setClockAlignment(preferences.getString("clockAlignment", "left"), clock.id, clockMargin) + setupApps() + setShortcutAlignment(preferences.getString("shortcutAlignment", "left"), binding.homeView) + dateText = findViewById(R.id.text_date) batteryReceiver = BatteryReceiver.register(this, dateText) @@ -115,6 +128,20 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap backToHome() } }) + + } + + override fun onSharedPreferenceChanged(preferences: SharedPreferences?, key: String?) { + + when (key) { + "clockAlignment" -> { + setClockAlignment(preferences?.getString(key, "left"), clock.id, clockMargin) + } + + "shortcutAlignment" -> { + setShortcutAlignment(preferences?.getString("shortcutAlignment", "left"), binding.homeView) + } + } } override fun onNewIntent(intent: Intent?) { @@ -131,6 +158,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap super.onDestroy() job?.cancel() unregisterReceiver(batteryReceiver) + preferences.unregisterOnSharedPreferenceChangeListener(this) } override fun onStart() { @@ -145,9 +173,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap override fun onResume() { super.onResume() setTextSizes() - - setClockAlignment() - setShortCutAlignment() setSearchAlignment() setGestures() @@ -456,8 +481,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap shortcutView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null) } - setShortCutAlignment() - shortcutView.text = textView.text.toString() shortcutView.setOnClickListener { val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull() @@ -540,29 +563,20 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap return true } - private fun setClockAlignment() { - setConstraintAlignment(sharedPreferenceManager.getClockAlignment(this@MainActivity), clock.id, clockMargin) - } - - private fun setConstraintAlignment(alignment: Int, widgetId: Int, margin: Int) { + private fun setClockAlignment(alignment: String?, widgetId: Int, margin: Int) { val constraintSet = ConstraintSet() constraintSet.clone(constraintLayout) println(alignment) - /* - 0 = left - 1 = center - 2 = right - */ - if (alignment == 2) { + if (alignment == "right") { constraintSet.clear(widgetId, ConstraintSet.START) } - else if (alignment == 0) { + else if (alignment == "left") { constraintSet.clear(widgetId, ConstraintSet.END) } - if (alignment == 1 || alignment == 0) { + if (alignment == "center" || alignment == "left") { constraintSet.connect( widgetId, ConstraintSet.START, @@ -573,7 +587,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap } - if (alignment != 0) { + if (alignment != "left") { constraintSet.connect( widgetId, ConstraintSet.END, @@ -586,8 +600,49 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap constraintSet.applyTo(constraintLayout) } - private fun setShortCutAlignment() { - setLinearAlignment(binding.homeView) + private fun setShortcutAlignment(alignment: String?, shortcuts: LinearLayout) { + shortcuts.children.forEach { + + if (it is TextView) { + + + when (alignment) { + "left" -> { + it.setCompoundDrawablesWithIntrinsicBounds(it.compoundDrawables.filterNotNull().first(),null, null, null) + it.gravity = Gravity.CENTER_VERTICAL or Gravity.START + } + "center" -> { + it.setCompoundDrawablesWithIntrinsicBounds(it.compoundDrawables.filterNotNull().first(),null,it.compoundDrawables.filterNotNull().first(), null) + it.gravity = Gravity.CENTER + } + "right" -> { + it.setCompoundDrawablesWithIntrinsicBounds(null,null, it.compoundDrawables.filterNotNull().first(), null) + it.gravity = Gravity.CENTER_VERTICAL or Gravity.END + } + } + + } + } + } + + private fun setSearchAlignment() { + + /* + 0 = left + 1 = center + 2 = right + */ + when (sharedPreferenceManager.getSearchAlignment(this@MainActivity)) { + 0 -> { + searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START + } + 1 -> { + searchView.textAlignment = View.TEXT_ALIGNMENT_CENTER + } + 2 -> { + searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END + } + } } private fun setShortcutSize(shortcuts: LinearLayout) { @@ -632,56 +687,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap } } - private fun setLinearAlignment(shortcuts: LinearLayout) { - shortcuts.children.forEach { - - if (it is TextView) { - - /* - 0 = left - 1 = center - 2 = right - */ - - when (sharedPreferenceManager.getHomeAppAlignment(this@MainActivity)) { - 0 -> { - it.setCompoundDrawablesWithIntrinsicBounds(it.compoundDrawables.filterNotNull().first(),null, null, null) - it.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - 1 -> { - it.setCompoundDrawablesWithIntrinsicBounds(it.compoundDrawables.filterNotNull().first(),null,it.compoundDrawables.filterNotNull().first(), null) - it.gravity = Gravity.CENTER - } - 2 -> { - it.setCompoundDrawablesWithIntrinsicBounds(null,null, it.compoundDrawables.filterNotNull().first(), null) - it.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } - } - - } - } - } - - private fun setSearchAlignment() { - - /* - 0 = left - 1 = center - 2 = right - */ - when (sharedPreferenceManager.getSearchAlignment(this@MainActivity)) { - 0 -> { - searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START - } - 1 -> { - searchView.textAlignment = View.TEXT_ALIGNMENT_CENTER - } - 2 -> { - searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END - } - } - } - private fun setTextSizes() { setShortcutSize(binding.homeView) diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt index 957fc8d..a0fe65d 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt @@ -7,7 +7,21 @@ import android.widget.AdapterView import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding class SettingsActivity : AppCompatActivity() { + private lateinit var binding: ActivitySettingsBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivitySettingsBinding.inflate(layoutInflater) + setContentView(binding.root) + supportFragmentManager + .beginTransaction() + .replace(R.id.settingsLayout, SettingsFragment()) + .commit() + } + + + /* private lateinit var binding: ActivitySettingsBinding private val sharedPreferenceManager = SharedPreferenceManager() override fun onCreate(savedInstanceState: Bundle?) { @@ -136,4 +150,6 @@ class SettingsActivity : AppCompatActivity() { } } + + */ } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt new file mode 100644 index 0000000..0ec6baf --- /dev/null +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt @@ -0,0 +1,11 @@ +package eu.ottop.yamlauncher + +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat + +class SettingsFragment : PreferenceFragmentCompat() { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.root_preferences, rootKey) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index ea1317d..22ec46d 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,452 +1,452 @@ + - - - - - + android:layout_height="match_parent" + android:visibility="gone"> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..bd74b04 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,30 @@ + + + + Reply + Reply to all + + + + reply + reply_all + + + + Left + Center + Right + + + + left + center + right + + + + Small + Medium + Large + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc71a32..599b501 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,15 +49,20 @@ Search… App App - - Left - Center - Right - - - Small - Medium - Large - + + + Messages + Sync + + + Your signature + Default reply action + + + Sync email periodically + Download incoming attachments + Automatically download attachments for incoming emails + + Only download attachments when manually requested \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml new file mode 100644 index 0000000..6923c3b --- /dev/null +++ b/app/src/main/res/xml/root_preferences.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file