Search in sources :

Example 1 with Test

use of com.giua.objects.Test in project Giua-App by Giua-app.

the class DBController method readTests.

public List<Test> readTests() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + TESTS_TABLE, null);
    List<Test> tests = new Vector<>();
    if (cursor.moveToFirst()) {
        boolean exists = cursor.getInt(DBTest.EXISTS_COL.ordinal()) != 0;
        do {
            tests.add(new Test(cursor.getString(DBTest.DATE_COL.ordinal()).split("-")[2], cursor.getString(DBTest.DATE_COL.ordinal()).split("-")[1], cursor.getString(DBTest.DATE_COL.ordinal()).split("-")[0], cursor.getString(DBTest.DATE_COL.ordinal()), cursor.getString(DBTest.SUBJECT_COL.ordinal()), cursor.getString(DBTest.CREATOR_COL.ordinal()), cursor.getString(DBTest.DETAILS_COL.ordinal()), exists));
        } while (cursor.moveToNext());
    // muovi il cursore nella prossima riga
    }
    cursor.close();
    return tests;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(com.giua.objects.Test) Cursor(android.database.Cursor) Vector(java.util.Vector)

Example 2 with Test

use of com.giua.objects.Test in project Giua-App by Giua-app.

the class DBController method addTests.

public void addTests(List<Test> tests) {
    SQLiteDatabase db = getWritableDatabase();
    for (Test test : tests) {
        addTest(test, db);
    }
    db.close();
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(com.giua.objects.Test)

Example 3 with Test

use of com.giua.objects.Test in project Giua-App by Giua-app.

the class OfflineDBController method addTests.

public void addTests(List<Test> tests) {
    SQLiteDatabase db = getWritableDatabase();
    for (Test test : tests) {
        addTest(test, db);
    }
    db.close();
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(com.giua.objects.Test)

Example 4 with Test

use of com.giua.objects.Test in project Giua-App by Giua-app.

the class AgendaView method initializeComponent.

private void initializeComponent(Context context) {
    // Rappresenta il giorno del compito o della verifica
    Calendar objectDay = Calendar.getInstance();
    loggerManager = new LoggerManager("AgendaView", context);
    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutInflater.inflate(R.layout.view_agenda, this);
    TextView tvTime = findViewById(R.id.agenda_view_time);
    TextView tvDate = findViewById(R.id.agenda_view_date);
    TextView tvSubject = findViewById(R.id.agenda_view_subject);
    TextView tvTeacher = findViewById(R.id.agenda_view_teacher);
    TextView tvText = findViewById(R.id.agenda_view_text);
    TextView tvType = findViewById(R.id.agenda_view_type);
    LinearLayout layout = findViewById(R.id.agenda_view_layout);
    if (getRepresentedObject() == Homework.class) {
        Homework homework = (Homework) agendaObject;
        objectDay.set(Integer.parseInt(homework.year), Integer.parseInt(homework.month) - 1, Integer.parseInt(homework.day), 23, 59, 59);
        tvDate.setText(homework.day + "-" + homework.month + "-" + homework.year);
        tvType.setText(R.string.agenda_view_type_homeworks);
        tvText.setText(homework.details);
        tvSubject.setText(homework.subject.split(": ")[1]);
        tvTeacher.setText(homework.creator);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_cyan, context.getTheme()));
    } else if (getRepresentedObject() == Test.class) {
        Test test = (Test) agendaObject;
        objectDay.set(Integer.parseInt(test.year), Integer.parseInt(test.month) - 1, Integer.parseInt(test.day), 23, 59, 59);
        tvDate.setText(test.day + "-" + test.month + "-" + test.year);
        tvType.setText(R.string.agenda_view_type_tests);
        tvText.setText(test.details);
        tvSubject.setText(test.subject);
        tvTeacher.setText(test.creator);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_orange, context.getTheme()));
    } else if (getRepresentedObject() == com.giua.objects.Activity.class) {
        com.giua.objects.Activity activity = (com.giua.objects.Activity) agendaObject;
        objectDay.set(Integer.parseInt(activity.year), Integer.parseInt(activity.month) - 1, Integer.parseInt(activity.day), 23, 59, 59);
        tvDate.setText(activity.day + "-" + activity.month + "-" + activity.year);
        tvType.setText(R.string.agenda_view_type_activities);
        tvText.setText(activity.details);
        tvSubject.setVisibility(GONE);
        tvTeacher.setVisibility(GONE);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_green, context.getTheme()));
    } else if (getRepresentedObject() == InterviewAgenda.class) {
        InterviewAgenda test = (InterviewAgenda) agendaObject;
        objectDay.set(Integer.parseInt(test.year), Integer.parseInt(test.month) - 1, Integer.parseInt(test.day), 23, 59, 59);
        tvDate.setText(test.day + "-" + test.month + "-" + test.year);
        tvType.setText(R.string.agenda_view_type_interviews);
        tvText.setText(test.details);
        tvSubject.setText(test.period);
        tvTeacher.setText(test.creator);
        layout.setBackgroundTintList(ResourcesCompat.getColorStateList(getResources(), R.color.adaptive_agenda_views_purple, context.getTheme()));
    }
    // Calendar fake = Calendar.getInstance();
    // fake.set(Calendar.MONTH, 11);
    // fake.set(Calendar.DAY_OF_MONTH, 29);
    int timeDiff = calcTimeDifferenceInDay(Calendar.getInstance(), objectDay);
    loggerManager.d("mancano " + timeDiff + " giorni al compito del " + objectDay.get(Calendar.DAY_OF_MONTH) + "/" + objectDay.get(Calendar.MONTH) + "/" + objectDay.get(Calendar.YEAR));
    if (timeDiff < 0)
        if (timeDiff == -1)
            tvTime.setText("Ieri");
        else
            tvTime.setText(Math.abs(timeDiff) + " giorni fa");
    else {
        switch(timeDiff) {
            case 3:
                tvTime.setTextColor(getResources().getColor(R.color.middle_vote_lighter, context.getTheme()));
                tvTime.setText("Tra " + timeDiff + " giorni");
                break;
            case 2:
                tvTime.setTextColor(getResources().getColor(R.color.middle_vote_no_night, context.getTheme()));
                tvTime.setText("Tra " + timeDiff + " giorni");
                break;
            case 1:
                tvTime.setTextColor(getResources().getColor(R.color.bad_vote, context.getTheme()));
                tvTime.setText("Domani");
                break;
            case 0:
                tvTime.setTextColor(getResources().getColor(R.color.bad_vote, context.getTheme()));
                tvTime.setText("Oggi");
                break;
            default:
                tvTime.setText("Tra " + timeDiff + " giorni");
                break;
        }
    }
}
Also used : Calendar(java.util.Calendar) Test(com.giua.objects.Test) InterviewAgenda(com.giua.objects.InterviewAgenda) LayoutInflater(android.view.LayoutInflater) LoggerManager(com.giua.app.LoggerManager) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) Homework(com.giua.objects.Homework)

