From 6e29b62ca91fdf704ba489ac69e0a56e4588e26b Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 17 Jun 2019 19:52:11 -0400 Subject: [PATCH] v1.1.0, but labeled v1.1.1 because i keep screwing up commits --- app/build.gradle | 2 +- .../adapters/novel/ChaptersViewHolder.java | 4 +- .../shosetsu/async/CataloguePageLoader.java | 83 +++++++++++++++++++ .../shosetsu/async/NovelChaptersLoader.java | 75 +++++++++++++++++ .../apps/shosetsu/async/NovelLoader.java | 81 ++++++++++++++++++ .../shosetsu/fragment/CatalogueFragement.java | 55 ++++-------- .../fragment/novel/NovelFragment.java | 56 ++++--------- .../fragment/novel/NovelFragmentChapters.java | 59 +++---------- .../fragment/novel/NovelFragmentMain.java | 34 +++++--- .../res/layout-land/fragment_novel_main.xml | 14 +++- .../main/res/layout/fragment_catalogue.xml | 37 +++++++-- app/src/main/res/layout/fragment_novel.xml | 19 ++++- .../res/layout/fragment_novel_chapters.xml | 42 ++++++++-- .../main/res/layout/fragment_novel_main.xml | 15 +++- .../res/layout/include_progress_overlay.xml | 20 ----- 15 files changed, 410 insertions(+), 186 deletions(-) create mode 100644 app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/CataloguePageLoader.java create mode 100644 app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelChaptersLoader.java create mode 100644 app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelLoader.java delete mode 100644 app/src/main/res/layout/include_progress_overlay.xml diff --git a/app/build.gradle b/app/build.gradle index 854c6e38fa..87bdaa8023 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { minSdkVersion 23 targetSdkVersion 28 versionCode 1 - versionName "v1.0.9-alpha" + versionName "v1.1.1-alpha" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/adapters/novel/ChaptersViewHolder.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/adapters/novel/ChaptersViewHolder.java index 2f3e827094..9f1956e38c 100644 --- a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/adapters/novel/ChaptersViewHolder.java +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/adapters/novel/ChaptersViewHolder.java @@ -57,11 +57,11 @@ public class ChaptersViewHolder extends RecyclerView.ViewHolder implements View. itemView.setOnClickListener(this); download.setOnClickListener(v -> { if (!downloaded) { - DownloadItem downloadItem = new DownloadItem(NovelChaptersAdapter.formatter, novelFragmentChapters.novelTitle, novelChapter.chapterNum, novelFragmentChapters.novelURL, novelChapter.link, novelFragmentChapters); + DownloadItem downloadItem = new DownloadItem(NovelChaptersAdapter.formatter, novelFragmentChapters.novelPage.title, novelChapter.chapterNum, novelFragmentChapters.novelURL, novelChapter.link, novelFragmentChapters); Downloadmanager.addToDownload(downloadItem); downloaded = true; } else { - if (Downloadmanager.delete(new DeleteItem(NovelChaptersAdapter.formatter, novelFragmentChapters.novelTitle, novelChapter.chapterNum, novelFragmentChapters.novelURL, novelChapter.link))) + if (Downloadmanager.delete(new DeleteItem(NovelChaptersAdapter.formatter, novelFragmentChapters.novelPage.title, novelChapter.chapterNum, novelFragmentChapters.novelURL, novelChapter.link))) download.setImageResource(R.drawable.ic_outline_arrow_drop_down_circle_24px); downloaded = false; } diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/CataloguePageLoader.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/CataloguePageLoader.java new file mode 100644 index 0000000000..5ac76760a5 --- /dev/null +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/CataloguePageLoader.java @@ -0,0 +1,83 @@ +package com.github.Doomsdayrs.apps.shosetsu.async; + +import android.os.AsyncTask; +import android.util.Log; +import android.view.View; + +import com.github.Doomsdayrs.api.novelreader_core.services.core.dep.Formatter; +import com.github.Doomsdayrs.api.novelreader_core.services.core.objects.Novel; +import com.github.Doomsdayrs.apps.shosetsu.fragment.CatalogueFragement; +import com.github.Doomsdayrs.apps.shosetsu.recycleObjects.CatalogueNovelCard; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; + +/** + * This file is part of Shosetsu. + * Shosetsu is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with Shosetsu. If not, see https://www.gnu.org/licenses/ . + * ==================================================================== + * Shosetsu + * 17 / 06 / 2019 + * + * @author github.com/doomsdayrs + */ +public class CataloguePageLoader extends AsyncTask { + private CatalogueFragement catalogueFragement; + private Formatter formatter; + private ArrayList catalogueNovelCards; + + public CataloguePageLoader(CatalogueFragement catalogueFragement, Formatter formatter, ArrayList catalogueNovelCards) { + this.catalogueFragement = catalogueFragement; + this.formatter = formatter; + this.catalogueNovelCards = catalogueNovelCards; + } + + @Override + protected Boolean doInBackground(Integer... integers) { + Log.d("Loading", "Catalogue"); + try { + List novels; + if (integers.length == 0) + novels = formatter.parseLatest(formatter.getLatestURL(1)); + else novels = formatter.parseLatest(formatter.getLatestURL(integers[0])); + + for (Novel novel : novels) + catalogueNovelCards.add(new CatalogueNovelCard(novel.imageURL, novel.title, new URI(novel.link))); + catalogueFragement.library_view.post(() -> catalogueFragement.library_Adapter.notifyDataSetChanged()); + + return true; + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return false; + } + + @Override + protected void onCancelled() { + catalogueFragement.progressBar.setVisibility(View.GONE); + } + + @Override + protected void onPreExecute() { + catalogueFragement.progressBar.setVisibility(View.VISIBLE); + } + + @Override + protected void onPostExecute(Boolean aBoolean) { + catalogueFragement.progressBar.setVisibility(View.GONE); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelChaptersLoader.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelChaptersLoader.java new file mode 100644 index 0000000000..f99426d73c --- /dev/null +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelChaptersLoader.java @@ -0,0 +1,75 @@ +package com.github.Doomsdayrs.apps.shosetsu.async; + +import android.os.AsyncTask; +import android.view.View; + +import com.github.Doomsdayrs.api.novelreader_core.services.core.objects.NovelPage; +import com.github.Doomsdayrs.apps.shosetsu.fragment.novel.NovelFragmentChapters; + +import java.io.IOException; + +/** + * This file is part of Shosetsu. + * Shosetsu is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with Shosetsu. If not, see https://www.gnu.org/licenses/ . + * ==================================================================== + * Shosetsu + * 17 / 06 / 2019 + * + * @author github.com/doomsdayrs + */ +public class NovelChaptersLoader extends AsyncTask { + private NovelFragmentChapters novelFragmentChapters; + + public NovelChaptersLoader(NovelFragmentChapters novelFragmentChapters) { + this.novelFragmentChapters = novelFragmentChapters; + } + + @Override + protected Boolean doInBackground(Integer... integers) { + if (novelFragmentChapters.formatter.isIncrementingChapterList()) + try { + NovelPage novelPage; + if (integers.length == 0) + novelPage = novelFragmentChapters.formatter.parseNovel(novelFragmentChapters.novelURL); + else + novelPage = novelFragmentChapters.formatter.parseNovel(novelFragmentChapters.novelURL, integers[0]); + //TODO Difference calculation + + if (!novelPage.novelChapters.get(novelPage.novelChapters.size() - 1).link + .equals(novelFragmentChapters.novelChapters.get(novelFragmentChapters.novelChapters.size() - 1).link)) + novelFragmentChapters.novelChapters.addAll(novelPage.novelChapters); + return true; + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + @Override + protected void onCancelled() { + novelFragmentChapters.progressBar.setVisibility(View.GONE); + super.onCancelled(); + } + + @Override + protected void onPreExecute() { + super.onPreExecute(); + novelFragmentChapters.progressBar.setVisibility(View.VISIBLE); + } + + @Override + protected void onPostExecute(Boolean aBoolean) { + novelFragmentChapters.progressBar.setVisibility(View.GONE); + if (aBoolean) + novelFragmentChapters.recyclerView.post(() -> novelFragmentChapters.adapter.notifyDataSetChanged()); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelLoader.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelLoader.java new file mode 100644 index 0000000000..147dc0b7f2 --- /dev/null +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/async/NovelLoader.java @@ -0,0 +1,81 @@ +package com.github.Doomsdayrs.apps.shosetsu.async; + +import android.app.Activity; +import android.os.AsyncTask; +import android.util.Log; +import android.view.View; +import android.widget.Toast; + +import com.github.Doomsdayrs.apps.shosetsu.fragment.novel.NovelFragment; + +import java.io.IOException; +import java.net.SocketTimeoutException; + +/** + * This file is part of Shosetsu. + * Shosetsu is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with Shosetsu. If not, see https://www.gnu.org/licenses/ . + * ==================================================================== + * Shosetsu + * 17 / 06 / 2019 + * + * @author github.com/doomsdayrs + */ +public class NovelLoader extends AsyncTask { + private NovelFragment novelFragment; + private Activity activity; + + public NovelLoader(NovelFragment novelFragment) { + this.novelFragment = novelFragment; + } + + + @Override + protected Boolean doInBackground(Activity... voids) { + this.activity = voids[0]; + + Log.d("Loading", "Novel"); + try { + novelFragment.novelPage = novelFragment.formatter.parseNovel(novelFragment.url); + novelFragment.novelFragmentMain.novelPage = novelFragment.novelPage; + Log.d("Loaded Novel:", novelFragment.novelPage.title); + + return true; + } catch (SocketTimeoutException e) { + activity.runOnUiThread(() -> Toast.makeText(novelFragment.getContext(), "Timeout", Toast.LENGTH_SHORT).show()); + + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + @Override + protected void onPreExecute() { + novelFragment.progressBar.setVisibility(View.VISIBLE); + super.onPreExecute(); + + } + + @Override + protected void onCancelled() { + super.onCancelled(); + } + + @Override + protected void onPostExecute(Boolean aBoolean) { + novelFragment.progressBar.setVisibility(View.GONE); + if (aBoolean) { + activity.runOnUiThread(() -> novelFragment.novelFragmentMain.setData()); + activity.runOnUiThread(() -> novelFragment.novelFragmentChapters.setNovels(novelFragment.novelFragmentChapters.novelChapters)); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/CatalogueFragement.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/CatalogueFragement.java index a0cf4109af..e50b426643 100644 --- a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/CatalogueFragement.java +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/CatalogueFragement.java @@ -17,12 +17,14 @@ import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ProgressBar; import android.widget.SearchView; import com.github.Doomsdayrs.api.novelreader_core.services.core.dep.Formatter; import com.github.Doomsdayrs.api.novelreader_core.services.core.objects.Novel; import com.github.Doomsdayrs.apps.shosetsu.R; import com.github.Doomsdayrs.apps.shosetsu.adapters.catalogue.CatalogueNovelCardsAdapter; +import com.github.Doomsdayrs.apps.shosetsu.async.CataloguePageLoader; import com.github.Doomsdayrs.apps.shosetsu.recycleObjects.CatalogueNovelCard; import java.io.IOException; @@ -60,8 +62,9 @@ public class CatalogueFragement extends Fragment { private SearchView searchView; private Context context; private boolean firstRun; - private RecyclerView.Adapter library_Adapter; + public RecyclerView.Adapter library_Adapter; private RecyclerView.LayoutManager library_layoutManager; + public ProgressBar progressBar; public CatalogueFragement() { setHasOptionsMenu(true); @@ -80,23 +83,16 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c library_view = view.findViewById(R.id.fragment_catalogue_recycler); swipeRefreshLayout = view.findViewById(R.id.fragment_catalogue_refresh); swipeRefreshLayout.setOnRefreshListener(new refresh(this)); - + progressBar = view.findViewById(R.id.fragment_catalogue_progress); this.context = container.getContext(); if (savedInstanceState == null) { Log.d("Process", "Loading up latest"); - try { - if (firstRun) { - firstRun = false; - boolean b = new setLatest().execute().get(); - if (b) - setLibraryCards(libraryCards); - } else setLibraryCards(libraryCards); - } catch (ExecutionException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + if (firstRun) { + firstRun = false; + setLibraryCards(libraryCards); + new CataloguePageLoader(this, formatter, libraryCards).execute(); + } else setLibraryCards(libraryCards); } else setLibraryCards(libraryCards); return view; } @@ -112,7 +108,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } - private void setLibraryCards(ArrayList recycleCards) { + public void setLibraryCards(ArrayList recycleCards) { if (library_view != null) { library_view.setHasFixedSize(false); if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) @@ -143,11 +139,11 @@ protected ArrayList doInBackground(String... strings) { } } - static class bottom extends RecyclerView.OnScrollListener { + class bottom extends RecyclerView.OnScrollListener { CatalogueFragement catalogueFragement; boolean running = false; - public bottom(CatalogueFragement catalogueFragement) { + bottom(CatalogueFragement catalogueFragement) { this.catalogueFragement = catalogueFragement; } @@ -160,7 +156,7 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { running = true; catalogueFragement.currentMaxPage++; try { - if (new setLatest().execute(catalogueFragement.currentMaxPage).get()) { + if (new CataloguePageLoader(catalogueFragement, formatter, libraryCards).execute(catalogueFragement.currentMaxPage).get()) { catalogueFragement.library_view.post(() -> { catalogueFragement.library_Adapter.notifyDataSetChanged(); catalogueFragement.library_view.addOnScrollListener(this); @@ -179,27 +175,6 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { } } - static class setLatest extends AsyncTask { - @Override - protected Boolean doInBackground(Integer... integers) { - try { - List novels; - if (integers.length == 0) - novels = formatter.parseLatest(formatter.getLatestURL(1)); - else novels = formatter.parseLatest(formatter.getLatestURL(integers[0])); - - for (Novel novel : novels) - libraryCards.add(new CatalogueNovelCard(novel.imageURL, novel.title, new URI(novel.link))); - return true; - } catch (IOException e) { - e.printStackTrace(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - return false; - } - } - class refresh implements SwipeRefreshLayout.OnRefreshListener { CatalogueFragement catalogueFragement; @@ -215,7 +190,7 @@ public void onRefresh() { libraryCards = new ArrayList<>(); try { Log.d("FragmentRefresh", "Refreshing catalogue data"); - if (new setLatest().execute().get()) { + if (new CataloguePageLoader(catalogueFragement, formatter, libraryCards).execute().get()) { Log.d("FragmentRefresh", "Complete"); catalogueFragement.library_Adapter.notifyDataSetChanged(); } diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragment.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragment.java index 001743a0d6..a97a74b456 100644 --- a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragment.java +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragment.java @@ -1,6 +1,5 @@ package com.github.Doomsdayrs.apps.shosetsu.fragment.novel; -import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -11,18 +10,18 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ProgressBar; import com.github.Doomsdayrs.api.novelreader_core.main.DefaultScrapers; import com.github.Doomsdayrs.api.novelreader_core.services.core.dep.Formatter; import com.github.Doomsdayrs.api.novelreader_core.services.core.objects.NovelPage; import com.github.Doomsdayrs.apps.shosetsu.R; import com.github.Doomsdayrs.apps.shosetsu.adapters.novel.SlidingNovelPageAdapter; +import com.github.Doomsdayrs.apps.shosetsu.async.NovelLoader; import com.github.Doomsdayrs.apps.shosetsu.settings.SettingsController; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; /** * This file is part of Shosetsu. @@ -47,12 +46,13 @@ public class NovelFragment extends Fragment { public FragmentManager fragmentManager = null; public Formatter formatter; public String url; - NovelPage novelPage; + public NovelPage novelPage; SlidingNovelPageAdapter pagerAdapter; - NovelFragmentMain novelFragmentMain; - NovelFragmentChapters novelFragmentChapters; - NovelFragmentTracking novelFragmentTracking; + public NovelFragmentMain novelFragmentMain; + public NovelFragmentChapters novelFragmentChapters; + public NovelFragmentTracking novelFragmentTracking; ViewPager viewPager; + public ProgressBar progressBar; public NovelFragment() { @@ -68,31 +68,24 @@ public void onSaveInstanceState(@NonNull Bundle outState) { outState.putSerializable("page", novelPage); } - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Log.d("OnCreate", "NovelFragment ###"); view = inflater.inflate(R.layout.fragment_novel, container, false); + progressBar = view.findViewById(R.id.fragment_novel_progress); novelFragmentMain = new NovelFragmentMain(); novelFragmentChapters = new NovelFragmentChapters(); //TODO FINISH TRACKING //boolean track = SettingsController.isTrackingEnabled(); if (savedInstanceState == null) { - if (SettingsController.isOnline()){ - try { - boolean a = new fillData(this).execute().get(); - if (a) - setViewPager(); - else System.exit(1); - } catch (ExecutionException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - }else { + if (SettingsController.isOnline()) { + setViewPager(); + new NovelLoader(this).execute(getActivity()); + } else { + //TODO, Offline data loading } } else { url = savedInstanceState.getString("imageURL"); @@ -115,12 +108,13 @@ void setViewPager() { // Sets the data { novelFragmentChapters.setFormatter(formatter); - novelFragmentChapters.novelTitle = novelPage.title; + novelFragmentChapters.novelPage = novelPage; novelFragmentChapters.setNovelURL(url); novelFragmentChapters.setFragmentManager(fragmentManager); novelFragmentMain.url = url; novelFragmentMain.formatter = formatter; + novelFragmentMain.novelFragmentChapters = novelFragmentChapters; } // Add the fragments { @@ -134,24 +128,4 @@ void setViewPager() { viewPager.setAdapter(pagerAdapter); } - static class fillData extends AsyncTask { - NovelFragment novelFragment; - - fillData(NovelFragment novelFragment) { - this.novelFragment = novelFragment; - } - - @Override - protected Boolean doInBackground(Void... voids) { - try { - novelFragment.novelPage = novelFragment.formatter.parseNovel(novelFragment.url); - novelFragment.novelFragmentMain.novelPage = novelFragment.novelPage; - Log.d("Loaded Novel:", novelFragment.novelPage.title); - return true; - } catch (IOException e) { - e.printStackTrace(); - } - return false; - } - } } diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentChapters.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentChapters.java index bd121b4815..69fed44abd 100644 --- a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentChapters.java +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentChapters.java @@ -1,7 +1,6 @@ package com.github.Doomsdayrs.apps.shosetsu.fragment.novel; import android.content.Context; -import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -16,6 +15,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.ProgressBar; import com.github.Doomsdayrs.api.novelreader_core.main.DefaultScrapers; import com.github.Doomsdayrs.api.novelreader_core.services.core.dep.Formatter; @@ -23,12 +23,12 @@ import com.github.Doomsdayrs.api.novelreader_core.services.core.objects.NovelPage; import com.github.Doomsdayrs.apps.shosetsu.R; import com.github.Doomsdayrs.apps.shosetsu.adapters.novel.NovelChaptersAdapter; +import com.github.Doomsdayrs.apps.shosetsu.async.NovelChaptersLoader; -import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.ExecutionException; /** * This file is part of Shosetsu. @@ -49,16 +49,17 @@ * @author github.com/doomsdayrs */ public class NovelFragmentChapters extends Fragment { - public static List novelChapters; + public static List novelChapters = new ArrayList<>(); public boolean reversed; public RecyclerView recyclerView; public int currentMaxPage = 1; - private Formatter formatter; - public String novelTitle; + public Formatter formatter; + public NovelPage novelPage; public String novelURL; private FragmentManager fragmentManager; public NovelChaptersAdapter adapter; private Context context; + public ProgressBar progressBar; public NovelFragmentChapters() { setHasOptionsMenu(true); @@ -90,12 +91,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c Log.d("OnCreate", "NovelFragmentChapters"); View view = inflater.inflate(R.layout.fragment_novel_chapters, container, false); recyclerView = view.findViewById(R.id.fragment_novel_chapters_recycler); + progressBar = view.findViewById(R.id.fragment_novel_chapters_progress); if (savedInstanceState != null) { novelURL = savedInstanceState.getString("imageURL"); formatter = DefaultScrapers.formatters.get(savedInstanceState.getInt("formatter") - 1); currentMaxPage = savedInstanceState.getInt("maxPage"); } - setNovels(novelChapters); this.context = Objects.requireNonNull(container).getContext(); Log.d("OnCreate", "Complete"); @@ -127,42 +128,13 @@ static class onFilter implements MenuItem.OnMenuItemClickListener { @Override public boolean onMenuItemClick(MenuItem item) { - Collections.reverse(novelChapters); + Collections.reverse(novelFragmentChapters.novelChapters); novelFragmentChapters.reversed = true; return novelFragmentChapters.recyclerView.post(() -> novelFragmentChapters.adapter.notifyDataSetChanged()); } } - static class addMore extends AsyncTask { - NovelFragmentChapters novelFragmentChapters; - - addMore(NovelFragmentChapters novelFragmentChapters) { - this.novelFragmentChapters = novelFragmentChapters; - } - - @Override - protected Boolean doInBackground(Integer... integers) { - if (novelFragmentChapters.formatter.isIncrementingChapterList()) - try { - NovelPage novelPage; - if (integers.length == 0) - novelPage = novelFragmentChapters.formatter.parseNovel(novelFragmentChapters.novelURL); - else - novelPage = novelFragmentChapters.formatter.parseNovel(novelFragmentChapters.novelURL, integers[0]); - //TODO Difference calculation - - if (!novelPage.novelChapters.get(novelPage.novelChapters.size() - 1).link - .equals(novelChapters.get(novelChapters.size() - 1).link)) - novelChapters.addAll(novelPage.novelChapters); - return true; - } catch (IOException e) { - e.printStackTrace(); - } - return false; - } - } - static class bottom extends RecyclerView.OnScrollListener { NovelFragmentChapters novelFragmentChapters; boolean running = false; @@ -178,21 +150,14 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (!novelFragmentChapters.recyclerView.canScrollVertically(1)) { Log.d("ScrollLoad", "Loading..."); if (novelFragmentChapters.reversed) - Collections.reverse(novelChapters); + Collections.reverse(novelFragmentChapters.novelChapters); running = true; novelFragmentChapters.currentMaxPage++; - try { - if (new addMore(novelFragmentChapters).execute(novelFragmentChapters.currentMaxPage).get()) - novelFragmentChapters.recyclerView.post(() -> novelFragmentChapters.adapter.notifyDataSetChanged()); - } catch (ExecutionException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + new NovelChaptersLoader(novelFragmentChapters).execute(novelFragmentChapters.currentMaxPage); Log.d("ScrollLoad", "Completed."); running = false; if (novelFragmentChapters.reversed) - Collections.reverse(novelChapters); + Collections.reverse(novelFragmentChapters.novelChapters); } } } diff --git a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentMain.java b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentMain.java index 0547060c45..1a265e8340 100644 --- a/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentMain.java +++ b/app/src/main/java/com/github/Doomsdayrs/apps/shosetsu/fragment/novel/NovelFragmentMain.java @@ -48,12 +48,14 @@ public class NovelFragmentMain extends Fragment { public Formatter formatter; public String url; - NovelPage novelPage; + public NovelPage novelPage; ImageView imageView; TextView title; TextView author; TextView description; - FloatingActionButton floatingActionButton; + TextView formatterName; + public FloatingActionButton floatingActionButton; + public NovelFragmentChapters novelFragmentChapters; boolean inLibrary = false; @@ -84,10 +86,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c title = view.findViewById(R.id.fragment_novel_title); author = view.findViewById(R.id.fragment_novel_author); description = view.findViewById(R.id.fragment_novel_description); + formatterName = view.findViewById(R.id.fragment_novel_formatter); floatingActionButton = view.findViewById(R.id.fragment_novel_add); floatingActionButton.setOnClickListener(new addToLibrary(this)); } - + floatingActionButton.hide(); if (savedInstanceState != null) { url = savedInstanceState.getString("imageURL"); @@ -95,25 +98,30 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c novelPage = (NovelPage) savedInstanceState.getSerializable("page"); } + if (Database.inLibrary(url)) inLibary(); if (inLibrary) floatingActionButton.setImageResource(R.drawable.ic_add_circle_black_24dp); - { - if (novelPage == null) - System.exit(1); - title.setText(novelPage.title); - author.setText(Arrays.toString(novelPage.authors)); - description.setText(novelPage.description); - NovelFragmentChapters.novelChapters = novelPage.novelChapters; - } + if (novelPage != null) + setData(); + + Log.d("OnCreate", "NovelFragmentMain Complete"); + return view; + } + + public void setData() { + title.setText(novelPage.title); + author.setText(Arrays.toString(novelPage.authors)); + description.setText(novelPage.description); + NovelFragmentChapters.novelChapters = novelPage.novelChapters; Picasso.get() .load(novelPage.imageURL) .into(imageView); - Log.d("OnCreate", "NovelFragmentMain Complete"); - return view; + floatingActionButton.show(); + formatterName.setText(formatter.getName()); } static class addToLibrary implements FloatingActionButton.OnClickListener { diff --git a/app/src/main/res/layout-land/fragment_novel_main.xml b/app/src/main/res/layout-land/fragment_novel_main.xml index 6bd8b5d344..8800873568 100644 --- a/app/src/main/res/layout-land/fragment_novel_main.xml +++ b/app/src/main/res/layout-land/fragment_novel_main.xml @@ -35,18 +35,24 @@ + + - + + + android:id="@+id/gridLayout" + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:scrollbars="vertical" + app:layout_column="1" + app:layout_row="0" /> - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_novel.xml b/app/src/main/res/layout/fragment_novel.xml index b9f3ab41f2..b9c78b6351 100644 --- a/app/src/main/res/layout/fragment_novel.xml +++ b/app/src/main/res/layout/fragment_novel.xml @@ -1,13 +1,28 @@ + + + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_novel_chapters.xml b/app/src/main/res/layout/fragment_novel_chapters.xml index b9954e8559..ee9cdbfdd7 100644 --- a/app/src/main/res/layout/fragment_novel_chapters.xml +++ b/app/src/main/res/layout/fragment_novel_chapters.xml @@ -1,11 +1,41 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> - - \ No newline at end of file + android:layout_height="match_parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_novel_main.xml b/app/src/main/res/layout/fragment_novel_main.xml index 98cecaa5ca..2b277ab22d 100644 --- a/app/src/main/res/layout/fragment_novel_main.xml +++ b/app/src/main/res/layout/fragment_novel_main.xml @@ -1,7 +1,6 @@ @@ -28,8 +27,6 @@ android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" - android:layout_marginBottom="8dp" - app:layout_constraintBottom_toTopOf="@+id/fragment_novel_author" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/fragment_novel_image" app:layout_constraintTop_toTopOf="parent" /> @@ -46,6 +43,17 @@ app:layout_constraintStart_toEndOf="@+id/fragment_novel_image" app:layout_constraintTop_toBottomOf="@+id/fragment_novel_title" /> + + - \ No newline at end of file diff --git a/app/src/main/res/layout/include_progress_overlay.xml b/app/src/main/res/layout/include_progress_overlay.xml deleted file mode 100644 index 8060c7f33a..0000000000 --- a/app/src/main/res/layout/include_progress_overlay.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - \ No newline at end of file