Search in sources :

Example 6 with ExternalLink

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<>();
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Example 7 with ExternalLink

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;
}
Also used : ExternalLinkType(com.owncloud.android.lib.common.ExternalLinkType) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Aggregations

ExternalLink (com.owncloud.android.lib.common.ExternalLink)7 Intent (android.content.Intent)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)2 TextDrawable (com.owncloud.android.ui.TextDrawable)2 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)2 ArrayList (java.util.ArrayList)2 Account (android.accounts.Account)1 Cursor (android.database.Cursor)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 SwitchPreference (android.preference.SwitchPreference)1 NavigationView (android.support.design.widget.NavigationView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1