Search in sources :

Example 1 with Chapter

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

the class ReaderFragment method onEndOver.

@Override
public void onEndOver() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    boolean imagesDelete = pm.getBoolean("delete_images", false);
    boolean seamlessChapterTransition = pm.getBoolean("seamless_chapter_transitions", false);
    boolean seamlessChapterTransitionDeleteRead = pm.getBoolean("seamless_chapter_transitions_delete_read", false);
    if (nextChapter != null) {
        if (!seamlessChapterTransition) {
            View v = inflater.inflate(R.layout.dialog_next_chapter, null);
            final CheckBox checkBox = v.findViewById(R.id.delete_images_oc);
            checkBox.setChecked(imagesDelete);
            mDialog = new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.finished_reading, mChapter.getTitle())).setView(v).setIcon(R.mipmap.ic_launcher).setNegativeButton(getString(R.string.back), null).setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    boolean del_images = checkBox.isChecked();
                    if (pm != null)
                        pm.edit().putBoolean("delete_images", del_images).apply();
                    mChapter.setReadStatus(Chapter.READ);
                    mChapter.setPagesRead(mChapter.getPages());
                    Database.updateChapter(getActivity(), mChapter);
                    Chapter pChapter = mChapter;
                    loadChapter(nextChapter, LoadMode.START);
                    if (del_images) {
                        pChapter.freeSpace(getActivity());
                    }
                    if (mDialog != null && mDialog.isShowing())
                        mDialog.dismiss();
                    mDialog = null;
                }
            }).setNeutralButton(R.string.dont_ask_again, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    boolean del_images = checkBox.isChecked();
                    if (pm != null)
                        pm.edit().putBoolean("delete_images", del_images).apply();
                    mChapter.setReadStatus(Chapter.READ);
                    mChapter.setPagesRead(mChapter.getPages());
                    Database.updateChapter(getActivity(), mChapter);
                    Chapter pChapter = mChapter;
                    loadChapter(nextChapter, LoadMode.START);
                    if (del_images) {
                        pChapter.freeSpace(getActivity());
                    }
                    if (mDialog != null && mDialog.isShowing())
                        mDialog.dismiss();
                    mDialog = null;
                    pm.edit().putBoolean("seamless_chapter_transitions", true).apply();
                }
            }).show();
        } else {
            mChapter.setReadStatus(Chapter.READ);
            mChapter.setPagesRead(mChapter.getPages());
            Chapter tmpChapter = mChapter;
            loadChapter(nextChapter, LoadMode.START);
            // Util.getInstance().toast(getApplicationContext(), mChapter.getTitle(), 0);
            Util.getInstance().showSlowSnackBar(mChapter.getTitle(), mControlsLayout, getActivity());
            if (seamlessChapterTransitionDeleteRead) {
                tmpChapter.freeSpace(getActivity());
                Util.getInstance().toast(getActivity(), getResources().getString(R.string.deleted, tmpChapter.getTitle()), 0);
            }
        }
    } else {
        final Chapter tmpChapter = mChapter;
        View v = inflater.inflate(R.layout.dialog_no_more_chapters, null);
        final CheckBox checkBox = v.findViewById(R.id.delete_images_oc);
        checkBox.setChecked(imagesDelete);
        mDialog = new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.finished_reading, mManga.getTitle())).setView(v).setIcon(R.mipmap.ic_launcher).setNegativeButton(R.string.back, null).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean del_images = checkBox.isChecked();
                if (pm != null)
                    pm.edit().putBoolean("delete_images", del_images).apply();
                if (del_images) {
                    try {
                        tmpChapter.freeSpace(getActivity());
                    } catch (Exception e) {
                    // TODO catch context lost if user close while freeSpace is working (need to add a little service for this)
                    }
                }
                if (mDialog != null)
                    mDialog.dismiss();
                // just to close
                controlVisible = true;
                mDialog = null;
                if (getActivity() != null)
                    getActivity().onBackPressed();
            }
        }).show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Chapter(ar.rulosoft.mimanganu.componentes.Chapter) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater)

Example 2 with Chapter

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

the class ChapterAdapter method getView.

public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = li.inflate(listItem, null);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Chapter item = getItem(position);
    if (item != null) {
        holder.textViewName.setText(item.getTitle());
        holder.textViewStatus.setVisibility(View.GONE);
        if (defaultColor == null) {
            defaultColor = holder.textViewName.getTextColors();
        }
        switch(item.getReadStatus()) {
            case Chapter.NEW:
                holder.textViewStatus.setVisibility(View.VISIBLE);
                holder.textViewName.setTextColor(defaultColor);
                holder.textViewPages.setTextColor(defaultColor);
                break;
            case Chapter.READ:
                holder.textViewName.setTextColor(COLOR_READ);
                holder.textViewPages.setTextColor(COLOR_READ);
                break;
            case Chapter.READING:
                holder.textViewName.setTextColor(COLOR_READING);
                holder.textViewPages.setTextColor(COLOR_READING);
                break;
            default:
                holder.textViewName.setTextColor(defaultColor);
                holder.textViewPages.setTextColor(defaultColor);
                break;
        }
        if (selected.get(position)) {
            convertView.setBackgroundColor(COLOR_SELECTED);
            holder.textViewName.setTextColor(Color.WHITE);
            holder.textViewPages.setTextColor(Color.WHITE);
        } else {
            convertView.setBackgroundColor(Color.TRANSPARENT);
        }
        if (item.getPages() > 0) {
            holder.textViewPages.setText(String.format("%d/%d", item.getPagesRead(), item.getPages()));
        } else {
            holder.textViewPages.setText("");
        }
        holder.imageButton.setImageResource(item.isDownloaded() ? buttonDelete : buttonDownload);
        holder.imageButton.setTag(item);
        holder.imageButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(final View v) {
                Chapter c = (Chapter) v.getTag();
                if (c.isDownloaded()) {
                    item.freeSpace(getContext());
                    getItem(position).setDownloaded(false);
                    Database.updateChapterDownloaded(activity, c.getId(), 0);
                    Util.getInstance().showFastSnackBar(activity.getResources().getString(R.string.borrado_imagenes), v, activity);
                    notifyDataSetChanged();
                // ((ImageView)v).setImageResource(R.drawable.ic_bajar);
                } else {
                    if (can_download) {
                        try {
                            DownloadPoolService.addChapterDownloadPool(activity, c, false);
                            Util.getInstance().showFastSnackBar(activity.getResources().getString(R.string.agregadodescarga), v, activity);
                        } catch (Exception e) {
                            Log.e("ChapterAdapter", Log.getStackTraceString(e));
                            if (e.getMessage() != null) {
                                // what the fuck ~ xtj9182
                                Util.getInstance().showFastSnackBar(activity.getResources().getString(R.string.agregadodescarga), v, activity);
                            }
                        }
                    }
                }
            }
        });
    }
    return convertView;
}
Also used : Chapter(ar.rulosoft.mimanganu.componentes.Chapter) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 3 with Chapter

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

the class TestServersCommon method testManga.

private void testManga(ArrayList<Manga> mangas) throws Exception {
    assertNotNull(getContext(), mangas);
    assertFalse(getContext(), mangas.isEmpty());
    // some servers list Manga without chapters - so try to fetch up to 'retries' times
    Manga manga;
    int retries = 5;
    do {
        manga = mangas.get(rand.nextInt(mangas.size()));
        assertNotNull(getContext(), manga);
        testLoadManga(manga);
        try {
            serverBase.loadChapters(manga, false);
        } catch (Exception e) {
            fail(getContext(e.getMessage()));
        }
        if (manga.getChapters().isEmpty()) {
            logMessage("[WRN] no chapters found - will try another Manga.");
        }
    } while (manga.getChapters().isEmpty() && retries-- > 0);
    assertFalse(getContext(), manga.getChapters().isEmpty());
    ArrayList<Chapter> chapters = manga.getChapters();
    Chapter.Comparators.setManga_title(manga.getTitle());
    Collections.sort(chapters, Chapter.Comparators.NUMBERS_ASC);
    assertEquals(getContext("chapters not sorted ascending"), manga.getChapters(), chapters);
    Chapter chapter = manga.getChapter(rand.nextInt(manga.getChapters().size()));
    assertNotNull(getContext(), chapter);
    testInitChapter(chapter);
}
Also used : Chapter(ar.rulosoft.mimanganu.componentes.Chapter) Manga(ar.rulosoft.mimanganu.componentes.Manga)

Example 4 with Chapter

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

the class RawSenManga method loadChapters.

