Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new features to attendance #188

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ android {
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
version "3.22.1"
}
}
lint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

package pl.szczodrzynski.edziennik.config

import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_ALPHABET

@Suppress("RemoveExplicitTypeArguments")
class ProfileConfigAttendance(base: ProfileConfig) {

var attendancePageSelection by base.config<Int>(1)
var groupConsecutiveDays by base.config<Boolean>(true)
var showPresenceInMonth by base.config<Boolean>(false)
var useSymbols by base.config<Boolean>(false)
var showDifference by base.config<Boolean>(false)
var orderBy by base.config<Int>(SORTED_BY_ALPHABET)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ abstract class AttendanceDao : BaseDao<Attendance, AttendanceFull> {
// GET ALL - LIVE DATA
fun getAll(profileId: Int) =
getRaw("$QUERY WHERE attendances.profileId = $profileId $ORDER_BY")

// GET ALL - NOW
fun getAllNow(profileId: Int) =
getRawNow("$QUERY WHERE attendances.profileId = $profileId $ORDER_BY")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import pl.szczodrzynski.edziennik.ui.attendance.AttendanceFragment.Companion.VIE
import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceSubject
import pl.szczodrzynski.edziennik.ui.base.lazypager.LazyFragment
import pl.szczodrzynski.edziennik.ui.grades.models.GradesSubject
import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_ALPHABET
import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_HIGHEST
import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_LOWEST
import pl.szczodrzynski.edziennik.utils.models.Date
import java.text.DecimalFormat
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -215,6 +218,8 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
totalCountSum += totalCount
presenceCountSum += presenceCount

subject.presenceDifference = presenceCount - (totalCount-presenceCount);

subject.percentage = if (totalCount == 0)
0f
else
Expand Down Expand Up @@ -286,7 +291,11 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope {
}
}

return items.toMutableList()
return when(manager.orderBy){
SORTED_BY_HIGHEST -> items.sortedByDescending { it.percentage }.toMutableList()
SORTED_BY_LOWEST -> items.sortedBy { it.percentage }.toMutableList()
else -> items.sortedBy { it.subjectName.lowercase() }.toMutableList()
}
}