Example 5 with Test

use of com.giua.objects.Test in project Giua-App by Giua-app.

the class OfflineDBController method readTests.

public List<Test> readTests() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + TESTS_TABLE, null);
    List<Test> tests = new Vector<>();
    if (cursor.moveToFirst()) {
        boolean exists = cursor.getInt(DBTest.EXISTS_COL.ordinal()) != 0;
        do {
            tests.add(new Test(cursor.getString(DBTest.DATE_COL.ordinal()).split("-")[2], cursor.getString(DBTest.DATE_COL.ordinal()).split("-")[1], cursor.getString(DBTest.DATE_COL.ordinal()).split("-")[0], cursor.getString(DBTest.DATE_COL.ordinal()), cursor.getString(DBTest.SUBJECT_COL.ordinal()), cursor.getString(DBTest.CREATOR_COL.ordinal()), cursor.getString(DBTest.DETAILS_COL.ordinal()), exists));
        } while (cursor.moveToNext());
    // muovi il cursore nella prossima riga
    }
    cursor.close();
    return tests;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(com.giua.objects.Test) Cursor(android.database.Cursor) Vector(java.util.Vector)

Aggregations

Test (com.giua.objects.Test)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Cursor (android.database.Cursor)2 Vector (java.util.Vector)2 LayoutInflater (android.view.LayoutInflater)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 LoggerManager (com.giua.app.LoggerManager)1 Homework (com.giua.objects.Homework)1 InterviewAgenda (com.giua.objects.InterviewAgenda)1 Calendar (java.util.Calendar)1