use of com.owncloud.android.lib.common.ExternalLink in project android by nextcloud.
the class ExternalLinksProvider method getExternalLink.
/**
* get by type external links.
*
* @return external links, empty if none exists
*/
public ArrayList<ExternalLink> getExternalLink(ExternalLinkType type) {
Cursor cursor = mContentResolver.query(ProviderMeta.ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS, null, "type = ?", new String[] { type.toString() }, null);
if (cursor != null) {
ArrayList<ExternalLink> list = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
ExternalLink externalLink = createExternalLinkFromCursor(cursor);
if (externalLink == null) {
Log_OC.e(TAG, "ExternalLink could not be created from cursor");
} else {
list.add(externalLink);
}
} while (cursor.moveToNext());
}
cursor.close();
return list;
} else {
Log_OC.e(TAG, "DB error restoring externalLinks.");
}
return new ArrayList<>();
}
use of com.owncloud.android.lib.common.ExternalLink in project android by nextcloud.
the class ExternalLinksProvider method createExternalLinkFromCursor.
/**
* cursor to externalLink
*
* @param cursor db cursor
* @return externalLink, null if cursor is null
*/
private ExternalLink createExternalLinkFromCursor(Cursor cursor) {
ExternalLink externalLink = null;
if (cursor != null) {
int id = cursor.getInt(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta._ID));
String iconUrl = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_ICON_URL));
String language = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE));
ExternalLinkType type;
switch(cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TYPE))) {
case "link":
type = ExternalLinkType.LINK;
break;
case "settings":
type = ExternalLinkType.SETTINGS;
break;
case "quota":
type = ExternalLinkType.QUOTA;
break;
default:
type = ExternalLinkType.UNKNOWN;
break;
}
String name = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME));
String url = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL));
externalLink = new ExternalLink(id, iconUrl, language, type, name, url);
}
return externalLink;
}
Aggregations