Search in sources :

Example 6 with Path

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;
    });
}
Also used : Path(com.jakdor.labday.common.model.Path) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 7 with Path

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);
}
Also used : Path(com.jakdor.labday.common.model.Path) AppData(com.jakdor.labday.common.model.AppData) ArrayList(java.util.ArrayList)

Example 8 with Path

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;
}
Also used : Path(com.jakdor.labday.common.model.Path) ContentValues(android.content.ContentValues)

Example 9 with Path

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("");
    }
}
Also used : Path(com.jakdor.labday.common.model.Path)

Example 10 with Path

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();
}
Also used : Path(com.jakdor.labday.common.model.Path) TimetableAdapter(com.jakdor.labday.view.adapter.TimetableAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

Path (com.jakdor.labday.common.model.Path)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Random (java.util.Random)4 ContentValues (android.content.ContentValues)3 Cursor (android.database.Cursor)3 PathDao (com.jakdor.labday.common.dao.PathDao)2 List (java.util.List)2 NestedScrollView (android.support.v4.widget.NestedScrollView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 TextView (android.widget.TextView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AppData (com.jakdor.labday.common.model.AppData)1 TimetableAdapter (com.jakdor.labday.view.adapter.TimetableAdapter)1