Skip to content

RssItem now is a Date instead of a String#9

Open
eagskunst wants to merge 2 commits intofaruktoptas:masterfrom
eagskunst:staging
Open

RssItem now is a Date instead of a String#9
eagskunst wants to merge 2 commits intofaruktoptas:masterfrom
eagskunst:staging

Conversation

@eagskunst
Copy link
Copy Markdown

As for issue #8 and in terms for making it more simple to devs to filter Items by date, I make the necessary modifications to now have a Date inside the RssItem.

Added also a Log message in order to inform the existence of an unparseable date.

I tried to make changes in dev, but I couldn't be able to resolve the conflicts in merge.

@faruktoptas
Copy link
Copy Markdown
Owner

Hi @eagskunst The date format is not the same for all RSS contents. It changes depends on the content. So date will be null if the format is other than EEE, dd MMM yyyy HH:mm:ss. You can find different contents here: https://github.com/faruktoptas/RetrofitRssConverterFactory/tree/dev/library/src/androidTest/assets/rss

@eagskunst
Copy link
Copy Markdown
Author

eagskunst commented Dec 15, 2018

@faruktoptas What about if there's a builder where you could add the formatter?

@faruktoptas
Copy link
Copy Markdown
Owner

@eagskunst The formatter should change depending on the RSS content. An interceptor should be better instead of the builder. You can manipulate the RssItem after it is created by intercepting. So you can change each field's value or type.

@eagskunst
Copy link
Copy Markdown
Author

@faruktoptas I'm not familiar with the concept of interceptors (how they're made). Could you help me a little bit so I can do it?

@faruktoptas
Copy link
Copy Markdown
Owner

Currently, it is not implemented. But I'm planning to add it to be more flexible. You can follow the steps below:

  • Extend RssItem with a date object instead of String. Something like MyRssItem
  • When Retrofit service successfully returns the RssFeed object. Iterate through RssItem list and convert them to MyRssItem with formatted date objects.

@eagskunst
Copy link
Copy Markdown
Author

eagskunst commented Dec 16, 2018

In my research for the ways to test all patterns of SimpleDateFormatter, I found this library,
POJava DateTime. They site is down, but with web archive you could see the docs. I tested the dates with the sample app and with the custom test you make, all passed @faruktoptas.

@eagskunst
Copy link
Copy Markdown
Author

@faruktoptas Don't forge to give me some feedback 😅

try{
DateTime.parse(it, DateTimeConfig.getGlobalDefault()).toDate()
}catch (e: Exception){
Log.i(XMLParser::class.java.simpleName, "Careful! ${e}")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If parsing fails date will be null. But the user could parse it somehow.

@faruktoptas
Copy link
Copy Markdown
Owner

@eagskunst sorry for late reply :)

Trying to parse the date string could cause date to be null. But it should not be. I will add a formatter that works with RSS urls. So user can add their own formatters. It would be more flexible

@eagskunst
Copy link
Copy Markdown
Author

@faruktoptas What about using a formatter with the RSS specification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants