From 6d18e80f4bfb40c7c8dee7ade9f19ef8c5a91c4f Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Sat, 17 Dec 2016 17:44:26 +0000 Subject: [PATCH] ZIM list updates once download is complete in Android #278 --- src/org/kiwix/kiwixmobile/ZimFileSelectFragment.java | 7 +++++++ src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java | 4 +++- src/org/kiwix/kiwixmobile/utils/files/FileSearch.java | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/org/kiwix/kiwixmobile/ZimFileSelectFragment.java b/src/org/kiwix/kiwixmobile/ZimFileSelectFragment.java index 7a19e25bf..99a0e66d9 100644 --- a/src/org/kiwix/kiwixmobile/ZimFileSelectFragment.java +++ b/src/org/kiwix/kiwixmobile/ZimFileSelectFragment.java @@ -77,6 +77,7 @@ import org.kiwix.kiwixmobile.library.LibraryAdapter; import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity; import org.kiwix.kiwixmobile.utils.LanguageUtils; import org.kiwix.kiwixmobile.utils.ShortcutUtils; +import org.kiwix.kiwixmobile.utils.files.FileReader; import org.kiwix.kiwixmobile.utils.files.FileSearch; import org.kiwix.kiwixmobile.utils.files.FileUtils; import org.kiwix.kiwixmobile.utils.files.FileWriter; @@ -143,6 +144,12 @@ public class ZimFileSelectFragment extends Fragment checkPermissions(); } + public void addBook(String path) { + mFiles.add(FileSearch.fileToBook(path)); + mRescanAdapter.notifyDataSetChanged(); + bookDao.saveBooks(mFiles); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FragmentActivity faActivity = (FragmentActivity) super.getActivity(); diff --git a/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java b/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java index 731c72dd6..8ec27d40c 100644 --- a/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java +++ b/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java @@ -121,9 +121,9 @@ public class DownloadFragment extends Fragment { if (progress == 100) { ImageView pause = (ImageView) viewGroup.findViewById(R.id.pause); pause.setEnabled(false); + String fileName = mDownloadFiles.get(mKeys[position]); { Snackbar completeSnack = Snackbar.make(mainLayout, getResources().getString(R.string.download_complete_snackbar), Snackbar.LENGTH_LONG); - String fileName = mDownloadFiles.get(mKeys[position]); completeSnack.setAction(getResources().getString(R.string.open), new View.OnClickListener() { @Override public void onClick(View v) { @@ -131,6 +131,8 @@ public class DownloadFragment extends Fragment { } }).setActionTextColor(getResources().getColor(R.color.white)).show(); } + ZimFileSelectFragment zimFileSelectFragment = (ZimFileSelectFragment) zimManageActivity.mSectionsPagerAdapter.getItem(0); + zimFileSelectFragment.addBook(fileName); mDownloads.remove(mKeys[position]); mDownloadFiles.remove(mKeys[position]); downloadAdapter.notifyDataSetChanged(); diff --git a/src/org/kiwix/kiwixmobile/utils/files/FileSearch.java b/src/org/kiwix/kiwixmobile/utils/files/FileSearch.java index 73f97fd0d..0a2ced70a 100644 --- a/src/org/kiwix/kiwixmobile/utils/files/FileSearch.java +++ b/src/org/kiwix/kiwixmobile/utils/files/FileSearch.java @@ -195,7 +195,7 @@ public class FileSearch { return files.toArray(arr); } - private synchronized LibraryNetworkEntity.Book fileToBook(String filePath) { + public static synchronized LibraryNetworkEntity.Book fileToBook(String filePath) { LibraryNetworkEntity.Book book = null; if (ZimContentProvider.zimFileName != null) {