Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show files selected by the user #201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.filestack.android.internal;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.filestack.android.R;

import java.util.ArrayList;

public class LocalFilesAdapter extends RecyclerView.Adapter<LocalFilesAdapter.CustomViewHolder> {
private ArrayList<String> fileNames = new ArrayList<>();

@NonNull
@Override
public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.filestack__local_files_list_item, parent, false);
return new CustomViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull CustomViewHolder holder, int position) {
holder.text.setText(fileNames.get(position));
}

@Override
public int getItemCount() {
return fileNames.size();
}

void updateFileNames(ArrayList<String> fileNames) {
this.fileNames = fileNames;
notifyDataSetChanged();
}

public static class CustomViewHolder extends RecyclerView.ViewHolder {
protected TextView text;

CustomViewHolder(View itemView) {
super(itemView);
text = itemView.findViewById(R.id.text_id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ImageViewCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
Expand All @@ -39,6 +42,8 @@ public class LocalFilesFragment extends Fragment implements View.OnClickListener
private static final String ARG_ALLOW_MULTIPLE_FILES = "multipleFiles";
private static final int READ_REQUEST_CODE = RESULT_FIRST_USER;
private static final String ARG_THEME = "theme";
private LocalFilesAdapter adapter = new LocalFilesAdapter();
private ImageView uploadLocalFilesImageView;

public static Fragment newInstance(boolean allowMultipleFiles, Theme theme) {
Fragment fragment = new LocalFilesFragment();
Expand All @@ -58,7 +63,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st
Theme theme = getArguments().getParcelable(ARG_THEME);
ViewCompat.setBackgroundTintList(openGalleryButton, ColorStateList.valueOf(theme.getAccentColor()));
openGalleryButton.setTextColor(theme.getBackgroundColor());
ImageViewCompat.setImageTintList((ImageView) view.findViewById(R.id.icon), ColorStateList.valueOf(theme.getTextColor()));
uploadLocalFilesImageView = view.findViewById(R.id.icon);
ImageViewCompat.setImageTintList((uploadLocalFilesImageView), ColorStateList.valueOf(theme.getTextColor()));
RecyclerView filesListView = view.findViewById(R.id.gallery_list);
filesListView.setLayoutManager(new LinearLayoutManager(getContext()));
filesListView.setItemAnimator(new DefaultItemAnimator());
filesListView.setAdapter(adapter);
return view;
}

Expand Down Expand Up @@ -111,9 +121,20 @@ public void onActivityResult(int requestCode, int resultCode, Intent resultData)
uris.add(resultData.getData());
}

ArrayList<String> fileNames = new ArrayList<>();
for (Uri uri : uris) {
Selection selection = processUri(uri);
Util.getSelectionSaver().toggleItem(selection);
if (selection != null) {
fileNames.add(selection.getName());
}
}

if (fileNames.size() > 0) {
adapter.updateFileNames(fileNames);
uploadLocalFilesImageView.setVisibility(View.GONE);
} else {
uploadLocalFilesImageView.setVisibility(View.VISIBLE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#2196F3" android:pathData="M14,13V17H10V13H7L12,8L17,13M19.35,10.03C18.67,6.59 15.64,4 12,4C9.11,4 6.6,5.64 5.35,8.03C2.34,8.36 0,10.9 0,14A6,6 0 0,0 6,20H19A5,5 0 0,0 24,15C24,12.36 21.95,10.22 19.35,10.03Z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
app:headerLayout="@layout/filestack__nav_header_filestack"
app:elevation="0dp"/>

<View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -27,4 +28,11 @@
android:layout_marginStart="8dp"
android:text="@string/filestack__local_files_select" />

<android.support.v7.widget.RecyclerView
android:id="@+id/gallery_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_gravity="center"/>

</LinearLayout>
23 changes: 23 additions & 0 deletions filestack/src/main/res/layout/filestack__local_files_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/image_id"
android:layout_width="36dp"
app:srcCompat="@drawable/filestack__ic_file_upload_blue"
android:layout_height="36dp" />

<TextView
android:id="@+id/text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="Planet Name" />
</LinearLayout>
3 changes: 1 addition & 2 deletions filestack/src/main/res/menu/filestack__menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_upload"
android:icon="@drawable/filestack__ic_menu_upload_white"
android:title="@string/filestack__menu_upload"
app:showAsAction="ifRoom"
app:showAsAction="always"
android:orderInCategory="1"
android:visible="false"/>
<item
Expand Down