-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Add a meal to a new activity #93
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.kcc.kmmhackathon.androidHackathonApp.view | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.kinandcarta.lib.add.meal.view.AddMealFragment | ||
|
||
class AddMealActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
if (savedInstanceState == null) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(android.R.id.content, AddMealFragment.newInstance()) | ||
.commit() | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.kcc.kmmhackathon.androidHackathonApp.view | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.* | ||
import androidx.fragment.app.Fragment | ||
import com.kcc.kmmhackathon.androidHackathonApp.R | ||
import com.kinandcarta.lib.add.meal.view.AddMealFragment | ||
import kotlinx.coroutines.Dispatchers.Main | ||
|
||
class FindMealContainerFragment : Fragment() { | ||
|
||
companion object { | ||
fun newInstance() = FindMealContainerFragment() | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setHasOptionsMenu(true) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
val view = inflater.inflate(R.layout.find_meal_container_fragment, container, false) | ||
val fragment = com.kinandcarta.feature.find.meal.view.MapsFragment() | ||
childFragmentManager.beginTransaction().apply { | ||
add(R.id.child_fragment_container, fragment) | ||
commit() | ||
} | ||
return view | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { | ||
super.onCreateOptionsMenu(menu, inflater) | ||
|
||
inflater.inflate(R.menu.find_meal_container_menu, menu) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're having the adding of a meal within a second tab of the bottom nav rather than this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the iOS side, it was a new modal from the map. |
||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
R.id.add_an_item -> { | ||
val intent = Intent(activity, AddMealActivity::class.java) | ||
startActivity(intent) | ||
true | ||
} | ||
else -> { | ||
super.onOptionsItemSelected(item) | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
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" | ||
android:id="@+id/add_meal_view" | ||
android:label="Test" | ||
tools:context=".view.AddMealActivity"> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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" | ||
android:id="@+id/child_fragment_container" | ||
tools:context=".view.FindMealContainerFragment"> | ||
</FrameLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,10 @@ | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<item | ||
android:id="@+id/mapsFragment" | ||
android:id="@+id/findMealFragment" | ||
android:icon="@drawable/ic_baseline_map_24" | ||
android:title="@string/map_tab_label" /> | ||
|
||
<item | ||
android:id="@+id/addMealFragment" | ||
android:icon="@drawable/ic_baseline_add_24" | ||
android:title="@string/add_meal_tab_label" /> | ||
|
||
<item android:id="@+id/findMealFragment" | ||
android:icon="@drawable/ic_baseline_list_24" | ||
android:title="@string/title_switch_to_list"/> | ||
|
||
<item | ||
android:id="@+id/settingsFragment" | ||
android:icon="@drawable/ic_baseline_settings_24" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to conflict with Fidel's PR with the refactoring of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure that's going to be conflicted. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:yourapp="http://schemas.android.com/apk/res-auto" > | ||
|
||
<item android:id="@+id/add_an_item" | ||
android:title="Add" | ||
android:orderInCategory="100" | ||
yourapp:showAsAction="always" /> | ||
</menu> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again I think this should stay as a tab :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
<string name="hint_password">Enter Password</string> | ||
|
||
//Headers | ||
<string name="add_meal_activity_header">This is the add meal activity screen</string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need it as an Activity? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to have the toolbar yes! |
||
<string name="add_meal_activity_header">Add a meal</string> | ||
<string name="find_meal_activity_header">This is the find meal activity screen</string> | ||
<string name="subheading_main">Add a meal to help out someone in your local community or browse the meals that others have added</string> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,9 +55,11 @@ class DisplayMealsViewModel @ViewModelInject constructor( | |
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION") | ||
fun startUpdatingLocation() { | ||
fusedLocationProviderClient.lastLocation.addOnSuccessListener { | ||
val latLng = LatLng(it.latitude, it.longitude) | ||
updateUserLocation(latLng) | ||
updateMeals(latLng) | ||
if (it != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this null check necessary? Would we get to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was crashing on my side without checking if it's null. |
||
val latLng = LatLng(it.latitude, it.longitude) | ||
updateUserLocation(latLng) | ||
updateMeals(latLng) | ||
} | ||
} | ||
fusedLocationProviderClient.requestLocationUpdates( | ||
createLocationRequest(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused as to why you've created this file - please could you give some more context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this file because I don't think that the find MapsFragment should know when to create a new add meal activity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! But following that logic, the
FindMeal
also shouldn't know about creating new meals and creating a new container just for that seems a bit overkill.I'd add this logic in the Activity holding the Fragments and BottomNavigation, maybe in a FloatingActionButton.
Either way, FAB or action in the Toolbar, the action belongs to the Activity, and then you have 3 independent Fragments to navigate to.