package com.platypii.baseline.tracks;

import com.platypii.baseline.R;
import com.platypii.baseline.events.SyncEvent;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;

public class TrackListFragment extends ListFragment implements AdapterView.OnItemClickListener {

    private List<TrackFile> trackList;
    private TrackAdapter listAdapter;

    private View tracksEmptyLabel;

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.track_list, container, false);
        tracksEmptyLabel = view.findViewById(R.id.tracks_empty);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // Initialize the ListAdapter
        trackList = new ArrayList<>();
        listAdapter = new TrackAdapter(this.getActivity(), trackList);
        setListAdapter(listAdapter);
        getListView().setOnItemClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();

        // Update the ListAdapter
        trackList.clear();
        trackList.addAll(TrackFiles.getTracks(this.getActivity()));
        listAdapter.notifyDataSetChanged();

        // Handle no-tracks case
        if(listAdapter.isEmpty()) {
            tracksEmptyLabel.setVisibility(View.VISIBLE);
        } else {
            tracksEmptyLabel.setVisibility(View.GONE);
        }

        // Listen for sync updates
        EventBus.getDefault().register(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        listAdapter.clickItem(position, getActivity());
    }
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
    }

    @Override
    public void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSyncEvent(SyncEvent event) {
        // Update sync status in the list
        listAdapter.notifyDataSetChanged();
    }

}

@@ -1289,21 +1289,16 @@
 Adapter(
-this.
 getActiv
@@ -1500,35 +1500,212 @@
  Update the 
-ListAdapter
+views%0A        updateList();%0A%0A        // Listen for sync updates%0A        EventBus.getDefault().register(this);%0A    %7D%0A%0A    private void updateList() %7B%0A        // Update list from track cache
 %0A        tra
@@ -1770,13 +1770,8 @@
 cks(
-this.
 getA
@@ -2040,90 +2040,8 @@
    %7D
-%0A%0A        // Listen for sync updates%0A        EventBus.getDefault().register(this);
 %0A   
@@ -2531,82 +2531,18 @@
     
-// U
+u
 pdate
- sync status in the list%0A        listAdapter.notifyDataSetChanged
+List
 ();%0A

Fix "no tracks" label