Search in sources :

Example 1 with FastScrollRecyclerView

use of com.foobnix.ui2.fast.FastScrollRecyclerView in project LibreraReader by foobnix.

the class OpdsFragment2 method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_opds2, container, false);
    recyclerView = (FastScrollRecyclerView) view.findViewById(R.id.recyclerView);
    titleView = (TextView) view.findViewById(R.id.titleView);
    onPlus = (ImageView) view.findViewById(R.id.onPlus);
    onProxy = (ImageView) view.findViewById(R.id.onProxy);
    starIcon = (ImageView) view.findViewById(R.id.starIcon);
    pathContainer = view.findViewById(R.id.pathContainer);
    view1 = view.findViewById(R.id.view1);
    view2 = view.findViewById(R.id.view2);
    progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
    progressBar.setVisibility(View.GONE);
    TintUtil.setDrawableTint(progressBar.getIndeterminateDrawable().getCurrent(), Color.WHITE);
    onPlus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AddCatalogDialog.showDialog(getActivity(), new Runnable() {

                @Override
                public void run() {
                    populate();
                }
            }, null, true);
        }
    });
    searchAdapter = new EntryAdapter();
    defaults = (TextView) view.findViewById(R.id.defaults);
    faq = (TextView) view.findViewById(R.id.faq);
    defaults.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialogs.showOkDialog(getActivity(), getActivity().getString(R.string.restore_defaults_full), new Runnable() {

                @Override
                public void run() {
                    AppState.get().myOPDSLinks = AppState.OPDS_DEFAULT;
                    url = "/";
                    populate();
                }
            });
        }
    });
    faq.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Urls.open(getActivity(), "https://wiki.mobileread.com/wiki/OPDS");
        }
    });
    onGridList();
    searchAdapter.setOnItemClickListener(new ResultResponse<Entry>() {

        @Override
        public boolean onResultRecive(Entry result) {
            for (Link link : result.links) {
                if (link.isOpdsLink()) {
                    onClickLink(link);
                    break;
                }
            }
            return false;
        }
    });
    searchAdapter.setOnRemoveLinkClickListener(new ResultResponse<Entry>() {

        @Override
        public boolean onResultRecive(final Entry result) {
            AlertDialogs.showDialog(getActivity(), getActivity().getString(R.string.do_you_want_to_delete_), getString(R.string.delete), new Runnable() {

                @Override
                public void run() {
                    AppState.get().myOPDSLinks = AppState.get().myOPDSLinks.replace(result.appState, "");
                    url = "/";
                    populate();
                }
            });
            return false;
        }
    });
    searchAdapter.setOnLinkClickListener(new ResultResponse<Link>() {

        @Override
        public boolean onResultRecive(Link link) {
            onClickLink(link);
            return false;
        }
    });
    searchAdapter.setOnItemLongClickListener(new ResultResponse<Entry>() {

        @Override
        public boolean onResultRecive(Entry result) {
            if (url.equals("/")) {
                AddCatalogDialog.showDialog(getActivity(), new Runnable() {

                    @Override
                    public void run() {
                        populate();
                    }
                }, result, SamlibOPDS.isSamlibUrl(result.homeUrl) ? false : true);
            }
            return false;
        }
    });
    starIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final Entry entry = new Entry();
            String url2 = url;
            if (url2.contains("?")) {
                url2 = url2.substring(0, url2.indexOf("?"));
            }
            entry.setAppState(url, title, url2, "assets://opds/star_1.png");
            if (!AppState.get().myOPDSLinks.contains(url)) {
                AddCatalogDialog.showDialog(getActivity(), new Runnable() {

                    @Override
                    public void run() {
                        starIcon.setImageResource(R.drawable.star_1);
                        TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
                    }
                }, entry, false);
            } else {
                AppState.get().myOPDSLinks = AppState.get().myOPDSLinks.replace(entry.appState, "");
                starIcon.setImageResource(R.drawable.star_2);
                TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
            // AlertDialogs.showOkDialog(getActivity(),
            // getActivity().getString(R.string.do_you_want_to_delete_), new Runnable() {
            // 
            // @Override
            // public void run() {
            // 
            // // url = "/";
            // }
            // });
            }
        }
    });
    view.findViewById(R.id.onBack).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackAction();
        }
    });
    view.findViewById(R.id.onHome).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            stack.clear();
            url = getHome();
            LOG.d("URLAction", "ADD", url);
            urlRoot = "";
            populate();
        }
    });
    view.findViewById(R.id.onHome).setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            AlertDialogs.showOkDialog(getActivity(), getActivity().getString(R.string.restore_defaults_full), new Runnable() {

                @Override
                public void run() {
                    AppState.get().myOPDSLinks = AppState.OPDS_DEFAULT;
                    populate();
                }
            });
            return true;
        }
    });
    onProxy.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            View view = LayoutInflater.from(v.getContext()).inflate(R.layout.dialog_proxy_server, null, false);
            final CheckBox proxyEnable = (CheckBox) view.findViewById(R.id.proxyEnable);
            final CheckBox opdsLargeCovers = (CheckBox) view.findViewById(R.id.opdsLargeCovers);
            final EditText proxyServer = (EditText) view.findViewById(R.id.proxyServer);
            final EditText proxyPort = (EditText) view.findViewById(R.id.proxyPort);
            final EditText proxyUser = (EditText) view.findViewById(R.id.proxyUser);
            final EditText proxyPassword = (EditText) view.findViewById(R.id.proxyPassword);
            final TextView proxyType = (TextView) view.findViewById(R.id.proxyType);
            TintUtil.setBackgroundFillColor(view.findViewById(R.id.section1), TintUtil.color);
            TintUtil.setBackgroundFillColor(view.findViewById(R.id.section2), TintUtil.color);
            proxyEnable.setChecked(AppState.get().proxyEnable);
            proxyServer.setText(AppState.get().proxyServer);
            proxyPort.setText(AppState.get().proxyPort == 0 ? "" : "" + AppState.get().proxyPort);
            proxyUser.setText(AppState.get().proxyUser);
            proxyPassword.setText(AppState.get().proxyPassword);
            proxyEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        if (TxtUtils.isEmpty(proxyServer.getText().toString())) {
                            proxyServer.requestFocus();
                            proxyEnable.setChecked(false);
                            Toast.makeText(getContext(), R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                        } else if ("0".equals(proxyPort.getText().toString()) || TxtUtils.isEmpty(proxyPort.getText().toString())) {
                            proxyPort.requestFocus();
                            proxyEnable.setChecked(false);
                            Toast.makeText(getContext(), R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            });
            TxtUtils.underline(proxyType, AppState.get().proxyType);
            proxyType.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PopupMenu menu = new PopupMenu(v.getContext(), v);
                    menu.getMenu().add(AppState.PROXY_HTTP).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().proxyType = AppState.PROXY_HTTP;
                            TxtUtils.underline(proxyType, AppState.get().proxyType);
                            return false;
                        }
                    });
                    menu.getMenu().add(AppState.PROXY_SOCKS).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().proxyType = AppState.PROXY_SOCKS;
                            TxtUtils.underline(proxyType, AppState.get().proxyType);
                            return false;
                        }
                    });
                    menu.show();
                }
            });
            builder.setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AppState.get().proxyEnable = proxyEnable.isChecked();
                    AppState.get().proxyServer = proxyServer.getText().toString();
                    try {
                        AppState.get().proxyPort = Integer.parseInt(proxyPort.getText().toString());
                    } catch (Exception e) {
                        AppState.get().proxyPort = 0;
                    }
                    AppState.get().proxyUser = proxyUser.getText().toString().trim();
                    AppState.get().proxyPassword = proxyPassword.getText().toString().trim();
                    OPDS.buildProxy();
                    AppState.get().save(getActivity());
                    Keyboards.close(proxyServer);
                }
            });
            builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            opdsLargeCovers.setChecked(AppState.get().opdsLargeCovers);
            opdsLargeCovers.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().opdsLargeCovers = isChecked;
                }
            });
            final TextView downlodsPath = (TextView) view.findViewById(R.id.downlodsPath);
            TxtUtils.underline(downlodsPath, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
            downlodsPath.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().downlodsPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                        @Override
                        public boolean onResultRecive(String nPath, Dialog dialog) {
                            AppState.get().downlodsPath = nPath;
                            TxtUtils.underline(downlodsPath, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
                            dialog.dismiss();
                            return false;
                        }
                    });
                }
            });
            builder.setView(view);
            builder.show();
        }
    });
    OPDS.buildProxy();
    populate();
    onTintChanged();
    return view;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) Entry(com.foobnix.opds.Entry) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) AddCatalogDialog(com.foobnix.pdf.info.widget.AddCatalogDialog) OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) EntryAdapter(com.foobnix.ui2.adapter.EntryAdapter) MenuItem(android.view.MenuItem) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) Link(com.foobnix.opds.Link) CompoundButton(android.widget.CompoundButton) PopupMenu(android.widget.PopupMenu)

