1 |
|
package com.dreamcatcher.bicycle.activity; |
2 |
|
|
3 |
|
import android.app.Activity; |
4 |
|
import android.app.ProgressDialog; |
5 |
|
import android.content.Intent; |
6 |
|
import android.os.Bundle; |
7 |
|
import android.view.View; |
8 |
|
import android.view.View.OnClickListener; |
9 |
|
import android.widget.Button; |
10 |
|
import android.widget.ListView; |
11 |
|
|
12 |
|
import com.dreamcatcher.bicycle.R; |
13 |
|
import com.dreamcatcher.bicycle.adapter.CityListAdapter; |
14 |
|
import com.dreamcatcher.bicycle.adapter.CityListAdapter.ICityListEvent; |
15 |
|
import com.dreamcatcher.bicycle.core.BicycleService; |
16 |
|
import com.dreamcatcher.bicycle.interfaces.IAssetsEvent; |
17 |
|
import com.dreamcatcher.bicycle.interfaces.IAssetsService; |
18 |
|
import com.dreamcatcher.bicycle.util.Constants; |
19 |
|
import com.dreamcatcher.bicycle.util.Utils; |
20 |
|
import com.dreamcatcher.bicycle.view.ActivityTitle; |
21 |
|
|
|
|
| 94% |
Uncovered Elements: 3 (50) |
Complexity: 13 |
Complexity Density: 0,38 |
|
22 |
|
public class SelectCityActivity extends Activity implements IAssetsEvent{ |
23 |
|
private int mSelectedCityIndex = -1; |
24 |
|
private IAssetsService mAssetsService = null; |
25 |
|
private ProgressDialog mProgressDialog = null; |
26 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
27 |
1
|
@Override... |
28 |
|
protected void onCreate(Bundle savedInstanceState) { |
29 |
|
|
30 |
1
|
super.onCreate(savedInstanceState); |
31 |
1
|
setContentView(R.layout.select_city); |
32 |
1
|
init(); |
33 |
|
} |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
35 |
1
|
@Override... |
36 |
|
protected void onDestroy() { |
37 |
1
|
this.removeEvent(); |
38 |
1
|
super.onDestroy(); |
39 |
|
} |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
|
41 |
1
|
private void init(){... |
42 |
1
|
this.addEvent(); |
43 |
|
|
44 |
1
|
mAssetsService = BicycleService.getInstance().getAssertsService(); |
45 |
|
|
46 |
1
|
ActivityTitle activityTitle = (ActivityTitle) findViewById(R.id.bicycle_title); |
47 |
1
|
activityTitle.setActivityTitle(R.string.title_select_city); |
48 |
|
|
49 |
1
|
ListView listView = (ListView) findViewById(R.id.select_city_list); |
50 |
|
|
51 |
1
|
ICityListEvent citySelectEvent = new ICityListEvent() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
2
|
public void onCityItemClicked(int index) {... |
53 |
2
|
mSelectedCityIndex = index; |
54 |
|
} |
55 |
|
}; |
56 |
|
|
57 |
1
|
CityListAdapter adapter = new CityListAdapter(citySelectEvent, 0); |
58 |
|
|
59 |
1
|
listView.setAdapter(adapter); |
60 |
|
|
61 |
1
|
Button nextBtn = (Button) findViewById(R.id.select_city_next_btn); |
62 |
1
|
nextBtn.setOnClickListener(new OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
1
|
public void onClick(View v) {... |
64 |
1
|
onNextBtnClicked(); |
65 |
|
} |
66 |
|
}); |
67 |
|
|
68 |
|
} |
69 |
|
|
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
1
|
private void addEvent(){... |
72 |
1
|
BicycleService.getInstance().getAssetsEventListener().addEvent(this); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
1
|
private void removeEvent(){... |
76 |
1
|
BicycleService.getInstance().getAssetsEventListener().removeEvent(this); |
77 |
|
} |
78 |
|
|
|
|
| 88,9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
79 |
1
|
private void onNextBtnClicked(){... |
80 |
1
|
if(mSelectedCityIndex != -1){ |
81 |
1
|
final String cityTag = Constants.CitySetting.CITY_TAG[mSelectedCityIndex]; |
82 |
|
|
83 |
1
|
mProgressDialog = new ProgressDialog(this); |
84 |
1
|
mProgressDialog.setMessage(getText(R.string.progress_dialog_loading_msg)); |
85 |
1
|
mProgressDialog.show(); |
86 |
|
|
87 |
1
|
Utils.storeStringDataToLocal(Constants.LocalStoreTag.CITY_NAME, cityTag); |
88 |
1
|
mAssetsService.loadCitySetting(); |
89 |
|
} |
90 |
|
} |
91 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
92 |
1
|
public void onCitySettingLoaded(int resultCode) {... |
93 |
1
|
if(resultCode == Constants.ResultCode.SUCCESS){ |
94 |
1
|
mAssetsService.loadBicyclesInfo(); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
98 |
1
|
public void onBicyclesInfoLoaded(int resultCode) {... |
99 |
1
|
if (resultCode == Constants.ResultCode.SUCCESS) { |
100 |
1
|
Intent data = new Intent(); |
101 |
1
|
data.putExtra("load_completed", true); |
102 |
1
|
setResult(RESULT_OK, data); |
103 |
1
|
mProgressDialog.dismiss(); |
104 |
1
|
finish(); |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
} |