use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class PathDao method getAllPaths.
public static Observable<List<Path>> getAllPaths(BriteDatabase db) {
Observable<SqlBrite.Query> dbQuery = db.createQuery(TABLE, "SELECT * FROM " + TABLE);
return dbQuery.map(query -> {
ArrayList<Path> paths = new ArrayList<>();
Cursor cursor = query.run();
if (cursor == null) {
return paths;
}
while (cursor.moveToNext()) {
paths.add(new Path(cursor.getInt(cursor.getColumnIndex(ID)), cursor.getString(cursor.getColumnIndex(NAME)), cursor.getString(cursor.getColumnIndex(INFO)), cursor.getInt(cursor.getColumnIndex(ACTIVE)) == 1));
}
cursor.close();
return paths;
});
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class MainFragmentTest method initMockData.
private void initMockData() {
AppData data = new AppData();
ArrayList<Path> paths = new ArrayList<>();
paths.add(new Path(1, "dummyNameWrong", "PathInfoWrong", false));
paths.add(new Path(2, "dummyName", "PathInfo", true));
data.setPaths(paths);
appData.setValue(RxResponse.success(data));
loadingStatus.setValue(false);
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class PathDao method insertPathList.
public static long insertPathList(BriteDatabase db, List<Path> paths) {
long pos = -1;
for (Path path : paths) {
ContentValues values = new Builder().id(path.getId()).name(path.getName()).info(path.getInfo()).active(path.getActive()).build();
pos = db.insert(TABLE, CONFLICT_FAIL, values);
}
return pos;
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class MainFragment method processResponse.
/**
* Set path name in timetable card
*/
public void processResponse(RxResponse<AppData> response) {
// stop swipe to refresh anim
binding.swiperefreshMain.setRefreshing(false);
if (response.status == RxStatus.SUCCESS || response.status == RxStatus.SUCCESS_DB) {
if (response.data != null) {
for (Path path : response.data.getPaths()) {
if (path.getActive()) {
activePath = path;
binding.setPath(activePath.getName());
break;
}
}
}
} else {
if (response.error != null) {
Timber.e(response.error.toString());
}
binding.setPath("");
}
}
use of com.jakdor.labday.common.model.Path in project LabDayApp by jakdor.
the class TimetableFragment method loadRecyclerView.
/**
* Load RecyclerView, and path info to bar
* @param appData from repository
* @param activePathId id of active Path
*/
private void loadRecyclerView(AppData appData, int activePathId) {
for (Path path : appData.getPaths()) {
if (path.getId() == activePathId) {
binding.setTitle(path.getInfo());
break;
}
}
RecyclerView recyclerView = binding.timetableRecyclerView;
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
TimetableAdapter timetableAdapter = new TimetableAdapter(this, appData, activePathId, GlideApp.with(this), getHeight());
recyclerView.setAdapter(timetableAdapter);
recyclerView.invalidate();
}
Aggregations