org.litepal.crud.DataSupport Java Examples
The following examples show how to use
org.litepal.crud.DataSupport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CityChooseActivity.java From FakeWeather with Apache License 2.0 | 6 votes |
@Override protected void loadData() { DataSupport.findAllAsync(HeWeatherCity.class).listen(new FindMultiCallback() { @Override public <T> void onFinish(List<T> t) { List<HeWeatherCity> list = (List<HeWeatherCity>) t; HashSet<String> provinces = new HashSet<>(); for (HeWeatherCity city : list) { provinces.add(city.getProvinceZh()); } List<String> provinceArray = new ArrayList<>(provinces); List<SimpleItem> datas = new ArrayList<>(); for (String s : provinceArray) { datas.add(new SimpleItem(s)); } provinceAdapter.setNewData(datas); } }); }
Example #2
Source File: MainActivity.java From Ucount with GNU General Public License v3.0 | 6 votes |
public void initBookItemList(final Context context) { bookItemList = DataSupport.findAll(BookItem.class); if (bookItemList.isEmpty()) { BookItem bookItem = new BookItem(); bookItem.saveBook(bookItem, 1, "默认账本"); bookItem.setSumAll(0.0); bookItem.setSumMonthlyCost(0.0); bookItem.setSumMonthlyEarn(0.0); bookItem.setDate(sumDate); bookItem.save(); bookItemList = DataSupport.findAll(BookItem.class); } setBookItemRecyclerView(context); }
Example #3
Source File: ChooseAreaFragment.java From coolweather with Apache License 2.0 | 6 votes |
/** * 查询选中市内所有的县,优先从数据库查询,如果没有查询到再去服务器上查询。 */ private void queryCounties() { titleText.setText(selectedCity.getCityName()); backButton.setVisibility(View.VISIBLE); countyList = DataSupport.where("cityid = ?", String.valueOf(selectedCity.getId())).find(County.class); if (countyList.size() > 0) { dataList.clear(); for (County county : countyList) { dataList.add(county.getCountyName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); currentLevel = LEVEL_COUNTY; } else { int provinceCode = selectedProvince.getProvinceCode(); int cityCode = selectedCity.getCityCode(); String address = "http://guolin.tech/api/china/" + provinceCode + "/" + cityCode; queryFromServer(address, "county"); } }
Example #4
Source File: NewsDALManager.java From BaoKanAndroid with MIT License | 6 votes |
/** * 从本地加载资讯内容数据 * * @param classid 分类id * @param id 文章id * @param newsContentCallback 资讯内容回调 */ private void loadNewsContentFromLocal(String classid, String id, NewsContentCallback newsContentCallback) { NewsContentCache contentCache = DataSupport.where("classid = ? and articleid = ?", classid, id).findFirst(NewsContentCache.class); if (contentCache != null) { try { JSONObject jsonObject = new JSONObject(contentCache.getNews()); newsContentCallback.onSuccess(jsonObject); LogUtils.d(TAG, "加载到缓存资讯内容数据 = " + jsonObject.toString()); } catch (JSONException e) { e.printStackTrace(); newsContentCallback.onError("数据解析异常"); } } else { newsContentCallback.onError("没有缓存数据"); } }
Example #5
Source File: LabelPopup.java From eBook with Apache License 2.0 | 6 votes |
public LabelPopup(Context context, int bookId) { super(context); mBookId = bookId; mLinearLayout = (LinearLayout) mConvertView.findViewById(R.id.pop_label_linear_layout); mClearFab = (FloatingActionButton) mConvertView.findViewById(R.id.pop_label_clear); mRecyclerView = (RecyclerView) mConvertView.findViewById(R.id.pop_label_recycle_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); updateUI(); mClearFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DataSupport.deleteAll(Label.class, "mBookId=?", mBookId + ""); updateUI(); } }); }
Example #6
Source File: MeFragment.java From SmallGdufe-Android with GNU General Public License v3.0 | 6 votes |
private void queryBasicInfo(){ factory.getBasicInfo(new Observer<BasicInfo>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(BasicInfo value) { DataSupport.deleteAll(BasicInfo.class); value.save(); setBasicInfo4View(value); } @Override public void onError(Throwable e) { if(e != null && !TextUtils.isEmpty(e.getMessage())) { LogUtils.e(e.toString()); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } @Override public void onComplete() { } }); }
Example #7
Source File: ModuleManageActivity.java From FakeWeather with Apache License 2.0 | 6 votes |
@Override public void onBackPressed() { DataSupport.order("index").findAsync(Module.class).listen(new FindMultiCallback() { @Override public <T> void onFinish(List<T> t) { List<Module> saved = (List<Module>) t; for (int i = 0; i < saved.size(); i++) { if (!saved.get(i).equals(adapter.getData().get(i))) { dataChanged = true; break; } } for (int i = 0; i < adapter.getData().size(); i++) { ContentValues values = new ContentValues(); values.put("index", i); values.put("enable", adapter.getItem(i).isEnable()); DataSupport.updateAll(Module.class, values, "name = ?", adapter.getItem(i).getName()); } if (dataChanged) { EventBus.getDefault().post(new ModuleChangedEvent()); } ModuleManageActivity.super.onBackPressed(); } }); }
Example #8
Source File: CityChooseActivity.java From FakeWeather with Apache License 2.0 | 6 votes |
private void queryLeader(String provice) { DataSupport.where("provinceZh = ?", provice).findAsync(HeWeatherCity.class).listen(new FindMultiCallback() { @Override public <T> void onFinish(List<T> t) { List<HeWeatherCity> list = (List<HeWeatherCity>) t; HashSet<String> leaders = new HashSet<>(); for (HeWeatherCity city : list) { leaders.add(city.getLeaderZh()); } List<String> leaderArray = new ArrayList<>(leaders); List<SimpleItem> datas = new ArrayList<>(); for (String s : leaderArray) { datas.add(new SimpleItem(s)); } leaderAdapter.setNewData(datas); } }); }
Example #9
Source File: CityChooseActivity.java From FakeWeather with Apache License 2.0 | 6 votes |
private void queryCity(String provice) { DataSupport.where("leaderZh = ?", provice).findAsync(HeWeatherCity.class).listen(new FindMultiCallback() { @Override public <T> void onFinish(List<T> t) { List<HeWeatherCity> list = (List<HeWeatherCity>) t; HashSet<String> citys = new HashSet<>(); for (HeWeatherCity city : list) { citys.add(city.getCityZh()); } List<String> cityArray = new ArrayList<>(citys); List<SimpleItem> datas = new ArrayList<>(); for (String s : cityArray) { datas.add(new SimpleItem(s)); } cityAdapter.setNewData(datas); } }); }
Example #10
Source File: CityManageActivity.java From FakeWeather with Apache License 2.0 | 6 votes |
private void updateCity(IFakeWeather weather) { for (int i = 0; i < adapter.getData().size(); i++) { if (weather.getFakeBasic().getCityName().equals(adapter.getItem(i).getCityName())) { adapter.getItem(i).setWeatherCode(weather.getFakeNow().getNowCode()); adapter.getItem(i).setWeatherTemp(weather.getFakeNow().getNowTemp()); adapter.getItem(i).setWeatherText(weather.getFakeNow().getNowText()); adapter.notifyItemChanged(i); ContentValues values = new ContentValues(); values.put("weatherCode", weather.getFakeNow().getNowCode()); values.put("weatherText", weather.getFakeNow().getNowText()); values.put("weatherTemp", weather.getFakeNow().getNowTemp()); DataSupport.updateAll(WeatherCity.class, values, "cityName = ?", weather.getFakeBasic().getCityName()); break; } } }
Example #11
Source File: HomeFragment.java From SmallGdufe-Android with GNU General Public License v3.0 | 6 votes |
private void initViewByDb() { int currentWeek = Integer.parseInt(FileUtils.getCurrentWeek(getActivity())); List<Schedule> list = DataSupport.findAll(Schedule.class); mScheduleView.cleanScheduleData(); if(list.size() == 0) { //空数据,有界面 mScheduleView.setScheduleData(new ArrayList<Schedule>()); }else{ //无设置按周看则显示全部,否则显示特定周数 if(currentWeek == FileUtils.SP_WEEK_NOT_SET) { mScheduleView.setScheduleData(list); }else{ mScheduleView.setScheduleData(list, currentWeek); } } }
Example #12
Source File: BookMarkFragment.java From Jreader with GNU General Public License v2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_mark,container,false); markListview = (ListView) view.findViewById(R.id.marklistview); initDeleteMarkPop(); markListview.setOnItemClickListener(this); markListview.setOnItemLongClickListener(this); Bundle bundle = getArguments(); if (bundle != null) { mArgument = bundle.getString(ARGUMENT); } bookMarksList = new ArrayList<>(); bookMarksList = DataSupport.where("bookpath = ?", mArgument).find(BookMarks.class); MarkAdapter markAdapter = new MarkAdapter(getActivity(), bookMarksList); markListview.setAdapter(markAdapter); return view; }
Example #13
Source File: NewsDALManager.java From LiuAGeAndroid with MIT License | 6 votes |
/** * 从本地加载资讯内容数据 * * @param classid 分类id * @param id 文章id * @param newsContentCallback 资讯内容回调 */ private void loadNewsContentFromLocal(String classid, String id, NewsContentCallback newsContentCallback) { NewsContentCache contentCache = DataSupport.where("classid = ? and articleid = ?", classid, id).findFirst(NewsContentCache.class); if (contentCache != null) { try { JSONObject jsonObject = new JSONObject(contentCache.getNews()); newsContentCallback.onSuccess(jsonObject); LogUtils.d(TAG, "加载到缓存资讯内容数据 = " + jsonObject.toString()); } catch (JSONException e) { e.printStackTrace(); newsContentCallback.onError("数据解析异常"); } } else { newsContentCallback.onError("没有缓存数据"); } }
Example #14
Source File: NewsDALManager.java From LiuAGeAndroid with MIT License | 6 votes |
/** * 加载本地关键词数据模型集合 * * @param keyboard 需要搜索的关键词 * @return 关键词模型集合 */ public List<KeyboardCache> loadKeyboardListFromLocation(String keyboard) { if (keyboard.length() == 0) { return new ArrayList<>(); } List<KeyboardCache> keyboardCacheList = new ArrayList<>(); Cursor cursor = DataSupport.findBySQL("select * from keyboardcache where keyboard like ? or pinyin like ? order by num desc limit 20", "%" + keyboard + "%", "%" + keyboard + "%"); if (cursor.moveToFirst()) { do { KeyboardCache keyboardCache = new KeyboardCache(); keyboardCache.setKeyboard(cursor.getString(cursor.getColumnIndex("keyboard"))); keyboardCache.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin"))); keyboardCache.setNum(cursor.getInt(cursor.getColumnIndex("num"))); keyboardCacheList.add(keyboardCache); } while (cursor.moveToNext()); } return keyboardCacheList; }
Example #15
Source File: NoteFolderModel.java From SuperNote with GNU General Public License v3.0 | 6 votes |
@Override public int initNoteFolderAndGetFolderId() { NoteFolder folder1 = new NoteFolder(); folder1.setFolderName("随手记"); folder1.setNoteCount(5); addNoteFolder(folder1); NoteFolder noteFolder2 = new NoteFolder(); noteFolder2.setFolderName("生活"); noteFolder2.setNoteCount(0); addNoteFolder(noteFolder2); NoteFolder noteFolder3 = new NoteFolder(); noteFolder3.setFolderName("工作"); addNoteFolder(noteFolder3); NoteFolder folder=DataSupport.where("folderName = ? ","随手记").find(NoteFolder.class).get(0); return folder.getId(); }
Example #16
Source File: ChooseCity.java From YourWeather with Apache License 2.0 | 6 votes |
/** * 查询县城 */ private void queryCounty() { toolbarTitle.setTitle(selectedCity.getCityName()); countyList = DataSupport.where("cityid = ?", String.valueOf(selectedCity.getId())).find(County.class); if (countyList.size() > 0) { dataList.clear(); for (County county : countyList) { dataList.add(county.getCountyName()); } mCityAdapter.notifyDataSetChanged(); recyclerView.smoothScrollToPosition(0); currentLeveL = LEVEL_COUNTY; } else { int provinceCode = selectedProvince.getProvinceCode(); int cityCode = selectedCity.getCityCode(); Log.d("TAG", String.valueOf(cityCode)); String address = "http://guolin.tech/api/china/" + provinceCode + "/" + cityCode; queryFromServer(address, "county"); Log.d("queryCounty",address); } }
Example #17
Source File: ChooseCity.java From YourWeather with Apache License 2.0 | 6 votes |
/** * 查询城市 */ private void queryCity() { toolbarTitle.setTitle(selectedProvince.getProvinceName()); cityList = DataSupport.where("provinceid=?", String.valueOf(selectedProvince.getId())).find(City.class); if (cityList.size() > 0) { dataList.clear(); for (City city : cityList) { dataList.add(city.getCityName()); } mCityAdapter.notifyDataSetChanged(); recyclerView.smoothScrollToPosition(0); currentLeveL = LEVEL_CITY; } else { int provinceCode = selectedProvince.getProvinceCode(); String address = "http://guolin.tech/api/china/" + provinceCode; queryFromServer(address, "city"); } }
Example #18
Source File: FileAcitvity.java From Jreader with GNU General Public License v2.0 | 5 votes |
/** * 添加书本到数据库 */ public void saveBooktoSqlite3 (final String bookName,final String key,final BookList bookList ) { putAsyncTask(new AsyncTask<Void, Void, Boolean>() { @Override protected void onPreExecute() { //可以进行界面上的初始化操作 } @Override protected Boolean doInBackground(Void... params) { try { String sql = "SELECT id FROM booklist WHERE bookname =? and bookpath =?"; Cursor cursor = DataSupport.findBySQL(sql, bookName, key); if (!cursor.moveToFirst()) { //This method will return false if the cursor is empty bookList.save(); } else { return false; } } catch (Exception e) { // return false; } return true; } @Override protected void onPostExecute(Boolean result) { if (result) { } else { // Toast.makeText(getApplicationContext(), bookName+"已在书架了", Toast.LENGTH_SHORT).show(); } } }); }
Example #19
Source File: MainActivity.java From Jreader with GNU General Public License v2.0 | 5 votes |
@Override protected void onRestart(){ DragGridView.setIsShowDeleteButton(false); bookLists = new ArrayList<>(); bookLists = DataSupport.findAll(BookList.class); adapter = new ShelfAdapter(MainActivity.this,bookLists); bookShelf.setAdapter(adapter); adapter.notifyDataSetChanged(); closeBookAnimation(); super.onRestart(); }
Example #20
Source File: SearchPresenter.java From UGank with GNU General Public License v3.0 | 5 votes |
@Override public void queryHistory() { // 展示查询所有,需要截取、去重和排序 List<History> historyList = DataSupport.order("createTimeMill desc").limit(10).find(History.class); // 将查询结果转为list对象 if (historyList == null || historyList.size() < 1) { mView.showSearchResult(); } else { mView.setHistory(historyList); } }
Example #21
Source File: ChooseAreaActivity.java From BS-Weather with Apache License 2.0 | 5 votes |
/** * 显示数据库中保存的信息 */ public void showRecond(){ recondList.clear(); List<CityRecond> list = DataSupport.select("cityName").find(CityRecond.class); for (CityRecond recond:list){ recondList.add(recond.getCityName()); } recondAdapter.notifyDataSetChanged(); listViewRecond.setSelection(0); }
Example #22
Source File: CalcUtils.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
/** * 获取当前登陆学号的大一那年的年份,如2013级则返回13(即使现在是2017年),从而构造2013-2014(大一) 这种选择框 * @return int 13 */ public static int getFirstYear(){ int firstYear = 13; //校友则学年根据个人信息的班级获取,正常账号直接截学号 if(AppConfig.schoolmateSno.equals(AppConfig.sno)) { BasicInfo basicInfo = DataSupport.findFirst(BasicInfo.class); if(basicInfo == null){ LogUtils.e("校友学年获取失败"); } firstYear = Integer.parseInt(basicInfo != null ? basicInfo.getClassroom().substring(2, 4) : "13"); }else { firstYear = Integer.parseInt(AppConfig.sno.substring(0, 2)); } return firstYear; }
Example #23
Source File: DBManager.java From LQRWeChat with MIT License | 5 votes |
public synchronized Groups getGroupsById(String groupId) { if (!TextUtils.isEmpty(groupId)) { List<Groups> groupses = DataSupport.where("groupid = ?", groupId).find(Groups.class); if (groupses != null && groupses.size() > 0) { return groupses.get(0); } } return null; }
Example #24
Source File: DBManager.java From LQRWeChat with MIT License | 5 votes |
public synchronized void saveGroups(List<GetGroupResponse.ResultEntity> list) { if (list != null && list.size() > 0) { mGroupsList = new ArrayList<>(); for (GetGroupResponse.ResultEntity groups : list) { String portrait = groups.getGroup().getPortraitUri(); if (TextUtils.isEmpty(portrait)) { portrait = RongGenerate.generateDefaultAvatar(groups.getGroup().getName(), groups.getGroup().getId()); } mGroupsList.add(new Groups(groups.getGroup().getId(), groups.getGroup().getName(), portrait, String.valueOf(groups.getRole()))); } } if (mGroupsList.size() > 0) DataSupport.saveAll(mGroupsList); }
Example #25
Source File: ChatRobotActivity.java From LLApp with Apache License 2.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.action_robot: //清空聊天记录 DataSupport.deleteAll(Message.class); mMsgs.clear(); mAdapter.notifyDataSetChanged(); break; } return super.onOptionsItemSelected(item); }
Example #26
Source File: NoteFolderModel.java From SuperNote with GNU General Public License v3.0 | 5 votes |
@Override public void deleteNoteFolder(NoteFolder folder) { int folderId=folder.getId(); List<Note> list=new ArrayList<Note>(); list= DataSupport.where("NoteFolderId = ? and inRecycleBin = ?",folderId+"","0").find(Note.class); for(int i=0;i<list.size();i++){ Note note=list.get(i); mNoteModel.deleteNote(note); } folder.delete(); }
Example #27
Source File: MigrationUtil.java From ankihelper with GNU General Public License v3.0 | 5 votes |
public static boolean needMigration(){ List<OutputPlan> oldPlan = DataSupport.findAll(OutputPlan.class); List<History> oldHistory = DataSupport.findAll(History.class); if(oldPlan.size() == 0 && oldHistory.size() == 0){ return false; }else{ return true; } }
Example #28
Source File: MigrationUtil.java From ankihelper with GNU General Public License v3.0 | 5 votes |
public static void migrate(){ List<OutputPlan> oldPlan = DataSupport.findAll(OutputPlan.class); if(oldPlan.size() > 0) { List<OutputPlanPOJO> newPlan = new ArrayList<>(); for (OutputPlan outputPlan : oldPlan) { OutputPlanPOJO np = new OutputPlanPOJO(); np.setFieldsMap(outputPlan.getFieldsMap()); np.setOutputModelId(outputPlan.getOutputModelId()); np.setOutputDeckId(outputPlan.getOutputDeckId()); np.setDictionaryKey(outputPlan.getDictionaryKey()); np.setPlanName(outputPlan.getPlanName()); newPlan.add(np); } ExternalDatabase.getInstance().refreshPlanWith(newPlan); DataSupport.deleteAll(OutputPlan.class); } List<History> oldHistory = DataSupport.findAll(History.class); List<HistoryPOJO> newHistory = new ArrayList<>(); for(History history : oldHistory){ HistoryPOJO hpojo = new HistoryPOJO(); hpojo.setWord(history.getWord()); hpojo.setType(history.getType()); hpojo.setSentence(history.getSentence()); hpojo.setNote(history.getNote()); hpojo.setDictionary(history.getDictionary()); hpojo.setDefinition(history.getDefinition()); hpojo.setTimeStamp(history.getTimeStamp()); newHistory.add(hpojo); } ExternalDatabase.getInstance().insertManyHistory(newHistory); DataSupport.deleteAll(History.class); }
Example #29
Source File: AppUtils.java From NetKnight with Apache License 2.0 | 5 votes |
/** * 从appInfo中读取信息 * @param context * @return */ public static List<App> queryAppInfo(Context context){ List<App> appList = DataSupport.findAll(App.class); if(appList == null||appList.size()==0){ Log.d("AppUtils","执行初始化数据咯"); initAppInfo(context); appList = DataSupport.findAll(App.class); } //获取icon的drawble信息 for(int i=0;i<appList.size();i++){ App appInfo = appList.get(i); try { appInfo.setIcon(context.getPackageManager().getApplicationIcon(appInfo.getPkgname())); } catch (PackageManager.NameNotFoundException e) { Log.e("AppUtils","setIcon failed"); e.printStackTrace(); } } return appList; }
Example #30
Source File: HomeFragment.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
private void realQuerySchedule(String studyTime){ factory.getSchedule(studyTime,JwApiFactory.MERGE_SCHEDULE, new Observer<List<Schedule>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(List<Schedule> value) { if(value.size()==0){ Toast.makeText(getActivity(), "没有喔", Toast.LENGTH_SHORT).show(); return; } mScheduleView.cleanScheduleData(); mScheduleView.setScheduleData(value); DataSupport.deleteAll(Schedule.class); DataSupport.saveAll(value); } @Override public void onError(Throwable e) { LogUtils.e(e.getMessage()); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); } @Override public void onComplete() { } }); }