mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
Adding RichObject to Activity View
This commit is contained in:
parent
2e6953064a
commit
0f36ce9485
4 changed files with 159 additions and 57 deletions
|
@ -30,7 +30,6 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
|
@ -51,6 +50,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
|
|||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.activities.GetRemoteActivitiesOperation;
|
||||
import com.owncloud.android.lib.resources.activities.models.RichObject;
|
||||
import com.owncloud.android.ui.adapter.ActivityListAdapter;
|
||||
import com.owncloud.android.ui.interfaces.ActivityListInterface;
|
||||
import com.owncloud.android.ui.preview.PreviewImageActivity;
|
||||
|
@ -105,6 +105,7 @@ public class ActivitiesListActivity extends FileActivity implements ActivityList
|
|||
|
||||
private ActivityListAdapter adapter;
|
||||
private Unbinder unbinder;
|
||||
private OwnCloudClient mClient;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -140,6 +141,20 @@ public class ActivitiesListActivity extends FileActivity implements ActivityList
|
|||
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(
|
||||
AccountUtils.getCurrentOwnCloudAccount( MainApp.getAppContext()),this
|
||||
|
||||
);
|
||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
Log_OC.i(TAG,e.getMessage());
|
||||
}
|
||||
|
||||
setupContent();
|
||||
}
|
||||
|
||||
|
@ -163,15 +178,12 @@ public class ActivitiesListActivity extends FileActivity implements ActivityList
|
|||
emptyContentIcon.setImageResource(R.drawable.ic_activity_light_grey);
|
||||
setLoadingMessage();
|
||||
|
||||
adapter = new ActivityListAdapter(this,this);
|
||||
adapter = new ActivityListAdapter(this,this,mClient);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
|
||||
layoutManager.getOrientation());
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
//recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_view);
|
||||
|
||||
|
@ -315,9 +327,9 @@ public class ActivitiesListActivity extends FileActivity implements ActivityList
|
|||
|
||||
|
||||
@Override
|
||||
public void onActivityClicked() {
|
||||
public void onActivityClicked(RichObject richObject) {
|
||||
Intent showDetailsIntent;
|
||||
OCFile ocFile=new OCFile("/alex123.jpg");
|
||||
OCFile ocFile=new OCFile("/"+richObject.getPath());
|
||||
if(PreviewImageFragment.canBePreviewed(ocFile))
|
||||
showDetailsIntent = new Intent(this, PreviewImageActivity.class);
|
||||
else
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.support.v7.widget.GridLayoutManager;
|
|||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
|
@ -43,7 +42,10 @@ import com.bumptech.glide.load.model.StreamEncoder;
|
|||
import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.resources.activities.models.Activity;
|
||||
import com.owncloud.android.lib.resources.activities.models.RichObject;
|
||||
import com.owncloud.android.lib.resources.activities.models.RichSubject;
|
||||
import com.owncloud.android.ui.interfaces.ActivityListInterface;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.svg.SvgDecoder;
|
||||
|
@ -64,14 +66,17 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
public static final int HEADER_TYPE=100;
|
||||
public static final int ACTIVITY_TYPE=101;
|
||||
private final ActivityListInterface activityListInterface;
|
||||
private final OwnCloudClient mClient;
|
||||
|
||||
private Context context;
|
||||
private List<Object> mValues;
|
||||
|
||||
public ActivityListAdapter(Context context, ActivityListInterface activityListInterface) {
|
||||
public ActivityListAdapter(Context context, ActivityListInterface activityListInterface,OwnCloudClient client) {
|
||||
this.mValues = new ArrayList<>();
|
||||
this.context = context;
|
||||
this.activityListInterface=activityListInterface;
|
||||
this.mClient=client;
|
||||
|
||||
}
|
||||
|
||||
public void setActivityItems(List<Object> activityItems) {
|
||||
|
@ -122,7 +127,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
if (!TextUtils.isEmpty(activity.getSubject())) {
|
||||
activityViewHolder.subject.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
activityViewHolder.subject.setText(addClickablePart("{user} aceptó la compartición remota de {file}"), TextView.BufferType.SPANNABLE);
|
||||
activityViewHolder.subject.setText(addClickablePart(activity.getRichSubject()), TextView.BufferType.SPANNABLE);
|
||||
activityViewHolder.subject.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
activityViewHolder.subject.setVisibility(View.GONE);
|
||||
|
@ -139,17 +144,12 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
downloadIcon(activity.getIcon(), activityViewHolder.activityIcon);
|
||||
}
|
||||
|
||||
ArrayList<String> richObjects=new ArrayList<>();
|
||||
richObjects.add("http://static3.businessinsider.com/image/55b675ab2acae7c7018ba34e-1200/milky-way-galaxy.jpg");
|
||||
richObjects.add("http://static3.businessinsider.com/image/55b675ab2acae7c7018ba34e-1200/milky-way-galaxy.jpg");
|
||||
richObjects.add("http://static3.businessinsider.com/image/55b675ab2acae7c7018ba34e-1200/milky-way-galaxy.jpg");
|
||||
richObjects.add("http://static3.businessinsider.com/image/55b675ab2acae7c7018ba34e-1200/milky-way-galaxy.jpg");
|
||||
richObjects.add("http://static3.businessinsider.com/image/55b675ab2acae7c7018ba34e-1200/milky-way-galaxy.jpg");
|
||||
|
||||
RichObjectAdapter richObjectAdapter=new RichObjectAdapter(context,activityListInterface);
|
||||
activityViewHolder.list.setLayoutManager(new GridLayoutManager(context,4));
|
||||
activityViewHolder.list.setAdapter(richObjectAdapter);
|
||||
richObjectAdapter.setValues(richObjects);
|
||||
if(activity.getRichSubject()!=null && activity.richSubject.getRichObjectList().size()>0) {
|
||||
RichObjectAdapter richObjectAdapter = new RichObjectAdapter(context, activityListInterface);
|
||||
activityViewHolder.list.setLayoutManager(new GridLayoutManager(context, 4));
|
||||
activityViewHolder.list.setAdapter(richObjectAdapter);
|
||||
richObjectAdapter.setValues(activity.richSubject.getRichObjectList(),mClient.getBaseUri());
|
||||
}
|
||||
|
||||
}else{
|
||||
ActivityViewHeaderHolder activityViewHeaderHolder=(ActivityViewHeaderHolder)holder;
|
||||
|
@ -179,32 +179,44 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
.into(itemViewType);
|
||||
}
|
||||
|
||||
private SpannableStringBuilder addClickablePart(String str) {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(str);
|
||||
private SpannableStringBuilder addClickablePart(RichSubject richSubject) {
|
||||
String text=richSubject.getRichSubject();
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
|
||||
|
||||
int idx1 = str.indexOf("{");
|
||||
int idx2 = 0;
|
||||
int idx1 = text.indexOf("{");
|
||||
int idx2;
|
||||
while (idx1 != -1) {
|
||||
idx2 = str.indexOf("}", idx1) + 1;
|
||||
|
||||
String stringFake="alex12345.png";
|
||||
ssb.replace(idx1,idx2,stringFake);
|
||||
str=ssb.toString();
|
||||
idx2=idx1+stringFake.length();
|
||||
final String clickString = str.substring(idx1, idx2);
|
||||
ssb.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
activityListInterface.onActivityClicked();
|
||||
}
|
||||
}, idx1, idx2, 0);
|
||||
ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),idx1,idx2,0);
|
||||
idx1 = str.indexOf("{", idx2);
|
||||
idx2 = text.indexOf("}", idx1) + 1;
|
||||
final String clickString = text.substring(idx1+1, idx2-1);
|
||||
final RichObject richObject=searchObjectByName(richSubject.getRichObjectList(),clickString);
|
||||
if(richObject!=null) {
|
||||
String name = richObject.getName();
|
||||
ssb.replace(idx1, idx2, name);
|
||||
text = ssb.toString();
|
||||
idx2 = idx1 + name.length();
|
||||
ssb.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
activityListInterface.onActivityClicked(richObject);
|
||||
}
|
||||
}, idx1, idx2, 0);
|
||||
ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), idx1, idx2, 0);
|
||||
}
|
||||
idx1 = text.indexOf("{", idx2);
|
||||
}
|
||||
|
||||
return ssb;
|
||||
}
|
||||
|
||||
public RichObject searchObjectByName(ArrayList<RichObject> richObjectList,String name){
|
||||
for (RichObject richObject : richObjectList) {
|
||||
if(richObject.getTag().equalsIgnoreCase(name))
|
||||
return richObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if(mValues.get(position) instanceof Activity)
|
||||
|
|
|
@ -1,6 +1,27 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Alejandro Bautista
|
||||
* Copyright (C) 2017 Alejandro Bautista
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -10,29 +31,43 @@ import android.widget.ImageView;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.resources.activities.models.RichObject;
|
||||
import com.owncloud.android.ui.interfaces.ActivityListInterface;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
import com.owncloud.android.utils.glide.CustomGlideStreamLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by alejandro on 11/05/17.
|
||||
* Rich Object Adapter
|
||||
*/
|
||||
|
||||
public class RichObjectAdapter extends RecyclerView.Adapter<RichObjectAdapter.RichObjectViewHolder> {
|
||||
|
||||
private static final String TAG = RichObjectAdapter.class.getName();
|
||||
private final Context mContext;
|
||||
private ArrayList<String> mValues;
|
||||
private final int px;
|
||||
private OwnCloudClient mClient;
|
||||
private ArrayList<RichObject> mValues;
|
||||
private final ActivityListInterface mActivityListInterface;
|
||||
private Uri mBaseUri;
|
||||
|
||||
|
||||
public RichObjectAdapter(Context context, ActivityListInterface activityListInterface) {
|
||||
this.mContext = context;
|
||||
this.mValues = new ArrayList<>();
|
||||
this.mActivityListInterface = activityListInterface;
|
||||
px=getThumbnailDimension();
|
||||
|
||||
|
||||
public RichObjectAdapter(Context context, ActivityListInterface activityListInterface){
|
||||
this.mContext=context;
|
||||
this.mValues=new ArrayList<>();
|
||||
this.mActivityListInterface=activityListInterface;
|
||||
}
|
||||
|
||||
|
||||
public void setValues(ArrayList<String> values){
|
||||
this.mValues=values;
|
||||
public void setValues(ArrayList<RichObject> values,Uri baseUri) {
|
||||
this.mBaseUri=baseUri;
|
||||
this.mValues = values;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@ -49,26 +84,67 @@ public class RichObjectAdapter extends RecyclerView.Adapter<RichObjectAdapter.Ri
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(RichObjectViewHolder holder, int position) {
|
||||
String url=mValues.get(position);
|
||||
Glide.with(mContext)
|
||||
.load(url)
|
||||
.into(holder.image);
|
||||
final RichObject richObject = mValues.get(position);
|
||||
|
||||
|
||||
OCFile file = new OCFile("/" + richObject.getPath());
|
||||
file.setRemoteId(richObject.getId());
|
||||
holder.image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mActivityListInterface.onActivityClicked();
|
||||
mActivityListInterface.onActivityClicked(richObject);
|
||||
}
|
||||
});
|
||||
setBitmap(file, holder.image);
|
||||
}
|
||||
|
||||
static class RichObjectViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
public void setBitmap(OCFile file, ImageView fileIcon) {
|
||||
// No Folder
|
||||
if (!file.isFolder()) {
|
||||
if ((MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file)) ) {
|
||||
String uri = mBaseUri+ "" +
|
||||
"/index.php/apps/files/api/v1/thumbnail/" +
|
||||
px + "/" + px + Uri.encode(file.getRemotePath(), "/");
|
||||
|
||||
Glide.with(mContext).using(new CustomGlideStreamLoader()).load(uri).into(fileIcon); //Using custom fetcher
|
||||
|
||||
} else {
|
||||
fileIcon.setImageResource(MimeTypeUtil.getFileTypeIconId(file.getMimetype(),
|
||||
file.getFileName()));
|
||||
}
|
||||
} else {
|
||||
// Folder
|
||||
fileIcon.setImageResource(
|
||||
MimeTypeUtil.getFolderTypeIconId(
|
||||
file.isSharedWithMe() || file.isSharedWithSharee(),
|
||||
file.isSharedViaLink()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class RichObjectViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
ImageView image;
|
||||
RichObjectViewHolder(View v){
|
||||
|
||||
RichObjectViewHolder(View v) {
|
||||
super(v);
|
||||
image=(ImageView)v.findViewById(R.id.image);
|
||||
image = (ImageView) v.findViewById(R.id.image);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts size of file icon from dp to pixel
|
||||
* @return int
|
||||
*/
|
||||
private int getThumbnailDimension(){
|
||||
// Converts dp to pixel
|
||||
Resources r = MainApp.getAppContext().getResources();
|
||||
Double d = Math.pow(2,Math.floor(Math.log(r.getDimension(R.dimen.file_icon_size_grid))/Math.log(2)));
|
||||
return d.intValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package com.owncloud.android.ui.interfaces;
|
||||
|
||||
import com.owncloud.android.lib.resources.activities.models.RichObject;
|
||||
|
||||
/**
|
||||
* Created by alejandro on 12/05/17.
|
||||
*/
|
||||
|
||||
public interface ActivityListInterface {
|
||||
|
||||
void onActivityClicked();
|
||||
void onActivityClicked(RichObject richObject);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue