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 accountsForWhichNotAllTransactionsHaveBeenFetched = listOf<TypedBankAccount>()
private var showTopFetchAllTransactionsView = true // TODO: read from db
private val transactionAdapter: AccountTransactionAdapter 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 registerForContextMenu(rcyvwAccountTransactions) // this is actually bad, splits code as context menu is created in AccountTransactionAdapter
rootView.btnFetchAllTransactions.setOnClickListener { rootView.btnTopFetchAllTransactions.setOnClickListener {
fetchAllTransactions() fetchAllTransactions()
} }
rootView.btnBottomFetchAllTransactions.setOnClickListener {
fetchAllTransactions()
}
rootView.btnHideTopFetchAllTransactionsView.setOnClickListener {
hideTopFetchAllTransactionsView()
}
rootView.btnRetrieveTransactions.setOnClickListener { fetchTransactions() } rootView.btnRetrieveTransactions.setOnClickListener { fetchTransactions() }
rootView.btnAddAccount.setOnClickListener { presenter.showAddAccountDialog() } rootView.btnAddAccount.setOnClickListener { presenter.showAddAccountDialog() }
@ -286,16 +296,31 @@ class HomeFragment : Fragment() {
private fun setFetchAllTransactionsView() { private fun setFetchAllTransactionsView() {
accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched
val showFetchAllTransactionsView = accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty()
|| presenter.selectedAccountsTransactionRetrievalState == TransactionsRetrievalState.RetrievedTransactions
val hideFetchAllTransactionsView = accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty() if (showFetchAllTransactionsView && showTopFetchAllTransactionsView) {
|| presenter.selectedAccountsTransactionRetrievalState != TransactionsRetrievalState.RetrievedTransactions lytTopFetchAllTransactions.visibility = View.VISIBLE
if (hideFetchAllTransactionsView) {
lytFetchAllTransactions.visibility = View.GONE
} }
else { 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> </RelativeLayout>
<LinearLayout <View
android:orientation="vertical" android:id="@+id/summaryAndTransactionsListDivider"
android:id="@+id/lytFetchAllTransactions" 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_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_layout_height" android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_layout_height"
android:gravity="center" android:gravity="center"
@ -67,18 +75,41 @@
> >
<Button <Button
android:id="@+id/btnFetchAllTransactions" android:id="@+id/btnTopFetchAllTransactions"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_button_height" android:layout_height="@dimen/fragment_account_transaction_fetch_all_transactions_button_height"
android:gravity="center_horizontal" android:layout_alignParentTop="true"
android:textAlignment="center" 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" style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="@color/linkColor" android:textColor="@color/linkColor"
android:text="@string/fragment_home_fetch_all_account_transactions" 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> </LinearLayout>
@ -95,6 +126,34 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior" 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 <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:id="@+id/lytNoTransactionsFetched" 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_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_layout_height">48dp</dimen>
<dimen name="fragment_account_transaction_fetch_all_transactions_button_height">40dp</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_height">74dp</dimen>
<dimen name="list_item_account_transaction_padding">0dp</dimen> <dimen name="list_item_account_transaction_padding">0dp</dimen>

View File

@ -4,6 +4,8 @@ import BankingUiSwift
struct AccountTransactionsDialog: View { struct AccountTransactionsDialog: View {
static private let HideTopFetchAllTransactionsViewButtonWidth: CGFloat = 34
static private let RetrievedTransactionsPeriodDateFormat = DateFormatter() static private let RetrievedTransactionsPeriodDateFormat = DateFormatter()
@ -20,6 +22,8 @@ struct AccountTransactionsDialog: View {
@State private var showFetchAllTransactionsView: Bool = false @State private var showFetchAllTransactionsView: Bool = false
@State private var showFetchAllTransactionsViewAtTop: Bool = true
@State private var accountsForWhichNotAllTransactionsHaveBeenFetched: [IBankAccount] = [] @State private var accountsForWhichNotAllTransactionsHaveBeenFetched: [IBankAccount] = []
@ -90,17 +94,18 @@ struct AccountTransactionsDialog: View {
} }
} }
if showFetchAllTransactionsView { if showFetchAllTransactionsView && showFetchAllTransactionsViewAtTop {
SectionWithoutBackground {
HStack(alignment: .center) { HStack(alignment: .center) {
Spacer()
fetchAllTransactionsButton 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 { if showTransactionsList {
@ -109,6 +114,18 @@ struct AccountTransactionsDialog: View {
AccountTransactionListItem(transaction, self.showBankIcons) AccountTransactionListItem(transaction, self.showBankIcons)
} }
} }
if showFetchAllTransactionsView && showFetchAllTransactionsViewAtTop == false {
SectionWithoutBackground {
HStack {
Spacer()
fetchAllTransactionsButton
Spacer()
}
}
}
} }
else { else {
VStack(alignment: .center) { VStack(alignment: .center) {
@ -146,7 +163,8 @@ struct AccountTransactionsDialog: View {
let haveTransactionsForSelectedAccountsBeenRetrieved = transactionsRetrievalState == .retrievedtransactions let haveTransactionsForSelectedAccountsBeenRetrieved = transactionsRetrievalState == .retrievedtransactions
self.accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched self.accountsForWhichNotAllTransactionsHaveBeenFetched = presenter.selectedAccountsForWhichNotAllTransactionsHaveBeenFetched
self.showFetchAllTransactionsView = shouldShowFetchAllTransactionsView && haveTransactionsForSelectedAccountsBeenRetrieved self.showFetchAllTransactionsView = accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty && haveTransactionsForSelectedAccountsBeenRetrieved
//self.showFetchAllTransactionsViewAtTop = true // TODO: read from database
self.showTransactionsList = haveTransactionsForSelectedAccountsBeenRetrieved self.showTransactionsList = haveTransactionsForSelectedAccountsBeenRetrieved
@ -155,11 +173,31 @@ struct AccountTransactionsDialog: View {
self.showFetchTransactionsButton = transactionsRetrievalState != .accountdoesnotsupportfetchingtransactions && transactionsRetrievalState != .accounttypenotsupported 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 { private var fetchAllTransactionsButton: some View {
Button("Fetch all account transactions") { Button(action: { self.fetchAllTransactions() } ) {
self.fetchAllTransactions(self.accountsForWhichNotAllTransactionsHaveBeenFetched) 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]) { private func fetchAllTransactions() {
accounts.forEach { account in accountsForWhichNotAllTransactionsHaveBeenFetched.forEach { account in
presenter.fetchAllAccountTransactionsAsync(account: account, callback: self.handleGetTransactionsResult) presenter.fetchAllAccountTransactionsAsync(account: account, callback: self.handleGetTransactionsResult)
} }
} }
@ -244,10 +282,6 @@ struct AccountTransactionsDialog: View {
return response.retrievedData.first { $0.successfullyRetrievedData == false }?.account return response.retrievedData.first { $0.successfullyRetrievedData == false }?.account
} }
private var shouldShowFetchAllTransactionsView: Bool {
return accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty
}
} }