Add basic Balances, Transactions and Merchants Fragments with their own layout and ViewModel.
This commit is contained in:
parent
aef6a9e3b9
commit
e5bb27da44
13 changed files with 181 additions and 69 deletions
|
@ -28,6 +28,8 @@ dependencies {
|
||||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
implementation 'com.android.support:design:28.0.0'
|
implementation 'com.android.support:design:28.0.0'
|
||||||
|
implementation 'com.android.support:support-v4:28.0.0'
|
||||||
|
implementation 'android.arch.lifecycle:extensions:1.1.1'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
package cy.agorise.bitsybitshareswallet.activities
|
package cy.agorise.bitsybitshareswallet.activities
|
||||||
|
|
||||||
import android.support.design.widget.Snackbar
|
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v4.app.FragmentManager
|
import android.support.v4.app.FragmentManager
|
||||||
import android.support.v4.app.FragmentPagerAdapter
|
import android.support.v4.app.FragmentPagerAdapter
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.fragments.BalancesFragment
|
||||||
|
import cy.agorise.bitsybitshareswallet.fragments.MerchantsFragment
|
||||||
|
import cy.agorise.bitsybitshareswallet.fragments.TransactionsFragment
|
||||||
|
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.android.synthetic.main.fragment_main.view.*
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
@ -74,9 +72,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
inner class SectionsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
|
inner class SectionsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
|
||||||
|
|
||||||
override fun getItem(position: Int): Fragment {
|
override fun getItem(position: Int): Fragment {
|
||||||
// getItem is called to instantiate the fragment for the given page.
|
return when (position) {
|
||||||
// Return a PlaceholderFragment (defined as a static inner class below).
|
0 -> BalancesFragment()
|
||||||
return PlaceholderFragment.newInstance(position + 1)
|
1 -> TransactionsFragment()
|
||||||
|
else -> MerchantsFragment()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCount(): Int {
|
override fun getCount(): Int {
|
||||||
|
@ -87,43 +87,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
override fun getPageTitle(position: Int): CharSequence? {
|
override fun getPageTitle(position: Int): CharSequence? {
|
||||||
return when (position) {
|
return when (position) {
|
||||||
0 -> ""
|
0 -> ""
|
||||||
1 -> "Transactions"
|
1 -> getString(R.string.title_transactions)
|
||||||
else -> "Merchants"
|
else -> getString(R.string.title_merchants)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.fragment_main, container, false)
|
|
||||||
rootView.section_label.text = getString(R.string.section_format, arguments?.getInt(ARG_SECTION_NUMBER))
|
|
||||||
return rootView
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
/**
|
|
||||||
* The fragment argument representing the section number for this
|
|
||||||
* fragment.
|
|
||||||
*/
|
|
||||||
private 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModelProviders
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v4.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
|
||||||
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.viewmodels.BalancesViewModel
|
||||||
|
|
||||||
|
class BalancesFragment : Fragment() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun newInstance() = BalancesFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
private lateinit var viewModel: BalancesViewModel
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
return inflater.inflate(R.layout.balances_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
viewModel = ViewModelProviders.of(this).get(BalancesViewModel::class.java)
|
||||||
|
// TODO: Use the ViewModel
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModelProviders
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v4.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
|
||||||
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.viewmodels.MerchantsViewModel
|
||||||
|
|
||||||
|
class MerchantsFragment : Fragment() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun newInstance() = MerchantsFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
private lateinit var viewModel: MerchantsViewModel
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
return inflater.inflate(R.layout.merchants_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
viewModel = ViewModelProviders.of(this).get(MerchantsViewModel::class.java)
|
||||||
|
// TODO: Use the ViewModel
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModelProviders
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v4.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
|
||||||
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.viewmodels.TransactionsViewModel
|
||||||
|
|
||||||
|
class TransactionsFragment : Fragment() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun newInstance() = TransactionsFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
private lateinit var viewModel: TransactionsViewModel
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
return inflater.inflate(R.layout.transactions_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
viewModel = ViewModelProviders.of(this).get(TransactionsViewModel::class.java)
|
||||||
|
// TODO: Use the ViewModel
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.viewmodels
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModel
|
||||||
|
|
||||||
|
class BalancesViewModel : ViewModel() {
|
||||||
|
// TODO: Implement the ViewModel
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.viewmodels
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
class MerchantsViewModel : ViewModel() {
|
||||||
|
// TODO: Implement the ViewModel
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package cy.agorise.bitsybitshareswallet.viewmodels
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
class TransactionsViewModel : ViewModel() {
|
||||||
|
// TODO: Implement the ViewModel
|
||||||
|
}
|
14
app/src/main/res/layout/balances_fragment.xml
Normal file
14
app/src/main/res/layout/balances_fragment.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
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.BalancesFragment">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="Balances"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -1,22 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<android.support.constraint.ConstraintLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/constraintLayout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".activities.MainActivity$PlaceholderFragment">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/section_label"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
|
||||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
|
||||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
|
||||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"/>
|
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
|
14
app/src/main/res/layout/merchants_fragment.xml
Normal file
14
app/src/main/res/layout/merchants_fragment.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
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="Merchants"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
14
app/src/main/res/layout/transactions_fragment.xml
Normal file
14
app/src/main/res/layout/transactions_fragment.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout
|
||||||
|
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.TransactionsFragment">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="Transactions"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -5,4 +5,6 @@
|
||||||
<string name="tab_text_3">Tab 3</string>
|
<string name="tab_text_3">Tab 3</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="section_format">Hello World from section: %1$d</string>
|
<string name="section_format">Hello World from section: %1$d</string>
|
||||||
|
<string name="title_transactions">Transactions</string>
|
||||||
|
<string name="title_merchants">Merchants</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue