This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from spacecowboy/fastscroller
Add FastScroller sample implementation
- Loading branch information
Showing
12 changed files
with
308 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...n/java/com/nononsenseapps/filepicker/sample/fastscroller/FastScrollerFileItemAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ava/com/nononsenseapps/filepicker/sample/fastscroller/FastScrollerFilePickerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...va/com/nononsenseapps/filepicker/sample/fastscroller/FastScrollerFilePickerActivity2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
70 changes: 70 additions & 0 deletions
70
...ava/com/nononsenseapps/filepicker/sample/fastscroller/FastScrollerFilePickerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.