Skip to content

Commit

Permalink
Merge pull request #2047 from kylecorry31/layout-2
Browse files Browse the repository at this point in the history
Tools layout redesign
  • Loading branch information
kylecorry31 authored Nov 11, 2023
2 parents 90ee480 + 289db79 commit b46b15a
Show file tree
Hide file tree
Showing 16 changed files with 844 additions and 368 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kylecorry.trail_sense.experimentation

import android.view.LayoutInflater
import android.view.ViewGroup
import com.kylecorry.andromeda.fragments.BoundFragment
import com.kylecorry.trail_sense.databinding.FragmentExperimentationBinding

class ExperimentationFragment : BoundFragment<FragmentExperimentationBinding>() {

override fun generateBinding(
layoutInflater: LayoutInflater, container: ViewGroup?
): FragmentExperimentationBinding {
return FragmentExperimentationBinding.inflate(layoutInflater, container, false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.kylecorry.trail_sense.quickactions

import android.widget.ImageButton
import androidx.core.view.setMargins
import com.google.android.flexbox.FlexboxLayout
import com.kylecorry.andromeda.core.system.Resources
import com.kylecorry.andromeda.fragments.AndromedaFragment
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.databinding.FragmentToolsBinding

class ToolsQuickActionBinder(
private val fragment: AndromedaFragment,
private val binding: FragmentToolsBinding
) : IQuickActionBinder {

private fun createButton(): ImageButton {
val size = Resources.dp(fragment.requireContext(), 40f).toInt()
val margins = Resources.dp(fragment.requireContext(), 8f).toInt()
val button = ImageButton(fragment.requireContext())
button.layoutParams = FlexboxLayout.LayoutParams(size, size).apply {
setMargins(margins)
}
button.background =
Resources.drawable(fragment.requireContext(), R.drawable.rounded_rectangle)
button.elevation = 2f

binding.quickActions.addView(button)

return button
}

override fun bind() {
binding.quickActions.removeAllViews()
// TODO: Weather monitor
// TODO: Backtrack quick action should be a toggle rather than opening the path
// QuickActionBacktrack(createButton(), fragment).bind(fragment.viewLifecycleOwner)
QuickActionFlashlight(createButton(), fragment).bind(fragment.viewLifecycleOwner)
QuickActionWhistle(createButton(), fragment).bind(fragment.viewLifecycleOwner)
LowPowerQuickAction(createButton(), fragment).bind(fragment.viewLifecycleOwner)
QuickActionSunsetAlert(createButton(), fragment).bind(fragment.viewLifecycleOwner)
QuickActionWhiteNoise(createButton(), fragment).bind(fragment.viewLifecycleOwner)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ object CustomUiUtils {
}
}

fun oneTimeToast(
context: Context,
message: String,
shownKey: String,
short: Boolean = true
){
val prefs = PreferencesSubsystem.getInstance(context).preferences
if (prefs.getBoolean(shownKey) != true) {
Alerts.toast(context, message, short)
prefs.putBoolean(shownKey, true)
}
}

fun disclaimer(
context: Context,
title: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.kylecorry.trail_sense.tools.ui

import com.kylecorry.andromeda.preferences.IPreferences

class PinnedToolManager(private val prefs: IPreferences) {

private val pinned = mutableSetOf<Long>()
private val lock = Any()

private val key = "pinned_tools"

init {
// TODO: Listen for changes
val all = readPrefs()
synchronized(lock) {
pinned.clear()
pinned.addAll(all)
}
}

fun getPinnedToolIds(): List<Long> {
return synchronized(lock) {
pinned.toList()
}
}

fun setPinnedToolIds(toolIds: List<Long>) {
synchronized(lock) {
pinned.clear()
pinned.addAll(toolIds)
}
writePrefs(getPinnedToolIds())
}

fun pin(toolId: Long) {
synchronized(lock) {
pinned.add(toolId)
}
writePrefs(getPinnedToolIds())
}

fun unpin(toolId: Long) {
synchronized(lock) {
pinned.remove(toolId)
}
writePrefs(getPinnedToolIds())
}

fun isPinned(toolId: Long): Boolean {
return synchronized(lock) {
pinned.contains(toolId)
}
}

private fun readPrefs(): List<Long> {
val str = prefs.getString(key) ?: return listOf(
6L, // Navigation
20L, // Weather
14L // Astronomy
)
return str.split(",").mapNotNull { it.toLongOrNull() }
}

private fun writePrefs(toolIds: List<Long>) {
prefs.putString(key, toolIds.joinToString(","))
}

}
Loading

0 comments on commit b46b15a

Please sign in to comment.