Example 2 with FastScrollRecyclerView

use of com.foobnix.ui2.fast.FastScrollRecyclerView in project LibreraReader by foobnix.

the class SearchFragment2 method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_search2, container, false);
    NO_SERIES = " (" + getString(R.string.without_series) + ")";
    handler = new Handler();
    secondTopPanel = view.findViewById(R.id.secondTopPanel);
    countBooks = (TextView) view.findViewById(R.id.countBooks);
    onRefresh = view.findViewById(R.id.onRefresh);
    onRefresh.setActivated(true);
    cleanFilter = (ImageView) view.findViewById(R.id.cleanFilter);
    sortBy = (TextView) view.findViewById(R.id.sortBy);
    sortOrder = (ImageView) view.findViewById(R.id.sortOrder);
    myAutoCompleteImage = (ImageView) view.findViewById(R.id.myAutoCompleteImage);
    searchEditText = (AutoCompleteTextView) view.findViewById(R.id.filterLine);
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    myAutoCompleteImage.setVisibility(View.GONE);
    ((FastScrollRecyclerView) recyclerView).setFastScrollStateChangeListener(new FastScrollStateChangeListener() {

        @Override
        public void onFastScrollStop() {
            ImageLoader.getInstance().resume();
            LOG.d("ImageLoader resume");
        }

        @Override
        public void onFastScrollStart() {
            LOG.d("ImageLoader pause");
            ImageLoader.getInstance().pause();
        }
    });
    searchEditText.addTextChangedListener(filterTextWatcher);
    searchEditText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    EditTextHelper.enableKeyboardSearch(searchEditText, new Runnable() {

        @Override
        public void run() {
            Keyboards.close(searchEditText);
            Keyboards.hideNavigation(getActivity());
        }
    });
    searchAdapter = new FileMetaAdapter();
    authorsAdapter = new AuthorsAdapter2();
    onGridlList = (ImageView) view.findViewById(R.id.onGridList);
    onGridlList.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popupMenu(onGridlList);
        }
    });
    onRefresh.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!onRefresh.isActivated()) {
                Toast.makeText(getActivity(), R.string.extracting_information_from_books, Toast.LENGTH_LONG).show();
                return;
            }
            PrefDialogs.chooseFolderDialog(getActivity(), new Runnable() {

                @Override
                public void run() {
                    AppState.get().searchPaths = AppState.get().searchPaths.replace("//", "/");
                }
            }, new Runnable() {

                @Override
                public void run() {
                    recyclerView.scrollToPosition(0);
                    seachAll();
                }
            });
        }
    });
    cleanFilter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            searchEditText.setText("");
            recyclerView.scrollToPosition(0);
            searchAndOrderAsync();
        }
    });
    sortBy.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            sortByPopup(v);
        }
    });
    sortOrder.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AppState.get().isSortAsc = !AppState.get().isSortAsc;
            searchAndOrderAsync();
        }
    });
    bindAdapter(searchAdapter);
    searchAdapter.setOnAuthorClickListener(onAuthorClick);
    searchAdapter.setOnSeriesClickListener(onSeriesClick);
    authorsAdapter.setOnItemClickListener(onAuthorSeriesClick);
    onGridList();
    if (AppDB.get().getCount() == 0) {
        seachAll();
    } else {
        checkForDeleteBooks();
        searchAndOrderAsync();
    }
    initAutocomplition();
    onTintChanged();
    recyclerView.addOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
        }
    });
    myAutoCompleteImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showAutoCompleteDialog();
        }
    });
    return view;
}
Also used : AuthorsAdapter2(com.foobnix.ui2.adapter.AuthorsAdapter2) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) OnScrollListener(android.support.v7.widget.RecyclerView.OnScrollListener) Handler(android.os.Handler) OnClickListener(android.view.View.OnClickListener) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) FastScrollStateChangeListener(com.foobnix.ui2.fast.FastScrollStateChangeListener) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) RecyclerView(android.support.v7.widget.RecyclerView) FileMetaAdapter(com.foobnix.ui2.adapter.FileMetaAdapter)

