Skip to content

Commit

Permalink
Add option to subscribe to app feed
Browse files Browse the repository at this point in the history
  • Loading branch information
tughi committed Jun 17, 2024
1 parent e2d782e commit af20247
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class SubscribeSearchFragment : Fragment(), SubscribeSearchFragmentAdapterListen
private lateinit var urlTextInputLayout: TextInputLayout
private lateinit var urlEditText: EditText
private lateinit var introView: View
private lateinit var subscribeAppFeedHint: View
private lateinit var subscribeAppFeedButton: Button
private lateinit var feedsRecyclerView: RecyclerView

private val adapter = SubscribeSearchFragmentAdapter(this)
Expand Down Expand Up @@ -52,6 +54,8 @@ class SubscribeSearchFragment : Fragment(), SubscribeSearchFragmentAdapterListen
urlTextInputLayout = view.findViewById(R.id.url_wrapper)
urlEditText = urlTextInputLayout.findViewById(R.id.url)
introView = view.findViewById(R.id.intro)
subscribeAppFeedHint = introView.findViewById(R.id.subscribe_app_feed_hint)
subscribeAppFeedButton = introView.findViewById(R.id.subscribe_app_feed)
feedsRecyclerView = view.findViewById(R.id.feeds)

val activity = activity as SubscribeActivity
Expand All @@ -78,6 +82,23 @@ class SubscribeSearchFragment : Fragment(), SubscribeSearchFragmentAdapterListen
requestDocument.launch(arrayOf("*/*"))
}

viewModel.hasNewsFeed.observe(viewLifecycleOwner) { hasNewsFeed ->
val visibility = if (hasNewsFeed) View.GONE else View.VISIBLE
subscribeAppFeedHint.visibility = visibility
subscribeAppFeedButton.visibility = visibility
}

subscribeAppFeedButton.setOnClickListener {
val context = requireContext()
onFeedClicked(
SubscribeSearchFragmentViewModel.Feed(
url = context.getString(R.string.app_feed),
title = context.getString(R.string.app_name),
link = context.getString(R.string.app_site),
)
)
}

if (savedInstanceState == null) {
if (activity.intent.action == Intent.ACTION_SEND) {
if (viewModel.state.value?.url == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.tughi.aggregator.activities.subscribe

import android.database.Cursor
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.tughi.aggregator.App
import com.tughi.aggregator.R
import com.tughi.aggregator.contentScope
import com.tughi.aggregator.data.Feeds
import com.tughi.aggregator.feeds.FeedsFinder
import com.tughi.aggregator.utilities.Failure
import com.tughi.aggregator.utilities.Http
Expand All @@ -24,6 +29,19 @@ class SubscribeSearchFragmentViewModel : ViewModel() {

private var currentFindJob: Job? = null

val hasNewsFeed = MediatorLiveData(true).apply {
addSource(
Feeds.liveQueryOne(
Feeds.UrlCriteria(App.instance.getString(R.string.app_feed)),
object : Feeds.QueryHelper<Long>(Feeds.ID) {
override fun createRow(cursor: Cursor): Long = cursor.getLong(0)
},
)
) {
value = it != null
}
}

fun findFeeds(url: String) {
currentFindJob?.cancel()

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/tughi/aggregator/data/Feeds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ object Feeds : Repository<Feeds.Column, Feeds.TableColumn, Feeds.UpdateCriteria,
}
}

class UrlCriteria(val url: String) : QueryCriteria {
override fun config(query: Query.Builder) {
query.where("f.url = ?", arrayOf(url))
}
}

abstract class QueryHelper<Row>(vararg columns: Column) : Repository.QueryHelper<Column, QueryCriteria, Row>(columns) {
override fun createQueryBuilder(criteria: QueryCriteria) = Query.Builder(columns, "feed f")
.also { criteria.config(it) }
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/res/layout/subscribe_search_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:hint="@string/subscribe_url"
android:hint="@string/subscribe__url__hint"
app:hintAnimationEnabled="false">

<com.google.android.material.textfield.TextInputEditText
Expand Down Expand Up @@ -44,7 +44,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/subscribe_intro"
android:text="@string/subscribe__intro"
android:textAppearance="?textAppearanceBody1" />

<Button
Expand All @@ -55,6 +55,22 @@
android:layout_marginBottom="16dp"
android:text="@string/subscribe__load_opml_file" />

<TextView
android:id="@+id/subscribe_app_feed_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/subscribe__app_feed__hint"
android:textAppearance="?textAppearanceBody1" />

<Button
android:id="@+id/subscribe_app_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text="@string/subscribe__app_feed" />

</LinearLayout>

</ScrollView>
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>

<string name="app_name" translatable="false">Aggregator</string>
<string name="app_site" translatable="false">https://tughi.github.io/aggregator-android</string>
<string name="app_feed" translatable="false">https://tughi.github.io/aggregator-android/news.rss</string>

<string name="action__add_star">Add star</string>
<string name="action__add_rule">Add rule</string>
Expand Down Expand Up @@ -140,8 +142,12 @@
<string name="styling__title">Theme</string>
<string name="styling__bottom_navigation">Bottom navigation</string>

<string name="subscribe_url">Website or feed URL</string>
<string name="subscribe_intro">Content providers, like news sites and blogs, often use feeds as an alternative way to inform readers about new or updated articles.\n\n<b>Aggregator</b> is able to detect if a website is providing such feeds.\n\n\nAdditionally, <b>Aggregator</b> also supports adding feeds from OPML files.</string>
<string name="subscribe__app_feed">Add news feed</string>
<string name="subscribe__app_feed__hint">Stay up to date with latest <b>Aggregator</b> news.</string>
<string name="subscribe__find_feeds">Find feeds</string>
<string name="subscribe__intro">Content providers, like news sites and blogs, often use feeds as an alternative way to inform readers about new or updated articles.\n\n<b>Aggregator</b> is able to detect if a website is providing such feeds.\n\n\nAdditionally, <b>Aggregator</b> also supports adding feeds from OPML files.</string>
<string name="subscribe__load_opml_file">Load OPML file</string>
<string name="subscribe__url__hint">Website or feed URL</string>

<string name="tag_settings">Tag settings</string>
<string name="tag_settings__name">Name</string>
Expand All @@ -159,9 +165,6 @@
<string name="title_feeds">Feeds</string>
<string name="title_tags">Tags</string>

<string name="subscribe__find_feeds">Find feeds</string>
<string name="subscribe__load_opml_file">Load OPML file</string>

<string name="support__title">Support</string>

<string name="unsubscribe_feed__message">Are you sure you want to unsubscribe from this feed and delete all its entries?</string>
Expand Down

0 comments on commit af20247

Please sign in to comment.