Skip to content
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
13 changes: 11 additions & 2 deletions .idea/navEditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/src/main/java/com/esp/localjobs/data/models/User.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.esp.localjobs.data.models

import android.os.Parcelable
import com.google.firebase.auth.FirebaseUser
import kotlinx.android.parcel.Parcelize

@Parcelize
data class User(
val uid: String = "",
val displayName: String = "",
val phoneNumber: String = "",
val photoUrl: String = "",
val mail: String = ""
)
) : Parcelable

fun FirebaseUser.toUser() = User(
uid = uid,
Expand Down
52 changes: 50 additions & 2 deletions app/src/main/java/com/esp/localjobs/fragments/JobsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SearchView
import androidx.core.view.forEach
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.RecyclerView
import com.esp.localjobs.R
import com.esp.localjobs.adapters.JobItem
import com.esp.localjobs.data.models.Location
import com.esp.localjobs.data.models.User
import com.esp.localjobs.data.repository.JobsRepository
import com.esp.localjobs.fragments.FiltersFragment.Companion.FILTER_FRAGMENT_TAG
import com.esp.localjobs.fragments.map.LocationPickerFragment
Expand All @@ -30,14 +33,17 @@ import kotlinx.android.synthetic.main.fragment_jobs.view.*
import kotlinx.coroutines.InternalCoroutinesApi

/**
* Fragment used to display a list of jobs
* Fragment used to display a list of jobs. If arguments include an User then the fragment
* shows the user's jobs/proposals
*/
@InternalCoroutinesApi
class JobsFragment : Fragment(), LocationPickerFragment.OnLocationPickedListener {

private val jobsViewModel: JobsViewModel by activityViewModels()
private val filterViewModel: FilterViewModel by activityViewModels()

private val args: JobsFragmentArgs by navArgs()

val adapter = GroupAdapter<ViewHolder>()

override fun onCreateView(
Expand All @@ -56,7 +62,10 @@ class JobsFragment : Fragment(), LocationPickerFragment.OnLocationPickedListener
setupAdapter()

observeChangesInJobList()
observeFilters()

args.user?.let {
setupUserJobsView(it)
} ?: observeFilters()
}

private fun setupUI(view: View) = with(view) {
Expand Down Expand Up @@ -137,6 +146,11 @@ class JobsFragment : Fragment(), LocationPickerFragment.OnLocationPickedListener
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
// hide menu actions if we are showing some user's jobs/proposals
args.user?.let {
menu.forEach { it.isVisible = false }
return
}
inflater.inflate(R.menu.menu_search, menu)
val searchView = menu.findItem(R.id.action_search_item).actionView as SearchView
setupSearchView(searchView)
Expand Down Expand Up @@ -181,6 +195,40 @@ class JobsFragment : Fragment(), LocationPickerFragment.OnLocationPickedListener
}
}

private fun setupUserJobsView(user: User) {
activity?.title = getString(R.string.user_jobs_title, user.displayName)
val fromJobs = filterViewModel.filteringJobs ?: true

val toCheck = if (fromJobs)
R.id.radio_job
else
R.id.radio_proposal

jobs_type_radio_group.check(toCheck)
jobs_type_radio_group.setOnCheckedChangeListener { _, checkedId ->
if (checkedId == R.id.radio_job) {
loadJobs(JobsRepository.JobFilter(
uid = user.uid,
filteringJobs = true
))
} else {
loadJobs(JobsRepository.JobFilter(
uid = user.uid,
filteringJobs = false
))
}
}

fabAdd.visibility = View.GONE
active_filters.visibility = View.GONE
jobs_type_radio_group.visibility = View.VISIBLE

loadJobs(JobsRepository.JobFilter(
uid = user.uid,
filteringJobs = fromJobs
))
}

override fun onLocationPicked(location: Location, distance: Int?) {
Log.d(TAG, "location: $location")
filterViewModel.setLocation(location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.esp.localjobs.R
import com.esp.localjobs.data.models.User
import com.esp.localjobs.data.repository.userFirebaseRepository
import com.esp.localjobs.databinding.FragmentUserProfileBinding
import com.esp.localjobs.viewModels.LoginViewModel
Expand Down Expand Up @@ -60,21 +61,23 @@ class UserProfileFragment : Fragment(), CoroutineScope {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val userId = args.userID

if (userId == null)
setupCurrentUserProfile()
else
setupUserDetails(userId)
args.userID?.let {
setupUserDetails(it)
} ?: setupCurrentUserProfile()
}

private fun setupCurrentUserProfile() {
name.text = getString(R.string.not_logged_in)
logout.visibility = View.GONE
login.visibility = View.VISIBLE
val user = loginViewModel.getCurrentUser()

if (user == null) {
name.text = getString(R.string.not_logged_in)
logout.visibility = View.GONE
login.visibility = View.VISIBLE
} else {
binding.user = user
setupUserJobsButton(user)

loginViewModel.getCurrentUser()?.let {
binding.user = it
logout.visibility = View.VISIBLE
login.visibility = View.GONE
}
Expand All @@ -93,7 +96,19 @@ class UserProfileFragment : Fragment(), CoroutineScope {
if (!isActive)
return@launch

binding.user = user
user?.let {
binding.user = it
setupUserJobsButton(it)
}
}

private fun setupUserJobsButton(user: User) {
user_jobs.visibility = View.VISIBLE
user_jobs.setOnClickListener {
val action =
UserProfileFragmentDirections.actionDestinationUserProfileToDestinationJobs(user)
findNavController().navigate(action)
}
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class FilterViewModel : ViewModel() {
val query: String?
get() = activeFilters.value?.query

val filteringJobs: Boolean?
get() = activeFilters.value?.filteringJobs

init {
val context = LocalJobsApplication.applicationContext()
val filter = retrieveLastUsedFilter(context)
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/res/layout/fragment_jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,36 @@
android:layout_height="50dp"
android:id="@+id/active_filters"/>

<RadioGroup
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:id="@+id/jobs_type_radio_group"
android:checkedButton="@id/radio_job">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_type"/>

<RadioButton
android:id="@+id/radio_job"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_job"
android:tag="@string/type_tag_job"/>

<RadioButton
android:id="@+id/radio_proposal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_proposal"
android:tag="@string/type_tag_proposal"/>
</RadioGroup>


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/job_list"
android:layout_width="match_parent"
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/layout/fragment_user_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
tools:context=".fragments.UserProfileFragment">

<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="40dp"
app:avatar="@{user.photoUrl}"
android:id="@+id/profilePicture"/>
Expand Down Expand Up @@ -57,5 +57,14 @@
android:visibility="gone"
android:text="@string/login"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/user_jobs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margins"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:visibility="gone"
android:text="@string/jobs_and_proposals_button" />

</LinearLayout>
</layout>
12 changes: 12 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
android:name="job"
app:argType="com.esp.localjobs.data.models.Job"/>
</action>
<argument
android:name="user"
app:argType="com.esp.localjobs.data.models.User"
app:nullable="true"
android:defaultValue="@null" />
</fragment>
<fragment
android:id="@+id/destination_add"
Expand Down Expand Up @@ -108,6 +113,13 @@
app:argType="string"
app:nullable="true"
android:defaultValue="@null"/>
<action
android:id="@+id/action_destination_user_profile_to_destination_jobs"
app:destination="@id/destination_jobs"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>

<fragment
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@
<string name="interested_people">Interested people:</string>
<string name="job_author">Author:</string>
<string name="in_the_past">In the past</string>
<string name="user_jobs_title">%1$s\'s stuff</string>
<string name="jobs_and_proposals_button">Jobs and proposals</string>
</resources>