Example 3 with FastScrollRecyclerView

use of com.foobnix.ui2.fast.FastScrollRecyclerView in project LibreraReader by foobnix.

the class UIFragment method onGridList.

public void onGridList(int mode, ImageView onGridlList, final FileMetaAdapter searchAdapter, AuthorsAdapter2 authorsAdapter) {
    if (searchAdapter == null) {
        return;
    }
    if (onGridlList != null) {
        PopupHelper.updateGridOrListIcon(onGridlList, mode);
    }
    if (mode == AppState.MODE_LIST) {
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(mLayoutManager);
        searchAdapter.setAdapterType(FileMetaAdapter.ADAPTER_LIST);
        recyclerView.setAdapter(searchAdapter);
    } else if (mode == AppState.MODE_COVERS || mode == AppState.MODE_GRID) {
        final int num = Math.max(1, Dips.screenWidthDP() / AppState.get().coverBigSize);
        GridLayoutManager mGridManager = new GridLayoutManager(getActivity(), num);
        mGridManager.setSpanSizeLookup(new SpanSizeLookup() {

            @Override
            public int getSpanSize(int pos) {
                int type = searchAdapter.getItemViewType(pos);
                if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_FOLDERS) {
                    return num;
                }
                if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TAG) {
                    return 1;
                }
                if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_NONE) {
                    return num;
                }
                if (type == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
                    if (num == 1) {
                        return 1;
                    } else if (num == 2) {
                        return 1;
                    } else if (num == 3) {
                        return 3;
                    }
                    return 2;
                }
                if (type == FileMetaAdapter.DISPALY_TYPE_SERIES) {
                    return num;
                }
                return (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_BOOKS) ? num : 1;
            }
        });
        recyclerView.setLayoutManager(mGridManager);
        searchAdapter.setAdapterType(mode == AppState.MODE_COVERS ? FileMetaAdapter.ADAPTER_COVERS : FileMetaAdapter.ADAPTER_GRID);
        recyclerView.setAdapter(searchAdapter);
    } else if (Arrays.asList(AppState.MODE_AUTHORS, AppState.MODE_SERIES, AppState.MODE_GENRE, AppState.MODE_TAGS).contains(mode)) {
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setAdapter(authorsAdapter);
    } else if (mode == AppState.MODE_LIST_COMPACT) {
        final int num = Math.max(2, Dips.screenWidthDP() / Dips.dpToPx(300));
        GridLayoutManager mGridManager = new GridLayoutManager(getActivity(), num);
        mGridManager.setSpanSizeLookup(new SpanSizeLookup() {

            @Override
            public int getSpanSize(int pos) {
                int type = searchAdapter.getItemViewType(pos);
                if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_FOLDERS) {
                    return num;
                }
                if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TAG) {
                    return 1;
                }
                if (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_NONE) {
                    return num;
                }
                return (type == FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_BOOKS) ? num : 1;
            }
        });
        recyclerView.setLayoutManager(mGridManager);
        searchAdapter.setAdapterType(FileMetaAdapter.ADAPTER_LIST_COMPACT);
        recyclerView.setAdapter(searchAdapter);
    }
    if (recyclerView instanceof FastScrollRecyclerView) {
        ((FastScrollRecyclerView) recyclerView).myConfiguration();
    }
}
Also used : SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(android.support.v7.widget.GridLayoutManager) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 4 with FastScrollRecyclerView

