Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ dependencies {
// Feature modules
implementation project(":android:feature:find-meal")
implementation project(':android:feature:add-meal')
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]
}
}
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
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.


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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
}
}
}

}
10 changes: 10 additions & 0 deletions android/app/src/main/res/layout/add_meal_activity.xml
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>
11 changes: 1 addition & 10 deletions android/app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

@kirstybutler kirstybutler Dec 17, 2020

Choose a reason for hiding this comment

The 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 FindMealFragment, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure that's going to be conflicted.

Expand Down
8 changes: 8 additions & 0 deletions android/app/src/main/res/menu/find_meal_container_menu.xml
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I think this should stay as a tab :)

13 changes: 3 additions & 10 deletions android/app/src/main/res/navigation/main_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@

<fragment
android:id="@+id/mapsFragment"
android:name="com.kinandcarta.feature.find.meal.view.MapsFragment"
android:name="com.kcc.kmmhackathon.androidHackathonApp.view.FindMealContainerFragment"
android:label="fragment_maps"
tools:layout="@layout/fragment_maps" />
tools:layout="@layout/find_meal_container_fragment" />
<fragment
android:id="@+id/settingsFragment"
android:name="com.kcc.kmmhackathon.androidHackathonApp.view.SettingsFragment"
android:label="settings_fragment"
tools:layout="@layout/settings_fragment" />
<fragment
android:id="@+id/findMealFragment"
android:name="com.kinandcarta.feature.find.meal.view.FindMealFragment"
android:label="FindMealFragment" />
<fragment
android:id="@+id/addMealFragment"
android:name="com.kinandcarta.lib.add.meal.view.AddMealFragment"
android:label="AddMealFragment" />

</navigation>
2 changes: 1 addition & 1 deletion android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need it as an Activity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this null check necessary? Would we get to startUpdatingLocation if there was no current location?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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(),
Expand Down
Binary file modified shared/swiftpackage/shared-1.0-SNAPSHOT.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.