diff --git a/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragment.kt b/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragment.kt index da777ac..75ee041 100644 --- a/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragment.kt +++ b/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragment.kt @@ -25,6 +25,7 @@ import com.tughi.aggregator.data.EntriesQueryCriteria import com.tughi.aggregator.data.EntryTags import com.tughi.aggregator.data.TagEntriesQueryCriteria import com.tughi.aggregator.data.Tags +import com.tughi.aggregator.utilities.openURL import kotlinx.coroutines.launch abstract class EntriesFragment : Fragment(), EntriesFragmentAdapterListener, Toolbar.OnMenuItemClickListener { @@ -161,15 +162,19 @@ abstract class EntriesFragment : Fragment(), EntriesFragmentAdapterListener, Too R.id.show_read_entries -> { viewModel.changeShowRead(!item.isChecked) } + R.id.sort_by_date_asc -> { viewModel.changeSortOrder(Entries.SortOrder.ByDateAscending) } + R.id.sort_by_date_desc -> { viewModel.changeSortOrder(Entries.SortOrder.ByDateDescending) } + R.id.sort_by_title -> { viewModel.changeSortOrder(Entries.SortOrder.ByTitle) } + R.id.mark_all_read -> { viewModel.entriesQueryCriteria.value?.let { queryCriteria -> contentScope.launch { @@ -198,6 +203,16 @@ abstract class EntriesFragment : Fragment(), EntriesFragmentAdapterListener, Too requestReadSession.launch(ReaderActivity.ReadSessionInput(viewModel.entriesQueryCriteria.value!!, position)) } + override fun onEntrySelectorClicked(entry: EntriesFragmentViewModel.Entry, position: Int) { + if (entry.link != null) { + requireContext().openURL(entry.link) + + contentScope.launch { + Entries.update(Entries.UpdateEntryCriteria(entry.id), Entries.READ_TIME to System.currentTimeMillis()) + } + } + } + private class SwipeItemTouchHelper : ItemTouchHelper.Callback() { override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int = diff --git a/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentAdapterListener.kt b/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentAdapterListener.kt index 448830d..cf160a5 100644 --- a/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentAdapterListener.kt +++ b/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentAdapterListener.kt @@ -4,4 +4,6 @@ internal interface EntriesFragmentAdapterListener { fun onEntryClicked(entry: EntriesFragmentViewModel.Entry, position: Int) + fun onEntrySelectorClicked(entry: EntriesFragmentViewModel.Entry, position: Int) + } diff --git a/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentViewHolder.kt b/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentViewHolder.kt index a2f1a0f..1e3629d 100644 --- a/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentViewHolder.kt +++ b/app/src/main/java/com/tughi/aggregator/activities/main/EntriesFragmentViewHolder.kt @@ -31,10 +31,15 @@ internal abstract class EntriesFragmentEntryViewHolder(itemView: View, private v private val author: TextView = itemView.findViewById(R.id.author) private val pin: View = itemView.findViewById(R.id.pin) private val star: View = itemView.findViewById(R.id.star) + private val selector: View = itemView.findViewById(R.id.selector) init { itemView.setOnClickListener { - listener.onEntryClicked(item as EntriesFragmentViewModel.Entry, adapterPosition / 2) + listener.onEntryClicked(item as EntriesFragmentViewModel.Entry, bindingAdapterPosition / 2) + } + + selector.setOnClickListener { + listener.onEntrySelectorClicked(item as EntriesFragmentViewModel.Entry, bindingAdapterPosition / 2) } } diff --git a/app/src/main/res/layout/entry_list_entry_placeholder.xml b/app/src/main/res/layout/entry_list_entry_placeholder.xml index 4d17ac8..285e0a1 100644 --- a/app/src/main/res/layout/entry_list_entry_placeholder.xml +++ b/app/src/main/res/layout/entry_list_entry_placeholder.xml @@ -15,6 +15,7 @@ android:id="@+id/selector" android:layout_width="wrap_content" android:layout_height="match_parent" + android:background="?selectableItemBackground" android:paddingStart="?listPreferredItemPaddingLeft" android:paddingEnd="?listPreferredItemPaddingLeft"> diff --git a/app/src/main/res/layout/entry_list_read_entry.xml b/app/src/main/res/layout/entry_list_read_entry.xml index fb5d975..aaf4ded 100644 --- a/app/src/main/res/layout/entry_list_read_entry.xml +++ b/app/src/main/res/layout/entry_list_read_entry.xml @@ -17,6 +17,7 @@ android:id="@+id/selector" android:layout_width="wrap_content" android:layout_height="match_parent" + android:background="?selectableItemBackground" android:paddingStart="?listPreferredItemPaddingLeft" android:paddingEnd="?listPreferredItemPaddingLeft"> diff --git a/app/src/main/res/layout/entry_list_unread_entry.xml b/app/src/main/res/layout/entry_list_unread_entry.xml index 245ddcd..e66de53 100644 --- a/app/src/main/res/layout/entry_list_unread_entry.xml +++ b/app/src/main/res/layout/entry_list_unread_entry.xml @@ -17,6 +17,7 @@ android:id="@+id/selector" android:layout_width="wrap_content" android:layout_height="match_parent" + android:background="?selectableItemBackground" android:paddingStart="?listPreferredItemPaddingLeft" android:paddingEnd="?listPreferredItemPaddingLeft">