diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt index f6103edc..52b91765 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt @@ -2,10 +2,16 @@ package net.dankito.banking.fints4java.android import android.os.Bundle import android.support.design.widget.NavigationView +import android.support.v4.view.GravityCompat import android.support.v4.widget.DrawerLayout +import android.support.v7.app.ActionBarDrawerToggle import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar import android.view.Menu +import android.view.MenuItem +import android.view.MotionEvent +import android.view.SubMenu +import android.widget.TextView import androidx.navigation.findNavController import com.github.clans.fab.FloatingActionMenu import kotlinx.android.synthetic.main.action_view_account_menu_item.view.* @@ -14,12 +20,20 @@ import net.dankito.banking.fints4java.android.util.Base64ServiceAndroid import net.dankito.banking.fints4javaBankingClientCreator import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.presenter.MainWindowPresenter +import org.slf4j.LoggerFactory class MainActivity : AppCompatActivity() { + companion object { + private val log = LoggerFactory.getLogger(MainActivity::class.java) + } + + // private lateinit var appBarConfiguration: AppBarConfiguration + private lateinit var drawerToggle: ActionBarDrawerToggle + private lateinit var floatingActionMenuButton: MainActivityFloatingActionMenuButton @@ -39,7 +53,7 @@ class MainActivity : AppCompatActivity() { setSupportActionBar(toolbar) val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout) - val navView: NavigationView = findViewById(R.id.nav_view) + val navigationView: NavigationView = findViewById(R.id.nav_view) val navController = findNavController(R.id.nav_host_fragment) // // Passing each menu ID as a set of Ids because each @@ -54,6 +68,13 @@ class MainActivity : AppCompatActivity() { // setupActionBarWithNavController(navController, appBarConfiguration) // navigationView.setupWithNavController(navController) + drawerToggle = ActionBarDrawerToggle( + this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) + drawerLayout.addDrawerListener(drawerToggle) + drawerToggle.syncState() + + setupNavigationView(navigationView, drawerLayout) + val floatingActionMenu = findViewById(R.id.floatingActionMenu) floatingActionMenuButton = MainActivityFloatingActionMenuButton(floatingActionMenu, presenter) } @@ -64,6 +85,84 @@ class MainActivity : AppCompatActivity() { return true } + + private fun setupNavigationView(navigationView: NavigationView, drawerLayout: DrawerLayout) { + showAppVersion(navigationView) + + val navigationMenu = navigationView.menu + val accountsMenuItem = navigationMenu.findItem(R.id.navBankAccountsSectionItem) + val accountsMenu = accountsMenuItem.subMenu + + presenter.addAccountsChangedListener { + runOnUiThread { updateNavigationMenuItems(accountsMenu) } + } + + updateNavigationMenuItems(accountsMenu) + + navigationView.setNavigationItemSelectedListener { navigationItemSelected(it) } + } + + private fun updateNavigationMenuItems(accountsMenu: SubMenu) { + accountsMenu.findItem(R.id.navAllBankAccounts).isVisible = presenter.accounts.isNotEmpty() + + // removes previously shown accounts; index 0 = 'Add account', 1 = 'All accounts', don't remove these + for (index in (accountsMenu.size() - 1) downTo 2) { + accountsMenu.removeItem(accountsMenu.getItem(index).itemId) + } + + presenter.accounts.forEach { account -> + val accountMenuItem = accountsMenu.add("") + + accountMenuItem.setActionView(R.layout.action_view_account_menu_item) + accountMenuItem.actionView.txtvwAccountName.text = account.displayName + accountMenuItem.actionView.imgvwEditAccount.setImageResource(R.drawable.ic_build_white_48dp) + accountMenuItem.actionView.imgvwEditAccount.setOnClickListener { editAccount(account) } + + accountMenuItem.setOnMenuItemClickListener { setSelectedAccount(account) } + } + } + + private fun setSelectedAccount(account: Account): Boolean { + presenter.selectedAccount(account) + + closeDrawer() + + return true + } + + private fun editAccount(account: Account) { + // TODO: implement + log.info("Edit account $account") + + closeDrawer() + } + + private fun showAppVersion(navigationView: NavigationView) { + try { + val packageInfo = this.packageManager.getPackageInfo(packageName, 0) + val version = packageInfo.versionName + (navigationView.getHeaderView(0).findViewById(R.id.txtAppVersion) as? TextView)?.text = version + } catch (e: Exception) { + log.error("Could not read application version") + } + } + + private fun navigationItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.navAddBankAccount -> presenter.showAddAccountDialog() + R.id.navAllBankAccounts -> presenter.selectedAllBankAccounts() + } + + closeDrawer() + + return true + } + + private fun closeDrawer() { + val drawer = findViewById(R.id.drawer_layout) as DrawerLayout + drawer.closeDrawer(GravityCompat.START) + } + // override fun onSupportNavigateUp(): Boolean { // val navController = findNavController(R.id.nav_host_fragment) // return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() @@ -86,13 +185,4 @@ class MainActivity : AppCompatActivity() { super.onBackPressed() } - - private fun getTanFromUserOffUiThread(account: Account, tanChallenge: TanChallenge): EnterTanResult { - return router.getTanFromUserOffUiThread(account, tanChallenge) - } - - private fun getAtcFromUserOffUiThread(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult { - return router.getAtcFromUserOffUiThread(tanMedium) - } - } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt index 4b35df7f..9110e636 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt @@ -15,7 +15,9 @@ import android.widget.EditText import net.dankito.banking.fints4java.android.MainActivity import net.dankito.banking.fints4java.android.R import net.dankito.banking.fints4java.android.ui.adapter.AccountTransactionAdapter +import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.AccountTransaction +import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.presenter.MainWindowPresenter @@ -35,6 +37,8 @@ class HomeFragment : Fragment() { private val transactionAdapter = AccountTransactionAdapter() + protected var appliedTransactionsFilter = "" + private lateinit var presenter: MainWindowPresenter @@ -127,6 +131,10 @@ class HomeFragment : Fragment() { (context as? MainActivity)?.presenter?.let { presenter -> this.presenter = presenter + presenter.addAccountsChangedListener { handleAccountsChanged(it) } + + presenter.addSelectedBankAccountsChangedListener { handleSelectedBankAccountsChanged(it) } + presenter.addRetrievedAccountTransactionsResponseListener { _, response -> handleGetTransactionsResponse(response) } @@ -134,6 +142,23 @@ class HomeFragment : Fragment() { } + private fun handleAccountsChanged(accounts: List) { + context?.asActivity()?.let { activity -> + activity.runOnUiThread { + mnitmSearchTransactions.isVisible = accounts.isNotEmpty() + mnitmUpdateTransactions.isVisible = accounts.isNotEmpty() + } + } + } + + private fun handleSelectedBankAccountsChanged(selectedBankAccounts: List) { + context?.asActivity()?.let { activity -> + activity.runOnUiThread { + updateTransactionsToDisplay() + } + } + } + private fun updateAccountsTransactions() { presenter.updateAccountsTransactionsAsync { } } @@ -142,15 +167,9 @@ class HomeFragment : Fragment() { context?.asActivity()?.let { activity -> activity.runOnUiThread { if (response.isSuccessful) { - val allTransactions = presenter.allTransactions - transactionAdapter.items = allTransactions - - mnitmSearchTransactions.isVisible = allTransactions.isNotEmpty() - mnitmUpdateTransactions.isVisible = allTransactions.isNotEmpty() - - mnitmBalance.title = presenter.balanceOfAllAccounts.toString() - mnitmBalance.isVisible = true - } else { + updateTransactionsToDisplay() + } + else { AlertDialog.Builder(activity) // TODO: may show account name in message .setMessage(activity.getString(R.string.fragment_home_could_not_retrieve_account_transactions, response.errorToShowToUser)) .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } @@ -178,7 +197,9 @@ class HomeFragment : Fragment() { private val searchAccountTransactionsTextListener: SearchView.OnQueryTextListener = object : SearchView.OnQueryTextListener { override fun onQueryTextChange(query: String): Boolean { - searchAccountTransactions(query) + appliedTransactionsFilter = query + + updateTransactionsToDisplay() return true } @@ -187,8 +208,13 @@ class HomeFragment : Fragment() { } } - private fun searchAccountTransactions(query: String) { - transactionAdapter.items = presenter.searchAccountTransactions(query) + + private fun updateTransactionsToDisplay() { + transactionAdapter.items = presenter.searchSelectedAccountTransactions(appliedTransactionsFilter) + + // TODO: if transactions are filtered calculate and show balance of displayed transactions? + mnitmBalance.title = presenter.balanceOfSelectedBankAccounts.toString() + mnitmBalance.isVisible = true } } \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_build_white_48dp.png new file mode 100755 index 00000000..ae11b916 Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_build_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_settings_applications_white_48dp.png new file mode 100755 index 00000000..8c04514d Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-hdpi/ic_settings_applications_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_build_white_48dp.png new file mode 100755 index 00000000..db384dee Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_build_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_settings_applications_white_48dp.png new file mode 100755 index 00000000..f4e3df5c Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-mdpi/ic_settings_applications_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_build_white_48dp.png new file mode 100755 index 00000000..874a0eb6 Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_build_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_settings_applications_white_48dp.png new file mode 100755 index 00000000..b3cc107a Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-xhdpi/ic_settings_applications_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_build_white_48dp.png new file mode 100755 index 00000000..d63a3b23 Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_build_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_settings_applications_white_48dp.png new file mode 100755 index 00000000..d003ced7 Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-xxhdpi/ic_settings_applications_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_build_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_build_white_48dp.png new file mode 100755 index 00000000..e23861fb Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_build_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_settings_applications_white_48dp.png b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_settings_applications_white_48dp.png new file mode 100755 index 00000000..c99e6a07 Binary files /dev/null and b/fints4javaAndroidApp/src/main/res/drawable-xxxhdpi/ic_settings_applications_white_48dp.png differ diff --git a/fints4javaAndroidApp/src/main/res/layout/action_view_account_menu_item.xml b/fints4javaAndroidApp/src/main/res/layout/action_view_account_menu_item.xml new file mode 100644 index 00000000..7ea8d692 --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/layout/action_view_account_menu_item.xml @@ -0,0 +1,32 @@ + + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/layout/activity_main.xml b/fints4javaAndroidApp/src/main/res/layout/activity_main.xml index f4df16d8..bc641837 100644 --- a/fints4javaAndroidApp/src/main/res/layout/activity_main.xml +++ b/fints4javaAndroidApp/src/main/res/layout/activity_main.xml @@ -20,6 +20,9 @@ android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_main" - app:menu="@menu/activity_main_drawer" /> + app:menu="@menu/activity_main_drawer" + android:theme="@style/AppTheme.NavigationView" + android:background="@color/backgroundColor_Dark" + /> diff --git a/fints4javaAndroidApp/src/main/res/layout/nav_header_main.xml b/fints4javaAndroidApp/src/main/res/layout/nav_header_main.xml index b697ad54..c3e1a028 100644 --- a/fints4javaAndroidApp/src/main/res/layout/nav_header_main.xml +++ b/fints4javaAndroidApp/src/main/res/layout/nav_header_main.xml @@ -27,10 +27,23 @@ android:text="@string/nav_header_title" android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> - + + + + + + + diff --git a/fints4javaAndroidApp/src/main/res/menu/activity_main_drawer.xml b/fints4javaAndroidApp/src/main/res/menu/activity_main_drawer.xml index d761f80d..ceaa8c09 100644 --- a/fints4javaAndroidApp/src/main/res/menu/activity_main_drawer.xml +++ b/fints4javaAndroidApp/src/main/res/menu/activity_main_drawer.xml @@ -1,6 +1,32 @@ + xmlns:tools="http://schemas.android.com/tools" + tools:showIn="navigation_view" +> + + + + + + + + + + + + diff --git a/fints4javaAndroidApp/src/main/res/values/dimens.xml b/fints4javaAndroidApp/src/main/res/values/dimens.xml index 47b9addc..63cc85b7 100644 --- a/fints4javaAndroidApp/src/main/res/values/dimens.xml +++ b/fints4javaAndroidApp/src/main/res/values/dimens.xml @@ -4,6 +4,9 @@ 16dp 8dp 176dp + 8dp + 56dp + 24dp 16dp 16dp 42dp diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml index 81665732..04c6f5e7 100644 --- a/fints4javaAndroidApp/src/main/res/values/strings.xml +++ b/fints4javaAndroidApp/src/main/res/values/strings.xml @@ -13,9 +13,12 @@ Open navigation drawer Close navigation drawer - Android Studio - android.studio@android.com + @string/app_name + Version\u0020 Navigation header + Accounts + Add account + All accounts Account Transfer money diff --git a/fints4javaAndroidApp/src/main/res/values/styles.xml b/fints4javaAndroidApp/src/main/res/values/styles.xml index b0aa1e40..21e5e413 100644 --- a/fints4javaAndroidApp/src/main/res/values/styles.xml +++ b/fints4javaAndroidApp/src/main/res/values/styles.xml @@ -21,6 +21,15 @@ +