Skip to content

Commit

Permalink
Merge pull request #2533 from nextcloud/fileDetail
Browse files Browse the repository at this point in the history
Iteration 1 for File detail & new sharing
  • Loading branch information
AndyScherzinger authored May 9, 2018
2 parents 14a127e + 200e5aa commit ad064fd
Show file tree
Hide file tree
Showing 26 changed files with 1,333 additions and 520 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ dependencies {
// dependencies for app building
implementation 'com.android.support:multidex:1.0.3'
// implementation project('nextcloud-android-library')
genericImplementation "com.github.nextcloud:android-library:${androidLibraryVersion}"
gplayImplementation "com.github.nextcloud:android-library:${androidLibraryVersion}"
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' // use always latest master
genericImplementation "com.github.nextcloud:android-library:filterActivities-SNAPSHOT"
gplayImplementation "com.github.nextcloud:android-library:filterActivities-SNAPSHOT"
versionDevImplementation 'com.github.nextcloud:android-library:filterActivities-SNAPSHOT' // use always latest master
implementation "com.android.support:support-v4:${supportLibraryVersion}"
implementation "com.android.support:design:${supportLibraryVersion}"
implementation 'com.jakewharton:disklrucache:2.0.2'
Expand Down
1 change: 1 addition & 0 deletions drawable_resources/ic_star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions drawable_resources/ic_star_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions drawable_resources/ic_tag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scripts/lint/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 114 warnings</span>
<span class="mdl-layout-title">Lint Report: 113 warnings</span>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.ui.adapter.DiskLruImageCache;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.utils.BitmapUtils;
import com.owncloud.android.utils.ConnectivityUtils;
Expand Down Expand Up @@ -208,17 +209,17 @@ public static Bitmap getBitmapFromDiskCache(String key) {
}

public static class ResizedImageGenerationTask extends AsyncTask<Object, Void, Bitmap> {
private PreviewImageFragment previewImageFragment;
private FileFragment fileFragment;
private FileDataStorageManager storageManager;
private Account account;
private WeakReference<ImageView> imageViewReference;
private OCFile file;


public ResizedImageGenerationTask(PreviewImageFragment previewImageFragment, ImageView imageView,
public ResizedImageGenerationTask(FileFragment fileFragment, ImageView imageView,
FileDataStorageManager storageManager, Account account)
throws IllegalArgumentException {
this.previewImageFragment = previewImageFragment;
this.fileFragment = fileFragment;
imageViewReference = new WeakReference<>(imageView);
this.storageManager = storageManager;
this.account = account;
Expand Down Expand Up @@ -350,9 +351,13 @@ protected void onPostExecute(Bitmap bitmap) {
} else {
new Thread(() -> {
if (ConnectivityUtils.isInternetWalled(MainApp.getAppContext())) {
previewImageFragment.setNoConnectionErrorMessage();
if (fileFragment instanceof PreviewImageFragment) {
((PreviewImageFragment) fileFragment).setNoConnectionErrorMessage();
}
} else {
previewImageFragment.setErrorPreviewMessage();
if (fileFragment instanceof PreviewImageFragment) {
((PreviewImageFragment) fileFragment).setErrorPreviewMessage();
}
}
}).start();

Expand Down
42 changes: 27 additions & 15 deletions src/main/java/com/owncloud/android/files/FileMenuFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,46 @@ public void filter(Menu menu, boolean inSingleFileFragment) {

filter(toShow, toHide, inSingleFileFragment);

MenuItem item;
for (int i : toShow) {
item = menu.findItem(i);
if (item != null) {
item.setVisible(true);
item.setEnabled(true);
}
showMenuItem(menu.findItem(i));
}

for (int i : toHide) {
item = menu.findItem(i);
if (item != null) {
item.setVisible(false);
item.setEnabled(false);
}
hideMenuItem(menu.findItem(i));
}
}
}

private void hideAll(Menu menu) {
MenuItem item;
for (int i = 0; i < menu.size(); i++) {
item = menu.getItem(i);
public static void hideAll(Menu menu) {
if (menu != null) {
for (int i = 0; i < menu.size(); i++) {
hideMenuItem(menu.getItem(i));
}
}
}

private static void hideMenuItem(MenuItem item) {
if (item != null) {
item.setVisible(false);
item.setEnabled(false);
}
}

private static void showMenuItem(MenuItem item) {
if (item != null) {
item.setVisible(true);
item.setEnabled(true);
}
}

public static void hideMenuItems(MenuItem... items) {
if (items != null) {
for (MenuItem item : items) {
hideMenuItem(item);
}
}
}

/**
* Performs the real filtering, to be applied in the {@link Menu} by the caller methods.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Nextcloud Android client application
*
* @author Andy Scherzinger
* Copyright (C) 2018 Andy Scherzinger
*
* 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.accounts.Account;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.fragment.FileDetailActivitiesFragment;
import com.owncloud.android.ui.fragment.FileDetailSharingFragment;

/**
* File details pager adapter.
*/
public class FileDetailTabAdapter extends FragmentStatePagerAdapter {
private OCFile file;
private Account account;

public FileDetailTabAdapter(FragmentManager fm, OCFile file, Account account) {
super(fm);

this.file = file;
this.account = account;
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return FileDetailActivitiesFragment.newInstance(file, account);
case 1:
return FileDetailSharingFragment.newInstance(file, account);
default:
return null;
}
}

@Override
public int getCount() {
return 2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -32,7 +33,10 @@
import com.owncloud.android.R;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.ui.TextDrawable;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

/**
Expand All @@ -43,13 +47,16 @@ public class ShareUserListAdapter extends ArrayAdapter {
private Context mContext;
private ArrayList<OCShare> mShares;
private ShareUserAdapterListener mListener;
private float mAvatarRadiusDimension;

public ShareUserListAdapter(Context context, int resource, ArrayList<OCShare>shares,
ShareUserAdapterListener listener) {
super(context, resource);
mContext= context;
mShares = shares;
mListener = listener;

mAvatarRadiusDimension = context.getResources().getDimension(R.dimen.standard_padding);
}

@Override
Expand All @@ -67,32 +74,46 @@ public long getItemId(int position) {
return 0;
}

@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflator = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.share_user_item, parent, false);
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.share_user_item, parent, false);
}

if (mShares != null && mShares.size() > position) {
OCShare share = mShares.get(position);

TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
ImageView iconView = (ImageView) view.findViewById(R.id.icon);
final ImageView editShareButton = (ImageView) view.findViewById(R.id.editShareButton);
final ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton);
TextView userName = view.findViewById(R.id.userOrGroupName);
ImageView icon = view.findViewById(R.id.icon);
final ImageView editShareButton = view.findViewById(R.id.editShareButton);
final ImageView unshareButton = view.findViewById(R.id.unshareButton);

String name = share.getSharedWithDisplayName();
Drawable icon = getContext().getResources().getDrawable(R.drawable.ic_user);
if (share.getShareType() == ShareType.GROUP) {
name = getContext().getString(R.string.share_group_clarification, name);
icon = getContext().getResources().getDrawable(R.drawable.ic_group);
try {
icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
icon.setImageResource(R.drawable.ic_group);
}
} else if (share.getShareType() == ShareType.EMAIL) {
name = getContext().getString(R.string.share_email_clarification, name);
icon = getContext().getResources().getDrawable(R.drawable.ic_email);
editShareButton.setVisibility(View.INVISIBLE);
try {
icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
icon.setImageResource(R.drawable.ic_email);
}
} else {
try {
icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
icon.setImageResource(R.drawable.ic_user);
}
}
userName.setText(name);
iconView.setImageDrawable(icon);

/// bind listener to edit privileges
editShareButton.setOnClickListener(new View.OnClickListener() {
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import com.owncloud.android.R;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.ui.TextDrawable;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

/**
Expand All @@ -42,11 +45,14 @@ public class UserListAdapter extends ArrayAdapter {

private Context mContext;
private ArrayList<OCShare> mShares;
private float mAvatarRadiusDimension;

public UserListAdapter(Context context, int resource, ArrayList<OCShare> shares) {
super(context, resource);
mContext = context;
mShares = shares;

mAvatarRadiusDimension = context.getResources().getDimension(R.dimen.standard_padding);
}

@Override
Expand Down Expand Up @@ -75,15 +81,29 @@ public long getItemId(int position) {
if (mShares != null && mShares.size() > position) {
OCShare share = mShares.get(position);

TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
ImageView icon = (ImageView) view.findViewById(R.id.userIcon);
TextView userName = view.findViewById(R.id.userOrGroupName);
ImageView icon = view.findViewById(R.id.userIcon);
String name = share.getSharedWithDisplayName();
if (share.getShareType() == ShareType.GROUP) {
name = getContext().getString(R.string.share_group_clarification, name);
icon.setImageResource(R.drawable.ic_group);
try {
icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
icon.setImageResource(R.drawable.ic_group);
}
} else if (share.getShareType() == ShareType.EMAIL) {
name = getContext().getString(R.string.share_email_clarification, name);
icon.setImageResource(R.drawable.ic_email);
try {
icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
icon.setImageResource(R.drawable.ic_email);
}
} else {
try {
icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
icon.setImageResource(R.drawable.ic_user);
}
}
userName.setText(name);

Expand Down
Loading

0 comments on commit ad064fd

Please sign in to comment.