package com.marverenic.music.ui.nowplaying;

import android.content.Context;
import android.databinding.Bindable;
import android.databinding.ObservableField;
import android.databinding.ObservableInt;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.view.View;

import com.marverenic.music.BR;
import com.marverenic.music.R;
import com.marverenic.music.model.Song;
import com.marverenic.music.player.PlayerController;
import com.marverenic.music.ui.BaseViewModel;

public class MiniplayerViewModel extends BaseViewModel {

    private PlayerController mPlayerController;

    @Nullable
    private Song mSong;
    private boolean mPlaying;

    private final ObservableField<Bitmap> mArtwork;
    private final ObservableInt mDuration;
    private final ObservableInt mProgress;

    public MiniplayerViewModel(Context context, PlayerController playerController) {
        super(context);
        mPlayerController = playerController;

        mArtwork = new ObservableField<>();
        mProgress = new ObservableInt();
        mDuration = new ObservableInt();

        setSong(null);
    }

    public void setSong(@Nullable Song song) {
        mSong = song;
        notifyPropertyChanged(BR.songTitle);
        notifyPropertyChanged(BR.songArtist);
    }

    public void setPlaying(boolean playing) {
        mPlaying = playing;
        notifyPropertyChanged(BR.togglePlayIcon);
    }

    public void setCurrentPosition(int position) {
        mProgress.set(position);
    }

    public void setDuration(int duration) {
        mDuration.set(duration);
    }

    public void setArtwork(Bitmap artwork) {
        mArtwork.set(artwork);
    }

    @Bindable
    public String getSongTitle() {
        if (mSong == null) {
            return getString(R.string.nothing_playing);
        } else {
            return mSong.getSongName();
        }
    }

    @Bindable
    public String getSongArtist() {
        if (mSong == null) {
            return null;
        } else {
            return mSong.getArtistName();
        }
    }

    public ObservableInt getSongDuration() {
        return mDuration;
    }

    public ObservableField<Bitmap> getArtwork() {
        return mArtwork;
    }

    public ObservableInt getProgress() {
        return mProgress;
    }

    @Bindable
    public Drawable getTogglePlayIcon() {
        if (mPlaying) {
            return getDrawable(R.drawable.ic_pause_32dp);
        } else {
            return getDrawable(R.drawable.ic_play_arrow_32dp);
        }
    }

    public View.OnClickListener onClickTogglePlay() {
        return v -> mPlayerController.togglePlay();
    }

    public View.OnClickListener onClickSkip() {
        return v -> mPlayerController.skip();
    }

}

@@ -111,94 +111,8 @@
 le;%0A
-import android.databinding.ObservableField;%0Aimport android.databinding.ObservableInt;%0A
 impo
@@ -456,16 +456,43 @@
 Model;%0A%0A
+import timber.log.Timber;%0A%0A
 public c
@@ -675,37 +675,14 @@
 ate 
-final ObservableField%3C
 Bitmap
-%3E
  mAr
@@ -700,34 +700,18 @@
 private 
-f
 in
-al ObservableIn
 t mDurat
@@ -731,25 +731,9 @@
 ate 
-final ObservableI
+i
 nt m
@@ -903,135 +903,8 @@
 r;%0A%0A
-        mArtwork = new ObservableField%3C%3E();%0A        mProgress = new ObservableInt();%0A        mDuration = new ObservableInt();%0A%0A
     
@@ -1299,105 +1299,283 @@
 ress
-.set(position);%0A    %7D%0A%0A    public void setDuration(int duration) %7B%0A        mDuration.set(duration
+ = position;%0A        notifyPropertyChanged(BR.songDuration);%0A        notifyPropertyChanged(BR.progress);%0A    %7D%0A%0A    public void setDuration(int duration) %7B%0A        mDuration = duration;%0A        notifyPropertyChanged(BR.songDuration);%0A        notifyPropertyChanged(BR.progress
 );%0A 
@@ -1645,13 +1645,53 @@
 work
-.set(
+ = artwork;%0A        notifyPropertyChanged(BR.
 artw
@@ -2095,34 +2095,38 @@
  %7D%0A%0A    
-public ObservableI
+@Bindable%0A    public i
 nt getSo
@@ -2181,38 +2181,35 @@
     
-public ObservableField%3C
+@Bindable%0A    public 
 Bitmap
-%3E
  get
@@ -2260,26 +2260,30 @@
     
-public ObservableI
+@Bindable%0A    public i
 nt g

Fix seek progress not displaying on app launch