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
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ class AnalyticsTracker constructor(
map["user_email"] = user.email.toString()

if (user.local_user_attr?.tags != null)
map["user_tags"] = user.local_user_attr.tags.toString()
map["user_tags"] = user.local_user_attr!!.tags.toString()

if (user.local_user_attr?.year != null)
map["user_year"] = user.local_user_attr.year.toString()
map["user_year"] = user.local_user_attr!!.year.toString()

if (user.local_user_attr?.college != null)
map["user_college"] = user.local_user_attr.college.toString()
map["user_college"] = user.local_user_attr!!.college.toString()

if (user.local_user_attr?.department != null)
map["user_department"] = user.local_user_attr.department.toString()
map["user_department"] = user.local_user_attr!!.department.toString()

return map
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.doubtless.doubtless.screens.auth.usecases.UserDataServerUseCase
import com.doubtless.doubtless.screens.auth.usecases.UserDataStorageUseCase
import com.doubtless.doubtless.screens.auth.usecases.UserManager
import com.doubtless.doubtless.screens.dashboard.usecases.DeleteAccountUseCase
import com.doubtless.doubtless.screens.dashboard.usecases.FetchUserDataUseCase
import com.doubtless.doubtless.screens.dashboard.usecases.FetchUserProfileFeedUseCase
import com.doubtless.doubtless.screens.dashboard.usecases.FetchUserFeedByDateUseCase
import com.doubtless.doubtless.screens.doubt.DoubtData
import com.doubtless.doubtless.screens.doubt.usecases.*
Expand Down Expand Up @@ -353,8 +353,8 @@ class AppCompositionRoot(appContext: DoubtlessApp) {
}

// --------- Dashboard -----------
fun getFetchUserDataUseCase(): FetchUserDataUseCase {
return FetchUserDataUseCase(
fun getFetchUserProfileFeedUseCase(): FetchUserProfileFeedUseCase {
return FetchUserProfileFeedUseCase(
FetchUserFeedByDateUseCase(FirebaseFirestore.getInstance()),
FirebaseFirestore.getInstance()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.fragment.app.FragmentManager
import com.doubtless.doubtless.R
import com.doubtless.doubtless.screens.answers.AnswersFragment
import com.doubtless.doubtless.screens.doubt.DoubtData
import com.doubtless.doubtless.screens.profile.OtherUsersProfileFragment
import com.doubtless.doubtless.screens.search.SearchFragment

class FragNavigator constructor(
Expand Down Expand Up @@ -44,4 +45,18 @@ class FragNavigator constructor(
.commitAllowingStateLoss()
}

fun moveToOtherUsersProfileFragment(userId: String) {
supportFragmentManager.beginTransaction()
.setCustomAnimations(
/* enter = */ R.anim.slide_in_right,
/* exit = */ R.anim.slide_out_left,
/* popEnter = */ R.anim.slide_in_left,
/* popExit = */ R.anim.slide_out_right
)
.replace(containerId, OtherUsersProfileFragment.getInstance(userId))
.addToBackStack(null)
.setReorderingAllowed(true)
.commitAllowingStateLoss()
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.doubtless.doubtless.screens.answers

import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.doubtless.doubtless.DoubtlessApp
import com.doubtless.doubtless.R
import com.doubtless.doubtless.screens.answers.viewholder.AnswerViewHolder
import com.doubtless.doubtless.screens.answers.viewholder.EnterAnswerViewHolder
import com.doubtless.doubtless.screens.auth.User
import com.doubtless.doubtless.screens.doubt.DoubtData
import com.doubtless.doubtless.screens.doubt.usecases.VotingUseCase
import com.doubtless.doubtless.screens.doubt.view.viewholder.DoubtPreviewViewHolder

class AnswerDoubtsAdapter(
Expand All @@ -23,6 +18,7 @@ class AnswerDoubtsAdapter(
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

interface InteractionListener {
fun onUserImageClicked(userId: String)
fun onLayoutClicked()
fun onDoubtClicked(doubtData: DoubtData, position: Int)
fun onAnswerClicked(answerData: AnswerData, position: Int)
Expand All @@ -40,6 +36,12 @@ class AnswerDoubtsAdapter(
override fun onDoubtClicked(doubtData: DoubtData, position: Int) {
interactionListener.onDoubtClicked(doubtData, position)
}

override fun onUserImageClicked(userId: String) {
interactionListener.onUserImageClicked(userId)

}

}, showVotingLayout = true
)
}
Expand All @@ -58,6 +60,10 @@ class AnswerDoubtsAdapter(
AnswerDoubtEntity.TYPE_ANSWER -> {
val view = inflater.inflate(R.layout.answer_layout, parent, false)
return AnswerViewHolder(view, object : AnswerViewHolder.InteractionListener {
override fun onUserImageClicked(userId: String) {
interactionListener.onUserImageClicked(userId)
}

override fun onAnswerClicked(answerData: AnswerData, position: Int) {
interactionListener.onAnswerClicked(answerData, position)
}
Expand All @@ -75,7 +81,10 @@ class AnswerDoubtsAdapter(
holder.setData(doubtAnswerEntities[position].doubt!!)

if (holder is AnswerViewHolder)
holder.setData(doubtAnswerEntities[position].answer!!, doubtAnswerEntities[position].answerVotingUseCase!!)
holder.setData(
doubtAnswerEntities[position].answer!!,
doubtAnswerEntities[position].answerVotingUseCase!!
)

if (holder is EnterAnswerViewHolder)
holder.setData(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ class AnswersFragment : Fragment() {
.getDashboardFragNavigator(requireActivity() as MainActivity)
}

if (_navigator != null)
navigator = _navigator
if (currentSelectedFrag is MainFragment.CurrentSelectedBottomNavFrag.InAppNotificationFrag) {
_navigator = DoubtlessApp.getInstance().getAppCompRoot()
.getInAppFragNavigator(requireActivity() as MainActivity)
}

if (_navigator != null) navigator = _navigator

val _doubtData = arguments?.getParcelable("doubt_data") as DoubtData?

Expand All @@ -89,14 +93,21 @@ class AnswersFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)



if (!::adapter.isInitialized) {
adapter = AnswerDoubtsAdapter(
user = userManager.getCachedUserData()!!,
adapter = AnswerDoubtsAdapter(user = userManager.getCachedUserData()!!,
doubtAnswerEntities = mutableListOf(),
onLastItemReached = {
/* no-op */
},
interactionListener = object : AnswerDoubtsAdapter.InteractionListener {
override fun onUserImageClicked(userId: String) {
if (userId != userManager.getCachedUserData()!!.id) navigator.moveToOtherUsersProfileFragment(
userId
)
}

override fun onLayoutClicked() {

}
Expand Down Expand Up @@ -124,8 +135,7 @@ class AnswersFragment : Fragment() {
)
}

}
)
})
}

binding.answerRecyclerView.adapter = adapter
Expand Down Expand Up @@ -185,8 +195,7 @@ class AnswersFragment : Fragment() {

private fun getViewModel(doubtData: DoubtData): AnswersViewModel {
return ViewModelProvider(
owner = this,
factory = AnswersViewModel.Companion.Factory(
owner = this, factory = AnswersViewModel.Companion.Factory(
userManager = userManager,
fetchAnswerUseCase = DoubtlessApp.getInstance().getAppCompRoot()
.getFetchAnswerUseCase(doubtData.id!!),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AnswerViewHolder(itemView: View, private val interactionListener: Interact
RecyclerView.ViewHolder(itemView) {

interface InteractionListener {
fun onUserImageClicked(userId: String)
fun onAnswerClicked(answerData: AnswerData, position: Int)
}

Expand Down Expand Up @@ -57,6 +58,10 @@ class AnswerViewHolder(itemView: View, private val interactionListener: Interact
interactionListener.onAnswerClicked(answerData, adapterPosition)
}

ivDp.setOnClickListener {
interactionListener.onUserImageClicked(answerData.authorId!!)
}

authorName.text = answerData.authorName

try {
Expand Down
33 changes: 29 additions & 4 deletions app/src/main/java/com/doubtless/doubtless/screens/auth/User.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.doubtless.doubtless.screens.auth

import android.os.Parcelable
import androidx.annotation.Keep
import com.google.firebase.firestore.DocumentSnapshot
import com.google.firebase.firestore.Exclude
import com.google.firebase.firestore.IgnoreExtraProperties
import com.google.firebase.firestore.PropertyName
import com.google.gson.annotations.SerializedName
import kotlinx.android.parcel.Parcelize

@IgnoreExtraProperties
@Keep
@Parcelize
data class User(
@SerializedName("id")
@get:PropertyName("id")
Expand All @@ -32,17 +36,38 @@ data class User(
@SerializedName("xpCount")
@get:PropertyName("xpCount")
@set:PropertyName("xpCount")
var xpCount: Long = 0,
var xpCount: Long? = 0,
@get:Exclude val document_id: String? = null,
@get:Exclude val local_user_attr: UserAttributes? = null
)
@get:Exclude var local_user_attr: UserAttributes? = null
) : Parcelable {
companion object {
fun parse(documentSnapshot: DocumentSnapshot?): User? {
return try {
documentSnapshot!!.toObject(User::class.java)
} catch (e: Exception) {
null
}
}
}
}

@Keep
@Parcelize
data class UserAttributes(
val tags: List<String>? = null,
val hobbies: List<String>? = null,
val year: String? = null,
val department: String? = null,
val college: String? = null,
val purpose: String? = null
)
) : Parcelable {
companion object {
fun parse(documentSnapshot: DocumentSnapshot?): UserAttributes? {
return try {
documentSnapshot!!.toObject(UserAttributes::class.java)
} catch (e: Exception) {
null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doubtless.doubtless.DoubtlessApp
import com.doubtless.doubtless.R
import com.doubtless.doubtless.screens.auth.User
import com.doubtless.doubtless.screens.dashboard.viewholder.UserProfileViewHolder
import com.doubtless.doubtless.screens.doubt.DoubtData
import com.doubtless.doubtless.screens.doubt.view.viewholder.DoubtPreviewViewHolder
Expand All @@ -14,10 +15,14 @@ import com.doubtless.doubtless.screens.home.entities.FeedEntity
class GenericFeedAdapter(
private val genericFeedEntities: MutableList<FeedEntity>,
private val onLastItemReached: () -> Unit,
private val interactionListener: InteractionListener
private val interactionListener: InteractionListener,
private val user: User = DoubtlessApp.getInstance().getAppCompRoot().getUserManager()
.getCachedUserData()!!
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

interface InteractionListener {

fun onUserImageClicked(doubtData: String)
fun onDoubtClicked(doubtData: DoubtData, position: Int)
fun onSignOutClicked()
fun onSubmitFeedbackClicked()
Expand All @@ -31,8 +36,10 @@ class GenericFeedAdapter(
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.user_profile_layout, parent, false)
return UserProfileViewHolder(
view,
object : UserProfileViewHolder.InteractionListener {
view = view,
otherUser = user.id != DoubtlessApp.getInstance().getAppCompRoot()
.getUserManager().getCachedUserData()!!.id,
interactionListener = object : UserProfileViewHolder.InteractionListener {
override fun onDeleteAccountClicked() =
interactionListener.onDeleteAccountClicked()

Expand All @@ -51,6 +58,10 @@ class GenericFeedAdapter(
override fun onDoubtClicked(doubtData: DoubtData, position: Int) {
interactionListener.onDoubtClicked(doubtData, position)
}

override fun onUserImageClicked(userId: String) {
interactionListener.onUserImageClicked(userId)
}
})
}

Expand All @@ -63,6 +74,10 @@ class GenericFeedAdapter(
override fun onDoubtClicked(doubtData: DoubtData, position: Int) {
interactionListener.onDoubtClicked(doubtData, position)
}

override fun onUserImageClicked(userId: String) {
interactionListener.onUserImageClicked(userId)
}
})
}
}
Expand All @@ -72,7 +87,7 @@ class GenericFeedAdapter(

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is UserProfileViewHolder) holder.setData(
userManager = DoubtlessApp.getInstance().getAppCompRoot().getUserManager()
user = user
)

if (holder is DoubtPreviewViewHolder && getItemViewType(position) == FeedEntity.TYPE_DOUBT) holder.setData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class DashboardFragment : Fragment() {
adapter = GenericFeedAdapter(genericFeedEntities = feedList, onLastItemReached = {
viewModel.fetchDoubts()
}, interactionListener = object : GenericFeedAdapter.InteractionListener {
override fun onUserImageClicked(userId: String) {
}


override fun onDoubtClicked(doubtData: DoubtData, position: Int) {
Expand All @@ -109,8 +111,8 @@ class DashboardFragment : Fragment() {
})
}

binding.doubtsRecyclerView.adapter = adapter
binding.doubtsRecyclerView.layoutManager = LinearLayoutManager(context)
binding.profileRecyclerView.adapter = adapter
binding.profileRecyclerView.layoutManager = LinearLayoutManager(context)

viewModel.fetchedHomeEntities.observe(viewLifecycleOwner) {
if (it == null) return@observe
Expand Down Expand Up @@ -166,8 +168,8 @@ class DashboardFragment : Fragment() {
owner = this, factory = DashboardViewModel.Companion.Factory(
deleteAccountUseCase = DoubtlessApp.getInstance().getAppCompRoot()
.getDeleteAccountUseCase(),
fetchUserDataUseCase = DoubtlessApp.getInstance().getAppCompRoot()
.getFetchUserDataUseCase(),
fetchUserProfileFeedUseCase = DoubtlessApp.getInstance().getAppCompRoot()
.getFetchUserProfileFeedUseCase(),
analyticsTracker = tracker,
userManager = userManager
)
Expand Down
Loading