news: make Local show only the user's set place
- Commit
6b20edbf798034c5f26e2fa0136c1977a0cc1610- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 02:25 UTC (4 days ago)
- Parents
07c9c76
Local was a boost, not a filter: selecting Local showed the catalog's whole Local bucket (364 outlets worldwide), and with a location set NewsViewModel only partitioned matching stories first, leaving every other local source in the feed. Search within Local filtered by catalog tag only. The owner reported Local serving clearly non-local news. Fix: SourceCatalog.matchesFeedFilter / Story.matchesFeedFilter are now the feed and search filter. Local passes only when a source's catalog region matches the manually set location (Settings -> Route.LocalLocation via NewsPrefs, never device location); with no location set Local is empty. FeedScreen shows an honest empty message for both cases (no location set / no downloaded news from the set place) instead of substituting national or world news. The old boost helpers (LocalNews.matchingFirst, orderedForLocal) are removed. LocalNews.matches also requires the trailing country to agree when both sides are hierarchical, so same-named places in different countries (Georgia, Florida) never match. Catalog: nine harvested rows were mistagged as US-state Local from name matching alone - seven .ge Georgia-country feeds (apsny, frontnews, news-3, georgiatoday, eng-ghn, kvirispalitra, netgazeti) plus the Georgian-language resonancedaily, all as 'Georgia, United States', and the Cuban radioflorida-icrt (.icrt.cu) as 'Florida, United States'. They are now World with no region; the TSV was edited and source_catalog.tsv.br regenerated, with the frozen catalog tests updated (Local 364 -> 355, World 9544 -> 9553). Tests pin: a source in the user's metro (latimes/laist for Los Angeles) and statewide outlet (calmatters) included under both city and state picks, a distant city (block-club/Chicago) and a world source (bbc) excluded, no-location behaviour empty at domain, ViewModel (feed + search), and UI levels, and the country-agreement rule. Verified in the worktree: ./gradlew :news:lint (green), :news:lintVitalRelease (in the graph; Gradle SKIPPED the vital report task), :news:testDevUnitTest (91 tests, 0 failures).
Diff
news/AGENTS.md
diff --git a/news/AGENTS.md b/news/AGENTS.mdindex a334ab2e46..fafc51899a 100644--- a/news/AGENTS.md+++ b/news/AGENTS.md@@ -50,6 +50,19 @@ source names, sitemap keywords, downloaded bodies (`domain/NewsSearch`). is the whole scale-up procedure. A missing or corrupt asset loads as an empty catalog (server feed and cached articles keep working; a malformed row drops only that source).+- Local category (`domain/LocalNews`, `SourceCatalog.matchesFeedFilter`):+ the Local chip is a filter to the user's manually set location+ (Settings → `Route.LocalLocation`, persisted by `NewsPrefs`; never+ device location), not the catalog's whole Local bucket. A source+ passes only when its catalog `region` matches the set location+ component-wise with the trailing country in agreement (a city pick+ also passes statewide outlets of its state, and vice versa). With no+ location set, or no matching downloaded source, Local is empty with+ an honest feed message — national/world/other-local news is never+ substituted. Search within Local applies the same filter. Catalog+ `region` is present on every Local-tagged source and on no other+ source; non-US outlets harvested under a same-named US state (e.g.+ `.ge` Georgia-country feeds) are World, not Local. - Room-cached feed + extracted article bodies (offline reading), bookmarks - Readability-style extraction in `domain/ArticleExtractor` over a small tolerant HTML DOM (`domain/HtmlDom`); reader with text size, serif/sans
news/catalog/source_catalog.tsv
diff --git a/news/catalog/source_catalog.tsv b/news/catalog/source_catalog.tsvindex 06bd8b4193..6384c769a5 100644--- a/news/catalog/source_catalog.tsv+++ b/news/catalog/source_catalog.tsv@@ -191,7 +191,7 @@ anyksta Anyksta https://www.anyksta.lt/sitemap.xml S W ;; apanews APA News: Com apa APA.AZ- Azərbaycan və dünyadan ən son xəbərlər https://apa.az/rss R az W ;; en-apa APA.AZ- Latest news from Azerbaijan and the world https://en.apa.az/rss R W apfdigital Apfdigital http://www.apfdigital.com.ar/sitemap-news.xml S es W ;; apgazeta Apgazeta https://apgazeta.kz/news-sitemap.xml S W apk-inform Apk Inform https://www.apk-inform.com/sitemap.xml S W ;; appnoticias APP – Agencia de noticias Patagónica https://appnoticias.com.ar/app/feed/ R es W-appleinsider AppleInsider News https://appleinsider.com/rss/news/ R T ;; aps APS https://www.aps.dz/sitemap.xml S W ;; apsny Apsny https://apsny.ge/sitemap.xml S L Georgia, United States+appleinsider AppleInsider News https://appleinsider.com/rss/news/ R T ;; aps APS https://www.aps.dz/sitemap.xml S W ;; apsny Apsny https://apsny.ge/sitemap.xml S W aqparat Aqparat https://aqparat.info/sitemap.xml S W ;; arabalears Ara Balears https://www.arabalears.cat/rss/ R es W ;; en-ara Ara in English https://en.ara.cat/rss/ R es W M ara Ara.cat - Portada https://www.ara.cat/rss/ R es W ;; aradon Aradon https://www.aradon.ro/feed/ R W ;; aragondigital Aragón Digital :: Últimas noticias https://www.aragondigital.es/rss/ R es T araratadvertiser Araratadvertiser https://www.araratadvertiser.com.au/sitemap.xml S W ;; arbejderen Arbejderen http://www.arbejderen.dk/sitemap_index.xml S da W@@ -893,7 +893,7 @@ freepresskashmir Freepresskashmir https://freepresskashmir.news/sitemap.xml S W fri-kopenskap Fri Kopenskap https://www.fri-kopenskap.se/sitemap.xml S sv W ;; friatider Fria Tider https://www.friatider.se/rss.xml R sv W thefridaytimes Friday Times http://www.thefridaytimes.com/sitemap.xml S W ;; frifagbevegelse Frifagbevegelse https://www.frifagbevegelse.no/sitemap.xml S nb W frognews Frognews https://frognews.bg/sitemap.xml S bg W ;; frolendingen Frolendingen http://www.frolendingen.no/sitemap.xml S nb W ;; from-ua From UA https://from-ua.org/sitemap.xml S W-frontnews Front News Georgia https://frontnews.ge/news-sitemap.xml S L Georgia, United States ;; frontenet Frontenet https://www.frontenet.com/rss/feed.xml R es W+frontnews Front News Georgia https://frontnews.ge/news-sitemap.xml S W ;; frontenet Frontenet https://www.frontenet.com/rss/feed.xml R es W frontpageafricaonline FrontPage Africa https://www.frontpageafricaonline.com/news-sitemap.xml S W ;; frettatiminn Fréttatíminn http://www.frettatiminn.is/news-sitemap.xml S W fsuthevoice Fsuthevoice http://www.fsuthevoice.com/sitemap.xml S L North Carolina, United States fuenlabradanoticias Fuenlabrada Noticias - Última hora :: Últimas noticias https://www.fuenlabradanoticias.com/rss/ R W@@ -919,16 +919,16 @@ gazetatema Gazetatema https://www.gazetatema.net/sitemap.xml S W ;; gazetavv Ga gazeteoku Gazeteoku https://www.gazeteoku.com/rss R tr W ;; ilkleygazette Gazette & Observer https://www.ilkleygazette.co.uk/news-sitemap.xml/ S W gazetteandherald Gazetteandherald https://www.gazetteandherald.co.uk/news-sitemap.xml/ S W ;; gazzetta Gazzetta https://www.gazzetta.gr/sitemap.xml S el W gbnews Gbnews https://www.gbnews.com/sitemap.xml S W ;; gbtimes Gbtimes https://gbtimes.com/sitemap.xml S W ;; gds GDS https://gds.it/sitemap-news.xml S it W-gds-2 GDS (ro) https://gds.ro/sitemap-news.xml S ro W ;; news-3 GE https://news.ge/sitemap.xml S L Georgia, United States+gds-2 GDS (ro) https://gds.ro/sitemap-news.xml S ro W ;; news-3 GE https://news.ge/sitemap.xml S W gebzegazetesi Gebzegazetesi https://www.gebzegazetesi.com/sitemap.xml S W ;; geeky-com Geeky Nigeria https://geeky.com.ng/news-sitemap.xml S W geelongadvertiser Geelongadvertiser https://www.geelongadvertiser.com.au/news-sitemap.xml S W ;; generaccion Generaccion http://www.generaccion.com/sitemap.xml S W giz General-Anzeiger https://www.giz.de/de/sitemap.xml S de W ;; geopolitika Geopolitika News https://www.geopolitika.news/feed/ R hr W georgeherald George Herald https://www.georgeherald.com/feed R W ;; gulawweekly Georgetown Law Weekly https://www.gulawweekly.org/sitemap.xml S U foursquare Georgia Today https://foursquare.com/sitemap.xml S L Georgia, United States ;; georgiaencyclopedia Georgiaencyclopedia http://www.georgiaencyclopedia.org/sitemap.xml S W-georgiatoday Georgiatoday https://georgiatoday.ge/sitemap.xml S L Georgia, United States ;; germistoncitynews Germistoncitynews https://germistoncitynews.co.za/sitemap_index.xml S W+georgiatoday Georgiatoday https://georgiatoday.ge/sitemap.xml S W ;; germistoncitynews Germistoncitynews https://germistoncitynews.co.za/sitemap_index.xml S W gfcnieuws Gfcnieuws https://www.gfcnieuws.com/sitemap-news.xml S W ;; ghanaguardian Ghanaguardian.com – Ghana News https://ghanaguardian.com/feed/ R W ghananewspage Ghananewspage https://ghananewspage.com/sitemap.xml S W ;; ghanastar Ghanastar https://www.ghanastar.com/sitemap.xml S W-ghettopost Ghettopost https://ghettopost.com/sitemap.xml S W ;; eng-ghn GHN https://eng.ghn.ge/rss R L Georgia, United States+ghettopost Ghettopost https://ghettopost.com/sitemap.xml S W ;; eng-ghn GHN https://eng.ghn.ge/rss R W giadinh-suckhoedoisong Giadinh Suckhoedoisong https://giadinh.suckhoedoisong.vn/sitemap.xml S vi W ;; chronicle Gibraltar Chronicle http://www.chronicle.gi/sitemap.xml S W gistlover Gistlover https://www.gistlover.com/sitemap.xml S W ;; glasistre Glas Istre https://www.glasistre.hr/rss.xml R W ;; glas-slavonije Glas Slavonije https://www.glas-slavonije.hr/rss.xml R W glavnoe Glavnoe http://www.glavnoe.ua/sitemap_index.xml S uk W ;; gleninnesexaminer Glen Innes Examiner - Local News https://www.gleninnesexaminer.com.au/rss.xml R W@@ -1232,7 +1232,7 @@ ksml Ksml https://www.ksml.fi/sitemap.xml S fi W ;; ksnmedia Ksnmedia https://ks ktpress Ktpress https://ktpress.rw/sitemap_index.xml S W ;; kul-alarab Kul Alarab https://www.kul-alarab.com/sitemap-news.xml S U kultura-portal Kultura https://kultura-portal.ru/sitemap.xml S ru W ;; kun KUN https://kun.uz/news-sitemap.xml S W ;; kurier Kurier https://kurier.at/xml/rss R de W kurierlubelski Kurier Lubelski https://kurierlubelski.pl/rss R pl W ;; poranny Kurier Poranny https://poranny.pl/rss R pl W-kurierwilenski Kurier Wileński https://www.kurierwilenski.lt/news-sitemap.xml S W ;; kvirispalitra Kvirispalitra https://kvirispalitra.ge/sitemap.xml S L Georgia, United States+kurierwilenski Kurier Wileński https://www.kurierwilenski.lt/news-sitemap.xml S W ;; kvirispalitra Kvirispalitra https://kvirispalitra.ge/sitemap.xml S W kwnews-co Kwnews https://www.kwnews.co.kr/sitemap.xml S ko W ;; kyeonggi Kyeonggi http://kyeonggi.com/sitemap.xml S W ;; kyeongin Kyeongin https://www.kyeongin.com/sitemap.xml S W kyivindependent Kyivindependent https://kyivindependent.com/news-sitemap.xml S W ;; kyivpost Kyivpost https://www.kyivpost.com/news-sitemap.xml S W kymensanomat Kymensanomat https://www.kymensanomat.fi/sitemap.xml S fi W ;; ksilbo-co Kyungsang Ilbo http://www.ksilbo.co.kr/sitemap.xml S ko W@@ -1584,7 +1584,7 @@ necocheanews Necocheanews http://necocheanews.com.ar/sitemap.xml S es W ;; negos ndb-online Negros Daily Bulletin https://www.ndb-online.com/sitemap.xml S W ;; nehandaradio Nehandaradio https://nehandaradio.com/sitemap-news.xml S W nelspruitpost Nelspruitpost https://nelspruitpost.co.za/sitemap_index.xml S W ;; nemzetisport Nemzetisport https://www.nemzetisport.hu/news_sitemap.xml S hu W ratopati Nepal's first 24-hour updated news portal - Ratopati https://www.ratopati.com/feed R W ;; nepalitimes Nepali Times https://nepalitimes.com/feed R W-nepszava Nepszava https://nepszava.hu/sitemap.xml S hu W ;; net NET https://net.hr/news-sitemap.xml S W ;; netgazeti Netgazeti https://netgazeti.ge/news-sitemap.xml S L Georgia, United States+nepszava Nepszava https://nepszava.hu/sitemap.xml S hu W ;; net NET https://net.hr/news-sitemap.xml S W ;; netgazeti Netgazeti https://netgazeti.ge/news-sitemap.xml S W netnews-com Netnews https://netnews.com.mt/sitemap.xml S W ;; netnoticias Netnoticias https://netnoticias.mx/sitemap-news.xml S es W neue-zeitung Neue Zeitung https://neue-zeitung.hu/sitemap.xml S hu W ;; nzz Neue Zürcher Zeitung https://www.nzz.ch/sitemap/news0.xml S de W neuquen24horas Neuquen24horas https://neuquen24horas.com/sitemap.xml S W ;; neuquenalinstante Neuquenalinstante http://www.neuquenalinstante.com.ar/sitemap-news.xml S es W@@ -1920,7 +1920,7 @@ bnrnews Radio Bulgaria – BNR https://bnrnews.bg/sitemap.xml S bg W ;; cadenagr radiocafayate Radio Cafayate http://www.radiocafayate.com/?feed=rss2 R es W ;; rcm Radio Ciudad del Mar, desde Cienfuegos, Cuba https://www.rcm.cu/feed/ R es W continental Radio Continental http://www.continental.com.ar/sitemap.xml S es W ;; radiocoral-icrt Radio Coral https://www.radiocoral.icrt.cu/sitemap.xml S W radio-corporacion Radio Corporacion https://radio-corporacion.com/sitemap.xml S W ;; radiocumanayagua-icrt Radio Cumanayagua https://www.radiocumanayagua.icrt.cu/sitemap.xml S W-evropaelire Radio Evropa e Lirë https://www.evropaelire.org/api/ R sq W ;; radioflorida-icrt Radio Florida https://www.radioflorida.icrt.cu/sitemap.xml S L Florida, United States+evropaelire Radio Evropa e Lirë https://www.evropaelire.org/api/ R sq W ;; radioflorida-icrt Radio Florida https://www.radioflorida.icrt.cu/sitemap.xml S W radiofarda Radio Free Europe / Radio Liberty https://www.radiofarda.com/api/ R fa W ;; rferl Radio Free Europe / Radio Liberty (EN) https://www.rferl.org/api/ R W radioformula Radio Fórmula https://www.radioformula.com.mx/rss/feed.xml R es W ;; radiojuvenil-icrt Radio Juvenil https://www.radiojuvenil.icrt.cu/?format=feed&type=rss R es W radiomhumahuaca Radio M http://www.radiomhumahuaca.com.ar/sitemap.xml S es W ;; radiomayabeque-icrt Radio Mayabeque https://www.radiomayabeque.icrt.cu/sitemap.xml S W@@ -2726,7 +2726,7 @@ anbaatlas وكالة أنباء أطلس https://anbaatlas.com/rss.xml R ar W ;; kabulpress کابل پرس: خبری، تحليلی و انتقادی https://kabulpress.org/sitemap.xml S W ;; nepalipost नेपालीपोष्ट http://nepalipost.com/beta/feed R W crimebarta ক্রাইম বার্তা https://crimebarta.com/feed/ R W ;; purbanchal দৈনিক পূর্বাঞ্চল https://purbanchal.com/feed/ R W naewna สำนักข่าวแนวหน้า มั่นคง ตรงไป ตรงมา https://www.naewna.com/n/feed/ R th W-resonancedaily გაზეთ რეზონანსის ინტერნეტ-პორტალი http://www.resonancedaily.com/sitemap.xml S L Georgia, United States+resonancedaily გაზეთ რეზონანსის ინტერნეტ-პორტალი http://www.resonancedaily.com/sitemap.xml S W thetidenewsonline …The Tide News Online:::… https://www.thetidenewsonline.com/feed/ R W ;; saipantribune ❯ https://www.saipantribune.com/index.php/feed/ R W 81 中国军网/中国军网 http://www.81.cn/rss.xml R zh W ;; leovan 中文博客 on 范叶亮 https://leovan.me/cn/index.xml R zh-HANS W ;; tcnn-org 台灣教會公報新聞網 https://tcnn.org.tw/en/feed R W visiontimesjp 看中国 / VisionTimesJP https://www.visiontimesjp.com/?feed=rss2 R ja W ;; secretchina 看中國 http://www.secretchina.com https://www.secretchina.com/news/gb/news.xml R W
news/src/main/java/com/vayunmathur/news/data/NewsPrefs.kt
diff --git a/news/src/main/java/com/vayunmathur/news/data/NewsPrefs.kt b/news/src/main/java/com/vayunmathur/news/data/NewsPrefs.ktindex 71f7260d8c..fcb6200af5 100644--- a/news/src/main/java/com/vayunmathur/news/data/NewsPrefs.kt+++ b/news/src/main/java/com/vayunmathur/news/data/NewsPrefs.kt@@ -39,8 +39,8 @@ class NewsPrefs(context: Context) { /** * Manually picked Local news location (a catalog region string or a- * free place name the user typed); null when unset, in which case all- * local sources are equal. This is a preference only — never device+ * free place name the user typed); null when unset, in which case+ * Local shows nothing. This is a preference only — never device * location. Blank stored values read as unset. */ val localLocation: Flow<String?> = safeData.map { it[LOCAL_LOCATION]?.takeIf { v -> v.isNotBlank() } }
news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt b/news/src/main/java/com/vayunmathur/news/domain/LocalNews.ktindex c8e9435ce7..d1eed1a5e7 100644--- a/news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt@@ -10,6 +10,12 @@ package com.vayunmathur.news.domain * typed alone matches its cities, and a city pick also matches statewide * outlets for that state. *+ * Local is a *filter*, not a boost: the Local category shows only+ * sources whose region matches this location (see+ * [SourceCatalog.matchesFeedFilter]). With no location set, or with no+ * matching source, Local is empty — national/world/other-local news is+ * never substituted into it.+ * * Server contract unchanged: `news.json` carries no region (or category) * field; region is resolved client-side from [SourceCatalog] by source * id, exactly like categories (see [SourceCatalog.regionOf]).@@ -18,46 +24,43 @@ object LocalNews { /** Country (last comma component) of [region], or null when blank. */ fun countryOf(region: String?): String? =- region?.split(",")?.lastOrNull()?.trim()?.takeIf { it.isNotEmpty() }+ region?.split(",")?.map { it.trim() }?.lastOrNull()?.takeIf { it.isNotEmpty() } /** * Whether a source from [sourceRegion] is "from" [location].- * Null/blank on either side never matches (an unset location boosts- * nothing, and a region-less source is never boosted).+ * Null/blank on either side never matches (an unset location matches+ * nothing, and a region-less source is never local). *- * Rule: drop the trailing country component from both sides when a- * comma hierarchy is present (country alone is not local enough to- * boost), then a match is any remaining component of one side that- * exactly equals a component of the other side. Components compare- * as whole token sets, never by subset: "Virginia" must not match- * "West Virginia", and "York" must not match "New York", however- * many tokens they share. Exact equality still makes "California"- * match both "California, United States" and "Los Angeles,- * California, United States", and "Los Angeles, California, United- * States" match the statewide "California, United States" (its- * California component), because those share a whole component.+ * Rule: when both sides carry a comma hierarchy, their trailing+ * country components must agree first — so "Georgia" the country+ * never matches "Georgia, United States", and a Florida in one+ * country never matches Florida in another. Then, with the country+ * dropped (country alone is not local enough), a match is any+ * remaining component of one side that exactly equals a component+ * of the other side. Components compare as whole token sets, never+ * by subset: "Virginia" must not match "West Virginia", and "York"+ * must not match "New York". Exact equality still makes+ * "California" match both "California, United States" and+ * "Los Angeles, California, United States", and a city pick match+ * the statewide "California, United States" outlet. */ fun matches(sourceRegion: String?, location: String?): Boolean {+ val chosenCountry = hierarchicalCountry(location)+ val regionCountry = hierarchicalCountry(sourceRegion)+ if (chosenCountry != null && regionCountry != null && chosenCountry != regionCountry) {+ return false+ } val chosen = specificComponents(location) val region = specificComponents(sourceRegion) if (chosen.isEmpty() || region.isEmpty()) return false return chosen.any { c -> region.any { r -> c == r } } } - /**- * Stable partition: items whose region matches [location] first, in- * their original (already ranked) order, then the rest unchanged.- * A null/blank [location] returns [items] untouched, so the unset- * behaviour is exactly the pre-feature feed order.- */- fun <T> matchingFirst(- items: List<T>,- location: String?,- regionOf: (T) -> String?,- ): List<T> {- if (location.isNullOrBlank() || items.isEmpty()) return items- val (matching, rest) = items.partition { matches(regionOf(it), location) }- return matching + rest+ /** Normalised country component, only when [value] is a comma hierarchy. */+ private fun hierarchicalCountry(value: String?): Set<String>? {+ if (value.isNullOrBlank()) return null+ val parts = value.split(",").map { normalise(it) }.filter { it.isNotEmpty() }+ return if (parts.size > 1) parts.last().split(" ").toSet() else null } /** Normalised token-set components, country component dropped when hierarchical. */@@ -76,7 +79,3 @@ object LocalNews { .trim() .replace(Regex("\\s+"), " ") }--/** [articles] reordered for the Local feed: chosen-location sources first. */-fun List<FeedArticle>.orderedForLocal(location: String?): List<FeedArticle> =- LocalNews.matchingFirst(this, location) { SourceCatalog.regionOf(it.sourceId) }
news/src/main/java/com/vayunmathur/news/domain/NewsCategory.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/NewsCategory.kt b/news/src/main/java/com/vayunmathur/news/domain/NewsCategory.ktindex 850f412c71..7dd952f4f7 100644--- a/news/src/main/java/com/vayunmathur/news/domain/NewsCategory.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/NewsCategory.kt@@ -27,6 +27,13 @@ package com.vayunmathur.news.domain * matches a selected category when the category is among its source's * tags. *+ * One exception at *filter* time (not assignment time): [LOCAL] is a+ * tag on city/metro/state/regional outlets worldwide, but selecting+ * Local in the feed does not show that whole bucket. It shows only+ * outlets whose [NewsSource.region] matches the user's manually set+ * Local location (see [SourceCatalog.matchesFeedFilter] and+ * [LocalNews]); with no location set, Local shows nothing.+ * * Server `news.json` carries no category field. Articles inherit their * category client-side: the server's `source` value is resolved to a * catalog id by [ServerFeedParser] (id or exact display name), and the
news/src/main/java/com/vayunmathur/news/domain/SourceCatalog.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/SourceCatalog.kt b/news/src/main/java/com/vayunmathur/news/domain/SourceCatalog.ktindex d7cbd238e3..c1147a64f3 100644--- a/news/src/main/java/com/vayunmathur/news/domain/SourceCatalog.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/SourceCatalog.kt@@ -100,6 +100,22 @@ object SourceCatalog { fun matchesLocalLocation(sourceId: String, location: String?): Boolean = LocalNews.matches(regionOf(sourceId), location) + /**+ * The feed/search filter actually shown to the user. "All" (null)+ * passes everything; a non-Local category is the plain catalog-tag+ * match; [NewsCategory.LOCAL] is *not* the catalog's Local bucket —+ * it passes only when the source's region matches the user's set+ * [location] (and therefore also nothing at all when no location is+ * set). A Local-tagged source from a different city/state/country+ * never passes, and neither does a national/world source.+ */+ fun matchesFeedFilter(sourceId: String, category: NewsCategory?, location: String?): Boolean =+ when (category) {+ null -> true+ NewsCategory.LOCAL -> matchesLocalLocation(sourceId, location)+ else -> category in categoriesOf(sourceId)+ }+ /** Categories present among [sources], in taxonomy order. */ fun categoriesAmong(sources: List<NewsSource>): List<NewsCategory> = NewsCategory.entries.filter { category -> sources.any { category in it.categories } }@@ -149,3 +165,11 @@ object SourceCatalog { /** [articles] kept to [category] via their sources' catalog tags; null keeps all. */ fun List<FeedArticle>.inCategory(category: NewsCategory?): List<FeedArticle> = filter { SourceCatalog.matchesCategory(it.sourceId, category) }++/**+ * [articles] kept to the user-facing feed filter ([SourceCatalog.matchesFeedFilter]):+ * like [inCategory], except Local means "from the user's [location]" and+ * keeps nothing when no location is set.+ */+fun List<FeedArticle>.inFeedFilter(category: NewsCategory?, location: String?): List<FeedArticle> =+ filter { SourceCatalog.matchesFeedFilter(it.sourceId, category, location) }
news/src/main/java/com/vayunmathur/news/domain/Story.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/Story.kt b/news/src/main/java/com/vayunmathur/news/domain/Story.ktindex 5589cce6f3..3d54d99e94 100644--- a/news/src/main/java/com/vayunmathur/news/domain/Story.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/Story.kt@@ -68,6 +68,16 @@ data class Story( /** Whether any member's source matches [category] (null = All). */ fun matchesCategory(category: NewsCategory?): Boolean = category == null || articles.any { SourceCatalog.matchesCategory(it.sourceId, category) }++ /**+ * Whether this story belongs in the feed for [category] as the user+ * sees it ([SourceCatalog.matchesFeedFilter]): for Local, any member+ * whose source region matches the user's [location]; with no+ * location set, no story is Local.+ */+ fun matchesFeedFilter(category: NewsCategory?, location: String?): Boolean =+ category == null ||+ articles.any { SourceCatalog.matchesFeedFilter(it.sourceId, category, location) } } /**
news/src/main/java/com/vayunmathur/news/platform/NewsViewModel.kt
diff --git a/news/src/main/java/com/vayunmathur/news/platform/NewsViewModel.kt b/news/src/main/java/com/vayunmathur/news/platform/NewsViewModel.ktindex 5692b81b2a..30eddb3a11 100644--- a/news/src/main/java/com/vayunmathur/news/platform/NewsViewModel.kt+++ b/news/src/main/java/com/vayunmathur/news/platform/NewsViewModel.kt@@ -13,7 +13,6 @@ import com.vayunmathur.news.domain.ExtractedArticle import com.vayunmathur.news.domain.FeedRanking import com.vayunmathur.news.domain.NewsCategory import com.vayunmathur.news.domain.SourceCatalog-import com.vayunmathur.news.domain.LocalNews import com.vayunmathur.news.domain.Story import com.vayunmathur.news.domain.StoryGrouping import com.vayunmathur.news.domain.orderedBySearchHits@@ -76,9 +75,9 @@ class NewsViewModel( * results without a new search. */ val searchResults: StateFlow<List<CachedArticle>> = combine(- _searchResults, _categoryFilter,- ) { results, category ->- results.filter { SourceCatalog.matchesCategory(it.sourceId, category) }+ _searchResults, _categoryFilter, localLocation,+ ) { results, category, location ->+ results.filter { SourceCatalog.matchesFeedFilter(it.sourceId, category, location) } }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) /** Search hits expanded to their whole stories, relevance order kept. */@@ -106,20 +105,15 @@ class NewsViewModel( } } - /** Feed stories: mechanical grouping, category = any-member, ordered (order only). */+ /**+ * Feed stories: mechanical grouping, filter = any-member via+ * [Story.matchesFeedFilter] (Local = any member from the user's set+ * location only; unset location makes Local empty), then ranked.+ */ val stories: StateFlow<List<Story>> = combine( allStories, _categoryFilter, localLocation, ) { grouped, category, location ->- val filtered = grouped.filter { it.matchesCategory(category) }- val ranked = FeedRanking.rankGroupedStories(filtered)- if (category == NewsCategory.LOCAL && !location.isNullOrBlank()) {- val (matching, rest) = ranked.partition { story ->- story.articles.any { LocalNews.matches(SourceCatalog.regionOf(it.sourceId), location) }- }- matching + rest- } else {- ranked- }+ FeedRanking.rankGroupedStories(grouped.filter { it.matchesFeedFilter(category, location) }) }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) /** Cached lookup by article URL, for story cards/pages. */
news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt
diff --git a/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt b/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.ktindex 4d187fdc22..f10df32aff 100644--- a/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt+++ b/news/src/main/java/com/vayunmathur/news/ui/FeedScreen.kt@@ -158,10 +158,18 @@ internal fun FeedContent( ) } if (shownStories.isEmpty() && !isRefreshing) {- Text(- stringResource(if (searching) R.string.feed_search_empty else R.string.feed_empty),- modifier = Modifier.padding(16.dp),- )+ // Local is honest when empty: no location set, or a set+ // location with no matching downloaded sources — never a+ // silent fall-back to national/world/other-local news.+ val emptyText = when {+ searching -> stringResource(R.string.feed_search_empty)+ categoryFilter == NewsCategory.LOCAL && localLocation.isNullOrBlank() ->+ stringResource(R.string.feed_local_no_location)+ categoryFilter == NewsCategory.LOCAL ->+ stringResource(R.string.feed_local_empty, localLocation!!)+ else -> stringResource(R.string.feed_empty)+ }+ Text(emptyText, modifier = Modifier.padding(16.dp)) } // Wide windows get story cards in as many ~280dp columns as fit // (in the two-pane list pane that collapses back to one column);
news/src/main/res/values/strings.xml
diff --git a/news/src/main/res/values/strings.xml b/news/src/main/res/values/strings.xmlindex 75c3672327..80292369f0 100644--- a/news/src/main/res/values/strings.xml+++ b/news/src/main/res/values/strings.xml@@ -14,14 +14,16 @@ <string name="reader_sans">Sans</string> <string name="reader_loading_failed">Could not load this article.</string> <string name="feed_local_with_location">Local · %1$s</string>+ <string name="feed_local_no_location">No local location is set, so Local is empty. Set your place in Settings to see news from your area — Local never substitutes national or world news.</string>+ <string name="feed_local_empty">No downloaded news from %1$s yet. Pull to refresh, or pick a wider place (for example your state or region) in Settings.</string> <!-- SettingsScreen --> <string name="settings_title">Settings</string> <string name="settings_note">Reader text options are in the reader.</string> <!-- LocalLocationScreen / SettingsScreen setting --> <string name="local_location_title">Local news location</string>- <string name="local_location_note">Choose where Local news should come from first. Sources from your location appear first in Local; other local sources still follow. This is only a preference — the app never uses your device location.</string>+ <string name="local_location_note">Choose where Local news comes from. Local shows only sources from that place; other places are not mixed in. This is only a preference — the app never uses your device location.</string> <string name="local_location_search_placeholder">Search or type a place</string>- <string name="local_location_unset">Not set — all local sources are equal</string>+ <string name="local_location_unset">Not set — Local is empty until you choose a place</string> <string name="local_location_current">Current: %1$s</string> <string name="local_location_clear">Tap to clear</string> <string name="local_location_use_typed">Use “%1$s”</string>
news/src/main/resources/source_catalog.tsv.br
diff --git a/news/src/main/resources/source_catalog.tsv.br b/news/src/main/resources/source_catalog.tsv.brindex 7be2f89562..e61b39aad1 100644Binary files a/news/src/main/resources/source_catalog.tsv.br and b/news/src/main/resources/source_catalog.tsv.br differ
news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt b/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.ktindex 3b6bec9f94..996e5398df 100644--- a/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt+++ b/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt@@ -10,8 +10,9 @@ class LocalNewsTest { @Test fun everyLocalSourceCarriesARegionAndNonLocalCarryNone() { val locals = SourceCatalog.sources.filter { NewsCategory.LOCAL in it.categories }- // 36 curated + 328 generated (curate.py + curate_r2.py provenance).- assertEquals(364, locals.size)+ // 36 curated + 319 generated (curate.py + curate_r2.py provenance;+ // 9 Georgian-country / Cuban rows reclassified to World, below).+ assertEquals(355, locals.size) for (source in locals) { assertTrue(!source.region.isNullOrBlank(), "${source.id} has no region") }@@ -87,25 +88,66 @@ class LocalNewsTest { private fun article(sourceId: String) = FeedArticle(url = "https://e/$sourceId", sourceId = sourceId, title = "Story $sourceId", publishedAtMillis = 1L) - @Test fun localOrderingPutsChosenLocationFirstStablyThenOthers() {+ @Test fun samePlaceNameInDifferentCountriesNeverMatches() {+ // Georgia the country vs Georgia the US state, Florida in Cuba vs+ // Florida the US state: the trailing country must agree.+ assertFalse(LocalNews.matches("Tbilisi, Georgia", "Georgia, United States"))+ assertFalse(LocalNews.matches("Georgia, United States", "Tbilisi, Georgia"))+ assertFalse(LocalNews.matches("Florida, Camagüey, Cuba", "Florida, United States"))+ assertFalse(LocalNews.matches("Florida, United States", "Florida, Camagüey, Cuba"))+ // Same country still matches as before.+ assertTrue(LocalNews.matches("Florida, United States", "Miami, Florida, United States"))+ }++ @Test fun georgianAndCubanRowsAreNotUsLocalSources() {+ // These feeds are from Georgia (country, .ge) and Cuba (.icrt.cu);+ // the harvest had tagged them as the US states Georgia/Florida.+ for (id in listOf(+ "apsny", "frontnews", "news-3", "georgiatoday", "eng-ghn",+ "kvirispalitra", "netgazeti", "resonancedaily", "radioflorida-icrt",+ )) {+ val source = SourceCatalog.byId(id)!!+ assertEquals(NewsCategory.WORLD, source.primaryCategory, id)+ assertEquals(null, source.region, id)+ assertFalse(SourceCatalog.matchesFeedFilter(id, NewsCategory.LOCAL, "Georgia, United States"), id)+ assertFalse(SourceCatalog.matchesFeedFilter(id, NewsCategory.LOCAL, "Florida, United States"), id)+ }+ }++ @Test fun localFilterKeepsOnlyTheUsersPlace() { val input = listOf(- article("gothamist"), article("latimes"), article("block-club"), article("laist"),+ article("gothamist"), article("latimes"), article("block-club"),+ article("laist"), article("calmatters"), article("bbc"), )- // California first, preserving input order within each group.+ // Metro pick: the city's outlets plus the statewide outlet for+ // its state; a distant city and a world source are excluded. assertEquals(- listOf("latimes", "laist", "gothamist", "block-club"),- input.orderedForLocal("California, United States").map { it.sourceId },+ listOf("latimes", "laist", "calmatters"),+ input.inFeedFilter(NewsCategory.LOCAL, "Los Angeles, California, United States")+ .map { it.sourceId }, )+ // State pick: every outlet in that state, nothing from other states. assertEquals(- listOf("block-club", "gothamist", "latimes", "laist"),- input.orderedForLocal("Chicago, Illinois, United States").map { it.sourceId },+ listOf("latimes", "laist", "calmatters"),+ input.inFeedFilter(NewsCategory.LOCAL, "California, United States").map { it.sourceId },+ )+ assertEquals(+ listOf("block-club"),+ input.inFeedFilter(NewsCategory.LOCAL, "Chicago, Illinois, United States")+ .map { it.sourceId },+ )+ // No location (or a place with no catalog sources): Local is+ // empty — never the whole Local bucket, never national/world.+ assertEquals(emptyList(), input.inFeedFilter(NewsCategory.LOCAL, null))+ assertEquals(emptyList(), input.inFeedFilter(NewsCategory.LOCAL, ""))+ assertEquals(emptyList(), input.inFeedFilter(NewsCategory.LOCAL, " "))+ assertEquals(emptyList(), input.inFeedFilter(NewsCategory.LOCAL, "Leeds, England, United Kingdom"))+ // Other categories and "All" are untouched by the location.+ assertEquals(input, input.inFeedFilter(null, null))+ assertEquals(+ listOf("bbc"),+ input.inFeedFilter(NewsCategory.WORLD, "Los Angeles, California, United States")+ .map { it.sourceId }, )- }-- @Test fun unsetLocationLeavesOrderUnchanged() {- val input = listOf(article("gothamist"), article("latimes"), article("block-club"))- assertEquals(input, input.orderedForLocal(null))- assertEquals(input, input.orderedForLocal(""))- assertEquals(input, input.orderedForLocal(" ")) } }
news/src/test/java/com/vayunmathur/news/domain/SourceCatalogAssetTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/domain/SourceCatalogAssetTest.kt b/news/src/test/java/com/vayunmathur/news/domain/SourceCatalogAssetTest.ktindex 98ae029ea0..39fd8efcd3 100644--- a/news/src/test/java/com/vayunmathur/news/domain/SourceCatalogAssetTest.kt+++ b/news/src/test/java/com/vayunmathur/news/domain/SourceCatalogAssetTest.kt@@ -37,23 +37,23 @@ class SourceCatalogAssetTest { "verification; some articles may still truncate." }, )- assertEquals(364, sources.count { it.region != null })+ assertEquals(355, sources.count { it.region != null }) assertEquals(66, SourceCatalog.localRegions.size) } @Test fun frozenCountsPerCategoryAndLanguage() { val primary = sources.groupingBy { it.primaryCategory }.eachCount()- assertEquals(9544, primary[NewsCategory.WORLD])+ assertEquals(9553, primary[NewsCategory.WORLD]) assertEquals(1329, primary[NewsCategory.US])- assertEquals(364, primary[NewsCategory.LOCAL])+ assertEquals(355, primary[NewsCategory.LOCAL]) assertEquals(123, primary[NewsCategory.TECHNOLOGY]) assertEquals(18, primary[NewsCategory.SCIENCE]) val tags = NewsCategory.entries.associateWith { category -> sources.count { category in it.categories } }- assertEquals(9544, tags[NewsCategory.WORLD])+ assertEquals(9553, tags[NewsCategory.WORLD]) assertEquals(1330, tags[NewsCategory.US])- assertEquals(364, tags[NewsCategory.LOCAL])+ assertEquals(355, tags[NewsCategory.LOCAL]) assertEquals(124, tags[NewsCategory.TECHNOLOGY]) assertEquals(21, tags[NewsCategory.SCIENCE]) assertEquals(85, sources.map { it.language }.distinct().size)@@ -145,7 +145,7 @@ class SourceCatalogAssetTest { NewsSource( "resonancedaily", "გაზეთ რეზონანსის ინტერნეტ-პორტალი", "http://www.resonancedaily.com/sitemap.xml", FeedKind.SITEMAP,- categories = listOf(NewsCategory.LOCAL), region = "Georgia, United States",+ categories = listOf(NewsCategory.WORLD), ), SourceCatalog.byId("resonancedaily"), )
news/src/test/java/com/vayunmathur/news/platform/NewsViewModelLocalTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/platform/NewsViewModelLocalTest.kt b/news/src/test/java/com/vayunmathur/news/platform/NewsViewModelLocalTest.ktindex dfa6510f78..8d5e423568 100644--- a/news/src/test/java/com/vayunmathur/news/platform/NewsViewModelLocalTest.kt+++ b/news/src/test/java/com/vayunmathur/news/platform/NewsViewModelLocalTest.kt@@ -22,9 +22,10 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue /**- * Local ordering at the ViewModel seam: with a location set, the Local- * feed puts that location's sources first (non-matching locals follow);- * unset, the Local order is the plain ranked order.+ * Local accuracy at the ViewModel seam: with a location set, the Local+ * feed contains only that location's sources (distant local sources and+ * everything else are excluded, in feed and in search); with no+ * location set, Local is empty rather than the whole Local bucket. */ @RunWith(RobolectricTestRunner::class) class NewsViewModelLocalTest {@@ -60,7 +61,7 @@ class NewsViewModelLocalTest { assertTrue(predicate(), description) } - @Test fun localLocationBoostsMatchingSourcesFirstAndUnsetRestores() {+ @Test fun localFeedShowsOnlyTheSetLocationAndUnsetIsEmpty() { val context = ApplicationProvider.getApplicationContext<Application>() seedNewsDb(context) val repository = NewsRepository(@@ -74,6 +75,7 @@ class NewsViewModelLocalTest { val collectors = CoroutineScope(Dispatchers.Default) collectors.launch { viewModel.articles.collect {} } collectors.launch { viewModel.localLocation.collect {} }+ collectors.launch { viewModel.searchResults.collect {} } try { // Clear via the ViewModel (its scope is pumped by await's looper // idling; a runBlocking DataStore edit on the Robolectric main@@ -81,24 +83,32 @@ class NewsViewModelLocalTest { viewModel.setLocalLocation(null) await("local location did not clear") { viewModel.localLocation.value == null } viewModel.setCategoryFilter(NewsCategory.LOCAL)- await("local feed did not land") {- viewModel.articles.value.map { it.url }.containsAll(ours)+ // Unset: Local is empty — none of our three local sources+ // (NY/Chicago/LA) is shown, and nothing else substitutes.+ await("unset local feed was not empty") {+ viewModel.articles.value.none { it.url in ours } }- // Unset: plain ranked (newest-first) order among our articles.- await("unset order was not ranked order") {- viewModel.articles.value.map { it.url }.filter { it in ours } == ours- }- // Set Chicago: its source jumps first, others keep ranked order.+ // Set Chicago: only its source remains; NY and LA (distant+ // local sources) are excluded, not merely demoted. viewModel.setLocalLocation("Chicago, Illinois, United States")- await("chicago boost did not apply") {+ await("chicago-only filter did not apply") { viewModel.articles.value.map { it.url }.filter { it in ours } ==- listOf(ours[1], ours[0], ours[2])+ listOf(ours[1]) } assertEquals("Chicago, Illinois, United States", viewModel.localLocation.value)- // Clearing restores the unset order.+ // Search within Local obeys the same filter.+ viewModel.setSearchQuery("Local")+ org.robolectric.shadows.ShadowSystemClock+ .advanceBy(java.time.Duration.ofMillis(300)); idle()+ await("search within local did not filter to chicago") {+ viewModel.searchResults.value.map { it.url }.filter { it in ours } ==+ listOf(ours[1])+ }+ viewModel.setSearchQuery("")+ // Clearing the location empties Local again. viewModel.setLocalLocation(null)- await("clearing did not restore ranked order") {- viewModel.articles.value.map { it.url }.filter { it in ours } == ours+ await("clearing did not empty the local feed") {+ viewModel.articles.value.none { it.url in ours } } } finally { collectors.cancel()
news/src/test/java/com/vayunmathur/news/ui/FeedScreenTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/ui/FeedScreenTest.kt b/news/src/test/java/com/vayunmathur/news/ui/FeedScreenTest.ktindex 6cf30c9bc7..19bf4db9a8 100644--- a/news/src/test/java/com/vayunmathur/news/ui/FeedScreenTest.kt+++ b/news/src/test/java/com/vayunmathur/news/ui/FeedScreenTest.kt@@ -101,6 +101,35 @@ class FeedScreenTest { rule.onNodeWithText("All").assertIsDisplayed() } + private fun setLocalEmpty(location: String?) {+ rule.setContent {+ FeedContent(+ stories = emptyList(), searchStories = emptyList(), cachedByUrl = emptyMap(),+ isRefreshing = false, refreshFailed = false,+ categoryFilter = com.vayunmathur.news.domain.NewsCategory.LOCAL,+ localLocation = location, searchQuery = "",+ onSearchQueryChange = {}, onRefresh = {}, onCategoryFilterChange = {},+ onToggleBookmark = {}, onOpenSaved = {}, onOpenStory = {}, onOpenSettings = {},+ )+ }+ }++ @Test fun localWithoutLocationSaysItIsEmptyUntilSet() {+ setLocalEmpty(null)+ rule.onNodeWithText(+ "No local location is set, so Local is empty. Set your place in Settings to see " ++ "news from your area — Local never substitutes national or world news."+ ).assertIsDisplayed()+ }++ @Test fun localWithLocationButNoNewsNamesThePlace() {+ setLocalEmpty("Chicago, Illinois, United States")+ rule.onNodeWithText(+ "No downloaded news from Chicago, Illinois, United States yet. Pull to refresh, " ++ "or pick a wider place (for example your state or region) in Settings."+ ).assertIsDisplayed()+ }+ @Test fun topBarActionsNavigate() { var saved = 0 var settings = 0