AskPresenter.java 2.94 KB
/*
 * Copyright (c) 2016 wugian
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xgimi.gimicinema.presenter;

import android.content.Context;
import android.util.Log;

import com.gimi.common.cinema.utils.ShellUtils;
import com.xgimi.gimicinema.BuildConfig;
import com.xgimi.gimicinema.model.IOtherModel;
import com.xgimi.gimicinema.model.ISambaModel;
import com.xgimi.gimicinema.model.OtherModelImpl;
import com.xgimi.gimicinema.model.SambaModelImpl;
import com.xgimi.gimicinema.mview.IAskView;

import java.util.ArrayList;

/**
 * Created by wugian on 2016/10/10
 */
public class AskPresenter implements SambaModelImpl.OnSambaMountListener,
        OtherModelImpl.OnScanOtherMovieListener, OtherModelImpl.OnScanMultiMovieListener {
    private ISambaModel sambaModel;
    private IOtherModel otherModel;

    private IAskView askView;

    public AskPresenter(IAskView askView) {
        this.sambaModel = new SambaModelImpl();
        this.otherModel = new OtherModelImpl();
        this.askView = askView;
    }

    public void load(Context context) {
        Log.d("lovely", "╟  service mount");
        if (!BuildConfig.MACHINE_TYPE.equals("himedia")) {
            Log.d("lovely", "╟  service mount if");
            sambaModel.mountSamba(context, this);
        } else {
            ShellUtils.execCommand(new String[]{"su", "start adbd"}, false);
            Log.d("lovely", "╟  service mount else");
        }
    }

    public void playMovie(Context context, String path) {
        otherModel.scanOtherMovies(context, path, this);
    }

    @Override
    public void onSambaMountSuccess() {

    }

    @Override
    public void onSambaMountFailure(int code, String wrongMsg) {

    }

    public void umountSamba() {
        Log.d("lovely", "╟  service umount");
//        sambaModel.umountSamba();
    }

    @Override
    public void onScanOtherMovieSuccess(ArrayList<String> result) {
        if (result.size() <= 1) {
            askView.playPath();
        } else if (result.size() > 1) {
            askView.playPath(result, 0);
        }
    }

    public void playMultiMovie(Context contexts, String[] movie_urls, int position) {
        otherModel.scanMultiMovies(contexts, movie_urls, position, this);
    }

    @Override
    public void onScanMultiMovieSuccess(ArrayList<String> result, int position) {
        askView.playPath(result, position);
    }

    @Override
    public void onScanMultiMovieFailure(String msg) {
        askView.showMsg(msg);
    }
}