package com.fyx.yunpan.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.fyx.yunpan.parse.entity.AlterFileEntity;
import com.fyx.yunpan.parse.entity.AlterFolderEntity;
import com.fyx.yunpan.parse.entity.FileDataFatherEntity;
import com.fyx.yunpan.ui.fragment.FileListFragment;

public class RenameRun implements Runnable {
	private String name;
	private int id;
	private FileListFragment context;
	private int t;
	private Handler handler = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				context.refresh();
				ToastUtils.toast(context.getActivity(), "修改成功");
				break;

			case -1:
				ToastUtils.toast(context.getActivity(), "修改失败");
				break;
			}
		}
	};;
	private FileDataFatherEntity fileLocalFile;

	public RenameRun(int type, final FileListFragment  context, int id, String name,
			Handler handler, FileDataFatherEntity file) {
		this.fileLocalFile = file;
		this.t = type;
		this.context = context;
		this.id = id;
		this.name = name;

	}

	@Override
	public void run() {
		if (t == 1) {
			
			AlterFileEntity file = AlterFile.down(context.getActivity(), id, name, null);
			if(file!=null){
				
				//ToastUtils.toast(context.getActivity(), "修改成功");
				handler.sendEmptyMessage(1);
			}else {
				//ToastUtils.toast(context.getActivity(), "修改失败");
				handler.sendEmptyMessage(-1);
			}
		} else if (t == 2) {
			
			AlterFolderEntity entity = AlterFolder
					.down(context.getActivity(), id, name, null);
				if(entity!=null){
				//	ToastUtils.toast(context.getActivity(), "修改成功");
					handler.sendEmptyMessage(1);
			}else {
				//ToastUtils.toast(context.getActivity(), "修改失败");
				handler.sendEmptyMessage(-1);
			}
		}

	}

}