use of com.foobnix.ui2.fast.FastScrollRecyclerView in project LibreraReader by foobnix.

the class BrowseFragment2 method onCreateView.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_browse2, container, false);
    Bundle arguments = getArguments();
    pathContainer = view.findViewById(R.id.pathContainer);
    View onCloseActionPaner = view.findViewById(R.id.onCloseActionPaner);
    onClose = view.findViewById(R.id.onClose);
    starIcon = (ImageView) view.findViewById(R.id.starIcon);
    onSort = (ImageView) view.findViewById(R.id.onSort);
    onSort.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            AppState.get().sortByReverse = !AppState.get().sortByReverse;
            onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
            populate();
            return true;
        }
    });
    onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
    onAction = view.findViewById(R.id.onAction);
    editPath = (EditText) view.findViewById(R.id.editPath);
    fragmentType = TYPE_DEFAULT;
    if (arguments != null) {
        fragmentType = arguments.getInt(EXTRA_TYPE, TYPE_DEFAULT);
        fragmentText = arguments.getString(EXTRA_TEXT);
        editPath.setText(fragmentText);
    }
    onClose.setOnClickListener(onCloseButtonActoin);
    onAction.setOnClickListener(onSelectAction);
    if (TYPE_DEFAULT == fragmentType) {
        editPath.setVisibility(View.GONE);
        onCloseActionPaner.setVisibility(View.GONE);
    }
    if (TYPE_SELECT_FOLDER == fragmentType) {
        editPath.setVisibility(View.VISIBLE);
        editPath.setEnabled(false);
        onCloseActionPaner.setVisibility(View.VISIBLE);
    }
    if (TYPE_SELECT_FILE == fragmentType) {
        editPath.setVisibility(View.VISIBLE);
        editPath.setEnabled(false);
        onCloseActionPaner.setVisibility(View.VISIBLE);
    }
    if (TYPE_CREATE_FILE == fragmentType) {
        editPath.setVisibility(View.VISIBLE);
        editPath.setEnabled(true);
        onCloseActionPaner.setVisibility(View.VISIBLE);
    }
    View onBack = view.findViewById(R.id.onBack);
    recyclerView = (FastScrollRecyclerView) view.findViewById(R.id.recyclerView);
    paths = (LinearLayout) view.findViewById(R.id.paths);
    scroller = (HorizontalScrollView) view.findViewById(R.id.scroller);
    final View onHome = view.findViewById(R.id.onHome);
    onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
    onListGrid.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popupMenu(onListGrid);
        }
    });
    searchAdapter = new FileMetaAdapter();
    bindAdapter(searchAdapter);
    bindAuthorsSeriesAdapter(searchAdapter);
    onGridList();
    onHome.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            List<String> extFolders = new ArrayList<String>();
            extFolders = ExtUtils.getExternalStorageDirectories(getActivity());
            String sdPath = ExtUtils.getSDPath();
            if (TxtUtils.isNotEmpty(sdPath) && !extFolders.contains(sdPath)) {
                extFolders.add(sdPath);
            }
            MyPopupMenu menu = new MyPopupMenu(getActivity(), onHome);
            menu.getMenu().add(R.string.internal_storage).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    setDirPath(Environment.getExternalStorageDirectory().getPath());
                    return false;
                }
            }).setIcon(R.drawable.glyphicons_146_folder_sd1);
            for (final String info : extFolders) {
                String name;
                if (ExtUtils.isExteralSD(info)) {
                    name = ExtUtils.getExtSDDisplayName(getContext(), info);
                } else {
                    name = new File(info).getName();
                }
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        setDirPath(info);
                        return false;
                    }
                }).setIcon(R.drawable.glyphicons_146_folder_sd1);
            }
            menu.getMenu().add("Librera").setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    setDirPath(AppState.get().downlodsPath);
                    return false;
                }
            }).setIcon(R.drawable.glyphicons_591_folder_heart);
            if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
                List<String> safs = StringDB.asList(AppState.get().pathSAF);
                for (final String saf : safs) {
                    String fileName = DocumentsContract.getTreeDocumentId(Uri.parse(saf));
                    menu.getMenu().add(fileName).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            setDirPath(saf);
                            return false;
                        }
                    }).setOnMenuItemLongClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().pathSAF = StringDB.delete(AppState.get().pathSAF, saf);
                            return false;
                        }
                    }).setIcon(R.drawable.glyphicons_146_folder_plus);
                }
            }
            // stars
            List<FileMeta> starFolders = AppDB.get().getStarsFolder();
            List<String> names = new ArrayList<String>();
            for (FileMeta f : starFolders) {
                names.add(f.getPath());
            }
            Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
            for (final String info : names) {
                String name;
                if (ExtUtils.isExteralSD(info)) {
                    name = ExtUtils.getExtSDDisplayName(getContext(), info);
                } else {
                    name = new File(info).getName();
                }
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        setDirPath(info);
                        return false;
                    }
                }).setIcon(R.drawable.glyphicons_591_folder_star);
            }
            if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
                menu.getMenu().add(R.string.add_resource).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                        intent.addFlags(// 
                        Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | // 
                        Intent.FLAG_GRANT_PREFIX_URI_PERMISSION | // 
                        Intent.FLAG_GRANT_READ_URI_PERMISSION | // 
                        Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                        getActivity().startActivityForResult(intent, MainTabs2.REQUEST_CODE_ADD_RESOURCE);
                        return true;
                    }
                }).setIcon(R.drawable.glyphicons_146_add_folder_plus);
            }
            menu.show();
        }
    });
    onBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackAction();
        }
    });
    searchAdapter.setOnItemClickListener(new ResultResponse<FileMeta>() {

        @Override
        public boolean onResultRecive(FileMeta result) {
            if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
                setDirPath(result.getPath());
                if (fragmentType == TYPE_SELECT_FOLDER) {
                    editPath.setText(fragmentText);
                }
            } else {
                if (fragmentType == TYPE_DEFAULT) {
                    DefaultListeners.getOnItemClickListener(getActivity()).onResultRecive(result);
                } else if (fragmentType == TYPE_SELECT_FILE) {
                    editPath.setText(ExtUtils.getFileName(result.getPath()));
                }
            }
            return false;
        }
    });
    searchAdapter.setOnItemLongClickListener(new ResultResponse<FileMeta>() {

        @Override
        public boolean onResultRecive(FileMeta result) {
            if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
            // setDirPath(result.getPath());
            } else {
                DefaultListeners.getOnItemLongClickListener(getActivity(), searchAdapter).onResultRecive(result);
            }
            return false;
        }
    });
    onSort.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            List<String> names = // 
            Arrays.asList(// 
            getActivity().getString(R.string.by_file_name), // 
            getActivity().getString(R.string.by_date), // 
            getActivity().getString(R.string.by_size), // 
            getActivity().getString(R.string.by_title), // 
            getActivity().getString(R.string.by_number_in_serie), // 
            getActivity().getString(R.string.by_number_of_pages), // 
            getActivity().getString(R.string.by_extension));
            // 
            final List<Integer> ids = // 
            Arrays.asList(// 
            AppState.BR_SORT_BY_PATH, // 
            AppState.BR_SORT_BY_DATE, // 
            AppState.BR_SORT_BY_SIZE, // 
            AppState.BR_SORT_BY_TITLE, // 
            AppState.BR_SORT_BY_NUMBER, // 
            AppState.BR_SORT_BY_PAGES, // 
            AppState.BR_SORT_BY_EXT);
            // 
            MyPopupMenu menu = new MyPopupMenu(getActivity(), v);
            for (int i = 0; i < names.size(); i++) {
                String name = names.get(i);
                final int j = i;
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().sortByBrowse = ids.get(j);
                        populate();
                        return false;
                    }
                });
            }
            menu.show();
        }
    });
    populate();
    onTintChanged();
    return view;
}
Also used : MainTabs2(com.foobnix.ui2.MainTabs2) Bundle(android.os.Bundle) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) MenuItem(android.view.MenuItem) Intent(android.content.Intent) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) FileMetaAdapter(com.foobnix.ui2.adapter.FileMetaAdapter) FileMeta(com.foobnix.dao2.FileMeta) TargetApi(android.annotation.TargetApi)

Aggregations

FastScrollRecyclerView (com.foobnix.ui2.fast.FastScrollRecyclerView)4 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 OnClickListener (android.view.View.OnClickListener)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 MenuItem (android.view.MenuItem)2 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)2 OnLongClickListener (android.view.View.OnLongClickListener)2 FileMetaAdapter (com.foobnix.ui2.adapter.FileMetaAdapter)2 TargetApi (android.annotation.TargetApi)1 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1