Improve settings
This commit is contained in:
1 parent
da905f2a4f
commit
b4f9e77a76
19 files changed
+849
-5
No files matched your search
@@ -259,7 +259,7 @@ public class Settings {
|
||||
return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir());
|
||||
}
|
||||
|
||||
public static void putImageSaveLocation(@NonNull UniFile location) {
|
||||
public static void putDownloadLocation(@NonNull UniFile location) {
|
||||
Uri uri = location.getUri();
|
||||
putString(KEY_DOWNLOAD_SAVE_SCHEME, uri.getScheme());
|
||||
putString(KEY_DOWNLOAD_SAVE_AUTHORITY, uri.getEncodedAuthority());
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.widget.DirExplorer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DirPickerActivity extends ToolbarActivity
|
||||
implements View.OnClickListener, DirExplorer.OnChangeDirListener {
|
||||
|
||||
public static final String KEY_FILE_URI = "file_uri";
|
||||
|
||||
private TextView mPath;
|
||||
private DirExplorer mDirExplorer;
|
||||
private View mOk;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_dir_picker);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
|
||||
mPath = (TextView) findViewById(R.id.path);
|
||||
mDirExplorer = (DirExplorer) findViewById(R.id.dir_explorer);
|
||||
mOk = findViewById(R.id.ok);
|
||||
|
||||
File file = null;
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
Uri fileUri = intent.getParcelableExtra(KEY_FILE_URI);
|
||||
if (fileUri != null) {
|
||||
file = new File(fileUri.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
mDirExplorer.setCurrentFile(file);
|
||||
mDirExplorer.setOnChangeDirListener(this);
|
||||
|
||||
RippleSalon.addRipple(mOk, false);
|
||||
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
mPath.setText(mDirExplorer.getCurrentFile().getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull View v) {
|
||||
if (mOk == v) {
|
||||
File file = mDirExplorer.getCurrentFile();
|
||||
if (!file.canWrite()) {
|
||||
Toast.makeText(this, R.string.directory_not_writable, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Intent intent = new Intent();
|
||||
intent.setData(Uri.fromFile(file));
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeDir(File dir) {
|
||||
mPath.setText(dir.getPath());
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,8 @@ import android.widget.ListAdapter;
|
||||
|
||||
import com.hippo.app.AppCompatPreferenceActivity;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.fragment.AboutFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.DownloadFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.EhFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.ReadFragment;
|
||||
import com.hippo.util.DrawableManager;
|
||||
@@ -48,11 +50,13 @@ public final class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
private static final String[] ENTRY_FRAGMENTS = {
|
||||
EhFragment.class.getName(),
|
||||
ReadFragment.class.getName(),
|
||||
DownloadFragment.class.getName(),
|
||||
AboutFragment.class.getName(),
|
||||
};
|
||||
|
||||
private class FakeLayoutInflater extends LayoutInflater {
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
protected FakeLayoutInflater(LayoutInflater inflater) {
|
||||
super(null);
|
||||
@@ -142,7 +146,6 @@ public final class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
replaceHeaderLayoutResId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class ToolbarActivity extends AppCompatActivity{
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
super.setContentView(R.layout.activity_toolbar);
|
||||
getLayoutInflater().inflate(layoutResID, (ViewGroup) findViewById(R.id.content_panel), true);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
super.setContentView(R.layout.activity_toolbar);
|
||||
((ViewGroup) findViewById(R.id.content_panel)).addView(view);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
super.setContentView(R.layout.activity_toolbar);
|
||||
((ViewGroup) findViewById(R.id.content_panel)).addView(view, params);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
}
|
||||
|
||||
public void setNavigationIcon(@DrawableRes int resId) {
|
||||
View toolbar = findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
((Toolbar) toolbar).setNavigationIcon(resId);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNavigationIcon(@Nullable Drawable icon) {
|
||||
View toolbar = findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
((Toolbar) toolbar).setNavigationIcon(icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class AboutFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.about_settings);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.DirPickerActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
|
||||
public class DownloadFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
|
||||
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR = 0;
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR_L = 1;
|
||||
|
||||
public static final String KEY_DOWNLOAD_LOCATION = "download_location";
|
||||
|
||||
private @Nullable Preference mDownloadLocation;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.download_settings);
|
||||
|
||||
mDownloadLocation = findPreference(KEY_DOWNLOAD_LOCATION);
|
||||
|
||||
onUpdateDownloadLocation();
|
||||
|
||||
if (mDownloadLocation != null) {
|
||||
mDownloadLocation.setOnPreferenceClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onUpdateDownloadLocation() {
|
||||
UniFile file = Settings.getDownloadLocation();
|
||||
if (mDownloadLocation != null) {
|
||||
if (file != null) {
|
||||
mDownloadLocation.setSummary(file.getUri().toString());
|
||||
} else {
|
||||
mDownloadLocation.setSummary(R.string.settings_download_invalid_download_location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
if (KEY_DOWNLOAD_LOCATION.equals(key)) {
|
||||
|
||||
int sdk = Build.VERSION.SDK_INT;
|
||||
if (sdk < Build.VERSION_CODES.KITKAT) {
|
||||
openDirPicker();
|
||||
} else if (sdk < Build.VERSION_CODES.LOLLIPOP) {
|
||||
showDirPickerDialogKK();
|
||||
} else {
|
||||
showDirPickerDialogL();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showDirPickerDialogKK() {
|
||||
new AlertDialog.Builder(getActivity()).setMessage(R.string.settings_download_pick_dir_kk)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
openDirPicker();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void showDirPickerDialogL() {
|
||||
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
openDirPicker();
|
||||
break;
|
||||
case DialogInterface.BUTTON_NEUTRAL:
|
||||
openDirPickerL();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
new AlertDialog.Builder(getActivity()).setMessage(R.string.settings_download_pick_dir_l)
|
||||
.setPositiveButton(android.R.string.ok, listener)
|
||||
.setNeutralButton(R.string.settings_download_document, listener)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void openDirPicker() {
|
||||
UniFile uniFile = Settings.getDownloadLocation();
|
||||
Intent intent = new Intent(getActivity(), DirPickerActivity.class);
|
||||
if (uniFile != null) {
|
||||
intent.putExtra(DirPickerActivity.KEY_FILE_URI, uniFile.getUri());
|
||||
}
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void openDirPickerL() {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(getActivity(), R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_PICK_IMAGE_DIR: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
UniFile uniFile = UniFile.fromUri(getActivity(), data.getData());
|
||||
if (uniFile != null) {
|
||||
Settings.putDownloadLocation(uniFile);
|
||||
onUpdateDownloadLocation();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_cant_get_download_location,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case REQUEST_CODE_PICK_IMAGE_DIR_L: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Uri treeUri = data.getData();
|
||||
getActivity().getContentResolver().takePersistableUriPermission(
|
||||
treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
UniFile uniFile = UniFile.fromTreeUri(getActivity(), treeUri);
|
||||
if (uniFile != null) {
|
||||
Settings.putDownloadLocation(uniFile);
|
||||
onUpdateDownloadLocation();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_cant_get_download_location,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class DirExplorer extends EasyRecyclerView implements EasyRecyclerView.OnItemClickListener {
|
||||
|
||||
private static final DirFilter DIR_FILTER = new DirFilter();
|
||||
private static final FileSort FILE_SORT = new FileSort();
|
||||
|
||||
private static final File PARENT_DIR = null;
|
||||
private static final String PARENT_DIR_NAME = "..";
|
||||
|
||||
private File mCurrentFile;
|
||||
private final List<File> mFiles = new ArrayList<>();
|
||||
|
||||
private DirAdapter mAdapter;
|
||||
|
||||
private OnChangeDirListener mOnChangeDirListener;
|
||||
|
||||
public DirExplorer(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public DirExplorer(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public DirExplorer(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mAdapter = new DirAdapter();
|
||||
setAdapter(mAdapter);
|
||||
setLayoutManager(new LinearLayoutManager(context));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, getResources().getColor(R.color.divider),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
addItemDecoration(decoration);
|
||||
setSelector(RippleSalon.generateRippleDrawable(ResourcesUtils.getAttrBoolean(context, R.attr.dark)));
|
||||
setOnItemClickListener(this);
|
||||
|
||||
mCurrentFile = Environment.getExternalStorageDirectory();
|
||||
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|
||||
|| mCurrentFile == null) {
|
||||
mCurrentFile = new File("/");
|
||||
}
|
||||
updateFileList();
|
||||
}
|
||||
|
||||
public void setOnChangeDirListener(OnChangeDirListener listener) {
|
||||
mOnChangeDirListener = listener;
|
||||
}
|
||||
|
||||
public void updateFileList() {
|
||||
File[] files = mCurrentFile.listFiles(DIR_FILTER);
|
||||
|
||||
mFiles.clear();
|
||||
if (mCurrentFile.getParent() != null) {
|
||||
mFiles.add(PARENT_DIR);
|
||||
}
|
||||
if (files != null) {
|
||||
Collections.addAll(mFiles, files);
|
||||
}
|
||||
// sort
|
||||
Collections.sort(mFiles, FILE_SORT);
|
||||
}
|
||||
|
||||
public File getCurrentFile() {
|
||||
return mCurrentFile;
|
||||
}
|
||||
|
||||
public void setCurrentFile(File file) {
|
||||
if (file != null && file.isDirectory()) {
|
||||
mCurrentFile = file;
|
||||
updateFileList();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
|
||||
if (mOnChangeDirListener != null) {
|
||||
mOnChangeDirListener.onChangeDir(mCurrentFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
File file = mFiles.get(position);
|
||||
if (file == PARENT_DIR) {
|
||||
file = mCurrentFile.getParentFile();
|
||||
}
|
||||
setCurrentFile(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
private class DirHolder extends ViewHolder {
|
||||
|
||||
public TextView textView;
|
||||
|
||||
public DirHolder(View itemView) {
|
||||
super(itemView);
|
||||
textView = (TextView) itemView;
|
||||
}
|
||||
}
|
||||
|
||||
private class DirAdapter extends Adapter<DirHolder> {
|
||||
|
||||
@Override
|
||||
public DirHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DirHolder( LayoutInflater.from(getContext()).inflate(R.layout.item_dir_explorer, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DirHolder holder, int position) {
|
||||
File file = mFiles.get(position);
|
||||
holder.textView.setText(file == PARENT_DIR ? PARENT_DIR_NAME : file.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mFiles.size();
|
||||
}
|
||||
}
|
||||
|
||||
static class DirFilter implements FileFilter {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
static class FileSort implements Comparator<File> {
|
||||
@Override
|
||||
public int compare(File lhs, File rhs) {
|
||||
if (lhs == null) {
|
||||
return Integer.MIN_VALUE;
|
||||
} else if (rhs == null) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else {
|
||||
return lhs.getName().compareToIgnoreCase(rhs.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnChangeDirListener {
|
||||
|
||||
void onChangeDir(File dir);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user