*/\r
package com.owncloud.android.ui.adapter;\r
\r
+import java.io.ByteArrayInputStream;\r
import java.io.File;\r
import java.io.IOException;\r
+import java.io.InputStream;\r
import java.lang.ref.WeakReference;\r
+import java.net.URLEncoder;\r
//import java.net.URLEncoder;\r
import java.util.Vector;\r
\r
+import org.apache.commons.httpclient.methods.GetMethod;\r
+import org.apache.http.HttpStatus;\r
+\r
import android.accounts.Account;\r
import android.accounts.AuthenticatorException;\r
import android.accounts.OperationCanceledException;\r
import com.owncloud.android.lib.common.OwnCloudClient;\r
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;\r
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;\r
+import com.owncloud.android.lib.resources.shares.ShareUtils;\r
import com.owncloud.android.ui.activity.ComponentsGetter;\r
import com.owncloud.android.utils.DisplayUtils;\r
+import com.owncloud.android.utils.Log_OC;\r
\r
/*\r
import org.apache.http.HttpEntity;\r
private static final CompressFormat mCompressFormat = CompressFormat.JPEG;\r
private static final int mCompressQuality = 70;\r
private Bitmap defaultImg;\r
+ private OwnCloudClient client;\r
\r
public FileListListAdapter(\r
boolean justFolders, \r
\r
// Initialise disk cache on background thread\r
new InitDiskCacheTask().execute();\r
+ \r
+ \r
+ \r
}\r
\r
class InitDiskCacheTask extends AsyncTask<File, Void, Void> {\r
@Override\r
protected Void doInBackground(File... params) {\r
synchronized (thumbnailDiskCacheLock) {\r
+ OwnCloudAccount ocAccount;\r
+ try {\r
+ ocAccount = new OwnCloudAccount(mAccount, mContext);\r
+ client = OwnCloudClientManagerFactory.getDefaultSingleton().\r
+ getClientFor(ocAccount, mContext);\r
+ } catch (AccountNotFoundException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (AuthenticatorException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (OperationCanceledException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ \r
mThumbnailCache = new DiskLruImageCache(mContext, "thumbnailCache", \r
DISK_CACHE_SIZE, mCompressFormat, mCompressQuality);\r
\r
@Override\r
protected Bitmap doInBackground(OCFile... params) {\r
file = params[0];\r
- final String imageKey = String.valueOf(file.getRemoteId());\r
+ final String imageKey = String.valueOf(file.getRemoteId()).toLowerCase();\r
+ Log_OC.d("Thumbnail", imageKey);\r
\r
// Check disk cache in background thread\r
Bitmap thumbnail = getBitmapFromDiskCache(imageKey);\r
} else {\r
// Download thumbnail from server\r
// Commented out as maybe changes to client library are needed\r
-// DefaultHttpClient httpclient = new DefaultHttpClient();\r
-// try {\r
-// httpclient.getCredentialsProvider().setCredentials(\r
-// new AuthScope(mClient.getBaseUri().toString().replace("https://", ""), 443), \r
-// new UsernamePasswordCredentials(mClient.getCredentials().getUsername(), mClient.getCredentials().getAuthToken()));\r
-// \r
-//\r
-// HttpGet httpget = new HttpGet(mClient.getBaseUri() + "/ocs/v1.php/thumbnail?x=50&y=50&path=" + URLEncoder.encode(file.getRemotePath(), "UTF-8"));\r
-// HttpResponse response = httpclient.execute(httpget);\r
-// HttpEntity entity = response.getEntity();\r
-// \r
-// if (entity != null) {\r
-// byte[] bytes = EntityUtils.toByteArray(entity);\r
-// Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);\r
-// thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);\r
-// \r
-// // Add thumbnail to cache\r
-// if (thumbnail != null){\r
-// addBitmapToCache(imageKey, thumbnail);\r
-// }\r
-// }\r
-// } catch(Exception e){\r
-// e.printStackTrace();\r
-// }finally {\r
-// httpclient.getConnectionManager().shutdown();\r
-// }\r
+ try {\r
+ int status = -1;\r
+ \r
+ String uri = client.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/100/100"+URLEncoder.encode(file.getRemotePath(), "UTF-8");\r
+ Log_OC.d("Thumbnail", "URI: " + uri);\r
+ GetMethod get = new GetMethod(uri);\r
+ status = client.executeMethod(get);\r
+ if(isSuccess(status)) {\r
+ byte[] bytes = get.getResponseBody();\r
+ Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);\r
+ thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);\r
+ \r
+ // Add thumbnail to cache\r
+ if (thumbnail != null){\r
+ addBitmapToCache(imageKey, thumbnail);\r
+ }\r
+ }\r
+ } catch(Exception e){\r
+ e.printStackTrace();\r
+ }\r
} \r
}\r
return thumbnail;\r
}\r
+ \r
+ private boolean isSuccess(int status) {\r
+ return (status == HttpStatus.SC_OK);\r
+ }\r
+\r
\r
protected void onPostExecute(Bitmap bitmap){\r
if (isCancelled()) {\r
// get Thumbnail if file is image\r
if (file.isImage()){\r
// Thumbnail in Cache?\r
- Bitmap thumbnail = getBitmapFromDiskCache(String.valueOf(file.getRemoteId()));\r
+ Bitmap thumbnail = getBitmapFromDiskCache(String.valueOf(file.getRemoteId().toLowerCase()));\r
if (thumbnail != null){\r
fileIcon.setImageBitmap(thumbnail);\r
} else {\r