Replace the icon-class with an absolute link to an image

Otherwise the icon can not be displayed in mobile apps

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-03-13 20:25:22 +01:00 committed by Julius Härtl
parent ff6f105ea6
commit 403b673b93
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
6 changed files with 21 additions and 16 deletions

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
*
@ -24,7 +25,6 @@ namespace OCA\Files\Collaboration\Resources;
use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IURLGenerator;
@ -65,7 +65,7 @@ class ResourceProvider implements IProvider {
*
* @param IResource $resource
* @return string
* @since 15.0.0
* @since 16.0.0
*/
public function getName(IResource $resource): string {
if (isset($this->nodes[(int) $resource->getId()])) {
@ -84,7 +84,7 @@ class ResourceProvider implements IProvider {
* @param IResource $resource
* @param IUser $user
* @return bool
* @since 15.0.0
* @since 16.0.0
*/
public function canAccessResource(IResource $resource, IUser $user = null): bool {
if (!$user instanceof IUser) {
@ -107,21 +107,25 @@ class ResourceProvider implements IProvider {
*
* @param IResource $resource
* @return string
* @since 15.0.0
* @since 16.0.0
*/
public function getIconClass(IResource $resource): string {
public function getIconLink(IResource $resource): string {
$node = $this->getNode($resource);
if ($node && $node->getMimetype() === 'httpd/unix-directory') {
return 'icon-files-dark';
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath('core', 'places/files')
);
}
return 'icon-filetype-file';
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath('core', 'filetypes/file')
);
}
/**
* Get the resource type of the provider
*
* @return string
* @since 15.0.0
* @since 16.0.0
*/
public function getType(): string {
return self::RESOURCE_TYPE;
@ -132,7 +136,7 @@ class ResourceProvider implements IProvider {
*
* @param IResource $resource
* @return string
* @since 15.0.0
* @since 16.0.0
*/
public function getLink(IResource $resource): string {
return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]);

View File

@ -245,7 +245,7 @@ class CollaborationResourcesController extends OCSController {
'type' => $resource->getType(),
'id' => $resource->getId(),
'name' => $resource->getName(),
'iconClass' => $resource->getIconClass(),
'iconLink' => $resource->getIconLink(),
'link' => $resource->getLink(),
];
}

View File

@ -309,11 +309,11 @@ class Manager implements IManager {
* @param IResource $resource
* @return string
*/
public function getIconClass(IResource $resource): string {
public function getIconLink(IResource $resource): string {
foreach ($this->getProviders() as $provider) {
if ($provider->getType() === $resource->getType()) {
try {
return $provider->getIconClass($resource);
return $provider->getIconLink($resource);
} catch (ResourceException $e) {
}
}

View File

@ -106,9 +106,9 @@ class Resource implements IResource {
* @return string
* @since 16.0.0
*/
public function getIconClass(): string {
public function getIconLink(): string {
if ($this->iconClass === null) {
$this->iconClass = $this->manager->getIconClass($this);
$this->iconClass = $this->manager->getIconLink($this);
}
return $this->iconClass;

View File

@ -53,7 +53,7 @@ interface IProvider {
* @return string
* @since 16.0.0
*/
public function getIconClass(IResource $resource): string;
public function getIconLink(IResource $resource): string;
/**
* Get the link to a resource

View File

@ -48,10 +48,11 @@ interface IResource {
public function getName(): string;
/**
* Absolute link to an icon to represent the resource
* @return string
* @since 16.0.0
*/
public function getIconClass(): string;
public function getIconLink(): string;
/**
* @return string