-
-
Notifications
You must be signed in to change notification settings - Fork 81
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 #2641 from kylecorry31/tool-summaries
Add tool summaries support
- Loading branch information
Showing
13 changed files
with
292 additions
and
6 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
19 changes: 19 additions & 0 deletions
19
...in/java/com/kylecorry/trail_sense/tools/experimentation/ExperimentationToolSummaryView.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,19 @@ | ||
package com.kylecorry.trail_sense.tools.experimentation | ||
|
||
import android.widget.FrameLayout | ||
import androidx.fragment.app.Fragment | ||
import com.kylecorry.trail_sense.shared.views.Views | ||
import com.kylecorry.trail_sense.tools.tools.ui.ToolSummaryView | ||
|
||
class ExperimentationToolSummaryView(root: FrameLayout, fragment: Fragment) : ToolSummaryView( | ||
root, | ||
fragment | ||
) { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
val textView = Views.text(context, "This is a test") | ||
root.addView(textView) | ||
} | ||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/kylecorry/trail_sense/tools/tools/infrastructure/ToolSummary.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,17 @@ | ||
package com.kylecorry.trail_sense.tools.tools.infrastructure | ||
|
||
import android.widget.FrameLayout | ||
import androidx.fragment.app.Fragment | ||
import com.kylecorry.trail_sense.tools.tools.ui.ToolSummaryView | ||
|
||
data class ToolSummary( | ||
val id: String, | ||
val name: String, | ||
val size: ToolSummarySize = ToolSummarySize.Full, | ||
val create: (root: FrameLayout, fragment: Fragment) -> ToolSummaryView | ||
) | ||
|
||
enum class ToolSummarySize { | ||
Half, | ||
Full | ||
} |
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
35 changes: 35 additions & 0 deletions
35
.../main/java/com/kylecorry/trail_sense/tools/tools/quickactions/QuickActionToolSummaries.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,35 @@ | ||
package com.kylecorry.trail_sense.tools.tools.quickactions | ||
|
||
import android.widget.ImageButton | ||
import androidx.fragment.app.Fragment | ||
import com.kylecorry.andromeda.fragments.show | ||
import com.kylecorry.trail_sense.R | ||
import com.kylecorry.trail_sense.shared.QuickActionButton | ||
import com.kylecorry.trail_sense.tools.tools.ui.ToolSummaryViewBottomSheet | ||
|
||
class QuickActionToolSummaries(button: ImageButton, fragment: Fragment) : QuickActionButton( | ||
button, | ||
fragment | ||
) { | ||
|
||
private var sheet: ToolSummaryViewBottomSheet? = null | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
setIcon(R.drawable.ic_summary) | ||
} | ||
|
||
override fun onClick() { | ||
super.onClick() | ||
sheet?.dismiss() | ||
sheet = ToolSummaryViewBottomSheet() | ||
sheet?.show(fragment) | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
sheet?.dismiss() | ||
sheet = null | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/kylecorry/trail_sense/tools/tools/ui/ToolSummaryView.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,65 @@ | ||
package com.kylecorry.trail_sense.tools.tools.ui | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.widget.FrameLayout | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleEventObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
|
||
abstract class ToolSummaryView( | ||
protected val root: FrameLayout, | ||
protected val fragment: Fragment | ||
) { | ||
protected val context: Context by lazy { fragment.requireContext() } | ||
|
||
private val observer = LifecycleEventObserver { _, event -> | ||
when (event) { | ||
Lifecycle.Event.ON_CREATE -> onCreate() | ||
Lifecycle.Event.ON_RESUME -> onResume() | ||
Lifecycle.Event.ON_PAUSE -> onPause() | ||
Lifecycle.Event.ON_DESTROY -> onDestroy() | ||
else -> { | ||
// Do nothing | ||
} | ||
} | ||
} | ||
|
||
private val attachStateChangeListener = object : View.OnAttachStateChangeListener { | ||
override fun onViewAttachedToWindow(v: View) { | ||
// Do nothing | ||
} | ||
|
||
override fun onViewDetachedFromWindow(v: View) { | ||
onDestroy() | ||
} | ||
} | ||
|
||
fun bind(lifecycleOwner: LifecycleOwner) { | ||
lifecycleOwner.lifecycle.addObserver(observer) | ||
} | ||
|
||
fun unbind(lifecycleOwner: LifecycleOwner) { | ||
lifecycleOwner.lifecycle.removeObserver(observer) | ||
} | ||
|
||
open fun onCreate() { | ||
root.removeAllViews() | ||
root.isVisible = true | ||
root.addOnAttachStateChangeListener(attachStateChangeListener) | ||
} | ||
|
||
open fun onResume() { | ||
// Do nothing | ||
} | ||
|
||
open fun onPause() { | ||
// Do nothing | ||
} | ||
|
||
open fun onDestroy() { | ||
root.removeOnAttachStateChangeListener(attachStateChangeListener) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/kylecorry/trail_sense/tools/tools/ui/ToolSummaryViewBottomSheet.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,77 @@ | ||
package com.kylecorry.trail_sense.tools.tools.ui | ||
|
||
import android.content.res.ColorStateList | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import androidx.core.view.setPadding | ||
import com.google.android.flexbox.FlexboxLayout | ||
import com.kylecorry.andromeda.core.system.Resources | ||
import com.kylecorry.andromeda.fragments.BoundBottomSheetDialogFragment | ||
import com.kylecorry.trail_sense.R | ||
import com.kylecorry.trail_sense.databinding.FragmentToolSummarySheetBinding | ||
import com.kylecorry.trail_sense.tools.tools.infrastructure.ToolSummarySize | ||
import com.kylecorry.trail_sense.tools.tools.infrastructure.Tools | ||
|
||
class ToolSummaryViewBottomSheet : | ||
BoundBottomSheetDialogFragment<FragmentToolSummarySheetBinding>() { | ||
override fun generateBinding( | ||
layoutInflater: LayoutInflater, | ||
container: ViewGroup? | ||
): FragmentToolSummarySheetBinding { | ||
return FragmentToolSummarySheetBinding.inflate(layoutInflater, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
// TODO: Filter to what the user selected | ||
val summaries = Tools.getTools(requireContext()) | ||
.flatMap { it.summaries } | ||
.sortedByDescending { it.size.ordinal } | ||
|
||
binding.summaries.removeAllViews() | ||
|
||
val summaryHeight = Resources.dp(requireContext(), 150f).toInt() | ||
val summaryGap = Resources.dp(requireContext(), 4f).toInt() | ||
val summaryElevation = Resources.dp(requireContext(), 4f) | ||
val summaryBackgroundColor = Resources.androidBackgroundColorSecondary(requireContext()) | ||
val summaryPadding = Resources.dp(requireContext(), 8f).toInt() | ||
|
||
// For each summary, create a linear layout with the title and the summary view | ||
summaries.forEach { summary -> | ||
// The root of the summary | ||
val root = FrameLayout(requireContext()) | ||
root.layoutParams = FrameLayout.LayoutParams( | ||
FrameLayout.LayoutParams.MATCH_PARENT, | ||
FrameLayout.LayoutParams.MATCH_PARENT | ||
) | ||
root.setPadding(summaryPadding) | ||
root.setBackgroundResource(R.drawable.rounded_rectangle) | ||
root.backgroundTintList = ColorStateList.valueOf(summaryBackgroundColor) | ||
root.elevation = summaryElevation | ||
|
||
// The wrapper which allows for a gap between the summaries | ||
val layout = FrameLayout(requireContext()) | ||
layout.addView(root) | ||
layout.layoutParams = FlexboxLayout.LayoutParams( | ||
FlexboxLayout.LayoutParams.MATCH_PARENT, | ||
summaryHeight | ||
).apply { | ||
flexBasisPercent = when (summary.size) { | ||
ToolSummarySize.Full -> 1f | ||
ToolSummarySize.Half -> 0.5f | ||
} | ||
} | ||
layout.setPadding(summaryGap) | ||
|
||
binding.summaries.addView(layout) | ||
|
||
val summaryView = summary.create(root, this) | ||
summaryView.bind(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- drawable/post_outline.xml --> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#ffffff" | ||
android:pathData="M19 5V19H5V5H19M21 3H3V21H21V3M17 17H7V16H17V17M17 15H7V14H17V15M17 12H7V7H17V12Z" /> | ||
</vector> |
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,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<com.kylecorry.andromeda.views.toolbar.Toolbar | ||
android:id="@+id/tool_summaries_title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:showSubtitle="false" | ||
app:title="@string/tool_summaries" /> | ||
|
||
<androidx.core.widget.NestedScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1"> | ||
|
||
<com.google.android.flexbox.FlexboxLayout | ||
android:id="@+id/summaries" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:alignItems="center" | ||
app:flexWrap="wrap" | ||
app:justifyContent="flex_start"> | ||
|
||
</com.google.android.flexbox.FlexboxLayout> | ||
</androidx.core.widget.NestedScrollView> | ||
|
||
</LinearLayout> |
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