From 0f36ce9485fb47926f448d95ae87c3c513136e12 Mon Sep 17 00:00:00 2001 From: alejandro Date: Tue, 16 May 2017 10:02:21 -0500 Subject: [PATCH] Adding RichObject to Activity View --- .../ui/activity/ActivitiesListActivity.java | 26 +++-- .../ui/adapter/ActivityListAdapter.java | 78 +++++++------ .../android/ui/adapter/RichObjectAdapter.java | 108 +++++++++++++++--- .../ui/interfaces/ActivityListInterface.java | 4 +- 4 files changed, 159 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/ActivitiesListActivity.java b/src/main/java/com/owncloud/android/ui/activity/ActivitiesListActivity.java index 8baf1968c5..3de1210bde 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ActivitiesListActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ActivitiesListActivity.java @@ -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 diff --git a/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java index c4a8cb9190..d03b879973 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java @@ -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 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 activityItems) { @@ -122,7 +127,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter 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 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) diff --git a/src/main/java/com/owncloud/android/ui/adapter/RichObjectAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/RichObjectAdapter.java index 0a7702b11c..99fd19a922 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/RichObjectAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/RichObjectAdapter.java @@ -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 . + */ 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 { + private static final String TAG = RichObjectAdapter.class.getName(); private final Context mContext; - private ArrayList mValues; + private final int px; + private OwnCloudClient mClient; + private ArrayList 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 values){ - this.mValues=values; + public void setValues(ArrayList values,Uri baseUri) { + this.mBaseUri=baseUri; + this.mValues = values; notifyDataSetChanged(); } @@ -49,26 +84,67 @@ public class RichObjectAdapter extends RecyclerView.Adapter