Add adapter for parsing jsonfeed feed

This commit is contained in:
Shinokuni 2020-09-15 13:48:52 +02:00
parent 0c48bd2adb
commit c9c316b579
3 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,82 @@
{
"version": "https://jsonfeed.org/version/1",
"title": "News from Flying Meat",
"home_page_url": "http://flyingmeat.com/blog/",
"feed_url": "http://flyingmeat.com/blog/feed.json",
"description": "News from your friends at Flying Meat.",
"author": {
"name": "Gus Mueller"
},
"items": [
{
"id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html",
"title": "Acorn and 10.13",
"content_html": "<p>Happy Mac OS High Sierra release day everyone.</p>\n<p>I&#39;m happy to say that there are no known issues with <a href=\"https://flyingmeat.com/acorn/\">Acorn</a> 6.0.3 or Acorn 5.6.6 when running on Mac OS 10.13 High Sierra. In fact, you might even notice that some things are actually faster and it can now open HEIF images. How awesome is that?</p>\n<p>I&#39;m also working on some 10.13 goodies for Acorn 6 folks later this year. I can&#39;t wait to share that with you, but you&#39;ll have to wait just a little bit.</p>\n",
"date_published": "2017-09-25T14:27:27-07:00",
"url": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2018/2/acorn_6.1_is_out.html",
"title": "Acorn 6.1 Is Out",
"content_html": "<p><a href=\"https://flyingmeat.com/acorn/\">Acorn 6.1 has been released</a>.</p>\n<p>You can <a href=\"http://shapeof.com/archives/2018/2/acorn_6.1_is_out.html\">read a longer post about it</a> over on Gus&#39;s blog, but the short of it is: Better, faster, smoother, stronger. And now with Metal 2 support.</p>\n",
"date_published": "2018-02-16T09:59:11-08:00",
"url": "http://flyingmeat.com/blog/archives/2018/2/acorn_6.1_is_out.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2018/6/a_pair_of_updates.html",
"title": "A Pair of Updates",
"content_html": "<p>Happy summer solstice everybody! (at least for folks in the northern hemisphere, and for folks in the south… sorry. It&#39;s going to start getting brighter for you though).</p>\n<p>Today I&#39;ve got a pair of minor app updates to annouce for you.</p>\n<p>First up is <a href=\"https://flyingmeat.com/acorn/\">Acorn 6.1.3</a>, which <a href=\"https://flyingmeat.com/acorn/releasenotes.html\">fixes a number of bugs</a> including one that stemmed from trying to use QuickLook on a file that was created with Acorn 1.0. For the one or two of you that this was affecting, hurray!</p>\n<p>Next up is <a href=\"https://flyingmeat.com/retrobatch/\">Retrobatch</a>, which also <a href=\"https://flyingmeat.com/retrobatch/releasenotes.html\">includes some bug fixes</a>, the beginnings of Voice Over support, performance improvements, and more.</p>\n<p>What&#39;s next for these apps? Work on Acorn 6.2 will begin shortly, as will Retrobatch 1.1. WWDC introduced some great new APIs that I want to take advantage of (cool new machine learning things), so that&#39;ll be a focus- as well as Dark Mode for Acorn and one other major thing I&#39;ve got planned. Retrobatch will probably also get the Dark Mode treatment, but not until I&#39;ve done it for Acorn first.</p>\n<p>So it&#39;s going to be a busy summer, but I&#39;m looking forward to it.</p>\n",
"date_published": "2018-06-21T10:18:46-07:00",
"url": "http://flyingmeat.com/blog/archives/2018/6/a_pair_of_updates.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2018/9/retrobatch_1.1_is_out.html",
"title": "Retrobatch 1.1 Is Out",
"content_html": "<p>Here&#39;s something new for your lazy <strike>August</strike> September* morning: <a href=\"https://flyingmeat.com/retrobatch/\">Retrobatch 1.1 is out</a>.</p>\n<p>What&#39;s new and awesome? Well, <a href=\"https://flyingmeat.com/retrobatch/\">Retrobatch</a> now has some great scripting goodness in the form of a new Automator action which will run a workflow for you (and create Automator droplets), a new JavaScript node*, and the ability to run Retrobatch workflows from the terminal.</p>\n<p>We&#39;ve added a handful of new nodes such as Dither, Auto Enhance, Instant Alpha, and Color Posterize. New options to existing nodes have also shown up, such as &quot;Only scale smaller&quot; for the Scale node.</p>\n<p>And an interesting idea that I&#39;ve had folks ask about a number of times- it&#39;s now possible to run an image through a machine learning classifier, and then have the classification written to metadata such as the image title, or keywords. This was done by adding token support to the Set Specific Metadata node. This also means you can use other tokens such as the Current Year in metadata fields. Awesome? We think so.</p>\n<p>The <a href=\"https://flyingmeat.com/retrobatch/releasenotes.html\">full release notes are available</a>, and if you have ideas or questions- make sure to <a href=\"https://forums.flyingmeat.com/\">poke around on the forums</a> or write us: <a href=\"mailto:support@flyingmeat.com\">support@flyingmeat.com</a>. We&#39;ve got lots of ideas for future releases, but if you&#39;d like something specific in there make sure to let us know.</p>\n<br/>\n\n<div style=\"color:#666\">\n* Whoa, it's September already?<br/><br/>\n\n<p>**I&#39;m calling the JavaScript node a &quot;preview&quot;. It works very well, but I&#39;m not 100% sold on the API that I&#39;ve provided to folks. So this is a disclaimer that it might change a little bit in the future.</div></p>\n",
"date_published": "2018-09-07T09:43:10-07:00",
"url": "http://flyingmeat.com/blog/archives/2018/9/retrobatch_1.1_is_out.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2018/9/acorn_6.2_with_mojave_dark_mode_is_out.html",
"title": "Acorn 6.2 With Mojave Dark Mode Is Out",
"content_html": "<p>On Monday I flipped some switches on the FM servers and <a href=\"https://flyingmeat.com/acorn/\">Acorn 6.2</a> was released to the universe. You might also remember that Monday a little known operating system from Apple was updated, which includes a neat new feature known as Dark Mode.</p>\n<center><img src=\"https://shapeof.com/archives/2018/media/acorn62.jpeg\" width=\"800\" style=\"\" /></center>\n\n<p>I think Acorn looks pretty good in Dark Aqua, especially the icon refresh from <a href=\"http://www.matthewskiles.com/\">Matthew Skiles</a>.</p>\n<p>To celebrate the new release, we&#39;ve put <a href=\"https://flyingmeat.com/store/\">Acorn on sale for 50% off</a>. So go grab it at the insanely low price of $14.99. If you haven&#39;t already upgraded from previous versions of Acorn, now is a good time to do so.</p>\n<p>We&#39;ve also packed a bunch of little changes, bug fixes, and compatibility with Mojave in there. And of course, there&#39;s more to come in the future as always.</p>\n",
"date_published": "2018-09-27T14:37:21-07:00",
"url": "http://flyingmeat.com/blog/archives/2018/9/acorn_6.2_with_mojave_dark_mode_is_out.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2019/1/acorn_6.3_is_out.html",
"title": "Acorn 6.3 Is Out",
"content_html": "<p><a href=\"https://flyingmeat.com/acorn/\">Acorn 6.3 is available</a>, and the full <a href=\"https://flyingmeat.com/acorn/releasenotes.html\">release notes</a> are up as well.</p>\n<p>Here&#39;s what I think is awesome in this release:</p>\n<p><strong>Portrait Mask Support</strong>. If you have an iPhone running iOS 12 (and can take Portrait photos), Acorn will now detect the Portrait Matte from those images and turn it into a layer mask. The Portrait Matte is the image data which enables blurring in the background, or other fancy camera tricks. This means you can use this matte to erase and add fancy backgrounds or custom blurs for your image, all within Acorn.</p>\n<p><strong>Other Mask Features</strong>. You can now drag and drop masks from the layers list into another layer, or copy it out as a new layer. When exporting layers you now have an option to apply the mask on export, or just write it as an additional image along with everything else. There are a number of new shortcuts when dealing with layer masks as well.</p>\n<p><strong>Brush Stuff</strong>. If you&#39;re running MacOS 10.13 or later, you get a performance boost when brushing (painting, smudging, cloning, etc…). This is especially noticeable when brusing on deep color images.</p>\n<p>I&#39;ve also added options to the brush palette for adjusting flow, softness and blending. In addition to all this, there&#39;s a bunch of new brushes under the &quot;Basic Round&quot; category which are designed for the new brush engine.</p>\n<p><strong>Other Stuff</strong>. There&#39;s other good things including improved PDF export, various MacOS Mojave UI fixes, additional speed improvements with with deep images, and more. And as always, it&#39;s a free upgrade for anyone who has already purchased Acorn 6.</p>\n",
"date_published": "2019-01-09T13:00:07-08:00",
"url": "http://flyingmeat.com/blog/archives/2019/1/acorn_6.3_is_out.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2019/4/retrobatch_1.2_released.html",
"title": "Retrobatch 1.2 Released",
"content_html": "<p>We&#39;re happy to announce that Retrobatch 1.2 has now been released, which is a free update for all owners of Retrobatch. Highlights of this release include:</p>\n<ul>\n<li><p><strong>Create animated GIF and PNG</strong> images with the Animated Image node. When using Retrobatch you can load in a folder of images and produce an optimized animated image with options for setting the frame rate, format, as well as letting the image loop or not.</p>\n</li>\n<li><p><strong>New nodes</strong> including &quot;Round Corner&quot;, &quot;Image Grid&quot;, and &quot;Limit&quot;. We&#39;ve also added improvements to the Write node allowing you to write back to the original processed image.</p>\n</li>\n<li><p><strong>Droplet support</strong> (Retrobatch Pro). Turn your workflow into an an application which you can drag and drop images onto. The droplet can work anywhere an application normally would, even in the Dock.</p>\n</li>\n<li><p><strong>Write Plug-Ins using JavaScript</strong> (Retrobatch Pro). Using the combined power of JavaScript and the native to MacOS Cocoa APIs, you can <a href=\"https://flyingmeat.com/retrobatch/jsapi/\">make and distribute</a> new plugins for Retrobatch. Got an idea for a plug-in and you want to use Core Image to make it? Or maybe you want to use Core Graphics to add some funky text to your images? Now you can do this with JavaScript and Cocoa.</p>\n</li>\n</ul>\n<p>The <a href=\"https://flyingmeat.com/retrobatch/releasenotes.html\">full release notes are available</a>, as well as information on bug fixes we delivered in this update.</p>\n<p>As always, we&#39;re <a href=\"https://flyingmeat.com/retrobatch/releasenotes.html\">always listening for feedback</a> and feature requests. And don&#39;t forget to head over to the <a href=\"http://forums.flyingmeat.com/c/retrobatch\">Retrobatch community formus</a> to chat with us and other Retrobatch users. </p>\n",
"date_published": "2019-04-01T13:38:21-07:00",
"url": "http://flyingmeat.com/blog/archives/2019/4/retrobatch_1.2_released.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2019/10/catalina_ready.html",
"title": "Catalina Ready",
"content_html": "<p>MacOS 10.15 Catalina was just released, and we&#39;re happy to let you know that both <a href=\"https://flyingmeat.com/acorn/\">Acorn 6.5.1</a> and <a href=\"https://flyingmeat.com/retrobatch/\">Retrobatch 1.2</a> are compatible with it.</p>\n<p>And to celebrate the release of Catalina, we&#39;re <a href=\"https://flyingmeat.com/store/\">discounting Acorn by 50% for a limited time</a>. So if you haven&#39;t upgraded yet, now is a good time.</p>\n",
"date_published": "2019-10-07T10:48:03-07:00",
"url": "http://flyingmeat.com/blog/archives/2019/10/catalina_ready.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2020/3/retrobatch_1.4_is_out.html",
"title": "Retrobatch 1.4 Is Out",
"content_html": "<p>I&#39;ve just typed the magic commands* and let the servers do their thing and now <a href=\"https://flyingmeat.com/retrobatch/\">Retrobatch 1.4</a> is loose on the world.</p>\n<p>There&#39;s a couple of interesting new features in this update I&#39;d like to call out. First up is JavaScript expressions in Retrobatch Pro. Various nodes in Retrobatch which allow you to set the size or length of a value (such as the Crop, Border, Gradient, Adjust Margin nodes) now have an option of running a little snippet of JavaScript code to figure out the value. This is a super powerful feature, which you can read about in our <a href=\"https://flyingmeat.com/retrobatch/jsapi-1/jsexpressions/\">JavaScript Expressions documentation</a></p>\n<p>Let&#39;s say you have some images of varying sizes, which are all at 480 x 380 or smaller, and you want them to expand to meet that size. But- you only want it to grow evenly on either side of the image, but you want to keep a baseline so only transparent area is added to the top of the image, and the bottom stays in the same spot. This little picture of the new Adjust Margins node shows how this can be done:</p>\n<center><img src=\"https://flyingmeat.com/retrobatch/jsapi-1/images/javascript_expression_fields_shot.png\" width=\"444\" style=\"border: solid 1px #777;\" /></center>\n\n<p>Yes, this is an oddball (and very real) case- but there&#39;s a billion of these little oddball cases out there. With the new JavaScript expressions support, these small but hard to do scenarios are now super easy.</p>\n<p>And yes, all of the JavaScript support in Retrobatch now sits atop <a href=\"https://github.com/ccgus/fmjs\">FMJS</a>, which any developer can use to build similar support into their apps.</p>\n<p>What else is new?</p>\n<p>File numbers with leading zeros for the Write node. You can add (and it&#39;s case sensitive) $FileNumber04$ in the File name: field of the Write node to have the file number of your image written out as part of the name, with a padding of up to 4 zeros. If you&#39;d like to pad that number to 6, you would enter $FileNumber06$, and so on.</p>\n<p>The Mask to Alpha node got a new &quot;invert colors&quot; option. Normally Mask to Alpha will convert the black areas of your image to transparent, and the white to opaque (with gray somewhere inbetween). With the new Invert Colors option, Mask to Alpha will now convert the white areas of your image to transparent, and keep the black opaque. This is great if you are scanning in line drawings from your own artwork, and want to make the backgrounds transparent.</p>\n<p>This request comes up a lot in <a href=\"https://flyingmeat.com/acorn/\">Acorn</a> as well. Previously you&#39;d have to add an Invert Colors node (or filter for Acorn), then the Mask to Alpha, and then Invert Colors again. Now it&#39;s just a checkbox in Mask to Alpha, which is super easy. I&#39;ve also added an update to the same filter in Acorn for the next release. You can grab a preview of it <a href=\"http://flyingmeat.com/download/latest/\">from here</a>.</p>\n<p>And finally for my short list, you can now make a droplet which doesn&#39;t take any files. Why is this useful? Well, imagine you have a workflow that reads an image from the clipboard, resizes it to a specific width, and then writes it back to the clipboard. Now you can make a little droplet to do just this. Just a double click from the Finder (or a single click from the Dock) and your workflow is run.</p>\n<p>The full release notes for Retrobatch 1.4 are <a href=\"https://flyingmeat.com/retrobatch/releasenotes.html\">available in the usual place</a>.</p>\n<p>* <code>./bin/otbuild.sh -e 1.4</code></p>\n",
"date_published": "2020-03-31T14:37:15-07:00",
"url": "http://flyingmeat.com/blog/archives/2020/3/retrobatch_1.4_is_out.html"
},
{
"id": "http://flyingmeat.com/blog/archives/2020/5/acorn_6.6_released.html",
"title": "Acorn 6.6 is out with new Shape Processors and more",
"content_html": "<p><a href=\"https://flyingmeat.com/acorn/\">Acorn 6.6</a> is out. You can update to this release via the <a href=\"https://flyingmeat.com/acorn/appstore/\">App Store</a> as or the Acorn ▸ Check for Updates… menu if you bought it directly from us.</p>\n<p>Originally this was going to be a bug fix release but I kept on adding useful things and it snowballed into a feature release. As usual, <a href=\"https://flyingmeat.com/acorn/releasenotes.html\">the full release notes</a> have all the details about what was updated.</p>\n<p>The main new features are with the <a href=\"https://flyingmeat.com/acorn/docs/shape_processor.html\">Shape Processor</a>. If you&#39;re not already familiar with the shape processor, it&#39;s a neat ability Acorn has to take shapes on vector layers and pipe them through a series of actions, similar to how Automator or Acorn&#39;s bitmap filters work. Only instead of working on pixels, the processors will alter the shapes by scaling them or moving them around, or changing colors or blend modes. There&#39;s even a processor which will generate shapes for you- so if you want your canvas to fill up with hundreds of stars, you can do that.</p>\n<p>Acorn 6.6 adds new processors which let you set the stroke, fill, and blend mode of your processed shapes. You can now also flip your shapes and even shift colors. </p>\n<img src=\"https://shapeof.com/archives/2020/5/proc_shape.png\" width=\"660\" height=\"510\" />\n\n<p>Chaining these processors together can get you some neat looking images. You can make interesting desktop backgrounds, as well as textures for your photos. Or if you just need a bunch of hexagons arranged in a circle, that&#39;s just two processors stacked together.</p>\n<p>Have you made something interesting with the Shape Processor? I&#39;d love to see it either via Twitter (I&#39;m <a href=\"https://twitter.com/ccgus/\">@ccgus</a>) or via <a href=\"mailto:support@flyingmeat.com\">email</a>.</p>\n<p>There are of course the usual bug fixes and other <a href=\"https://flyingmeat.com/acorn/releasenotes.html\">minor details</a>. And if you don&#39;t already have Acorn, a <a href=\"https://flyingmeat.com/acorn/\">no-strings attached free trial</a> is available on our website. Try it out, and we&#39;re always looking to hear from you about feature requests, thoughts, and anything else.</p>\n",
"date_published": "2020-05-28T12:17:57-07:00",
"url": "http://flyingmeat.com/blog/archives/2020/5/acorn_6.6_released.html"
}
]
}

View File

@ -0,0 +1,35 @@
package com.readrops.api.localfeed.json
import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.readrops.db.entities.Feed
import com.squareup.moshi.Moshi
import junit.framework.TestCase.assertEquals
import okio.Buffer
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class JSONFeedAdapterTest {
private val context: Context = InstrumentationRegistry.getInstrumentation().context
private val adapter = Moshi.Builder()
.add(JSONFeedAdapter())
.build()
.adapter<Feed>(Feed::class.java)
@Test
fun normalCasesTest() {
val stream = context.assets.open("localfeed/json/json_feed.json")
val feed = adapter.fromJson(Buffer().readFrom(stream))!!
assertEquals(feed.name, "News from Flying Meat")
assertEquals(feed.url, "http://flyingmeat.com/blog/feed.json")
assertEquals(feed.siteUrl, "http://flyingmeat.com/blog/")
assertEquals(feed.description, "News from your friends at Flying Meat.")
}
}

View File

@ -0,0 +1,39 @@
package com.readrops.api.localfeed.json
import com.readrops.api.utils.nextNullableString
import com.readrops.db.entities.Feed
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonReader
import com.squareup.moshi.ToJson
class JSONFeedAdapter {
@ToJson
fun toJson(feed: Feed) = ""
@FromJson
fun fromJson(reader: JsonReader): Feed {
val feed = Feed()
reader.beginObject()
while (reader.hasNext()) {
with(feed) {
when (reader.selectName(names)) {
0 -> name = reader.nextString()
1 -> siteUrl = reader.nextNullableString()
2 -> url = reader.nextNullableString()
3 -> description = reader.nextNullableString()
else -> reader.skipValue()
}
}
}
reader.endObject()
return feed
}
companion object {
val names: JsonReader.Options = JsonReader.Options.of("title", "home_page_url",
"feed_url", "description")
}
}