private fun animatePercentageIndicator(targetProgress: Double) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ data class AttendanceSubject(

var typeCountMap: Map<AttendanceType, Int> = mapOf()
var percentage: Float = 0f
var presenceDifference: Int = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ class SubjectViewHolder(
}
else {
b.percentage.setText(R.string.attendance_percentage_format, item.percentage)

if(manager.showDifference){
val differenceText = if(item.presenceDifference > 0)
"+" + item.presenceDifference
else
item.presenceDifference

b.percentage.setText(b.percentage.text.toString() + " | " + differenceText);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ package pl.szczodrzynski.edziennik.ui.dialogs.settings

import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.AttendanceConfigDialogBinding
import pl.szczodrzynski.edziennik.ext.onChange
import pl.szczodrzynski.edziennik.ext.onClick
import pl.szczodrzynski.edziennik.ext.setOnSelectedListener
import pl.szczodrzynski.edziennik.ui.dialogs.base.ConfigDialog
import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_ALPHABET
import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_HIGHEST
import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_LOWEST

class AttendanceConfigDialog(
activity: AppCompatActivity,
Expand All @@ -33,6 +39,14 @@ class AttendanceConfigDialog(
b.useSymbols.isChecked = app.profile.config.attendance.useSymbols
b.groupConsecutiveDays.isChecked = app.profile.config.attendance.groupConsecutiveDays
b.showPresenceInMonth.isChecked = app.profile.config.attendance.showPresenceInMonth
b.showDifference.isChecked = app.profile.config.attendance.showDifference

when (app.profile.config.attendance.orderBy) {
SORTED_BY_ALPHABET -> b.sortAttendanceByAlphabet
SORTED_BY_LOWEST -> b.sortAttendanceByLowest
SORTED_BY_HIGHEST -> b.sortAttendanceByHighest
else -> null
}?.isChecked = true
}

override fun initView() {
Expand All @@ -45,5 +59,20 @@ class AttendanceConfigDialog(
b.showPresenceInMonth.onChange { _, isChecked ->
app.profile.config.attendance.showPresenceInMonth = isChecked
}
b.showDifference.onChange { _, isChecked ->
app.profile.config.attendance.showDifference = isChecked
}

b.sortAttendanceByAlphabet.setOnSelectedListener { app.profile.config.attendance.orderBy = SORTED_BY_ALPHABET }
b.sortAttendanceByHighest.setOnSelectedListener { app.profile.config.attendance.orderBy = SORTED_BY_HIGHEST }
b.sortAttendanceByLowest.setOnSelectedListener { app.profile.config.attendance.orderBy = SORTED_BY_LOWEST }

b.showDifferenceHelp.onClick {
MaterialAlertDialogBuilder(activity)
.setTitle(R.string.attendance_config_show_difference)
.setMessage(R.string.attendance_config_show_difference_message)
.setPositiveButton(R.string.ok, null)
.show()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ import kotlin.coroutines.CoroutineContext

class AttendanceManager(val app: App) : CoroutineScope {

companion object {
const val SORTED_BY_ALPHABET = 0
const val SORTED_BY_HIGHEST = 1
const val SORTED_BY_LOWEST = 2
}
private val job = Job()
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Default

val useSymbols
get() = app.profile.config.attendance.useSymbols
val showDifference
get() = app.profile.config.attendance.showDifference
val orderBy
get() = app.profile.config.attendance.orderBy

fun getTypeShort(baseType: Int): String {
return when (baseType) {
Expand Down
63 changes: 62 additions & 1 deletion app/src/main/res/layout/attendance_config_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
~ Copyright (c) Kuba Szczodrzyński 2020-5-4.
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<ScrollView
android:layout_width="match_parent"
Expand All @@ -30,6 +32,32 @@
android:minHeight="32dp"
android:text="@string/attendance_config_use_symbols" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<CheckBox
android:id="@+id/showDifference"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="32dp"
android:text="@string/attendance_config_show_difference" />

<com.mikepenz.iconics.view.IconicsImageView
android:id="@+id/showDifferenceHelp"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="?selectableItemBackgroundBorderless"
android:scaleType="centerInside"
app:iiv_color="?android:textColorSecondary"
app:iiv_icon="cmd-help-circle-outline"
app:iiv_size="24dp"
tools:src="@android:drawable/ic_menu_help" />

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -52,6 +80,39 @@
android:layout_height="wrap_content"
android:minHeight="32dp"
android:text="@string/attendance_config_show_presence_in_month" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="4dp"
style="@style/TextAppearance.AppCompat.Small"
android:text="@string/menu_attendance_sort_mode"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/sortAttendanceByAlphabet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:text="@string/attendance_config_dialog_sort_by_alphabet" />

<RadioButton
android:id="@+id/sortAttendanceByLowest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:text="@string/attendance_config_dialog_sort_by_lowest"/>

<RadioButton
android:id="@+id/sortAttendanceByHighest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:text="@string/attendance_config_dialog_sort_by_highest"/>

</RadioGroup>
</LinearLayout>
</ScrollView>
</layout>
5 changes: 5 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1433,4 +1433,9 @@
<string name="menu_agenda_config">Agenda settings</string>
<string name="registration_config_note_sharing_title">Share notes</string>
<string name="home_timetable_all_lessons">All lessons:</string>
<string name="attendance_config_show_difference">Display attendance differences</string>
<string name="menu_attendance_sort_mode">Sort attendance</string>
<string name="attendance_config_dialog_sort_by_alphabet">Alphabetically</string>
<string name="attendance_config_dialog_sort_by_highest">From the highest</string>
<string name="attendance_config_dialog_sort_by_lowest">from the lowest</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@
<string name="attendance_belated_excused" translatable="false">su</string>
<string name="attendance_config_group_consecutive_days">Grupuj kolejne dni na liście</string>
<string name="attendance_config_show_presence_in_month">Wyświetlaj obecność w widoku miesięcy</string>
<string name="attendance_config_show_difference">Wyświetlaj różnice obecności</string>
<string name="attendance_config_show_difference_message">Wyświetla różnice między obecnościami a nieobecnościami (Ile lekcji potrzebujesz lub możesz nie mieć aby mieć nadal 50%) \n\nnp. -1 oznacza, że brakuje ci jednej lekcji do 50%</string>
<string name="attendance_config_title">Konfiguracja frekwencji</string>
<string name="attendance_config_use_symbols">Używaj symboli i kolorów wg dziennika</string>
<string name="attendance_config_use_symbols_hint">Widoczne po rozwinięciu listy</string>
<string name="attendance_config_dialog_sort_by_alphabet">Alfabetycznie</string>
<string name="attendance_config_dialog_sort_by_lowest">Od najniższej</string>
<string name="attendance_config_dialog_sort_by_highest">Od najwyższej</string>
<string name="attendance_empty_text">Nie ma tutaj żadnych nieobecności.</string>
<string name="attendance_free_day" translatable="false">w</string>
<string name="attendance_lesson_number_format">lekcja %d</string>
Expand Down Expand Up @@ -677,6 +682,7 @@
<string name="menu_announcements">Tablica ogłoszeń</string>
<string name="menu_attendance">Frekwencja</string>
<string name="menu_attendance_config">Ustawienia frekwencji</string>
<string name="menu_attendance_sort_mode">Sortuj frekwencje</string>
<string name="menu_debug">Debugowanie</string>
<string name="menu_feedback">Pomoc i opinie</string>
<string name="menu_generate_block_timetable">Zapisz plan lekcji jako obraz</string>
Expand Down