package hh.dejsem.fm;

import android.os.AsyncTask;
import android.widget.RelativeLayout;

import hh.dejsem.K;
import hh.dejsem.SendUriNG;
import hh.dejsem.net.PullFromServer;
import hh.dejsem.net.SrvCmd;
import hh.lib.D;

/**
 * panel with remote directory list
 */
class PanelServerDir extends PanelDirView {

	PanelServerDir(D d, RelativeLayout layout, String dirViewLabel, String newWorkDirName) {
		super(d);
		dirView = new DirListView(this, layout, dirViewLabel, K.SRV_FS);
		fm = new FMServer(d);
		fm.enterDir(newWorkDirName);
		setUpDirView();
	}

	@Override
	void handOverServerCopy(NetTaskRef netTaskRef) {
		try { new PullFromServer(d, netTaskRef).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
		catch(Exception e) { d.abendMsg("copy from server", e); }
	}

	@Override
	void expose(String selection) throws Exception {
		String uriPath = (String)SrvCmd.EXPOSE.exec(d, selection);   // expose se nedávkuje, vyřizuje se jen 1.vybraný
		FragFM.sweepOutNetCmd(d);
		SendUriNG.decideSendUri(uriPath);
	}

	@Override
	void hide(String[] selection) throws Exception {
		for(String sel: selection) {
			SrvCmd.HIDE.exec(d, sel);
			if(d.ll(4)) d.l(sel + " hiden");
		}
		FragFM.sweepOutNetCmd(d);
	}
}
