Skip to content

Commit 685c5ab

Browse files
paodbjavier-godoy
authored andcommitted
refactor: replace deprecated PolymerTemplate
Close #19
1 parent e0e30da commit 685c5ab

File tree

2 files changed

+41
-64
lines changed

2 files changed

+41
-64
lines changed

src/main/java/com/flowingcode/vaadin/addons/rssitems/RssItems.java

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030
import org.apache.http.client.methods.HttpGet;
3131
import org.apache.http.impl.client.HttpClientBuilder;
3232
import org.apache.http.util.EntityUtils;
33-
33+
import com.vaadin.flow.component.Component;
3434
import com.vaadin.flow.component.HasSize;
3535
import com.vaadin.flow.component.HasStyle;
3636
import com.vaadin.flow.component.Tag;
3737
import com.vaadin.flow.component.dependency.JsModule;
3838
import com.vaadin.flow.component.dependency.NpmPackage;
39-
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
4039

4140
/**
4241
* Simple RSS Reader component based on https://github.com/TherapyChat/rss-items
@@ -49,7 +48,7 @@
4948
@NpmPackage(value="x2js",version="3.4.0")
5049
@JsModule("./rss-items.js")
5150
@SuppressWarnings("serial")
52-
public class RssItems extends PolymerTemplate<RssItemsModel> implements HasSize, HasStyle {
51+
public class RssItems extends Component implements HasSize, HasStyle {
5352

5453
private String url;
5554

@@ -96,13 +95,13 @@ public RssItems(String url, int max, int maxTitleLength, int maxExcerptLength, b
9695
this.getElement().executeJs(IMAGE_METHOD.replaceAll("%%ATTRIBUTE_NAME%%", attributeName), this);
9796
}
9897

99-
getModel().setAuto(true);
100-
getModel().setMax(max);
101-
getModel().setMaxExcerptLength(maxExcerptLength);
102-
getModel().setMaxTitleLength(maxTitleLength);
98+
this.setUrl(url);
99+
this.setAuto(true);
100+
this.setMax(max);
101+
this.setMaxExcerptLength(maxExcerptLength);
102+
this.setMaxTitleLength(maxTitleLength);
103103
addClassName("x-scope");
104-
addClassName("rss-items-0");
105-
this.url = url;
104+
addClassName("rss-items-0");
106105
refreshUrl();
107106
}
108107

@@ -142,37 +141,53 @@ private String obtainRss(String url) throws ClientProtocolException, IOException
142141
return result;
143142
}
144143

144+
/**
145+
* Sets the auto property to init the RSS request
146+
* @param auto
147+
*/
148+
public void setAuto(boolean auto) {
149+
this.getElement().setProperty("auto", auto);
150+
}
151+
145152
/**
146153
* Sets the max title length
147154
* @param length
148155
*/
149-
public void setMaxTitleLength(int length) {
150-
getModel().setMaxTitleLength(length);
151-
refreshUrl();
152-
}
156+
public void setMaxTitleLength(int length) {
157+
this.getElement().setProperty("maxTitleLength", length);
158+
refreshUrl();
159+
}
153160

154161
/**
155162
* Sets the max title excerpt length
156163
* @param length
157164
*/
158-
public void setMaxExcerptLength(int length) {
159-
getModel().setMaxExcerptLength(length);
160-
refreshUrl();
161-
}
165+
public void setMaxExcerptLength(int length) {
166+
this.getElement().setProperty("maxExcerptLength", length);
167+
refreshUrl();
168+
}
162169

163170
/**
164171
* Sets the maximun number of items to be shown
165172
* @param max
166173
*/
167-
public void setMax(int max) {
168-
getModel().setMax(max);
169-
refreshUrl();
170-
}
171-
172-
public void setExtractImageFromDescription(boolean extractImageFromDescription) {
173-
this.extractImageFromDescription = extractImageFromDescription;
174-
refreshUrl();
175-
}
174+
public void setMax(int max) {
175+
this.getElement().setProperty("max", max);
176+
refreshUrl();
177+
}
178+
179+
public void setExtractImageFromDescription(boolean extractImageFromDescription) {
180+
this.extractImageFromDescription = extractImageFromDescription;
181+
refreshUrl();
182+
}
176183

184+
/**
185+
* Sets the url of the RSS
186+
* @param url
187+
*/
188+
public void setUrl(String url) {
189+
this.getElement().setProperty("url", url);
190+
this.url = url;
191+
}
177192

178193
}

src/main/java/com/flowingcode/vaadin/addons/rssitems/RssItemsModel.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)