@Override
public void loadChapters(Manga manga, boolean forceReload) throws Exception {
    if (manga.getChapters().isEmpty() || forceReload) {
        String data = getNavigatorAndFlushParameters().get(manga.getPath());
        // Summary
        manga.setSynopsis(getFirstMatchDefault("<span itemprop=\"description\">([\\s\\S]+?)</span>", data, context.getString(R.string.nodisponible)));
        if (manga.getSynopsis().startsWith("No Description.") || manga.getSynopsis().isEmpty()) {
            manga.setSynopsis(context.getString(R.string.nodisponible));
        }
        // Cover
        manga.setImages(getFirstMatchDefault("\"image\" src=\"([^\"]+)", data, ""));
        // Author(s)
        manga.setAuthor(getFirstMatchDefault("<li><b>Author</b>:(.+?)</li>", data, context.getString(R.string.nodisponible)).replace("</a>", "</a>,"));
        // Genre
        manga.setGenre(getFirstMatchDefault("<li><b>Categories</b>:(.+?)</li>", data, context.getString(R.string.nodisponible)));
        // Status
        manga.setFinished(getFirstMatchDefault("<li><b>Status</b>:(.+?)</li>", data, "").trim().contains("Complete"));
        // Chapters
        Pattern p = Pattern.compile("<div class=\"title\"><a href=\"([^\"]+)\" title=\"([^\"]+)\"", Pattern.DOTALL);
        Matcher m = p.matcher(data);
        while (m.find()) {
            if (m.group(1).endsWith("/1")) {
                // strip off page suffix if present
                manga.addChapterFirst(new Chapter(m.group(2), m.group(1).substring(0, m.group(1).length() - 2)));
            } else {
                manga.addChapterFirst(new Chapter(m.group(2), m.group(1)));
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Chapter(ar.rulosoft.mimanganu.componentes.Chapter)

Example 5 with Chapter

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

the class ReadComicOnline method loadMangaInformation.

@Override
public void loadMangaInformation(Manga manga, boolean forceReload) throws Exception {
    if (manga.getChapters().isEmpty() || forceReload) {
        String source = getNavigatorAndFlushParameters().get(HOST + manga.getPath());
        // Summary
        manga.setSynopsis(getFirstMatchDefault("<span " + "class=\"info\">Summary:</span>(.+?)</div>", source, context.getString(R.string.nodisponible)));
        // Cover Image
        if (manga.getImages() == null || manga.getImages().isEmpty()) {
            String coverImage = getFirstMatchDefault("src=\"(http[s]?://readcomiconline.to/Uploads/[^\"]+?|http[s]?://\\d+.bp.blogspot.com/[^\"]+?)\"", source, "");
            if (!coverImage.isEmpty()) {
                manga.setImages(coverImage);
            }
        }
        // Author
        String artist = getFirstMatchDefault("Artist:.+?\">(.+?)</a>", source, context.getString(R.string.nodisponible));
        String writer = getFirstMatchDefault("Writer:.+?\">(.+?)</a>", source, context.getString(R.string.nodisponible));
        if (artist.equals(writer)) {
            manga.setAuthor(artist);
        } else {
            manga.setAuthor(artist + ", " + writer);
        }
        // Genre
        manga.setGenre(getFirstMatchDefault("Genres:</span>&nbsp;(.+?)</p>", source, context.getString(R.string.nodisponible)));
        // Status
        manga.setFinished(source.contains("Status:</span>&nbsp;Completed"));
        // Chapter
        Pattern p = Pattern.compile(PATTERN_CHAPTER, Pattern.DOTALL);
        Matcher matcher = p.matcher(source);
        while (matcher.find()) {
            manga.addChapterFirst(new Chapter(matcher.group(2).replace(" Read Online", ""), matcher.group(1)));
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Chapter(ar.rulosoft.mimanganu.componentes.Chapter)

Aggregations

Chapter (ar.rulosoft.mimanganu.componentes.Chapter)37 Matcher (java.util.regex.Matcher)27 Pattern (java.util.regex.Pattern)27 ArrayList (java.util.ArrayList)5 Manga (ar.rulosoft.mimanganu.componentes.Manga)4 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 AlertDialog (android.app.AlertDialog)2 SharedPreferences (android.content.SharedPreferences)2 TextView (android.widget.TextView)2 ServerBase (ar.rulosoft.mimanganu.servers.ServerBase)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 SparseBooleanArray (android.util.SparseBooleanArray)1 ActionMode (android.view.ActionMode)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1