mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Merge pull request #1348 from nextcloud/activitiesThumbnails
Use ocs api header for thumbnails
This commit is contained in:
commit
6826f9dda3
3 changed files with 37 additions and 36 deletions
|
@ -43,6 +43,7 @@ import com.owncloud.android.authentication.AccountUtils;
|
|||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.ui.adapter.DiskLruImageCache;
|
||||
|
@ -352,6 +353,10 @@ public class ThumbnailsCacheManager {
|
|||
getMethod = new GetMethod(uri);
|
||||
getMethod.setRequestHeader("Cookie",
|
||||
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
|
||||
|
||||
getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
|
||||
RemoteOperation.OCS_API_HEADER_VALUE);
|
||||
|
||||
int status = mClient.executeMethod(getMethod);
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
InputStream inputStream = getMethod.getResponseBodyAsStream();
|
||||
|
|
|
@ -75,8 +75,8 @@ import java.util.List;
|
|||
|
||||
public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public static final int HEADER_TYPE = 100;
|
||||
public static final int ACTIVITY_TYPE = 101;
|
||||
private static final int HEADER_TYPE = 100;
|
||||
private static final int ACTIVITY_TYPE = 101;
|
||||
private final ActivityListInterface activityListInterface;
|
||||
private final int px;
|
||||
private static final String TAG = ActivityListAdapter.class.getSimpleName();
|
||||
|
@ -101,7 +101,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
String sTime = "";
|
||||
for (Object o : activityItems) {
|
||||
Activity activity = (Activity) o;
|
||||
String time = null;
|
||||
String time;
|
||||
if (activity.getDatetime() != null) {
|
||||
time = DisplayUtils.getRelativeTimestamp(context,
|
||||
activity.getDatetime().getTime()).toString();
|
||||
|
@ -182,18 +182,15 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
activityViewHolder.list.setVisibility(View.VISIBLE);
|
||||
activityViewHolder.list.removeAllViews();
|
||||
|
||||
activityViewHolder.list.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int w = activityViewHolder.list.getMeasuredWidth();
|
||||
int elPxSize = px + 20;
|
||||
int totalColumnCount = (int) Math.floor(w / elPxSize);
|
||||
activityViewHolder.list.post(() -> {
|
||||
int w = activityViewHolder.list.getMeasuredWidth();
|
||||
int elPxSize = px + 20;
|
||||
int totalColumnCount = (int) Math.floor(w / elPxSize);
|
||||
|
||||
try {
|
||||
activityViewHolder.list.setColumnCount(totalColumnCount);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log_OC.e(TAG, "error setting column count to " + totalColumnCount);
|
||||
}
|
||||
try {
|
||||
activityViewHolder.list.setColumnCount(totalColumnCount);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log_OC.e(TAG, "error setting column count to " + totalColumnCount);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -231,12 +228,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
params.setMargins(10, 10, 10, 10);
|
||||
ImageView imageView = new ImageView(context);
|
||||
imageView.setLayoutParams(params);
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
activityListInterface.onActivityClicked(richObject);
|
||||
}
|
||||
});
|
||||
imageView.setOnClickListener(v -> activityListInterface.onActivityClicked(richObject));
|
||||
setBitmap(file, imageView);
|
||||
|
||||
return imageView;
|
||||
|
@ -246,11 +238,19 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
// No Folder
|
||||
if (!file.isFolder()) {
|
||||
if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file))) {
|
||||
String uri = mClient.getBaseUri() + "" +
|
||||
"/index.php/apps/files/api/v1/thumbnail/" +
|
||||
px + "/" + px + Uri.encode(file.getRemotePath(), "/");
|
||||
int placeholder;
|
||||
|
||||
Glide.with(context).using(new CustomGlideStreamLoader()).load(uri).into(fileIcon); //Using custom fetcher
|
||||
if (MimeTypeUtil.isImage(file)) {
|
||||
placeholder = R.drawable.file_image;
|
||||
} else {
|
||||
placeholder = R.drawable.file_movie;
|
||||
}
|
||||
|
||||
String uri = mClient.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" + px + "/" + px +
|
||||
Uri.encode(file.getRemotePath(), "/");
|
||||
|
||||
Glide.with(context).using(new CustomGlideStreamLoader()).load(uri).placeholder(placeholder)
|
||||
.error(placeholder).into(fileIcon); // using custom fetcher
|
||||
|
||||
} else {
|
||||
fileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimetype(), file.getFileName(), null));
|
||||
|
@ -258,11 +258,8 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
} else {
|
||||
// Folder
|
||||
fileIcon.setImageDrawable(
|
||||
MimeTypeUtil.getFolderTypeIcon(
|
||||
file.isSharedWithMe() || file.isSharedWithSharee(),
|
||||
file.isSharedViaLink()
|
||||
)
|
||||
);
|
||||
MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
|
||||
file.isSharedViaLink()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,8 +275,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
.placeholder(R.drawable.ic_activity)
|
||||
.error(R.drawable.ic_activity)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.listener(new SvgSoftwareLayerSetter<Uri>());
|
||||
|
||||
.listener(new SvgSoftwareLayerSetter<>());
|
||||
|
||||
Uri uri = Uri.parse(icon);
|
||||
requestBuilder
|
||||
|
@ -319,7 +315,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
return ssb;
|
||||
}
|
||||
|
||||
public RichObject searchObjectByName(ArrayList<RichObject> richObjectList, String name) {
|
||||
private RichObject searchObjectByName(ArrayList<RichObject> richObjectList, String name) {
|
||||
for (RichObject richObject : richObjectList) {
|
||||
if (richObject.getTag().equalsIgnoreCase(name))
|
||||
return richObject;
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.owncloud.android.authentication.AccountUtils;
|
|||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
|
@ -65,12 +66,11 @@ public class HttpStreamFetcher implements DataFetcher<InputStream> {
|
|||
GetMethod get = null;
|
||||
try {
|
||||
get = new GetMethod(mURL);
|
||||
get.setRequestHeader("Cookie",
|
||||
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
|
||||
get.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
|
||||
get.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE);
|
||||
int status = mClient.executeMethod(get);
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
InputStream inputStream = get.getResponseBodyAsStream();
|
||||
return inputStream;
|
||||
return get.getResponseBodyAsStream();
|
||||
} else {
|
||||
mClient.exhaustResponse(get.getResponseBodyAsStream());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue