Android Open Source - EnklawaPlayer Enklawa Base Abstract List Fragment






From Project

Back to project page EnklawaPlayer.

License

The source code is released under:

GNU General Public License

If you think the Android project EnklawaPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package macbury.pod.fragments.main;
/*from  w w  w .  jav  a2s.co  m*/
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;

import macbury.pod.R;
import macbury.pod.db.models.EpisodeFile;
import macbury.pod.managers.App;
import macbury.pod.managers.IntentManager;
import macbury.pod.services.SyncPodService;

/**
 * Created by macbury on 12.09.14.
 */
public abstract class EnklawaBaseAbstractListFragment extends Fragment implements AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
  protected App app;
  protected ListView listView;
  private SwipeRefreshLayout swipeRefreshLayout;
  private BaseAdapter currentAdapter;

  public EnklawaBaseAbstractListFragment() {
    app = App.current();
  }

  private BroadcastReceiver syncRefreshReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      onSyncPodUpdate();
      swipeRefreshLayout.setRefreshing(SyncPodService.isRunning());
    }
  };

  private BroadcastReceiver downloadRefreshReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      int eid        = intent.getIntExtra(IntentManager.EXTRA_EPISODE_FILE_ID, -1);
      EpisodeFile ep = App.current().db.episodeFiles.find(eid);
      onDownloadUpdate(intent.getIntExtra(IntentManager.EXTRA_PROGRESS, 0), ep);
    }
  };

  protected abstract void onSyncPodUpdate();
  protected abstract void onDownloadUpdate(int progress, EpisodeFile file);

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_list_view_with_swipe_to_refresh, null);
    swipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipe_container);
    listView           = (ListView)view.findViewById(R.id.list_view);
    listView.setOnItemClickListener(this);
    view.setBackgroundColor(Color.WHITE);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.progress_color_1, R.color.progress_color_3, R.color.progress_color_4, R.color.progress_color_5);
    return view;
  }

  @Override
  public void onResume() {
    listView.setAdapter(currentAdapter);
    super.onResume();
    swipeRefreshLayout.setRefreshing(SyncPodService.isRunning());
    app.broadcasts.podSyncReceiver(this.getActivity(), syncRefreshReceiver);
    app.broadcasts.downloadReceiver(this.getActivity(), downloadRefreshReceiver);
    onSyncPodUpdate();
  }

  @Override
  public void onPause() {
    super.onPause();
    getActivity().unregisterReceiver(syncRefreshReceiver);
    getActivity().unregisterReceiver(downloadRefreshReceiver);
  }

  public void setListAdapter(BaseAdapter adapter) {
    currentAdapter = adapter;
    if (listView != null)
      listView.setAdapter(adapter);
  }


  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    onListItemClick(listView, view, position, id);
  }

  protected void onListItemClick(ListView listView, View view, int position, long id) {

  }

  @Override
  public void onRefresh() {
    App.current().services.syncPodService();
  }
}




Java Source Code List

macbury.pod.ApplicationTest.java
macbury.pod.activities.DonateActivity.java
macbury.pod.activities.ProgramEpisodesActivity.java
macbury.pod.activities.SettingsActivity.java
macbury.pod.activities.ext.AccentFragmentActivity.java
macbury.pod.activities.main.MainActivityActionBarToggle.java
macbury.pod.activities.main.MainActivity.java
macbury.pod.activities.main.NavigationController.java
macbury.pod.activities.main.NavigationListener.java
macbury.pod.activities.player.PlayerActivity.java
macbury.pod.activities.player.RadioActivity.java
macbury.pod.adapters.EpisodesAdapterListener.java
macbury.pod.adapters.EpisodesAdapter.java
macbury.pod.adapters.ProgramsAdapter.java
macbury.pod.api.APICategory.java
macbury.pod.api.APIEpisode.java
macbury.pod.api.APIProgram.java
macbury.pod.api.APIResponse.java
macbury.pod.api.APIThread.java
macbury.pod.db.DatabaseCRUDListener.java
macbury.pod.db.models.EnqueueEpisode.java
macbury.pod.db.models.EpisodeFile.java
macbury.pod.db.models.Episode.java
macbury.pod.db.models.ForumThread.java
macbury.pod.db.models.Program.java
macbury.pod.db.scopes.AbstractScope.java
macbury.pod.db.scopes.EnqueueEpisodeScope.java
macbury.pod.db.scopes.EpisodeFilesScope.java
macbury.pod.db.scopes.EpisodesScope.java
macbury.pod.db.scopes.ProgramsScope.java
macbury.pod.db.scopes.ThreadScope.java
macbury.pod.dialogs.EpisodeAboutDialog.java
macbury.pod.dialogs.ProgramAboutDialog.java
macbury.pod.extensions.Converter.java
macbury.pod.extensions.DateDeserializer.java
macbury.pod.extensions.SleepTimer.java
macbury.pod.fragments.SettingsFragment.java
macbury.pod.fragments.main.AbstractEpisodesFragment.java
macbury.pod.fragments.main.AllProgramsFragment.java
macbury.pod.fragments.main.EnklawaBaseAbstractListFragment.java
macbury.pod.fragments.main.episodes.DownloadedEpisodesFragment.java
macbury.pod.fragments.main.episodes.NewestEpisodesFragment.java
macbury.pod.fragments.main.episodes.PlaylistFragment.java
macbury.pod.fragments.main.episodes.ProgramEpisodesFragment.java
macbury.pod.fragments.player.ExternalPlayerFragment.java
macbury.pod.fragments.player.PlayerArtworkAndInfoFragment.java
macbury.pod.fragments.player.PlayerControllerFragment.java
macbury.pod.managers.AlarmsManager.java
macbury.pod.managers.App.java
macbury.pod.managers.BroadcastsManager.java
macbury.pod.managers.DatabaseManager.java
macbury.pod.managers.IntentManager.java
macbury.pod.managers.NotificationsManager.java
macbury.pod.managers.ServiceManager.java
macbury.pod.managers.SettingsManager.java
macbury.pod.managers.StorageManager.java
macbury.pod.managers.download.DownloadEpisode.java
macbury.pod.managers.download.DownloadManagerListener.java
macbury.pod.managers.download.DownloadManager.java
macbury.pod.managers.player.PlaybackStatus.java
macbury.pod.managers.player.PlayerManagerListener.java
macbury.pod.managers.player.PlayerManager.java
macbury.pod.managers.player.sources.AbstractMediaSource.java
macbury.pod.managers.player.sources.EpisodeMediaSource.java
macbury.pod.managers.player.sources.RadioMediaSource.java
macbury.pod.navigation_drawer.NavAdapter.java
macbury.pod.navigation_drawer.NavBaseItem.java
macbury.pod.navigation_drawer.NavDivider.java
macbury.pod.navigation_drawer.items.AllProgramsNavItem.java
macbury.pod.navigation_drawer.items.DownloadedEpisodesNavItem.java
macbury.pod.navigation_drawer.items.FavoriteProgramNavItem.java
macbury.pod.navigation_drawer.items.ForumNavItem.java
macbury.pod.navigation_drawer.items.NavItemFragment.java
macbury.pod.navigation_drawer.items.NewestEpisodesNavItem.java
macbury.pod.navigation_drawer.items.PlayQueueNavItem.java
macbury.pod.receivers.BootReceiver.java
macbury.pod.receivers.MediaButtonReceiver.java
macbury.pod.services.DownloadService.java
macbury.pod.services.PlayerService.java
macbury.pod.services.SyncPodService.java
macbury.pod.tutorial.MainActivityTutorial.java
macbury.pod.views.TappableFrameLayout.java