Skip to content

Commit

Permalink
Use general OnItemClickListener interface
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoMoreta committed Sep 21, 2023
1 parent cbce322 commit bd1afaa
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onCreate(Bundle savedInstanceState) {

final List<QuizAttempt> attempts = attemptsRepository.getQuizAttempts(this, stats);
QuizAttemptAdapter adapter = new QuizAttemptAdapter(this, attempts);
adapter.setOnItemClickListener((v, position) -> {
adapter.setOnItemClickListener((v, position, type, enabled) -> {
Intent i = new Intent(CourseQuizAttemptsActivity.this, QuizAttemptActivity.class);
Bundle tb = new Bundle();
QuizAttempt attempt = attempts.get(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ protected void onCreate(Bundle savedInstanceState) {
DevicesBTAdapter adapterPairedDevices = new DevicesBTAdapter(this, pairedDevicesNames);

// Find and set up the RecyclerView for paired devices
adapterPairedDevices.setOnItemClickListener((v, position) -> selectDevice(v));
adapterPairedDevices.setOnItemClickListener((v, position, type, enabled) -> selectDevice(v));
binding.recyclerPairedDevices.setAdapter(adapterPairedDevices);

// Find and set up the RecyclerView for newly discovered devices

newDevicesNames.clear();
adapterNewDevices = new DevicesBTAdapter(this, newDevicesNames);

adapterNewDevices.setOnItemClickListener((v, position) -> selectDevice(v));
adapterNewDevices.setOnItemClickListener((v, position, type, enabled) -> selectDevice(v));
binding.recyclerNewDevices.setAdapter(adapterNewDevices);

// Register for broadcasts when a device is discovered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void onDestroyActionMode(androidx.appcompat.view.ActionMode mode) {
}
});

coursesAdapter.setOnItemClickListener((view, position) -> {
coursesAdapter.setOnItemClickListener((view, position, type, enabled) -> {
Log.d("course-download", "Clicked " + position);
CourseInstallViewAdapter course = courses.get(position);
// When installing, don't do anything on click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onCreate(Bundle savedInstanceState) {
adapterResults = new SearchResultsAdapter(this, results);

binding.recyclerResultsSearch.setAdapter(adapterResults);
adapterResults.setOnItemClickListener((view, position) -> {
adapterResults.setOnItemClickListener((view, position, type, enabled) -> {
Course course = (Course) view.getTag(R.id.TAG_COURSE);
String digest = (String) view.getTag(R.id.TAG_ACTIVITY_DIGEST);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
adapterTags = new TagsAdapter(this, tags);

binding.recyclerTags.setAdapter(adapterTags);
adapterTags.setOnItemClickListener((view, position) -> {
adapterTags.setOnItemClickListener((view, position, type, enabled) -> {
Tag selectedTag = tags.get(position);
Intent i = new Intent(TagSelectActivity.this, DownloadActivity.class);
Bundle tb = new Bundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class ActivityTypesAdapter(

init {
binding = RowActivityTypeBinding.bind(itemView)
itemView.setOnClickListener { v: View? ->
itemView.setOnClickListener {
val activityType = getItemAtPosition(adapterPosition)
activityType.isEnabled = !activityType.isEnabled
notifyDataSetChanged()
if (itemClickListener != null) {
itemClickListener!!.onItemClick(
itemView,
adapterPosition,
activityType.type,
activityType.isEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BadgesAdapter(private val context: Context, private val badges: List<Badge
binding = RowFragmentBadgesListBinding.bind(itemView)
binding.btnDownloadCertificate.setOnClickListener {
if (onItemClickListener != null) {
onItemClickListener?.onItemClick(adapterPosition, "", true)
onItemClickListener?.onItemClick(itemView, adapterPosition, "", true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.digitalcampus.mobile.learning.R
import org.digitalcampus.mobile.learning.databinding.RowCourseDownloadBinding
import org.digitalcampus.oppia.activity.PrefsActivity
import org.digitalcampus.oppia.adapter.DownloadCoursesAdapter.DownloadCoursesViewHolder
import org.digitalcampus.oppia.listener.OnItemClickListener
import org.digitalcampus.oppia.model.CourseInstallViewAdapter
import org.digitalcampus.oppia.utils.TextUtilsJava
import java.util.Locale
Expand Down Expand Up @@ -115,16 +116,12 @@ class DownloadCoursesAdapter(private val context: Context, private val courses:

init {
binding.downloadCourseBtn.setOnClickListener { v: View? ->
itemClickListener?.onDownloadButtonClick(v, adapterPosition)
itemClickListener?.onItemClick(v, adapterPosition)
}
}
}

fun setOnItemClickListener(listener: OnItemClickListener?) {
fun setOnItemClickListener(listener: OnItemClickListener) {
itemClickListener = listener
}

interface OnItemClickListener {
fun onDownloadButtonClick(view: View?, position: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.digitalcampus.mobile.learning.R
import org.digitalcampus.mobile.learning.databinding.RowWidgetQuizFeedbackBinding
import org.digitalcampus.mobile.quiz.Quiz
import org.digitalcampus.oppia.adapter.QuizAnswersFeedbackAdapter.QuizFeedbackViewHolder
import org.digitalcampus.oppia.listener.OnItemClickListener
import org.digitalcampus.oppia.model.QuizAnswerFeedback
import org.digitalcampus.oppia.utils.TextUtilsJava
import org.digitalcampus.oppia.utils.UIUtils.getFromHtmlAndTrim
Expand Down Expand Up @@ -84,11 +85,7 @@ class QuizAnswersFeedbackAdapter(
return quizFeedbacks[position]
}

fun setOnItemClickListener(listener: OnItemClickListener?) {
fun setOnItemClickListener(listener: OnItemClickListener) {
itemClickListener = listener
}

interface OnItemClickListener {
fun onItemClick(view: View?, position: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.digitalcampus.oppia.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.digitalcampus.oppia.listener.OnItemClickListener

abstract class RecyclerViewClickableAdapter<H : RecyclerViewClickableAdapter<H>.ViewHolder> :
RecyclerView.Adapter<H>() {
Expand All @@ -16,11 +17,7 @@ abstract class RecyclerViewClickableAdapter<H : RecyclerViewClickableAdapter<H>.
}
}

fun setOnItemClickListener(listener: OnItemClickListener?) {
fun setOnItemClickListener(listener: OnItemClickListener) {
itemClickListener = listener
}

interface OnItemClickListener {
fun onItemClick(v: View?, position: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
import org.digitalcampus.mobile.learning.R
import org.digitalcampus.mobile.learning.databinding.RowTagBinding
import org.digitalcampus.oppia.adapter.TagsAdapter.TagsViewHolder
import org.digitalcampus.oppia.listener.OnItemClickListener
import org.digitalcampus.oppia.model.Tag

class TagsAdapter(private val context: Context, private val tags: List<Tag>) :
Expand All @@ -22,7 +23,6 @@ class TagsAdapter(private val context: Context, private val tags: List<Tag>) :
init {
itemView.setOnClickListener {
itemClickListener?.onItemClick(itemView, adapterPosition)

}
}
}
Expand Down Expand Up @@ -60,8 +60,4 @@ class TagsAdapter(private val context: Context, private val tags: List<Tag>) :
fun setOnItemClickListener(listener: OnItemClickListener) {
itemClickListener = listener
}

interface OnItemClickListener {
fun onItemClick(view: View?, position: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ public void onTabReselected(TabLayout.Tab tab) {

// Event types list
@Override
public void onItemClick(int position, String type, boolean enabled) {

public void onItemClick(View view, int position, String type, boolean enabled) {
loadPlot(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
getAppComponent().inject(this);

adapterBadges = new BadgesAdapter(super.getActivity(), badges);
adapterBadges.setOnItemClickListener((position, type, enabled) -> checkPermissionAndDownloadCertificate(badges.get(position)));
adapterBadges.setOnItemClickListener((view, position, type, enabled) -> checkPermissionAndDownloadCertificate(badges.get(position)));
binding.recyclerBadges.setAdapter(adapterBadges);

downloadOppiaDataService = new DownloadOppiaDataService(getActivity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
quizzesAdapter = new CourseQuizzesAdapter(getActivity(), quizStats);
binding.scorecardGridQuizzes.setAdapter(quizzesAdapter);
binding.scorecardGridQuizzes.setNestedScrollingEnabled(false);
quizzesAdapter.setOnItemClickListener((v, position)->{
quizzesAdapter.setOnItemClickListener((v, position, type, enabled)->{
QuizStats stats = quizzesAdapter.getItemAtPosition(position);
Intent i = new Intent(getActivity(), CourseQuizAttemptsActivity.class);
Bundle tb = new Bundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

adapter = new GlobalQuizAttemptsAdapter(this.getContext(), attempts);
binding.attemptsList.setAdapter(adapter);
adapter.setOnItemClickListener((v, position) -> {
adapter.setOnItemClickListener((v, position, type, enabled) -> {
Intent i = new Intent(getActivity(), QuizAttemptActivity.class);
Bundle tb = new Bundle();
QuizAttempt attempt = attempts.get(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.digitalcampus.oppia.adapter.ScorecardsGridAdapter;
import org.digitalcampus.oppia.api.ApiEndpoint;
import org.digitalcampus.oppia.application.AdminSecurityManager;
import org.digitalcampus.oppia.listener.OnItemClickListener;
import org.digitalcampus.oppia.model.Badge;
import org.digitalcampus.oppia.model.Course;
import org.digitalcampus.oppia.model.CoursesRepository;
Expand All @@ -46,7 +47,7 @@

import javax.inject.Inject;

public class GlobalScorecardFragment extends AppFragment implements ScorecardsGridAdapter.OnItemClickListener {
public class GlobalScorecardFragment extends AppFragment implements OnItemClickListener {

private ScorecardsGridAdapter adapterScorecards;

Expand Down Expand Up @@ -129,8 +130,7 @@ private void showEmptyStateView(boolean show) {
}

@Override
public void onItemClick(View view, int position) {

public void onItemClick(View view, int position, String type, boolean enabled) {
Course selectedCourse = adapterScorecards.getItemAtPosition(position);
Intent i = new Intent(super.getActivity(), CourseIndexActivity.class);
Bundle tb = new Bundle();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.digitalcampus.oppia.listener
import android.view.View

interface OnItemClickListener {
fun onItemClick(position: Int, type: String?, enabled: Boolean)
fun onItemClick(view: View? = null, position: Int, type: String? = null, enabled: Boolean = true)
}

0 comments on commit bd1afaa

Please sign in to comment.