3
3
import android .app .TabActivity ;
4
4
import android .content .Intent ;
5
5
import android .os .Bundle ;
6
- import android .util . Log ;
6
+ import android .support . annotation . NonNull ;
7
7
import android .view .KeyEvent ;
8
8
import android .view .View ;
9
9
import android .view .View .OnClickListener ;
10
10
import android .widget .TabHost ;
11
11
import android .widget .TabHost .TabSpec ;
12
12
import android .widget .Toast ;
13
13
14
- import com .cleaner .config .MainPageConfig ;
14
+ import com .cleaner .config .PatientUtil ;
15
15
import com .cleaner .view .BadgeRadioButton ;
16
16
17
17
import butterknife .BindView ;
18
18
import butterknife .ButterKnife ;
19
19
import butterknife .Unbinder ;
20
20
21
- public class MainActivity extends TabActivity {
21
+ public class MainActivity extends TabActivity implements MainConfigContracts . ConfigView {
22
22
private static final String TAG = MainActivity .class .getSimpleName ();
23
23
24
24
@ BindView (android .R .id .tabhost )
@@ -61,13 +61,13 @@ public class MainActivity extends TabActivity {
61
61
private static final int EVENT_EXPLORE = 5 ;
62
62
private static final int EVENT_PROFILE = 3 ;
63
63
64
- private MainPageConfig mainPageConfig ;
64
+ private final ExitingTrigger exitingTrigger = new ExitingTrigger ();
65
+ private final ToastWrapper toastWrapper = new ToastWrapper (R .string .toast_exit , Toast .LENGTH_LONG );
65
66
67
+ private Unbinder unbinder ;
66
68
private BadgeRadioButton activeBadgeRadio ;
67
69
68
- private long exitInterval ;
69
-
70
- private Unbinder unbinder ;
70
+ private final RadioClickListener listener = new RadioClickListener ();
71
71
72
72
@ Override
73
73
protected void onCreate (Bundle savedInstanceState ) {
@@ -89,9 +89,10 @@ public void onContentChanged() {
89
89
// checkAndLoginXbkpIM();
90
90
// PatientApplication.getInstance().addActivity(this);
91
91
92
- mainPageConfig = new MainPageConfig (this );
93
-
94
- initTabs ();
92
+ MainConfigContracts .ConfigPresenter configPresenter = new MainConfigPresenterImpl (this , parsePageConfig ());
93
+ initSelectTab (getIntent ());
94
+ initRadioButtons ();
95
+ configPresenter .initTabs ();
95
96
96
97
//事件的监听
97
98
// AndroidEventManager.getInstance().addEventListener(
@@ -104,110 +105,6 @@ public void onContentChanged() {
104
105
// .getUnreadMessageTotalCount());
105
106
}
106
107
107
- private TabSpec getHomePage () {
108
- TabSpec tabNearby = null ;
109
- if (mainPageConfig .hasSummary ()) {
110
- tabNearby = tabHost .newTabSpec (TAB_SPEC_SUMMARY );
111
- tabNearby .setIndicator (TAB_SPEC_SUMMARY ).setContent (new Intent (this , SummaryActivity .class ));
112
- } else if (mainPageConfig .hasRecyclerSummary ()) {
113
- tabNearby = tabHost .newTabSpec (TAB_SPEC_SUMMARY );
114
- tabNearby .setIndicator (TAB_SPEC_SUMMARY ).setContent (new Intent (this , RecyclerSummaryActivity .class ));
115
- } else if (mainPageConfig .hasRecyclerSummaryV2 ()) {
116
- tabNearby = tabHost .newTabSpec (TAB_SPEC_SUMMARY );
117
- tabNearby .setIndicator (TAB_SPEC_SUMMARY ).setContent (new Intent (this , RecyclerSummaryV2Activity .class ));
118
- } else {
119
- // Temporarily not processed
120
- }
121
-
122
- return tabNearby ;
123
- }
124
-
125
- private TabSpec getMessagePage () {
126
- TabSpec tabMessage = null ;
127
- if (mainPageConfig .hasMessage ()) {
128
- tabConversation = tabHost .newTabSpec (TAB_SPEC_CONVERSATION );
129
- initOrUpdateConversationTab ();
130
- tabMessage = tabConversation ;
131
- } else {
132
- Log .e (TAG , "message is null" );
133
- }
134
- return tabMessage ;
135
- }
136
-
137
- private TabSpec getDoctorPage () {
138
- TabSpec tabFind = null ;
139
- if (mainPageConfig .hasDoctorPage ()) {
140
- tabFind = tabHost .newTabSpec (TAB_SPEC_CONTACT );
141
- tabFind .setIndicator (TAB_SPEC_CONTACT ).setContent (
142
- new Intent (this , TabSearchDoctorActivity .class ));
143
- } else {
144
- // Temporarily not processed
145
- }
146
-
147
- return tabFind ;
148
- }
149
-
150
- private TabSpec getMinePage () {
151
- TabSpec tabMy = null ;
152
- if (mainPageConfig .hasMinePage ()) {
153
- tabMy = tabHost .newTabSpec (TAB_SPEC_PROFILE );
154
- tabMy .setIndicator (TAB_SPEC_PROFILE ).setContent (
155
- new Intent (this , MineActivity .class ));
156
- } else {
157
- // Temporarily not processed
158
- }
159
- return tabMy ;
160
- }
161
-
162
- private TabSpec getDiscoveryPage () {
163
- TabSpec tabDiscovery = null ;
164
- if (mainPageConfig .hasDiscoveryPage ()) {
165
- tabDiscovery = tabHost .newTabSpec (TAB_SPEC_EXPLORE );
166
- tabDiscovery .setIndicator (TAB_SPEC_EXPLORE ).setContent (
167
- new Intent (this , DiscoveryActivity .class ));
168
- } else {
169
- // Temporarily not processed
170
- }
171
- return tabDiscovery ;
172
- }
173
- private boolean initTabPanel (TabSpec tabSpec , BadgeRadioButton panel , int labelId , int iconId ,
174
- RadioClickListener listener ) {
175
- if (null == tabSpec ) {
176
- panel .setVisibility (View .GONE );
177
- return false ;
178
- } else {
179
- tabHost .addTab (tabSpec );
180
- panel .setOnClickListener (labelId , iconId , listener );
181
- panel .setVisibility (View .VISIBLE );
182
- }
183
- return true ;
184
- }
185
-
186
- private void initTabs () {
187
- initSelectTab (getIntent ());
188
- initRadioButtons ();
189
- RadioClickListener listener = new RadioClickListener ();
190
- // Home page
191
- TabSpec tabNearby = getHomePage ();
192
- initTabPanel (tabNearby , summaryBadgeRadio , R .string .tab_main , R .drawable .main_tab_home , listener );
193
-
194
- //message
195
- TabSpec tabMessage = getMessagePage ();
196
- initTabPanel (tabMessage , conversationBadgeRadio , R .string .tab_message , R .drawable .main_tab_message , listener );
197
-
198
- //find doctor
199
- TabSpec tabDoctor = getDoctorPage ();
200
- initTabPanel (tabDoctor , contactBadgeRadio , R .string .tab_find_doctor , R .drawable .main_tab_search , listener );
201
-
202
- //discovery
203
- TabSpec tabDiscovery = getDiscoveryPage ();
204
- initTabPanel (tabDiscovery , exploreBadgeRadio , R .string .tab_discovery , R .drawable .main_tab_search , listener );
205
-
206
- //me
207
- TabSpec tabMy = getMinePage ();
208
- initTabPanel (tabMy , profileBadgeRadio , R .string .tab_mine , R .drawable .main_tab_mine , listener );
209
- }
210
-
211
108
private static void setActiveIndex (int which ) {
212
109
activeIndex = which ;
213
110
}
@@ -262,9 +159,9 @@ protected void onResume() {
262
159
//如果是“我的医生”页,右上角“找医生”跳转过来的,手动触发“找医生界面”
263
160
Intent intent = getIntent ();
264
161
265
- String docter = intent .getStringExtra ("callDocter" );
162
+ String doctor = intent .getStringExtra ("callDocter" );
266
163
267
- if ("true" .equals (docter )) {
164
+ if ("true" .equals (doctor )) {
268
165
intent .removeExtra ("callDocter" );
269
166
contactBadgeRadio .performClick ();
270
167
}
@@ -280,6 +177,122 @@ protected void onResume() {
280
177
// }
281
178
// }
282
179
180
+ private MainConfigContracts .PageConfig parsePageConfig () {
181
+ String pageConfigKey = MainPageConfigImpl .getPageConfigKey ();
182
+ String preferredConfig = PatientUtil .loadConfigItem (this , pageConfigKey );
183
+ return new MainPageConfigImpl (preferredConfig );
184
+ }
185
+
186
+ @ Override
187
+ public void addSummaryTab () {
188
+ initHomePageTab (SummaryActivity .class );
189
+ }
190
+
191
+ @ Override
192
+ public void addRecyclerSummaryTab () {
193
+ initHomePageTab (RecyclerSummaryActivity .class );
194
+ }
195
+
196
+ @ Override
197
+ public void addRecyclerSummaryV2Tab () {
198
+ initHomePageTab (RecyclerSummaryV2Activity .class );
199
+ }
200
+
201
+ @ Override
202
+ public void addUnknownSummaryTab () {
203
+ // do nothing to prevent adding any HOME tab
204
+ hideTabPanel (summaryBadgeRadio );
205
+ }
206
+
207
+ private void initHomePageTab (@ NonNull Class <?> cls ) {
208
+ TabSpec tabNearby = tabHost .newTabSpec (TAB_SPEC_SUMMARY );
209
+ tabNearby .setIndicator (TAB_SPEC_SUMMARY ).setContent (new Intent (this , cls ));
210
+ initTabPanel (tabNearby , summaryBadgeRadio , R .string .radio_label_summary , R .drawable .radio_bg_summary , listener );
211
+ }
212
+
213
+ // private boolean initTabPanel(TabSpec tabSpec, View panel, View tabView, RadioClickListener listener) {
214
+ // if (null == tabSpec) {
215
+ // panel.setVisibility(View.GONE);
216
+ // return false;
217
+ // } else {
218
+ // tabHost.addTab(tabSpec);
219
+ // tabView.setOnClickListener(listener);
220
+ // panel.setVisibility(View.VISIBLE);
221
+ // }
222
+ // return true;
223
+ // }
224
+
225
+ private boolean initTabPanel (TabSpec tabSpec , BadgeRadioButton panel , int labelId , int iconId ,
226
+ RadioClickListener listener ) {
227
+ // if (null == tabSpec) {
228
+ // panel.setVisibility(View.GONE);
229
+ // return false;
230
+ // } else {
231
+ tabHost .addTab (tabSpec );
232
+ panel .setOnClickListener (labelId , iconId , listener );
233
+ panel .setVisibility (View .VISIBLE );
234
+ // }
235
+ return true ;
236
+ }
237
+
238
+ private void hideTabPanel (@ NonNull BadgeRadioButton panel ) {
239
+ panel .setVisibility (View .GONE );
240
+ }
241
+
242
+ @ Override
243
+ public void addMessageTab () {
244
+ tabConversation = tabHost .newTabSpec (TAB_SPEC_CONVERSATION );
245
+ initOrUpdateConversationTab ();
246
+ initTabPanel (tabConversation , conversationBadgeRadio , R .string .radio_label_conversation , R .drawable .radio_bg_conversation , listener );
247
+ }
248
+
249
+ @ Override
250
+ public void addUnknownMessageTab () {
251
+ // do nothing to prevent adding any MESSAGE tab
252
+ hideTabPanel (conversationBadgeRadio );
253
+ }
254
+
255
+ @ Override
256
+ public void addDoctorTab () {
257
+ TabSpec tabDoctor = tabHost .newTabSpec (TAB_SPEC_CONTACT );
258
+ tabDoctor .setIndicator (TAB_SPEC_CONTACT ).setContent (
259
+ new Intent (this , TabSearchDoctorActivity .class ));
260
+ initTabPanel (tabDoctor , contactBadgeRadio , R .string .radio_label_contact , R .drawable .radio_bg_explore , listener );
261
+ }
262
+
263
+ @ Override
264
+ public void addUnknownDoctorTab () {
265
+ // do nothing to prevent adding any DOCTOR tab
266
+ hideTabPanel (contactBadgeRadio );
267
+ }
268
+
269
+ @ Override
270
+ public void addMineTab () {
271
+ TabSpec tabMine = tabHost .newTabSpec (TAB_SPEC_PROFILE );
272
+ tabMine .setIndicator (TAB_SPEC_PROFILE ).setContent (new Intent (this , MineActivity .class ));
273
+ initTabPanel (tabMine , profileBadgeRadio , R .string .radio_label_profile , R .drawable .radio_bg_profile , listener );
274
+ }
275
+
276
+ @ Override
277
+ public void addUnknownMineTab () {
278
+ // do nothing to prevent adding any MINE tab
279
+ hideTabPanel (profileBadgeRadio );
280
+ }
281
+
282
+ @ Override
283
+ public void addDiscoveryTab () {
284
+ TabSpec tabDiscovery = tabHost .newTabSpec (TAB_SPEC_EXPLORE );
285
+ tabDiscovery .setIndicator (TAB_SPEC_EXPLORE ).setContent (
286
+ new Intent (this , DiscoveryActivity .class ));
287
+ initTabPanel (tabDiscovery , exploreBadgeRadio , R .string .radio_label_explore , R .drawable .radio_bg_explore , listener );
288
+ }
289
+
290
+ @ Override
291
+ public void addUnknownDiscoveryTab () {
292
+ // do nothing to prevent adding any DISCOVERY tab
293
+ hideTabPanel (exploreBadgeRadio );
294
+ }
295
+
283
296
private class RadioClickListener implements OnClickListener {
284
297
@ Override
285
298
public void onClick (View v ) {
@@ -297,17 +310,18 @@ protected void onDestroy() {
297
310
// AndroidEventManager.getInstance().removeEventListener(
298
311
// EventCode.UnreadMessageCountChanged, this);
299
312
unbinder .unbind ();
313
+ toastWrapper .cancel ();
300
314
}
301
315
302
316
@ Override
303
317
public boolean dispatchKeyEvent (KeyEvent event ) {
304
- if (event .getAction () == KeyEvent .ACTION_DOWN && event .getKeyCode () == KeyEvent .KEYCODE_BACK ) {
305
- if ((System .currentTimeMillis () - exitInterval ) > 3000 ) {
306
- Toast .makeText (this , R .string .toast_exit , Toast .LENGTH_LONG ).show ();
307
- exitInterval = System .currentTimeMillis ();
318
+ if (KeyEventHelper .isBackKeyDown (event )) {
319
+ if (exitingTrigger .testExpired (System .currentTimeMillis ())) {
320
+ toastWrapper .show (this );
308
321
} else {
309
322
finish ();
310
323
}
324
+
311
325
return true ;
312
326
}
313
327
return super .dispatchKeyEvent (event );
@@ -374,7 +388,7 @@ protected void reportTabClickEvent(int tabIndex) {
374
388
375
389
}
376
390
protected void bindUnreadCountTextView (BadgeRadioButton view ) {
377
- int viewId = view . findViewById ( R .id .badge ). getId ( );
391
+ //bindUnreadCountTextView(view, R.id.badge);
378
392
}
379
393
380
394
// refactor tab view item.
0 commit comments