diff --git a/app/build.gradle b/app/build.gradle index 87a8784816..a8a30aec19 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1085 - versionName "0.10.85" + versionCode 1086 + versionName "0.10.86" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/AdapterLibrary.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/AdapterLibrary.java index fd3f230611..aa6af16fb4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/AdapterLibrary.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/AdapterLibrary.java @@ -1,20 +1,14 @@ package org.ole.planet.myplanet.ui.library; import android.content.Context; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatRatingBar; -import androidx.recyclerview.widget.RecyclerView; - import android.text.TextUtils; import android.view.LayoutInflater; import android.view.MotionEvent; -import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import com.google.android.flexbox.FlexboxLayout; import com.google.gson.JsonObject; @@ -23,6 +17,7 @@ import org.ole.planet.myplanet.callback.OnHomeItemClickListener; import org.ole.planet.myplanet.callback.OnLibraryItemSelected; import org.ole.planet.myplanet.callback.OnRatingChangeListener; +import org.ole.planet.myplanet.databinding.RowLibraryBinding; import org.ole.planet.myplanet.model.RealmMyLibrary; import org.ole.planet.myplanet.model.RealmTag; import org.ole.planet.myplanet.ui.course.AdapterCourses; @@ -39,7 +34,8 @@ import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Realm; -public class AdapterLibrary extends RecyclerView.Adapter { +public class AdapterLibrary extends RecyclerView.Adapter { + private RowLibraryBinding rowLibraryBinding; private Context context; private List libraryList; private List selectedItems; @@ -86,38 +82,36 @@ public void setListener(OnLibraryItemSelected listener) { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_library, parent, false); - return new ViewHolderLibrary(v); + public ViewHolderLibrary onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowLibraryBinding = RowLibraryBinding.inflate(LayoutInflater.from(context), parent, false); + return new ViewHolderLibrary(rowLibraryBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) { - if (holder instanceof ViewHolderLibrary) { - Utilities.log("On bind " + position); - ((ViewHolderLibrary) holder).title.setText(libraryList.get(position).getTitle()); - Utilities.log(libraryList.get(position).getDescription()); - markwon.setMarkdown(((ViewHolderLibrary) holder).desc, libraryList.get(position).getDescription()); - ((ViewHolderLibrary) holder).timesRated.setText(libraryList.get(position).getTimesRated() + context.getString(R.string.total)); - ((ViewHolderLibrary) holder).checkBox.setChecked(selectedItems.contains(libraryList.get(position))); - ((ViewHolderLibrary) holder).rating.setText(TextUtils.isEmpty(libraryList.get(position).getAverageRating()) ? "0.0" : String.format("%.1f", Double.parseDouble(libraryList.get(position).getAverageRating()))); - ((ViewHolderLibrary) holder).tvDate.setText(TimeUtils.formatDate(libraryList.get(position).getCreatedDate(), "MMM dd, yyyy")); - displayTagCloud(((ViewHolderLibrary) holder).flexboxDrawable, position); - holder.itemView.setOnClickListener(view -> openLibrary(libraryList.get(position))); - ((ViewHolderLibrary) holder).ivDownloaded.setImageResource(libraryList.get(position).isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download); - if (ratingMap.containsKey(libraryList.get(position).getResource_id())) { - JsonObject object = ratingMap.get(libraryList.get(position).getResource_id()); - AdapterCourses.showRating(object, ((ViewHolderLibrary) holder).rating, ((ViewHolderLibrary) holder).timesRated, ((ViewHolderLibrary) holder).ratingBar); - } else { - ((ViewHolderLibrary) holder).ratingBar.setRating(0); - } - - ((ViewHolderLibrary) holder).checkBox.setOnClickListener((view) -> { - Utilities.handleCheck(((CheckBox) view).isChecked(), position, (ArrayList) selectedItems, libraryList); - if (listener != null) listener.onSelectedListChange(selectedItems); - notifyDataSetChanged(); - }); + public void onBindViewHolder(@NonNull ViewHolderLibrary holder, final int position) { + Utilities.log("On bind " + position); + rowLibraryBinding.title.setText(libraryList.get(position).getTitle()); + Utilities.log(libraryList.get(position).getDescription()); + markwon.setMarkdown(rowLibraryBinding.description, libraryList.get(position).getDescription()); + rowLibraryBinding.timesRated.setText(libraryList.get(position).getTimesRated() + context.getString(R.string.total)); + rowLibraryBinding.checkbox.setChecked(selectedItems.contains(libraryList.get(position))); + rowLibraryBinding.rating.setText(TextUtils.isEmpty(libraryList.get(position).getAverageRating()) ? "0.0" : String.format("%.1f", Double.parseDouble(libraryList.get(position).getAverageRating()))); + rowLibraryBinding.tvDate.setText(TimeUtils.formatDate(libraryList.get(position).getCreatedDate(), "MMM dd, yyyy")); + displayTagCloud(rowLibraryBinding.flexboxDrawable, position); + holder.itemView.setOnClickListener(view -> openLibrary(libraryList.get(position))); + rowLibraryBinding.ivDownloaded.setImageResource(libraryList.get(position).isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download); + if (ratingMap.containsKey(libraryList.get(position).getResource_id())) { + JsonObject object = ratingMap.get(libraryList.get(position).getResource_id()); + AdapterCourses.showRating(object, rowLibraryBinding.rating, rowLibraryBinding.timesRated, rowLibraryBinding.ratingBar); + } else { + rowLibraryBinding.ratingBar.setRating(0); } + + rowLibraryBinding.checkbox.setOnClickListener((view) -> { + Utilities.handleCheck(((CheckBox) view).isChecked(), position, (ArrayList) selectedItems, libraryList); + if (listener != null) listener.onSelectedListChange(selectedItems); + notifyDataSetChanged(); + }); } public boolean areAllSelected(){ @@ -172,31 +166,15 @@ public int getItemCount() { } class ViewHolderLibrary extends RecyclerView.ViewHolder { - TextView title, desc, rating, tvDate, timesRated, average; - CheckBox checkBox; - AppCompatRatingBar ratingBar; - FlexboxLayout flexboxDrawable; - LinearLayout llRating; - ImageView ivDownloaded; - - public ViewHolderLibrary(View itemView) { - super(itemView); - title = itemView.findViewById(R.id.title); - desc = itemView.findViewById(R.id.description); - rating = itemView.findViewById(R.id.rating); - timesRated = itemView.findViewById(R.id.times_rated); - ratingBar = itemView.findViewById(R.id.rating_bar); - tvDate = itemView.findViewById(R.id.tv_date); - checkBox = itemView.findViewById(R.id.checkbox); - llRating = itemView.findViewById(R.id.ll_rating); - ivDownloaded = itemView.findViewById(R.id.iv_downloaded); - average = itemView.findViewById(R.id.average); - ratingBar.setOnTouchListener((v1, event) -> { + RowLibraryBinding rowLibraryBinding; + public ViewHolderLibrary(RowLibraryBinding rowLibraryBinding) { + super(rowLibraryBinding.getRoot()); + this.rowLibraryBinding = rowLibraryBinding; + rowLibraryBinding.ratingBar.setOnTouchListener((v1, event) -> { if (event.getAction() == MotionEvent.ACTION_UP) homeItemClickListener.showRatingDialog("resource", libraryList.get(getAdapterPosition()).getResource_id(), libraryList.get(getAdapterPosition()).getTitle(), ratingChangeListener); return true; }); - flexboxDrawable = itemView.findViewById(R.id.flexbox_drawable); } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceActivity.java index e432f60349..52a700224a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceActivity.java @@ -1,21 +1,17 @@ package org.ole.planet.myplanet.ui.library; import android.os.Bundle; - -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; - import android.view.MenuItem; import android.view.View; import android.widget.ArrayAdapter; -import android.widget.EditText; import android.widget.ListView; -import android.widget.Spinner; import android.widget.TextView; -import com.google.android.material.textfield.TextInputLayout; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityAddResourceBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmMyLibrary; import org.ole.planet.myplanet.model.RealmUserModel; @@ -32,9 +28,7 @@ import io.realm.RealmList; public class AddResourceActivity extends AppCompatActivity { - EditText etTitle, etAuthor, etYear, etDescription, etPublisher, etLinkToLicense, etOpenWhich; - Spinner spnLang, spnMedia, spnResourceType, spnOpenWith; - TextView tvSubjects, tvLevels, tvResourceFor, tvAddedBy, fileUrl; + private ActivityAddResourceBinding activityAddResourceBinding; Realm mRealm; RealmUserModel userModel; RealmList subjects; @@ -45,7 +39,8 @@ public class AddResourceActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_add_resource); + activityAddResourceBinding = ActivityAddResourceBinding.inflate(getLayoutInflater()); + setContentView(activityAddResourceBinding.getRoot()); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); userModel = new UserProfileDbHandler(this).getUserModel(); @@ -64,33 +59,17 @@ protected void onDestroy() { } private void initializeViews() { - etTitle = findViewById(R.id.et_title); - etAuthor = findViewById(R.id.et_author); - fileUrl = findViewById(R.id.file_url); - etYear = findViewById(R.id.et_year); - etDescription = findViewById(R.id.et_description); - etPublisher = findViewById(R.id.et_publisher); - etLinkToLicense = findViewById(R.id.et_link_to_license); - etOpenWhich = findViewById(R.id.et_open_which); - spnLang = findViewById(R.id.spn_lang); - spnMedia = findViewById(R.id.spn_media); - spnResourceType = findViewById(R.id.spn_resource_type); - spnOpenWith = findViewById(R.id.spn_open_with); - tvSubjects = findViewById(R.id.tv_subject); - tvAddedBy = findViewById(R.id.tv_added_by); - tvLevels = findViewById(R.id.tv_levels); - tvResourceFor = findViewById(R.id.tv_resource_for); - fileUrl.setText(getString(R.string.file) + resourceUrl); - tvAddedBy.setText(userModel.getName()); - tvLevels.setOnClickListener(view -> showMultiSelectList(getResources().getStringArray(R.array.array_levels), levels, view)); - tvSubjects.setOnClickListener(view -> showMultiSelectList(getResources().getStringArray(R.array.array_subjects), subjects, view)); - tvResourceFor.setOnClickListener(view -> showMultiSelectList(getResources().getStringArray(R.array.array_resource_for), subjects, view)); - findViewById(R.id.btn_submit).setOnClickListener(view -> saveResource()); - findViewById(R.id.btn_cancel).setOnClickListener(view -> finish()); + activityAddResourceBinding.fileUrl.setText(getString(R.string.file) + resourceUrl); + activityAddResourceBinding.tvAddedBy.setText(userModel.getName()); + activityAddResourceBinding.tvLevels.setOnClickListener(view -> showMultiSelectList(getResources().getStringArray(R.array.array_levels), levels, view)); + activityAddResourceBinding.tvSubject.setOnClickListener(view -> showMultiSelectList(getResources().getStringArray(R.array.array_subjects), subjects, view)); + activityAddResourceBinding.tvResourceFor.setOnClickListener(view -> showMultiSelectList(getResources().getStringArray(R.array.array_resource_for), subjects, view)); + activityAddResourceBinding.btnSubmit.setOnClickListener(view -> saveResource()); + activityAddResourceBinding.btnCancel.setOnClickListener(view -> finish()); } private void saveResource() { - String title = etTitle.getText().toString().trim(); + String title = activityAddResourceBinding.etTitle.getText().toString().trim(); if (!validate(title)) return; mRealm.executeTransactionAsync(realm -> { String id = UUID.randomUUID().toString(); @@ -104,17 +83,17 @@ private void saveResource() { } private void createResource(RealmMyLibrary resource, String id) { - resource.setAddedBy(tvAddedBy.getText().toString().trim()); - resource.setAuthor(etAuthor.getText().toString().trim()); + resource.setAddedBy(activityAddResourceBinding.tvAddedBy.getText().toString().trim()); + resource.setAuthor(activityAddResourceBinding.etAuthor.getText().toString().trim()); resource.setResource_id(id); - resource.setYear(etYear.getText().toString().trim()); - resource.setDescription(etDescription.getText().toString().trim()); - resource.setPublisher(etPublisher.getText().toString().trim()); - resource.setLinkToLicense(etLinkToLicense.getText().toString().trim()); - resource.setOpenWith(spnOpenWith.getSelectedItem().toString()); - resource.setLanguage(spnLang.getSelectedItem().toString()); - resource.setMediaType(spnMedia.getSelectedItem().toString()); - resource.setResourceType(spnResourceType.getSelectedItem().toString()); + resource.setYear(activityAddResourceBinding.etYear.getText().toString().trim()); + resource.setDescription(activityAddResourceBinding.etDescription.getText().toString().trim()); + resource.setPublisher(activityAddResourceBinding.etPublisher.getText().toString().trim()); + resource.setLinkToLicense(activityAddResourceBinding.etLinkToLicense.getText().toString().trim()); + resource.setOpenWith(activityAddResourceBinding.spnOpenWith.getSelectedItem().toString()); + resource.setLanguage(activityAddResourceBinding.spnLang.getSelectedItem().toString()); + resource.setMediaType(activityAddResourceBinding.spnMedia.getSelectedItem().toString()); + resource.setResourceType(activityAddResourceBinding.spnResourceType.getSelectedItem().toString()); resource.setSubject(subjects); resource.setUserId(new RealmList<>()); resource.setLevel(levels); @@ -127,7 +106,7 @@ private void createResource(RealmMyLibrary resource, String id) { private boolean validate(String title) { if (title.isEmpty()) { - ((TextInputLayout) findViewById(R.id.tl_title)).setError(getString(R.string.title_is_required)); + activityAddResourceBinding.tlTitle.setError(getString(R.string.title_is_required)); return false; } if (levels.isEmpty()) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java index c03a648a94..4a37503e73 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java @@ -2,7 +2,6 @@ import static android.app.Activity.RESULT_OK; -import android.app.Activity; import android.app.Dialog; import android.content.ContentValues; import android.content.Context; @@ -23,7 +22,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import androidx.core.content.FileProvider; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; @@ -33,6 +31,8 @@ import org.jetbrains.annotations.NotNull; import org.ole.planet.myplanet.MainApplication; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.AlertSoundRecorderBinding; +import org.ole.planet.myplanet.databinding.FragmentAddResourceBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmMyPersonal; import org.ole.planet.myplanet.model.RealmUserModel; @@ -48,6 +48,7 @@ import io.realm.Realm; public class AddResourceFragment extends BottomSheetDialogFragment { + private FragmentAddResourceBinding fragmentAddResourceBinding; static final int REQUEST_VIDEO_CAPTURE = 1; static final int REQUEST_RECORD_SOUND = 0; static final int REQUEST_CAPTURE_PICTURE = 2; @@ -113,29 +114,36 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_add_resource, container, false); - v.findViewById(R.id.ll_record_video).setOnClickListener(view -> dispatchTakeVideoIntent()); - v.findViewById(R.id.ll_record_audio).setOnClickListener(view -> { + fragmentAddResourceBinding = FragmentAddResourceBinding.inflate(inflater, container, false); + fragmentAddResourceBinding.llRecordVideo.setOnClickListener(view -> dispatchTakeVideoIntent()); + fragmentAddResourceBinding.llRecordAudio.setOnClickListener(view -> { showAudioRecordAlert(); }); - v.findViewById(R.id.ll_capture_image).setOnClickListener(view -> takePhoto()); - v.findViewById(R.id.ll_draft).setOnClickListener(view -> FileUtils.openOleFolder(this, 100)); - return v; + fragmentAddResourceBinding.llCaptureImage.setOnClickListener(view -> takePhoto()); + fragmentAddResourceBinding.llDraft.setOnClickListener(view -> FileUtils.openOleFolder(this, 100)); + return fragmentAddResourceBinding.getRoot(); } private void showAudioRecordAlert() { - View v = LayoutInflater.from(getActivity()).inflate(R.layout.alert_sound_recorder, null); - tvTime = v.findViewById(R.id.tv_time); - floatingActionButton = v.findViewById(R.id.fab_record); - AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle("Record Audio").setView(v).setCancelable(false).create(); + AlertSoundRecorderBinding alertSoundRecorderBinding = AlertSoundRecorderBinding.inflate(LayoutInflater.from(getActivity())); + tvTime = alertSoundRecorderBinding.tvTime; + floatingActionButton = alertSoundRecorderBinding.fabRecord; + AlertDialog dialog = new AlertDialog.Builder(getActivity()) + .setTitle("Record Audio") + .setView(alertSoundRecorderBinding.getRoot()) + .setCancelable(false) + .create(); + createAudioRecorderService(dialog); - floatingActionButton.setOnClickListener(view -> { + + alertSoundRecorderBinding.fabRecord.setOnClickListener(view -> { if (!audioRecorderService.isRecording()) { audioRecorderService.startRecording(); } else { audioRecorderService.stopRecording(); } }); + dialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss), (dialogInterface, i) -> { if (audioRecorderService != null && audioRecorderService.isRecording()) { audioRecorderService.forceStop(); @@ -253,9 +261,7 @@ private String getRealPathFromUri(Uri uri) { return cursor.getString(columnIndex); } } - return ""; - } private void addResource(String path) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/CollectionsFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/CollectionsFragment.java index 976253d192..ed5d42ea8c 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/CollectionsFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/CollectionsFragment.java @@ -1,32 +1,22 @@ package org.ole.planet.myplanet.ui.library; - import android.os.Bundle; - -import androidx.annotation.Nullable; - -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; - import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.ExpandableListView; -import com.google.android.material.textfield.TextInputLayout; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; import org.ole.planet.myplanet.MainApplication; -import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.callback.TagClickListener; +import org.ole.planet.myplanet.databinding.FragmentCollectionsBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmTag; import org.ole.planet.myplanet.utilities.KeyboardUtils; -import org.ole.planet.myplanet.utilities.Utilities; import java.util.ArrayList; import java.util.HashMap; @@ -35,15 +25,12 @@ import io.realm.Realm; public class CollectionsFragment extends DialogFragment implements TagExpandableAdapter.OnClickTagItem, CompoundButton.OnCheckedChangeListener { + private FragmentCollectionsBinding fragmentCollectionsBinding; static List recentList; - ExpandableListView listTag; - TextInputLayout tlFilter; Realm mRealm; List list; List filteredList; TagExpandableAdapter adapter; - EditText etFilter; - Button btnOk; String dbType; TagClickListener listener; private ArrayList selectedItemsList = new ArrayList<>(); @@ -73,15 +60,11 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_collections, container, false); - listTag = v.findViewById(R.id.list_tags); - tlFilter = v.findViewById(R.id.tl_filter); - etFilter = v.findViewById(R.id.et_filter); - btnOk = v.findViewById(R.id.btn_ok); + fragmentCollectionsBinding = FragmentCollectionsBinding.inflate(inflater, container, false); mRealm = new DatabaseService(getActivity()).getRealmInstance(); filteredList = new ArrayList<>(); KeyboardUtils.hideSoftKeyboard(getActivity()); - return v; + return fragmentCollectionsBinding.getRoot(); } @Override @@ -92,13 +75,13 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { } private void setListeners() { - btnOk.setOnClickListener(view -> { + fragmentCollectionsBinding.btnOk.setOnClickListener(view -> { if (listener != null) { listener.onOkClicked(selectedItemsList); dismiss(); } }); - etFilter.addTextChangedListener(new TextWatcher() { + fragmentCollectionsBinding.etFilter.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { @@ -139,12 +122,12 @@ private void setListAdapter() { for (RealmTag t : allTags) { createChildMap(childMap, t); } - listTag.setGroupIndicator(null); + fragmentCollectionsBinding.listTags.setGroupIndicator(null); adapter = new TagExpandableAdapter(getActivity(), list, childMap, selectedItemsList); adapter.setSelectMultiple(true); adapter.setClickListener(this); - listTag.setAdapter(adapter); - btnOk.setVisibility(View.VISIBLE); + fragmentCollectionsBinding.listTags.setAdapter(adapter); + fragmentCollectionsBinding.btnOk.setVisibility(View.VISIBLE); } private void createChildMap(HashMap> childMap, RealmTag t) { @@ -178,7 +161,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { MainApplication.isCollectionSwitchOn = b; adapter.setSelectMultiple(b); adapter.setTagList(list); - listTag.setAdapter(adapter); - btnOk.setVisibility(b ? View.VISIBLE : View.GONE); + fragmentCollectionsBinding.listTags.setAdapter(adapter); + fragmentCollectionsBinding.btnOk.setVisibility(b ? View.VISIBLE : View.GONE); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryDetailFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryDetailFragment.java index 36996bdc87..d373eec519 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryDetailFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryDetailFragment.java @@ -1,39 +1,33 @@ package org.ole.planet.myplanet.ui.library; import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatImageButton; - import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.Nullable; + import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.base.BaseContainerFragment; import org.ole.planet.myplanet.callback.OnRatingChangeListener; +import org.ole.planet.myplanet.databinding.FragmentLibraryDetailBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmMyLibrary; import org.ole.planet.myplanet.model.RealmRating; import org.ole.planet.myplanet.model.RealmRemovedLog; import org.ole.planet.myplanet.model.RealmUserModel; import org.ole.planet.myplanet.service.UserProfileDbHandler; -import org.ole.planet.myplanet.utilities.Constants; import org.ole.planet.myplanet.utilities.FileUtils; import org.ole.planet.myplanet.utilities.Utilities; import io.realm.Realm; public class LibraryDetailFragment extends BaseContainerFragment implements OnRatingChangeListener { - TextView author, pubishedBy, title, media, subjects, license, language, resource, type; - AppCompatImageButton download, remove, back; + private FragmentLibraryDetailBinding fragmentLibraryDetailBinding; String libraryId; DatabaseService dbService; Realm mRealm; @@ -56,19 +50,19 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public void onDownloadComplete() { - download.setImageResource(R.drawable.ic_play); + fragmentLibraryDetailBinding.btnDownload.setImageResource(R.drawable.ic_play); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + fragmentLibraryDetailBinding = FragmentLibraryDetailBinding.inflate(inflater, container, false); View v = inflater.inflate(R.layout.fragment_library_detail, container, false); dbService = new DatabaseService(getActivity()); mRealm = dbService.getRealmInstance(); userModel = new UserProfileDbHandler(getActivity()).getUserModel(); library = mRealm.where(RealmMyLibrary.class).equalTo("resourceId", libraryId).findFirst(); - initView(v); - return v; + return fragmentLibraryDetailBinding.getRoot(); } @Override @@ -78,30 +72,15 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { setLibraryData(); } - private void initView(View v) { - author = v.findViewById(R.id.tv_author); - title = v.findViewById(R.id.tv_title); - pubishedBy = v.findViewById(R.id.tv_published); - media = v.findViewById(R.id.tv_media); - subjects = v.findViewById(R.id.tv_subject); - language = v.findViewById(R.id.tv_language); - license = v.findViewById(R.id.tv_license); - resource = v.findViewById(R.id.tv_resource); - type = v.findViewById(R.id.tv_type); - download = v.findViewById(R.id.btn_download); - remove = v.findViewById(R.id.btn_remove); - back = v.findViewById(R.id.btn_back); - } - private void setLibraryData() { - title.setText(String.format("%s%s", openFrom.isEmpty() ? "" : openFrom + "-", library.getTitle())); - author.setText(library.getAuthor()); - pubishedBy.setText(library.getPublisher()); - media.setText(library.getMediaType()); - subjects.setText(library.getSubjectsAsString()); - language.setText(library.getLanguage()); - license.setText(library.getLinkToLicense()); - resource.setText(RealmMyLibrary.listToString(library.getResourceFor())); + fragmentLibraryDetailBinding.tvTitle.setText(String.format("%s%s", openFrom.isEmpty() ? "" : openFrom + "-", library.getTitle())); + fragmentLibraryDetailBinding.tvAuthor.setText(library.getAuthor()); + fragmentLibraryDetailBinding.tvPublished.setText(library.getPublisher()); + fragmentLibraryDetailBinding.tvMedia.setText(library.getMediaType()); + fragmentLibraryDetailBinding.tvSubject.setText(library.getSubjectsAsString()); + fragmentLibraryDetailBinding.tvLanguage.setText(library.getLanguage()); + fragmentLibraryDetailBinding.tvLicense.setText(library.getLinkToLicense()); + fragmentLibraryDetailBinding.tvResource.setText(RealmMyLibrary.listToString(library.getResourceFor())); profileDbHandler.setResourceOpenCount(library); try { onRatingChanged(); @@ -109,16 +88,16 @@ private void setLibraryData() { ex.printStackTrace(); } - download.setVisibility(TextUtils.isEmpty(library.getResourceLocalAddress()) ? View.GONE : View.VISIBLE); - download.setImageResource(library.getResourceOffline() == null || library.isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download); + fragmentLibraryDetailBinding.btnDownload.setVisibility(TextUtils.isEmpty(library.getResourceLocalAddress()) ? View.GONE : View.VISIBLE); + fragmentLibraryDetailBinding.btnDownload.setImageResource(library.getResourceOffline() == null || library.isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download); if (FileUtils.getFileExtension(library.getResourceLocalAddress()).equals("mp4")) { - download.setImageResource(R.drawable.ic_play); + fragmentLibraryDetailBinding.btnDownload.setImageResource(R.drawable.ic_play); } setClickListeners(); } public void setClickListeners() { - download.setOnClickListener(view -> { + fragmentLibraryDetailBinding.btnDownload.setOnClickListener(view -> { if (TextUtils.isEmpty(library.getResourceLocalAddress())) { Toast.makeText(getActivity(), getString(R.string.link_not_available), Toast.LENGTH_LONG).show(); return; @@ -127,8 +106,8 @@ public void setClickListeners() { }); Utilities.log("user id " + profileDbHandler.getUserModel().getId() + " " + library.getUserId().contains(profileDbHandler.getUserModel().getId())); boolean isAdd = !library.getUserId().contains(profileDbHandler.getUserModel().getId()); - remove.setImageResource(isAdd ? R.drawable.ic_add_library : R.drawable.close_x); - remove.setOnClickListener(view -> { + fragmentLibraryDetailBinding.btnRemove.setImageResource(isAdd ? R.drawable.ic_add_library : R.drawable.close_x); + fragmentLibraryDetailBinding.btnRemove.setOnClickListener(view -> { if (!mRealm.isInTransaction()) mRealm.beginTransaction(); if (isAdd) { library.setUserId(profileDbHandler.getUserModel().getId()); @@ -140,7 +119,7 @@ public void setClickListeners() { Utilities.toast(getActivity(), getString(R.string.resources) + (isAdd ? getString(R.string.added_to) : getString(R.string.removed_from) + getString(R.string.my_library))); setLibraryData(); }); - back.setOnClickListener(view -> + fragmentLibraryDetailBinding.btnBack.setOnClickListener(view -> getActivity().onBackPressed() ); } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFilterFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFilterFragment.java index 9091f8e27c..c2b7f614f4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFilterFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFilterFragment.java @@ -17,13 +17,15 @@ import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.callback.OnFilterListener; +import org.ole.planet.myplanet.databinding.FragmentLibraryDetailBinding; +import org.ole.planet.myplanet.databinding.FragmentLibraryFilterBinding; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; public class LibraryFilterFragment extends DialogFragment implements AdapterView.OnItemClickListener { - ListView listSub, listLang, listMedium, listLevel; + private FragmentLibraryFilterBinding fragmentLibraryFilterBinding; Set languages, subjects, mediums, levels; OnFilterListener listener; Set selectedLang = new HashSet<>(); @@ -39,18 +41,14 @@ public void setListener(OnFilterListener listener) { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_library_filter, container, false); - listLang = v.findViewById(R.id.list_lang); - listSub = v.findViewById(R.id.list_sub); - listMedium = v.findViewById(R.id.list_medium); - listLevel = v.findViewById(R.id.list_level); - listMedium.setOnItemClickListener(this); - listLang.setOnItemClickListener(this); - listLevel.setOnItemClickListener(this); - listSub.setOnItemClickListener(this); - v.findViewById(R.id.iv_close).setOnClickListener(vi -> dismiss()); - return v; + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentLibraryFilterBinding = FragmentLibraryFilterBinding.inflate(inflater, container, false); + fragmentLibraryFilterBinding.listMedium.setOnItemClickListener(this); + fragmentLibraryFilterBinding.listLang.setOnItemClickListener(this); + fragmentLibraryFilterBinding.listLevel.setOnItemClickListener(this); + fragmentLibraryFilterBinding.listSub.setOnItemClickListener(this); + fragmentLibraryFilterBinding.ivClose.setOnClickListener(vi -> dismiss()); + return fragmentLibraryFilterBinding.getRoot(); } @Override @@ -68,10 +66,10 @@ private void initList() { selectedSubs = listener.getSelectedFilter().get("subjects"); selectedMeds = listener.getSelectedFilter().get("mediums"); selectedLang = listener.getSelectedFilter().get("languages"); - setAdapter(listLevel, levels, selectedLvls); - setAdapter(listLang, languages, selectedLang); - setAdapter(listMedium, mediums, selectedMeds); - setAdapter(listSub, subjects, selectedSubs); + setAdapter(fragmentLibraryFilterBinding.listLevel, levels, selectedLvls); + setAdapter(fragmentLibraryFilterBinding.listLang, languages, selectedLang); + setAdapter(fragmentLibraryFilterBinding.listMedium, mediums, selectedMeds); + setAdapter(fragmentLibraryFilterBinding.listSub, subjects, selectedSubs); } private void setAdapter(ListView listView, Set ar, Set set) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFragment.java index d7e8d7f210..2c41dcec9e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/LibraryFragment.java @@ -344,4 +344,4 @@ private void saveSearchActivity() { mRealm.commitTransaction(); } } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/TagExpandableAdapter.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/TagExpandableAdapter.java index ea625cfba4..2a11b3eae2 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/TagExpandableAdapter.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/TagExpandableAdapter.java @@ -1,17 +1,17 @@ package org.ole.planet.myplanet.ui.library; import android.content.Context; - -import androidx.appcompat.widget.AppCompatImageView; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; -import android.widget.TextView; + +import androidx.appcompat.widget.AppCompatImageView; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.RowAdapterNavigationChildBinding; +import org.ole.planet.myplanet.databinding.RowAdapterNavigationParentBinding; import org.ole.planet.myplanet.model.RealmTag; import java.util.ArrayList; @@ -81,28 +81,34 @@ public boolean hasStableIds() { @Override public View getGroupView(final int groupPosition, final boolean isExpanded, View convertView, ViewGroup parent) { String headerTitle = tagList.get(groupPosition).getName(); - convertView = inflateView(parent, R.layout.row_adapter_navigation_parent); - AppCompatImageView ivIndicator = convertView.findViewById(R.id.iv_indicators); - TextView drawerTitle = convertView.findViewById(R.id.tv_drawer_title); - TextView nonChildTitle = convertView.findViewById(R.id.tv_drawer_title_1); - nonChildTitle.setText(headerTitle); + RowAdapterNavigationParentBinding rowAdapterNavigationParentBinding; + if (convertView == null) { + rowAdapterNavigationParentBinding = RowAdapterNavigationParentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + convertView = rowAdapterNavigationParentBinding.getRoot(); + convertView.setTag(rowAdapterNavigationParentBinding); + } else { + rowAdapterNavigationParentBinding = (RowAdapterNavigationParentBinding) convertView.getTag(); + } + + rowAdapterNavigationParentBinding.tvDrawerTitle1.setText(headerTitle); createCheckbox(convertView, tagList.get(groupPosition)); - drawerTitle.setText(headerTitle); + rowAdapterNavigationParentBinding.tvDrawerTitle.setText(headerTitle); if (!childMap.containsKey(tagList.get(groupPosition).getId())) { - nonChildTitle.setVisibility(View.VISIBLE); - drawerTitle.setVisibility(View.GONE); - ivIndicator.setVisibility(View.GONE); - nonChildTitle.setOnClickListener(v -> clickListener.onTagClicked(tagList.get(groupPosition))); + rowAdapterNavigationParentBinding.tvDrawerTitle1.setVisibility(View.VISIBLE); + rowAdapterNavigationParentBinding.tvDrawerTitle.setVisibility(View.GONE); + rowAdapterNavigationParentBinding.ivIndicators.setVisibility(View.GONE); + rowAdapterNavigationParentBinding.tvDrawerTitle1.setOnClickListener(v -> clickListener.onTagClicked(tagList.get(groupPosition))); } else { - drawerTitle.setVisibility(View.VISIBLE); - nonChildTitle.setOnClickListener(null); - nonChildTitle.setVisibility(View.GONE); - ivIndicator.setVisibility(View.VISIBLE); - setExpandedIcon(isExpanded, ivIndicator); - drawerTitle.setOnClickListener(v -> clickListener.onTagClicked(tagList.get(groupPosition))); + rowAdapterNavigationParentBinding.tvDrawerTitle.setVisibility(View.VISIBLE); + rowAdapterNavigationParentBinding.tvDrawerTitle1.setOnClickListener(null); + rowAdapterNavigationParentBinding.tvDrawerTitle1.setVisibility(View.GONE); + rowAdapterNavigationParentBinding.ivIndicators.setVisibility(View.VISIBLE); + setExpandedIcon(isExpanded, rowAdapterNavigationParentBinding.ivIndicators); + rowAdapterNavigationParentBinding.tvDrawerTitle.setOnClickListener(v -> clickListener.onTagClicked(tagList.get(groupPosition))); } + return convertView; } @@ -131,15 +137,24 @@ private void createCheckbox(View convertView, RealmTag tag) { @Override public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { RealmTag tag = (RealmTag) getChild(groupPosition, childPosition); - convertView = inflateView(parent, R.layout.row_adapter_navigation_child); - TextView tvDrawerTitle = convertView.findViewById(R.id.tv_drawer_title); + + RowAdapterNavigationChildBinding rowAdapterNavigationChildBinding; + if (convertView == null) { + rowAdapterNavigationChildBinding = RowAdapterNavigationChildBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + convertView = rowAdapterNavigationChildBinding.getRoot(); + convertView.setTag(rowAdapterNavigationChildBinding); + } else { + rowAdapterNavigationChildBinding = (RowAdapterNavigationChildBinding) convertView.getTag(); + } + createCheckbox(convertView, tag); - tvDrawerTitle.setText(tag.getName()); - tvDrawerTitle.setOnClickListener(v -> { + rowAdapterNavigationChildBinding.tvDrawerTitle.setText(tag.getName()); + rowAdapterNavigationChildBinding.tvDrawerTitle.setOnClickListener(v -> { if (clickListener != null) { clickListener.onTagClicked(tag); } }); + return convertView; } diff --git a/app/src/main/res/layout/fragment_my_library.xml b/app/src/main/res/layout/fragment_my_library.xml index 7cd21fc223..a9198f85a2 100644 --- a/app/src/main/res/layout/fragment_my_library.xml +++ b/app/src/main/res/layout/fragment_my_library.xml @@ -6,13 +6,11 @@ android:layout_height="match_parent" tools:context=".ui.library.LibraryFragment"> - - - -