You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.1 KiB
105 lines
3.1 KiB
11 years ago
|
/*
|
||
|
* Copyright 2010-2013 Eric Kok et al.
|
||
|
*
|
||
|
* Transdroid is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* Transdroid is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
11 years ago
|
package org.transdroid.core.app.settings;
|
||
11 years ago
|
|
||
11 years ago
|
import java.util.Date;
|
||
|
|
||
11 years ago
|
import org.transdroid.core.gui.lists.SimpleListItem;
|
||
11 years ago
|
|
||
|
import android.net.Uri;
|
||
|
import android.text.TextUtils;
|
||
|
|
||
|
/**
|
||
|
* Represents a user-specified RSS feed.
|
||
|
* @author Eric Kok
|
||
|
*/
|
||
11 years ago
|
public class RssfeedSetting implements SimpleListItem {
|
||
11 years ago
|
|
||
|
private static final String DEFAULT_NAME = "Default";
|
||
11 years ago
|
|
||
11 years ago
|
private final int order;
|
||
|
private final String name;
|
||
|
private final String url;
|
||
|
private final boolean requiresAuth;
|
||
11 years ago
|
private Date lastViewed;
|
||
11 years ago
|
private final String lastViewedItemUrl;
|
||
11 years ago
|
|
||
11 years ago
|
public RssfeedSetting(int order, String name, String baseUrl, boolean needsAuth, Date lastViewed,
|
||
|
String lastViewedItemUrl) {
|
||
11 years ago
|
this.order = order;
|
||
|
this.name = name;
|
||
|
this.url = baseUrl;
|
||
|
this.requiresAuth = needsAuth;
|
||
11 years ago
|
this.lastViewed = lastViewed;
|
||
11 years ago
|
this.lastViewedItemUrl = lastViewedItemUrl;
|
||
11 years ago
|
}
|
||
|
|
||
|
public int getOrder() {
|
||
|
return order;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getName() {
|
||
|
if (!TextUtils.isEmpty(name))
|
||
|
return name;
|
||
11 years ago
|
if (!TextUtils.isEmpty(url)) {
|
||
|
String host = Uri.parse(url).getHost();
|
||
11 years ago
|
return host == null ? DEFAULT_NAME : host;
|
||
11 years ago
|
}
|
||
11 years ago
|
return DEFAULT_NAME;
|
||
|
}
|
||
|
|
||
|
public String getUrl() {
|
||
|
return url;
|
||
|
}
|
||
|
|
||
|
public boolean requiresExternalAuthentication() {
|
||
|
return requiresAuth;
|
||
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Returns the date on which we last checked this feed. Note that this is NOT updated automatically after the
|
||
|
* settings were loaded from {@link ApplicationSettings}; instead the settings have to be manually loaded again
|
||
|
* using {@link ApplicationSettings#getRssfeedSetting(int)}.
|
||
|
* @return The last new item's URL as URL-encoded string
|
||
|
*/
|
||
|
public Date getLastViewed() {
|
||
|
return this.lastViewed;
|
||
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
11 years ago
|
* Returns the URL of the item that was the newest last time we checked this feed. Note that this is NOT updated
|
||
|
* automatically after the settings were loaded from {@link ApplicationSettings}; instead the settings have to be
|
||
|
* manually loaded again using {@link ApplicationSettings#getRssfeedSetting(int)}.
|
||
11 years ago
|
* @return The last new item's URL as URL-encoded string
|
||
|
*/
|
||
11 years ago
|
public String getLastViewedItemUrl() {
|
||
|
return this.lastViewedItemUrl;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
/**
|
||
|
* Returns a nicely formatted identifier containing (a portion of) the feed URL
|
||
|
* @return A string to identify this feed's URL
|
||
|
*/
|
||
|
public String getHumanReadableIdentifier() {
|
||
|
String host = Uri.parse(url).getHost();
|
||
|
String path = Uri.parse(url).getPath();
|
||
11 years ago
|
return (host == null ? null : host + (path == null ? "" : path));
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
}
|