Search in sources :

Example 1 with ControlInfoNoScroll

use of ar.rulosoft.mimanganu.componentes.ControlInfoNoScroll in project MiMangaNu by raulhaag.

the class MangaFragment method onActivityCreated.

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    pm = PreferenceManager.getDefaultSharedPreferences(getActivity());
    super.onCreate(savedInstanceState);
    if (mMangaId == -1) {
        getActivity().onBackPressed();
    }
    mManga = Database.getManga(getActivity(), mMangaId);
    mServerBase = ServerBase.getServer(mManga.getServerId(), getContext());
    if (getView() == null) {
        try {
            finalize();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    } else {
        mListView = getView().findViewById(R.id.list);
        swipeReLayout = getView().findViewById(R.id.str);
        readerOptions = getView().findViewById(R.id.reader_options);
        mImageLoader = new ImageLoader(getActivity());
        final int[] colors = ThemeColors.getColors(pm);
        readerOptions.setBackgroundColor(colors[0]);
        readerOptions.setManga(mManga);
        swipeReLayout.setColorSchemeColors(colors[0], colors[1]);
        if (savedInstanceState != null) {
            if (searchForNewChapters.getStatus() == AsyncTask.Status.RUNNING) {
                swipeReLayout.post(new Runnable() {

                    @Override
                    public void run() {
                        swipeReLayout.setRefreshing(true);
                    }
                });
            }
        }
        swipeReLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                if ((searchForNewChapters.getStatus() != AsyncTask.Status.RUNNING)) {
                    searchForNewChapters = new SearchForNewChapters();
                    searchForNewChapters.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            }
        });
        mListView.setDivider(new ColorDrawable(colors[0]));
        mListView.setDividerHeight(1);
        mInfo = new ControlInfoNoScroll(getActivity());
        mListView.addHeaderView(mInfo);
        mInfo.setColor(MainActivity.darkTheme, colors[0]);
        mInfo.enableTitleCopy(getActivity(), mManga.getTitle());
        ChapterAdapter.setColor(MainActivity.darkTheme, colors[1], colors[0]);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Chapter c = (Chapter) mListView.getAdapter().getItem(position);
                getPagesTask = new GetPagesTask();
                getPagesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, c);
            }
        });
        mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        mListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

            @Override
            public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public void onDestroyActionMode(android.view.ActionMode mode) {
                mChapterAdapter.clearSelection();
            }

            @Override
            public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
                MenuInflater inflater = getActivity().getMenuInflater();
                inflater.inflate(R.menu.listitem_capitulo_menu_cab, menu);
                return true;
            }

            @Override
            public boolean onActionItemClicked(final android.view.ActionMode mode, MenuItem item) {
                final SparseBooleanArray selection = mChapterAdapter.getSelection();
                final ServerBase serverBase = ServerBase.getServer(mManga.getServerId(), getContext());
                boolean finish = true;
                switch(item.getItemId()) {
                    case R.id.select_all:
                        mChapterAdapter.selectAll();
                        return true;
                    case R.id.unselect:
                        mChapterAdapter.clearSelection();
                        return true;
                    case R.id.select_from:
                        mChapterAdapter.selectFrom(selection.keyAt(0));
                        return true;
                    case R.id.select_to:
                        mChapterAdapter.selectTo(selection.keyAt(0));
                        return true;
                    case R.id.download_selection:
                        new AsyncAddChapters().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mChapterAdapter.getSelectedChapters());
                        break;
                    case R.id.mark_as_read_and_delete_images:
                        markSelectedAsRead = new MarkSelectedAsRead(selection.size());
                        markSelectedAsRead.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        deleteImages = new DeleteImages(serverBase, selection.size());
                        deleteImages.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        break;
                    case R.id.delete_images:
                        deleteImages = new DeleteImages(serverBase, selection.size());
                        deleteImages.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        break;
                    case R.id.remove_chapter:
                        finish = false;
                        new AlertDialog.Builder(getContext()).setTitle(R.string.app_name).setMessage(R.string.delete_confirm).setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (selection.size() < 8) {
                                    // Remove chapters on UI Thread
                                    for (int i = selection.size() - 1; i >= 0; i--) {
                                        Chapter chapter = mChapterAdapter.getItem(selection.keyAt(i));
                                        chapter.delete(getActivity(), mManga, serverBase);
                                        mChapterAdapter.remove(chapter);
                                        mode.finish();
                                    }
                                } else {
                                    removeChapters = new RemoveChapters(serverBase, selection.size(), mode);
                                    removeChapters.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                }
                                dialog.dismiss();
                            }
                        }).show();
                        break;
                    case R.id.reset_chapter:
                        resetChapters = new ResetChapters(serverBase, selection.size());
                        resetChapters.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        break;
                    case R.id.mark_selected_as_read:
                        markSelectedAsRead = new MarkSelectedAsRead(selection.size());
                        markSelectedAsRead.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        break;
                    case R.id.mark_selected_as_unread:
                        markSelectedAsUnread = new MarkSelectedAsUnread(selection.size());
                        markSelectedAsUnread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        break;
                }
                mChapterAdapter.notifyDataSetChanged();
                if (finish)
                    mode.finish();
                return false;
            }

            @Override
            public void onItemCheckedStateChanged(android.view.ActionMode mode, int position, long id, boolean checked) {
                mChapterAdapter.setSelectedOrUnselected(position);
            }
        });
        getActivity().setTitle(mManga.getTitle());
        Database.updateMangaRead(getActivity(), mManga.getId());
        loadInfo(mManga);
        chapters_order = pm.getInt(CHAPTERS_ORDER, 1);
        hide_read = pm.getBoolean(CHAPTERS_HIDE_READ, false);
    }
}
Also used : ActionMode(android.view.ActionMode) DialogInterface(android.content.DialogInterface) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SparseBooleanArray(android.util.SparseBooleanArray) Menu(android.view.Menu) ServerBase(ar.rulosoft.mimanganu.servers.ServerBase) MenuInflater(android.view.MenuInflater) Chapter(ar.rulosoft.mimanganu.componentes.Chapter) AbsListView(android.widget.AbsListView) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) ControlInfoNoScroll(ar.rulosoft.mimanganu.componentes.ControlInfoNoScroll) ColorDrawable(android.graphics.drawable.ColorDrawable) AdapterView(android.widget.AdapterView) ImageLoader(com.fedorvlasov.lazylist.ImageLoader)

Aggregations

DialogInterface (android.content.DialogInterface)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 SparseBooleanArray (android.util.SparseBooleanArray)1 ActionMode (android.view.ActionMode)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 Chapter (ar.rulosoft.mimanganu.componentes.Chapter)1 ControlInfoNoScroll (ar.rulosoft.mimanganu.componentes.ControlInfoNoScroll)1 ServerBase (ar.rulosoft.mimanganu.servers.ServerBase)1 ImageLoader (com.fedorvlasov.lazylist.ImageLoader)1