package com.marverenic.music.activity.instance;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.marverenic.music.JockeyApplication;
import com.marverenic.music.R;
import com.marverenic.music.activity.BaseActivity;
import com.marverenic.music.data.store.MusicStore;
import com.marverenic.music.instances.Album;
import com.marverenic.music.instances.Song;
import com.marverenic.music.instances.section.LibraryEmptyState;
import com.marverenic.music.instances.section.SongSection;
import com.marverenic.music.utils.Themes;
import com.marverenic.music.view.BackgroundDecoration;
import com.marverenic.music.view.DividerDecoration;
import com.marverenic.music.view.EnhancedAdapters.HeterogeneousAdapter;

import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

public class AlbumActivity extends BaseActivity {

    public static final String ALBUM_EXTRA = "album";

    @Inject MusicStore mMusicStore;

    private HeterogeneousAdapter mAdapter;
    private SongSection mSongSection;
    private List<Song> mSongs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_instance_artwork);
        JockeyApplication.getComponent(this).inject(this);

        Album reference = getIntent().getParcelableExtra(ALBUM_EXTRA);

        if (reference != null) {
            mMusicStore.getSongs(reference)
                    .compose(bindToLifecycle())
                    .subscribe(
                            songs -> {
                                mSongs = songs;
                                setupAdapter();
                            });

            if (getSupportActionBar() != null) {
                getSupportActionBar().setTitle(reference.getAlbumName());
            }

            Glide.with(this).load(reference.getArtUri())
                    .centerCrop()
                    .into((ImageView) findViewById(R.id.backdrop));
        } else {
            mSongs = Collections.emptyList();
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

        mAdapter = new HeterogeneousAdapter();
        setupAdapter();
        mAdapter.setEmptyState(new LibraryEmptyState(this, mMusicStore) {
                    @Override
                    public String getEmptyMessage() {
                        if (reference == null) {
                            return getString(R.string.empty_error_album);
                        } else {
                            return super.getEmptyMessage();
                        }
                    }

                    @Override
                    public String getEmptyMessageDetail() {
                        if (reference == null) {
                            return "";
                        } else {
                            return super.getEmptyMessageDetail();
                        }
                    }

                    @Override
                    public String getEmptyAction1Label() {
                        return "";
                    }
                });

        RecyclerView list = (RecyclerView) findViewById(R.id.list);
        list.setAdapter(mAdapter);
        list.addItemDecoration(new BackgroundDecoration(Themes.getBackgroundElevated()));
        list.addItemDecoration(new DividerDecoration(this, R.id.empty_layout));

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        list.setLayoutManager(layoutManager);
    }

    private void setupAdapter() {
        if (mAdapter == null || mSongs == null) {
            return;
        }

        if (mSongSection != null) {
            mSongSection.setData(mSongs);
            mAdapter.notifyDataSetChanged();
        } else {
            mSongSection = new SongSection(mSongs);
            mAdapter.addSection(mSongSection);
        }
    }
}

@@ -2725,32 +2725,24 @@
             
-        
 @Override%0A  
@@ -2735,32 +2735,24 @@
   @Override%0A
-        
             
@@ -2797,32 +2797,24 @@
             
-     
-   
 if (referenc
@@ -2822,32 +2822,24 @@
  == null) %7B%0A
-        
             
@@ -2904,32 +2904,24 @@
             
-        
 %7D else %7B%0A   
@@ -2933,32 +2933,24 @@
             
-  
-      
 return super
@@ -2985,33 +2985,18 @@
         
-        %7D%0A       
+%7D%0A
         
@@ -2995,36 +2995,27 @@
             
- 
 %7D%0A%0A
-        
             
@@ -3020,32 +3020,24 @@
   @Override%0A
-        
             
@@ -3088,32 +3088,24 @@
             
-    
-    
 if (referenc
@@ -3133,32 +3133,24 @@
             
-       
- 
 return %22%22;%0A 
@@ -3160,32 +3160,24 @@
             
-        
 %7D else %7B%0A   
@@ -3189,32 +3189,24 @@
             
- 
-       
 return super
@@ -3247,32 +3247,18 @@
         
-        %7D%0A      
+%7D%0A
         
@@ -3257,37 +3257,27 @@
             
-  
 %7D%0A%0A
-        
             
@@ -3282,32 +3282,24 @@
   @Override%0A
-        
             
@@ -3349,32 +3349,24 @@
             
-   
-     
 return %22%22;%0A 
@@ -3376,34 +3376,18 @@
         
-        %7D%0A        
+%7D%0A
         

Fix incorrect indentation