Skip to content

Commit

Permalink
Version 5.0.2 Done (#176)
Browse files Browse the repository at this point in the history
* * Sorting is added (RESOLVE #166)

* * Ads removed (RESOLVE #174)

* * Version 5.0.2 Done
  • Loading branch information
aiyu-ayaan authored Aug 26, 2023
1 parent 8458f66 commit c755920
Show file tree
Hide file tree
Showing 21 changed files with 335 additions and 68 deletions.
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/kotlinScripting.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class AttendanceFragment : Fragment(R.layout.fragment_attendance) {
}

@Suppress("UNCHECKED_CAST")
private fun observeData() {
viewModel.unArchive.observe(viewLifecycleOwner) { attendanceList ->
private fun observeData() = launchWhenStarted {
viewModel.getAttendance().await().observe(viewLifecycleOwner) { attendanceList ->
findPercentage(
attendanceList.sumOf { it.present }.toFloat(),
attendanceList.sumOf { it.total }.toFloat()
Expand Down Expand Up @@ -174,12 +174,22 @@ class AttendanceFragment : Fragment(R.layout.fragment_attendance) {
R.id.menu_archive -> navigateToArchiveFragment()
R.id.menu_setting -> navigateToChangePercentageDialog()
R.id.menu_delete_all -> deleteAll()
R.id.menu_sort -> navigateToSortMenu()
else -> false
}

}
}

private fun navigateToSortMenu(): Boolean {
viewModel.sortPref.observe(viewLifecycleOwner) { }
val sort = viewModel.sortPref.value ?: return false
val action = AttendanceFragmentDirections
.actionAttendanceFragmentToSortMenuDialog(sort)
navigate(action)
return true
}

private fun navigateToAddSubjectFromSyllabus(): Boolean {
val action =
AttendanceFragmentDirections.actionAttendanceFragmentToAddFromSyllabusBottomSheet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.atech.attendance
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.switchMap
import androidx.lifecycle.viewModelScope
import com.atech.core.datastore.DataStoreCases
import com.atech.core.room.attendance.AttendanceDao
Expand All @@ -11,6 +12,8 @@ import com.atech.core.room.syllabus.SyllabusDao
import com.atech.core.room.syllabus.SyllabusModel
import com.atech.core.utils.REQUEST_ADD_SUBJECT_FROM_SYLLABUS
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
Expand All @@ -20,22 +23,27 @@ import javax.inject.Inject
class AttendanceViewModel @Inject constructor(
private val attendanceDao: AttendanceDao,
private val syllabusDao: SyllabusDao,
cases: DataStoreCases
private val cases: DataStoreCases,
) : ViewModel() {


val getAllPref = cases.getAll.invoke()
private val _attendance = attendanceDao.getNonArchiveAttendance()
val unArchive: LiveData<List<AttendanceModel>>
get() = _attendance.asLiveData()

val sortPref = cases.attendancePref.invoke()

val archive: LiveData<List<AttendanceModel>> =
attendanceDao.getAllArchiveAttendance().asLiveData()
val allAttendance = attendanceDao.getAllAttendance().asLiveData()

fun getAttendance() = viewModelScope.async(Dispatchers.IO) {
val list = cases.attendancePref.invoke().switchMap {
attendanceDao.getAttendanceSorted(it).asLiveData()
}
list
}


val _attendanceEvent = Channel<AttendanceEvent>()
val attendanceEvent = _attendanceEvent.receiveAsFlow()
val attendanceEventChannel = Channel<AttendanceEvent>()
val attendanceEvent = attendanceEventChannel.receiveAsFlow()

// IO function
fun update(attendanceModel: AttendanceModel) = viewModelScope.launch {
Expand All @@ -46,7 +54,7 @@ class AttendanceViewModel @Inject constructor(
viewModelScope.launch {
syllabusDao.updateSyllabusAddedInAttendance(attendanceModel.subject, 0)
attendanceDao.delete(attendanceModel)
_attendanceEvent.send(AttendanceEvent.ShowUndoDeleteMessage(attendanceModel))
attendanceEventChannel.send(AttendanceEvent.ShowUndoDeleteMessage(attendanceModel))
}

fun add(attendanceModel: AttendanceModel, request: Int) = viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AttendanceMenuBottomSheet : BaseBottomSheet() {
bsDelete.setOnClickListener {
communicator.delete(attendance)
launchWhenStarted {
communicator._attendanceEvent.send(
communicator.attendanceEventChannel.send(
AttendanceViewModel.AttendanceEvent.ShowUndoDeleteMessage(
attendance
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.atech.attendance.sort

import android.app.Dialog
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.navArgs
import com.atech.attendance.databinding.MenuSortBinding
import com.atech.core.datastore.DataStoreCases
import com.atech.core.room.attendance.Sort
import com.atech.core.room.attendance.SortBy
import com.atech.core.room.attendance.SortOrder
import com.atech.core.utils.capitalizeWords
import com.atech.theme.R
import com.atech.theme.launchWhenStarted
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.MaterialAutoCompleteTextView
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class SortMenuDialog : DialogFragment() {

private lateinit var binding: MenuSortBinding

@Inject
lateinit var dataStoreCases: DataStoreCases

private val args: SortMenuDialogArgs by navArgs()


override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = MenuSortBinding.inflate(layoutInflater)
binding.apply {
setView()
setDropDown()
}
return MaterialAlertDialogBuilder(requireContext())
.setView(binding.root)
.setTitle(getString(R.string.sort))
.setPositiveButton("Done") { _, _ ->
saveData()
}.setNegativeButton("Cancel", null)
.create()
}

private fun saveData() = launchWhenStarted {
val sortBy = SortBy.valueOf(
(binding.textInputLayoutSortBy.editText as? MaterialAutoCompleteTextView)?.text.toString()
.uppercase()
)
val sortOrder = SortOrder.valueOf(
(binding.textInputLayoutSortOrder.editText as? MaterialAutoCompleteTextView)?.text.toString()
.uppercase()
)
val sort = Sort(sortBy, sortOrder)
Log.d("AAA", "saveData: $sort")
dataStoreCases.updateAttendanceSort(sort)
}

private fun MenuSortBinding.setDropDown() = this.root.apply {
val sortBy = SortBy.values().map { it.name.capitalizeWords() }.toTypedArray()
val sortOrder = SortOrder.values().map { it.name.capitalizeWords() }.toTypedArray()

(textInputLayoutSortBy.editText as? MaterialAutoCompleteTextView)?.setSimpleItems(sortBy)
(textInputLayoutSortOrder.editText as? MaterialAutoCompleteTextView)?.setSimpleItems(
sortOrder
)
}

private fun MenuSortBinding.setView() {
val it = args.sort
textInputLayoutSortBy.editText?.setText(it.sortBy.name.capitalizeWords())
textInputLayoutSortOrder.editText?.setText(it.sortOrder.name.capitalizeWords())
}

}
36 changes: 36 additions & 0 deletions bitapp/attendance/src/main/res/layout/menu_sort.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/grid_1"
tools:theme="@style/Base.Theme.BITApp">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_sort_by"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="match_parent">

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/sort_by"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_sort_order"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/grid_1">

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/sort_order"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
5 changes: 5 additions & 0 deletions bitapp/attendance/src/main/res/menu/attendance_app_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
android:icon="@drawable/ic_archive"
android:title="@string/archive"
app:showAsAction="always" />
<item
android:id="@+id/menu_sort"
android:icon="@drawable/round_sort_24"
android:title="@string/sort"
app:showAsAction="always" />
<item
android:id="@+id/menu_setting"
android:title="@string/setting"
Expand Down
12 changes: 12 additions & 0 deletions bitapp/attendance/src/main/res/navigation/attendance_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<action
android:id="@+id/action_attendanceFragment_to_addFromSyllabusBottomSheet"
app:destination="@id/addFromSyllabusBottomSheet" />
<action
android:id="@+id/action_attendanceFragment_to_sortMenuDialog"
app:destination="@id/sortMenuDialog" />
</fragment>
<dialog
android:id="@+id/addEditAttendanceBottomSheet"
Expand Down Expand Up @@ -116,4 +119,13 @@
android:id="@+id/action_addFromSyllabusBottomSheet_to_addEditAttendanceBottomSheet"
app:destination="@id/addEditAttendanceBottomSheet" />
</dialog>
<dialog
android:id="@+id/sortMenuDialog"
android:name="com.atech.attendance.sort.SortMenuDialog"
tools:layout="@layout/menu_sort"
android:label="SortMenuDialog" >
<argument
android:name="sort"
app:argType="com.atech.core.room.attendance.Sort" />
</dialog>
</navigation>
4 changes: 2 additions & 2 deletions bitapp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId = "com.atech.bit"
minSdk = 24
targetSdk = 33
versionCode = 63
versionName = "5.0.1"
versionCode = 64
versionName = "5.0.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import com.atech.theme.changeBottomNav
import com.atech.theme.changeStatusBarToolbarColorImageView
import com.atech.theme.currentNavigationFragment
import com.atech.theme.exitTransition
import com.atech.theme.initAds
import com.atech.theme.isDark
import com.atech.theme.openCustomChromeTab
import com.atech.theme.openLinks
Expand Down Expand Up @@ -115,7 +114,7 @@ class MainActivity : AppCompatActivity(), ParentActivity, DrawerLocker,
shareReview()
checkForUpdate()
if (isConnected()) {
initAds(this)
// initAds(this)
fetchRemoteConfigData()
if (auth.hasLogIn.invoke()) registerLifeCycleOwner(this@MainActivity)
} else Log.d(TAGS.BIT_DEBUG.name, "onCreate: No Internet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.atech.bit.utils.getImageLinkNotification
import com.atech.bit.utils.set
import com.atech.bit.utils.setView
import com.atech.core.room.library.LibraryModel
import com.atech.core.utils.capitalizeWords
import com.atech.theme.CardHighlightModel
import com.atech.theme.R
import com.atech.theme.databinding.CardViewHighlightBinding
Expand Down Expand Up @@ -124,7 +125,7 @@ sealed class HomeViewHolder(
fun bind(model: HomeItems.Subject) {
binding.apply {
binding.root.transitionName = model.data.subject
subjectTextView.text = model.data.subject
subjectTextView.text = model.data.subject.capitalizeWords()
creditTextView.text = String.format("Credits: %d", model.data.credits)
creditTextView.visibility =
if (model.data.credits == -1) View.GONE else View.VISIBLE
Expand Down
18 changes: 16 additions & 2 deletions core/src/main/java/com/atech/core/datastore/DataStoreCases.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.atech.core.datastore

import androidx.lifecycle.asLiveData
import com.atech.core.room.attendance.Sort
import com.atech.core.room.syllabus.SyllabusDao
import javax.inject.Inject

data class DataStoreCases @Inject constructor(
val getAll: GetAllPref,
val attendancePref: AttendancePref,
val updatePercentage: UpdatePercentage,
val updateCourse: UpdateCourse,
val updateSem: UpdateSem,
val updateCgpa: UpdateCgpa,
val updateAttendanceSort: UpdateAttendanceSort,
val reset: Reset,
val clearAll: ClearAll
)
Expand All @@ -20,6 +23,12 @@ class GetAllPref @Inject constructor(
operator fun invoke() = preferencesManager.preferencesFlow.asLiveData()
}

class AttendancePref @Inject constructor(
private val preferencesManager: PreferencesManager
) {
operator fun invoke() = preferencesManager.attendanceSortFLow.asLiveData()
}

class UpdatePercentage @Inject constructor(
private val preferencesManager: PreferencesManager
) {
Expand All @@ -28,8 +37,7 @@ class UpdatePercentage @Inject constructor(
}

class UpdateCourse @Inject constructor(
private val preferencesManager: PreferencesManager,
private val syllabusDao: SyllabusDao
private val preferencesManager: PreferencesManager, private val syllabusDao: SyllabusDao
) {
suspend operator fun invoke(value: String) {
preferencesManager.updateCourse(value)
Expand All @@ -51,6 +59,12 @@ class UpdateCgpa @Inject constructor(
suspend operator fun invoke(cgpa: Cgpa) = preferencesManager.updateCgpa(cgpa)
}

class UpdateAttendanceSort @Inject constructor(
private val preferencesManager: PreferencesManager
) {
suspend operator fun invoke(sort: Sort) = preferencesManager.updateSort(sort)
}

class Reset @Inject constructor(
private val syllabusDao: SyllabusDao
) {
Expand Down
Loading

0 comments on commit c755920

Please sign in to comment.