UniRegensburg / unsere-app-fur-die-universitat-regensburg-bib-buddy

Bib Buddy - deine App für eine konzentrierte, offene Literaturarbeit!
0 stars 0 forks source link

Library Export (BibTex) #105

Closed silvia-ivanova-github-rep closed 3 years ago

silvia-ivanova-github-rep commented 3 years ago

Description Closes #19 and #103. Export of all data (all books and notes from all shelves) in the personal library as a BibTex file.

Affects Mainly Library Fragment and the export of all data in the library.

Notes for Reviewer Go to Library fragment and select the export function from the menu on the top right corner. The exported .bib file can be found in the "Download" folder of your physical device/emulator. A toast with the path is also shown. Please review & comment/approve.

claudia3 commented 3 years ago

private String retrieveBibContent() in LibraryFragment, BookFragment. Please decompose this function into smaller ones and change it according to the suggestions. It is hard to read the code because it has a lot of nested for or ifs and is about 80 lines long. Also its better create a new class for the exports. Because this function to create a BibTeX String looks nearly identical in both fragments.

claudia3 commented 3 years ago

Also do we export the "Untertitel" and "Band" of a book?

silvia-ivanova-github-rep commented 3 years ago

Also do we export the "Untertitel" and "Band" of a book?

No, I will add them. Thanks

silvia-ivanova-github-rep commented 3 years ago

Please remove duplicate code (I didn't mark everything) and change the code according to the suggestions. Also after each comment please leave an empty space.

I added a new class ExportBibTex which includes methods that can be used in more than one class. Since you suggested using LibraryModel class for LibraryFragment class and BookModel class for BookFragment class, there are specific references in those classes that cannot be generalized in the ExportBibTex class.

For example, the following code from LibraryFragment class uses libraryModel from the LibraryModel class, which I do not use/ need in the BookFragment class. Example:

  private String retrieveBibContentShelf() {
    List<ShelfItem> shelfItem = new ArrayList<>();
    shelfItem = libraryModel.getCurrentLibraryList();
    String bibLibraryContent = "";
...

The methods for the permissions are also specific for the current class. The following code from the class LibraryFragment also uses methods from the ExportBibTex class that generate specific BibTex content for the LibraryFragment. In BookFragment there is another specific content that is stored in the BibTex file.

  private void checkStoragePermission() {
    if (ContextCompat.checkSelfPermission(getContext(),
        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
      requestStoragePermission();
    } else {
      // if the user has already allowed access to device external storage
      exportBibTex.createBibFile();
      exportBibTex.writeBibFile(retrieveBibContentShelf());

      Toast.makeText(getContext(),
          getString(R.string.exported_file_stored_in) + '\n'
              + File.separator + folderName + File.separator + fileName
              + fileTypeBibToast, Toast.LENGTH_LONG).show();
    }
  }

I can generalize the Alert Dialogs in a new class but I am not sure if this is appropriate at the moment.