Skip to content

Commit

Permalink
Add option to open entry in the browser
Browse files Browse the repository at this point in the history
Resolves #75
  • Loading branch information
tughi committed Jun 16, 2024
1 parent 3b1ef2a commit 94e9837
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ internal interface EntriesFragmentAdapterListener {

fun onEntryClicked(entry: EntriesFragmentViewModel.Entry, position: Int)

fun onEntrySelectorClicked(entry: EntriesFragmentViewModel.Entry, position: Int)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/entry_list_entry_placeholder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/entry_list_read_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/entry_list_unread_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

Expand Down

0 comments on commit 94e9837

Please sign in to comment.