Search in sources :

Example 1 with StreamService

use of com.sdsmdg.harjot.MusicDNA.interfaces.StreamService in project MusicDNA by harjot-oberai.

the class HomeActivity method updateStreamingList.

private void updateStreamingList(String query) {
    if (!isLocalVisible) {
        mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if ((settings.isStreamOnlyOnWifiEnabled() && mWifi.isConnected()) || (!settings.isStreamOnlyOnWifiEnabled())) {
            new Thread(new CancelCall()).start();
            if (!query.equals("")) {
                streamRecyclerContainer.setVisibility(View.VISIBLE);
                startLoadingIndicator();
                Retrofit client = new Retrofit.Builder().baseUrl(Config.API_URL).addConverterFactory(GsonConverterFactory.create()).build();
                StreamService ss = client.create(StreamService.class);
                call = ss.getTracks(query, 75);
                call.enqueue(new Callback<List<Track>>() {

                    @Override
                    public void onResponse(Call<List<Track>> call, Response<List<Track>> response) {
                        if (response.isSuccessful()) {
                            streamingTrackList = response.body();
                            sAdapter = new StreamTracksHorizontalAdapter(streamingTrackList, ctx);
                            LinearLayoutManager mLayoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
                            soundcloudRecyclerView.setLayoutManager(mLayoutManager);
                            soundcloudRecyclerView.setItemAnimator(new DefaultItemAnimator());
                            soundcloudRecyclerView.setAdapter(sAdapter);
                            if (streamingTrackList.size() == 0) {
                                streamRecyclerContainer.setVisibility(GONE);
                            } else {
                                streamRecyclerContainer.setVisibility(View.VISIBLE);
                            }
                            stopLoadingIndicator();
                            (soundcloudRecyclerView.getAdapter()).notifyDataSetChanged();
                            StreamMusicFragment sFrag = (StreamMusicFragment) fragMan.findFragmentByTag("stream");
                            if (sFrag != null) {
                                sFrag.dataChanged();
                            }
                        } else {
                            stopLoadingIndicator();
                        }
                        Log.d("RETRO", response.body() + "");
                    }

                    @Override
                    public void onFailure(Call<List<Track>> call, Throwable t) {
                        Log.d("RETRO1", t.getMessage());
                    }
                });
            } else {
                stopLoadingIndicator();
                streamRecyclerContainer.setVisibility(GONE);
            }
        } else {
            stopLoadingIndicator();
            streamRecyclerContainer.setVisibility(GONE);
        }
    }
}
Also used : StreamService(com.sdsmdg.harjot.MusicDNA.interfaces.StreamService) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) StreamTracksHorizontalAdapter(com.sdsmdg.harjot.MusicDNA.adapters.horizontalrecycleradapters.StreamTracksHorizontalAdapter) StreamMusicFragment(com.sdsmdg.harjot.MusicDNA.fragments.StreamFragment.StreamMusicFragment) Retrofit(retrofit2.Retrofit) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ColorStateList (android.content.res.ColorStateList)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 StreamTracksHorizontalAdapter (com.sdsmdg.harjot.MusicDNA.adapters.horizontalrecycleradapters.StreamTracksHorizontalAdapter)1 StreamMusicFragment (com.sdsmdg.harjot.MusicDNA.fragments.StreamFragment.StreamMusicFragment)1 StreamService (com.sdsmdg.harjot.MusicDNA.interfaces.StreamService)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Retrofit (retrofit2.Retrofit)1