package com.xplora.xpsettings.Observer;

import android.content.ContentUris;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.xplora.xpsettings.Utils.Constant;

public class RingtonesContentObserver extends ContentObserver {
    public String TAG = "losion / xpsettings :" + getClass().getSimpleName();
    private static Handler mHandler = null;

    public RingtonesContentObserver(Handler handler) {
        super(handler);
        mHandler = handler;
    }

    @Override
    public void onChange(boolean selfChange, Uri uri) {
        Log.d(TAG, "onChange :" + uri);
        super.onChange(selfChange, uri);

        if (uri == null)
            return;
        long value = ContentUris.parseId(uri);
        int primaryKey = Integer.parseInt(String.valueOf(value));

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Message msg = new Message();
                msg.what = Constant.MSG_DB_OBSERVER_RINGTONE;
                msg.arg1 = primaryKey;
                mHandler.sendMessage(msg);
            }
        }, 10);
    }
}
