NeighbActivity.java
8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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();
}
});
}
}