mirror of
https://github.com/hmalik144/Farmr.git
synced 2025-12-10 02:25:19 +00:00
- mid commit
This commit is contained in:
@@ -49,6 +49,9 @@ dependencies {
|
||||
implementation "androidx.lifecycle:lifecycle-livedata-core:$LIFECYCLE_VERSION"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel:$LIFECYCLE_VERSION"
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
/ * Fragment Navigation * /
|
||||
implementation "androidx.navigation:navigation-fragment-ktx:$NAVIGATION_VERSION"
|
||||
implementation "androidx.navigation:navigation-ui-ktx:$NAVIGATION_VERSION"
|
||||
/ * Unit testing * /
|
||||
testImplementation "junit:junit:$JUNIT_VERSION"
|
||||
androidTestRuntimeOnly "org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION"
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.appttude.h_mal.farmr.R
|
||||
import com.appttude.h_mal.farmr.base.BaseFragment
|
||||
import com.appttude.h_mal.farmr.model.ShiftType
|
||||
import com.appttude.h_mal.farmr.model.Success
|
||||
import com.appttude.h_mal.farmr.utils.goBack
|
||||
import com.appttude.h_mal.farmr.utils.setDatePicker
|
||||
import com.appttude.h_mal.farmr.viewmodel.FilterViewModel
|
||||
|
||||
@@ -100,6 +101,6 @@ class FilterDataFragment : BaseFragment<FilterViewModel>(R.layout.fragment_filte
|
||||
|
||||
override fun onSuccess(data: Any?) {
|
||||
super.onSuccess(data)
|
||||
if (data is Success) popBackStack()
|
||||
if (data is Success) goBack()
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.appttude.h_mal.farmr.utils.createDialog
|
||||
import com.appttude.h_mal.farmr.utils.displayToast
|
||||
import com.appttude.h_mal.farmr.utils.formatAsCurrencyString
|
||||
import com.appttude.h_mal.farmr.utils.formatToTwoDpString
|
||||
import com.appttude.h_mal.farmr.utils.goBack
|
||||
import com.appttude.h_mal.farmr.utils.hide
|
||||
import com.appttude.h_mal.farmr.utils.popBackStack
|
||||
import com.appttude.h_mal.farmr.utils.setDatePicker
|
||||
@@ -118,6 +119,8 @@ class FragmentAddItem : BaseFragment<SubmissionViewModel>(R.layout.fragment_add_
|
||||
}
|
||||
|
||||
private fun setupViewAfterViewCreated() {
|
||||
// val id = arguments?.let { FragmentAddItemArgs.fromBundle(it).id)
|
||||
|
||||
id = arguments?.getLong(ID)
|
||||
wholeView.hide()
|
||||
|
||||
@@ -274,7 +277,7 @@ class FragmentAddItem : BaseFragment<SubmissionViewModel>(R.layout.fragment_add_
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
if (mRadioGroup.checkedRadioButtonId == -1) {
|
||||
mActivity?.popBackStack()
|
||||
goBack()
|
||||
} else {
|
||||
requireContext().createDialog(
|
||||
title = "Discard Changes?",
|
||||
@@ -292,7 +295,7 @@ class FragmentAddItem : BaseFragment<SubmissionViewModel>(R.layout.fragment_add_
|
||||
super.onSuccess(data)
|
||||
if (data is Success) {
|
||||
displayToast(data.successMessage)
|
||||
popBackStack()
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import com.appttude.h_mal.farmr.model.Success
|
||||
import com.appttude.h_mal.farmr.utils.createDialog
|
||||
import com.appttude.h_mal.farmr.utils.displayToast
|
||||
import com.appttude.h_mal.farmr.utils.hide
|
||||
import com.appttude.h_mal.farmr.utils.navigateTo
|
||||
import com.appttude.h_mal.farmr.utils.navigateToFragment
|
||||
import com.appttude.h_mal.farmr.utils.show
|
||||
import com.appttude.h_mal.farmr.viewmodel.MainViewModel
|
||||
@@ -57,7 +58,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
})
|
||||
|
||||
view.findViewById<FloatingActionButton>(R.id.fab1).setOnClickListener {
|
||||
navigateToFragment(FragmentAddItem(), name = "additem")
|
||||
navigateTo(R.id.main_to_addItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
}
|
||||
|
||||
R.id.filter_data -> {
|
||||
navigateToFragment(FilterDataFragment(), name = "filterdata")
|
||||
navigateTo(R.id.main_to_filterData)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ class MainActivity : BaseActivity() {
|
||||
currentFragment.onBackPressed()
|
||||
} else {
|
||||
if (supportFragmentManager.backStackEntryCount > 1) {
|
||||
popBackStack()
|
||||
// Todo: go back
|
||||
// goBack()
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ class ShiftListAdapter(
|
||||
bundle = b,
|
||||
name = "furtherinfo"
|
||||
)
|
||||
// val nav = FragmentMainDirections.mainToFurtherInfo(data.id)
|
||||
// fragment.navigateTo(nav)
|
||||
}
|
||||
editView.setOnClickListener {
|
||||
// Navigate to edit
|
||||
@@ -88,6 +90,8 @@ class ShiftListAdapter(
|
||||
bundle = b,
|
||||
name = "additem"
|
||||
)
|
||||
// val nav = FragmentMainDirections.mainToAddItem(data.id)
|
||||
// fragment.navigateTo(nav)
|
||||
}
|
||||
view.setOnLongClickListener {
|
||||
AlertDialog.Builder(it.context)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.appttude.h_mal.farmr.utils
|
||||
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavDirections
|
||||
import androidx.navigation.Navigation
|
||||
import com.appttude.h_mal.farmr.R
|
||||
|
||||
fun Fragment.navigateToFragment(newFragment: Fragment) {
|
||||
childFragmentManager.beginTransaction()
|
||||
.add(R.id.container, newFragment)
|
||||
.commit()
|
||||
}
|
||||
|
||||
|
||||
fun View.navigateTo(navigationId: Int) {
|
||||
Navigation.findNavController(this).navigate(navigationId)
|
||||
}
|
||||
|
||||
fun View.navigateTo(navDirections: NavDirections) {
|
||||
Navigation.findNavController(this).navigate(navDirections)
|
||||
}
|
||||
|
||||
fun Fragment.navigateTo(navigationId: Int) {
|
||||
Navigation.findNavController(requireView()).navigate(navigationId)
|
||||
}
|
||||
|
||||
fun Fragment.navigateTo(navDirections: NavDirections) {
|
||||
Navigation.findNavController(requireView()).navigate(navDirections)
|
||||
}
|
||||
|
||||
fun Fragment.goBack() = Navigation.findNavController(requireView()).popBackStack()
|
||||
50
app/src/main/res/navigation/shift_navigation.xml
Normal file
50
app/src/main/res/navigation/shift_navigation.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation 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/shift_navigation"
|
||||
app:startDestination="@id/fragmentMain">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragmentMain"
|
||||
android:name="com.appttude.h_mal.farmr.ui.FragmentMain"
|
||||
android:label="fragment_main"
|
||||
tools:layout="@layout/fragment_main" >
|
||||
<action
|
||||
android:id="@+id/main_to_addItem"
|
||||
app:destination="@id/fragmentAddItem" />
|
||||
<action
|
||||
android:id="@+id/main_to_filterData"
|
||||
app:destination="@id/filterDataFragment" />
|
||||
<action
|
||||
android:id="@+id/main_to_furtherInfo"
|
||||
app:destination="@id/furtherInfoFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/fragmentAddItem"
|
||||
android:name="com.appttude.h_mal.farmr.ui.FragmentAddItem"
|
||||
android:label="fragment_add_item"
|
||||
tools:layout="@layout/fragment_add_item" >
|
||||
<argument
|
||||
android:name="shiftId"
|
||||
app:nullable="true"
|
||||
app:argType="long" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/filterDataFragment"
|
||||
android:name="com.appttude.h_mal.farmr.ui.FilterDataFragment"
|
||||
android:label="fragment_filter_data"
|
||||
tools:layout="@layout/fragment_filter_data" />
|
||||
<fragment
|
||||
android:id="@+id/furtherInfoFragment"
|
||||
android:name="com.appttude.h_mal.farmr.ui.FurtherInfoFragment"
|
||||
android:label="fragment_futher_info"
|
||||
tools:layout="@layout/fragment_futher_info" >
|
||||
<action
|
||||
android:id="@+id/furtherInfo_to_AddItem"
|
||||
app:destination="@id/fragmentAddItem" />
|
||||
<argument
|
||||
android:name="shiftId"
|
||||
app:argType="long" />
|
||||
</fragment>
|
||||
</navigation>
|
||||
@@ -8,6 +8,7 @@ MATERIAL_VERSION = 1.0.0
|
||||
CONSTR_LAYOUT_VERSION = 1.1.3
|
||||
LIFECYCLE_VERSION = 2.5.1
|
||||
VIEWMODEL_VERSION = 2.4.1
|
||||
NAVIGATION_VERSION = 2.3.2
|
||||
PREFERENCES_VERSION = 1.2.1
|
||||
MOKITO_INLINE_VERSION = 2.13.0
|
||||
CORE_TEST_VERSION = 2.1.0
|
||||
|
||||
Reference in New Issue
Block a user