StartPresenter.java 2.56 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.text.TextUtils;

import com.gimi.common.cinema.model.Constant;
import com.xgimi.gimicinema.BuildConfig;
import com.xgimi.gimicinema.model.AdsModelImpl;
import com.xgimi.gimicinema.model.IAdsModel;
import com.xgimi.gimicinema.model.ISambaModel;
import com.xgimi.gimicinema.model.SambaModelImpl;
import com.xgimi.gimicinema.mview.IStartView;

import java.io.File;

/**
 * Created by 李攀 on 2016/9/22
 */
public class StartPresenter implements AdsModelImpl.OnGetAdsPathListener,
        SambaModelImpl.OnSambaMountListener {
    private IStartView startView;
    private IAdsModel startModel;
    private ISambaModel sambaModel;

    public StartPresenter(IStartView startView) {
        this.startView = startView;
        this.startModel = new AdsModelImpl();
        this.sambaModel = new SambaModelImpl();
    }

    public void load(Context context) {
        startModel.getPosterAds(context, this);
        sambaModel.mountSamba(context, this);
        Constant.userOpen = true;//broadcast too slow
    }

    public void mountSamba(Context context) {

        sambaModel.mountSamba(context, this);
    }

    public void timeOut() {
        if (!BuildConfig.MACHINE_TYPE.equals("himedia")) {
            startView.showMain();
        }
    }

    @Override
    public void onSuccess(String path) {
        if (!TextUtils.isEmpty(path) && new File(path).exists()) {
            startView.showAdsPicture(path);
        } else {
            startView.showDefault();
        }
    }

    @Override
    public void onFailure() {
        startView.showDefault();
    }

    @Override
    public void onSambaMountSuccess() {
        if (BuildConfig.MACHINE_TYPE.equals("himedia")) {
            startView.showMain();
        }
    }

    @Override
    public void onSambaMountFailure(int code, String wrongMsg) {
        if (BuildConfig.MACHINE_TYPE.equals("himedia")) {
            startView.showMsg("samba挂载失败");
        }
    }
}