Commit 45b64f1c0a99c01b464cde3cc9081228b917fe23
1 parent
105e0366
Exists in
yxb_dev
and in
2 other branches
no message
Showing
10 changed files
with
90 additions
and
251 deletions
Show diff stats
app/libs/processor.jar
No preview for this file type
app/src/main/java/com/shunzhi/parent/AppContext.java
... | ... | @@ -19,7 +19,6 @@ import com.share.mvpsdk.global.GlobalApplication; |
19 | 19 | import com.share.mvpsdk.helper.RetrofitCreateHelper; |
20 | 20 | import com.shunzhi.parent.bean.message.DaoMaster; |
21 | 21 | import com.shunzhi.parent.bean.message.DaoSession; |
22 | -import com.shunzhi.parent.db.DBControl; | |
23 | 22 | import com.shunzhi.parent.dbhelper.GreenDaoDatabaseOpenHelper; |
24 | 23 | import com.shunzhi.parent.manager.MessageManager; |
25 | 24 | import com.shunzhi.parent.ui.MainActivity; |
... | ... | @@ -63,7 +62,6 @@ public class AppContext extends GlobalApplication { |
63 | 62 | appContext = this; |
64 | 63 | super.onCreate(); |
65 | 64 | |
66 | - DBControl.init(appContext); | |
67 | 65 | NIMClient.init(this, loginInfo(), options()); |
68 | 66 | if (inMainProcess(this)) { |
69 | 67 | //开启地图地位 | ... | ... |
app/src/main/java/com/shunzhi/parent/db/ChildInfoDao.java
... | ... | @@ -1,89 +0,0 @@ |
1 | -package com.shunzhi.parent.db; | |
2 | - | |
3 | -import android.content.Context; | |
4 | - | |
5 | -import com.j256.ormlite.dao.Dao; | |
6 | -import com.j256.ormlite.stmt.DeleteBuilder; | |
7 | -import com.j256.ormlite.stmt.QueryBuilder; | |
8 | -import com.shunzhi.parent.bean.ChildBean; | |
9 | -import com.shunzhi.parent.util.DatabaseHelper; | |
10 | - | |
11 | -import java.sql.SQLException; | |
12 | -import java.util.ArrayList; | |
13 | -import java.util.List; | |
14 | - | |
15 | -/** | |
16 | - * Created by Administrator on 2018/4/19 0019. | |
17 | - */ | |
18 | - | |
19 | -public class ChildInfoDao { | |
20 | - private Context context; | |
21 | - private DatabaseHelper databaseHelper; | |
22 | - private Dao<ChildBean, Integer> dao; | |
23 | - | |
24 | - public ChildInfoDao(Context context) { | |
25 | - this.context = context; | |
26 | - try { | |
27 | - databaseHelper = DatabaseHelper.getHelper(context); | |
28 | - dao = databaseHelper.getDao(ChildBean.class); | |
29 | - } catch (SQLException e) { | |
30 | - e.printStackTrace(); | |
31 | - } | |
32 | - } | |
33 | - | |
34 | - public boolean createOrUpdate(ChildBean childBean){ | |
35 | - try { | |
36 | - return dao.createOrUpdate(childBean).getNumLinesChanged() > 0; | |
37 | - } catch (SQLException e) { | |
38 | - e.printStackTrace(); | |
39 | - return false; | |
40 | - } | |
41 | - } | |
42 | - | |
43 | - | |
44 | - public boolean onCreate(ChildBean childBean) { | |
45 | - try { | |
46 | - return dao.create(childBean) > 0; | |
47 | - } catch (SQLException e) { | |
48 | - e.printStackTrace(); | |
49 | - return false; | |
50 | - } | |
51 | - } | |
52 | - | |
53 | - public boolean deleteAll(){ | |
54 | - try { | |
55 | - DeleteBuilder builder = dao.deleteBuilder(); | |
56 | - return dao.delete(builder.prepare())>0; | |
57 | - } catch (SQLException e) { | |
58 | - e.printStackTrace(); | |
59 | - return false; | |
60 | - } | |
61 | - } | |
62 | - public synchronized List<ChildBean> getAllChildren() { | |
63 | - List<ChildBean> children = null; | |
64 | - try { | |
65 | - children = dao.queryForAll(); | |
66 | - if (children != null && children.size() > 0) return children; | |
67 | - } catch (SQLException e) { | |
68 | - e.printStackTrace(); | |
69 | - return new ArrayList<>(); | |
70 | - } | |
71 | - return new ArrayList<>(); | |
72 | - } | |
73 | - | |
74 | - | |
75 | - public synchronized ChildBean getChildBystudentId(int studentId) { | |
76 | - QueryBuilder queryBuilder = dao.queryBuilder(); | |
77 | - try { | |
78 | - queryBuilder.where().eq("studentId", studentId); | |
79 | - List<ChildBean> list = dao.query(queryBuilder.prepare()); | |
80 | - ChildBean studentInfo = list.get(0); | |
81 | - return studentInfo; | |
82 | -// return dao.queryForFirst(queryBuilder.prepare()); | |
83 | - } catch (SQLException e) { | |
84 | - e.printStackTrace(); | |
85 | - return null; | |
86 | - } | |
87 | - } | |
88 | - | |
89 | - } |
app/src/main/java/com/shunzhi/parent/db/DBControl.java
... | ... | @@ -1,15 +0,0 @@ |
1 | -package com.shunzhi.parent.db; | |
2 | - | |
3 | -import android.content.Context; | |
4 | - | |
5 | -/** | |
6 | - * Created by Administrator on 2018/4/19 0019. | |
7 | - */ | |
8 | - | |
9 | -public class DBControl { | |
10 | - public static ChildInfoDao childInfoDao; | |
11 | - | |
12 | - public static void init(Context context){ | |
13 | - childInfoDao=new ChildInfoDao(context); | |
14 | - } | |
15 | -} |
app/src/main/java/com/shunzhi/parent/ui/activity/MyChildActivity.java
... | ... | @@ -22,7 +22,6 @@ import com.shunzhi.parent.bean.ChildBean; |
22 | 22 | import com.shunzhi.parent.bean.ChildClass; |
23 | 23 | import com.shunzhi.parent.bean.CurrentBean; |
24 | 24 | import com.shunzhi.parent.contract.mine.MyChildContract; |
25 | -import com.shunzhi.parent.db.DBControl; | |
26 | 25 | import com.shunzhi.parent.presenter.mine.MyChildPresenter; |
27 | 26 | import com.shunzhi.parent.ui.activity.binding.SelectSchoolActivity; |
28 | 27 | import com.shunzhi.parent.ui.activity.mywebview.WebViewActivity; |
... | ... | @@ -103,10 +102,6 @@ public class MyChildActivity extends BaseMVPCompatActivity<MyChildContract.MyChi |
103 | 102 | public void updateChildList(CurrentBean currentBean) { |
104 | 103 | currlist.clear(); |
105 | 104 | List<ChildBean> list = currentBean.getStudentClass(); |
106 | - for(int i=0;i<list.size();i++){ | |
107 | - DBControl.childInfoDao.createOrUpdate(list.get(i)); | |
108 | - } | |
109 | - | |
110 | 105 | currlist.addAll(list); |
111 | 106 | if (childAdapter == null) { |
112 | 107 | childAdapter = new ChildAdapter(this); | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/fragment/ReportFragment.java
... | ... | @@ -4,35 +4,40 @@ package com.shunzhi.parent.ui.fragment; |
4 | 4 | import android.os.Bundle; |
5 | 5 | import android.os.Handler; |
6 | 6 | import android.os.Message; |
7 | +import android.support.annotation.NonNull; | |
7 | 8 | import android.support.annotation.Nullable; |
8 | 9 | import android.support.design.widget.TabLayout; |
9 | 10 | import android.support.v4.app.Fragment; |
10 | 11 | import android.support.v4.app.FragmentManager; |
11 | 12 | import android.support.v4.app.FragmentPagerAdapter; |
12 | 13 | import android.support.v4.view.ViewPager; |
13 | -import android.support.v7.widget.PopupMenu; | |
14 | 14 | import android.text.TextUtils; |
15 | 15 | import android.view.Menu; |
16 | 16 | import android.view.MenuItem; |
17 | 17 | import android.view.View; |
18 | +import android.widget.PopupMenu; | |
19 | +import android.widget.RelativeLayout; | |
18 | 20 | import android.widget.TextView; |
19 | -import android.widget.Toast; | |
20 | 21 | |
21 | 22 | import com.google.gson.Gson; |
22 | -import com.share.mvpsdk.base.fragment.BaseCompatFragment; | |
23 | -import com.share.mvpsdk.utils.ToastUtils; | |
23 | +import com.share.mvpsdk.base.BasePresenter; | |
24 | +import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; | |
24 | 25 | import com.shunzhi.parent.AppConfig; |
25 | 26 | import com.shunzhi.parent.AppContext; |
26 | 27 | import com.shunzhi.parent.R; |
27 | 28 | import com.shunzhi.parent.bean.ChildBean; |
28 | -import com.shunzhi.parent.db.DBControl; | |
29 | +import com.shunzhi.parent.bean.ChildClass; | |
30 | +import com.shunzhi.parent.bean.CurrentBean; | |
31 | +import com.shunzhi.parent.contract.mine.MyChildContract; | |
29 | 32 | import com.shunzhi.parent.popu.ShaiXuanPop; |
33 | +import com.shunzhi.parent.presenter.mine.MyChildPresenter; | |
30 | 34 | import com.shunzhi.parent.ui.fragment.report.ChengZhangFragment; |
31 | 35 | |
32 | 36 | import java.util.ArrayList; |
33 | 37 | import java.util.List; |
34 | 38 | |
35 | -public class ReportFragment extends BaseCompatFragment implements View.OnClickListener { | |
39 | +public class ReportFragment extends BaseMVPCompatFragment<MyChildContract.MyChildPresenter, MyChildContract.IMyChildModel> | |
40 | + implements MyChildContract.IMyChildView, View.OnClickListener { | |
36 | 41 | ViewPager viewPager; |
37 | 42 | |
38 | 43 | TextView tvDate, tvShaiXuan, tvNoData, tvName; |
... | ... | @@ -41,6 +46,8 @@ public class ReportFragment extends BaseCompatFragment implements View.OnClickLi |
41 | 46 | |
42 | 47 | TabLayout tabLayout; |
43 | 48 | |
49 | + RelativeLayout rl_noData; | |
50 | + | |
44 | 51 | ChengZhangFragment chengZhangFragment1 = null, chengZhangFragment2 = null;//成长、报告页面 |
45 | 52 | |
46 | 53 | ShaiXuanPop shaiXuanPop = null; |
... | ... | @@ -62,25 +69,11 @@ public class ReportFragment extends BaseCompatFragment implements View.OnClickLi |
62 | 69 | tvShaiXuan = view.findViewById(R.id.tvShaiXuan); |
63 | 70 | tvNoData = view.findViewById(R.id.tvNoData); |
64 | 71 | tabLayout = view.findViewById(R.id.tabLayout); |
72 | + rl_noData = view.findViewById(R.id.rl_noData); | |
65 | 73 | tvName.setOnClickListener(this); |
66 | 74 | tvName.setEllipsize(TextUtils.TruncateAt.END); |
67 | 75 | tvShaiXuan.setOnClickListener(this); |
68 | - | |
69 | 76 | myFragmentAdapter = new MyFragmentAdapter(getChildFragmentManager()); |
70 | - | |
71 | - childlist = DBControl.childInfoDao.getAllChildren(); | |
72 | - createSchoolMenu(); | |
73 | - String currChildStr = AppConfig.getAppConfig(AppContext.getInstance()).get(AppConfig.CURRCHILDJSONSTR); | |
74 | - if (TextUtils.isEmpty(currChildStr)) { | |
75 | - if (childlist != null && childlist.size() > 0) { | |
76 | - tvName.setText(childlist.get(0).getStudentName()); | |
77 | - jsonStr = g.toJson(childlist.get(0), ChildBean.class); | |
78 | - } | |
79 | - } else { | |
80 | - ChildBean childBean = g.fromJson(currChildStr, ChildBean.class); | |
81 | - tvName.setText(childBean.getStudentName()); | |
82 | - jsonStr = currChildStr; | |
83 | - } | |
84 | 77 | viewPager.setAdapter(myFragmentAdapter); |
85 | 78 | tabLayout.setupWithViewPager(viewPager); |
86 | 79 | tabLayout.removeAllTabs(); |
... | ... | @@ -106,6 +99,13 @@ public class ReportFragment extends BaseCompatFragment implements View.OnClickLi |
106 | 99 | |
107 | 100 | } |
108 | 101 | |
102 | + | |
103 | + @Override | |
104 | + public void onResume() { | |
105 | + super.onResume(); | |
106 | + mPresenter.loadChildList(AppConfig.getAppConfig(AppContext.getInstance()).get(AppConfig.LOGIN_NAME), 0, ""); | |
107 | + } | |
108 | + | |
109 | 109 | @Override |
110 | 110 | public void onClick(View view) { |
111 | 111 | switch (view.getId()) { |
... | ... | @@ -138,6 +138,7 @@ public class ReportFragment extends BaseCompatFragment implements View.OnClickLi |
138 | 138 | tvName.setText(item.getTitle()); |
139 | 139 | jsonStr = g.toJson(childlist.get(finalI), ChildBean.class); |
140 | 140 | AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.CURRCHILDJSONSTR, jsonStr); |
141 | + myFragmentAdapter.notifyDataSetChanged(); | |
141 | 142 | return false; |
142 | 143 | } |
143 | 144 | }); |
... | ... | @@ -160,6 +161,64 @@ public class ReportFragment extends BaseCompatFragment implements View.OnClickLi |
160 | 161 | if (handler != null) handler = null; |
161 | 162 | } |
162 | 163 | |
164 | + @NonNull | |
165 | + @Override | |
166 | + public BasePresenter initPresenter() { | |
167 | + return new MyChildPresenter(); | |
168 | + } | |
169 | + | |
170 | + | |
171 | + @Override | |
172 | + public void updateChildList(CurrentBean currentBean) { | |
173 | + childlist.clear(); | |
174 | + if (currentBean != null) { | |
175 | + List<ChildBean> list = currentBean.getStudentClass(); | |
176 | + String currChildStr = AppConfig.getAppConfig(AppContext.getInstance()).get(AppConfig.CURRCHILDJSONSTR); | |
177 | + childlist.addAll(list); | |
178 | + | |
179 | + if (childlist == null || childlist.size() == 0) { | |
180 | + rl_noData.setVisibility(View.VISIBLE); | |
181 | + viewPager.setVisibility(View.GONE); | |
182 | + } | |
183 | + if (TextUtils.isEmpty(currChildStr)) { | |
184 | + if (childlist != null && childlist.size() > 0) { | |
185 | + tvName.setText(childlist.get(0).getStudentName()); | |
186 | + jsonStr = g.toJson(childlist.get(0), ChildBean.class); | |
187 | + } | |
188 | + } else { | |
189 | + ChildBean childBean = g.fromJson(currChildStr, ChildBean.class); | |
190 | + for (int i = 0; i < childlist.size(); i++) { | |
191 | + if (childBean.getStudentId() == childlist.get(i).getStudentId()) { | |
192 | + jsonStr = g.toJson(childlist.get(i), ChildBean.class); | |
193 | + break; | |
194 | + } | |
195 | + } | |
196 | + tvName.setText(childBean.getStudentName()); | |
197 | + } | |
198 | + AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.CURRCHILDJSONSTR, jsonStr); | |
199 | + createSchoolMenu(); | |
200 | + } | |
201 | + | |
202 | + } | |
203 | + | |
204 | + @Override | |
205 | + public void addChildSuccess(String account, String password) { | |
206 | + | |
207 | + } | |
208 | + | |
209 | + @Override | |
210 | + public void showClass(List<ChildClass> list) { | |
211 | + | |
212 | + } | |
213 | + | |
214 | + @Override | |
215 | + public void showError(String error) { | |
216 | + if (error.equals("访问的接口要求登录")) { | |
217 | + rl_noData.setVisibility(View.VISIBLE); | |
218 | + viewPager.setVisibility(View.GONE); | |
219 | + } | |
220 | + } | |
221 | + | |
163 | 222 | private class MyFragmentAdapter extends FragmentPagerAdapter { |
164 | 223 | |
165 | 224 | public MyFragmentAdapter(FragmentManager fm) { | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/fragment/apply/ApplySigninFragment.java
1 | 1 | package com.shunzhi.parent.ui.fragment.apply; |
2 | 2 | |
3 | -import android.app.DatePickerDialog; | |
4 | 3 | import android.os.Build; |
5 | 4 | import android.os.Bundle; |
6 | 5 | import android.support.annotation.Nullable; |
... | ... | @@ -10,16 +9,11 @@ import android.support.v7.widget.RecyclerView; |
10 | 9 | import android.text.TextUtils; |
11 | 10 | import android.util.Log; |
12 | 11 | import android.view.View; |
13 | -import android.widget.CheckBox; | |
14 | -import android.widget.CompoundButton; | |
15 | -import android.widget.DatePicker; | |
16 | 12 | import android.widget.ImageView; |
17 | 13 | import android.widget.LinearLayout; |
18 | 14 | import android.widget.TextView; |
19 | -import android.widget.Toast; | |
20 | 15 | |
21 | 16 | import com.bigkoo.pickerview.builder.TimePickerBuilder; |
22 | -import com.bigkoo.pickerview.listener.CustomListener; | |
23 | 17 | import com.bigkoo.pickerview.listener.OnTimeSelectChangeListener; |
24 | 18 | import com.bigkoo.pickerview.listener.OnTimeSelectListener; |
25 | 19 | import com.bigkoo.pickerview.view.TimePickerView; |
... | ... | @@ -27,16 +21,13 @@ import com.google.gson.Gson; |
27 | 21 | import com.share.mvpsdk.base.BasePresenter; |
28 | 22 | import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; |
29 | 23 | import com.share.mvpsdk.utils.ToastUtils; |
30 | -import com.shunzhi.parent.AppContext; | |
31 | 24 | import com.shunzhi.parent.R; |
32 | 25 | import com.shunzhi.parent.adapter.AttendanceAdapter; |
33 | 26 | import com.shunzhi.parent.bean.ChildBean; |
34 | -import com.shunzhi.parent.bean.ToolBean; | |
35 | 27 | import com.shunzhi.parent.bean.apply.AttendanceBean; |
36 | 28 | import com.shunzhi.parent.contract.apply.ApplySigninContract; |
37 | 29 | import com.shunzhi.parent.presenter.apply.ApplySigninPresenter; |
38 | 30 | |
39 | -import java.sql.Time; | |
40 | 31 | import java.text.SimpleDateFormat; |
41 | 32 | import java.util.ArrayList; |
42 | 33 | import java.util.Calendar; |
... | ... | @@ -81,10 +72,10 @@ public class ApplySigninFragment extends BaseMVPCompatFragment<ApplySigninContra |
81 | 72 | String jsonStr = getArguments().getString("childStr"); |
82 | 73 | if (!TextUtils.isEmpty(jsonStr)) |
83 | 74 | currChildBean = g.fromJson(jsonStr, ChildBean.class); |
84 | - | |
85 | 75 | initLunarPicker(); |
86 | 76 | iv_calendar.setOnClickListener(this); |
87 | - | |
77 | + tv_kaoqin_user.setText(currChildBean.getStudentName()); | |
78 | + tv_tips.setText(currChildBean.getStudentName() + "今日无刷卡记录"); | |
88 | 79 | currdate = getNowTime(); |
89 | 80 | tv_kaoqin_date.setText(getNowTime()); |
90 | 81 | recycle_attendance = view.findViewById(R.id.recycle_attendance); |
... | ... | @@ -183,8 +174,10 @@ public class ApplySigninFragment extends BaseMVPCompatFragment<ApplySigninContra |
183 | 174 | |
184 | 175 | if (list.size() == 0) { |
185 | 176 | layout_tv.setVisibility(View.VISIBLE); |
177 | + recycle_attendance.setVisibility(View.GONE); | |
186 | 178 | } else { |
187 | 179 | recycle_attendance.setVisibility(View.VISIBLE); |
180 | + layout_tv.setVisibility(View.GONE); | |
188 | 181 | signinlist.clear(); |
189 | 182 | signinlist.addAll(list); |
190 | 183 | attendanceAdapter.addAll(signinlist); | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/fragment/report/ChengZhangFragment.java
1 | 1 | package com.shunzhi.parent.ui.fragment.report; |
2 | 2 | |
3 | -import android.content.Intent; | |
4 | 3 | import android.os.Bundle; |
5 | 4 | import android.os.Handler; |
6 | 5 | import android.os.Message; |
... | ... | @@ -8,7 +7,6 @@ import android.support.annotation.NonNull; |
8 | 7 | import android.support.annotation.Nullable; |
9 | 8 | import android.support.v7.widget.RecyclerView; |
10 | 9 | import android.text.TextUtils; |
11 | -import android.util.Log; | |
12 | 10 | import android.view.Gravity; |
13 | 11 | import android.view.LayoutInflater; |
14 | 12 | import android.view.View; |
... | ... | @@ -33,13 +31,10 @@ import com.shunzhi.parent.bean.ReportBean; |
33 | 31 | import com.shunzhi.parent.contract.report.ReportContract; |
34 | 32 | import com.shunzhi.parent.presenter.report.ReportPresenter; |
35 | 33 | import com.shunzhi.parent.ui.activity.BankActivity; |
36 | -import com.shunzhi.parent.ui.activity.MyChildActivity; | |
37 | 34 | import com.shunzhi.parent.ui.activity.apply.ApplyReplaceCardActivity; |
38 | 35 | import com.shunzhi.parent.ui.activity.apply.ApplySigninActivity; |
39 | -import com.shunzhi.parent.ui.activity.binding.CheckInfoActivity; | |
40 | 36 | import com.shunzhi.parent.ui.activity.mywebview.WebViewActivity; |
41 | 37 | |
42 | - | |
43 | 38 | import java.util.List; |
44 | 39 | |
45 | 40 | /** |
... | ... | @@ -102,12 +97,9 @@ public class ChengZhangFragment extends BaseMVPCompatFragment<ReportContract.Rep |
102 | 97 | layout_kaoqin.setOnClickListener(this); |
103 | 98 | layout_buka.setOnClickListener(this); |
104 | 99 | layout_qingjia.setOnClickListener(this); |
105 | - | |
106 | 100 | type = getArguments().getString("type"); |
107 | 101 | jsonStr = getArguments().getString("jsonStr"); |
108 | 102 | Gson g = new Gson(); |
109 | - | |
110 | - | |
111 | 103 | if (type.equals(TYPE_CHENGZHANG)) { |
112 | 104 | layout_chengzhang.setVisibility(View.VISIBLE); |
113 | 105 | layout_report.setVisibility(View.GONE); |
... | ... | @@ -123,6 +115,11 @@ public class ChengZhangFragment extends BaseMVPCompatFragment<ReportContract.Rep |
123 | 115 | } |
124 | 116 | } |
125 | 117 | |
118 | + @Override | |
119 | + public void onResume() { | |
120 | + super.onResume(); | |
121 | + } | |
122 | + | |
126 | 123 | private void initCalendarView() { |
127 | 124 | |
128 | 125 | showDate(); |
... | ... | @@ -225,7 +222,6 @@ public class ChengZhangFragment extends BaseMVPCompatFragment<ReportContract.Rep |
225 | 222 | switch (view.getId()) { |
226 | 223 | |
227 | 224 | case R.id.layout_kaoqin: |
228 | - | |
229 | 225 | ApplySigninActivity.getInstance(getActivity(), jsonStr); |
230 | 226 | break; |
231 | 227 | case R.id.layout_buka: | ... | ... |
app/src/main/java/com/shunzhi/parent/util/DatabaseHelper.java
... | ... | @@ -1,99 +0,0 @@ |
1 | -package com.shunzhi.parent.util; | |
2 | - | |
3 | -import android.content.Context; | |
4 | -import android.database.sqlite.SQLiteDatabase; | |
5 | - | |
6 | -import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; | |
7 | -import com.j256.ormlite.dao.Dao; | |
8 | -import com.j256.ormlite.support.ConnectionSource; | |
9 | -import com.j256.ormlite.table.TableUtils; | |
10 | -import com.shunzhi.parent.bean.ChildBean; | |
11 | - | |
12 | -import java.sql.SQLException; | |
13 | -import java.util.HashMap; | |
14 | -import java.util.Map; | |
15 | - | |
16 | -/** | |
17 | - * Created by ToaHanDong on 2017/3/24. | |
18 | - */ | |
19 | - | |
20 | -public class DatabaseHelper extends OrmLiteSqliteOpenHelper { | |
21 | - private static final String TABLE_NAME = "parent.db"; | |
22 | - private Map<String, Dao> daos = new HashMap<String, Dao>(); | |
23 | - private static DatabaseHelper instance; | |
24 | - | |
25 | - public DatabaseHelper(Context context){ | |
26 | - super(context,TABLE_NAME,null,1); | |
27 | - } | |
28 | - | |
29 | - /* | |
30 | - 创建数据库 | |
31 | - */ | |
32 | - @Override | |
33 | - public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { | |
34 | - try { | |
35 | - TableUtils.createTableIfNotExists(connectionSource, ChildBean.class); | |
36 | - } catch (SQLException e) { | |
37 | - e.printStackTrace(); | |
38 | - } | |
39 | - } | |
40 | - | |
41 | - @Override | |
42 | - public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { | |
43 | - try { | |
44 | - TableUtils.dropTable(connectionSource,ChildBean.class,true); | |
45 | - onCreate(database,connectionSource); | |
46 | - } catch (SQLException e) { | |
47 | - e.printStackTrace(); | |
48 | - } | |
49 | - } | |
50 | - | |
51 | - //删除数据库 | |
52 | - public void deleteAll(){ | |
53 | - try { | |
54 | - TableUtils.dropTable(connectionSource,ChildBean.class,true); | |
55 | - } catch (SQLException e) { | |
56 | - e.printStackTrace(); | |
57 | - } | |
58 | - } | |
59 | - | |
60 | - public static synchronized DatabaseHelper getHelper(Context context){ | |
61 | - context=context.getApplicationContext(); | |
62 | - if (null==instance){ | |
63 | - synchronized (DatabaseHelper.class){ | |
64 | - if (null==instance){ | |
65 | - instance=new DatabaseHelper(context); | |
66 | - } | |
67 | - } | |
68 | - } | |
69 | - return instance; | |
70 | - } | |
71 | - | |
72 | - public synchronized Dao getDao(Class clazz) throws SQLException { | |
73 | - Dao dao = null; | |
74 | - String className = clazz.getSimpleName(); | |
75 | - | |
76 | - if (daos.containsKey(className)) { | |
77 | - dao = daos.get(className); | |
78 | - } | |
79 | - if (dao == null) { | |
80 | - dao = super.getDao(clazz); | |
81 | - daos.put(className, dao); | |
82 | - } | |
83 | - return dao; | |
84 | - } | |
85 | - | |
86 | - /** | |
87 | - * 释放资源 | |
88 | - */ | |
89 | - @Override | |
90 | - public void close() { | |
91 | - super.close(); | |
92 | - | |
93 | - for (String key : daos.keySet()) | |
94 | - { | |
95 | - Dao dao = daos.get(key); | |
96 | - dao = null; | |
97 | - } | |
98 | - } | |
99 | -} |
app/src/main/res/layout/fragment_report.xml