Search in sources :

Example 1 with ExternalLink

use of com.owncloud.android.lib.common.ExternalLink in project android by nextcloud.

the class SettingsActivity method loadExternalSettingLinks.

private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) {
    if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());
        for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) {
            // only add if it does not exist, in case activity is re-used
            if (findPreference(String.valueOf(link.getId())) == null) {
                Preference p = new Preference(this);
                p.setTitle(link.getName());
                p.setKey(String.valueOf(link.getId()));
                p.setOnPreferenceClickListener(preference -> {
                    Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.getName());
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.getUrl());
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
                    externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, link.getId());
                    startActivity(externalWebViewIntent);
                    return true;
                });
                preferenceCategory.addPreference(p);
            }
        }
    }
}
Also used : ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) ExternalLinksProvider(com.owncloud.android.datamodel.ExternalLinksProvider) Intent(android.content.Intent) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Example 2 with ExternalLink

use of com.owncloud.android.lib.common.ExternalLink in project android by nextcloud.

the class DrawerActivity method fetchExternalLinks.

/**
 * Retrieves external links via api from 'external' app
 */
public void fetchExternalLinks(final boolean force) {
    if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        Thread t = new Thread(() -> {
            // fetch capabilities as early as possible
            if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) {
                GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
                getCapabilities.execute(getBaseContext());
            }
            User user = accountManager.getUser();
            String name = user.getAccountName();
            if (getStorageManager() != null && getStorageManager().getCapability(name).getExternalLinks().isTrue()) {
                int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT);
                if (count > 10 || count == -1 || force) {
                    if (force) {
                        Log_OC.d("ExternalLinks", "force update");
                    }
                    arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0");
                    Log_OC.d("ExternalLinks", "update via api");
                    RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
                    RemoteOperationResult result = getExternalLinksOperation.execute(user.toPlatformAccount(), this);
                    if (result.isSuccess() && result.getData() != null) {
                        externalLinksProvider.deleteAllExternalLinks();
                        ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
                        for (ExternalLink link : externalLinks) {
                            externalLinksProvider.storeExternalLink(link);
                        }
                    }
                } else {
                    arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
                }
            } else {
                externalLinksProvider.deleteAllExternalLinks();
                Log_OC.d("ExternalLinks", "links disabled");
            }
            runOnUiThread(this::updateExternalLinksInDrawer);
        });
        t.start();
    }
}
Also used : GetUserInfoRemoteOperation(com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetCapabilitiesOperation(com.owncloud.android.operations.GetCapabilitiesOperation) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList) ExternalLinksOperation(com.owncloud.android.lib.common.accounts.ExternalLinksOperation) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Example 3 with ExternalLink

use of com.owncloud.android.lib.common.ExternalLink in project android by nextcloud.

the class DrawerActivity method updateExternalLinksInDrawer.

private void updateExternalLinksInDrawer() {
    if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links);
        float density = getResources().getDisplayMetrics().density;
        final int size = Math.round(24 * density);
        int greyColor = ContextCompat.getColor(this, R.color.drawer_menu_icon);
        for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
            int id = mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK + link.getId(), MENU_ORDER_EXTERNAL_LINKS, link.getName()).setCheckable(true).getItemId();
            MenuSimpleTarget target = new MenuSimpleTarget<Drawable>(id) {

                @Override
                public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                    setExternalLinkIcon(getIdMenuItem(), resource, greyColor);
                }

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    super.onLoadFailed(e, errorDrawable);
                    setExternalLinkIcon(getIdMenuItem(), errorDrawable, greyColor);
                }
            };
            DisplayUtils.downloadIcon(getUserAccountManager(), clientFactory, this, link.getIconUrl(), target, R.drawable.ic_link, size, size);
        }
        setDrawerMenuItemChecked(mCheckedMenuItem);
    }
}
Also used : MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ExternalLink(com.owncloud.android.lib.common.ExternalLink) AuthenticatorException(android.accounts.AuthenticatorException) OperationCanceledException(android.accounts.OperationCanceledException) IOException(java.io.IOException)

Example 4 with ExternalLink

use of com.owncloud.android.lib.common.ExternalLink in project android by nextcloud.

the class Preferences method loadExternalSettingLinks.

private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) {
    if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());
        for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) {
            // only add if it does not exist, in case activity is re-used
            if (findPreference(link.id.toString()) == null) {
                Preference p = new Preference(this);
                p.setTitle(link.name);
                p.setKey(link.id.toString());
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.name);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.url);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, link.id);
                        startActivity(externalWebViewIntent);
                        return true;
                    }
                });
                preferenceCategory.addPreference(p);
            }
        }
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference) ExternalLinksProvider(com.owncloud.android.datamodel.ExternalLinksProvider) Intent(android.content.Intent) ExternalLink(com.owncloud.android.lib.common.ExternalLink)

Example 5 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.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta._ID));
        String iconUrl = cursor.getString(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_ICON_URL));
        String language = cursor.getString(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE));
        ExternalLinkType type;
        switch(cursor.getString(cursor.getColumnIndexOrThrow(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.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME));
        String url = cursor.getString(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL));
        boolean redirect = cursor.getInt(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) == 1;
        externalLink = new ExternalLink(id, iconUrl, language, type, name, url, redirect);
    }
    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)8 Intent (android.content.Intent)4 AuthenticatorException (android.accounts.AuthenticatorException)2 OperationCanceledException (android.accounts.OperationCanceledException)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 ListPreference (android.preference.ListPreference)2 Preference (android.preference.Preference)2 SwitchPreference (android.preference.SwitchPreference)2 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)2 ExternalLinksProvider (com.owncloud.android.datamodel.ExternalLinksProvider)2 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Cursor (android.database.Cursor)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 User (com.nextcloud.client.account.User)1