Exemplo n.º 1
0
        @Override
        public void OnLibraryDownloadFinished(DownloaderResult result) {
          mProgressDialog.dismiss();
          App.libraryDownloader = null;

          if (result.getResult() == DownloadResult.SUCCESSFUL) {
            if (mLibrary != null) {
              mLibrary.closeDatabase();
            }
            mLibrary = new MyLibrary(getActivity());
            mLibrary.openDatabase();
            LibraryAdapter a =
                new LibraryAdapter(
                    getActivity(), mLibrary.getArtists(), mLibrary, MyLibrary.LVL_ARTIST);
            mAdapters.add(a);
            showList();
          } else {
            Utilities.ShowMessageDialog(
                getActivity(), R.string.library_download_error, result.getMessageId());
          }
        }
Exemplo n.º 2
0
  @SuppressLint({"InlinedApi", "NewApi"})
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.library_fragment, container, false);

    Log.d(TAG, "onCreateView");

    mLibraryPath = (TextView) view.findViewById(R.id.library_path);
    mList = (ListView) view.findViewById(R.id.library);
    mEmptyLibrary = view.findViewById(R.id.library_empty);

    mLibraryEmptyText = (TextView) mEmptyLibrary.findViewById(R.id.library_empty_txt);

    mList.setOnItemClickListener(oiclLibraryClick);
    mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setMultiChoiceModeListener(
        new MultiChoiceModeListener() {
          @Override
          public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) {
            SparseBooleanArray checkedPositions = mList.getCheckedItemPositions();

            switch (item.getItemId()) {
              case R.id.library_context_add:
                for (int i = 0; i < checkedPositions.size(); ++i) {
                  int position = checkedPositions.keyAt(i);
                  if (checkedPositions.valueAt(i)) {
                    MyLibraryItem libraryItem = mAdapters.getLast().getItem(position);
                    addSongsToPlaylist(libraryItem);
                  }
                }
                mode.finish();
                return true;
              default:
                return false;
            }
          }

          @Override
          public boolean onCreateActionMode(ActionMode mode, android.view.Menu menu) {
            android.view.MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.library_context_menu, menu);
            return true;
          }

          @Override
          public boolean onPrepareActionMode(ActionMode mode, android.view.Menu menu) {
            return false;
          }

          @Override
          public void onDestroyActionMode(ActionMode mode) {}

          @Override
          public void onItemCheckedStateChanged(
              ActionMode mode, int position, long id, boolean checked) {}
        });

    // Create the adapter
    mLibrary = new MyLibrary(getActivity());
    mLibrary.removeDatabaseIfFromOtherClementine();
    if (App.libraryDownloader == null && mLibrary.databaseExists()) {
      mLibrary.openDatabase();
      LibraryAdapter a =
          new LibraryAdapter(getActivity(), mLibrary.getArtists(), mLibrary, MyLibrary.LVL_ARTIST);
      mAdapters.add(a);
    }

    showList();

    mActionBar.setTitle("");
    mActionBar.setSubtitle("");

    setHasOptionsMenu(true);

    return view;
  }