Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RssItem now is a Date instead of a String #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class RssItemsAdapter(private val listener: OnItemClickListener) : Recy
val item = itemList[position]
holder.apply {
textTitle.text = item.title
textPubDate.text = item.publishDate
textPubDate.text = item.publishDate?.toString()

if (item.image != null) {
Picasso.get()
Expand Down
13 changes: 11 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// https://mvnrepository.com/artifact/org.pojava/datetime
implementation group: 'org.pojava', name: 'datetime', version: '3.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation 'com.squareup.retrofit2:retrofit-mock:2.2.0'

}

repositories {
mavenCentral()
}

tasks.withType(Test) {
testLogging {
events "started", "passed", "skipped", "failed"
}
}
3 changes: 2 additions & 1 deletion library/src/main/java/me/toptas/rssconverter/RssItem.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.toptas.rssconverter

import java.io.Serializable
import java.util.Date

/**
* Model for Rss Item
Expand All @@ -16,7 +17,7 @@ class RssItem : Serializable {
field = link?.trim { it <= ' ' }
}
var image: String? = null
var publishDate: String? = null
var publishDate: Date? = null
var description: String? = null


Expand Down
18 changes: 15 additions & 3 deletions library/src/main/java/me/toptas/rssconverter/XMLParser.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package me.toptas.rssconverter

import android.util.Log
import org.pojava.datetime.DateTime
import org.pojava.datetime.DateTimeConfig
import org.xml.sax.Attributes
import org.xml.sax.SAXException
import org.xml.sax.helpers.DefaultHandler
import java.lang.Exception
import java.util.Date

/**
* RSS Feed XML parser
Expand All @@ -18,7 +23,7 @@ internal class XMLParser : DefaultHandler() {
private var title = EMPTY_STRING
private var link: String? = null
private var image: String? = null
private var date: String? = null
private var date: Date? = null
private var description: String? = null

private var rssItem: RssItem? = null
Expand Down Expand Up @@ -73,7 +78,7 @@ internal class XMLParser : DefaultHandler() {
}
link = EMPTY_STRING
image = null
date = EMPTY_STRING
date = null
}
TITLE -> if (!qName.contains(MEDIA)) {
parsingTitle = false
Expand All @@ -88,7 +93,14 @@ internal class XMLParser : DefaultHandler() {
IMAGE, URL -> if (elementValue != null && elementValue?.isNotEmpty() == true) {
image = elementValue
}
PUBLISH_DATE -> date = elementValue
PUBLISH_DATE -> date = elementValue?.let {
try{
DateTime.parse(it, DateTimeConfig.getGlobalDefault()).toDate()
}catch (e: Exception){
Log.i(XMLParser::class.java.simpleName, "Careful! ${e}")
Copy link
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.

null
}
}
DESCRIPTION -> {
parsingDescription = false
elementValue = EMPTY_STRING
Expand Down