Skip to content

Commit af20247

Browse files
committed
Add option to subscribe to app feed
1 parent e2d782e commit af20247

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

app/src/main/java/com/tughi/aggregator/activities/subscribe/SubscribeSearchFragment.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class SubscribeSearchFragment : Fragment(), SubscribeSearchFragmentAdapterListen
2424
private lateinit var urlTextInputLayout: TextInputLayout
2525
private lateinit var urlEditText: EditText
2626
private lateinit var introView: View
27+
private lateinit var subscribeAppFeedHint: View
28+
private lateinit var subscribeAppFeedButton: Button
2729
private lateinit var feedsRecyclerView: RecyclerView
2830

2931
private val adapter = SubscribeSearchFragmentAdapter(this)
@@ -52,6 +54,8 @@ class SubscribeSearchFragment : Fragment(), SubscribeSearchFragmentAdapterListen
5254
urlTextInputLayout = view.findViewById(R.id.url_wrapper)
5355
urlEditText = urlTextInputLayout.findViewById(R.id.url)
5456
introView = view.findViewById(R.id.intro)
57+
subscribeAppFeedHint = introView.findViewById(R.id.subscribe_app_feed_hint)
58+
subscribeAppFeedButton = introView.findViewById(R.id.subscribe_app_feed)
5559
feedsRecyclerView = view.findViewById(R.id.feeds)
5660

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

85+
viewModel.hasNewsFeed.observe(viewLifecycleOwner) { hasNewsFeed ->
86+
val visibility = if (hasNewsFeed) View.GONE else View.VISIBLE
87+
subscribeAppFeedHint.visibility = visibility
88+
subscribeAppFeedButton.visibility = visibility
89+
}
90+
91+
subscribeAppFeedButton.setOnClickListener {
92+
val context = requireContext()
93+
onFeedClicked(
94+
SubscribeSearchFragmentViewModel.Feed(
95+
url = context.getString(R.string.app_feed),
96+
title = context.getString(R.string.app_name),
97+
link = context.getString(R.string.app_site),
98+
)
99+
)
100+
}
101+
81102
if (savedInstanceState == null) {
82103
if (activity.intent.action == Intent.ACTION_SEND) {
83104
if (viewModel.state.value?.url == null) {

app/src/main/java/com/tughi/aggregator/activities/subscribe/SubscribeSearchFragmentViewModel.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.tughi.aggregator.activities.subscribe
22

3+
import android.database.Cursor
4+
import androidx.lifecycle.MediatorLiveData
35
import androidx.lifecycle.MutableLiveData
46
import androidx.lifecycle.ViewModel
7+
import com.tughi.aggregator.App
8+
import com.tughi.aggregator.R
59
import com.tughi.aggregator.contentScope
10+
import com.tughi.aggregator.data.Feeds
611
import com.tughi.aggregator.feeds.FeedsFinder
712
import com.tughi.aggregator.utilities.Failure
813
import com.tughi.aggregator.utilities.Http
@@ -24,6 +29,19 @@ class SubscribeSearchFragmentViewModel : ViewModel() {
2429

2530
private var currentFindJob: Job? = null
2631

32+
val hasNewsFeed = MediatorLiveData(true).apply {
33+
addSource(
34+
Feeds.liveQueryOne(
35+
Feeds.UrlCriteria(App.instance.getString(R.string.app_feed)),
36+
object : Feeds.QueryHelper<Long>(Feeds.ID) {
37+
override fun createRow(cursor: Cursor): Long = cursor.getLong(0)
38+
},
39+
)
40+
) {
41+
value = it != null
42+
}
43+
}
44+
2745
fun findFeeds(url: String) {
2846
currentFindJob?.cancel()
2947

app/src/main/java/com/tughi/aggregator/data/Feeds.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ object Feeds : Repository<Feeds.Column, Feeds.TableColumn, Feeds.UpdateCriteria,
9494
}
9595
}
9696

97+
class UrlCriteria(val url: String) : QueryCriteria {
98+
override fun config(query: Query.Builder) {
99+
query.where("f.url = ?", arrayOf(url))
100+
}
101+
}
102+
97103
abstract class QueryHelper<Row>(vararg columns: Column) : Repository.QueryHelper<Column, QueryCriteria, Row>(columns) {
98104
override fun createQueryBuilder(criteria: QueryCriteria) = Query.Builder(columns, "feed f")
99105
.also { criteria.config(it) }

app/src/main/res/layout/subscribe_search_fragment.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android:layout_marginStart="16dp"
1717
android:layout_marginTop="16dp"
1818
android:layout_marginEnd="16dp"
19-
android:hint="@string/subscribe_url"
19+
android:hint="@string/subscribe__url__hint"
2020
app:hintAnimationEnabled="false">
2121

2222
<com.google.android.material.textfield.TextInputEditText
@@ -44,7 +44,7 @@
4444
android:layout_width="match_parent"
4545
android:layout_height="wrap_content"
4646
android:layout_marginTop="8dp"
47-
android:text="@string/subscribe_intro"
47+
android:text="@string/subscribe__intro"
4848
android:textAppearance="?textAppearanceBody1" />
4949

5050
<Button
@@ -55,6 +55,22 @@
5555
android:layout_marginBottom="16dp"
5656
android:text="@string/subscribe__load_opml_file" />
5757

58+
<TextView
59+
android:id="@+id/subscribe_app_feed_hint"
60+
android:layout_width="match_parent"
61+
android:layout_height="wrap_content"
62+
android:layout_marginTop="16dp"
63+
android:text="@string/subscribe__app_feed__hint"
64+
android:textAppearance="?textAppearanceBody1" />
65+
66+
<Button
67+
android:id="@+id/subscribe_app_feed"
68+
android:layout_width="match_parent"
69+
android:layout_height="wrap_content"
70+
android:layout_marginTop="16dp"
71+
android:layout_marginBottom="16dp"
72+
android:text="@string/subscribe__app_feed" />
73+
5874
</LinearLayout>
5975

6076
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<resources>
22

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

57
<string name="action__add_star">Add star</string>
68
<string name="action__add_rule">Add rule</string>
@@ -140,8 +142,12 @@
140142
<string name="styling__title">Theme</string>
141143
<string name="styling__bottom_navigation">Bottom navigation</string>
142144

143-
<string name="subscribe_url">Website or feed URL</string>
144-
<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>
145+
<string name="subscribe__app_feed">Add news feed</string>
146+
<string name="subscribe__app_feed__hint">Stay up to date with latest <b>Aggregator</b> news.</string>
147+
<string name="subscribe__find_feeds">Find feeds</string>
148+
<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>
149+
<string name="subscribe__load_opml_file">Load OPML file</string>
150+
<string name="subscribe__url__hint">Website or feed URL</string>
145151

146152
<string name="tag_settings">Tag settings</string>
147153
<string name="tag_settings__name">Name</string>
@@ -159,9 +165,6 @@
159165
<string name="title_feeds">Feeds</string>
160166
<string name="title_tags">Tags</string>
161167

162-
<string name="subscribe__find_feeds">Find feeds</string>
163-
<string name="subscribe__load_opml_file">Load OPML file</string>
164-
165168
<string name="support__title">Support</string>
166169

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

0 commit comments

Comments
 (0)