Search in sources :

Example 1 with SearchFragment2

use of com.foobnix.ui2.fragment.SearchFragment2 in project LibreraReader by foobnix.

the class MainTabs2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (AppState.get().isWhiteTheme) {
        setTheme(R.style.StyledIndicatorsWhite);
    } else {
        setTheme(R.style.StyledIndicatorsBlack);
    }
    super.onCreate(savedInstanceState);
    if (PasswordDialog.isNeedPasswordDialog(this)) {
        return;
    }
    LOG.d(TAG, "onCreate");
    LOG.d("EXTRA_EXIT", EXTRA_EXIT);
    if (getIntent().getBooleanExtra(EXTRA_EXIT, false)) {
        finish();
        return;
    }
    isEink = Dips.isEInk(this);
    TintUtil.setStatusBarColor(this);
    DocumentController.doRotation(this);
    setContentView(R.layout.main_tabs);
    imageMenu = (ImageView) findViewById(R.id.imageMenu1);
    imageMenuParent = findViewById(R.id.imageParent1);
    imageMenuParent.setBackgroundColor(TintUtil.color);
    overlay = findViewById(R.id.overlay);
    toastBrightnessText = (TextView) findViewById(R.id.toastBrightnessText);
    toastBrightnessText.setVisibility(View.GONE);
    TintUtil.setDrawableTint(toastBrightnessText.getCompoundDrawables()[0], Color.WHITE);
    tabFragments = new ArrayList<UIFragment>();
    try {
        for (UITab tab : UITab.getOrdered(AppState.get().tabsOrder)) {
            if (tab.isVisible()) {
                tabFragments.add(tab.getClazz().newInstance());
            }
        }
    } catch (Exception e) {
        LOG.e(e);
        Toast.makeText(MainTabs2.this, R.string.msg_unexpected_error, Toast.LENGTH_LONG).show();
        tabFragments.add(new SearchFragment2());
        tabFragments.add(new BrowseFragment2());
        tabFragments.add(new RecentFragment2());
        tabFragments.add(new BookmarksFragment2());
        tabFragments.add(new OpdsFragment2());
        tabFragments.add(new PrefFragment2());
    }
    getSupportFragmentManager().beginTransaction().replace(R.id.left_drawer, new PrefFragment2()).commit();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    imageMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (drawerLayout.isDrawerOpen(Gravity.START))
                drawerLayout.closeDrawer(Gravity.START, !AppState.get().isInkMode);
            else
                drawerLayout.openDrawer(Gravity.START, !AppState.get().isInkMode);
        }
    });
    if (UITab.isShowPreferences()) {
        imageMenu.setVisibility(View.GONE);
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    } else {
        imageMenu.setVisibility(View.VISIBLE);
    }
    // ((BrigtnessDraw)
    // findViewById(R.id.brigtnessProgressView)).setActivity(this);
    adapter = new TabsAdapter2(this, tabFragments);
    pager = (ViewPager) findViewById(R.id.pager);
    if (Android6.canWrite(this)) {
        pager.setAdapter(adapter);
    }
    pager.setOffscreenPageLimit(5);
    pager.addOnPageChangeListener(onPageChangeListener);
    drawerLayout.addDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerStateChanged(int arg0) {
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {
        }

        @Override
        public void onDrawerOpened(View arg0) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onDrawerClosed(View arg0) {
            tabFragments.get(pager.getCurrentItem()).onSelectFragment();
        }
    });
    indicator = (SlidingTabLayout) findViewById(R.id.slidingTabs);
    indicator.setViewPager(pager);
    indicator.setDividerColors(getResources().getColor(R.color.tint_divider));
    indicator.setSelectedIndicatorColors(Color.WHITE);
    indicator.setBackgroundColor(TintUtil.color);
    if (AppState.get().isInkMode) {
        TintUtil.setTintImageNoAlpha(imageMenu, TintUtil.color);
        indicator.setSelectedIndicatorColors(TintUtil.color);
        indicator.setDividerColors(TintUtil.color);
        indicator.setBackgroundColor(Color.TRANSPARENT);
        imageMenuParent.setBackgroundColor(Color.TRANSPARENT);
    }
    Android6.checkPermissions(this);
    // Analytics.onStart(this);
    List<String> actions = Arrays.asList("android.intent.action.PROCESS_TEXT", "android.intent.action.SEARCH", "android.intent.action.SEND");
    List<String> extras = Arrays.asList(Intent.EXTRA_PROCESS_TEXT_READONLY, Intent.EXTRA_PROCESS_TEXT, SearchManager.QUERY, Intent.EXTRA_TEXT);
    if (getIntent() != null && getIntent().getAction() != null) {
        if (actions.contains(getIntent().getAction())) {
            for (String extra : extras) {
                final String text = getIntent().getStringExtra(extra);
                if (TxtUtils.isNotEmpty(text)) {
                    AppState.get().lastClosedActivity = null;
                    pager.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            ((SearchFragment2) tabFragments.get(0)).searchAndOrderExteral(text);
                        }
                    }, 250);
                    break;
                }
            }
        }
    }
    boolean showTabs = getIntent().getBooleanExtra(EXTRA_SHOW_TABS, false);
    LOG.d("EXTRA_SHOW_TABS", showTabs, AppState.get().lastMode);
    if (showTabs == false && AppState.get().isOpenLastBook) {
        LOG.d("Open lastBookPath", AppState.get().lastBookPath);
        if (AppState.get().lastBookPath == null || !new File(AppState.get().lastBookPath).isFile()) {
            LOG.d("Open Last book not found");
            return;
        }
        AppState.get().lastClosedActivity = null;
        Safe.run(new Runnable() {

            @Override
            public void run() {
                boolean isEasyMode = HorizontalViewActivity.class.getSimpleName().equals(AppState.get().lastMode);
                Intent intent = new Intent(MainTabs2.this, isEasyMode ? HorizontalViewActivity.class : VerticalViewActivity.class);
                intent.putExtra(PasswordDialog.EXTRA_APP_PASSWORD, getIntent().getStringExtra(PasswordDialog.EXTRA_APP_PASSWORD));
                intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
                startActivity(intent);
            }
        });
    } else if (!AppState.get().isOpenLastBook) {
        LOG.d("Open book lastA", AppState.get().lastClosedActivity);
        if (AppState.get().lastBookPath == null || !new File(AppState.get().lastBookPath).isFile()) {
            LOG.d("Open Last book not found");
            return;
        }
        final String saveMode = AppState.get().lastClosedActivity;
        Safe.run(new Runnable() {

            @Override
            public void run() {
                if (HorizontalViewActivity.class.getSimpleName().equals(saveMode)) {
                    Intent intent = new Intent(MainTabs2.this, HorizontalViewActivity.class);
                    intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
                    startActivity(intent);
                    LOG.d("Start lastA", saveMode);
                } else if (VerticalViewActivity.class.getSimpleName().equals(saveMode)) {
                    Intent intent = new Intent(MainTabs2.this, VerticalViewActivity.class);
                    intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
                    startActivity(intent);
                    LOG.d("Start lastA", saveMode);
                }
            }
        });
    } else {
        RecentUpates.updateAll(this);
    }
    checkGoToPage(getIntent());
    try {
        AndroidWhatsNew.checkForNewBeta(this);
    } catch (Exception e) {
        LOG.e(e);
    }
    if (Android6.canWrite(this)) {
        FontExtractor.extractFonts(this);
    }
    EventBus.getDefault().register(this);
}
Also used : BrowseFragment2(com.foobnix.ui2.fragment.BrowseFragment2) TabsAdapter2(com.foobnix.ui2.adapter.TabsAdapter2) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener) OpdsFragment2(com.foobnix.ui2.fragment.OpdsFragment2) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) RecentFragment2(com.foobnix.ui2.fragment.RecentFragment2) UIFragment(com.foobnix.ui2.fragment.UIFragment) PrefFragment2(com.foobnix.ui2.fragment.PrefFragment2) Intent(android.content.Intent) SearchFragment2(com.foobnix.ui2.fragment.SearchFragment2) BookmarksFragment2(com.foobnix.ui2.fragment.BookmarksFragment2) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) UITab(com.foobnix.pdf.info.wrapper.UITab) OnClickListener(android.view.View.OnClickListener) File(java.io.File)

