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);
}
}
}
}
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();
}
}
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);
}
}
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);
}
}
}
}
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;
}
Aggregations