Skip to content

Commit

Permalink
teams: new surveys added (fixes #5029) (#4884)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
Okuro3499 and dogi authored Jan 15, 2025
1 parent e7551f5 commit 029ca40
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2206
versionName "0.22.6"
versionCode 2207
versionName "0.22.7"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import androidx.fragment.app.DialogFragment
abstract class BaseDialogFragment : DialogFragment() {
@JvmField
var id: String? = null
var teamId: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.AppTheme_Dialog_NoActionBar_MinWidth)
if (arguments != null) {
id = requireArguments().getString(key)
teamId = requireArguments().getString("teamId")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ abstract class BaseResourceFragment : Fragment() {
}
AlertDialog.Builder(requireActivity()).setTitle("Pending Surveys")
.setAdapter(arrayAdapter) { _: DialogInterface?, i: Int ->
AdapterMySubmission.openSurvey(homeItemClickListener, list[i].id, true)
AdapterMySubmission.openSurvey(homeItemClickListener, list[i].id, true, false, "")
}.setPositiveButton(R.string.dismiss, null).show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open class RealmStepExam : RealmObject() {
var passingPercentage: String? = null
var noOfQuestions = 0
var isFromNation = false
var teamId: String? = null

companion object {
val examDataList: MutableList<Array<String>> = mutableListOf()
Expand Down Expand Up @@ -66,6 +67,7 @@ open class RealmStepExam : RealmObject() {
myExam?.totalMarks = JsonUtils.getInt("totalMarks", exam)
myExam?.noOfQuestions = JsonUtils.getJsonArray("questions", exam).size()
myExam?.isFromNation = !TextUtils.isEmpty(parentId)
myExam.teamId = JsonUtils.getString("teamId", exam)
val oldQuestions: RealmResults<*>? = mRealm.where(RealmExamQuestion::class.java).equalTo("examId", JsonUtils.getString("_id", exam)).findAll()
if (oldQuestions == null || oldQuestions.isEmpty()) {
RealmExamQuestion.insertExamQuestions(JsonUtils.getJsonArray("questions", exam), JsonUtils.getString("_id", exam), mRealm)
Expand All @@ -84,8 +86,10 @@ open class RealmStepExam : RealmObject() {
JsonUtils.getString("updatedDate", exam),
JsonUtils.getString("totalMarks", exam),
JsonUtils.getString("noOfQuestions", exam),
JsonUtils.getString("isFromNation", exam)
JsonUtils.getString("isFromNation", exam),
JsonUtils.getString("teamId", exam)
)

examDataList.add(csvRow)
}

Expand All @@ -94,7 +98,7 @@ open class RealmStepExam : RealmObject() {
val file = File(filePath)
file.parentFile?.mkdirs()
val writer = CSVWriter(FileWriter(file))
writer.writeNext(arrayOf("_id", "_rev", "name", "passingPercentage", "type", "createdBy", "sourcePlanet", "createdDate", "updatedDate", "totalMarks", "noOfQuestions", "isFromNation"))
writer.writeNext(arrayOf("_id", "_rev", "name", "passingPercentage", "type", "createdBy", "sourcePlanet", "createdDate", "updatedDate", "totalMarks", "noOfQuestions", "isFromNation", "teamId"))
for (row in data) {
writer.writeNext(row)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CourseStepFragment : BaseContainerFragment(), ImageCaptureCallback {

fragmentCourseStepBinding.btnTakeSurvey.setOnClickListener {
if (stepSurvey.isNotEmpty()) {
AdapterMySubmission.openSurvey(homeItemClickListener, stepSurvey[0].id, false)
AdapterMySubmission.openSurvey(homeItemClickListener, stepSurvey[0].id, false, false, "")
}
}
val downloadedResources: List<RealmMyLibrary> = cRealm.where(RealmMyLibrary::class.java).equalTo("stepId", stepId).equalTo("resourceOffline", true).isNotNull("resourceLocalAddress").findAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
v.findViewById<LinearLayout>(R.id.ll_prompt).visibility = View.VISIBLE
v.findViewById<LinearLayout>(R.id.ll_prompt).setOnClickListener {
if (!childFragmentManager.isStateSaved) {
UserInformationFragment.getInstance("").show(childFragmentManager, "")
UserInformationFragment.getInstance("", "").show(childFragmentManager, "")
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class BellDashboardFragment : BaseDashboardFragment() {

val adapter = SurveyAdapter(surveyTitles, { position ->
val selectedSurvey = pendingSurveys[position].id
AdapterMySubmission.openSurvey(homeItemClickListener, selectedSurvey, true)
AdapterMySubmission.openSurvey(homeItemClickListener, selectedSurvey, true, false, "")
}, alertDialog)

recyclerView.adapter = adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class NotificationsFragment : Fragment() {
"survey" -> {
val currentStepExam = mRealm.where(RealmStepExam::class.java).equalTo("name", notification.relatedId)
.findFirst()
if(context is OnHomeItemClickListener) {
AdapterMySubmission.openSurvey(context as OnHomeItemClickListener, currentStepExam?.id, false)
if (context is OnHomeItemClickListener) {
AdapterMySubmission.openSurvey(context as OnHomeItemClickListener, currentStepExam?.id, false, false, "")
}
}
"task" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ abstract class BaseExamFragment : Fragment(), ImageCaptureCallback {
var date = Date().toString()
private var photoPath: String? = ""
var submitId = ""
private var isTeam: Boolean = false
private var teamId: String? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
db = DatabaseService(requireActivity())
Expand All @@ -60,6 +63,8 @@ abstract class BaseExamFragment : Fragment(), ImageCaptureCallback {
stepId = requireArguments().getString("stepId")
stepNumber = requireArguments().getInt("stepNum")
isMySurvey = requireArguments().getBoolean("isMySurvey")
isTeam = requireArguments().getBoolean("isTeam", false)
teamId = requireArguments().getString("teamId")
checkId()
checkType()
}
Expand Down Expand Up @@ -108,6 +113,8 @@ abstract class BaseExamFragment : Fragment(), ImageCaptureCallback {
private fun continueExam() {
if (currentIndex < (questions?.size ?: 0)) {
startExam(questions?.get(currentIndex))
} else if (isTeam == true && type?.startsWith("survey") == true) {
showUserInfoDialog()
} else {
saveCourseProgress()
AlertDialog.Builder(requireActivity(), R.style.AlertDialogTheme)
Expand All @@ -131,7 +138,7 @@ abstract class BaseExamFragment : Fragment(), ImageCaptureCallback {

private fun showUserInfoDialog() {
if (!isMySurvey && !exam?.isFromNation!!) {
UserInformationFragment.getInstance(sub?.id).show(childFragmentManager, "")
UserInformationFragment.getInstance(sub?.id, teamId).show(childFragmentManager, "")
} else {
if (!mRealm.isInTransaction) mRealm.beginTransaction()
sub?.status = "complete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import io.realm.Realm
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.base.BaseDialogFragment
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.databinding.FragmentUserInformationBinding
import org.ole.planet.myplanet.datamanager.DatabaseService
import org.ole.planet.myplanet.model.RealmSubmission
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.team.TeamDetailFragment
import org.ole.planet.myplanet.utilities.Utilities
import java.util.Calendar
import java.util.Locale
Expand All @@ -31,6 +33,7 @@ class UserInformationFragment : BaseDialogFragment(), View.OnClickListener {
lateinit var mRealm: Realm
private var submissions: RealmSubmission? = null
var userModel: RealmUserModel? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
fragmentUserInformationBinding = FragmentUserInformationBinding.inflate(inflater, container, false)
mRealm = DatabaseService(requireActivity()).realmInstance
Expand All @@ -45,16 +48,8 @@ class UserInformationFragment : BaseDialogFragment(), View.OnClickListener {
private fun initViews() {
val langArray = resources.getStringArray(R.array.language).toMutableList()
val levelArray = resources.getStringArray(R.array.level).toMutableList()
val adapterLang = ArrayAdapter(
requireContext(),
R.layout.spinner_item_white,
langArray
)
val adapterLevel = ArrayAdapter(
requireContext(),
R.layout.spinner_item_white,
levelArray
)
val adapterLang = ArrayAdapter(requireContext(), R.layout.spinner_item_white, langArray)
val adapterLevel = ArrayAdapter(requireContext(), R.layout.spinner_item_white, levelArray)
adapterLang.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
adapterLevel.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
fragmentUserInformationBinding.spnLang.adapter = adapterLang
Expand All @@ -67,13 +62,18 @@ class UserInformationFragment : BaseDialogFragment(), View.OnClickListener {
val selectedView = fragmentUserInformationBinding.spnLevel.selectedView as? TextView
selectedView?.setTextColor(ContextCompat.getColor(requireContext(), R.color.daynight_textColor))
}
fragmentUserInformationBinding.etEmail.setText(getString(R.string.message_placeholder, userModel?.email))
fragmentUserInformationBinding.etFname.setText(getString(R.string.message_placeholder, userModel?.firstName))
fragmentUserInformationBinding.etLname.setText(getString(R.string.message_placeholder, userModel?.lastName))
fragmentUserInformationBinding.etPhone.setText(getString(R.string.message_placeholder, userModel?.phoneNumber))
fragmentUserInformationBinding.txtDob.text = getString(R.string.message_placeholder, userModel?.dob)
dob = userModel?.dob
fragmentUserInformationBinding.btnCancel.setOnClickListener(this)
// fragmentUserInformationBinding.etEmail.setText(getString(R.string.message_placeholder, userModel?.email))
// fragmentUserInformationBinding.etFname.setText(getString(R.string.message_placeholder, userModel?.firstName))
// fragmentUserInformationBinding.etLname.setText(getString(R.string.message_placeholder, userModel?.lastName))
// fragmentUserInformationBinding.etPhone.setText(getString(R.string.message_placeholder, userModel?.phoneNumber))
// fragmentUserInformationBinding.txtDob.text = getString(R.string.message_placeholder, userModel?.dob)
// dob = userModel?.dob
if (teamId != null) {
fragmentUserInformationBinding.btnCancel.visibility = View.GONE
} else {
fragmentUserInformationBinding.btnCancel.setOnClickListener(this)
}

fragmentUserInformationBinding.btnSubmit.setOnClickListener(this)
fragmentUserInformationBinding.txtDob.setOnClickListener(this)
}
Expand Down Expand Up @@ -157,7 +157,19 @@ class UserInformationFragment : BaseDialogFragment(), View.OnClickListener {
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
Utilities.toast(activity, getString(R.string.thank_you_for_taking_this_survey))
BaseExamFragment.navigateToSurveyList(requireActivity())
if (teamId == null) {
BaseExamFragment.navigateToSurveyList(requireActivity())
} else {
if (context is OnHomeItemClickListener) {
val f = TeamDetailFragment()
val b = Bundle()
b.putString("id", teamId)
b.putBoolean("isMyTeam", true)
b.putInt("navigateToPage", 6)
f.arguments = b
(context as OnHomeItemClickListener).openCallFragment(f)
}
}
}

private fun showDatePickerDialog() {
Expand All @@ -173,15 +185,16 @@ class UserInformationFragment : BaseDialogFragment(), View.OnClickListener {
get() = "sub_id"

companion object {
fun getInstance(id: String?): UserInformationFragment {
fun getInstance(id: String?, teamId: String?): UserInformationFragment {
val f = UserInformationFragment()
setArgs(f, id)
setArgs(f, id, teamId)
return f
}

private fun setArgs(f: UserInformationFragment, id: String?) {
private fun setArgs(f: UserInformationFragment, id: String?, teamId: String?) {
val b = Bundle()
b.putString("sub_id", id)
b.putString("teamId", teamId)
f.arguments = b
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AdapterMySubmission(private val context: Context, private val list: List<R
rowMySurveyBinding.title.text = examHashMap[list?.get(position)?.parentId]?.name
holder.itemView.setOnClickListener {
if (type == "survey")
openSurvey(listener, list?.get(position)?.id, true)
openSurvey(listener, list?.get(position)?.id, true, false, "")
else
openSubmissionDetail(listener, list?.get(position)?.id)
}
Expand Down Expand Up @@ -98,12 +98,14 @@ class AdapterMySubmission(private val context: Context, private val list: List<R

companion object {
@JvmStatic
fun openSurvey(listener: OnHomeItemClickListener?, id: String?, isMySurvey: Boolean) {
fun openSurvey(listener: OnHomeItemClickListener?, id: String?, isMySurvey: Boolean, isTeam: Boolean, teamId: String?) {
if (listener != null) {
val b = Bundle()
b.putString("type", "survey")
b.putString("id", id)
b.putBoolean("isMySurvey", isMySurvey)
b.putBoolean("isTeam", isTeam)
b.putString("teamId", teamId)
val f: Fragment = TakeExamFragment()
f.arguments = b
listener.openCallFragment(f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@ import org.ole.planet.myplanet.model.RealmExamQuestion
import org.ole.planet.myplanet.model.RealmStepExam
import org.ole.planet.myplanet.model.RealmSubmission.Companion.getNoOfSubmissionByUser
import org.ole.planet.myplanet.model.RealmSubmission.Companion.getRecentSubmissionDate
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.submission.AdapterMySubmission
import org.ole.planet.myplanet.utilities.TimeUtils.formatDate

class AdapterSurvey(private val context: Context, private val mRealm: Realm, private val userId: String) : RecyclerView.Adapter<AdapterSurvey.ViewHolderSurvey>() {
class AdapterSurvey(private val context: Context, private val mRealm: Realm, private val userId: String, private val isTeam: Boolean, val teamId: String?) : RecyclerView.Adapter<AdapterSurvey.ViewHolderSurvey>() {
private var examList: List<RealmStepExam> = emptyList()
private var listener: OnHomeItemClickListener? = null
private var user: RealmUserModel? = null

init {
if (context is OnHomeItemClickListener) {
listener = context
}
user = UserProfileDbHandler(context).userModel
}

fun updateData(newList: List<RealmStepExam>) {
Expand Down Expand Up @@ -63,7 +59,7 @@ class AdapterSurvey(private val context: Context, private val mRealm: Realm, pri
binding.apply {
tvTitle.text = exam.name
startSurvey.setOnClickListener {
AdapterMySubmission.openSurvey(listener, exam.id, false)
AdapterMySubmission.openSurvey(listener, exam.id, false, isTeam, teamId)
}

val questions = mRealm.where(RealmExamQuestion::class.java)
Expand All @@ -81,12 +77,12 @@ class AdapterSurvey(private val context: Context, private val mRealm: Realm, pri
context.getString(R.string.record_survey)
}

if (user?.id?.startsWith("guest") == true) {
if (userId.startsWith("guest") == true) {
startSurvey.visibility = View.GONE
}

tvNoSubmissions.text = getNoOfSubmissionByUser(exam.id, exam.courseId, user?.id, mRealm)
tvDateCompleted.text = getRecentSubmissionDate(exam.id, exam.courseId, user?.id, mRealm)
tvNoSubmissions.text = getNoOfSubmissionByUser(exam.id, exam.courseId, userId, mRealm)
tvDateCompleted.text = getRecentSubmissionDate(exam.id, exam.courseId, userId, mRealm)
tvDate.text = formatDate(RealmStepExam.getSurveyCreationTime(exam.id!!, mRealm)!!, "MMM dd, yyyy")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ class SurveyFragment : BaseRecyclerFragment<RealmStepExam?>() {
private lateinit var spn: CustomSpinner
private var isTitleAscending = true
private lateinit var adapter: AdapterSurvey
private var isTeam: Boolean = false
private var teamId: String? = null

override fun getLayout(): Int {
return R.layout.fragment_survey
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
adapter = AdapterSurvey(requireActivity(), mRealm, model?.id ?: "")
isTeam = arguments?.getBoolean("isTeam", false) == true
teamId = arguments?.getString("teamId", null)
adapter = AdapterSurvey(requireActivity(), mRealm, model?.id ?: "", isTeam, teamId)
}

override fun getAdapter(): RecyclerView.Adapter<*> {
Expand Down Expand Up @@ -78,8 +82,18 @@ class SurveyFragment : BaseRecyclerFragment<RealmStepExam?>() {
}

private fun updateAdapterData(sort: Sort = Sort.ASCENDING, field: String = "name") {
val newList = getList(RealmStepExam::class.java, field, sort)
adapter.updateData(safeCastList(newList, RealmStepExam::class.java))
val query = mRealm.where(RealmStepExam::class.java)

val surveys = if (teamId != null && isTeam) {
query.equalTo("teamId", teamId)
.sort(field, sort)
.findAll()
} else {
query.sort(field, sort)
.findAll()
}

adapter.updateData(safeCastList(surveys, RealmStepExam::class.java))
updateUIState()
}

Expand Down
Loading

0 comments on commit 029ca40

Please sign in to comment.