Example 2 with SearchFragment2

use of com.foobnix.ui2.fragment.SearchFragment2 in project LibreraReader by foobnix.

the class BrowseFragment2 method setDirPath.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setDirPath(final String path, List<FileMeta> items) {
    LOG.d("setDirPath", path);
    if (searchAdapter == null) {
        return;
    }
    if (!path.equals(prevPath)) {
        int pos = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
        rememberPos.put(prevPath, pos);
        LOG.d("rememberPos", path, pos);
    }
    prevPath = path;
    if (AppDB.get().isStarFolder(path)) {
        starIcon.setImageResource(R.drawable.star_1);
    } else {
        starIcon.setImageResource(R.drawable.star_2);
    }
    TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
    starIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            FileMeta fileMeta = AppDB.get().getOrCreate(path);
            fileMeta.setCusType(FileMetaAdapter.DISPLAY_TYPE_DIRECTORY);
            fileMeta.setPathTxt(ExtUtils.getFileName(path));
            DefaultListeners.getOnStarClick(getActivity()).onResultRecive(fileMeta, null);
            if (AppDB.get().isStarFolder(path)) {
                starIcon.setImageResource(R.drawable.star_1);
            } else {
                starIcon.setImageResource(R.drawable.star_2);
            }
        }
    });
    AppState.get().dirLastPath = path;
    searchAdapter.clearItems();
    if (items == null) {
        if (!ExtUtils.isExteralSD(path)) {
            items = SearchCore.getFilesAndDirs(path, fragmentType == TYPE_DEFAULT);
        } else {
            items = new ArrayList<FileMeta>();
            if (Build.VERSION.SDK_INT >= 21) {
                Uri uri = Uri.parse(path);
                ContentResolver contentResolver = getActivity().getContentResolver();
                Uri childrenUri = null;
                try {
                    childrenUri = ExtUtils.getChildUri(getContext(), uri);
                    if (childrenUri != null) {
                        LOG.d("newNode uri >> ", uri);
                        LOG.d("newNode childrenUri >> ", childrenUri);
                        Cursor childCursor = contentResolver.query(childrenUri, new String[] { // 
                        Document.COLUMN_DISPLAY_NAME, // 
                        Document.COLUMN_DOCUMENT_ID, // 
                        Document.COLUMN_ICON, // 
                        Document.COLUMN_LAST_MODIFIED, // 
                        Document.COLUMN_MIME_TYPE, // 
                        Document.COLUMN_SIZE, // 
                        Document.COLUMN_SUMMARY }, // 
                        null, null, // 
                        null);
                        try {
                            while (childCursor.moveToNext()) {
                                String COLUMN_DISPLAY_NAME = childCursor.getString(0);
                                String COLUMN_DOCUMENT_ID = childCursor.getString(1);
                                String COLUMN_ICON = childCursor.getString(2);
                                String COLUMN_LAST_MODIFIED = childCursor.getString(3);
                                String COLUMN_MIME_TYPE = childCursor.getString(4);
                                String COLUMN_SIZE = childCursor.getString(5);
                                String COLUMN_SUMMARY = childCursor.getString(6);
                                LOG.d("found- child 2=", COLUMN_DISPLAY_NAME, COLUMN_DOCUMENT_ID, COLUMN_ICON);
                                FileMeta meta = new FileMeta();
                                meta.setAuthor(SearchFragment2.EMPTY_ID);
                                final Uri newNode = DocumentsContract.buildDocumentUriUsingTree(uri, COLUMN_DOCUMENT_ID);
                                meta.setPath(newNode.toString());
                                LOG.d("newNode", newNode);
                                if (Document.MIME_TYPE_DIR.equals(COLUMN_MIME_TYPE)) {
                                    meta.setCusType(FileMetaAdapter.DISPLAY_TYPE_DIRECTORY);
                                    meta.setPathTxt(COLUMN_DISPLAY_NAME);
                                    meta.setTitle(COLUMN_DISPLAY_NAME);
                                } else {
                                    try {
                                        if (COLUMN_SIZE != null) {
                                            long size = Long.parseLong(COLUMN_SIZE);
                                            meta.setSize(size);
                                            meta.setSizeTxt(ExtUtils.readableFileSize(size));
                                        }
                                        if (COLUMN_LAST_MODIFIED != null) {
                                            meta.setDateTxt(ExtUtils.getDateFormat(Long.parseLong(COLUMN_LAST_MODIFIED)));
                                        }
                                    } catch (Exception e) {
                                        LOG.e(e);
                                    }
                                    meta.setExt(ExtUtils.getFileExtension(COLUMN_DISPLAY_NAME));
                                    if (BookType.FB2.is(COLUMN_DISPLAY_NAME)) {
                                        meta.setTitle(TxtUtils.encode1251(COLUMN_DISPLAY_NAME));
                                    } else {
                                        meta.setTitle(COLUMN_DISPLAY_NAME);
                                    }
                                }
                                items.add(meta);
                            }
                        } finally {
                            closeQuietly(childCursor);
                        }
                    }
                } catch (Exception e) {
                    LOG.e(e);
                    Toast.makeText(getActivity(), R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                }
            }
        }
    }
    if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_PATH) {
        Collections.sort(items, FileMetaComparators.BY_PATH);
    } else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_DATE) {
        Collections.sort(items, FileMetaComparators.BY_DATE);
    } else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_SIZE) {
        Collections.sort(items, FileMetaComparators.BY_SIZE);
    } else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_NUMBER) {
        Collections.sort(items, FileMetaComparators.BR_BY_NUMBER1);
    } else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_PAGES) {
        Collections.sort(items, FileMetaComparators.BR_BY_PAGES);
    } else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_TITLE) {
        Collections.sort(items, FileMetaComparators.BR_BY_TITLE);
    } else if (AppState.get().sortByBrowse == AppState.BR_SORT_BY_EXT) {
        Collections.sort(items, FileMetaComparators.BR_BY_EXT);
    }
    if (AppState.get().sortByReverse) {
        Collections.reverse(items);
    }
    Collections.sort(items, FileMetaComparators.DIRS);
    for (int i = 0; i < items.size(); i++) {
        FileMeta m = items.get(i);
        if (m.getCusType() == null) {
            // directory
            LOG.d("DISPALY_TYPE_LAYOUT_TITLE_FOLDERS", i);
            FileMeta it = new FileMeta();
            it.setCusType(FileMetaAdapter.DISPALY_TYPE_LAYOUT_TITLE_NONE);
            items.add(i, it);
            break;
        }
    }
    searchAdapter.getItemsList().addAll(items);
    recyclerView.setAdapter(searchAdapter);
    paths.removeAllViews();
    if (ExtUtils.isExteralSD(path)) {
        String id = ExtUtils.getExtSDDisplayName(getContext(), path);
        TextView slash = new TextView(getActivity());
        slash.setText(id);
        slash.setTextColor(getResources().getColor(R.color.white));
        paths.addView(slash);
    } else {
        final String[] split = path.split("/");
        if (split == null || split.length == 0) {
            TextView slash = new TextView(getActivity());
            slash.setText(" / ");
            slash.setTextColor(getResources().getColor(R.color.white));
            paths.addView(slash);
        } else {
            for (int i = 0; i < split.length; i++) {
                final int index = i;
                String part = split[i];
                if (TxtUtils.isEmpty(part)) {
                    continue;
                }
                TextView slash = new TextView(getActivity());
                slash.setText(" / ");
                slash.setTextColor(getResources().getColor(R.color.white));
                TextView item = new TextView(getActivity());
                item.setText(part);
                item.setGravity(Gravity.CENTER);
                item.setTextColor(getResources().getColor(R.color.white));
                item.setSingleLine();
                TypedValue outValue = new TypedValue();
                getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
                item.setBackgroundResource(outValue.resourceId);
                if (i == split.length - 1) {
                    item.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                }
                item.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        StringBuilder builder = new StringBuilder();
                        for (int j = 0; j <= index; j++) {
                            builder.append("/");
                            builder.append(split[j]);
                        }
                        String itemPath = builder.toString();
                        setDirPath(itemPath);
                    }
                });
                paths.addView(slash);
                paths.addView(item, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
            }
            TextView stub = new TextView(getActivity());
            stub.setText("    ");
            paths.addView(stub);
        }
    }
    scroller.postDelayed(new Runnable() {

        @Override
        public void run() {
            scroller.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
        }
    }, 100);
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Cursor(android.database.Cursor) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) FileMeta(com.foobnix.dao2.FileMeta) TypedValue(android.util.TypedValue) TargetApi(android.annotation.TargetApi)

Aggregations

View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 DrawerListener (android.support.v4.widget.DrawerLayout.DrawerListener)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 TypedValue (android.util.TypedValue)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 FileMeta (com.foobnix.dao2.FileMeta)1 UITab (com.foobnix.pdf.info.wrapper.UITab)1 HorizontalViewActivity (com.foobnix.pdf.search.activity.HorizontalViewActivity)1 TabsAdapter2 (com.foobnix.ui2.adapter.TabsAdapter2)1 FastScrollRecyclerView (com.foobnix.ui2.fast.FastScrollRecyclerView)1