Create a new BalancesFragment and NetWorthFragment which are used in the HomeFragment's second card. The Balances is already working but the NetWorth only shows a 'Coming soon' notice.

This commit is contained in:
Severiano Jaramillo 2018-12-13 20:53:38 -06:00
parent a608ec162a
commit 8d25b92063
8 changed files with 115 additions and 69 deletions

View file

@ -0,0 +1,46 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.adapters.BalancesAdapter
import cy.agorise.bitsybitshareswallet.database.joins.BalanceDetail
import cy.agorise.bitsybitshareswallet.viewmodels.BalanceDetailViewModel
import kotlinx.android.synthetic.main.fragment_balances.*
class BalancesFragment: Fragment() {
private lateinit var mBalanceDetailViewModel: BalanceDetailViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
setHasOptionsMenu(true)
return inflater.inflate(R.layout.fragment_balances, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Configure BalanceDetailViewModel to show the current balances
mBalanceDetailViewModel = ViewModelProviders.of(this).get(BalanceDetailViewModel::class.java)
val balancesAdapter = BalancesAdapter(context!!)
rvBalances.adapter = balancesAdapter
rvBalances.layoutManager = LinearLayoutManager(context!!)
rvBalances.addItemDecoration(DividerItemDecoration(context!!, DividerItemDecoration.VERTICAL))
mBalanceDetailViewModel.getAll().observe(this, Observer<List<BalanceDetail>> { balancesDetails ->
balancesAdapter.replaceAll(balancesDetails)
})
}
}

View file

@ -21,7 +21,6 @@ import kotlinx.android.synthetic.main.item_balance.view.*
class HomeFragment : Fragment() {
private lateinit var mUserAccountViewModel: UserAccountViewModel
// private lateinit var mBalanceDetailViewModel: BalanceDetailViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
@ -45,18 +44,6 @@ class HomeFragment : Fragment() {
tvAccountName.text = user.name
})
// // Configure BalanceDetailViewModel to show the current balances
// mBalanceDetailViewModel = ViewModelProviders.of(this).get(BalanceDetailViewModel::class.java)
//
// val balancesAdapter = BalancesAdapter(context!!)
// rvBalances.adapter = balancesAdapter
// rvBalances.layoutManager = LinearLayoutManager(context!!)
// rvBalances.addItemDecoration(DividerItemDecoration(context!!, DividerItemDecoration.VERTICAL))
//
// mBalanceDetailViewModel.getAll().observe(this, Observer<List<BalanceDetail>> { balancesDetails ->
// balancesAdapter.replaceAll(balancesDetails)
// })
// Navigate to the Receive Transaction Fragment
fabReceiveTransaction.setOnClickListener (
Navigation.createNavigateOnClickListener(R.id.receive_action)
@ -74,6 +61,7 @@ class HomeFragment : Fragment() {
findNavController().navigate(action)
}
// Configure ViewPager with PagerAdapter and TabLayout to display the Balances/NetWorth section
val pagerAdapter = PagerAdapter(fragmentManager!!)
viewPager.adapter = pagerAdapter
tabLayout.setupWithViewPager(viewPager)
@ -87,11 +75,14 @@ class HomeFragment : Fragment() {
override fun getItem(position: Int): Fragment {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(position + 1)
return if (position == 0)
BalancesFragment()
else
NetWorthFragment()
}
override fun getPageTitle(position: Int): CharSequence? {
return listOf(getString(R.string.title_balances), "Net Worth")[position]
return getString(listOf(R.string.title_balances, R.string.title_net_worth)[position])
}
override fun getCount(): Int {
@ -99,40 +90,6 @@ class HomeFragment : Fragment() {
}
}
/**
* A placeholder fragment containing a simple view.
*/
class PlaceholderFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.item_balance, container, false)
val text = "Hello World from section ${arguments?.getInt(ARG_SECTION_NUMBER)}"
rootView.tvBalance.text = text
return rootView
}
companion object {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private const val ARG_SECTION_NUMBER = "section_number"
/**
* Returns a new instance of this fragment for the given section
* number.
*/
fun newInstance(sectionNumber: Int): PlaceholderFragment {
val fragment = PlaceholderFragment()
val args = Bundle()
args.putInt(ARG_SECTION_NUMBER, sectionNumber)
fragment.arguments = args
return fragment
}
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_balances, menu)
}

View file

@ -0,0 +1,20 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import cy.agorise.bitsybitshareswallet.R
class NetWorthFragment: Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
setHasOptionsMenu(true)
return inflater.inflate(R.layout.fragment_net_worth, container, false)
}
}

View file

@ -0,0 +1,20 @@
<?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="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvBalances"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
tools:listitem="@layout/item_balance"
tools:itemCount="3"/>
</LinearLayout>

View file

@ -144,10 +144,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="?attr/themedColorBackgroundFloating"
android:background="?android:colorControlHighlight"
app:tabSelectedTextColor="?android:textColorPrimary"
app:tabIndicatorColor="?android:colorControlHighlight"
app:tabIndicatorColor="?attr/themedColorBackgroundFloating"
app:tabIndicatorHeight="50dp"
app:tabPaddingStart="@dimen/activity_horizontal_margin"
app:tabMode="scrollable" />
<androidx.viewpager.widget.ViewPager
@ -155,23 +156,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginTop="@dimen/spacing_same_topic"-->
<!--android:layout_marginStart="@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="match_parent"-->
<!--android:paddingStart="@dimen/spacing_same_topic"-->
<!--android:paddingEnd="@dimen/spacing_same_topic"-->
<!--tools:listitem="@layout/item_balance"-->
<!--tools:itemCount="3"/>-->
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text__coming_soon"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:layout_centerInParent="true"/>
</RelativeLayout>

View file

@ -5,5 +5,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
tools:text="123.45 BTS"/>

View file

@ -73,5 +73,7 @@
<string name="msg__bugs_or_ideas">Telegram chat: http://t.me/Agorise\nEmail: Agorise@protonmail.ch\nOpen Source:
https://github.com/Agorise
</string>
<string name="text__coming_soon">Coming soon</string>
<string name="title_net_worth">Net Worth</string>
</resources>