-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2047 from kylecorry31/layout-2
Tools layout redesign
- Loading branch information
Showing
16 changed files
with
844 additions
and
368 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/kylecorry/trail_sense/experimentation/ExperimentationFragment.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,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) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/kylecorry/trail_sense/quickactions/ToolsQuickActionBinder.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,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) | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/kylecorry/trail_sense/tools/ui/PinnedToolManager.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,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(",")) | ||
} | ||
|
||
} |
Oops, something went wrong.