diff --git a/build.gradle b/build.gradle index 34ad6129..314fffa6 100644 --- a/build.gradle +++ b/build.gradle @@ -7,10 +7,12 @@ ext { kotlinVersion = '1.3.41' - javaUtilsVersion = '1.0.8' + javaUtilsVersion = '1.0.9' androidUtilsVersion = '1.1.0' + clansFloatingActionButtonVersion = '1.6.4' + javaFxUtilsVersion = '1.0.3' junitVersion = '4.12' diff --git a/fints4javaAndroidApp/build.gradle b/fints4javaAndroidApp/build.gradle index 8efaec66..ccd7581c 100644 --- a/fints4javaAndroidApp/build.gradle +++ b/fints4javaAndroidApp/build.gradle @@ -53,6 +53,8 @@ dependencies { // TODO: try to get rid of this import implementation project(':fints4javaLib') + implementation "com.github.clans:fab:$clansFloatingActionButtonVersion" + api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" api "net.dankito.utils:android-utils:$androidUtilsVersion", { 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 36200ad1..90003b11 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 @@ -1,18 +1,19 @@ package net.dankito.banking.fints4java.android import android.os.Bundle -import android.support.design.widget.FloatingActionButton import android.support.design.widget.NavigationView import android.support.v4.widget.DrawerLayout import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar import android.view.Menu import androidx.navigation.findNavController +import com.github.clans.fab.FloatingActionMenu +import kotlinx.android.synthetic.main.action_view_account_menu_item.view.* import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.banking.fints4java.android.ui.dialogs.AddAccountDialog import net.dankito.banking.fints4java.android.ui.dialogs.EnterAtcDialog import net.dankito.banking.fints4java.android.ui.dialogs.EnterTanDialog -import net.dankito.banking.mapper.fints4javaModelMapper +import net.dankito.banking.fints4java.android.ui.views.MainActivityFloatingActionMenuButton import net.dankito.banking.ui.BankingClientCallback import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult @@ -27,6 +28,9 @@ class MainActivity : AppCompatActivity() { // private lateinit var appBarConfiguration: AppBarConfiguration + private lateinit var floatingActionMenuButton: MainActivityFloatingActionMenuButton + + val presenter = MainWindowPresenter(Base64ServiceAndroid(), object : BankingClientCallback { override fun enterTan(account: Account, tanChallenge: TanChallenge): EnterTanResult { @@ -52,11 +56,6 @@ class MainActivity : AppCompatActivity() { val toolbar: Toolbar = findViewById(R.id.toolbar) setSupportActionBar(toolbar) - val fab: FloatingActionButton = findViewById(R.id.fab) - fab.setOnClickListener { view -> - AddAccountDialog().show(this, presenter) - } - val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout) val navView: NavigationView = findViewById(R.id.nav_view) val navController = findNavController(R.id.nav_host_fragment) @@ -71,11 +70,13 @@ class MainActivity : AppCompatActivity() { // ) // // setupActionBarWithNavController(navController, appBarConfiguration) -// navView.setupWithNavController(navController) +// navigationView.setupWithNavController(navController) + + val floatingActionMenu = findViewById(R.id.floatingActionMenu) + floatingActionMenuButton = MainActivityFloatingActionMenuButton(floatingActionMenu, presenter) } override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.menu_main, menu) return true @@ -86,6 +87,24 @@ class MainActivity : AppCompatActivity() { // return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() // } + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + if(floatingActionMenuButton.handlesTouch(event)) { // close menu when menu is opened and touch is outside floatingActionMenuButton + return true + } + + return super.dispatchTouchEvent(event) + } + + override fun onBackPressed() { + if (floatingActionMenuButton.handlesBackButtonPress()) { // close menu when menu is opened and back button gets pressed + return + } + + super.onBackPressed() + } + + private fun getTanFromUserOffUiThread(account: Account, tanChallenge: TanChallenge): EnterTanResult { val enteredTan = AtomicReference(null) val tanEnteredLatch = CountDownLatch(1) @@ -107,7 +126,6 @@ class MainActivity : AppCompatActivity() { val tanEnteredLatch = CountDownLatch(1) runOnUiThread { - // TODO: don't create a fints4javaModelMapper instance here, let MainWindowPresenter do the job EnterAtcDialog().show(tanMedium, this@MainActivity, false) { enteredResult -> result.set(enteredResult) tanEnteredLatch.countDown() diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/FloatingActionMenuButton.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/FloatingActionMenuButton.kt new file mode 100644 index 00000000..ab9f15a2 --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/FloatingActionMenuButton.kt @@ -0,0 +1,78 @@ +package net.dankito.banking.fints4java.android.ui.views + +import android.os.Bundle +import android.view.MotionEvent +import com.github.clans.fab.FloatingActionMenu +import net.dankito.utils.android.extensions.isTouchInsideView + + +open class FloatingActionMenuButton(protected val floatingActionMenu: FloatingActionMenu) { + + companion object { + private const val IS_OPENED_EXTRA_NAME = "IS_OPENED" + } + + + private var isClosingMenu = false + + + init { + setup() + } + + + protected open fun setup() { + floatingActionMenu.setClosedOnTouchOutside(true) + floatingActionMenu.setOnMenuToggleListener { isClosingMenu = false } + } + + + protected open fun executeAndCloseMenu(action: () -> Unit) { + action() // first execute action and then close menu as when action sets menu items visibility closeMenu() would otherwise overwrite this value + closeMenu() + } + + protected open fun closeMenu() { + isClosingMenu = true // as closing is animated it takes till animation end till floatingActionMenu.isOpened is set to true + floatingActionMenu.close(true) + } + + + open fun handlesBackButtonPress(): Boolean { + if(floatingActionMenu.isOpened) { + closeMenu() + return true + } + + return false + } + + + open fun handlesTouch(event: MotionEvent): Boolean { + if(floatingActionMenu.isOpened) { // if menu is opened and user clicked somewhere else in the view, close menu + if(floatingActionMenu.isTouchInsideView(event) == false) { + closeMenu() + + return true + } + } + + return false + } + + + open fun saveInstanceState(outState: Bundle?) { + outState?.let { + outState.putBoolean(IS_OPENED_EXTRA_NAME, floatingActionMenu.isOpened && isClosingMenu == false) + } + } + + open fun restoreInstanceState(savedInstanceState: Bundle?) { + savedInstanceState?.let { + if(savedInstanceState.getBoolean(IS_OPENED_EXTRA_NAME, false)) { + floatingActionMenu.open(false) + } + } + } + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt new file mode 100644 index 00000000..ba03959b --- /dev/null +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/MainActivityFloatingActionMenuButton.kt @@ -0,0 +1,39 @@ +package net.dankito.banking.fints4java.android.ui.views + +import android.support.v7.app.AppCompatActivity +import com.github.clans.fab.FloatingActionMenu +import kotlinx.android.synthetic.main.view_floating_action_button_main.view.* +import net.dankito.banking.fints4java.android.ui.MainWindowPresenter +import net.dankito.banking.fints4java.android.ui.dialogs.AddAccountDialog +import net.dankito.banking.fints4java.android.ui.dialogs.TransferMoneyDialog + + +open class MainActivityFloatingActionMenuButton(floatingActionMenu: FloatingActionMenu, protected val presenter: MainWindowPresenter) + : FloatingActionMenuButton(floatingActionMenu) { + + init { + setupButtons(floatingActionMenu) + } + + private fun setupButtons(floatingActionMenu: FloatingActionMenu) { + (floatingActionMenu.context as? AppCompatActivity)?.let { activity -> + floatingActionMenu.fabAddAccount.setOnClickListener { + executeAndCloseMenu { AddAccountDialog().show(activity, presenter) } + } + + val fabTransferMoney = floatingActionMenu.fabTransferMoney + fabTransferMoney.isEnabled = false + + floatingActionMenu.setOnMenuToggleListener { + if (floatingActionMenu.isOpened) { + fabTransferMoney.isEnabled = presenter.accounts.isNotEmpty() + } + } + + fabTransferMoney.setOnClickListener { + executeAndCloseMenu { TransferMoneyDialog().show(activity, presenter, null) } + } + } + } + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/anim/jump_from_down.xml b/fints4javaAndroidApp/src/main/res/anim/jump_from_down.xml new file mode 100755 index 00000000..7985e6be --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/anim/jump_from_down.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/anim/jump_to_down.xml b/fints4javaAndroidApp/src/main/res/anim/jump_to_down.xml new file mode 100755 index 00000000..89e3a8d6 --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/anim/jump_to_down.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/drawable/fab_label_background.xml b/fints4javaAndroidApp/src/main/res/drawable/fab_label_background.xml new file mode 100644 index 00000000..deedf52a --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/drawable/fab_label_background.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/layout/app_bar_main.xml b/fints4javaAndroidApp/src/main/res/layout/app_bar_main.xml index 685b0e60..3cdbaa5c 100644 --- a/fints4javaAndroidApp/src/main/res/layout/app_bar_main.xml +++ b/fints4javaAndroidApp/src/main/res/layout/app_bar_main.xml @@ -22,12 +22,15 @@ - + android:layout_marginRight="@dimen/fab_margin" + android:layout_marginEnd="@dimen/fab_margin" + android:layout_marginBottom="@dimen/fab_margin_bottom_without_toolbar" + app:layout_behavior="@string/move_upward_behaviour" + /> \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/layout/view_floating_action_button_main.xml b/fints4javaAndroidApp/src/main/res/layout/view_floating_action_button_main.xml new file mode 100644 index 00000000..aaed848b --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/layout/view_floating_action_button_main.xml @@ -0,0 +1,36 @@ + + + + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/values/attrs.xml b/fints4javaAndroidApp/src/main/res/values/attrs.xml new file mode 100644 index 00000000..76ce3c7d --- /dev/null +++ b/fints4javaAndroidApp/src/main/res/values/attrs.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/values/colors.xml b/fints4javaAndroidApp/src/main/res/values/colors.xml index f792bb38..a0ddb022 100644 --- a/fints4javaAndroidApp/src/main/res/values/colors.xml +++ b/fints4javaAndroidApp/src/main/res/values/colors.xml @@ -1,6 +1,12 @@ + #BABABA + #000000 + + #303030 + #FFFFFF + #00FF00 #FF0000 @@ -9,4 +15,10 @@ #ff669900 #ffcc0000 + + #FFFFFF + + @color/colorAccent + #444 + diff --git a/fints4javaAndroidApp/src/main/res/values/dimens.xml b/fints4javaAndroidApp/src/main/res/values/dimens.xml index 587cf016..47b9addc 100644 --- a/fints4javaAndroidApp/src/main/res/values/dimens.xml +++ b/fints4javaAndroidApp/src/main/res/values/dimens.xml @@ -5,6 +5,8 @@ 8dp 176dp 16dp + 16dp + 42dp 100dp 4dp diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml index d582b541..ca7ada80 100644 --- a/fints4javaAndroidApp/src/main/res/values/strings.xml +++ b/fints4javaAndroidApp/src/main/res/values/strings.xml @@ -17,6 +17,9 @@ android.studio@android.com Navigation header + Account + Transfer money + Home Update transactions diff --git a/fints4javaAndroidApp/src/main/res/values/styles.xml b/fints4javaAndroidApp/src/main/res/values/styles.xml index 545b9c6d..b0aa1e40 100644 --- a/fints4javaAndroidApp/src/main/res/values/styles.xml +++ b/fints4javaAndroidApp/src/main/res/values/styles.xml @@ -6,6 +6,10 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent + + @color/fabTextColor + @color/fabLabelBackgroundColor + @color/fabShadowColor + + +