Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #89 from spacecowboy/fastscroller
Browse files Browse the repository at this point in the history
Add FastScroller sample implementation
  • Loading branch information
spacecowboy committed Jun 8, 2016
2 parents 2dff306 + 6b8a787 commit b879497
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 10 deletions.
5 changes: 4 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
}

defaultConfig {
minSdkVersion 9
minSdkVersion 11
targetSdkVersion 23
versionCode gitCommitCount
versionName gitTag
Expand Down Expand Up @@ -50,4 +50,7 @@ dependencies {

// Root example
compile 'eu.chainfire:libsuperuser:1.0.0.+'

// Fast scroll example
compile 'com.simplecityapps:recyclerview-fastscroll:1.0.9'
}
24 changes: 22 additions & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</activity>

<activity
android:name=".MultimediaPickerActivity"
android:name=".multimedia.MultimediaPickerActivity"
android:label="@string/title_activity_no_nonsense_file_picker"
android:theme="@style/SampleTheme">
<intent-filter>
Expand All @@ -62,6 +62,16 @@
</intent-filter>
</activity>

<activity
android:name=".multimedia.MultimediaPickerActivity2"
android:label="@string/title_activity_no_nonsense_file_picker"
android:theme="@style/SampleThemeLight">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".root.SUPickerActivity"
android:label="@string/title_activity_no_nonsense_file_picker"
Expand All @@ -83,7 +93,7 @@
</activity>

<activity
android:name=".MultimediaPickerActivity2"
android:name=".fastscroller.FastScrollerFilePickerActivity"
android:label="@string/title_activity_no_nonsense_file_picker"
android:theme="@style/SampleThemeLight">
<intent-filter>
Expand All @@ -92,6 +102,16 @@
</intent-filter>
</activity>

<activity
android:name=".fastscroller.FastScrollerFilePickerActivity2"
android:label="@string/title_activity_no_nonsense_file_picker"
android:theme="@style/SampleTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<!-- FtpPickers -->
<activity
android:name="com.nononsenseapps.filepicker.sample.ftp.FtpPickerActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
import com.nononsenseapps.filepicker.sample.dropbox.DropboxFilePickerActivity;
import com.nononsenseapps.filepicker.sample.dropbox.DropboxFilePickerActivity2;
import com.nononsenseapps.filepicker.sample.dropbox.DropboxSyncHelper;
import com.nononsenseapps.filepicker.sample.fastscroller.FastScrollerFilePickerActivity;
import com.nononsenseapps.filepicker.sample.fastscroller.FastScrollerFilePickerActivity2;
import com.nononsenseapps.filepicker.sample.ftp.FtpPickerActivity;
import com.nononsenseapps.filepicker.sample.ftp.FtpPickerActivity2;
import com.nononsenseapps.filepicker.sample.multimedia.MultimediaPickerActivity;
import com.nononsenseapps.filepicker.sample.multimedia.MultimediaPickerActivity2;
import com.nononsenseapps.filepicker.sample.root.SUPickerActivity;
import com.nononsenseapps.filepicker.sample.root.SUPickerActivity2;

Expand Down Expand Up @@ -244,11 +248,50 @@ public void onClick(View v) {
Intent i;

if (checkLightTheme.isChecked()) {
i = new Intent(NoNonsenseFilePicker.this,
SUPickerActivity.class);
} else {
i = new Intent(NoNonsenseFilePicker.this,
SUPickerActivity2.class);
}
i.setAction(Intent.ACTION_GET_CONTENT);

i.putExtra(SUPickerActivity.EXTRA_ALLOW_MULTIPLE,
checkAllowMultiple.isChecked());
i.putExtra(SUPickerActivity.EXTRA_ALLOW_CREATE_DIR,
checkAllowCreateDir.isChecked());

// What mode is selected (makes no sense to restrict to folders here)
final int mode;
switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.radioFilesAndDirs:
mode =
AbstractFilePickerFragment.MODE_FILE_AND_DIR;
break;
case R.id.radioFile:
default:
mode = AbstractFilePickerFragment.MODE_FILE;
break;
}

i.putExtra(FilePickerActivity.EXTRA_MODE, mode);


startActivityForResult(i, CODE_SD);
}
});

findViewById(R.id.button_fastscroll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i;

if (checkLightTheme.isChecked()) {
i = new Intent(NoNonsenseFilePicker.this,
FastScrollerFilePickerActivity.class);
} else {
i = new Intent(NoNonsenseFilePicker.this,
SUPickerActivity.class);
FastScrollerFilePickerActivity2.class);
}
i.setAction(Intent.ACTION_GET_CONTENT);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.nononsenseapps.filepicker.sample.fastscroller;

import android.support.annotation.NonNull;

