Implemented showing fetch all transactions view at top and by clicking on 'x' button showing it at bottom (TODO on Android: show at bottom)

This commit is contained in:
dankito 2020-09-27 00:32:18 +02:00
parent e8aee07b34
commit 3be297c0d3
4 changed files with 200 additions and 80 deletions

View File

@ -52,6 +52,8 @@ class HomeFragment : Fragment() {
private var accountsForWhichNotAllTransactionsHaveBeenFetched = listOf<TypedBankAccount>()
private var showTopFetchAllTransactionsView = true // TODO: read from db
private val transactionAdapter: AccountTransactionAdapter
@ -92,10 +94,18 @@ class HomeFragment : Fragment() {
registerForContextMenu(rcyvwAccountTransactions) // this is actually bad, splits code as context menu is created in AccountTransactionAdapter
rootView.btnFetchAllTransactions.setOnClickListener {
rootView.btnTopFetchAllTransactions.setOnClickListener {
fetchAllTransactions()
}
rootView.btnBottomFetchAllTransactions.setOnClickListener {
fetchAllTransactions()
}
rootView.btnHideTopFetchAllTransactionsView.setOnClickListener {
hideTopFetchAllTransactionsView()
}
rootView.btnRetrieveTransactions.setOnClickListener { fetchTransactions() }
rootView.btnAddAccount.setOnClickListener { presenter.showAddAccountDialog() }
@ -286,16 +296,31 @@ class HomeFragment : Fragment() {
private fun setFetchAllTransactionsView() {
accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched
val showFetchAllTransactionsView = accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty()
|| presenter.selectedAccountsTransactionRetrievalState == TransactionsRetrievalState.RetrievedTransactions
val hideFetchAllTransactionsView = accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty()
|| presenter.selectedAccountsTransactionRetrievalState != TransactionsRetrievalState.RetrievedTransactions
if (hideFetchAllTransactionsView) {
lytFetchAllTransactions.visibility = View.GONE
if (showFetchAllTransactionsView && showTopFetchAllTransactionsView) {
lytTopFetchAllTransactions.visibility = View.VISIBLE
}
else {
lytFetchAllTransactions.visibility = View.VISIBLE
lytTopFetchAllTransactions.visibility = View.GONE
}
if (showFetchAllTransactionsView && showTopFetchAllTransactionsView == false) {
// TODO: implement CoordinatorLayout to show lytBottomFetchAllTransactions below rcyvwAccountTransactions
// lytBottomFetchAllTransactions.visibility = View.VISIBLE
}
else {
lytBottomFetchAllTransactions.visibility = View.GONE
}
}
private fun hideTopFetchAllTransactionsView() {
// TODO: persist
showTopFetchAllTransactionsView = false
setFetchAllTransactionsView()
}

View File

@ -57,9 +57,17 @@
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/lytFetchAllTransactions"
<View
android:id="@+id/summaryAndTransactionsListDivider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:paddingLeft="-12dp"
android:paddingRight="-12dp"
android:background="@color/formSectionDivideColor"
/>
<RelativeLayout
android:id="@+id/lytTopFetchAllTransactions"
android:layout_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_layout_height"
android:gravity="center"
@ -67,18 +75,41 @@
>
<Button
android:id="@+id/btnFetchAllTransactions"
android:id="@+id/btnTopFetchAllTransactions"
android:layout_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_button_height"
android:gravity="center_horizontal"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/btnHideTopFetchAllTransactionsView"
android:layout_toStartOf="@+id/btnHideTopFetchAllTransactionsView"
android:gravity="center"
android:textAlignment="gravity"
style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false"
android:textColor="@color/linkColor"
android:text="@string/fragment_home_fetch_all_account_transactions"
/>
</LinearLayout>
<ImageButton
android:id="@+id/btnHideTopFetchAllTransactionsView"
android:layout_width="@dimen/fragment_account_transaction_hide_fetch_all_transactions_button_height_and_width"
android:layout_height="@dimen/fragment_account_transaction_hide_fetch_all_transactions_button_height_and_width"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="@dimen/fragment_account_transaction_hide_fetch_all_transactions_button_margin_start_and_end"
android:layout_marginStart="@dimen/fragment_account_transaction_hide_fetch_all_transactions_button_margin_start_and_end"
android:layout_marginRight="@dimen/fragment_account_transaction_hide_fetch_all_transactions_button_margin_start_and_end"
android:layout_marginEnd="@dimen/fragment_account_transaction_hide_fetch_all_transactions_button_margin_start_and_end"
android:background="@null"
android:tint="#000000"
app:srcCompat="@drawable/ic_baseline_close_24"
/>
</RelativeLayout>
</LinearLayout>
@ -95,6 +126,34 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<!-- TODO: add CoordinatorLayout to show lytBottomFetchAllTransactions below rcyvwAccountTransactions -->
<LinearLayout
android:orientation="vertical"
android:id="@+id/lytBottomFetchAllTransactions"
android:layout_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_layout_height"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="@color/formSectionDivideColor"
android:visibility="gone"
>
<Button
android:id="@+id/btnBottomFetchAllTransactions"
android:layout_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_button_height"
android:gravity="center"
android:textAlignment="gravity"
style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false"
android:textColor="@color/linkColor"
android:text="@string/fragment_home_fetch_all_account_transactions"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/lytNoTransactionsFetched"

View File

@ -31,6 +31,8 @@
<dimen name="fragment_account_transaction_add_account_button_height">40dp</dimen>
<dimen name="fragment_account_transaction_fetch_all_transactions_layout_height">48dp</dimen>
<dimen name="fragment_account_transaction_fetch_all_transactions_button_height">40dp</dimen>
<dimen name="fragment_account_transaction_hide_fetch_all_transactions_button_height_and_width">30dp</dimen>
<dimen name="fragment_account_transaction_hide_fetch_all_transactions_button_margin_start_and_end">2dp</dimen>
<dimen name="list_item_account_transaction_height">74dp</dimen>
<dimen name="list_item_account_transaction_padding">0dp</dimen>

View File

@ -4,6 +4,8 @@ import BankingUiSwift
struct AccountTransactionsDialog: View {
static private let HideTopFetchAllTransactionsViewButtonWidth: CGFloat = 34
static private let RetrievedTransactionsPeriodDateFormat = DateFormatter()
@ -20,6 +22,8 @@ struct AccountTransactionsDialog: View {
@State private var showFetchAllTransactionsView: Bool = false
@State private var showFetchAllTransactionsViewAtTop: Bool = true
@State private var accountsForWhichNotAllTransactionsHaveBeenFetched: [IBankAccount] = []
@ -90,17 +94,18 @@ struct AccountTransactionsDialog: View {
}
}
if showFetchAllTransactionsView {
SectionWithoutBackground {
if showFetchAllTransactionsView && showFetchAllTransactionsViewAtTop {
HStack(alignment: .center) {
Spacer()
fetchAllTransactionsButton
.padding(.horizontal, 0)
Spacer()
}
.padding(.horizontal, 6)
}
.padding(.horizontal, 0)
.padding(.trailing, Self.HideTopFetchAllTransactionsViewButtonWidth)
.frame(maxWidth: .infinity, minHeight: 44, maxHeight: .infinity) // has to have at least a height of 44 (iOS 14; iOS 13: 40), otherwise a white line at bottom gets displayed
.removeSectionBackground()
.overlay(hideTopFetchAllTransactionsViewButton, alignment: .trailing)
}
if showTransactionsList {
@ -109,6 +114,18 @@ struct AccountTransactionsDialog: View {
AccountTransactionListItem(transaction, self.showBankIcons)
}
}
if showFetchAllTransactionsView && showFetchAllTransactionsViewAtTop == false {
SectionWithoutBackground {
HStack {
Spacer()
fetchAllTransactionsButton
Spacer()
}
}
}
}
else {
VStack(alignment: .center) {
@ -146,7 +163,8 @@ struct AccountTransactionsDialog: View {
let haveTransactionsForSelectedAccountsBeenRetrieved = transactionsRetrievalState == .retrievedtransactions
self.accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched
self.showFetchAllTransactionsView = shouldShowFetchAllTransactionsView && haveTransactionsForSelectedAccountsBeenRetrieved
self.showFetchAllTransactionsView = accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty && haveTransactionsForSelectedAccountsBeenRetrieved
//self.showFetchAllTransactionsViewAtTop = true // TODO: read from database
self.showTransactionsList = haveTransactionsForSelectedAccountsBeenRetrieved
@ -155,11 +173,31 @@ struct AccountTransactionsDialog: View {
self.showFetchTransactionsButton = transactionsRetrievalState != .accountdoesnotsupportfetchingtransactions && transactionsRetrievalState != .accounttypenotsupported
}
private func hideTopFetchAllTransactionsView() {
// TODO: save that we shouldn't show showFetchAllTransactionsView at top anymore in database
for account in accountsForWhichNotAllTransactionsHaveBeenFetched {
//UserDefaults.standard.set(true, forKey: Self.DoNotShowFetchAllTransactionsOverlayForUserDefaultsKeyPrefix + account.technicalId)
}
self.showFetchAllTransactionsViewAtTop = false
}
private var fetchAllTransactionsButton: some View {
Button("Fetch all account transactions") {
self.fetchAllTransactions(self.accountsForWhichNotAllTransactionsHaveBeenFetched)
Button(action: { self.fetchAllTransactions() } ) {
Text("Fetch all account transactions")
.multilineTextAlignment(.center)
}
.foregroundColor(Color.blue)
}
private var hideTopFetchAllTransactionsViewButton: some View {
// do not set Button's action as then if any of the two buttons get pressed, both actions get executed (bug in iOS). Use .onTapGesture() instead
Button("X") { }
.onTapGesture {
self.hideTopFetchAllTransactionsView()
}
.frame(width: Self.HideTopFetchAllTransactionsViewButtonWidth, height: 44, alignment: .center)
}
@ -191,8 +229,8 @@ struct AccountTransactionsDialog: View {
}
}
private func fetchAllTransactions(_ accounts: [IBankAccount]) {
accounts.forEach { account in
private func fetchAllTransactions() {
accountsForWhichNotAllTransactionsHaveBeenFetched.forEach { account in
presenter.fetchAllAccountTransactionsAsync(account: account, callback: self.handleGetTransactionsResult)
}
}
@ -244,10 +282,6 @@ struct AccountTransactionsDialog: View {
return response.retrievedData.first { $0.successfullyRetrievedData == false }?.account
}
private var shouldShowFetchAllTransactionsView: Bool {
return accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty
}
}