Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.

## UNRELEASED
### Added
*ui: Add new headline option for the payment options (APPS-1915)
### Changed
### Removed
### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package io.snabble.sdk.ui.payment

import android.os.Bundle
import android.view.View
import io.snabble.sdk.ui.BaseFragment
import io.snabble.sdk.ui.R

open class PaymentOptionsFragment : BaseFragment(
layoutResId = R.layout.snabble_fragment_payment_options,
waitForProject = false
)
) {
companion object {
const val ARG_PAYMENT_OPTIONS_HEADLINE = PaymentOptionsView.ARG_PAYMENT_OPTIONS_HEADLINE
}

override fun onActualViewCreated(view: View, savedInstanceState: Bundle?) {
val v = view as PaymentOptionsView
arguments?.getString(ARG_PAYMENT_OPTIONS_HEADLINE)?.let { v.setHeadline(it) }
}
}
13 changes: 12 additions & 1 deletion ui/src/main/java/io/snabble/sdk/ui/payment/PaymentOptionsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
Expand All @@ -25,12 +26,15 @@ import io.snabble.sdk.ui.SnabbleUI
import io.snabble.sdk.ui.utils.executeUiAction
import io.snabble.sdk.ui.utils.getFragmentActivity
import io.snabble.sdk.ui.utils.loadAsset
import kotlin.collections.set

open class PaymentOptionsView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

companion object {
const val ARG_PAYMENT_OPTIONS_HEADLINE = "headline"
}

init {
inflate(context, R.layout.snabble_payment_options, this)
val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
Expand Down Expand Up @@ -61,6 +65,13 @@ open class PaymentOptionsView @JvmOverloads constructor(
})
}

fun setHeadline(headline: String) {
findViewById<TextView>(R.id.headline).apply {
text = headline
isVisible = true
}
}

private fun getEntries(): List<Entry> {
val projects = Snabble.projects.filter { project ->
project.availablePaymentMethods.count { it.isRequiringCredentials } > 0
Expand Down
22 changes: 19 additions & 3 deletions ui/src/main/res/layout/snabble_payment_options.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/headline"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:textAlignment="center"
android:visibility="gone" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>