-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] - User can see Payment Methods screen (#367)
* setting up payment methods screen * added strings and query for payment methods * added custom scalar type, viewmodel for viewHolder * added formatter to viewholder and added dimens for payment methods * fixed text styling for the list item * added new lines to new classes * wrote viewmodel tests for paymentmethods * added Locale default for date formatting * fixed drawables * switched src to background * removed double dependency and fixed the manifest * fixed line spacing * fixed schema issue * fixed manifest line * fixed creditcard schema * fixed constraint layout version and added new line to list item * fixed custom type mapping formatting * fixed list item text spacing * addressed PR feedback * removed error methods * fixed date test * added test for when adding cards fails
- Loading branch information
Rashad Cureton
committed
Nov 1, 2018
1 parent
bd7ff9d
commit 2436858
Showing
48 changed files
with
1,216 additions
and
23 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,14 @@ | ||
query UserPayments { | ||
me { | ||
storedCards { | ||
nodes { | ||
id | ||
expirationDate | ||
lastFour | ||
state | ||
paymentType | ||
type | ||
} | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/kickstarter/libs/graphql/DateAdapter.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,24 @@ | ||
package com.kickstarter.libs.graphql | ||
|
||
import com.apollographql.apollo.response.CustomTypeAdapter | ||
import com.apollographql.apollo.response.CustomTypeValue | ||
import java.text.ParseException | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
class DateAdapter: CustomTypeAdapter<Date> { | ||
|
||
private val DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) | ||
|
||
override fun encode(value: Date): CustomTypeValue<*> { | ||
return CustomTypeValue.GraphQLString(DATE_FORMAT.format(value)) | ||
} | ||
|
||
override fun decode(value: CustomTypeValue<*>): Date { | ||
try { | ||
return DATE_FORMAT.parse(value.value.toString()) | ||
} catch (exception: ParseException) { | ||
throw RuntimeException(exception) | ||
} | ||
} | ||
} |
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
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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/kickstarter/ui/activities/PaymentMethodsActivity.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,40 @@ | ||
package com.kickstarter.ui.activities | ||
|
||
import UserPaymentsQuery | ||
import android.os.Bundle | ||
import android.support.v7.widget.LinearLayoutManager | ||
import com.kickstarter.R | ||
import com.kickstarter.libs.BaseActivity | ||
import com.kickstarter.libs.qualifiers.RequiresActivityViewModel | ||
import com.kickstarter.ui.adapters.PaymentMethodsAdapter | ||
import com.kickstarter.viewmodels.PaymentMethodsViewModel | ||
import kotlinx.android.synthetic.main.activity_payment_method.* | ||
import rx.android.schedulers.AndroidSchedulers | ||
|
||
@RequiresActivityViewModel(PaymentMethodsViewModel.ViewModel::class) | ||
class PaymentMethodsActivity : BaseActivity<PaymentMethodsViewModel.ViewModel>() { | ||
|
||
private lateinit var adapter: PaymentMethodsAdapter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_payment_method) | ||
|
||
setupRecyclerview() | ||
|
||
this.viewModel.outputs.getCards() | ||
.compose(bindToLifecycle()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe { setCards(it) } | ||
|
||
} | ||
|
||
private fun setCards(cards: MutableList<UserPaymentsQuery.Node>) = this.adapter.populateCards(cards) | ||
|
||
private fun setupRecyclerview() { | ||
this.adapter = PaymentMethodsAdapter(this.viewModel) | ||
recycler_view.adapter = this.adapter | ||
recycler_view.layoutManager = LinearLayoutManager(this) | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/kickstarter/ui/adapters/PaymentMethodsAdapter.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,21 @@ | ||
package com.kickstarter.ui.adapters | ||
|
||
import UserPaymentsQuery | ||
import android.view.View | ||
import com.kickstarter.R | ||
import com.kickstarter.ui.viewholders.KSViewHolder | ||
import com.kickstarter.ui.viewholders.PaymentMethodsViewHolder | ||
|
||
class PaymentMethodsAdapter(private val delegate: PaymentMethodsViewHolder.Delegate): KSAdapter() { | ||
|
||
interface Delegate: PaymentMethodsViewHolder.Delegate | ||
|
||
override fun layout(sectionRow: SectionRow): Int = R.layout.list_item_payment_methods | ||
|
||
override fun viewHolder(layout: Int, view: View): KSViewHolder = PaymentMethodsViewHolder(view, delegate) | ||
|
||
fun populateCards(cards: MutableList<UserPaymentsQuery.Node>) { | ||
addSection(cards) | ||
notifyDataSetChanged() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/kickstarter/ui/viewholders/PaymentMethodsViewHolder.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,60 @@ | ||
package com.kickstarter.ui.viewholders | ||
|
||
import UserPaymentsQuery | ||
import android.support.annotation.NonNull | ||
import android.view.View | ||
import com.kickstarter.R | ||
import com.kickstarter.libs.rx.transformers.Transformers.observeForUI | ||
import com.kickstarter.viewmodels.PaymentMethodsViewHolderViewModel | ||
import kotlinx.android.synthetic.main.list_item_payment_methods.view.* | ||
|
||
class PaymentMethodsViewHolder(@NonNull view: View, @NonNull delegate: Delegate) : KSViewHolder(view) { | ||
|
||
private val ksString = environment().ksString() | ||
private val vm: PaymentMethodsViewHolderViewModel.ViewModel = PaymentMethodsViewHolderViewModel.ViewModel(environment()) | ||
|
||
private val creditCardExpirationString = this.context().getString(R.string.Credit_card_expiration) | ||
private val cardEndingInString = this.context().getString(R.string.Card_ending_in_last_four) | ||
|
||
interface Delegate | ||
|
||
init { | ||
|
||
this.vm.outputs.type() | ||
.compose(bindToLifecycle()) | ||
.compose(observeForUI()) | ||
.subscribe { | ||
itemView.credit_card_logo.setImageResource(it) | ||
} | ||
|
||
this.vm.outputs.expirationDate() | ||
.compose(bindToLifecycle()) | ||
.compose(observeForUI()) | ||
.subscribe { | ||
setExpirationDateTextView(it) | ||
} | ||
|
||
this.vm.outputs.lastFour() | ||
.compose(bindToLifecycle()) | ||
.compose(observeForUI()) | ||
.subscribe { | ||
setLastFourTextView(it) | ||
} | ||
|
||
} | ||
|
||
override fun bindData(data: Any?) { | ||
val cards = requireNotNull(data as UserPaymentsQuery.Node) | ||
this.vm.inputs.card(cards) | ||
} | ||
|
||
private fun setExpirationDateTextView(date: String) { | ||
itemView.credit_card_expiration_date.text = this.ksString.format(this.creditCardExpirationString, | ||
"expiration_date", date) | ||
} | ||
|
||
private fun setLastFourTextView(lastFour: String) { | ||
itemView.credit_card_last_four_digits.text = this.ksString.format(this.cardEndingInString, "last_four", lastFour) | ||
} | ||
|
||
} |
Oops, something went wrong.