From f7a21331efe265a2d3a6a31f83494bf3df03fa9e Mon Sep 17 00:00:00 2001 From: aiyu-ayaan Date: Fri, 18 Nov 2022 10:20:52 +0530 Subject: [PATCH 1/2] This Close #55 --- .../feature-request-\360\237\247\256.md" | 2 +- .../bit/ui/fragments/course/CourseFragment.kt | 6 +- .../course/sem_choose/ChooseSemViewModel.kt | 4 +- .../course/sem_choose/SemChooseFragment.kt | 72 +++++++++++++++---- .../view_syllabus/ViewSyllabusFragment.kt | 2 + .../res/layout/fragment_view_syllabus.xml | 13 ++++ .../main/res/layout/layout_syllabus_book.xml | 14 ---- .../res/layout/layout_syllabus_content.xml | 35 --------- .../layout/layout_syllabus_lab_content.xml | 34 --------- bitapp/src/main/res/values/strings.xml | 1 + .../java/com/atech/core/utils/Constants.kt | 2 +- .../main/res/xml/remote_config_defaults.xml | 4 +- 12 files changed, 84 insertions(+), 105 deletions(-) delete mode 100644 bitapp/src/main/res/layout/layout_syllabus_book.xml delete mode 100644 bitapp/src/main/res/layout/layout_syllabus_content.xml delete mode 100644 bitapp/src/main/res/layout/layout_syllabus_lab_content.xml diff --git "a/.github/ISSUE_TEMPLATE/feature-request-\360\237\247\256.md" "b/.github/ISSUE_TEMPLATE/feature-request-\360\237\247\256.md" index 230e3144..fbd536d9 100644 --- "a/.github/ISSUE_TEMPLATE/feature-request-\360\237\247\256.md" +++ "b/.github/ISSUE_TEMPLATE/feature-request-\360\237\247\256.md" @@ -2,7 +2,7 @@ name: "Feature request \U0001F9EE" about: Suggest an idea for this project title: Feature -labels: documentation, enhancement +labels: enhancement assignees: aiyu-ayaan --- diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt index 6a8e6d42..6580243f 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt @@ -15,7 +15,7 @@ import androidx.navigation.fragment.findNavController import com.atech.bit.R import com.atech.bit.databinding.FragmentCourseBinding import com.atech.core.utils.Course -import com.atech.core.utils.KEY_TOGGLE_SYLLABUS_SOURCE +import com.atech.core.utils.KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY import com.atech.core.utils.RemoteConfigUtil import com.atech.core.utils.TAG import com.google.android.material.transition.MaterialElevationScale @@ -76,9 +76,9 @@ class CourseFragment : Fragment(R.layout.fragment_course) { remoteConfigUtil.fetchData({ Log.e(TAG, "setDefaultValueForSwitch: $it") }) { - val isSwitchOn = remoteConfigUtil.getBoolean(KEY_TOGGLE_SYLLABUS_SOURCE) + val switchState = remoteConfigUtil.getString(KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY) pref.edit() - .putBoolean(KEY_TOGGLE_SYLLABUS_SOURCE, isSwitchOn) + .putString(KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY, switchState) .apply() } } diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt index 1286819b..8db42d50 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt @@ -1,6 +1,5 @@ package com.atech.bit.ui.fragments.course.sem_choose -import android.util.Log import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData @@ -45,6 +44,9 @@ class ChooseSemViewModel @Inject constructor( state["chooseSemNestedViewPosition"] = value } + var syllabusEnableModel: SemChooseFragment.SyllabusEnableModel = + SemChooseFragment.SyllabusEnableModel() + fun getOnlineSyllabus() = sem.flatMapLatest { semester -> apiRepository.getSyllabus(semester.lowercase()) diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt index ddca4563..60832852 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt @@ -7,6 +7,7 @@ import android.util.Log import android.view.View import android.viewbinding.library.fragment.viewBinding import android.widget.Toast +import androidx.annotation.Keep import androidx.core.content.ContextCompat import androidx.core.view.doOnPreDraw import androidx.core.view.isVisible @@ -32,7 +33,7 @@ import com.atech.core.api.syllabus.Semester import com.atech.core.api.syllabus.SubjectModel import com.atech.core.data.room.syllabus.SyllabusModel import com.atech.core.utils.DataState -import com.atech.core.utils.KEY_TOGGLE_SYLLABUS_SOURCE +import com.atech.core.utils.KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY import com.atech.core.utils.RemoteConfigUtil import com.atech.core.utils.openCustomChromeTab import com.atech.core.utils.showSnackBar @@ -41,6 +42,7 @@ import com.google.android.material.transition.MaterialContainerTransform import com.google.android.material.transition.MaterialElevationScale import com.google.android.material.transition.MaterialSharedAxis import com.google.firebase.firestore.FirebaseFirestore +import com.google.gson.Gson import dagger.hilt.android.AndroidEntryPoint import retrofit2.HttpException import javax.inject.Inject @@ -115,9 +117,9 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { buttonClick() setUpMenu() switchClick() - setSource() getOnlineSyllabus() setAds() + setSyllabusEnableModel() } @@ -212,10 +214,48 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { prefManagerViewModel.preferencesFlow.observe(viewLifecycleOwner) { viewModel.sem.value = "${viewModel.request}${it.semSyllabus}" courseSem = "${viewModel.request}${it.semSyllabus}".lowercase() + setSource(courseSem) buttonColorChange(it.semSyllabus, binding) } } + private fun setSyllabusEnableModel() { + val source = pref.getString( + KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY, + resources.getString(R.string.def_value_online_syllabus) + ) + viewModel.syllabusEnableModel = Gson().fromJson(source, SyllabusEnableModel::class.java) + } + + private fun setSource(courseSem: String) { + + val source = viewModel.syllabusEnableModel.compareToCourseSem(courseSem) + binding.switchOldNew.isChecked = source + setText(source) + layoutChanges(source) + } + + private fun SyllabusEnableModel.compareToCourseSem(courseSem: String) = this.run { + when (courseSem) { + "bca1" -> bca1 + "bca2" -> bca2 + "bca3" -> bca3 + "bca4" -> bca4 + "bca5" -> bca5 + "bca6" -> bca6 + "bba1" -> bba1 + "bba2" -> bba2 + "bba3" -> bba3 + "bba4" -> bba4 + "bba5" -> bba5 + "bba6" -> bba6 + else -> { + false + } + } + } + + private fun getOnlineSyllabus() { viewModel.getOnlineSyllabus().observe(viewLifecycleOwner) { dataState -> when (dataState) { @@ -271,16 +311,9 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { onlinePEAdapter.submitList(data.subjects.pe) } - private fun setSource() { - val source = pref.getBoolean(KEY_TOGGLE_SYLLABUS_SOURCE, false) - binding.switchOldNew.isChecked = source - setText(source) - layoutChanges(source) - } private fun switchClick() = binding.switchOldNew.apply { setOnCheckedChangeListener { _, isChecked -> - saveSource(isChecked) setText(isChecked) layoutChanges(isChecked) } @@ -291,11 +324,6 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { else resources.getString(R.string.switch_to_new) } - private fun saveSource(isEnable: Boolean) { - pref.edit().putBoolean( - KEY_TOGGLE_SYLLABUS_SOURCE, isEnable - ).apply() - } private fun layoutChanges(isEnable: Boolean) = binding.apply { semChoseOnlineExt.root.isVisible = isEnable @@ -392,4 +420,20 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { else -> Log.d("Error", "buttonColorChange: Error") } } + + @Keep + data class SyllabusEnableModel( + val bca1: Boolean = false, + val bca2: Boolean = false, + val bca3: Boolean = false, + val bca4: Boolean = false, + val bca5: Boolean = false, + val bca6: Boolean = false, + val bba1: Boolean = false, + val bba2: Boolean = false, + val bba3: Boolean = false, + val bba4: Boolean = false, + val bba5: Boolean = false, + val bba6: Boolean = false, + ) } \ No newline at end of file diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/view_syllabus/ViewSyllabusFragment.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/view_syllabus/ViewSyllabusFragment.kt index 4791309e..6959e9c7 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/view_syllabus/ViewSyllabusFragment.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/view_syllabus/ViewSyllabusFragment.kt @@ -11,6 +11,7 @@ import androidx.lifecycle.asLiveData import androidx.navigation.fragment.navArgs import com.atech.bit.R import com.atech.bit.databinding.FragmentViewSyllabusBinding +import com.atech.bit.utils.loadAdds import com.atech.core.api.ApiRepository import com.atech.core.utils.DataState import com.atech.core.utils.getColorForText @@ -98,6 +99,7 @@ class ViewSyllabusFragment : Fragment(R.layout.fragment_view_syllabus) { } private fun FragmentViewSyllabusBinding.setMarkDownFile(dataState: DataState.Success) { + requireContext().loadAdds(adViewSyllabusLabContent) markdown.apply { setViewsVisible(true) setBackgroundColor( diff --git a/bitapp/src/main/res/layout/fragment_view_syllabus.xml b/bitapp/src/main/res/layout/fragment_view_syllabus.xml index 79402ab6..a937573a 100644 --- a/bitapp/src/main/res/layout/fragment_view_syllabus.xml +++ b/bitapp/src/main/res/layout/fragment_view_syllabus.xml @@ -1,5 +1,6 @@ + + diff --git a/bitapp/src/main/res/layout/layout_syllabus_book.xml b/bitapp/src/main/res/layout/layout_syllabus_book.xml deleted file mode 100644 index 2dbee9d0..00000000 --- a/bitapp/src/main/res/layout/layout_syllabus_book.xml +++ /dev/null @@ -1,14 +0,0 @@ - - diff --git a/bitapp/src/main/res/layout/layout_syllabus_content.xml b/bitapp/src/main/res/layout/layout_syllabus_content.xml deleted file mode 100644 index f9a327bd..00000000 --- a/bitapp/src/main/res/layout/layout_syllabus_content.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/bitapp/src/main/res/layout/layout_syllabus_lab_content.xml b/bitapp/src/main/res/layout/layout_syllabus_lab_content.xml deleted file mode 100644 index b7adbb34..00000000 --- a/bitapp/src/main/res/layout/layout_syllabus_lab_content.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/bitapp/src/main/res/values/strings.xml b/bitapp/src/main/res/values/strings.xml index 060f83c5..37a11dba 100644 --- a/bitapp/src/main/res/values/strings.xml +++ b/bitapp/src/main/res/values/strings.xml @@ -226,5 +226,6 @@ https://bitapp.page.link/issue https://bitapp.page.link/BIT No Internet + "bca1": false, "bca2": false, "bca3": false, "bca4": false, "bca5": false, "bca6": false, "bba1": false, "bba2": false, "bba3": false, "bba4": false, "bba5": false, "bba6": false \ No newline at end of file diff --git a/core/src/main/java/com/atech/core/utils/Constants.kt b/core/src/main/java/com/atech/core/utils/Constants.kt index e82859c4..08cff8e3 100644 --- a/core/src/main/java/com/atech/core/utils/Constants.kt +++ b/core/src/main/java/com/atech/core/utils/Constants.kt @@ -18,7 +18,7 @@ const val KEY_REACH_TO_HOME = "KEY_REACH_TO_HOME" const val KEY_IS_USER_LOG_IN = "KEY_IS_USER_LOG_IN" const val KEY_FIRST_TIME_LOGIN = "KEY_FIRST_TIME_LOGIN" const val KEY_ATTENDANCE_UPLOAD_FIRST_TIME = "KEY_ATTENDANCE_UPLOAD_FIRST_TIME" -const val KEY_TOGGLE_SYLLABUS_SOURCE = "KEY_TOGGLE_SYLLABUS_SOURCE" +const val KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY = "KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY" const val KEY_COURSE_OPEN_FIRST_TIME = "KEY_COURSE_OPEN_FIRST_TIME" const val REQUEST_UPDATE_SEM = 345 * 33434 const val REQUEST_UPDATE_SEM_FROM_CGPA = 345 * 33434 + 1 diff --git a/core/src/main/res/xml/remote_config_defaults.xml b/core/src/main/res/xml/remote_config_defaults.xml index e3baaeca..cbe4eba5 100644 --- a/core/src/main/res/xml/remote_config_defaults.xml +++ b/core/src/main/res/xml/remote_config_defaults.xml @@ -5,8 +5,8 @@ 2022-23 - KEY_TOGGLE_SYLLABUS_SOURCE - false + KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY + { "bca1": true, "bca2": false, "bca3": true, "bca4": false, "bca5": false, "bca6": false, "bba1": false, "bba2": false, "bba3": false, "bba4": false, "bba5": false, "bba6": false } SYLLABUS_BCA From bf93d930c48e0b88e14ce361acf0b924726aca75 Mon Sep 17 00:00:00 2001 From: aiyu-ayaan Date: Fri, 18 Nov 2022 23:22:28 +0530 Subject: [PATCH 2/2] Online syllabus added in HomeFragment.kt --- bitapp/build.gradle | 13 +- .../bit/ui/fragments/course/CourseFragment.kt | 15 -- .../course/sem_choose/ChooseSemViewModel.kt | 5 +- .../course/sem_choose/SemChooseFragment.kt | 38 +-- .../adapters/SyllabusOnlineAdapter.kt | 6 + .../bit/ui/fragments/home/HomeFragment.kt | 217 ++++++++++++++++-- .../bit/ui/fragments/home/HomeViewModel.kt | 8 +- .../atech/bit/utils/SyllabusEnableModel.kt | 39 ++++ bitapp/src/main/res/layout/fragment_home.xml | 149 +----------- .../src/main/res/layout/fragment_home_ext.xml | 182 +++++++++++++++ .../main/res/layout/sem_choose_online_ext.xml | 3 +- bitapp/src/main/res/navigation/nav_graph.xml | 3 + bitapp/src/main/res/values/strings.xml | 4 +- 13 files changed, 465 insertions(+), 217 deletions(-) create mode 100644 bitapp/src/main/java/com/atech/bit/utils/SyllabusEnableModel.kt create mode 100644 bitapp/src/main/res/layout/fragment_home_ext.xml diff --git a/bitapp/build.gradle b/bitapp/build.gradle index e012e4c7..47a17659 100644 --- a/bitapp/build.gradle +++ b/bitapp/build.gradle @@ -16,8 +16,8 @@ android { applicationId "com.atech.bit" minSdk 24 targetSdk 33 - versionCode 32 - versionName "4.1.1 Patch 6" + versionCode 33 + versionName "4.1.1 Patch 7" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -39,12 +39,21 @@ android { versionNameSuffix "-beta" } } + signingConfigs { + release { + storeFile file('keystore/keystore.jks') + storePassword System.getenv("SIGNING_STORE_PASSWORD") + keyAlias System.getenv("SIGNING_KEY_ALIAS") + keyPassword System.getenv("SIGNING_KEY_PASSWORD") + } + } buildTypes { release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.release } } compileOptions { diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt index 6580243f..4e78eead 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/CourseFragment.kt @@ -32,8 +32,6 @@ class CourseFragment : Fragment(R.layout.fragment_course) { @Inject lateinit var db: FirebaseFirestore - @Inject - lateinit var remoteConfigUtil: RemoteConfigUtil @Inject lateinit var pref: SharedPreferences @@ -69,21 +67,8 @@ class CourseFragment : Fragment(R.layout.fragment_course) { navigateToSemChoose(Course.Bba.name, imageButtonBba) } } - setDefaultValueForSwitch() } - private fun setDefaultValueForSwitch() { - remoteConfigUtil.fetchData({ - Log.e(TAG, "setDefaultValueForSwitch: $it") - }) { - val switchState = remoteConfigUtil.getString(KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY) - pref.edit() - .putString(KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY, switchState) - .apply() - } - } - - override fun onPause() { super.onPause() myScrollViewerInstanceState = binding.nestedViewSyllabus.onSaveInstanceState() diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt index 8db42d50..713a31cd 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/ChooseSemViewModel.kt @@ -3,6 +3,7 @@ package com.atech.bit.ui.fragments.course.sem_choose import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData +import com.atech.bit.utils.SyllabusEnableModel import com.atech.core.api.ApiRepository import com.atech.core.data.room.syllabus.SyllabusDao import dagger.hilt.android.lifecycle.HiltViewModel @@ -44,8 +45,8 @@ class ChooseSemViewModel @Inject constructor( state["chooseSemNestedViewPosition"] = value } - var syllabusEnableModel: SemChooseFragment.SyllabusEnableModel = - SemChooseFragment.SyllabusEnableModel() + var syllabusEnableModel: SyllabusEnableModel = + SyllabusEnableModel() fun getOnlineSyllabus() = sem.flatMapLatest { semester -> diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt index 60832852..959d0a7d 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/SemChooseFragment.kt @@ -26,7 +26,9 @@ import com.atech.bit.ui.activity.main_activity.viewmodels.PreferenceManagerViewM import com.atech.bit.ui.custom_views.DividerItemDecorationNoLast import com.atech.bit.ui.fragments.course.sem_choose.adapters.SubjectAdapter import com.atech.bit.ui.fragments.course.sem_choose.adapters.SyllabusOnlineAdapter +import com.atech.bit.utils.SyllabusEnableModel import com.atech.bit.utils.addMenuHost +import com.atech.bit.utils.compareToCourseSem import com.atech.bit.utils.loadAdds import com.atech.bit.utils.openBugLink import com.atech.core.api.syllabus.Semester @@ -228,32 +230,12 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { } private fun setSource(courseSem: String) { - val source = viewModel.syllabusEnableModel.compareToCourseSem(courseSem) binding.switchOldNew.isChecked = source setText(source) layoutChanges(source) } - private fun SyllabusEnableModel.compareToCourseSem(courseSem: String) = this.run { - when (courseSem) { - "bca1" -> bca1 - "bca2" -> bca2 - "bca3" -> bca3 - "bca4" -> bca4 - "bca5" -> bca5 - "bca6" -> bca6 - "bba1" -> bba1 - "bba2" -> bba2 - "bba3" -> bba3 - "bba4" -> bba4 - "bba5" -> bba5 - "bba6" -> bba6 - else -> { - false - } - } - } private fun getOnlineSyllabus() { @@ -421,19 +403,5 @@ class SemChooseFragment : Fragment(R.layout.fragment_sem_choose) { } } - @Keep - data class SyllabusEnableModel( - val bca1: Boolean = false, - val bca2: Boolean = false, - val bca3: Boolean = false, - val bca4: Boolean = false, - val bca5: Boolean = false, - val bca6: Boolean = false, - val bba1: Boolean = false, - val bba2: Boolean = false, - val bba3: Boolean = false, - val bba4: Boolean = false, - val bba5: Boolean = false, - val bba6: Boolean = false, - ) + } \ No newline at end of file diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/adapters/SyllabusOnlineAdapter.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/adapters/SyllabusOnlineAdapter.kt index 2978d7ba..c6302a3d 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/adapters/SyllabusOnlineAdapter.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/course/sem_choose/adapters/SyllabusOnlineAdapter.kt @@ -10,6 +10,7 @@ import com.atech.core.api.syllabus.DiffUtilTheorySyllabusCallback import com.atech.core.api.syllabus.SubjectModel class SyllabusOnlineAdapter( + private val isFromHome: Boolean = false, private val onClick: (SubjectModel) -> Unit ) : ListAdapter>(DiffUtilTheorySyllabusCallback()) { @@ -43,6 +44,11 @@ class SyllabusOnlineAdapter( R.string.theory_code, type, theory.code ) creditTextView.text = theory.credit.toString() + if (isFromHome) { + subjectTextView.textSize = 16f + subjectCodeTextView.textSize = 12f + creditTextView.textSize = 12f + } } } } diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeFragment.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeFragment.kt index d065fab8..32e88b58 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeFragment.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeFragment.kt @@ -30,6 +30,7 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController +import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.PagerSnapHelper import androidx.recyclerview.widget.RecyclerView @@ -43,16 +44,22 @@ import com.atech.bit.ui.activity.main_activity.viewmodels.PreferenceManagerViewM import com.atech.bit.ui.activity.main_activity.viewmodels.UserDataViewModel import com.atech.bit.ui.custom_views.DividerItemDecorationNoLast import com.atech.bit.ui.fragments.course.CourseFragment +import com.atech.bit.ui.fragments.course.sem_choose.adapters.SyllabusOnlineAdapter import com.atech.bit.ui.fragments.event.EventsAdapter import com.atech.bit.ui.fragments.home.adapter.AttendanceHomeAdapter import com.atech.bit.ui.fragments.home.adapter.HolidayHomeAdapter import com.atech.bit.ui.fragments.home.adapter.SyllabusHomeAdapter import com.atech.bit.utils.Encryption.decryptText import com.atech.bit.utils.Encryption.getCryptore +import com.atech.bit.utils.SyllabusEnableModel import com.atech.bit.utils.addMenuHost +import com.atech.bit.utils.compareToCourseSem import com.atech.bit.utils.getUid import com.atech.bit.utils.loadAdds +import com.atech.bit.utils.openBugLink import com.atech.bit.utils.sortBySno +import com.atech.core.api.syllabus.Semester +import com.atech.core.api.syllabus.SubjectModel import com.atech.core.data.network.user.UserModel import com.atech.core.data.preferences.Cgpa import com.atech.core.data.room.BitDatabase @@ -65,6 +72,7 @@ import com.atech.core.utils.KEY_COURSE_OPEN_FIRST_TIME import com.atech.core.utils.KEY_DO_NOT_SHOW_AGAIN import com.atech.core.utils.KEY_IS_USER_LOG_IN import com.atech.core.utils.KEY_REACH_TO_HOME +import com.atech.core.utils.KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY import com.atech.core.utils.KEY_USER_HAS_DATA_IN_DB import com.atech.core.utils.REQUEST_EVENT_FROM_HOME import com.atech.core.utils.REQUEST_LOGIN_FROM_HOME @@ -87,7 +95,9 @@ import com.google.android.material.transition.MaterialElevationScale import com.google.android.material.transition.MaterialSharedAxis import com.google.firebase.auth.FirebaseAuth import com.google.firebase.firestore.FirebaseFirestore +import com.google.gson.Gson import dagger.hilt.android.AndroidEntryPoint +import retrofit2.HttpException import java.math.RoundingMode import java.text.DecimalFormat import javax.inject.Inject @@ -105,6 +115,9 @@ class HomeFragment : Fragment(R.layout.fragment_home) { private lateinit var syllabusTheoryAdapter: SyllabusHomeAdapter private lateinit var syllabusLabAdapter: SyllabusHomeAdapter private lateinit var holidayAdapter: HolidayHomeAdapter + private lateinit var onlineTheoryAdapter: SyllabusOnlineAdapter + private lateinit var onlineLabAdapter: SyllabusOnlineAdapter + private lateinit var onlinePEAdapter: SyllabusOnlineAdapter private var userModel: UserModel? = null @Inject @@ -122,6 +135,12 @@ class HomeFragment : Fragment(R.layout.fragment_home) { @Inject lateinit var bitDatabase: BitDatabase + + @Inject + lateinit var remoteConfigUtil: RemoteConfigUtil + + private var courseSem: String = "" + private lateinit var requestPermissionLauncher: ActivityResultLauncher override fun onCreate(savedInstanceState: Bundle?) { @@ -143,16 +162,20 @@ class HomeFragment : Fragment(R.layout.fragment_home) { holidayAdapter = HolidayHomeAdapter() binding.apply { lineChartCgpa.setNoDataText(resources.getString(R.string.loading)) - setting.setOnClickListener { - navigateToWelcomeScreen() + fragmentHomeExt.apply { + setting.setOnClickListener { + navigateToWelcomeScreen() + } + edit.setOnClickListener { + navigateToEdit() + } } attendanceClick.root.setOnClickListener { navigateToAttendance() } - edit.setOnClickListener { - navigateToEdit() - } + + textShowAllHoliday.setOnClickListener { navigateToHoliday() } @@ -178,8 +201,11 @@ class HomeFragment : Fragment(R.layout.fragment_home) { // Handle on Destroy detectScroll() + setDefaultValueForSwitch() + // setTimeTable() getData() + getOnlineSyllabus() setHoliday() createMenu() @@ -196,6 +222,75 @@ class HomeFragment : Fragment(R.layout.fragment_home) { clearAndAddSyllabusDatabase() checkPermission() + getHoliday() + setOnlineSyllabusView() + switchClick() + } + + private fun setSource(courseSem: String) { + val source = viewModel.syllabusEnableModel.compareToCourseSem(courseSem) + binding.fragmentHomeExt.switchOldNew.isChecked = source + setText(source) + layoutChanges(source) + } + + private fun setOnlineSyllabusView() { + onlineTheoryAdapter = SyllabusOnlineAdapter(true) { pos -> + navigateToViewOnlineSyllabus(pos) + } + onlineLabAdapter = SyllabusOnlineAdapter(true) { + navigateToViewOnlineSyllabus(it) + }.also { it.setType("Lab") } + onlinePEAdapter = SyllabusOnlineAdapter(true) { + navigateToViewOnlineSyllabus(it) + }.also { it.setType("Pe") } + + binding.fragmentHomeExt.semChoseOnlineExt + .constraintLayoutOnline.setPadding(0, 0, 0, 0) + binding.fragmentHomeExt.semChoseOnlineExt.recyclerViewOnlineSyllabus.apply { + adapter = ConcatAdapter(onlineTheoryAdapter, onlineLabAdapter, onlinePEAdapter) + layoutManager = LinearLayoutManager(requireContext()) + addItemDecoration(DividerItemDecorationNoLast( + requireContext(), LinearLayoutManager.VERTICAL + ).apply { + setDrawable( + ContextCompat.getDrawable( + requireContext(), R.drawable.divider + ) + ) + }) + } + } + + private fun navigateToViewOnlineSyllabus(model: SubjectModel) { + exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true) + reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false) + Log.d(TAG, "navigateToViewOnlineSyllabus: $courseSem") + val action = + HomeFragmentDirections.actionHomeFragmentToViewSyllabusFragment( + model.subjectName, + courseSem.lowercase() + ) + findNavController().navigate(action) + } + + private fun switchClick() = binding.fragmentHomeExt.switchOldNew.apply { + setOnCheckedChangeListener { _, isChecked -> + setText(isChecked) + layoutChanges(isChecked) + binding.fragmentHomeExt.edit.isVisible = !isChecked + } + } + + private fun setText(isEnable: Boolean) { + binding.fragmentHomeExt.switchOldNew.text = + if (isEnable) resources.getString(R.string.online) + else resources.getString(R.string.offline) + } + + private fun layoutChanges(isEnable: Boolean) = binding.fragmentHomeExt.apply { + semChoseOnlineExt.root.isVisible = isEnable + materialCardViewSyllabusRecyclerView.isVisible = !isEnable } private fun checkPermission() { @@ -453,7 +548,7 @@ class HomeFragment : Fragment(R.layout.fragment_home) { val snapHelper = PagerSnapHelper() snapHelper.attachToRecyclerView(this) eventIndicator.attachToRecyclerView(this, snapHelper) - eventAdapter.registerAdapterDataObserver(eventIndicator.adapterDataObserver); + eventAdapter.registerAdapterDataObserver(eventIndicator.adapterDataObserver) } eventAdapter.stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY @@ -536,7 +631,7 @@ class HomeFragment : Fragment(R.layout.fragment_home) { val snapHelper = PagerSnapHelper() snapHelper.attachToRecyclerView(this) binding.attendanceClick.attendanceIndicator.attachToRecyclerView(this, snapHelper) - attendanceHomeAdapter.registerAdapterDataObserver(binding.attendanceClick.attendanceIndicator.adapterDataObserver); + attendanceHomeAdapter.registerAdapterDataObserver(binding.attendanceClick.attendanceIndicator.adapterDataObserver) } viewModel.attAttendance.observe(viewLifecycleOwner) { attendanceHomeAdapter.submitList(it) @@ -599,7 +694,9 @@ class HomeFragment : Fragment(R.layout.fragment_home) { private fun preferenceManager() { preferencesManagerViewModel.preferencesFlow.observe(viewLifecycleOwner) { - viewModel.syllabusQuery.value = "${it.course}${it.sem}" + courseSem = "${it.course}${it.sem}" + setSource(courseSem.lowercase()) + viewModel.syllabusQuery.value = courseSem binding.materialCardViewCgpaGraph.isVisible = !it.cgpa.isAllZero binding.textViewCgpa.isVisible = !it.cgpa.isAllZero binding.textViewEdit.isVisible = !it.cgpa.isAllZero @@ -658,7 +755,7 @@ class HomeFragment : Fragment(R.layout.fragment_home) { syllabusPeAdapter = SyllabusHomeAdapter(listener = { s, v -> setOnSyllabusClickListener(s, v) }) - binding.apply { + binding.fragmentHomeExt.apply { showTheory.apply { adapter = syllabusTheoryAdapter @@ -684,25 +781,88 @@ class HomeFragment : Fragment(R.layout.fragment_home) { } - private fun getData() = lifecycleScope.launchWhenStarted { + private fun getOnlineSyllabus() { + viewModel.getOnlineSyllabus().observe(viewLifecycleOwner) { dataState -> + when (dataState) { + DataState.Empty -> {} + is DataState.Error -> { + Log.d("AAA", "getOnlineSyllabus: ${dataState.exception}") + if (dataState.exception is HttpException) { + binding.root.showSnackBar( + "${dataState.exception.message}", Snackbar.LENGTH_SHORT, "Report" + ) { +// setViewOfOnlineSyllabusExt(false) + requireActivity().openBugLink( + com.atech.core.R.string.bug_repost, + "${this.javaClass.simpleName}.class", + dataState.exception.message + ) + } + } + + } + + DataState.Loading -> { + binding.fragmentHomeExt.semChoseOnlineExt.apply { + progressBarLoading.isVisible = true + noData.isVisible = false + noDataText.isVisible = false + } + } + + is DataState.Success -> { + Log.d("AAA", "getOnlineSyllabus: ${dataState.data}") + dataState.data.semester?.let { syllabus -> + setOnLineData(syllabus) // + } + setViewOfOnlineSyllabusExt(dataState.data.semester != null) + } + } + } + } + + private fun setOnLineData(data: Semester) { + onlineTheoryAdapter.submitList(data.subjects.theory) + onlineLabAdapter.setStartPos(data.subjects.theory.size) + onlineLabAdapter.submitList(data.subjects.lab) + onlinePEAdapter.setStartPos(data.subjects.theory.size + data.subjects.lab.size) + + onlinePEAdapter.submitList(data.subjects.pe) + } + + + private fun setViewOfOnlineSyllabusExt(isVisible: Boolean) = + binding.fragmentHomeExt.semChoseOnlineExt.apply { + progressBarLoading.isVisible = false + noData.isVisible = !isVisible + noDataText.isVisible = !isVisible + recyclerViewOnlineSyllabus.isVisible = isVisible + textView6.isVisible = false + } + + private fun getData() { viewModel.theory.observe(viewLifecycleOwner) { - binding.showTheory.isVisible = it.isNotEmpty() - binding.textView6.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.showTheory.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.textView6.isVisible = it.isNotEmpty() syllabusTheoryAdapter.submitList(it) } viewModel.lab.observe(viewLifecycleOwner) { - binding.showLab.isVisible = it.isNotEmpty() - binding.textView7.isVisible = it.isNotEmpty() - binding.dividerTheory.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.showLab.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.textView7.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.dividerTheory.isVisible = it.isNotEmpty() syllabusLabAdapter.submitList(it) } viewModel.pe.observe(viewLifecycleOwner) { - binding.showPe.isVisible = it.isNotEmpty() - binding.textView8.isVisible = it.isNotEmpty() - binding.dividerLab.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.showPe.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.textView8.isVisible = it.isNotEmpty() + binding.fragmentHomeExt.dividerLab.isVisible = it.isNotEmpty() syllabusPeAdapter.submitList(it) } + + } + + private fun getHoliday() { viewModel.getHoliday().observe(viewLifecycleOwner) { dateState -> when (dateState) { is DataState.Success -> { @@ -796,6 +956,27 @@ class HomeFragment : Fragment(R.layout.fragment_home) { } } + private fun setDefaultValueForSwitch() { + remoteConfigUtil.fetchData({ + Log.e(TAG, "setDefaultValueForSwitch: $it") + }) { + val switchState = remoteConfigUtil.getString(KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY) + pref.edit() + .putString(KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY, switchState) + .apply() + } + setSyllabusEnableModel() + } + + private fun setSyllabusEnableModel() { + val source = pref.getString( + KEY_TOGGLE_SYLLABUS_SOURCE_ARRAY, + resources.getString(R.string.def_value_online_syllabus) + ) + viewModel.syllabusEnableModel = + Gson().fromJson(source, SyllabusEnableModel::class.java) + } + override fun onPause() { super.onPause() diff --git a/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeViewModel.kt b/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeViewModel.kt index 192286cc..1683be6d 100644 --- a/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeViewModel.kt +++ b/bitapp/src/main/java/com/atech/bit/ui/fragments/home/HomeViewModel.kt @@ -13,6 +13,7 @@ package com.atech.bit.ui.fragments.home import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData +import com.atech.bit.utils.SyllabusEnableModel import com.atech.core.api.ApiRepository import com.atech.core.data.room.attendance.AttendanceDao import com.atech.core.data.room.syllabus.SyllabusDao @@ -45,6 +46,9 @@ class HomeViewModel @Inject constructor( }).asLiveData() + var syllabusEnableModel: SyllabusEnableModel = + SyllabusEnableModel() + // Syllabus val syllabusQuery = MutableStateFlow("-fdfjdfk") @@ -69,5 +73,7 @@ class HomeViewModel @Inject constructor( fun getEvent(start: Long, end: Long) = eventRepository.getEvent7Days(start, end).asLiveData() - + fun getOnlineSyllabus() = syllabusQuery.flatMapLatest { semester -> + apiRepository.getSyllabus(semester.lowercase()) + }.asLiveData() } \ No newline at end of file diff --git a/bitapp/src/main/java/com/atech/bit/utils/SyllabusEnableModel.kt b/bitapp/src/main/java/com/atech/bit/utils/SyllabusEnableModel.kt new file mode 100644 index 00000000..4616c1e3 --- /dev/null +++ b/bitapp/src/main/java/com/atech/bit/utils/SyllabusEnableModel.kt @@ -0,0 +1,39 @@ +package com.atech.bit.utils + +import androidx.annotation.Keep + +@Keep +data class SyllabusEnableModel( + val bca1: Boolean = false, + val bca2: Boolean = false, + val bca3: Boolean = false, + val bca4: Boolean = false, + val bca5: Boolean = false, + val bca6: Boolean = false, + val bba1: Boolean = false, + val bba2: Boolean = false, + val bba3: Boolean = false, + val bba4: Boolean = false, + val bba5: Boolean = false, + val bba6: Boolean = false, +) + +fun SyllabusEnableModel.compareToCourseSem(courseSem: String) = this.run { + when (courseSem) { + "bca1" -> bca1 + "bca2" -> bca2 + "bca3" -> bca3 + "bca4" -> bca4 + "bca5" -> bca5 + "bca6" -> bca6 + "bba1" -> bba1 + "bba2" -> bba2 + "bba3" -> bba3 + "bba4" -> bba4 + "bba5" -> bba5 + "bba6" -> bba6 + else -> { + false + } + } +} \ No newline at end of file diff --git a/bitapp/src/main/res/layout/fragment_home.xml b/bitapp/src/main/res/layout/fragment_home.xml index 8934cd44..c189b310 100644 --- a/bitapp/src/main/res/layout/fragment_home.xml +++ b/bitapp/src/main/res/layout/fragment_home.xml @@ -34,147 +34,11 @@ android:layout_height="match_parent" android:layout_marginHorizontal="@dimen/grid_1"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" /> @@ -228,6 +92,7 @@ android:layout_height="wrap_content" android:layout_below="@id/text_event" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bitapp/src/main/res/layout/sem_choose_online_ext.xml b/bitapp/src/main/res/layout/sem_choose_online_ext.xml index 37141302..8cea37a0 100644 --- a/bitapp/src/main/res/layout/sem_choose_online_ext.xml +++ b/bitapp/src/main/res/layout/sem_choose_online_ext.xml @@ -10,9 +10,10 @@ android:paddingBottom="@dimen/grid_2"> + android:padding="@dimen/grid_2"> + https://bitapp.page.link/issue https://bitapp.page.link/BIT No Internet - "bca1": false, "bca2": false, "bca3": false, "bca4": false, "bca5": false, "bca6": false, "bba1": false, "bba2": false, "bba3": false, "bba4": false, "bba5": false, "bba6": false + { "bca1": true, "bca2": false, "bca3": true, "bca4": false, "bca5": false, "bca6": false, "bba1": false, "bba2": false, "bba3": false, "bba4": false, "bba5": false, "bba6": false } + Online + Offline \ No newline at end of file