NeighbActivity.java 8 KB
package com.lotus.town;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ad.lib.RewardManager;
import com.lotus.town.dao.HubDatabaseHelper;
import com.lotus.town.dao.HubNotes;
import com.lotus.town.dialog.Dialog;
import com.lotus.town.home.ItemType;
import com.lotus.town.neighgour.Neighbour;
import com.lotus.town.neighgour.NeighbourManager;
import com.lotus.town.utils.SharedPrefConfig;
import com.lotus.town.utils.UIUtils;
import com.lotus.town.utils.Utils;
import com.lotus.town.widget.NeighbourTypeView;
import com.sdk.Sdk;
import com.sdk.log.LogConstants;

public class NeighbActivity extends BaseHomeActivity implements View.OnClickListener {
    private static final String TAG = "NeighbActivity";

    private TextView mActionBarTv;
//    private TextView mMoneyTv;
//    private ImageView mHeadIv;
    private View mBack;
    private View.OnClickListener mTutorialConfirmClickListener;

    private NeighbourTypeView mNeighbourView;
    private NeighbourTypeView mMe;

    private Neighbour mNeighbour;

    private boolean mIsQwDead;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isHomePage = false;
        if(SharedPrefConfig.getInstance(this).isNeighbRemind()) {
            showTutorial();
        }
        Sdk.logger().logEvent(this, LogConstants.LOG_NEIGHB_DISPLAY);

    }

    @Override
    protected void initView() {
        super.initView();
        mNeighbour = NeighbourManager.getInstance().getNeighbour();
        Log.d(TAG, "initView: neighbour: " + mNeighbour);
        mActionBarTv = findViewById(R.id.action_bar_text);
//        mMoneyTv = findViewById(R.id.monkey);
//        mHeadIv = findViewById(R.id.neighbour_1_icon);
        mNeighbourView = findViewById(R.id.neighboure);
        mMe = findViewById(R.id.me);
        mMe.setInfo(R.drawable.me_head, R.drawable.head2, scManager.getInstance(this).getMoney());
        mBack = findViewById(R.id.back);
        mBack.setOnClickListener(this);
        if (mNeighbour != null) {
            mActionBarTv.setText(mNeighbour.getName());
            mNeighbourView.setInfo(R.drawable.neighbour_head, mNeighbour.getHead(), mNeighbour.getMoney());
//            mMoneyTv.setText(mNeighbour.getMoney() + "元");
//            mHeadIv.setBackgroundResource(mNeighbour.getHead());
        } else {
            Log.e(TAG, "initView: no neighbour");
            showNoNeighbourHehua();
        }
    }

    private void showNoNeighbourHehua() {
        Dialog dialog = getDialog();
        dialog.show(this,
                getString(R.string.no_neighbour),
                null,
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                },
                null,
                null,
                "确认",
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_neighb;
    }

    private void showTutorial() {
        mTutorialConfirmClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPrefConfig.getInstance(NeighbActivity.this).neighbRemind();
                dismissDialog();
            }
        };
        Dialog dialog = getDialog();
        dialog.showCenter(this,
                getString(R.string.neighbour_play_main_hint),
                mTutorialConfirmClickListener,
                getString(R.string.neighbour_play_right_btn_hint),
                mTutorialConfirmClickListener);
    }

    @Override
    protected void insertNotes(String result) {
        super.insertNotes(result);
    }

    @Override
    public void onClick(View v) {
        if(v == mBack){
            finish();
        } else {
            super.onClick(v);
        }
    }

    @Override
    protected boolean hasHehua() {
        return mNeighbour.getJumpCount() >= 3;
    }

    protected void showJumpResult(ItemType itemType, View view, final double money) {
        if(itemType == ItemType.TIMES_OUT){
            final Dialog dialog = getDialog();

            dialog.show(this,
                    getString(R.string.neighbour_lotus_ran_out_main_hint),
                    getString(R.string.neighbour_lotus_ran_out_sub_hint, Utils.doubleToString(getTodayMoney()/2.0), Utils.doubleToString(getTodayMoney()/2.0)),
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dismissDialog();
                        }
                    },
                    null,
                    null,
                    getString(R.string.neighbour_lotus_ran_out_right_btn_hint),
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dismissDialog();
                            if( NeighbourManager.getInstance().getNeighbour() == null){
//                                UIUtils.showToast("今天已经拜访过附近邻居了,明天再去吧");
                                showNoNeighbourToday();
                                return;
                            }
                            finish();
                            Sdk.logger().logEvent(NeighbActivity.this,LogConstants.LOG_GOTO_NEIGHB_FROM_NEIGHB);
                            Intent i = new Intent();
                            i.setClass(NeighbActivity.this,NeighbActivity.class);
                            NeighbActivity.this.startActivity(i);
                        }
                    });
        } else {
            super.showJumpResult(itemType,view,money);
        }

    }

    @Override
    protected void doJump() {
        super.doJump();
        NeighbourManager.getInstance().jump(mNeighbour);
        Sdk.logger().logEvent(this, LogConstants.LOG_JUMP_ACTION,LogConstants.LOG_JUMP_FROM_NEIGHB);
    }

    @Override
    protected void notifyBoom() {
        super.notifyBoom();
        mIsQwDead = true;
    }

    @Override
    protected boolean isQWdead() {
        return mIsQwDead;
    }

    @Override
    protected void notifyQwHeal() {
        super.notifyQwHeal();
        mIsQwDead = false;
    }

    @Override
    protected void notifyNeighbourMoneyEarn(final double money) {
        super.notifyNeighbourMoneyEarn(money);
        Log.d(TAG, "notifyNeighbourMoneyEarn() called with: money = [" + money + "]");
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                NeighbourManager.getInstance().earn(mNeighbour, money);
                mNeighbourView.setMonkey(mNeighbour.getMoney());
                mMe.setMonkey(scManager.getInstance(NeighbActivity.this).getMoney());
//                mMoneyTv.setText(Utils.doubleToString(mNeighbour.getMoney()) + "元");
            }
        });
    }

    private double getTodayMoney() {
        return mNeighbour != null ? mNeighbour.getTodayMoney() : 0;
    }

    protected void showNoNeighbourToday() {
        Dialog dialog = getDialog();
        dialog.dismiss(this);
        dialog.showCenter(this,
                "今天已经拜访过附近邻居了,明天再去吧",
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                },
                "知道啦",
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
    }
}