Search in sources :

Example 1 with FromFolder

use of ar.rulosoft.mimanganu.servers.FromFolder in project MiMangaNu by raulhaag.

the class Chapter method deleteImages.

private void deleteImages(Context context, Manga manga, ServerBase serverBase) {
    String path;
    if (!(serverBase instanceof FromFolder)) {
        path = Paths.generateBasePath(serverBase, manga, this, context);
    } else {
        path = getPath();
    }
    File f = new File(path);
    if (f.exists()) {
        Util.getInstance().deleteRecursive(f);
    }
}
Also used : FromFolder(ar.rulosoft.mimanganu.servers.FromFolder) File(java.io.File)

Example 2 with FromFolder

use of ar.rulosoft.mimanganu.servers.FromFolder in project MiMangaNu by raulhaag.

the class ReaderFragment method loadChapter.

private void loadChapter(Chapter nChapter, LoadMode mode) {
    if (mChapter != null) {
        DownloadPoolService.detachListener(mChapter.getId());
        Database.updateChapter(getActivity(), mChapter);
    }
    mChapter = nChapter;
    if (mChapter == null) {
        return;
    }
    if (!mChapter.isDownloaded()) {
        try {
            DownloadPoolService.addChapterDownloadPool(getActivity(), mChapter, true);
        } catch (Exception e) {
            if (e.getMessage() != null) {
                Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
    titleTextView.setText(mChapter.getTitle());
    if (mChapter.getPages() == 0) {
        new GetPageTask().execute(mChapter);
    } else {
        if (mChapter.getPagesRead() == 0)
            mChapter.setPagesRead(1);
        DownloadPoolService.setDownloadListener(this);
        mChapter.setReadStatus(Chapter.READING);
        Database.updateChapter(getActivity(), mChapter);
        mReader.reset();
        ArrayList<String> pages = new ArrayList<>();
        if (!(mServerBase instanceof FromFolder)) {
            for (int i = 0; i < mChapter.getPages(); i++) {
                pages.add(Paths.generateBasePath(mServerBase, mManga, mChapter, getActivity()) + "/" + (i + 1) + ".jpg");
            }
        } else {
            for (int i = 0; i < mChapter.getPages(); i++) {
                try {
                    pages.add(mServerBase.getImageFrom(mChapter, i));
                } catch (Exception ignore) {
                }
            }
        }
        mReader.setPaths(pages);
        mActionBar.setTitle(mManga.getTitle());
        mSeekBar.setMax(mChapter.getPages() - 1);
        DownloadPoolService.attachListener(this, mChapter.getId());
        boolean next = false;
        for (int i = 0; i < mManga.getChapters().size(); i++) {
            if (mManga.getChapters().get(i).getId() == mChapter.getId()) {
                if (i > 0) {
                    next = true;
                    nextChapter = mManga.getChapters().get(i - 1);
                }
                if (i + 1 < mManga.getChapters().size()) {
                    previousChapter = mManga.getChapters().get(i + 1);
                }
                break;
            }
        }
        if (!next)
            nextChapter = null;
        if (nextChapter != null) {
            if (!nextChapter.isDownloaded()) {
                if (pm.getBoolean("download_next_chapter_automatically", false)) {
                    if (DownloadPoolService.isNewDownload(nextChapter.getId())) {
                        try {
                            DownloadPoolService.addChapterDownloadPool(getActivity(), nextChapter, false);
                            Util.getInstance().toast(getActivity(), getResources().getString(R.string.downloading) + " " + nextChapter.getTitle());
                        } catch (Exception e) {
                            Log.e("ServB", "Download add pool error", e);
                        }
                    }
                }
            }
        }
        switch(mode) {
            case START:
                mReader.seekPage(1);
                break;
            case END:
                mReader.seekPage(mChapter.getPages());
                break;
            case SAVED:
                if (mChapter.getPagesRead() == 0)
                    mChapter.setPagesRead(1);
                mReader.seekPage(mChapter.getPagesRead());
        }
    }
    mReader.postInvalidateDelayed(200);
}
Also used : FromFolder(ar.rulosoft.mimanganu.servers.FromFolder) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint)

Example 3 with FromFolder

use of ar.rulosoft.mimanganu.servers.FromFolder in project MiMangaNu by raulhaag.

the class ServersSelectFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(getActivity());
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_add_manga, container, false);
    server_list = viewGroup.findViewById(R.id.lista_de_servers);
    server_list.setLayoutManager(new LinearLayoutManager(getActivity()));
    serverRecAdapter = new ServerRecAdapter(ServerBase.getServers(getContext()), pm, getActivity());
    serverRecAdapter.setEndActionModeListener(this);
    server_list.setAdapter(serverRecAdapter);
    serverRecAdapter.setOnServerClickListener(new ServerRecAdapter.OnServerClickListener() {

        @Override
        public void onServerClick(final ServerBase server) {
            if (!(server instanceof FromFolder)) {
                if (server.hasCredentials()) {
                    if (server.hasFilteredNavigation()) {
                        ServerFilteredNavigationFragment fragment = new ServerFilteredNavigationFragment();
                        Bundle b = new Bundle();
                        b.putInt(MainFragment.SERVER_ID, server.getServerID());
                        fragment.setArguments(b);
                        ((MainActivity) getActivity()).replaceFragment(fragment, "FilteredNavigation");
                    } else {
                        ServerListFragment fragment = new ServerListFragment();
                        Bundle b = new Bundle();
                        b.putInt(MainFragment.SERVER_ID, server.getServerID());
                        fragment.setArguments(b);
                        ((MainActivity) getActivity()).replaceFragment(fragment, "FilteredServerList");
                    }
                } else {
                    LoginDialog lDialog = new LoginDialog(getContext(), server);
                    lDialog.getDialog().setCanceledOnTouchOutside(false);
                    lDialog.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (server.hasCredentials())
                                onServerClick(server);
                            else
                                Util.getInstance().showFastSnackBar(getString(R.string.this_server_needs_an_account), getView(), getContext());
                        }
                    });
                    lDialog.show();
                }
            } else {
                MangaFolderSelect mangaFolderSelect = new MangaFolderSelect();
                mangaFolderSelect.show(getChildFragmentManager(), "fragment_find_folder");
            }
        }
    });
    return viewGroup;
}
Also used : ServerBase(ar.rulosoft.mimanganu.servers.ServerBase) FromFolder(ar.rulosoft.mimanganu.servers.FromFolder) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) MangaFolderSelect(ar.rulosoft.mimanganu.componentes.MangaFolderSelect) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ServerRecAdapter(ar.rulosoft.mimanganu.adapters.ServerRecAdapter) LoginDialog(ar.rulosoft.mimanganu.componentes.LoginDialog)

Aggregations

FromFolder (ar.rulosoft.mimanganu.servers.FromFolder)3 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ViewGroup (android.view.ViewGroup)1 ServerRecAdapter (ar.rulosoft.mimanganu.adapters.ServerRecAdapter)1 LoginDialog (ar.rulosoft.mimanganu.componentes.LoginDialog)1 MangaFolderSelect (ar.rulosoft.mimanganu.componentes.MangaFolderSelect)1 ServerBase (ar.rulosoft.mimanganu.servers.ServerBase)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1