import com.nononsenseapps.filepicker.FileItemAdapter;
import com.nononsenseapps.filepicker.LogicHandler;
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;

import java.io.File;


public class FastScrollerFileItemAdapter extends FileItemAdapter<File> implements
FastScrollRecyclerView.SectionedAdapter {

public FastScrollerFileItemAdapter(
@NonNull LogicHandler<File> logic) {
super(logic);
}

@NonNull
@Override
public String getSectionName(int position) {
File path = getItem(position);
if (path == null) {
return "..";
}
return mLogic.getName(path).substring(0, 1).toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.nononsenseapps.filepicker.sample.fastscroller;

import android.os.Environment;
import android.support.annotation.Nullable;

import com.nononsenseapps.filepicker.AbstractFilePickerActivity;
import com.nononsenseapps.filepicker.AbstractFilePickerFragment;

import java.io.File;

/**
* All this class does is return a suitable fragment.
*/
public class FastScrollerFilePickerActivity extends AbstractFilePickerActivity {

public FastScrollerFilePickerActivity() {
super();
}

@Override
protected AbstractFilePickerFragment<File> getFragment(
@Nullable final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir) {
AbstractFilePickerFragment<File> fragment = new FastScrollerFilePickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir);
return fragment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nononsenseapps.filepicker.sample.fastscroller;

/**
* Just for theme sample purposes
*/
public class FastScrollerFilePickerActivity2 extends FastScrollerFilePickerActivity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.nononsenseapps.filepicker.sample.fastscroller;

import android.os.Bundle;
import android.support.v4.content.Loader;
import android.support.v7.util.SortedList;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nononsenseapps.filepicker.FilePickerFragment;
import com.nononsenseapps.filepicker.sample.R;
import com.nononsenseapps.filepicker.sample.fastscroller.FastScrollerFileItemAdapter;
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;

import java.io.File;

public class FastScrollerFilePickerFragment extends FilePickerFragment {

private FastScrollRecyclerView recyclerView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fastscrollerfilepicker, container, false);

Toolbar toolbar = (Toolbar) view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_picker_toolbar);
if (toolbar != null) {
setupToolbar(toolbar);
}

recyclerView = (FastScrollRecyclerView) view.findViewById(android.R.id.list);
// improve performance if you know that changes in content
// do not change the size of the RecyclerView
recyclerView.setHasFixedSize(true);
// use a linear layout manager
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
// Set adapter
mAdapter = new FastScrollerFileItemAdapter(this);
recyclerView.setAdapter(mAdapter);

view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_button_cancel)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onClickCancel(v);
}
});

view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_button_ok)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onClickOk(v);
}
});

mCurrentDirView = (TextView) view.findViewById(com.nononsenseapps.filepicker.R.id.nnf_current_dir);
// Restore state
if (mCurrentPath != null && mCurrentDirView != null) {
mCurrentDirView.setText(getFullPath(mCurrentPath));
}

return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.nononsenseapps.filepicker.sample;
package com.nononsenseapps.filepicker.sample.multimedia;

import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.nononsenseapps.filepicker.AbstractFilePickerActivity;
import com.nononsenseapps.filepicker.AbstractFilePickerFragment;
Expand All @@ -25,7 +25,7 @@ public MultimediaPickerActivity() {

@Override
protected AbstractFilePickerFragment<File> getFragment(
@NonNull final String startPath, final int mode, final boolean allowMultiple,
@Nullable final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir) {
AbstractFilePickerFragment<File> fragment = new MultimediaPickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.nononsenseapps.filepicker.sample;
package com.nononsenseapps.filepicker.sample.multimedia;

/**
* Duplicate to allow second theme to be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.nononsenseapps.filepicker.sample;
package com.nononsenseapps.filepicker.sample.multimedia;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
Expand All @@ -15,6 +15,7 @@

import com.bumptech.glide.Glide;
import com.nononsenseapps.filepicker.FilePickerFragment;
import com.nononsenseapps.filepicker.sample.R;

import java.io.File;

Expand Down Expand Up @@ -97,7 +98,7 @@ public int getItemViewType(int position, @NonNull File file) {
*/
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, @NonNull int viewType) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
case VIEWTYPE_IMAGE_CHECKABLE:
return new CheckableViewHolder(LayoutInflater.from(getActivity())
Expand Down
11 changes: 11 additions & 0 deletions sample/src/main/res/layout/activity_no_nonsense_file_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@
android:gravity="center"
android:text="Pick Dropbox" />

<Button
android:id="@+id/button_fastscroll"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:fontFamily="light"
android:gravity="center"
android:text="Pick With Fast Scroller" />

<Button
android:id="@+id/button_root"
style="?attr/borderlessButtonStyle"
Expand Down
Loading

0 comments on commit b879497

Please sign in to comment.