package com.mogo.cloud.location.third.core;

import android.content.Context;
import android.content.Intent;

import com.mogo.cloud.location.third.service.UploadDataService;

public class LocUploadManager {

    private static volatile LocUploadManager mInstance;

    private LocUploadManager() {}

    public static LocUploadManager getInstance() {
        if (mInstance == null) {
            synchronized (LocUploadManager.class) {
                if (mInstance == null) {
                    mInstance = new LocUploadManager();
                }
            }
        }
        return mInstance;
    }

    public void startUpload() {
        LocationDelegateManager.getInstance().loadDelegates();
        startLocService(LocUploadConfig.instance().getContext());
    }

    public void stopUpload(){
        LocationDelegateManager.getInstance().unloadDelegates();
        stopLocService(LocUploadConfig.instance().getContext());
    }

    private void startLocService(Context context) {
        Intent intent = new Intent(context, UploadDataService.class);
        context.startService(intent);
    }

    private void stopLocService(Context context) {
        Intent intent = new Intent(context, UploadDataService.class);
        context.stopService(intent);
    }
}
