- Created basic Balances layout with sections to show the account name, a list of Balances and a list of Transactions.
- Created UserAccountViewModel to serve as a bridge between the views and the database, and use it to fetch the current active UserAccount to display it in the BalancesFragment.
This commit is contained in:
parent
c77c62fb87
commit
d42050afa1
12 changed files with 136 additions and 27 deletions
|
@ -11,6 +11,9 @@ interface UserAccountDao {
|
|||
@Insert
|
||||
fun insert(userAccount: UserAccount)
|
||||
|
||||
@Query("SELECT * FROM user_accounts WHERE user_accounts.id = :id")
|
||||
fun getUserAccount(id: String): LiveData<UserAccount>
|
||||
|
||||
@Query("SELECT * FROM user_accounts")
|
||||
fun getAllUserAccounts(): LiveData<List<UserAccount>>
|
||||
}
|
|
@ -3,24 +3,28 @@ package cy.agorise.bitsybitshareswallet.fragments
|
|||
import androidx.lifecycle.ViewModelProviders
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.Nullable
|
||||
import androidx.lifecycle.Observer
|
||||
|
||||
import cy.agorise.bitsybitshareswallet.R
|
||||
import cy.agorise.bitsybitshareswallet.activities.ReceiveTransactionActivity
|
||||
import cy.agorise.bitsybitshareswallet.activities.SendTransactionActivity
|
||||
import cy.agorise.bitsybitshareswallet.models.UserAccount
|
||||
import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository
|
||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||
import cy.agorise.bitsybitshareswallet.viewmodels.BalancesViewModel
|
||||
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
|
||||
import kotlinx.android.synthetic.main.fragment_balances.*
|
||||
|
||||
class BalancesFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = BalancesFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: BalancesViewModel
|
||||
private lateinit var mUserAccountViewModel: UserAccountViewModel
|
||||
private lateinit var mBalancesViewModel: BalancesViewModel
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
|
@ -29,9 +33,21 @@ class BalancesFragment : Fragment() {
|
|||
return inflater.inflate(R.layout.fragment_balances, container, false)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
viewModel = ViewModelProviders.of(this).get(BalancesViewModel::class.java)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java)
|
||||
|
||||
val userId = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "")
|
||||
|
||||
mUserAccountViewModel.getUserAccount(userId!!).observe(this, Observer<UserAccount>{ user ->
|
||||
tvAccountName.text = user.name
|
||||
})
|
||||
|
||||
|
||||
mBalancesViewModel = ViewModelProviders.of(this).get(BalancesViewModel::class.java)
|
||||
// TODO: Use the ViewModel
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,6 @@ import cy.agorise.bitsybitshareswallet.viewmodels.MerchantsViewModel
|
|||
|
||||
class MerchantsFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = MerchantsFragment()
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MerchantsViewModel
|
||||
|
||||
override fun onCreateView(
|
||||
|
@ -25,8 +21,9 @@ class MerchantsFragment : Fragment() {
|
|||
return inflater.inflate(R.layout.fragment_merchants, container, false)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = ViewModelProviders.of(this).get(MerchantsViewModel::class.java)
|
||||
// TODO: Use the ViewModel
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cy.agorise.bitsybitshareswallet.repositories
|
|||
|
||||
import android.app.Application
|
||||
import android.os.AsyncTask
|
||||
import androidx.lifecycle.LiveData
|
||||
import cy.agorise.bitsybitshareswallet.daos.BitsyDatabase
|
||||
import cy.agorise.bitsybitshareswallet.daos.UserAccountDao
|
||||
import cy.agorise.bitsybitshareswallet.models.UserAccount
|
||||
|
@ -19,6 +20,10 @@ class UserAccountRepository internal constructor(application: Application) {
|
|||
insertAsyncTask(mUserAccountDao).execute(userAccount)
|
||||
}
|
||||
|
||||
fun getUserAccount(id: String): LiveData<UserAccount> {
|
||||
return mUserAccountDao.getUserAccount(id)
|
||||
}
|
||||
|
||||
private class insertAsyncTask internal constructor(private val mAsyncTaskDao: UserAccountDao) :
|
||||
AsyncTask<UserAccount, Void, Void>() {
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package cy.agorise.bitsybitshareswallet.viewmodels
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
|
||||
class BalancesViewModel : ViewModel() {
|
||||
// TODO: Implement the ViewModel
|
||||
}
|
||||
|
||||
class BalancesViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cy.agorise.bitsybitshareswallet.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
import cy.agorise.bitsybitshareswallet.models.UserAccount
|
||||
import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository
|
||||
|
||||
class UserAccountViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private var mRepository = UserAccountRepository(application)
|
||||
|
||||
internal fun getUserAccount(id: String): LiveData<UserAccount> {
|
||||
return mRepository.getUserAccount(id)
|
||||
}
|
||||
|
||||
// fun insert(userAccount: UserAccount) {
|
||||
// mRepository.insert(userAccount)
|
||||
// }
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/night_mode"
|
||||
android:textAppearance="@style/TextAppearance.Body1"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
|
||||
android:textColor="?android:textColorPrimary"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,14 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".fragments.MerchantsFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/title_balances"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||
android:orientation="vertical">
|
||||
|
||||
</FrameLayout>
|
||||
<TextView
|
||||
android:id="@+id/tvAccountName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="seventest-5"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Headline6"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
android:text="@string/title_balances"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Subtitle1"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvBalances"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/item_balance"
|
||||
tools:itemCount="3"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
android:text="@string/title_transactions"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Subtitle1"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvTransactions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/item_transaction"
|
||||
tools:itemCount="6"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
9
app/src/main/res/layout/item_balance.xml
Normal file
9
app/src/main/res/layout/item_balance.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
android:id="@+id/tvBalance"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp"
|
||||
tools:text="123.45 BTS"/>
|
14
app/src/main/res/layout/item_transaction.xml
Normal file
14
app/src/main/res/layout/item_transaction.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp"
|
||||
tools:text="Transaction example"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -29,6 +29,9 @@
|
|||
<string name="title_merchants">Merchants</string>
|
||||
<string name="title_send">Send</string>
|
||||
|
||||
<!-- Balances -->
|
||||
<string name="title_transactions">Transactions</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="title_settings">Settings</string>
|
||||
<string name="night_mode">Night mode</string>
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
</style>
|
||||
|
||||
<!-- Text styles -->
|
||||
<style name="TextAppearance.Body1" parent="TextAppearance.MaterialComponents.Body1" />
|
||||
<style name="TextAppearance.Body2" parent="TextAppearance.MaterialComponents.Body2" />
|
||||
<style name="TextAppearance.Bitsy.Headline6" parent="TextAppearance.MaterialComponents.Headline6" />
|
||||
<style name="TextAppearance.Bitsy.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1" />
|
||||
<style name="TextAppearance.Bitsy.Body1" parent="TextAppearance.MaterialComponents.Body1" />
|
||||
<style name="TextAppearance.Bitsy.Body2" parent="TextAppearance.MaterialComponents.Body2" />
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue