mirror of
https://github.com/hmalik144/Farmr.git
synced 2025-12-10 02:25:19 +00:00
- Show dialog on back press broken
This commit is contained in:
@@ -16,6 +16,7 @@ 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.ID
|
||||
import com.appttude.h_mal.farmr.utils.SHIFT_ID
|
||||
import com.appttude.h_mal.farmr.utils.createDialog
|
||||
import com.appttude.h_mal.farmr.utils.displayToast
|
||||
import com.appttude.h_mal.farmr.utils.formatAsCurrencyString
|
||||
@@ -119,13 +120,14 @@ class FragmentAddItem : BaseFragment<SubmissionViewModel>(R.layout.fragment_add_
|
||||
}
|
||||
|
||||
private fun setupViewAfterViewCreated() {
|
||||
val id = arguments?.let { FragmentAddItemArgs.fromBundle(it).shiftId }
|
||||
val id = arguments?.takeIf { it.containsKey(SHIFT_ID) }
|
||||
?.let { FragmentAddItemArgs.fromBundle(it).shiftId }
|
||||
|
||||
wholeView.hide()
|
||||
|
||||
val title = id?.let {
|
||||
// Since we are editing a shift lets load the shift data into the views
|
||||
viewModel.getCurrentShift(arguments!!.getLong(ID))?.run {
|
||||
viewModel.getCurrentShift(id)?.run {
|
||||
mLocationEditText.setText(description)
|
||||
mDateEditText.setText(date)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class FurtherInfoFragment : BaseFragment<InfoViewModel>(R.layout.fragment_futher
|
||||
val id = FurtherInfoFragmentArgs.fromBundle(requireArguments()).shiftId
|
||||
|
||||
editButton.setOnClickListener {
|
||||
val nav = FragmentAddItemDirections.furtherInfoToAddItem(id)
|
||||
val nav = FurtherInfoFragmentDirections.furtherInfoToAddItem(id)
|
||||
navigateTo(nav)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.app.Activity
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
@@ -36,6 +37,19 @@ class MainActivity : BaseActivity() {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
val currentFragment = navHost.parentFragment
|
||||
return if (currentFragment is BackPressedListener) {
|
||||
currentFragment.onBackPressed()
|
||||
} else {
|
||||
if (supportFragmentManager.backStackEntryCount > 1) {
|
||||
navHost.goBack()
|
||||
} else {
|
||||
super.onSupportNavigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
val currentFragment = supportFragmentManager.findFragmentById(R.id.container)
|
||||
if (currentFragment is BackPressedListener) {
|
||||
@@ -48,4 +62,14 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> onBackPressed()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
@@ -76,12 +76,12 @@ class ShiftListAdapter(
|
||||
|
||||
view.setOnClickListener {
|
||||
// Navigate to further info
|
||||
val nav = FurtherInfoFragmentDirections.mainToFurtherInfo(data.id)
|
||||
val nav = FragmentMainDirections.mainToFurtherInfo(data.id)
|
||||
fragment.navigateTo(nav)
|
||||
}
|
||||
editView.setOnClickListener {
|
||||
// Navigate to edit
|
||||
val nav = FragmentAddItemDirections.mainToAddItem(data.id)
|
||||
val nav = FragmentMainDirections.mainToAddItem(data.id)
|
||||
fragment.navigateTo(nav)
|
||||
}
|
||||
view.setOnLongClickListener {
|
||||
|
||||
@@ -22,6 +22,7 @@ class SplashScreen : Activity() {
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
startActivity(i)
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
this.finish()
|
||||
}, SPLASH_TIME_OUT)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ const val LEGACY = "LEGACY_"
|
||||
const val DATE_FORMAT = "yyyy-MM-dd"
|
||||
const val TIME_FORMAT = "hh:mm"
|
||||
const val ID = "ID"
|
||||
const val SHIFT_ID = "shiftId"
|
||||
const val CURRENCY = "£"
|
||||
@@ -41,6 +41,7 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:defaultNavHost="true"
|
||||
android:id="@+id/container"
|
||||
tools:layout="@layout/fragment_main">
|
||||
</androidx.fragment.app.FragmentContainerView>
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
tools:layout="@layout/fragment_add_item" >
|
||||
<argument
|
||||
android:name="shiftId"
|
||||
app:nullable="true"
|
||||
app:argType="long" />
|
||||
</fragment>
|
||||
<fragment
|
||||
|
||||
Reference in New Issue
Block a user