Search in sources :

Example 1 with InterviewAgenda

use of com.giua.objects.InterviewAgenda 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)

Aggregations

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 Test (com.giua.objects.Test)1 Calendar (java.util.Calendar)1