Compare commits

...

No commits in common. "main" and "7cf154daa01732c8e1b93eb766722ebab7118ea5" have entirely different histories.

235 changed files with 18733 additions and 0 deletions

15
.gitignore vendored 100644
View File

@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

3
.idea/.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\maksi\.android\avd\Pixel_5_API_29_2.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-11-30T18:27:18.890685800Z" />
</component>
</project>

20
.idea/gradle.xml 100644
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="SameParameterValue" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.8.0" />
</component>
</project>

9
.idea/misc.xml 100644
View File

@ -0,0 +1,9 @@
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

1
app/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/build

102
app/build.gradle 100644
View File

@ -0,0 +1,102 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.doctor'
compileSdk 33
defaultConfig {
applicationId "com.example.doctor"
minSdk 28
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures{
viewBinding true
}
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "com.mikepenz:materialdrawer:7.0.0"
implementation "com.mikepenz:materialdrawer-nav:7.0.0"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.1.17'
implementation platform('com.google.firebase:firebase-bom:31.2.0')
implementation 'com.google.firebase:firebase-database-ktx:20.1.0'
implementation 'com.google.firebase:firebase-auth-ktx:21.1.0'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.test:core-ktx:1.4.0'
implementation 'androidx.games:games-activity:1.1.0'
implementation 'com.google.mlkit:common:18.1.0'
implementation 'com.google.firebase:firebase-messaging-ktx:23.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
implementation 'com.kizitonwose.calendar:view:2.0.0'
//Lifecycle
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
//OkHttp
implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"
implementation "com.squareup.okhttp3:okhttp:4.7.2"
implementation 'com.squareup.picasso:picasso:2.71828'
//Свайп
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.work:work-runtime-ktx:2.8.1"
// // Kotlin
// implementation "androidx.navigation:navigation-fragment-ktx:2.5.2"
// implementation "androidx.navigation:navigation-ui-ktx:2.5.2"
}

21
app/proguard-rules.pro vendored 100644
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package com.example.doctor
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.doctor", appContext.packageName)
}
}

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.CALL_PHONE"
tools:ignore="PermissionImpliesUnsupportedChromeOsHardware" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Doctor"
android:usesCleartextTraffic="true"
tools:targetApi="31" >
<activity
android:name=".CodeError.Code500Activity"
android:exported="false" />
<activity
android:name=".CodeError.Code429Activity"
android:exported="false" />
<activity
android:name=".Enternet.EnternetActivity"
android:exported="false" />
<activity
android:name=".Setting.Courses.CoursesActivity"
android:exported="false" />
<activity
android:name=".Appeals.AppealsCreateMessageActivity"
android:exported="false" />
<activity
android:name=".Patients.PatientActivity"
android:exported="false" />
<activity
android:name=".Auth.AuthActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustPan|stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>

View File

@ -0,0 +1,17 @@
package com.example.doctor.Adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
class VpAdapter(fr_act:FragmentActivity, private val list:List<Fragment>):FragmentStateAdapter(fr_act) {//private val list:List<Fragment> - список с фрагментами сюда передастся, тоесть с двумя фрагментами
//Возврощаем для createFragment количество элементов(фрагментов) в листе(List)
override fun getItemCount(): Int {
return list.size//возврощаем количество фрагметов
}
//Позиция фрагмента или 1 или 2, то есть 0 или 1. И по позиции будут выводится фрагмент.
override fun createFragment(position: Int): Fragment {
return list[position]//Возврощаем фрагмент из листа по позиции
}
}

View File

@ -0,0 +1,17 @@
package com.example.doctor.Adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
class VpAdapterPatientList(fr_act:FragmentActivity, private val list:List<Fragment>):FragmentStateAdapter(fr_act) {//private val list:List<Fragment> - список с фрагментами сюда передастся, тоесть с двумя фрагментами
//Возврощаем для createFragment количество элементов(фрагментов) в листе(List)
override fun getItemCount(): Int {
return list.size//возврощаем количество фрагметов
}
//Позиция фрагмента или 1 или 2, то есть 0 или 1. И по позиции будут выводится фрагмент.
override fun createFragment(position: Int): Fragment {
return list[position]//Возврощаем фрагмент из листа по позиции
}
}

View File

@ -0,0 +1,17 @@
package com.example.doctor.Adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
class VpEditSportAdapter(fr_act:FragmentActivity, private val list: List<Any>):FragmentStateAdapter(fr_act) {//private val list:List<Fragment> - список с фрагментами сюда передастся, тоесть с двумя фрагментами
//Возврощаем для createFragment количество элементов(фрагментов) в листе(List)
override fun getItemCount(): Int {
return list.size//возврощаем количество фрагметов
}
//Позиция фрагмента или 1 или 2, то есть 0 или 1. И по позиции будут выводится фрагмент.
override fun createFragment(position: Int): Fragment {
return list[position] as Fragment//Возврощаем фрагмент из листа по позиции
}
}

View File

@ -0,0 +1,19 @@
package com.example.doctor
data class AddSportPatientModel(
val id: Int,
val status: String,
val one: Int,
val two: Int,
val three: Int,
val four: Int,
val five: Int,
val six: Int,
val seven: Int,
val eight: Int,
val nine: Int,
val ten: Int,
val eleven: Int,
val twelve: Int,
)

View File

@ -0,0 +1,17 @@
package com.example.doctor.Appeals
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.doctor.R
import com.example.doctor.databinding.ActivityAppealsBinding
class AppealsCreateMessageActivity : AppCompatActivity() {
private lateinit var binding: ActivityAppealsBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityAppealsBinding.inflate(layoutInflater)
setContentView(binding.root)
supportFragmentManager.beginTransaction().replace(R.id.CLAppealsActivity, CreateMessageFragment.newInstance()).commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}

View File

@ -0,0 +1,343 @@
package com.example.doctor.Appeals
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.activityViewModels
import com.example.doctor.Adapter.VpAdapter
import com.example.doctor.R
import com.example.doctor.Appeals.TabLayout.OldAppealsFragment
import com.example.doctor.Appeals.TabLayout.NewAppealsFragment
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentAppealsBinding
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class AppealsFragment : Fragment() {
private lateinit var binding: FragmentAppealsBinding
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
private val model: DoctorViewModel by activityViewModels()
val prefDoctorConclusion = ConclusionPref()
private val dataModel: DataModel by activityViewModels()//Для передачи данных
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
private val tList = listOf(
"новые",
"обработанные",
)
//Список с фрагментами для переключения
private val flist = listOf(
NewAppealsFragment.newInstance(),
OldAppealsFragment.newInstance(),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentAppealsBinding.inflate(layoutInflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
init()
binding.btnAddMessage.setOnClickListener {
val intetn = Intent(requireContext(), AppealsCreateMessageActivity::class.java)
startActivity(intetn)
// activity?.supportFragmentManager?.beginTransaction()
// ?.replace(R.id.CLAppeals, CreateMessageFragment.newInstance())?.commit()
// binding.ConstrainLayoutProductEdit.visibility = View.GONE
// binding.CLAppeals.visibility = View.VISIBLE
}
// dataModel.patientAppeal.observe(viewLifecycleOwner, Observer {
// requireActivity().runOnUiThread {
// val viewPatient = prefDoctorConclusion.conclusionViewPatient(requireContext())
// val idPatient = prefDoctorConclusion.conclusionIdPatient(requireContext())
// if (viewPatient == 1 && idPatient != 0) {
//
// prefDoctorClear.clearIdPatient(requireContext())
// prefDoctorClear.clearViewPatient(requireContext())
// GetPatientID(it)
// }
// }
// })
// dataModel.patientAppeal.observe(viewLifecycleOwner, Observer {
// binding.btnExit.visibility = View.GONE
// binding.CLMainPatientAppeals.visibility = View.GONE
//
// })
// fixedRateTimer("timer", false, 0, 10000) {
// activity?.runOnUiThread {
//
// }
// }
}
private fun getOldAppeals() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorOld("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listAppeals.body()
val Nice = listAppeals.isSuccessful
val Code = listAppeals.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
if (List?.appeals_old != null) {
model.appealsOldList.value = List.appeals_old
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получение необработанных сообщений
private fun getNewAppeals() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorNew("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listAppeals.body()
val Nice = listAppeals.isSuccessful
val Code = listAppeals.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
if(List.appeals_new != null){
model.appealsNewList.value = List.appeals_new
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Функция подключения переключения
private fun init() = with(binding) {
val adapter = VpAdapter(activity as FragmentActivity, flist)
vpProduct.adapter = adapter
//Переключения (связываем таблаяут(переключатель) с viewpager, чтобы переключать фрагменты)
TabLayoutMediator(tabLayoutProduct, vpProduct) { tab, pos ->
tab.text =
tList[pos]//tab - нажатая кнопка, pos - позиция кнопки, tList[pos] - передаем название по полученной позиции
}.attach()// attach() - чтобы все переключалось, а не вывадило постоянно один экран
//Изменения цвета в зависомости на каком из tabLayout вы находитесь
binding.tabLayoutProduct.setTabTextColors(
getResources().getColor(R.color.black),
getResources().getColor(R.color.white)
);
}
// //Получение необработанных сообщений
// private fun addCheckAppeals(id: Int, id_patient: Int) {
// if (enternetCheck.isOnline(requireContext())) {
// initRetrofit()
// val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
// CoroutineScope(Dispatchers.IO).launch {
// val listAppeals = doctorApi.UpdateMessageDoctor("Bearer $Tokens", id, id_patient)
// requireActivity().runOnUiThread {
//
// //Фиксируем полученные данные
// val AppealsMes = listAppeals.body()
//
// //Если нету ошибок
// if (AppealsMes != null) {
// Toast(requireContext()).showCustomInfoToast(
// AppealsMes.message,
// requireActivity()
// )
// }
//
// }
//
// }
// } else {
// val intetn = Intent(requireContext(), EnternetActivity::class.java)
// activity?.finish()
// startActivity(intetn)
// }
//
// }
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
// private fun GetPatientID(idPatient: Int) {
// if (enternetCheck.isOnline(requireContext())) {
// initRetrofit()
// val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
// CoroutineScope(Dispatchers.IO).launch {
// val listPatient = doctorApi.GetPatientID("Bearer $Tokens", idPatient)
// requireActivity().runOnUiThread {
//
// //Фиксируем полученные данные
// val patientId = listPatient.body()
//
// //Если нету ошибок
// if (patientId != null) {
// //Вывод фрагмента на активити при первоначальной загрузке
//// activity?.supportFragmentManager?.beginTransaction()
//// ?.replace(R.id.CLMainPatientAppeals, PatientFragment.newInstance())
//// ?.commit()
// model.patientCurrent.value = patientId
//
// }
// }
//
// }
// } else {
// val intetn = Intent(requireContext(), EnternetActivity::class.java)
// activity?.finish()
// startActivity(intetn)
// }
//
// }
companion object {
fun newInstance() = AppealsFragment()
}
override fun onStart() {
super.onStart()
checkForUpdates(true)
}
override fun onStop() {
super.onStop()
timer.cancel()
timer.purge()
}
private fun checkForUpdates(daemonIsTrue: Boolean) {
timer = fixedRateTimer("default", daemonIsTrue, 0, 10000) {
activity?.runOnUiThread {
getOldAppeals()
getNewAppeals()
}
}
}
}

View File

@ -0,0 +1,118 @@
package com.example.doctor.Appeals
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.Appeals.TabLayout.Model.AppealsNewModel
import com.example.doctor.Appeals.TabLayout.Model.AppealsOldModel
import com.example.doctor.R
import com.example.doctor.databinding.ItemAppealsNewBinding
class AppealsNewAdapter(val listener_check_apeals: Listener, val listener_patient_apeals: Listener2) :
ListAdapter<AppealsNewModel, AppealsNewAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_check_apeals: Listener, val listener_patient_apeals: Listener2) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding =
ItemAppealsNewBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: AppealsNewModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
binding.btnAdd.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
itemTemp?.let { it1 -> listener_check_apeals.onClickAppeals(it1) }
}
binding.btnPatient.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
itemTemp?.let { it2 -> listener_patient_apeals.onClickAppealsPatient(it2) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: AppealsNewModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumber.text = item.number.toString()+"."
txtAppeals.text = item.text
txtLoginPatient.text = item.login
if (item.expand) {
txtAppeals.maxLines = 30
} else {
txtAppeals.maxLines = 1
}
CardViewNew.setOnClickListener {
if (item.expand == false) {
txtAppeals.maxLines = 100
item.expand = true
} else {
txtAppeals.maxLines = 1
item.expand = false
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_appeals_new, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_check_apeals,listener_patient_apeals)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<AppealsNewModel>() {
override fun areItemsTheSame(
oldItem: AppealsNewModel,
newItem: AppealsNewModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: AppealsNewModel,
newItem: AppealsNewModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
interface Listener {
fun onClickAppeals(item: AppealsNewModel)
}
interface Listener2 {
fun onClickAppealsPatient(item: AppealsNewModel)
}
}

View File

@ -0,0 +1,116 @@
package com.example.doctor.Appeals
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.Appeals.TabLayout.Model.AppealsOldModel
import com.example.doctor.Appeals.TabLayout.OldAppealsFragment
import com.example.doctor.R
import com.example.doctor.databinding.ItemAppealsOldBinding
class AppealsOldAdapter(val listener_appeal: Listener, val listener_patient_apeals: OldAppealsFragment) :
ListAdapter<AppealsOldModel, AppealsOldAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_appeal: Listener, val listener_patient_apeals: OldAppealsFragment) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding =
ItemAppealsOldBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: AppealsOldModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
itemView.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
itemTemp?.let { it1 -> listener_appeal.onClickAppeals(it1) }
}
binding.btnPatient.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
itemTemp?.let { it2 -> listener_patient_apeals.onClickAppealsPatient(it2) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: AppealsOldModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumber.text = item.number.toString()+"."
txtAppeals.text = item.text
txtLoginPatient.text = item.login
if (item.expand) {
binding.txtAppeals.maxLines = 100
} else {
binding.txtAppeals.maxLines = 1
}
binding.CardViewOld.setOnClickListener {
if (item.expand == false) {
binding.txtAppeals.maxLines = 100
item.expand = true
} else {
binding.txtAppeals.maxLines = 1
item.expand = false
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_appeals_old, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_appeal,listener_patient_apeals)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<AppealsOldModel>() {
override fun areItemsTheSame(
oldItem: AppealsOldModel,
newItem: AppealsOldModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: AppealsOldModel,
newItem: AppealsOldModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickAppeals(item: AppealsOldModel)
}
interface Listener2 {
fun onClickAppealsPatient(item: AppealsOldModel)
}
}

View File

@ -0,0 +1,275 @@
package com.example.doctor.Appeals
import android.content.Intent
import android.os.Bundle
import android.transition.TransitionInflater
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Reports.PatientFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentCreateMessageBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class CreateMessageFragment : Fragment() {
private lateinit var binding: FragmentCreateMessageBinding
private val dataModel: DataModel by activityViewModels()//Для передачи данных
private val modelDoctor: DoctorViewModel by activityViewModels()
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
var patientList:List<PatientAllModel>?=null
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentCreateMessageBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val inflater = TransitionInflater.from(requireContext())
enterTransition = inflater.inflateTransition(R.transition.slide_right)
exitTransition = inflater.inflateTransition(R.transition.slide_right)
GetPatientList()
binding.btnAddMessagePatient.setOnClickListener{
val login = binding.searchPatient.text.toString()
val text = binding.edTextMessagePatient.text.toString()
if(login!="" && text!=""){
AddMessageDoctor()
}
else{
Toast(requireContext()).showCustomInfoToast("Не все данные заполнены", requireActivity())
}
}
// binding.btnExit.setOnClickListener{
// dataModel.patientAppeal.value = 1
// }
binding.btnExit.setOnClickListener{
activity?.finish()
}
modelDoctor.patientListSearch.observe(viewLifecycleOwner){
if(patientList!=it){
patientList =it
addPatientLogin(it)
}
}
// fixedRateTimer("timer", false, 0, 10000) {
// activity?.runOnUiThread {
//
// }
// }
}
private fun addPatientLogin(patient: List<PatientAllModel>) {
val listPatient = arrayListOf("")
for(i in 0 .. patient.count()-1){
listPatient.add(patient[i].login.toString())
}
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, listPatient)
binding.searchPatient.threshold = 1
binding.searchPatient.setAdapter(adapter)
binding.searchPatient.setOnItemClickListener { parent, arg1, pos, id ->
//val list = ArrayList<PatientModel>()
val serpat = binding.searchPatient.text.toString()
binding.searchPatient.setText(serpat)
}
}
//Получения списка пациентов
fun GetPatientList() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetPatientAll("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
//Если нету ошибок
if (List != null) {
modelDoctor.patientListSearch.value = List.patient
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Отправка сообщения
fun AddMessageDoctor() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.AddMessageDoctor("Bearer $Tokens",binding.searchPatient.text.toString(),binding.edTextMessagePatient.text.toString())
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
if (Nice) {
if (List != null) {
//Если нету ошибок
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
binding.edTextMessagePatient.setText("")
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
companion object {
fun newInstance() = CreateMessageFragment()
}
override fun onResume() {
super.onResume()
checkForUpdates(true)
}
override fun onStop() {
super.onStop()
timer.cancel()
timer.purge()
}
private fun checkForUpdates(daemonIsTrue: Boolean) {
timer = fixedRateTimer("default", daemonIsTrue, 0, 10000) {
activity?.runOnUiThread {
GetPatientList()
}
}
}
}

View File

@ -0,0 +1,6 @@
package com.example.doctor.Appeals.TabLayout.Model
data class AppealsNewListModel(
val appeals_new: List<AppealsNewModel>
)

View File

@ -0,0 +1,16 @@
package com.example.doctor.Appeals.TabLayout.Model
data class AppealsNewModel(
val id: Int,
val number: Int,
val text: String,
val id_patient: Int,
val id_doctor: Int,
val check: Int,
val login: String,
val created_at: String,
val updated_at: String,
var expand : Boolean = false,
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Appeals.TabLayout.Model
data class AppealsOldListModel(
val appeals_old: List<AppealsOldModel>
)

View File

@ -0,0 +1,16 @@
package com.example.doctor.Appeals.TabLayout.Model
data class AppealsOldModel(
val id: Int,
val number: Int,
val text: String,
val id_patient: Int,
val id_doctor: Int,
val check: Int,
val login: String,
val created_at: String,
val updated_at: String,
var expand : Boolean = false,
)

View File

@ -0,0 +1,292 @@
package com.example.doctor.Appeals.TabLayout
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Appeals.AppealsNewAdapter
import com.example.doctor.Appeals.TabLayout.Model.AppealsNewModel
import com.example.doctor.Appeals.TabLayout.Model.AppealsOldModel
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Model.PatientIdModel
import com.example.doctor.Patients.PatientActivity
import com.example.doctor.Patients.PatientsListFragment
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentNewAppealsBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class NewAppealsFragment : Fragment(), AppealsNewAdapter.Listener,AppealsNewAdapter.Listener2 {
private lateinit var binding:FragmentNewAppealsBinding
private val model: DoctorViewModel by activityViewModels()
private val dataModel: DataModel by activityViewModels()//Для передачи данных
lateinit var adapter: AppealsNewAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
//Список новых соощений
var newAppeals: List<AppealsNewModel>? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentNewAppealsBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//binding.CLNull.visibility = View.VISIBLE
initRcViewAppeals()
patientListCurrent()
model.appealsNewList.observe(viewLifecycleOwner) {//viewLifecycleOwner - следит за циклом жизни fragment
if(newAppeals != it){
newAppeals = it
adapter.submitList(it)//Напрямую переадем созданный список в adapter(ProductAdapter)
if(newAppeals !=null){
binding.CLNull.visibility = View.GONE
binding.txtNull.visibility = View.GONE
}
}
}
getNewAppeals()
}
//Получение необработанных сообщений
private fun getNewAppeals() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorNew("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listAppeals.body()
val Nice = listAppeals.isSuccessful
val Code = listAppeals.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if(List?.appeals_new != null){
// binding.CLNull.visibility = View.GONE
binding.txtNull.visibility = View.GONE
model.appealsNewList.value = List.appeals_new
}
else{
// binding.CLNull.visibility = View.VISIBLE
binding.txtNull.visibility = View.VISIBLE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
private fun getOldAppeals() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorOld("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listAppeals.body()
val Nice = listAppeals.isSuccessful
val Code = listAppeals.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if(List?.appeals_old != null){
// binding.txtNull.visibility = View.GONE
model.appealsOldList.value = List.appeals_old
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получение необработанных сообщений
private fun addCheckAppeals(id:Int,id_patient:Int) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.UpdateMessageDoctor("Bearer $Tokens",id,id_patient)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listAppeals.body()
val Nice = listAppeals.isSuccessful
val Code = listAppeals.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
}
}
getNewAppeals()
getOldAppeals()
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Вывод прогресса на один день
private fun patientListCurrent() = with(binding) {
// model.appealsAllCurrent.observe(viewLifecycleOwner) {//viewLifecycleOwner - следит за циклом жизни fragment
//
// }
}
//Инициализация списка
private fun initRcViewAppeals() = with(binding) {
rcView.layoutManager = GridLayoutManager(requireContext(),1)//По вертикали будет выводить по умолчанию
adapter = AppealsNewAdapter(this@NewAppealsFragment,this@NewAppealsFragment)
rcView.adapter = adapter
}
companion object {
fun newInstance() = NewAppealsFragment()
}
override fun onClickAppeals(item: AppealsNewModel) {
addCheckAppeals(item.id,item.id_patient)
}
override fun onClickAppealsPatient(item: AppealsNewModel) {
prefDoctorSave.saveIdPatient(requireContext(),item.id_patient)
prefDoctorSave.saveViewPatient(requireContext(),1)
model.patientId.value = PatientIdModel(item.id)
//dataModel.patientAppeal.value = item.id_patient
val intetn = Intent(requireContext(), PatientActivity::class.java)
startActivity(intetn)
}
}

View File

@ -0,0 +1,197 @@
package com.example.doctor.Appeals.TabLayout
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Appeals.AppealsOldAdapter
import com.example.doctor.Appeals.TabLayout.Model.AppealsNewModel
import com.example.doctor.Appeals.TabLayout.Model.AppealsOldModel
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Model.PatientIdModel
import com.example.doctor.Patients.PatientActivity
import com.example.doctor.Patients.PatientsListFragment
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.FragmentOldAppealsBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import kotlin.concurrent.fixedRateTimer
class OldAppealsFragment : Fragment(), AppealsOldAdapter.Listener,AppealsOldAdapter.Listener2 {
private lateinit var binding:FragmentOldAppealsBinding
private val model: DoctorViewModel by activityViewModels()
private val dataModel: DataModel by activityViewModels()//Для передачи данных
lateinit var adapter: AppealsOldAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
//Список прочитанных соощений
var oldAppeals: List<AppealsOldModel>? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentOldAppealsBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//binding.CLNull.visibility = View.VISIBLE
initRcViewAppeals()
appealsAllCurrent()
model.appealsOldList.observe(viewLifecycleOwner) {//viewLifecycleOwner - следит за циклом жизни fragment
if(oldAppeals != it){
oldAppeals = it
adapter.submitList(it)//Напрямую переадем созданный список в adapter(ProductAdapter)
if(oldAppeals !=null){
binding.CLNull.visibility = View.GONE
binding.txtNull.visibility = View.GONE
}
}
}
getOldAppeals()
// fixedRateTimer("timer", false, 0, 10000) {
// activity?.runOnUiThread {
//
// }
// }
}
private fun getOldAppeals() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorOld("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listAppeals.body()
val Nice = listAppeals.isSuccessful
val Code = listAppeals.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
//Если нету ошибок
if (List != null) {
if(List.appeals_old != null){
//binding.CLNull.visibility = View.GONE
binding.txtNull.visibility = View.GONE
model.appealsOldList.value = List.appeals_old
}
else{
//binding.CLNull.visibility = View.VISIBLE
binding.txtNull.visibility = View.VISIBLE
}
}else{
// binding.CLNull.visibility = View.VISIBLE
binding.txtNull.visibility = View.VISIBLE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Вывод прогресса на один день
private fun appealsAllCurrent() = with(binding) {
// model.appealsAllCurrent.observe(viewLifecycleOwner) {//viewLifecycleOwner - следит за циклом жизни fragment
//
// }
}
//Инициализация списка
private fun initRcViewAppeals() = with(binding) {
rcView.layoutManager = GridLayoutManager(requireContext(),1)//По вертикали будет выводить по умолчанию
adapter = AppealsOldAdapter(this@OldAppealsFragment,this@OldAppealsFragment)
rcView.adapter = adapter
}
companion object {
fun newInstance() = OldAppealsFragment()
}
override fun onClickAppeals(item: AppealsOldModel) {
}
override fun onClickAppealsPatient(item: AppealsOldModel) {
// prefDoctorSave.saveIdPatient(requireContext(),item.id_patient)
// prefDoctorSave.saveViewPatient(requireContext(),1)
model.patientId.value = PatientIdModel(item.id)
// dataModel.patientAppeal.value = item.id_patient
val intetn = Intent(requireContext(), PatientActivity::class.java)
startActivity(intetn)
}
}

View File

@ -0,0 +1,22 @@
package com.example.doctor.Auth
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.doctor.R
import com.example.doctor.databinding.ActivityAuthBinding
class AuthActivity : AppCompatActivity() {
private lateinit var binding:ActivityAuthBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityAuthBinding.inflate(layoutInflater)
setContentView(binding.root)
//Вывод фрагмента на активити при первоначальной загрузке
supportFragmentManager.beginTransaction()
.replace(R.id.CLAuth, AuthFragment.newInstance())
.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}

View File

@ -0,0 +1,181 @@
package com.example.doctor.Auth
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import com.example.doctor.Auth.Model.AuthModel
import com.example.doctor.Auth.Model.UserModel
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.MainActivity
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Pref.SavePref
import com.example.doctor.Toast.showCustomDangerToast
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentAuthBinding
import com.squareup.picasso.Picasso
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
class AuthFragment : Fragment() {
private lateinit var binding: FragmentAuthBinding
private lateinit var doctorApi: DoctorApi
private val DoctorviewModel: DoctorViewModel by activityViewModels()
//private var prefToken: SharedPreferences? = null
private var Token = ""
val prefDoctorSave = SavePref()
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentAuthBinding.inflate(layoutInflater, container, false)
return binding.root
}
@SuppressLint("SuspiciousIndentation")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRetrofit()
prefDoctorClear.clearToken(requireContext())
Token = prefDoctorConclusion.conclusionToken(requireContext())
binding.apply {
binding.textError.text = ""
//Авторизоваться
binding.btnAuth.setOnClickListener {
if(edLogin.text.toString() == ""||edPassword.text.toString() == ""){
Toast(requireContext()).showCustomInfoToast(
"Не все поля заполнены",
requireActivity()
)
}
else{
Auth(
AuthModel(
edLogin.text.toString(),
edPassword.text.toString(),
)
)
}
}
}
}
private fun Auth(authModel: AuthModel) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
CoroutineScope(Dispatchers.IO).launch {
val response = doctorApi.LoginDoctor(authModel)
val errorMessage = response.errorBody()?.string()
?.let { JSONObject(it).getString("error") }//JSONObject(response.errorBody()?.string())
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = response.body()
val Nice = response.isSuccessful
val Code = response.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
DoctorviewModel.token.value = List.token
prefDoctorSave.saveToken(requireContext(), List.token)
val intetn = Intent(requireContext(), MainActivity::class.java)
startActivity(intetn)
activity?.finish()
}
else{
Toast(requireContext()).showCustomInfoToast(
"Такого пользователя нету",
requireActivity()
)
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
companion object {
fun newInstance() = AuthFragment()
}
}

View File

@ -0,0 +1,7 @@
package com.example.doctor.Auth.Model
data class AuthModel(
//val login:String,
val login:String,
val password:String,
)

View File

@ -0,0 +1,5 @@
package com.example.doctor.Auth.Model
data class CheckTokenModel(
val status:String,
)

View File

@ -0,0 +1,7 @@
package com.example.doctor.Auth.Model
data class UserModel(
val id:String,
val token:String,
)

View File

@ -0,0 +1,171 @@
//package com.example.doctor.BottomSheetMenu
//
//import android.annotation.SuppressLint
//import android.app.Dialog
//import android.graphics.Color
//import android.os.Bundle
//import android.support.annotation.Nullable
//import android.view.KeyEvent
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import android.widget.FrameLayout
//import android.widget.Toast
//import androidx.coordinatorlayout.widget.CoordinatorLayout
//import androidx.fragment.app.activityViewModels
//import com.example.doctor.DoctorViewModel
//import com.example.doctor.R
//import com.example.doctor.databinding.ItemButtomMenu2Binding
//import com.google.android.material.bottomsheet.BottomSheetBehavior
//import com.google.android.material.bottomsheet.BottomSheetDialogFragment
//
//class AccountBottomSheetMenu: BottomSheetDialogFragment() {
// private lateinit var binding: ItemButtomMenu2Binding
// private val model: DoctorViewModel by activityViewModels()//Инициализировали класс
//
// @SuppressLint("RestrictedApi")
// override fun setupDialog(dialog: Dialog, style: Int) {
// super.setupDialog(dialog, style)
//
// val view = LayoutInflater.from(context).inflate(R.layout.item_buttom_menu, null)
// dialog.setContentView(view)
//
// val param = (view.parent as View).layoutParams as CoordinatorLayout.LayoutParams
//
// val behavior = param.behavior
//
// if(behavior is BottomSheetBehavior<*>){
// behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback(){
// override fun onStateChanged(bottomSheet: View, newState: Int) {
// var state = ""
// when(newState){
// BottomSheetBehavior.STATE_DRAGGING->{
// state = "DRAGGING"
// }
// BottomSheetBehavior.STATE_SETTLING->{
// state = "SETTLING"
// }
// BottomSheetBehavior.STATE_EXPANDED->{
// state = "EXPANDED"
// }
// BottomSheetBehavior.STATE_COLLAPSED->{
// state = "COLLAPSED"
// }
// BottomSheetBehavior.STATE_HIDDEN->{
// state = "HIDDEN"
// dismiss()
// behavior.state = BottomSheetBehavior.STATE_COLLAPSED
// }
//
// }
// }
//
// override fun onSlide(bottomSheet: View, slideOffset: Float) {
//
// }
//
// })
// }
// }
//
// //Данная функция необходима чтобы убрать белый фон в нижнем всплывающем меню
// override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
//
// return super.onCreateDialog(savedInstanceState).apply {
// // window?.setDimAmount(0.2f) // Set dim amount here
// setOnShowListener {
// val bottomSheet = findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout
// bottomSheet.setBackgroundResource(android.R.color.transparent)
// }
// }
// }
//
//
// override fun onCreateView(
// inflater: LayoutInflater,
// container: ViewGroup?,
// savedInstanceState: Bundle?
// ): View? {
// binding = ItemButtomMenu2Binding.inflate(inflater,container,false)
// return binding.root
// }
//
//
//
//
// companion object {
//
// fun newInstance(): AccountBottomSheetMenu {
// val args = Bundle()
// val fragment = AccountBottomSheetMenu()
// fragment.arguments = args
// return fragment
// }
// }
//
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
//
// /* //Ввод адреса вручную
// binding.btnAdresAdd.setOnClickListener{
// binding.CardViewStart.visibility = View.GONE
// binding.CardView1.visibility = View.VISIBLE
// }
// //Вернутся из ввода адреса
// binding.btnBack.setOnClickListener{
// binding.CardViewStart.visibility = View.VISIBLE
// binding.CardView1.visibility = View.GONE
// }*/
// //Оформления заказа по введенному адресу
// /* binding.btnAddZakaz.setOnClickListener{
// setListener()
// }*/
// /*//Оформления заказа по адресу из профиля
// binding.btnZakazAdresUserProfile.setOnClickListener{
// setListener()
// }*/
// //Вызов фунции
// setListener()
//
//
// //binding.textView34.setText(binding.editTextAdres.getText().toString())
// }
//
// //Функция оформления заказа
// private fun setListener(){
// /* binding.btnAddZakaz.setOnClickListener{
// adresUser = binding.editTextAdres.text.toString()
// if(adresUser == ""){
// Toast.makeText(requireContext(), "Нужен адрес", Toast.LENGTH_SHORT).show()
// }
// else{
// //Данная модель нужна только для того чтобы передать сигнал для BasketFragmen и в случае если true, то он вызовет запрос и прогрузочный экран
// val itemStatus = StatusModel(true)
// model.addZakaz.value = itemStatus
// dismiss()//После нажатия закрываем
// }
// //requestWithSomeHttpHeadersZakaz(requireContext(), adresUser)
// }
// binding.editTextAdres.setOnKeyListener { v, keyCode, event ->
//
// when {
// //Проверяем нажалили мы на "ввод"
// //Check if it is the Enter-Key, Check if the Enter Key was pressed down
// ((keyCode == KeyEvent.KEYCODE_ENTER) && (event.action == KeyEvent.ACTION_DOWN)) -> {
//
// //Если да, то выполняем нажати на кнопку отправки сообщения
// binding.btnAddZakaz.performClick()
//
// //return true
// return@setOnKeyListener true
// }
// else -> false
// }
//
//
// }*/
//
// }
//
//}

View File

@ -0,0 +1,176 @@
package com.example.user.BottomSheetMenu
import android.annotation.SuppressLint
import android.app.Dialog
import android.graphics.Color
import android.os.Bundle
import android.support.annotation.Nullable
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.activityViewModels
import com.example.doctor.DoctorViewModel
import com.example.doctor.Patients.Model.CreatePatientModel
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.ItemButtomMenuBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class NoteBottomSheetMenu: BottomSheetDialogFragment() {
private lateinit var binding: ItemButtomMenuBinding
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
@SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = LayoutInflater.from(context).inflate(R.layout.item_buttom_menu, null)
dialog.setContentView(view)
val param = (view.parent as View).layoutParams as CoordinatorLayout.LayoutParams
val behavior = param.behavior
if(behavior is BottomSheetBehavior<*>){
behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback(){
override fun onStateChanged(bottomSheet: View, newState: Int) {
var state = ""
when(newState){
BottomSheetBehavior.STATE_DRAGGING->{
state = "DRAGGING"
}
BottomSheetBehavior.STATE_SETTLING->{
state = "SETTLING"
}
BottomSheetBehavior.STATE_EXPANDED->{
state = "EXPANDED"
}
BottomSheetBehavior.STATE_COLLAPSED->{
state = "COLLAPSED"
}
BottomSheetBehavior.STATE_HIDDEN->{
state = "HIDDEN"
dismiss()
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {
}
})
}
}
//Данная функция необходима чтобы убрать белый фон в нижнем всплывающем меню
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).apply {
// window?.setDimAmount(0.2f) // Set dim amount here
setOnShowListener {
val bottomSheet = findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout
bottomSheet.setBackgroundResource(android.R.color.transparent)
}
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = ItemButtomMenuBinding.inflate(inflater,container,false)
return binding.root
}
companion object {
fun newInstance(): NoteBottomSheetMenu {
val args = Bundle()
val fragment = NoteBottomSheetMenu()
fragment.arguments = args
return fragment
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.btnAddPatient.setOnClickListener{
if(binding.edEmail.text.toString() == "" && binding.edPassword.text.toString() == ""){
Toast(requireContext()).showCustomInfoToast("Не все поля заполнены", requireActivity())
}
else{
CreateAccountPatient(CreatePatientModel(binding.edEmail.text.toString(),binding.edPassword.text.toString()))
}
}
}
fun CreateAccountPatient(createPatientModel: CreatePatientModel) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.CreateAccountPatient("Bearer $Tokens",createPatientModel)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val patientList = listProduct.body()
//Если нету ошибок
if (patientList != null) {
Toast(requireContext()).showCustomInfoToast("Аккаунт для пациента создан", requireActivity())
dismiss()//После нажатия закрываем
}
else{
Toast(requireContext()).showCustomInfoToast("Ошибка валидации", requireActivity())
}
}
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("http://mobileapp.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
}

View File

@ -0,0 +1,5 @@
package com.example.doctor.BottomSheetMenu
data class StatusModel(
val status: Boolean = false
)

View File

@ -0,0 +1,136 @@
package com.example.doctor.CodeError
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.MainActivity
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.ActivityCode429Binding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class Code429Activity : AppCompatActivity() {
private lateinit var binding:ActivityCode429Binding
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCode429Binding.inflate(layoutInflater)
setContentView(binding.root)
}
fun CheckToken(){
if (enternetCheck.isOnline(this@Code429Activity)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this@Code429Activity)
CoroutineScope(Dispatchers.IO).launch {
val list = doctorApi.CheckToken("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val List = list.body()
val Nice = list.isSuccessful
val Code = list.code()
if(Code==500){
val intetn = Intent(this@Code429Activity, Code500Activity::class.java)
finish()
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
//Если нету ошибок
if (List != null) {
Log.i("clogon1231111","clogon1231111")
finish()
}
}
}
else if (Code == 401) {
val intetn = Intent(this@Code429Activity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
override fun onResume() {
super.onResume()
checkForUpdates(true)
}
override fun onStop() {
super.onStop()
timer.cancel()
timer.purge()
}
private fun checkForUpdates(daemonIsTrue: Boolean) {
timer = fixedRateTimer("default", daemonIsTrue, 0, 15000) {
this@Code429Activity.runOnUiThread {
CheckToken()
}
}
}
}

View File

@ -0,0 +1,178 @@
package com.example.doctor.CodeError
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.CountDownTimer
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.core.content.ContentProviderCompat.requireContext
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.MainActivity
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.ActivityCode500Binding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class Code500Activity : AppCompatActivity() {
private lateinit var binding: ActivityCode500Binding
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
var checkClose = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCode500Binding.inflate(layoutInflater)
setContentView(binding.root)
// val fixedRateTimer = fixedRateTimer("hello-timer",
// false,0,5000) {
//
// }
// try {
// this@Code500Activity.runOnUiThread {
// CheckToken()
// }
// }
// finally {
// fixedRateTimer.cancel();
// }
//ПОСТОЯННО ВЫЗЫВАЕТСЯ НУЖНО КАК-ТО ОТКЛЮЧАТЬ
// fixedRateTimer("timer", false, 0, 10000) {
// this@Code500Activity?.runOnUiThread {
// }
// }
binding.apply {
val timer = object: CountDownTimer(30000, 1000) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
val intetn = Intent(this@Code500Activity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
timer.start()
}
}
fun CheckToken(){
if (enternetCheck.isOnline(this@Code500Activity)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this@Code500Activity)
CoroutineScope(Dispatchers.IO).launch {
val list = doctorApi.CheckToken("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val List = list.body()
val Nice = list.isSuccessful
val Code = list.code()
if(Code==429){
val intetn = Intent(this@Code500Activity, Code429Activity::class.java)
finish()
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
//Если нету ошибок
if (List != null) {
Log.i("clogon1231111","clogon1231111")
finish()
}
}
}
else if (Code == 401) {
val intetn = Intent(this@Code500Activity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
override fun onResume() {
super.onResume()
checkForUpdates(true)
}
override fun onStop() {
super.onStop()
timer.cancel()
timer.purge()
}
private fun checkForUpdates(daemonIsTrue: Boolean) {
timer = fixedRateTimer("default", daemonIsTrue, 0, 15000) {
this@Code500Activity.runOnUiThread {
CheckToken()
}
}
}
}

View File

@ -0,0 +1,30 @@
package com.example.doctor
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
//Ослеживание за обновлением подробной продуктовой карточкой
open class DataModel: ViewModel() {
/*//Для отлеживания обновлений активити
val messageForActivity: MutableLiveData<String> by lazy{//by lazy - чтобы каждый раз не создавался MutableLiveData(MutableLiveData<String>()), а он один раз при загрузке создаться и дальше будет пользоваться уже созданным
MutableLiveData<String>()//LiveData - означает что будет обновляться в нужынй момент, не постоянна, а в зависимоти от жизни активити
}*/
//Для отлеживания обновлений фрагммента 1
val messageForFrag1: MutableLiveData<Int> by lazy{//by lazy - чтобы каждый раз не создавался MutableLiveData(MutableLiveData<String>()), а он один раз при загрузке создаться и дальше будет пользоваться уже созданным
MutableLiveData<Int>()//LiveData - означает что будет обновляться в нужынй момент, не постоянна, а в зависимоти от жизни активити
}
val fragmentMenu: MutableLiveData<Int> by lazy{//by lazy - чтобы каждый раз не создавался MutableLiveData(MutableLiveData<String>()), а он один раз при загрузке создаться и дальше будет пользоваться уже созданным
MutableLiveData<Int>()//LiveData - означает что будет обновляться в нужынй момент, не постоянна, а в зависимоти от жизни активити
}
val patientList: MutableLiveData<Int> by lazy{//by lazy - чтобы каждый раз не создавался MutableLiveData(MutableLiveData<String>()), а он один раз при загрузке создаться и дальше будет пользоваться уже созданным
MutableLiveData<Int>()//LiveData - означает что будет обновляться в нужынй момент, не постоянна, а в зависимоти от жизни активити
}
val patientAppeal: MutableLiveData<Int> by lazy{//by lazy - чтобы каждый раз не создавался MutableLiveData(MutableLiveData<String>()), а он один раз при загрузке создаться и дальше будет пользоваться уже созданным
MutableLiveData<Int>()//LiveData - означает что будет обновляться в нужынй момент, не постоянна, а в зависимоти от жизни активити
}
/*//Для отлеживания обновлений фрагммента 2
val messageForFrag2: MutableLiveData<String> by lazy{//by lazy - чтобы каждый раз не создавался MutableLiveData(MutableLiveData<String>()), а он один раз при загрузке создаться и дальше будет пользоваться уже созданным
MutableLiveData<String>()//LiveData - означает что будет обновляться в нужынй момент, не постоянна, а в зависимоти от жизни активити
}*/
}

View File

@ -0,0 +1,93 @@
package com.example.doctor
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.doctor.Appeals.TabLayout.Model.AppealsNewModel
import com.example.doctor.Appeals.TabLayout.Model.AppealsOldModel
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Model.PatientIdModel
import com.example.doctor.Patients.Model.PatientModel
import com.example.doctor.Patients.Reports.Courses.SportCoursModel
import com.example.doctor.Patients.Reports.Edit.EditSportModel
import com.example.doctor.Patients.Reports.QBAModel
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.EditCoursesDoctorModel
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.CoursesDoctorCA
import com.example.doctor.Setting.Courses.Model.CoursesDoctorModel
//import com.example.retrofit.model.Product
class DoctorViewModel: ViewModel() {
//Токен
val token = MutableLiveData<String>()
//Пациенты
val patientId = MutableLiveData<PatientIdModel>()
val patientCurrent = MutableLiveData<PatientAllModel>()
val patientListList= MutableLiveData<PatientAllModel>()
//Обращения необработанные
val appealsNewCurrent = MutableLiveData<AppealsNewModel>()
val appealsNewList= MutableLiveData<List<AppealsNewModel>>()
//Обращения обработанные
val appealsOldCurrent = MutableLiveData<AppealsOldModel>()
val appealsOldList= MutableLiveData<List<AppealsOldModel>>()
//val productList = MutableLiveData<List<Product>>()
val patientOneCurrent = MutableLiveData<PatientModel>()
//Отчеты
val qbaCurrent = MutableLiveData<QBAModel>()
val qbaList= MutableLiveData<List<QBAModel>>()
//КУрсы
val SportCoursCurrent = MutableLiveData<SportCoursModel>()
val SportCoursList= MutableLiveData<List<SportCoursModel>>()
val SportCoursDoctorList= MutableLiveData<List<SportCoursModel>>()
val BtnSportCoursDoctorCurrent = MutableLiveData<Int>()
//Редактирование занятий
val EditSportCurrentYes = MutableLiveData<EditSportModel>()
val EditSportListYes= MutableLiveData<List<EditSportModel>>()
//Редактирование занятий
val EditSportCurrentNO = MutableLiveData<EditSportModel>()
val EditSportListNo= MutableLiveData<List<EditSportModel>>()
//Список пациентов
val PatientActiveCurrent = MutableLiveData<PatientAllModel>()
val PatientActiveList= MutableLiveData<List<PatientAllModel>>()
val PatientNotCurrent = MutableLiveData<PatientAllModel>()
val PatientNotList= MutableLiveData<List<PatientAllModel>>()
//Список со всеми пациентами
val PatientAllModel= MutableLiveData<List<PatientAllModel>>()
//id пациента
val id_patient = MutableLiveData<Int>()
//Курсы созданный доктором
val CoursesDoctorCurrent = MutableLiveData<CoursesDoctorModel>()
val CoursesDoctorList= MutableLiveData<List<CoursesDoctorModel>>()
//Упражнения не входяшие в курс доктора
val EditCoursesDoctorAllCurrent = MutableLiveData<EditCoursesDoctorModel>()
val EditCoursesDoctorAllList= MutableLiveData<List<EditCoursesDoctorModel>>()
//Упражнения входяшие в курс доктора
val EditCoursesDoctorYourCurrent = MutableLiveData<EditCoursesDoctorModel>()
val EditCoursesDoctorYourList= MutableLiveData<List<EditCoursesDoctorModel>>()
val CoursesDoctorCA = MutableLiveData<CoursesDoctorCA>()
//Список пациентов для поисковой строки
val patientListSearch= MutableLiveData<List<PatientAllModel>>()
//Для передачи данных редактируемого курса
val CoursesCustomDoctor = MutableLiveData<CoursesDoctorModel>()
}

View File

@ -0,0 +1,23 @@
package com.example.doctor.Enternet
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.doctor.R
import com.example.doctor.databinding.ActivityEnternetBinding
import com.example.doctor.databinding.FragmentEnternetBinding
class EnternetActivity : AppCompatActivity() {
private lateinit var binding: ActivityEnternetBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityEnternetBinding.inflate(layoutInflater)
setContentView(binding.root)
supportFragmentManager.beginTransaction()
.replace(R.id.CLEnternet, EnternetFragment.newInstance())
.commit()
}
}

View File

@ -0,0 +1,41 @@
package com.example.doctor.Enternet
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
class EnternetCheck() {
//Проверка интернета
fun isOnline(context: Context): Boolean {
if (context == null) return false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val capabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
if (capabilities != null) {
when {
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> {
return true
}
}
}
} else {
val activeNetworkInfo = connectivityManager.activeNetworkInfo
if (activeNetworkInfo != null && activeNetworkInfo.isConnected) {
return true
}
}
return false
}
}

View File

@ -0,0 +1,38 @@
package com.example.doctor.Enternet
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.doctor.MainActivity
import com.example.doctor.databinding.FragmentEnternetBinding
class EnternetFragment : Fragment() {
private lateinit var binding: FragmentEnternetBinding
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentEnternetBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.btnEnternet.setOnClickListener{
val intetn = Intent(requireContext(), MainActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
companion object {
fun newInstance() = EnternetFragment()
}
}

View File

@ -0,0 +1,142 @@
package com.example.doctor.Home
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.FragmentHomeBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding
private val dataModel: DataModel by activityViewModels()//Для передачи данных
private var Token = ""
val prefDoctorClear= ClearPref()
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
private val modelDoctor: DoctorViewModel by activityViewModels()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentHomeBinding.inflate(layoutInflater,container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.CVPatinet.setOnClickListener {
dataModel.fragmentMenu.value = R.id.patient
}
binding.CVAppeals.setOnClickListener {
dataModel.fragmentMenu.value = R.id.list_check
}
CountPatientAndAppeals()
}
//Получение данных для главной страницы
fun CountPatientAndAppeals() = with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listHomeView = doctorApi.CountPatientAndAppeals("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listHomeView.body()
val Nice = listHomeView.isSuccessful
val Code = listHomeView.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
txtCountPatient.text = List?.patient.toString()
txtCountAppealsNew.text = List?.appeals_check.toString()
txtCountAppealsAll.text = List?.appeals_all.toString()
CLLoad.visibility = View.GONE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
companion object {
fun newInstance() = HomeFragment()
}
}

View File

@ -0,0 +1,8 @@
package com.example.doctor.Home
data class HomeInfoModel(
val patient: Int,
val appeals_check: Int,
val appeals_all: Int,
)

View File

@ -0,0 +1,484 @@
package com.example.doctor
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.ArrayAdapter
import android.widget.RemoteViews
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.constraintlayout.widget.ConstraintSet.Constraint
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequest
import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager
import androidx.work.WorkRequest
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.Auth.AuthFragment
import com.example.doctor.Auth.Model.AuthModel
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.Worker.MyWorker
import com.example.doctor.databinding.ActivityMainBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
import android.app.TaskStackBuilder
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.view.View
import androidx.activity.viewModels
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.test.core.app.ActivityScenario.launch
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Enternet.EnternetFragment
import kotlinx.coroutines.Job
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
//Токен
private var Token = ""
val prefDoctorSave = SavePref()
val prefDoctorConclusion = ConclusionPref()
var backPressedTime: Long = 0
lateinit var notificationManager: NotificationManager
lateinit var notificationChannel: NotificationChannel
lateinit var builder: Notification.Builder
private val channelId = "i.apps.notifications"
private val description = "Test notification"
val CHANNEL_ID = "channelID"
val CHANNEL_NAME = "channelName"
val NOTIF_ID = 0
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
private val modelDoctor: DoctorViewModel by viewModels()//Инициализировали класс
@SuppressLint("RemoteViewLayout", "MissingPermission")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
MainAndAuth()
}
//Получение необработанных сообщений
private fun getNewAppeals() {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorNew("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val AppealsMes = listAppeals.body()
//Если нету ошибок
if (AppealsMes != null) {
if (AppealsMes.appeals_new != null) {
modelDoctor.appealsNewList.value = AppealsMes.appeals_new
}
}
}
}
} else {
// finish()
// val intetn = Intent(this, EnternetActivity::class.java)
// startActivity(intetn)
}
}
//Получение обработанных сообщений
private fun getOldAppeals() {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listAppeals = doctorApi.GetAppealsDoctorOld("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val AppealsMes = listAppeals.body()
//Если нету ошибок
if (AppealsMes != null) {
if (AppealsMes.appeals_old != null) {
modelDoctor.appealsOldList.value = AppealsMes.appeals_old
}
}
}
}
} else {
// finish()
// val intetn = Intent(this, EnternetActivity::class.java)
// startActivity(intetn)
}
}
//Получения списка пациентов для поиска
fun GetPatientListSearch() {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listPatientList = doctorApi.GetPatientAll("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val patientList = listPatientList.body()
//Если нету ошибок
if (patientList != null) {
modelDoctor.patientListSearch.value = patientList.patient
}
}
}
} else {
// finish()
// val intetn = Intent(this, EnternetActivity::class.java)
// startActivity(intetn)
}
}
//Получения списка пациентов
fun GetPatientListYes() {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetPatientAllActive("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val patientList = listProduct.body()
//Если нету ошибок
if (patientList != null) {
modelDoctor.PatientActiveList.value = patientList.patient
}
}
}
} else {
// finish()
// val intetn = Intent(this, EnternetActivity::class.java)
// startActivity(intetn)
}
}
//Получения списка пациентов
fun GetPatientListNo() {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetPatientAllNotActive("Bearer $Tokens")
runOnUiThread {
//Фиксируем полученные данные
val patientList = listProduct.body()
//Если нету ошибок
if (patientList != null) {
modelDoctor.PatientNotList.value = patientList.patient
}
}
}
} else {
// finish()
// val intetn = Intent(this, EnternetActivity::class.java)
// startActivity(intetn)
}
}
// private fun createNotifChannel() {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// val channel = NotificationChannel(
// CHANNEL_ID,
// CHANNEL_NAME,
// NotificationManager.IMPORTANCE_DEFAULT
// ).apply {
// lightColor = Color.BLUE
// enableLights(true)
// }
// val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
// manager.createNotificationChannel(channel)
// }
// }
// //Одинарный
// fun myOneTimeWork() {
// val constraints = Constraints.Builder()
// .setRequiredNetworkType(NetworkType.NOT_REQUIRED)//Тут мы указыаем что сработает при наличие интернета
// .setRequiresCharging(true)
// .build()
//
// //Ограничение
// val myWorkRequest: WorkRequest =
// OneTimeWorkRequest.Builder(MyWorker::class.java)//OneTimeWorkRequest - разовая
// .setConstraints(constraints)
// .build()
//
// WorkManager.getInstance(this@MainActivity).enqueue(myWorkRequest)//Отправка запроса
// }
// //Повторяющийся
// fun myPriodicTimeWork() {
// val constraints = Constraints.Builder()
// .setRequiredNetworkType(NetworkType.NOT_REQUIRED)//Тут мы указыаем что сработает при наличие интернета
// .setRequiresCharging(true)
// .build()
//
// //Ограничение
// val myWorkRequest = PeriodicWorkRequest.Builder(
// MyWorker::class.java,
// 15,
// TimeUnit.MINUTES
// )//PeriodicWorkRequest - переодически, 15 - время интервала(минимальное 15 минут)
// .setConstraints(constraints)
// .addTag("my_id")//Уникальный индификатор для уведомления, для того чтобы можно было кпримеру обратиться и остановать данный менеджер
// .build()
//
// WorkManager.getInstance(this@MainActivity).enqueueUniquePeriodicWork(
// "my_id",
// ExistingPeriodicWorkPolicy.KEEP,
// myWorkRequest
// )//Отправка запроса
// }
fun MainAndAuth() {
Token = prefDoctorConclusion.conclusionToken(this@MainActivity)
//CheckTokenAuth(Token)
if (Token == "") {
Auth()
} else {
CheckTokenAuth(Token)
}
}
fun Auth() {
binding.CLLoad.visibility = View.GONE
supportFragmentManager.beginTransaction()
.replace(R.id.CLMain, AuthFragment.newInstance())
.commit()
}
fun Main() {
binding.CLLoad.visibility = View.GONE
fragment_inicializ()
// fixedRateTimer("timer", false, 0, 10000) {
// this@MainActivity.runOnUiThread {
// getNewAppeals()
// getOldAppeals()
// GetPatientListSearch()
// GetPatientListYes()
// GetPatientListNo()
// }
// }
}
@SuppressLint("MissingPermission")
private fun main() = with(binding) {
// btn11.setOnClickListener {
// myOneTimeWork()
// }
// btn22.setOnClickListener {
// myPriodicTimeWork()
// }
// createNotifChannel()
// notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// val intent = Intent(this@MainActivity, MainActivity::class.java)
// val pendingIntent = TaskStackBuilder.create(this@MainActivity).run {
// addNextIntentWithParentStack(intent)
// getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
// }
//
// val notif = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)
// .setContentTitle("Sample Title")
// .setContentText("This is sample body notif")
// .setSmallIcon(R.drawable.door)
// .setPriority(NotificationCompat.PRIORITY_HIGH)
// .setContentIntent(pendingIntent)
// .build()
//
//
// val notifManger = NotificationManagerCompat.from(this@MainActivity)
// button3.setOnClickListener {
//
// notifManger.notify(NOTIF_ID, notif)
// }
//
//
}
private fun CheckTokenAuth(token: String) {
if (enternetCheck.isOnline(this)) {
initRetrofit()
CoroutineScope(Dispatchers.IO).launch {
val response = doctorApi.CheckToken("Bearer $token")
runOnUiThread {
//Фиксируем полученные данные
val List = response.body()
val Nice = response.isSuccessful
val Code = response.code()
if(Code==429){
val intetn = Intent(this@MainActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (Code.toString() == "200") {
Main()
} else {
Auth()
}
}
}
else if (Code == 500) {
val intetn = Intent(this@MainActivity, Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@MainActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
private fun fragment_inicializ() {
//Вывод фрагмента на активити при первоначальной загрузке
supportFragmentManager.beginTransaction()
.replace(R.id.CLMain, MainFragment.newInstance())
.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
// override fun onBackPressed() {
// if (backPressedTime + 3000 > System.currentTimeMillis()) {
// super.onBackPressed()
// finish()
// } else {
// AlertDialog.Builder(this@MainActivity)
// .setTitle("Выйти")
// .setMessage("Вы точно хотите выйти из приложения?")
// .setPositiveButton("Да") { dialog, whichButton ->
// super.onBackPressed()
// }
// .setNegativeButton("Нет") { dialog, whichButton ->
//
// }
// .show()
// }
// backPressedTime = System.currentTimeMillis()
// }
// override fun onResume() {
// super.onResume()
// checkForUpdates(true)
// }
//
//
// override fun onStop() {
// super.onStop()
// timer.cancel()
// timer.purge()
// }
//
// private fun checkForUpdates(daemonIsTrue: Boolean) {
// Token = prefDoctorConclusion.conclusionToken(this@MainActivity)
// timer = fixedRateTimer("default", daemonIsTrue, 0, 5000) {
// this@MainActivity?.runOnUiThread {
//
// CheckTokenAuth(Token)
// }
// }
//
//}
}

View File

@ -0,0 +1,206 @@
package com.example.doctor
import android.annotation.SuppressLint
import android.icu.text.SimpleDateFormat
import android.icu.util.Calendar
import android.os.Bundle
import android.os.SystemClock
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
//import androidx.navigation.fragment.findNavController
import com.example.doctor.Appeals.AppealsFragment
import com.example.doctor.Home.HomeFragment
import com.example.doctor.Patients.PatientsListFragment
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.Setting.SettingFragment
import com.example.doctor.databinding.FragmentMainBinding
import java.util.Date
class MainFragment : Fragment() {
private lateinit var binding: FragmentMainBinding
private val dataModel: DataModel by activityViewModels()//Для передачи данных
val prefDoctorSave = SavePref()
val prefDoctorConclusion = ConclusionPref()
private var Token = ""
var sdf: SimpleDateFormat = SimpleDateFormat("EEEE")
var d: Date = Date()
var dayOfTheWeek: String = sdf.format(d)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentMainBinding.inflate(layoutInflater, container, false)
return binding.root
}
@SuppressLint("ResourceType")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//MainAndAuth()
dataModel.fragmentMenu.observe(viewLifecycleOwner, Observer {
binding.buttonNavigation.selectedItemId = it
})
addDate()
fragment_inicializ()
}
private fun addDate() {
val calendar: Calendar = Calendar.getInstance()
val sdf: SimpleDateFormat = SimpleDateFormat("EEEE")
val d: Date = Date()
val DayOfTheWeek: String = sdf.format(d)
val Day = calendar.get(Calendar.DATE)
val Month = calendar.get(Calendar.MONTH).plus(1)
var day = Day.toString()
var month = ""
var date_of_the_week = ""
when (Month) {
1 -> month = "Январь"
2 -> month = "Февраль"
3 -> month = "Март"
4 -> month = "Апрель"
5 -> month = "Май"
6 -> month = "Июнь"
7 -> month = "Июль"
8 -> month = "Август"
9 -> month = "Сентябрь"
10 -> month = "Октябрь"
11 -> month = "Ноябрь"
12 -> month = "Декабрь"
else -> { // обратите внимание на блок
month = ""
}
}
when (dayOfTheWeek) {
"Monday" -> date_of_the_week = "Пн"
"Tuesday" -> date_of_the_week = "Вт"
"Wednesday" -> date_of_the_week = "Ср"
"Thursday" -> date_of_the_week = "Чт"
"Friday" -> date_of_the_week = "Пт"
"Saturday" -> date_of_the_week = "Сб"
"Sunday" -> date_of_the_week = "Вс"
"Понедельник" -> date_of_the_week = "Пн"
"Вторник" -> date_of_the_week = "Вт"
"Стреда" -> date_of_the_week = "Ср"
"Четверг" -> date_of_the_week = "Чт"
"Пятница" -> date_of_the_week = "Пт"
"Суббота" -> date_of_the_week = "Сб"
"Воскресенье" -> date_of_the_week = "Вс"
else -> {
date_of_the_week = ""
}
}
System.out.println(calendar.get(Calendar.DATE))
binding.txtDate.setText("${day}" + " " + "${month}")
}
// fun MainAndAuth(){
//
// //Token = prefDoctorConclusion.conclusionToken()
// if(Token == ""){
// Auth()
// }
// else{
// Main()
// }
// }
// fun Auth(){
// val intetn = Intent(requireContext(), AuthActivity::class.java)
// startActivity(intetn)
// activity?.finish()
// }
// fun Main(){
// fragment_inicializ()
// }
//Инициализация фрагментов
fun fragment_inicializ() {
Token = prefDoctorConclusion.conclusionToken(requireContext())
//Вывод фрагмента на активити при первоначальной загрузке
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.CLMainFragment, HomeFragment.newInstance())
?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
//Эран который будет выбран по умолчанию(кнопка которая будет прожата по умолчанию)
binding.buttonNavigation.selectedItemId =
R.id.home//По умолчанию и так первая, но на всякий случай выберу еще програмным путем первую ячейку
//Нажатие на bottom navigation
binding.buttonNavigation.setOnItemSelectedListener {
when (it.itemId) {//it.itemId - это id нажатого элемента
R.id.home -> {
if (!isClickRecently()) {
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.CLMainFragment, HomeFragment.newInstance())
?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}
R.id.patient -> {
if (!isClickRecently()) {
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.CLMainFragment, PatientsListFragment.newInstance())
?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}
R.id.list_check -> {//Если вы не авторизованный пользваотель то вам не будет доступен доступ к данном фрагменту
if (!isClickRecently()) {
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.CLMainFragment, AppealsFragment.newInstance())
?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}
R.id.setting -> {//Если вы не авторизованный пользваотель то вам не будет доступен доступ к данном фрагменту
if (!isClickRecently()) {
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.CLMainFragment, SettingFragment.newInstance())
?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}
}
true
}
}
var mLastClickTime = 0L
fun isClickRecently(): Boolean {
if (SystemClock.elapsedRealtime() - mLastClickTime < 500) {
return true
}
mLastClickTime = SystemClock.elapsedRealtime()
return false
}
companion object {
fun newInstance() = MainFragment()
}
}

View File

@ -0,0 +1,92 @@
package com.example.doctor.Patients.Adapter
import android.annotation.SuppressLint
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Model.PatientModel
import com.example.doctor.R
import com.example.doctor.databinding.ItemCardPatientBinding
class PatientListAdapter(val listener_patient: Listener) :
ListAdapter<PatientAllModel, PatientListAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_patient: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding =
ItemCardPatientBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: PatientAllModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
itemView.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
itemTemp?.let { it1 -> listener_patient.onClickPatient(it1) }
}
}
@SuppressLint("SuspiciousIndentation", "SetTextI18n")
fun bind(item: PatientAllModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumberCurds.text = item.number.toString() + "."
txtLoginPatient.text = item.login
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_card_patient, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_patient)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<PatientAllModel>() {
override fun areItemsTheSame(
oldItem: PatientAllModel,
newItem: PatientAllModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: PatientAllModel,
newItem: PatientAllModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickPatient(item: PatientAllModel)
}
}

View File

@ -0,0 +1,7 @@
package com.example.doctor.Patients.Model
data class CreatePatientModel(
//val login:String,
val login:String,
val password:String,
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Model
data class MessageModel(
val message: String,
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Model
data class PatientAllListModel(
val patient: List<PatientAllModel>
)

View File

@ -0,0 +1,22 @@
package com.example.doctor.Patients.Model
import java.util.Date
data class PatientAllModel(
val number: Int? = null,
val id: Int? = null,
val login: String? = null,
val email: String? = null,
val loginDoctor: String? = null,
val emailDoctor: String? = null,
val pause: String? = null,
val block: String? = null,
val report7day: String? = null,
val report15day: String? = null,
val id_sport_patient: Int? = null,
val total_days_sports: Int? = null,
val now_days_sports: Int? = null,
val created_at: String? = null,
val updated_at: String? = null,
)

View File

@ -0,0 +1,9 @@
package com.example.doctor.Patients.Model
import java.util.Date
data class PatientIdModel(
val id: Int
)

View File

@ -0,0 +1,8 @@
package com.example.doctor.Patients.Model
data class PatientModel(
val id: Int,
val login: String,
//val email:String,
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Model
data class PauseModel(
val message: String,
)

View File

@ -0,0 +1,421 @@
package com.example.doctor.Patients
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.viewModels
import androidx.core.content.ContentProviderCompat.requireContext
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Reports.PatientFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.ActivityPatientBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class PatientActivity : AppCompatActivity() {
private lateinit var binding: ActivityPatientBinding
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
private val modelDoctor: DoctorViewModel by viewModels()//Инициализировали класс
var idPatient = 0
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPatientBinding.inflate(layoutInflater)
setContentView(binding.root)
supportFragmentManager.beginTransaction().replace(R.id.CLPatientActivity, PatientFragment.newInstance()).commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
idPatient = prefDoctorConclusion.conclusionIdPatient(this)
}
//Получения списка анкет ДО и ПОСЛЕ для пациента
fun QBAPatientList(id:Int){
if (enternetCheck.isOnline(this@PatientActivity)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this@PatientActivity)
CoroutineScope(Dispatchers.IO).launch {
val list = doctorApi.GetPatientBAQiestionar("Bearer $Tokens",id)
runOnUiThread {
//Фиксируем полученные данные
val List = list.body()
val Nice = list.isSuccessful
val Code = list.code()
if(Code==429){
val intetn = Intent(this@PatientActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
if(List?.questionnaire !=null){
modelDoctor.qbaList.value = List.questionnaire
}
}
}
//2
GetPatientID(idPatient)
}
else if (Code == 500) {
val intetn = Intent(this@PatientActivity, Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@PatientActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
finish()
val intetn = Intent(this, EnternetActivity::class.java)
startActivity(intetn)
}
}
private fun GetPatientID(idPatient: Int) {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listPatient = doctorApi.GetPatientID("Bearer $Tokens", idPatient)
runOnUiThread {
//Фиксируем полученные данные
val List = listPatient.body()
val Nice = listPatient.isSuccessful
val Code = listPatient.code()
if(Code==429){
val intetn = Intent(this@PatientActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.patientCurrent.value = List
}
}
//3
GetCoursesAllSport(idPatient)
}
else if (Code == 500) {
val intetn = Intent(this@PatientActivity,Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@PatientActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Вывод всех курсов
fun GetCoursesAllSport(idPatient: Int){
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetCoursAllPatient("Bearer $Tokens",idPatient)
runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(this@PatientActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.SportCoursList.value = List.courses
}
}
//4
GetCoursesYouSport(idPatient)
}
else if (Code == 500) {
val intetn = Intent(this@PatientActivity, Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@PatientActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this@PatientActivity, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Получения списка курсов созданных доктором
fun GetCoursesYouSport(idPatient:Int) {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetCoursesDoctorPatient("Bearer $Tokens",idPatient)
runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctor.body()
val Nice = listCoursesDoctor.isSuccessful
val Code = listCoursesDoctor.code()
if(Code==429){
val intetn = Intent(this@PatientActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.SportCoursDoctorList.value = List.courses_doctor
}
}
//5
GetCoursesSportYes(idPatient)
}
else if (Code == 500) {
val intetn = Intent(this@PatientActivity, Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@PatientActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Получения списка пациентов
fun GetCoursesSportYes(id_patient:Int) {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.GetCoursesSportYes("Bearer $Tokens", id_patient)
runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
val intetn = Intent(this@PatientActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.EditSportListYes.value = List.set_of_sports_exercises_yes
}
}
//6
GetCoursesSportNo(idPatient)
}
else if (Code == 500) {
val intetn = Intent(this@PatientActivity, Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@PatientActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Получения списка пациентов
fun GetCoursesSportNo(id_patient:Int) {
if (enternetCheck.isOnline(this)) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(this)
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.GetCoursesSportNo("Bearer $Tokens",id_patient)
runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
val intetn = Intent(this@PatientActivity, Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.EditSportListNo.value = List.set_of_sports_exercises_no
}
}
}
else if (Code == 500) {
val intetn = Intent(this@PatientActivity, Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(this@PatientActivity, AuthActivity::class.java)
finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(this, EnternetActivity::class.java)
finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
override fun onResume() {
super.onResume()
checkForUpdates(true)
}
override fun onStop() {
super.onStop()
timer.cancel()
timer.purge()
}
private fun checkForUpdates(daemonIsTrue: Boolean) {
timer = fixedRateTimer("default", daemonIsTrue, 0, 10000) {
this@PatientActivity?.runOnUiThread {
QBAPatientList(idPatient)
}
}
}
}

View File

@ -0,0 +1,290 @@
package com.example.doctor.Patients
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.fragment.app.activityViewModels
import com.example.doctor.DoctorViewModel
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Reports.PatientFragment
import com.example.doctor.Pref.ConclusionPref
import android.R
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Handler
import android.util.Log
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
//import androidx.navigation.fragment.findNavController
import com.example.doctor.Adapter.VpAdapterPatientList
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.MainActivity
import com.example.doctor.Patients.TabLayoutPatient.ActiveCoursesPatientFragment
import com.example.doctor.Patients.TabLayoutPatient.NotActiveCoursesPatientFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.FragmentPatientsListBinding
import com.example.user.BottomSheetMenu.NoteBottomSheetMenu
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.Timer
import kotlin.concurrent.fixedRateTimer
class PatientsListFragment : Fragment(){
private lateinit var binding: FragmentPatientsListBinding
private val modelDoctor: DoctorViewModel by activityViewModels()
private val dataModel: DataModel by activityViewModels()//Для передачи данных
private lateinit var doctorApi: DoctorApi
private lateinit var timer: Timer
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
var viewListPAtient = true
var patientListSearch:List<PatientAllModel>?=null
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
private val tList = listOf(
"Активные",
"Без курса",
)
//Список с фрагментами для переключения
private val flist = listOf(
ActiveCoursesPatientFragment.newInstance(),
NotActiveCoursesPatientFragment.newInstance(),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentPatientsListBinding.inflate(layoutInflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
//Чтобы срабатывала команда 1 раз
if(viewListPAtient){
GetPatientList()
init()
//Нажатие на кнопку для добавления пациента
binding.btnAddPatient.setOnClickListener {
val noteBottomSheetMenu = NoteBottomSheetMenu.newInstance()
noteBottomSheetMenu.show(
requireActivity().supportFragmentManager,
"Note Bottom Sheet Fragment"
)
}
}
modelDoctor.patientListSearch.observe(viewLifecycleOwner){
if(patientListSearch!=it){
patientListSearch = it
addListSerchPatient(it)
}
}
}
//Функция подключения переключения
private fun init() = with(binding) {
val adapter = VpAdapterPatientList(activity as FragmentActivity, flist as List<Fragment>)
vpPatient.adapter = adapter
//Переключения (связываем таблаяут(переключатель) с viewpager, чтобы переключать фрагменты)
TabLayoutMediator(tabLayoutPatient, vpPatient) { tab, pos ->
tab.text =
tList[pos]//tab - нажатая кнопка, pos - позиция кнопки, tList[pos] - передаем название по полученной позиции
}.attach()// attach() - чтобы все переключалось, а не вывадило постоянно один экран
//Изменения цвета в зависомости на каком из tabLayout вы находитесь
binding.tabLayoutPatient.setTabTextColors(getResources().getColor(com.example.doctor.R.color.black),
getResources().getColor(com.example.doctor.R.color.white));
}
// private fun viewPatient() {
// val viewPatient = prefDoctorConclusion.conclusionViewPatient(requireContext())
// val idPatient = prefDoctorConclusion.conclusionIdPatient(requireContext())
// Log.i("viewPatient1",viewPatient.toString())
// Log.i("idPatient1",viewPatient.toString())
// if(viewPatient ==1 && idPatient !=0){
// GetPatientID(idPatient)
// prefDoctorClear.clearIdPatient(requireContext())
// prefDoctorClear.clearViewPatient(requireContext())
// Log.i("viewPatient2",viewPatient.toString())
// Log.i("idPatient2",viewPatient.toString())
// }
// }
//Получения списка пациентов
fun GetPatientList() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listPatientList = doctorApi.GetPatientAll("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listPatientList.body()
val Nice = listPatientList.isSuccessful
val Code = listPatientList.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.patientListSearch.value = List?.patient
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
private fun addListSerchPatient(patient: List<PatientAllModel>) {
val listPatient = arrayListOf("")
for(i in 0 .. patient.count()-1){
listPatient.add(patient[i].login.toString())
}
val adapter = ArrayAdapter(requireContext(), R.layout.simple_list_item_1, listPatient)
binding.searchPatient.threshold = 1
binding.searchPatient.setAdapter(adapter)
binding.searchPatient.setOnItemClickListener { parent, arg1, pos, id ->
//val list = ArrayList<PatientModel>()
val serpat = binding.searchPatient.text.toString()
//Вывод фрагмента на активити при первоначальной загрузке
// ///////// activity?.supportFragmentManager?.beginTransaction()
// ///////// ?.replace(com.example.doctor.R.id.CLMainPatient, PatientFragment.newInstance())
// ///////////// ?.addToBackStack(null)
// /////////// ?.commit()
//binding.CLMainListPatient2.visibility = View.GONE
//Ищем пациента по логину
for(i in 0 ..patient.count()-1) {
if(patient[i].login == serpat){
modelDoctor.patientCurrent.value = patient[i]
prefDoctorSave.saveIdPatient(requireContext(),patient[i].id!!)
prefDoctorSave.saveViewPatient(requireContext(),1)
val intetn = Intent(requireContext(), PatientActivity::class.java)
startActivity(intetn)
}
}
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
companion object {
fun newInstance() = PatientsListFragment()
}
override fun onResume() {
super.onResume()
checkForUpdates(true)
}
override fun onStop() {
super.onStop()
timer.cancel()
timer.purge()
}
private fun checkForUpdates(daemonIsTrue: Boolean) {
timer = fixedRateTimer("default", daemonIsTrue, 0, 10000) {
activity?.runOnUiThread {
GetPatientList()
}
}
}
}

View File

@ -0,0 +1,90 @@
package com.example.doctor.Patients.Reports.Courses
import android.annotation.SuppressLint
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemCardCoursesDoctorBinding
import com.example.doctor.databinding.ItemSportCourseBinding
class CoursesAllAdapter(val listener_courses: Listener) : ListAdapter<SportCoursModel, CoursesAllAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_courses: Listener): RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemCardCoursesDoctorBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: SportCoursModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
itemView.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
//timerButtonDoubleButton(itemView)
itemTemp?.let { it1 -> listener_courses.onClickSportCourses(it1) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: SportCoursModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumberCurds.text = item.number.toString() + "."
txtNameCoursesDoctor.text = item.name
if (item.visibility == 100000) {
CVCours.setCardBackgroundColor(Color.parseColor("#83da83"))
Log.i("11111111111","sasdasdasdasdasadsdasda")
} else {
CVCours.setCardBackgroundColor(Color.parseColor("#b6b6b6"))
Log.i("2222222222222","sasdasdasdasdasadsdasda")
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_card_courses_doctor, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_courses)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<SportCoursModel>() {
override fun areItemsTheSame(oldItem: SportCoursModel, newItem: SportCoursModel): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(oldItem: SportCoursModel, newItem: SportCoursModel): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickSportCourses(item: SportCoursModel)
}
}

View File

@ -0,0 +1,99 @@
package com.example.doctor.Patients.Reports.Courses
import android.annotation.SuppressLint
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.Setting.Courses.Model.CoursesDoctorModel
import com.example.doctor.databinding.ItemCardCoursesDoctorBinding
class CoursesYouAdapter(val listener: Listener) :
ListAdapter<SportCoursModel, CoursesYouAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemCardCoursesDoctorBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: SportCoursModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
itemView.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
itemTemp?.let { it1 -> listener.onClickCourses(it1) }
}
}
@SuppressLint("SuspiciousIndentation", "SetTextI18n")
fun bind(item: SportCoursModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumberCurds.text = item.number.toString() + "."
txtNameCoursesDoctor.text = item.name
if (item.visibility == 100000) {
CVCours.setCardBackgroundColor(Color.parseColor("#83da83"))
Log.i("11111111111","sasdasdasdasdasadsdasda")
} else {
CVCours.setCardBackgroundColor(Color.parseColor("#b6b6b6"))
Log.i("2222222222222","sasdasdasdasdasadsdasda")
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_card_courses_doctor, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<SportCoursModel>() {
override fun areItemsTheSame(
oldItem: SportCoursModel,
newItem: SportCoursModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: SportCoursModel,
newItem: SportCoursModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickCourses(item: SportCoursModel)
}
}

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Reports.Courses
data class SportCoursDoctorListModel(
val courses_doctor: List<SportCoursModel>
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Reports.Courses
data class SportCoursListModel(
val courses: List<SportCoursModel>
)

View File

@ -0,0 +1,11 @@
package com.example.doctor.Patients.Reports.Courses
data class SportCoursModel(
val number: Int,
val id: Int,
val name: String,
val description: String,
val visibility: Int,
val created_at: String,
val updated_at: String,
)

View File

@ -0,0 +1,204 @@
package com.example.doctor.Patients.Reports.Courses.TabLayout
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Reports.Courses.CoursesAllAdapter
import com.example.doctor.Patients.Reports.Courses.SportCoursModel
import com.example.doctor.Patients.Reports.CoursesListAdapter
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentCoursesAllBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class CoursesAllFragment : Fragment(),CoursesAllAdapter.Listener {
private lateinit var binding: FragmentCoursesAllBinding
private val modelDoctor: DoctorViewModel by activityViewModels()
lateinit var adapterCours: CoursesAllAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
var sportCourses:List<SportCoursModel>?=null
var id: Int? = null
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentCoursesAllBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewCours()
modelDoctor.id_patient.observe(viewLifecycleOwner){
id = it
GetAllCoursesSport()
}
modelDoctor.SportCoursList.observe(viewLifecycleOwner) {//viewLifecycleOwner - следит за циклом жизни fragment
if(sportCourses != it){
sportCourses = it
adapterCours.submitList(it)//Напрямую переадем созданный список в adapter(ProductAdapter)
binding.txtNull.visibility = View.GONE
}
}
}
//Вывод всех курсов
fun GetAllCoursesSport(){
if (enternetCheck.isOnline(requireContext())) {
binding.txtNull.visibility = View.VISIBLE
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetCoursAllPatient("Bearer $Tokens",id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.SportCoursList.value = List.courses
binding.txtNull.visibility = View.GONE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Инициализация списка
private fun initRcViewCours() = with(binding) {
rcView.layoutManager = GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterCours = CoursesAllAdapter(this@CoursesAllFragment)
rcView.adapter = adapterCours
}
companion object {
fun newInstance() = CoursesAllFragment()
}
override fun onClickSportCourses(item: SportCoursModel) {
AddSportPatient(id!!,item.id,14)
GetAllCoursesSport()
}
fun AddSportPatient(id_patient:Int,id_course:Int,all_day:Int){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val updatePassword= doctorApi.AddSportPatient("Bearer $Tokens",id_patient,id_course,all_day)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = updatePassword.body()
val Nice = updatePassword.isSuccessful
val Code = updatePassword.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
GetAllCoursesSport()
modelDoctor.BtnSportCoursDoctorCurrent.value = 2
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}

View File

@ -0,0 +1,208 @@
package com.example.doctor.Patients.Reports.Courses.TabLayout
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Reports.Courses.CoursesYouAdapter
import com.example.doctor.Patients.Reports.Courses.SportCoursModel
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Setting.Courses.Model.CoursesDoctorModel
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentCoursesYouBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class CoursesYouFragment : Fragment(),CoursesYouAdapter.Listener {
private lateinit var binding:FragmentCoursesYouBinding
private val modelDoctor: DoctorViewModel by activityViewModels()
lateinit var adapterCours: CoursesYouAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
var sportCoursesDoctor:List<SportCoursModel>?=null
var id: Int? = null
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentCoursesYouBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewCours()
modelDoctor.id_patient.observe(viewLifecycleOwner){
id = it
GetCoursesDoctor()
}
modelDoctor.SportCoursDoctorList.observe(viewLifecycleOwner){
if(sportCoursesDoctor!=it){
sportCoursesDoctor = it
adapterCours.submitList(it)
binding.txtNull.visibility = View.GONE
}
}
}
//Получения списка курсов созданных доктором
fun GetCoursesDoctor() {
if (enternetCheck.isOnline(requireContext())) {
binding.txtNull.visibility = View.VISIBLE
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetCoursesDoctorPatient("Bearer $Tokens",id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctor.body()
val Nice = listCoursesDoctor.isSuccessful
val Code = listCoursesDoctor.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.SportCoursDoctorList.value = List.courses_doctor
binding.txtNull.visibility = View.GONE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Инициализация списка
private fun initRcViewCours() = with(binding) {
rcView.layoutManager = GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterCours = CoursesYouAdapter(this@CoursesYouFragment)
rcView.adapter = adapterCours
}
companion object {
fun newInstance() = CoursesYouFragment()
}
override fun onClickCourses(item: SportCoursModel) {
AddSportPatient(id!!,item.id,14)
GetCoursesDoctor()
}
fun AddSportPatient(id_patient:Int,id_course:Int,all_day:Int){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val updatePassword= doctorApi.AddSportPatient("Bearer $Tokens",id_patient,id_course,all_day)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = updatePassword.body()
val Nice = updatePassword.isSuccessful
val Code = updatePassword.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
GetCoursesDoctor()
modelDoctor.BtnSportCoursDoctorCurrent.value = 2
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}

View File

@ -0,0 +1,90 @@
package com.example.doctor.Patients.Reports
import android.annotation.SuppressLint
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.Patients.Reports.Courses.SportCoursModel
import com.example.doctor.R
import com.example.doctor.databinding.ItemSportCourseBinding
class CoursesListAdapter(val listener_courses: Listener) : ListAdapter<SportCoursModel, CoursesListAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_courses: Listener): RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemSportCourseBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: SportCoursModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
binding.CardViewCourses.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
//timerButtonDoubleButton(itemView)
itemTemp?.let { it1 -> listener_courses.onClickSportCourses(it1) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: SportCoursModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtCoursesSport.text = item.name
if (item.visibility == 1) {
CVCours.setCardBackgroundColor(Color.parseColor("#83da83"))
Log.i("11111111111","sasdasdasdasdasadsdasda")
} else {
CVCours.setCardBackgroundColor(Color.parseColor("#b6b6b6"))
Log.i("2222222222222","sasdasdasdasdasadsdasda")
}
Log.i("ssadsdasda","sasdasdasdasdasadsdasda")
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_sport_course, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_courses)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<SportCoursModel>() {
override fun areItemsTheSame(oldItem: SportCoursModel, newItem: SportCoursModel): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(oldItem: SportCoursModel, newItem: SportCoursModel): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickSportCourses(item: SportCoursModel)
}
}

View File

@ -0,0 +1,76 @@
package com.example.doctor.Patients.Reports.Edit
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.example.doctor.Adapter.VpEditSportAdapter
import com.example.doctor.Patients.Reports.Edit.TabLayout.EditSportNoFragment
import com.example.doctor.Patients.Reports.Edit.TabLayout.EditSportYesFragment
import com.example.doctor.R
import com.example.doctor.databinding.FragmentEditSportBinding
import com.google.android.material.tabs.TabLayoutMediator
class EditSportFragment : Fragment() {
private lateinit var binding: FragmentEditSportBinding
private val tListSport = listOf(
"Активные",
"Отключенные",
)
//Список с фрагментами для переключения
private val flistSport = listOf(
EditSportYesFragment.newInstance(),
EditSportNoFragment.newInstance(),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentEditSportBinding.inflate(layoutInflater,container,false)
return binding.root
}
companion object {
fun newInstance() = EditSportFragment()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
init()
}
//Функция подключения переключения
private fun init() = with(binding) {
val adapter = VpEditSportAdapter(activity as FragmentActivity, flistSport)
vpEditSport.adapter = adapter
//Переключения (связываем таблаяут(переключатель) с viewpager, чтобы переключать фрагменты)
TabLayoutMediator(tabLayoutSport, vpEditSport) { tab, pos ->
tab.text =
tListSport[pos]//tab - нажатая кнопка, pos - позиция кнопки, tList[pos] - передаем название по полученной позиции
}.attach()// attach() - чтобы все переключалось, а не вывадило постоянно один экран
//Изменения цвета в зависомости на каком из tabLayout вы находитесь
binding.tabLayoutSport.setTabTextColors(getResources().getColor(R.color.black),
getResources().getColor(R.color.white));
}
// //Инициализация списка
// private fun initRcViewDay() = with(binding) {
// rcView.layoutManager =
// GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
// adapterPatient = PatientListAdapter(this@PatientsListFragment)
// rcView.adapter = adapterPatient
// }
}

View File

@ -0,0 +1,8 @@
package com.example.doctor.Patients.Reports.Edit
data class EditSportListNoModel(
val set_of_sports_exercises_no: List<EditSportModel>
)

View File

@ -0,0 +1,10 @@
package com.example.doctor.Patients.Reports.Edit
import com.example.doctor.Patients.Reports.QBAModel
data class EditSportListYesModel(
val set_of_sports_exercises_yes: List<EditSportModel>
)

View File

@ -0,0 +1,11 @@
package com.example.doctor.Patients.Reports.Edit
data class EditSportModel(
val number: Int,
val id: Int,
val name:String,
val description:String,
val url_image:String,
var expand : Boolean = false,
)

View File

@ -0,0 +1,107 @@
package com.example.doctor.Patients.Reports.Edit
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemEditSportNoBinding
import com.example.doctor.databinding.ItemEditSportYesBinding
class EditSportNoAdapter(val listener_sport: Listener) :
ListAdapter<EditSportModel, EditSportNoAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_sport: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemEditSportNoBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: EditSportModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
binding.btnYeyNo.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
itemTemp?.let { it1 -> listener_sport.onClickAppeals(it1) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: EditSportModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumber.text = item.number.toString()+"."
txtNameSport.text = item.name
txtDescriptionSport.text = item.description
if (item.expand) {
binding.txtDescriptionSport.maxLines = 100
} else {
binding.txtDescriptionSport.maxLines = 1
}
binding.CardViewOld.setOnClickListener {
if (item.expand == false) {
binding.txtDescriptionSport.maxLines = 100
item.expand = true
} else {
binding.txtDescriptionSport.maxLines = 1
item.expand = false
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_edit_sport_no, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_sport)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<EditSportModel>() {
override fun areItemsTheSame(
oldItem: EditSportModel,
newItem: EditSportModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: EditSportModel,
newItem: EditSportModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickAppeals(item: EditSportModel)
}
}

View File

@ -0,0 +1,8 @@
package com.example.doctor.Patients.Reports.Edit
data class EditSportSearchModel(
val id_patient: Int,
val id_sports_courses_patient: Int,
)

View File

@ -0,0 +1,106 @@
package com.example.doctor.Patients.Reports.Edit
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemEditSportYesBinding
class EditSportYesAdapter(val listener_sport: Listener) :
ListAdapter<EditSportModel, EditSportYesAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_sport: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemEditSportYesBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: EditSportModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
binding.btnYeyYes.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
itemTemp?.let { it1 -> listener_sport.onClickAppeals(it1) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: EditSportModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumber.text = item.number.toString()+"."
txtNameSport.text = item.name
txtDescriptionSport.text = item.description
if (item.expand) {
binding.txtDescriptionSport.maxLines = 100
} else {
binding.txtDescriptionSport.maxLines = 1
}
binding.CardViewOld.setOnClickListener {
if (item.expand == false) {
binding.txtDescriptionSport.maxLines = 100
item.expand = true
} else {
binding.txtDescriptionSport.maxLines = 1
item.expand = false
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_edit_sport_yes, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_sport)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<EditSportModel>() {
override fun areItemsTheSame(
oldItem: EditSportModel,
newItem: EditSportModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: EditSportModel,
newItem: EditSportModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickAppeals(item: EditSportModel)
}
}

View File

@ -0,0 +1,317 @@
package com.example.doctor.Patients.Reports.Edit.TabLayout
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Reports.Edit.EditSportYesAdapter
import com.example.doctor.Patients.Reports.Edit.EditSportModel
import com.example.doctor.Patients.Reports.Edit.EditSportNoAdapter
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentEditSportNoBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class EditSportNoFragment : Fragment(),EditSportNoAdapter.Listener {
private lateinit var binding:FragmentEditSportNoBinding
lateinit var adapterNo: EditSportNoAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
private val model: DoctorViewModel by activityViewModels()
var id_patient = 0;
var editNo:List<EditSportModel>?=null
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentEditSportNoBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewDay()
model.EditSportListNo.observe(viewLifecycleOwner){
if(it!=null){
if(editNo!=it){
editNo = it
adapterNo.submitList(it)
binding.txtNo.visibility = View.GONE
}
}
else{
binding.txtNo.visibility = View.VISIBLE
}
}
model.id_patient.observe(viewLifecycleOwner) {id->
id_patient = id.toInt()
GetCoursesSportNo(id_patient)
}
btnClick()
}
private fun btnClick()=with(binding) {
CLLoad.setOnClickListener { }
}
//Инициализация списка
private fun initRcViewDay() = with(binding) {
rcViewEditSportNo.layoutManager =
GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterNo = EditSportNoAdapter(this@EditSportNoFragment)
rcViewEditSportNo.adapter = adapterNo
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Получения списка пациентов
fun GetCoursesSportYes(id_patient:Int)= with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.GetCoursesSportYes("Bearer $Tokens", id_patient)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200){
//Если нету ошибок
if(Nice){
if (List != null) {
model.EditSportListYes.value = List.set_of_sports_exercises_yes
}
}
else{
CLLoad.visibility = View.GONE
}
}
else if(Code==500){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
else{
CLLoad.visibility = View.GONE
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получения списка пациентов
fun GetCoursesSportNo(id_patient:Int)= with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.GetCoursesSportNo("Bearer $Tokens", id_patient)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200){
//Если нету ошибок
if(Nice){
if (List != null) {
model.EditSportListNo.value = List.set_of_sports_exercises_no
binding.txtNo.visibility = View.GONE
binding.CLLoad.visibility = View.GONE
}
else{
binding.txtNo.visibility = View.VISIBLE
binding.CLLoad.visibility = View.GONE
}
}
else{
CLLoad.visibility = View.GONE
}
}
else if(Code==500){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
else{
CLLoad.visibility = View.GONE
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Удаление упражнения из блока
fun UpdateBlockSportTasksNo(id:Int)= with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val NoEdit = doctorApi.UpdateBlockSportTasksNo("Bearer $Tokens", id)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = NoEdit.body()
val Nice = NoEdit.isSuccessful
val Code = NoEdit.code()
if(Code==429){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200){
//Если нету ошибок
if(Nice){
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
GetCoursesSportYes(id_patient)
GetCoursesSportNo(id_patient)
}
else{
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
CLLoad.visibility = View.GONE
}
CLLoad.visibility = View.GONE
}
}
else{
CLLoad.visibility = View.GONE
}
}
else if(Code==500){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
else{
CLLoad.visibility = View.GONE
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
companion object {
fun newInstance() = EditSportNoFragment()
}
override fun onClickAppeals(item: EditSportModel) {
binding.CLLoad.visibility = View.VISIBLE
UpdateBlockSportTasksNo(item.id)
}
}

View File

@ -0,0 +1,325 @@
package com.example.doctor.Patients.Reports.Edit.TabLayout
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Reports.Edit.EditSportYesAdapter
import com.example.doctor.Patients.Reports.Edit.EditSportModel
import com.example.doctor.Patients.Reports.Edit.EditSportNoAdapter
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentEditSportYesBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class EditSportYesFragment : Fragment(), EditSportYesAdapter.Listener {
private lateinit var binding:FragmentEditSportYesBinding
lateinit var adapterYes: EditSportYesAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
private val model: DoctorViewModel by activityViewModels()
var id_patient = 0;
var editYes:List<EditSportModel>?=null
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentEditSportYesBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewDay()
model.id_patient.observe(viewLifecycleOwner) {id->
id_patient = id.toInt()
Log.i("id_patient",id_patient.toString())
Log.i("id",id.toString())
GetCoursesSportYes(id_patient)
}
model.EditSportListYes.observe(viewLifecycleOwner){
if(it!=null){
if(editYes!=it){
editYes=it
adapterYes.submitList(it)
binding.txtYes.visibility = View.GONE
}
}
else{
binding.txtYes.visibility = View.GONE
}
}
btnClick()
}
private fun btnClick()=with(binding) {
CLLoad.setOnClickListener { }
}
//Инициализация списка
private fun initRcViewDay() = with(binding) {
rcViewEditSportYes.layoutManager =
GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterYes = EditSportYesAdapter(this@EditSportYesFragment)
rcViewEditSportYes.adapter = adapterYes
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Получения списка пациентов
fun GetCoursesSportYes(id_patient:Int)=with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.GetCoursesSportYes("Bearer $Tokens", id_patient)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200){
//Если нету ошибок
if(Nice){
if (List != null) {
model.EditSportListYes.value = List.set_of_sports_exercises_yes
binding.txtYes.visibility = View.GONE
binding.CLLoad.visibility = View.GONE
}
else{
model.EditSportListYes.value = null
binding.txtYes.visibility = View.VISIBLE
binding.rcViewEditSportYes.visibility = View.GONE
binding.CLLoad.visibility = View.GONE
}
}
else{
CLLoad.visibility = View.GONE
}
}
else if(Code==500){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
else{
CLLoad.visibility = View.GONE
}
//Фиксируем полученные данные
val sportEditList = sportEdit.body()
//Если нету ошибок
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получения списка пациентов
fun GetCoursesSportNo(id_patient:Int)=with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.GetCoursesSportNo("Bearer $Tokens",id_patient)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200){
//Если нету ошибок
if(Nice){
if (List != null) {
model.EditSportListNo.value = List.set_of_sports_exercises_no
}
CLLoad.visibility = View.GONE
}
else{
CLLoad.visibility = View.GONE
}
}
else if(Code==500){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
else{
CLLoad.visibility = View.GONE
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Отключение упражнения
fun UpdateBlockSportTasksYes(id_pateint:Int,id_sports_tasks:Int)=with(binding) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val sportEdit = doctorApi.UpdateBlockSportTasksYes("Bearer $Tokens", id_pateint,id_sports_tasks)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = sportEdit.body()
val Nice = sportEdit.isSuccessful
val Code = sportEdit.code()
if(Code==429){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200){
//Если нету ошибок
if(Nice){
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
GetCoursesSportYes(id_patient)
GetCoursesSportNo(id_patient)
}
else{
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
CLLoad.visibility = View.GONE
}
CLLoad.visibility = View.GONE
}
}
else{
CLLoad.visibility = View.GONE
}
}
else if(Code==500){
CLLoad.visibility = View.GONE
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
else{
CLLoad.visibility = View.GONE
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
companion object {
fun newInstance() = EditSportYesFragment()
}
override fun onClickAppeals(item: EditSportModel) {
binding.CLLoad.visibility = View.VISIBLE
UpdateBlockSportTasksYes(id_patient, item.id)
}
}

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Reports.Edit
data class UpdateSportTaskNoModel(
val id: Int,
)

View File

@ -0,0 +1,7 @@
package com.example.doctor.Patients.Reports.Edit
data class UpdateSportTaskYesModel(
val id_sport_patient: Int,
val id_sports_tasks: Int,
)

View File

@ -0,0 +1,945 @@
package com.example.doctor.Patients.Reports
import android.graphics.Color
import android.os.Bundle
import android.transition.TransitionInflater
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.widget.PopupMenu
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.DoctorViewModel
import com.example.doctor.Patients.PatientsListFragment
import com.example.doctor.Patients.Reports.Edit.EditSportFragment
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.R as R_D
import android.R
import android.content.Intent
import androidx.fragment.app.FragmentActivity
import com.example.doctor.Adapter.VpAdapter
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Reports.Courses.TabLayout.CoursesAllFragment
import com.example.doctor.Patients.Reports.Courses.TabLayout.CoursesYouFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.AllSportCoursesDoctorFragment
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.YourSportCoursesDoctorFragment
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.Toast.showCustomNiceToast
import com.example.doctor.databinding.FragmentPatientsBinding
import com.example.doctor.databinding.ItemQuestionnaireAfterBinding
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.time.LocalDate
class PatientFragment : Fragment() {
private lateinit var binding: FragmentPatientsBinding
private val modelDoctor: DoctorViewModel by activityViewModels()
lateinit var adapter: QBBAdapter
lateinit var adapterCours: CoursesListAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
var id: Int? = null
var block = ""
var pause = ""
var id_sport = ""
var btnSC = 0;
var idPatient = 0;
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
//Для 10 сек обновления
var qba:List<QBAModel>?=null
var patientAll:PatientAllModel?=null
private val tList = listOf(
"Все",
"Ваши",
)
//Список с фрагментами для переключения
private val flist = listOf(
CoursesAllFragment.newInstance(),
CoursesYouFragment.newInstance(),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentPatientsBinding.inflate(layoutInflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewDay()
init()
modelDoctor.qbaList.observe(viewLifecycleOwner) {//viewLifecycleOwner - следит за циклом жизни fragment
if(qba != it){
qba = it
adapter.submitList(it)//Напрямую переадем созданный список в adapter(ProductAdapter)
// binding.txtNullQBA.visibility = View.GONE
}
}
idPatient = prefDoctorConclusion.conclusionIdPatient(requireContext())
modelDoctor.BtnSportCoursDoctorCurrent.observe(viewLifecycleOwner){
if(it == 1){
binding.btnClearSportPatient.setCardBackgroundColor(Color.parseColor("#D86767"))
}
else if(it == 2){
binding.btnClearSportPatient.setCardBackgroundColor(Color.parseColor("#A9D867"))
}
else{
binding.btnClearSportPatient.setCardBackgroundColor(Color.parseColor("#D86767"))
}
}
val inflater = TransitionInflater.from(requireContext())
enterTransition = inflater.inflateTransition(R_D.transition.slide_right)
binding.btnExit.setOnClickListener {
exitTransition = inflater.inflateTransition(R_D.transition.slide_right)
activity?.finish()
}
popMenu()
//Вывод экрана
viewPatient()
//Получаем id
modelDoctor.patientId.observe(viewLifecycleOwner){
Log.i("adsa","as111111111111dsadasd")
}
//Вывод данных
modelDoctor.patientCurrent.observe(viewLifecycleOwner) {
if(patientAll !=it){
patientAll = it
binding.txtLogin.text = it.login
id = it.id
modelDoctor.id_patient.value = id
block = it.block.toString()
pause = it.pause.toString()
id_sport = it.id_sport_patient.toString()
//Проверка даты, так как если дата уже прошла, то должно выводится что блока нету
if(block == "null"){
block(block)
}
else{
if(LocalDate.parse(block)<LocalDate.now()){
block("null")
}
else{
block(block)
}
}
//Проверка даты, так как если дата уже прошла, то должно выводится что паузы нету
if(pause == "null"){
pause(pause)
}
else{
if(LocalDate.parse(pause)<LocalDate.now()){
pause("null")
}
else{
pause(pause)
}
}
Log.i("id_sport","$id_sport")
Log.i("id_sport123","$it")
//Проверка есть ли курс
btnClearSportPatient(id_sport)
report()
}
}
btnCreate()
}
private fun btnCreate() = with(binding) {
CVEditCard.setOnClickListener { }
CVSportCourses.setOnClickListener { }
CVReportCard.setOnClickListener { }
CVEditSportCard.setOnClickListener { }
}
//Функция подключения переключения
private fun init() = with(binding) {
val adapter = VpAdapter(activity as FragmentActivity, flist)
vpCourses.adapter = adapter
//Переключения (связываем таблаяут(переключатель) с viewpager, чтобы переключать фрагменты)
TabLayoutMediator(tabLayoutCourses, vpCourses) { tab, pos ->
tab.text =
tList[pos]//tab - нажатая кнопка, pos - позиция кнопки, tList[pos] - передаем название по полученной позиции
}.attach()// attach() - чтобы все переключалось, а не вывадило постоянно один экран
//Изменения цвета в зависомости на каком из tabLayout вы находитесь
binding.tabLayoutCourses.setTabTextColors(
getResources().getColor(com.example.doctor.R.color.black),
getResources().getColor(com.example.doctor.R.color.white)
);
}
private fun viewPatient() {
val viewPatient = prefDoctorConclusion.conclusionViewPatient(requireContext())
val idPatient = 23412
Log.i("viewPatient1",viewPatient.toString())
Log.i("idPatient1",viewPatient.toString())
if(viewPatient ==1 && idPatient !=0 && idPatient !=null){
GetPatientID(idPatient)
prefDoctorClear.clearIdPatient(requireContext())
prefDoctorClear.clearViewPatient(requireContext())
Log.i("viewPatient2",viewPatient.toString())
Log.i("idPatient2",viewPatient.toString())
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
private fun GetPatientID(idPatient: Int) {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listPatient = doctorApi.GetPatientID("Bearer $Tokens", idPatient)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listPatient.body()
val Nice = listPatient.isSuccessful
val Code = listPatient.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.patientCurrent.value = List
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
private fun popMenu() {
//Созданиеменю
val popMenu = PopupMenu(
requireContext(),
binding.btnQBA
)
//Кнопуи
popMenu.menu.add(Menu.NONE, 0, 0, "Анкета ДО")
popMenu.menu.add(Menu.NONE, 1, 1, "Анкета ПОСЛЕ")
popMenu.setOnMenuItemClickListener {
val id = it.itemId
//Ситуции при нажатие на один из пунктов
if (id == 0) {
binding.CVQB.visibility = View.VISIBLE
} else if (id == 1) {
binding.CVQA.visibility = View.VISIBLE
} else {
Toast.makeText(requireContext(), "Ошибка", Toast.LENGTH_SHORT).show()
}
false
}
binding.btnQBA.setOnClickListener {
//Активируем меню
popMenu.show()
}
}
//Получения списка анкет ДО и ПОСЛЕ для пациента
fun ClearSportPaient(){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listcsp = doctorApi.ClearPatientSport("Bearer $Tokens",id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listcsp.body()
val Nice = listcsp.isSuccessful
val Code = listcsp.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
GetAllCoursesSport()
GetCoursesDoctor()
modelDoctor.BtnSportCoursDoctorCurrent.value = 1
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
}
else{
Toast(requireContext()).showCustomInfoToast("${List?.message}", requireActivity())
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получения списка курсов созданных доктором
fun GetCoursesDoctor() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetCoursesDoctorPatient("Bearer $Tokens",id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctor.body()
val Nice = listCoursesDoctor.isSuccessful
val Code = listCoursesDoctor.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.SportCoursDoctorList.value = List.courses_doctor
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Вывод всех курсов
fun GetAllCoursesSport(){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetCoursAllPatient("Bearer $Tokens",id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.SportCoursList.value = List.courses
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
private fun btnClearSportPatient(id_sport:String) {
if (id_sport == "null") {
modelDoctor.BtnSportCoursDoctorCurrent.value = 1
} else {
modelDoctor.BtnSportCoursDoctorCurrent.value = 2
}
binding.btnClearSportPatient.setOnClickListener {
ClearSportPaient()
}
}
//Получения списка анкет ДО и ПОСЛЕ для пациента
fun QBAPatientList()=with(binding){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetPatientBAQiestionar("Bearer $Tokens",id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
if(List.questionnaire !=null){
txtNullQBA.visibility = View.GONE
modelDoctor.qbaList.value = List.questionnaire
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
private fun pause(pause:String) {
if (pause == "null") {
binding.CVPause.setCardBackgroundColor(Color.parseColor("#A9D867"))
} else {
binding.CVPause.setCardBackgroundColor(Color.parseColor("#D86767"))
}
binding.btnPause.setOnClickListener {
UpdatePausePatient()
}
}
private fun block(block:String) {
if (block == "null") {
binding.CVBlock.setCardBackgroundColor(Color.parseColor("#A9D867"))
} else {
binding.CVBlock.setCardBackgroundColor(Color.parseColor("#D86767"))
}
binding.btnBlock.setOnClickListener {
UpdateBlockPatient()
}
}
//Блокировка пациента
fun UpdateBlockPatient(){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.UpdateBlockAccountPatient("Bearer $Tokens", id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
if (block == "null") {
block = "true"
binding.CVBlock.setCardBackgroundColor(Color.parseColor("#D86767"))
Toast(requireContext()).showCustomInfoToast("Блок установлен", requireActivity())
} else {
block = "null"
binding.CVBlock.setCardBackgroundColor(Color.parseColor("#A9D867"))
Toast(requireContext()).showCustomInfoToast("Блок убран", requireActivity())
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Блокировка пациента
fun UpdatePausePatient(){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.UpdatePauseAccountPatient("Bearer $Tokens", id!!)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
if (pause == "null") {
pause = "true"
binding.CVPause.setCardBackgroundColor(Color.parseColor("#D86767"))
Toast(requireContext()).showCustomInfoToast("Пауза установлен", requireActivity())
} else {
pause = "null"
binding.CVPause.setCardBackgroundColor(Color.parseColor("#A9D867"))
Toast(requireContext()).showCustomInfoToast("Пауза убран", requireActivity())
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Обновленеи логина
fun UpdatePatientLogin(id:Int,login:String){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val updateLogin = doctorApi.UpdatePatientLogin("Bearer $Tokens",id,login)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = updateLogin.body()
val Nice = updateLogin.isSuccessful
val Code = updateLogin.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
}
else{
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Обновленеи пароля
fun UpdatePatientPassword(id:Int,password:String){
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val updatePassword= doctorApi.UpdatePatientPassword("Bearer $Tokens",id,password)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = updatePassword.body()
val Nice = updatePassword.isSuccessful
val Code = updatePassword.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
}
else{
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
}
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
private fun sport() {
}
private fun report() = with(binding) {
btnExitPatientFragment.setOnClickListener {
activity?.supportFragmentManager?.beginTransaction()
?.replace(com.example.doctor.R.id.CLMainListPatient, PatientsListFragment.newInstance())
?.commit()
//this@PatientFragment.onDestroy()
}
btnReport.setOnClickListener {
CVReport.visibility = View.VISIBLE
QBAPatientList()
}
btnSport.setOnClickListener {
binding.CVSport.visibility = View.VISIBLE
}
btnCloseReport.setOnClickListener {
CVReport.visibility = View.GONE
initRcViewDay()
}
btnClouseEditSport.setOnClickListener {
CVEditSport.visibility = View.GONE
initRcViewDay()
}
CVEditSport.setOnClickListener {
CVEditSport.visibility = View.GONE
initRcViewDay()
}
CVEditPatient.setOnClickListener{
CVEditPatient.visibility = View.GONE
initRcViewDay()
}
btnClouseEditPatient.setOnClickListener{
CVEditPatient.visibility = View.GONE
initRcViewDay()
}
btnCloseReport2.setOnClickListener {
CVSport.visibility = View.GONE
}
btnCloseBefore.setOnClickListener {
CVQB.visibility = View.GONE
}
btnCloseAfter.setOnClickListener {
CVQA.visibility = View.GONE
}
CVReport.setOnClickListener {
CVReport.visibility = View.GONE
initRcViewDay()
}
CVSport.setOnClickListener {
CVSport.visibility = View.GONE
}
CVReportList.setOnClickListener {
}
btnEditPatient.setOnClickListener {
CVEditPatient.visibility = View.VISIBLE
}
//Переход на страницу редактирования курса
binding.btnEditSport.setOnClickListener{
binding.CVEditSport.visibility = View.VISIBLE
//Вывод фрагмента на активити при первоначальной загрузке
activity?.supportFragmentManager?.beginTransaction()
?.replace(com.example.doctor.R.id.CLEditSport, EditSportFragment.newInstance())
?.commit()
}
//Нажатие на кнопку для обновления логина
btnUpdateLogin.setOnClickListener{
val login = edLogin.text.toString()
if(login.count() != 0){
if(login.count() > 3){
UpdatePatientLogin(id!!,login)
}
else{
Toast(requireContext()).showCustomInfoToast("Логин слишком короткий", requireActivity())
}
}
else{
Toast(requireContext()).showCustomInfoToast("Поле пустое", requireActivity())
}
}
//Нажатие на кнопку для обновления пароля
btnUpdatePassword.setOnClickListener{
val password = edPassword.text.toString()
if(password.count() != 0){
if(password.count() > 10){
UpdatePatientPassword(id!!,password)
}
else{
Toast(requireContext()).showCustomInfoToast("Пароль слишком короткий", requireActivity())
}
}
else{
Toast(requireContext()).showCustomInfoToast("Поле пустое", requireActivity())
}
}
}
//Инициализация списка
private fun initRcViewDay() = with(binding) {
RCView.layoutManager = GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapter = QBBAdapter()
RCView.adapter = adapter
}
fun closeViewCard() {
binding.txtLogin.text = ""
binding.CVReport.visibility = View.GONE
initRcViewDay()
}
override fun onDestroy() {
super.onDestroy()
closeViewCard()
}
companion object {
fun newInstance() = PatientFragment()
}
}

View File

@ -0,0 +1,129 @@
package com.example.doctor.Patients.Reports
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemQuestionnaireAfterBinding
class QAAdapter() : ListAdapter<QAModel, QAAdapter.Holder>(Comparator()) {
class Holder(view: View) :
RecyclerView.ViewHolder(view) {
val binding = ItemQuestionnaireAfterBinding.bind(view)
@SuppressLint("SuspiciousIndentation")
fun bind(item: QAModel) = with(binding) {
// if (item.one == 1) {
// txtB1.text = "Да"
// } else {
// txtB1.text = "Нет"
// }
// txtA1.text = item.one.toString()
//
// if (item.two == 2) {
// txtA2.text = "Да"
// } else {
// txtA2.text = "Нет"
// }
//
// if (item.three == 3) {
// txtA3.text = "Да"
// } else {
// txtA3.text = "Нет"
// }
//
// if (item.four == 4) {
// txtA4.text = "Да"
// } else {
// txtA4.text = "Нет"
// }
//
// if (item.five == 5) {
// txtA5.text = "Да"
// } else {
// txtA5.text = "Нет"
// }
//
// if (item.six == 6) {
// txtA6.text = "Да"
// } else {
// txtA6.text = "Нет"
// }
//
// if (item.seven == 7) {
// txtA7.text = "Да"
// } else {
// txtA7.text = "Нет"
// }
//
// if (item.eight == 8) {
// txtA8.text = "Да"
// } else {
// txtA8.text = "Нет"
// }
//
// if (item.nine == 9) {
// txtA9.text = "Да"
// } else {
// txtA9.text = "Нет"
// }
//
// if (item.ten == 10) {
// txtA10.text = "Да"
// } else {
// txtA10.text = "Нет"
// }
//
// if (item.eleven == 11) {
// txtA11.text = "Да"
// } else {
// txtA11.text = "Нет"
// }
//
// if (item.twelve == 12) {
// txtA12.text = "Да"
// } else {
// txtA12.text = "Нет"
// }
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_questionnaire_after, parent, false)
return Holder(view)
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))
}
class Comparator : DiffUtil.ItemCallback<QAModel>() {
override fun areItemsTheSame(
oldItem: QAModel,
newItem: QAModel
): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(
oldItem: QAModel,
newItem: QAModel
): Boolean {
return oldItem == newItem
}
}
}

View File

@ -0,0 +1,19 @@
package com.example.doctor.Patients.Reports
data class QAModel(
val id: Int,
val status: String,
val one: Int,
val two: Int,
val three: Int,
val four: Int,
val five: Int,
val six: Int,
val seven: Int,
val eight: Int,
val nine: Int,
val ten: Int,
val eleven: Int,
val twelve: Int,
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Reports
data class QBAListModel(
val questionnaire: List<QBAModel>
)

View File

@ -0,0 +1,35 @@
package com.example.doctor.Patients.Reports
data class QBAModel(
val id: Int,
val date: String,
val idb: Int,
//val statusb: Int,
val oneb: Int,
val twob: Int,
val threeb: Int,
val fourb: Int,
val fiveb: Int,
val sixb: Int,
val sevenb: Int,
val eightb: Int,
val nineb: Int,
val statusa: Int,
val ida: Int,
val onea: Int,
val twoa: Int,
val threea: Int,
val foura: Int,
val fivea: Int,
val sixa: Int,
val sevena: Int,
val eighta: Int,
val ninea: Int,
val tena: Int,
val elevena: Int,
val twelvea: Int,
)

View File

@ -0,0 +1,112 @@
package com.example.doctor.Patients.Reports
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemQuestionnaireBeforeBinding
class QBAdapter() : ListAdapter<QBModel, QBAdapter.Holder>(Comparator()) {
class Holder(view: View) :
RecyclerView.ViewHolder(view) {
val binding = ItemQuestionnaireBeforeBinding.bind(view)
@SuppressLint("SuspiciousIndentation")
fun bind(item: QBModel) = with(binding) {
// if (item.one == 1) {
// txtB1.text = "Да"
// } else {
// txtB1.text = "Нет"
// }
// txtB1.text = item.one.toString()
//
// if (item.two == 2) {
// txtB2.text = "Да"
// } else {
// txtB2.text = "Нет"
// }
//
// if (item.three == 3) {
// txtB3.text = "Да"
// } else {
// txtB3.text = "Нет"
// }
//
// if (item.four == 4) {
// txtB4.text = "Да"
// } else {
// txtB4.text = "Нет"
// }
//
// if (item.five == 5) {
// txtB5.text = "Да"
// } else {
// txtB5.text = "Нет"
// }
//
// if (item.six == 6) {
// txtB6.text = "Да"
// } else {
// txtB6.text = "Нет"
// }
//
// if (item.seven == 7) {
// txtB7.text = "Да"
// } else {
// txtB7.text = "Нет"
// }
//
// if (item.eight == 8) {
// txtB8.text = "Да"
// } else {
// txtB8.text = "Нет"
// }
//
// if (item.nine == 9) {
// txtB9.text = "Да"
// } else {
// txtB9.text = "Нет"
// }
//
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_questionnaire_before, parent, false)
return Holder(view)
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))
}
class Comparator : DiffUtil.ItemCallback<QBModel>() {
override fun areItemsTheSame(oldItem: QBModel, newItem: QBModel): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: QBModel, newItem: QBModel): Boolean {
return oldItem == newItem
}
}
}

View File

@ -0,0 +1,293 @@
package com.example.doctor.Patients.Reports
import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemQbaBinding
class QBBAdapter() : ListAdapter<QBAModel, QBBAdapter.Holder>(Comparator()) {
class Holder(view: View) :
RecyclerView.ViewHolder(view) {
val binding = ItemQbaBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
@SuppressLint("SuspiciousIndentation")
fun bind(item: QBAModel) = with(binding) {
// if (item.one == 1) {
// txtB1.text = "Да"
// } else {
// txtB1.text = "Нет"
// }
txtDate.text = item.date
if(item.oneb >= 6){
txtStatusB.text = "Плохо"
CVB.setCardBackgroundColor(Color.parseColor("#DA8383"))
}
else if(item.fourb == 1 || item.fiveb == 1 ||item.sixb == 1 ||item.sevenb == 1 ||item.nineb == 1){
txtStatusB.text = "Средне"
CVB.setCardBackgroundColor(Color.parseColor("#DABA83"))
}
else{
txtStatusB.text = "Хорошо"
CVB.setCardBackgroundColor(Color.parseColor("#ABDA83"))
}
txtB1.text = item.oneb.toString()
if(item.oneb==0){
CLQB1.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
else if(item.oneb in 1..5){
CLQB1.setBackgroundColor(Color.parseColor("#C6DFD386"))
}
else{
CLQB1.setBackgroundColor(Color.parseColor("#C6DF8686"))
}
//Красный - "#C6DF8686"
//Зеленый - "#C686DF8F"
//Желтый - "#C6DFD386"
if (item.twob == 1) {
txtB2.text = "Да"
CLQB2.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB2.text = "Нет"
CLQB2.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.threeb == 1) {
txtB3.text = "Да"
CLQB3.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB3.text = "Нет"
CLQB3.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.fourb == 1) {
txtB4.text = "Да"
CLQB4.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB4.text = "Нет"
CLQB4.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.fiveb == 1) {
txtB5.text = "Да"
CLQB5.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB5.text = "Нет"
CLQB5.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.sixb == 1) {
txtB6.text = "Да"
CLQB6.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB6.text = "Нет"
CLQB6.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.sevenb == 1) {
txtB7.text = "Да"
CLQB7.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB7.text = "Нет"
CLQB7.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.eightb == 1) {
txtB8.text = "Да"
CLQB8.setBackgroundColor(Color.parseColor("#C686DF8F"))
} else {
txtB8.text = "Нет"
CLQB8.setBackgroundColor(Color.parseColor("#C6DF8686"))
}
if (item.nineb == 1) {
txtB9.text = "Да"
CLQB9.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtB9.text = "Нет"
CLQB9.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
//Если анкета после была заполнена
if(item.statusa == 1){
if(item.ninea == 1){
txtStatusA.text = "Плохо"
CVA.setCardBackgroundColor(Color.parseColor("#DA8383"))
}
else if(item.onea >= 6 || item.threea == 1 ||item.sixa == 1 ||item.eighta == 1 ||item.elevena == 1){
txtStatusA.text = "Средне"
CVA.setCardBackgroundColor(Color.parseColor("#DABA83"))
}
else{
txtStatusA.text= "Хорошо"
CVA.setCardBackgroundColor(Color.parseColor("#ABDA83"))
}
txtA1.text = item.onea.toString()
if(item.onea==0){
CLQA1.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
else if(item.onea in 1..5){
CLQA1.setBackgroundColor(Color.parseColor("#C6DFD386"))
}
else{
CLQA1.setBackgroundColor(Color.parseColor("#C6DF8686"))
}
if (item.twoa == 1) {
txtA2.text = "Да"
CLQA2.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA2.text = "Нет"
CLQA2.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.threea == 1) {
txtA3.text = "Да"
CLQA3.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA3.text = "Нет"
CLQA3.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.foura == 1) {
txtA4.text = "Да"
CLQA4.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA4.text = "Нет"
CLQA4.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.fivea == 1) {
txtA5.text = "Да"
CLQA5.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA5.text = "Нет"
CLQA5.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.sixa == 1) {
txtA6.text = "Да"
CLQA6.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA6.text = "Нет"
CLQA6.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.sevena == 1) {
txtA7.text = "Да"
CLQA7.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA7.text = "Нет"
CLQA7.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.eighta == 1) {
txtA8.text = "Да"
CLQA8.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA8.text = "Нет"
CLQA8.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.ninea == 1) {
txtA9.text = "Да"
CLQA9.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA9.text = "Нет"
CLQA9.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.tena == 1) {
txtA10.text = "Да"
CLQA10.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA10.text = "Нет"
CLQA10.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.elevena == 1) {
txtA11.text = "Да"
CLQA11.setBackgroundColor(Color.parseColor("#C6DF8686"))
} else {
txtA11.text = "Нет"
CLQA11.setBackgroundColor(Color.parseColor("#C686DF8F"))
}
if (item.twelvea == 1) {
txtA12.text = "Да"
CLQA12.setBackgroundColor(Color.parseColor("#C686DF8F"))
} else {
txtA12.text = "Нет"
CLQA12.setBackgroundColor(Color.parseColor("#C6DF8686"))
}
}
else{
//Если анкета ПОСЛЕ небыла заполнена
txtStatusA.text = "ПУСТО"
txtStatusA.setTextColor(Color.parseColor("#FFFFFF"))
CVA.setCardBackgroundColor(Color.parseColor("#000000"))
CVColorAfter.setCardBackgroundColor(Color.parseColor("#FF8E8E8E"))
txtA1.text = ""
txtA2.text = ""
txtA3.text = ""
txtA4.text = ""
txtA5.text = ""
txtA6.text = ""
txtA7.text = ""
txtA8.text = ""
txtA9.text = ""
txtA10.text = ""
txtA11.text = ""
txtA12.text = ""
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_qba, parent, false)
return Holder(view)
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))
}
class Comparator : DiffUtil.ItemCallback<QBAModel>() {
override fun areItemsTheSame(oldItem: QBAModel, newItem: QBAModel): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: QBAModel, newItem: QBAModel): Boolean {
return oldItem == newItem
}
}
}

View File

@ -0,0 +1,16 @@
package com.example.doctor.Patients.Reports
data class QBModel(
val id: Int,
val status: String,
val one: Int,
val two: Int,
val three: Int,
val four: Int,
val five: Int,
val six: Int,
val seven: Int,
val eight: Int,
val nine: Int,
)

View File

@ -0,0 +1,6 @@
package com.example.doctor.Patients.Reports.Requests
data class ClearSportPatientModel(
val message: String,
)

View File

@ -0,0 +1,173 @@
package com.example.doctor.Patients.TabLayoutPatient
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Adapter.PatientListAdapter
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Model.PatientIdModel
import com.example.doctor.Patients.PatientActivity
import com.example.doctor.Patients.Reports.PatientFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.FragmentActiveCoursesPatientBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class ActiveCoursesPatientFragment : Fragment(),PatientListAdapter.Listener {
private lateinit var binding:FragmentActiveCoursesPatientBinding
private val modelDoctor: DoctorViewModel by activityViewModels()
private val dataModel: DataModel by activityViewModels()//Для передачи данных
lateinit var adapterPatient: PatientListAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
var patientYesList:List<PatientAllModel>?=null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentActiveCoursesPatientBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewDay()
GetPatientList()
modelDoctor.PatientActiveList.observe(viewLifecycleOwner){
if(patientYesList!=it){
patientYesList=it
adapterPatient.submitList(it)
}
}
}
//Инициализация списка
private fun initRcViewDay() = with(binding) {
rcView.layoutManager =
GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterPatient = PatientListAdapter(this@ActiveCoursesPatientFragment)
rcView.adapter = adapterPatient
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Получения списка пациентов
fun GetPatientList() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetPatientAllActive("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
modelDoctor.PatientActiveList.value = List.patient
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
companion object {
fun newInstance() = ActiveCoursesPatientFragment()
}
override fun onClickPatient(item: PatientAllModel) {
//Вывод фрагмента на активити при первоначальной загрузке
// activity?.supportFragmentManager?.beginTransaction()
// ?.replace(com.example.doctor.R.id.CLMainPatient, PatientFragment.newInstance())
// ?.commit()
// prefDoctorSave.saveIdPatient(requireContext(),item.id!!)
// prefDoctorSave.saveViewPatient(requireContext(),1)
//modelDoctor.patientId.value = PatientIdModel(item.id!!)
prefDoctorSave.saveIdPatient(requireContext(),item.id!!)
prefDoctorSave.saveViewPatient(requireContext(),1)
val intetn = Intent(requireContext(), PatientActivity::class.java)
startActivity(intetn)
// dataModel.patientList.value = 1
}
}

View File

@ -0,0 +1,173 @@
package com.example.doctor.Patients.TabLayoutPatient
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DataModel
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetCheck
import com.example.doctor.Patients.Adapter.PatientListAdapter
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Model.PatientIdModel
import com.example.doctor.Patients.PatientActivity
import com.example.doctor.Patients.Reports.PatientFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.databinding.FragmentNotActiveCoursesPatientBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class NotActiveCoursesPatientFragment : Fragment(),PatientListAdapter.Listener {
private lateinit var binding:FragmentNotActiveCoursesPatientBinding
private val model: DoctorViewModel by activityViewModels()
private val dataModel: DataModel by activityViewModels()//Для передачи данных
lateinit var adapterPatient: PatientListAdapter
private lateinit var doctorApi: DoctorApi
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
//Класс проверки интеренета
val enternetCheck = EnternetCheck()
//Список не активных пациентов
var patientNoList: List<PatientAllModel>? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentNotActiveCoursesPatientBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcViewDay()
GetPatientList()
model.PatientNotList.observe(viewLifecycleOwner){
if(patientNoList != it){
patientNoList = it
adapterPatient.submitList(it)
}
}
}
//Инициализация списка
private fun initRcViewDay() = with(binding) {
rcView.layoutManager =
GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterPatient = PatientListAdapter(this@NotActiveCoursesPatientFragment)
rcView.adapter = adapterPatient
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Получения списка пациентов
fun GetPatientList() {
if (enternetCheck.isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listProduct = doctorApi.GetPatientAllNotActive("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listProduct.body()
val Nice = listProduct.isSuccessful
val Code = listProduct.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
model.PatientNotList.value = List.patient
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
override fun onClickPatient(item: PatientAllModel) {
//Вывод фрагмента на активити при первоначальной загрузке
// activity?.supportFragmentManager?.beginTransaction()
// ?.replace(com.example.doctor.R.id.CLMainPatient, PatientFragment.newInstance())
// ?.commit()
prefDoctorSave.saveIdPatient(requireContext(),item.id!!)
prefDoctorSave.saveViewPatient(requireContext(),1)
//model.patientId.value = PatientIdModel(item.id!!)
val intetn = Intent(requireContext(), PatientActivity::class.java)
startActivity(intetn)
// dataModel.patientList.value = 1
}
companion object {
fun newInstance() = NotActiveCoursesPatientFragment()
}
}

View File

@ -0,0 +1,42 @@
package com.example.doctor.Pref
import android.content.Context
import android.content.SharedPreferences
class ClearPref() {
fun clearToken(context: Context) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORtoken", Context.MODE_PRIVATE)
val edit = prefDoctor.edit()
edit?.clear()
edit?.apply()
}
fun clearViewPatient(context: Context) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORviewPatient", Context.MODE_PRIVATE)
val edit = prefDoctor.edit()
edit?.clear()
edit?.apply()
}
fun clearIdPatient(context: Context) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORIdPatient", Context.MODE_PRIVATE)
val edit = prefDoctor.edit()
edit?.clear()
edit?.apply()
}
fun clearIdCourses(context: Context) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORIdCourses", Context.MODE_PRIVATE)
val edit = prefDoctor.edit()
edit?.clear()
edit?.apply()
}
fun clearIdActivitis(context: Context) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORIdActivitis", Context.MODE_PRIVATE)
val edit = prefDoctor.edit()
edit?.clear()
edit?.apply()
}
}

View File

@ -0,0 +1,37 @@
package com.example.doctor.Pref
import android.content.Context
import android.content.SharedPreferences
class ConclusionPref() {
fun conclusionToken(context: Context):String {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORtoken", Context.MODE_PRIVATE)
val token = prefDoctor.getString("token", "")
return token.toString()
}
fun conclusionViewPatient(context: Context):Int {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORviewPatient", Context.MODE_PRIVATE)
val viewPatient = prefDoctor.getInt("viewPatient", 0)
return viewPatient.toInt()
}
fun conclusionIdPatient(context: Context):Int {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORidPatient", Context.MODE_PRIVATE)
val idPatient = prefDoctor.getInt("idPatient", 0)
return idPatient.toInt()
}
fun conclusionIdCourses(context: Context):Int {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORidCourses", Context.MODE_PRIVATE)
val idPatient = prefDoctor.getInt("idCourses", 0)
return idPatient.toInt()
}
fun conclusionIdActivitis(context: Context):Int {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORIdActivitis", Context.MODE_PRIVATE)
val idPatient = prefDoctor.getInt("idActivitis", 0)
return idPatient.toInt()
}
}

View File

@ -0,0 +1,39 @@
package com.example.doctor.Pref
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
class SavePref (){
@SuppressLint("CommitPrefEdits")
fun saveToken(context: Context, token: String) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORtoken", Context.MODE_PRIVATE)
prefDoctor.edit().putString("token", token).apply()
}
@SuppressLint("CommitPrefEdits")
fun saveViewPatient(context: Context, view_patient: Int) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORviewPatient", Context.MODE_PRIVATE)
prefDoctor.edit().putInt("viewPatient", view_patient).apply()
}
@SuppressLint("CommitPrefEdits")
fun saveIdPatient(context: Context, view_patient: Int) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORidPatient", Context.MODE_PRIVATE)
prefDoctor.edit().putInt("idPatient", view_patient).apply()
}
@SuppressLint("CommitPrefEdits")
fun saveIdCourses(context: Context, view_patient: Int) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORidCourses", Context.MODE_PRIVATE)
prefDoctor.edit().putInt("idCourses", view_patient).apply()
}
@SuppressLint("CommitPrefEdits")
fun saveIdActivitis(context: Context, view_patient: Int) {
val prefDoctor: SharedPreferences = context.getSharedPreferences("DOCTORIdActivitis", Context.MODE_PRIVATE)
prefDoctor.edit().putInt("idActivitis", view_patient).apply()
}
}

View File

@ -0,0 +1,234 @@
package com.example.doctor.Retrofit
import com.example.doctor.Appeals.TabLayout.Model.AppealsNewListModel
import com.example.doctor.Appeals.TabLayout.Model.AppealsOldListModel
import com.example.doctor.Auth.Model.AuthModel
import com.example.doctor.Auth.Model.CheckTokenModel
import com.example.doctor.Auth.Model.UserModel
import com.example.doctor.Home.HomeInfoModel
import com.example.doctor.Patients.Model.MessageModel
import com.example.doctor.Patients.Model.CreatePatientModel
import com.example.doctor.Patients.Model.PatientAllListModel
import com.example.doctor.Patients.Model.PatientAllModel
import com.example.doctor.Patients.Model.PatientModel
import com.example.doctor.Patients.Model.PauseModel
import com.example.doctor.Patients.Reports.Courses.SportCoursDoctorListModel
import com.example.doctor.Patients.Reports.Courses.SportCoursListModel
import com.example.doctor.Patients.Reports.Edit.EditSportListNoModel
import com.example.doctor.Patients.Reports.Edit.EditSportListYesModel
import com.example.doctor.Patients.Reports.QBAListModel
import com.example.doctor.Patients.Reports.Requests.ClearSportPatientModel
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.EditCoursesDoctorListAllModel
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.EditCoursesDoctorListYourModel
import com.example.doctor.Setting.Courses.Model.CoursesDoctorListModel
import com.example.doctor.Sport.AddSportPatientModel
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Headers
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Query
interface DoctorApi {
//Проверка токена
@Headers("Content-Type: application/json")
@GET("CheckTokenDoctor")
suspend fun CheckToken(@Header("Authorization") token:String): Response<CheckTokenModel>
//Выход из аккаунта
@Headers("Content-Type: application/json")
@POST("LoginDoctor")
suspend fun LoginDoctor(@Body authModel: AuthModel): Response<UserModel>
//Выход из аккаунта
@Headers("Content-Type: application/json")
@POST("LogoutDoctor")
suspend fun LogoutDoctor(@Header("Authorization") token:String):Response<MessageModel>
//Вывод всех пациентов
@Headers("Content-Type: application/json")
@GET("GetPatientAll")
suspend fun GetPatientAll(@Header("Authorization") token:String):Response<PatientAllListModel>
//Вывод пациентов конкретного врача с активным курсом
@Headers("Content-Type: application/json")
@GET("GetPatientAllActive")
suspend fun GetPatientAllActive(@Header("Authorization") token:String):Response<PatientAllListModel>
//Вывод пациентов конкретного врача с не активным курсом
@Headers("Content-Type: application/json")
@GET("GetPatientAllNotActive")
suspend fun GetPatientAllNotActive(@Header("Authorization") token:String):Response<PatientAllListModel>
//Вывод всех пациентов
@Headers("Content-Type: application/json")
@GET("GetPatientID")
suspend fun GetPatientID(@Header("Authorization") token:String,@Query("id") id:Int):Response<PatientAllModel>
//Поиск пациентов
@Headers("Content-Type: application/json")
@GET("GetPatientSearch")
suspend fun GetPatientSearch(@Header("Authorization") token:String,@Query("login") login:String):PatientModel
//Вывод всех курсов
@Headers("Content-Type: application/json")
@GET("GetCoursAll")
suspend fun GetCoursAll(@Header("Authorization") token:String):Response<SportCoursListModel>
//Вывод всех курсов
@Headers("Content-Type: application/json")
@GET("GetCoursAllPatient")
suspend fun GetCoursAllPatient(@Header("Authorization") token:String,@Query("id") id:Int):Response<SportCoursListModel>
//Вывод курсов созданных врачем
@Headers("Content-Type: application/json")
@GET("GetCoursesDoctorPatient")
suspend fun GetCoursesDoctorPatient(@Header("Authorization") token:String,@Query("id") id:Int):Response<SportCoursDoctorListModel>
//Вывод анкеты пациентов которые сейчас действуют
@Headers("Content-Type: application/json")
@GET("GetPatientBAQiestionar")
suspend fun GetPatientBAQiestionar(@Header("Authorization") token:String,@Query("id") id:Int):Response<QBAListModel>
//Создание аккаунта
@Headers("Content-Type: application/json")
@POST("CreateAccountPatient")
suspend fun CreateAccountPatient(@Header("Authorization") token:String,@Body createPatientModel: CreatePatientModel):Response<MessageModel>
//Обновление данных пользователя
@Headers("Content-Type: application/json")
@PUT("UpdateAccountPatient")
suspend fun UpdateAccountPatient(@Header("Authorization") token:String,@Query("id") id:String, @Query("login") login:String,@Query("password") password:String)
//Добавление блокировки
@Headers("Content-Type: application/json")
@PUT("UpdateBlockAccountPatient")
suspend fun UpdateBlockAccountPatient(@Header("Authorization") token:String,@Query("id") id:Int):Response<MessageModel>
//Добавление паузы
@Headers("Content-Type: application/json")
@PUT("UpdatePauseAccountPatient")
suspend fun UpdatePauseAccountPatient(@Header("Authorization") token:String,@Query("id") id:Int):Response<PauseModel>
//Получения курса пациента в зависимости от того сколько дней пройдено
@Headers("Content-Type: application/json")
@GET("GetCours")
suspend fun GetCours(@Header("Authorization") token:String,@Query("name") name:String,@Query("day") day:String)
//Добавление курса пациенту
@Headers("Content-Type: application/json")
@POST("AddSportPatient")
suspend fun AddSportPatient(@Header("Authorization") token:String,@Body addSportPatientModel: AddSportPatientModel)
//Очистка курса у пациента
@Headers("Content-Type: application/json")
@PUT("ClearPatientSport")
suspend fun ClearPatientSport(@Header("Authorization") token:String,@Query("id_patient") id_patient:Int):Response<ClearSportPatientModel>
//Вывод всех курсов
@Headers("Content-Type: application/json")
@GET("GetCoursesSport")
suspend fun GetCoursesSport(@Header("Authorization") token:String,@Query("id_patient") id_patient:Int,@Query("id_sports_courses_patient") id_sports_courses_patient:Int):Response<EditSportListNoModel>
//Вывод всех включенных упражненйи
@Headers("Content-Type: application/json")
@GET("GetCoursesSportYes")
suspend fun GetCoursesSportYes(@Header("Authorization") token:String,@Query("id_patient") id_patient:Int):Response<EditSportListYesModel>
//Вывод всех отключенных упражнений
@Headers("Content-Type: application/json")
@GET("GetCoursesSportNo")
suspend fun GetCoursesSportNo(@Header("Authorization") token:String,@Query("id_patient") id_patient:Int):Response<EditSportListNoModel>
//Отключенных упражнений
@Headers("Content-Type: application/json")
@PUT("UpdateBlockSportTasksYes")
suspend fun UpdateBlockSportTasksYes(@Header("Authorization") token:String,@Query("id_patient") id_patient:Int,@Query("id_sports_tasks") id_sports_tasks:Int):Response<MessageModel>
//Отключенных упражнений
@Headers("Content-Type: application/json")
@PUT("UpdateBlockSportTasksNo")
suspend fun UpdateBlockSportTasksNo(@Header("Authorization") token:String,@Query("id") id:Int):Response<MessageModel>
//Отключенных упражнений
@Headers("Content-Type: application/json")
@PUT("UpdatePatientLogin")
suspend fun UpdatePatientLogin(@Header("Authorization") token:String,@Query("id") id:Int,@Query("login") login:String):Response<MessageModel>
//Отключенных упражнений
@Headers("Content-Type: application/json")
@PUT("UpdatePatientPassword")
suspend fun UpdatePatientPassword(@Header("Authorization") token:String,@Query("id") id:Int,@Query("password") password:String):Response<MessageModel>
//Добавление курса пациенту
@Headers("Content-Type: application/json")
@POST("AddSportPatient")
suspend fun AddSportPatient(@Header("Authorization") token:String,@Query("id_patient") id:Int,@Query("id_course") id_course:Int,@Query("all_day") all_day:Int):Response<MessageModel>
//Вывод необработанных сообщений
@Headers("Content-Type: application/json")
@GET("GetAppealsDoctorNew")
suspend fun GetAppealsDoctorNew(@Header("Authorization") token:String) :Response<AppealsNewListModel>
//Вывод необработанных сообщений
@Headers("Content-Type: application/json")
@GET("GetAppealsDoctorOld")
suspend fun GetAppealsDoctorOld(@Header("Authorization") token:String) :Response<AppealsOldListModel>
//Подтверждение необработанных сообщений
@Headers("Content-Type: application/json")
@PUT("UpdateMessageDoctor")
suspend fun UpdateMessageDoctor(@Header("Authorization") token:String,@Query("id") id:Int,@Query("id_patient") id_patient:Int) :Response<MessageModel>
//Отправка сообщения пациенту
@Headers("Content-Type: application/json")
@POST("AddMessageDoctor")
suspend fun AddMessageDoctor(@Header("Authorization") token:String,@Query("login") login:String,@Query("text") text:String) :Response<MessageModel>
//Создание курса врачем
@Headers("Content-Type: application/json")
@POST("AddCoursesName")
suspend fun AddCoursesName(@Header("Authorization") token:String,@Query("name") name:String,@Query("description") description:String) :Response<MessageModel>
//Вывод курсов созданных врачем
@Headers("Content-Type: application/json")
@GET("GetCoursesDoctor")
suspend fun GetCoursesDoctor(@Header("Authorization") token:String) :Response<CoursesDoctorListModel>
//Вывод упражнений которые не входят в курс
@Headers("Content-Type: application/json")
@GET("GetEditCourseDoctorAll")
suspend fun GetEditCourseDoctorAll(@Header("Authorization") token:String,@Query("id_doctor_courses") id_doctor_courses:Int) :Response<EditCoursesDoctorListAllModel>
//Вывод упражнений которые входят в курс
@Headers("Content-Type: application/json")
@GET("GetEditCourseDoctorYour")
suspend fun GetEditCourseDoctorYour(@Header("Authorization") token:String,@Query("id_doctor_courses") id_doctor_courses:Int) :Response<EditCoursesDoctorListYourModel>
//Добавление упражнений в курс
@Headers("Content-Type: application/json")
@POST("AddCoursesCreatingDoctor")
suspend fun AddCoursesCreatingDoctor(@Header("Authorization") token:String,@Query("id_sports_tasks") id_sports_tasks:Int,@Query("id_sets_of_sports_activities") id_sets_of_sports_activities:Int) :Response<MessageModel>
//Удаление упражнений из курса
@Headers("Content-Type: application/json")
@DELETE("ClearCoursesCreatingDoctor")
suspend fun ClearCoursesCreatingDoctor(@Header("Authorization") token:String,@Query("id_sets_of_sports_exercises") id_sets_of_sports_exercises:Int) :Response<MessageModel>
//Вывод данных для первой страницы врача
@Headers("Content-Type: application/json")
@GET("CountPatientAndAppeals")
suspend fun CountPatientAndAppeals(@Header("Authorization") token:String) :Response<HomeInfoModel>
}

View File

@ -0,0 +1,90 @@
package com.example.doctor.Setting.Courses.Adapter
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.Setting.Courses.Model.CoursesDoctorModel
import com.example.doctor.databinding.ItemCardCoursesDoctorBinding
class CoursesDoctorAdapter(val listener: Listener) :
ListAdapter<CoursesDoctorModel, CoursesDoctorAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemCardCoursesDoctorBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: CoursesDoctorModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
itemView.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
//itemView.setEnabled(false)
itemTemp?.let { it1 -> listener.onClickCourses(it1) }
}
}
@SuppressLint("SuspiciousIndentation", "SetTextI18n")
fun bind(item: CoursesDoctorModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumberCurds.text = item.number.toString() + "."
txtNameCoursesDoctor.text = item.name
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_card_courses_doctor, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<CoursesDoctorModel>() {
override fun areItemsTheSame(
oldItem: CoursesDoctorModel,
newItem: CoursesDoctorModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: CoursesDoctorModel,
newItem: CoursesDoctorModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickCourses(item: CoursesDoctorModel)
}
}

View File

@ -0,0 +1,22 @@
package com.example.doctor.Setting.Courses
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.doctor.Patients.Reports.PatientFragment
import com.example.doctor.R
import com.example.doctor.Setting.Courses.EditCourses.CreateCoursesFragment
import com.example.doctor.databinding.ActivityCoursesBinding
class CoursesActivity : AppCompatActivity() {
private lateinit var binding: ActivityCoursesBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCoursesBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.apply {
supportFragmentManager.beginTransaction().replace(R.id.CLCoursesActivity, CreateCoursesFragment.newInstance()).commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}
}

View File

@ -0,0 +1,407 @@
package com.example.doctor.Setting.Courses.EditCourses
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Adapter.VpAdapter
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Setting.Courses.Adapter.CoursesDoctorAdapter
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.AllSportCoursesDoctorFragment
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.YourSportCoursesDoctorFragment
import com.example.doctor.Setting.Courses.Model.CoursesDoctorModel
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentCreateCoursesBinding
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class CreateCoursesFragment : Fragment(),CoursesDoctorAdapter.Listener {
private lateinit var binding: FragmentCreateCoursesBinding
private val model: DoctorViewModel by activityViewModels()
private lateinit var doctorApi: DoctorApi
lateinit var adapter: CoursesDoctorAdapter
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentCreateCoursesBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.apply {
initRcView()
GetCoursesDoctor()
button()
CLCreate.visibility = View.GONE
btnCreateCourses.setOnClickListener{
CLCreate.visibility = View.VISIBLE
}
//Закрытие экоана создания названия
CLCreate.setOnClickListener{
CLCreate.visibility = View.GONE
}
btnExitCreat.setOnClickListener{
CLCreate.visibility = View.GONE
}
// CLEditCourses.setOnClickListener {
// CLEditCourses.visibility = View.GONE
// }
btnExit.setOnClickListener{
activity?.finish()
}
model.CoursesDoctorList.observe(viewLifecycleOwner) {
adapter.submitList(it)
}
btnCreateCoursrsDoctor.setOnClickListener{
CreateCoursesDoctor()
}
}
}
private fun CreateCoursesDoctor() {
val name = binding.edCoursesDoctorName.text.toString()
val description = binding.edCoursesDoctorDescription.text.toString()
if(name!="" && description !=""){
AddCoursesName(name,description)
}
else{
Toast(requireContext()).showCustomInfoToast("Не все поля заполнены", requireActivity())
}
}
private fun button() = with(binding){
CVCardCreateCourses.setOnClickListener {
}
// CVEditCourses.setOnClickListener {
//
// }
}
//Получения списка пациентов
fun AddCoursesName(name:String,description:String) {
if (isOnline(requireContext())) {
visibleLoadYes()
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCreateCoursesDoctor = doctorApi.AddCoursesName("Bearer $Tokens",name,description)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCreateCoursesDoctor.body()
val Nice = listCreateCoursesDoctor.isSuccessful
val Code = listCreateCoursesDoctor.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
GetCoursesDoctor()
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
visibleLoadNo()
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получения списка курсов созданных доктором
fun GetCoursesDoctor() {
if (isOnline(requireContext())) {
visibleLoadYes()
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetCoursesDoctor("Bearer $Tokens")
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctor.body()
val Nice = listCoursesDoctor.isSuccessful
val Code = listCoursesDoctor.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
model.CoursesDoctorList.value = List.sport_courses_doctor
binding.txtNull.visibility = View.GONE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
visibleLoadNo()
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Инициализация списка
private fun initRcView() = with(binding) {
rcView.layoutManager = GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapter = CoursesDoctorAdapter(this@CreateCoursesFragment)
rcView.adapter = adapter
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
fun visible1()=with(binding){
constraintLayout2.visibility = View.VISIBLE
CLCreate.visibility = View.GONE
// CLEditCourses.visibility = View.GONE
CLLoad.visibility = View.GONE
}
fun visible2()=with(binding){
constraintLayout2.visibility = View.GONE
CLCreate.visibility = View.VISIBLE
//CLEditCourses.visibility = View.GONE
CLLoad.visibility = View.GONE
}
fun visible3()=with(binding){
constraintLayout2.visibility = View.GONE
CLCreate.visibility = View.GONE
// CLEditCourses.visibility = View.VISIBLE
CLLoad.visibility = View.GONE
}
fun visibleLoadYes()=with(binding){
CLLoad.visibility = View.VISIBLE
}
fun visibleLoadNo()=with(binding){
CLLoad.visibility = View.GONE
}
companion object {
fun newInstance() = CreateCoursesFragment()
}
// //Получения списка курсов созданных доктором
// fun GetEditCourseDoctorAll(id:Int) {
// if (isOnline(requireContext())) {
// initRetrofit()
// val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
// CoroutineScope(Dispatchers.IO).launch {
// val listCoursesDoctor = doctorApi.GetEditCourseDoctorAll("Bearer $Tokens",id)
//
// requireActivity().runOnUiThread {
//
// //Фиксируем полученные данные
// val CoursesDoctorList = listCoursesDoctor.body()
//
// //Если нету ошибок
// if (CoursesDoctorList != null) {
// model.EditCoursesDoctorAllList.value = CoursesDoctorList.set_of_sports_exercises_all
// binding.txtNull.visibility = View.GONE
// }
// else{
// binding.txtNull.visibility = View.VISIBLE
// }
//
// }
//
// }
// } else {
// val intetn = Intent(requireContext(), EnternetActivity::class.java)
// activity?.finish()
// startActivity(intetn)
// }
//
// }
// //Получения списка курсов созданных доктором
// fun GetEditCourseDoctorYour(id:Int) {
// if (isOnline(requireContext())) {
// initRetrofit()
// val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
// CoroutineScope(Dispatchers.IO).launch {
// val listCoursesDoctor = doctorApi.GetEditCourseDoctorYour("Bearer $Tokens",id)
//
// requireActivity().runOnUiThread {
//
// //Фиксируем полученные данные
// val CoursesDoctorList = listCoursesDoctor.body()
//
// //Если нету ошибок
// if (CoursesDoctorList != null) {
// model.EditCoursesDoctorYourList.value = CoursesDoctorList.set_of_sports_exercises_your
// }
// }
// }
// } else {
// val intetn = Intent(requireContext(), EnternetActivity::class.java)
// activity?.finish()
// startActivity(intetn)
// }
//
// }
//Проверка интернета
fun isOnline(context: Context): Boolean {
if (context == null) return false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val capabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
if (capabilities != null) {
when {
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> {
return true
}
}
}
} else {
val activeNetworkInfo = connectivityManager.activeNetworkInfo
if (activeNetworkInfo != null && activeNetworkInfo.isConnected) {
return true
}
}
return false
}
override fun onClickCourses(item: CoursesDoctorModel){
// // CLEditCourses.visibility = View.VISIBLE
// prefDoctorSave.saveIdCourses(requireContext(),item.id)
// prefDoctorSave.saveIdActivitis(requireContext(),item.id_activity)
// // model.CoursesDoctorCA.value= CoursesDoctorCA(item.id,item.id_activity)
// GetEditCourseDoctorAll(item.id)
// GetEditCourseDoctorYour(item.id)
model.CoursesCustomDoctor.value = item
activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.CLCoursesActivity, EditCoursesFragment.newInstance())?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
}

View File

@ -0,0 +1,242 @@
package com.example.doctor.Setting.Courses.EditCourses
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.activityViewModels
import com.example.doctor.Adapter.VpAdapter
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Setting.Courses.Adapter.CoursesDoctorAdapter
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.AllSportCoursesDoctorFragment
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.YourSportCoursesDoctorFragment
import com.example.doctor.databinding.FragmentEditCoursesBinding
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class EditCoursesFragment : Fragment() {
private lateinit var binding:FragmentEditCoursesBinding
private val model: DoctorViewModel by activityViewModels()
private lateinit var doctorApi: DoctorApi
lateinit var adapter: CoursesDoctorAdapter
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
private val tList = listOf(
"добавленные",
"Все",
)
//Список с фрагментами для переключения
private val flist = listOf(
YourSportCoursesDoctorFragment.newInstance(),
AllSportCoursesDoctorFragment.newInstance(),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentEditCoursesBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.apply {
init()
binding.btnBack.setOnClickListener{
activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.CLCoursesActivity, CreateCoursesFragment.newInstance())?.commit()//Заменяем наш экран на фрагмент (используем наш экран как основу)//R.id.placeHolder - куда всталяем //MainFragment.newInstance() - это то что мы вставляем
}
model.CoursesCustomDoctor.observe(viewLifecycleOwner){
txtNameCourses.text = it.name
GetEditCourseDoctorYour(it.id)
GetEditCourseDoctorAll(it.id)
}
}
}
//Получения списка упражнений созданных врачем
fun GetEditCourseDoctorYour(id:Int) {
if (isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetEditCourseDoctorYour("Bearer $Tokens",id)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctor.body()
val Nice = listCoursesDoctor.isSuccessful
val Code = listCoursesDoctor.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
model.EditCoursesDoctorYourList.value = List.set_of_sports_exercises_your
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получения списка курсов созданных доктором
fun GetEditCourseDoctorAll(id:Int) {
if (isOnline(requireContext())) {
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetEditCourseDoctorAll("Bearer $Tokens",id)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val CoursesDoctorList = listCoursesDoctor.body()
//Если нету ошибок
if (CoursesDoctorList != null) {
model.EditCoursesDoctorAllList.value = CoursesDoctorList.set_of_sports_exercises_all
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Функция подключения переключения
private fun init() = with(binding) {
val adapter = VpAdapter(activity as FragmentActivity, flist)
vpCourses.adapter = adapter
//Переключения (связываем таблаяут(переключатель) с viewpager, чтобы переключать фрагменты)
TabLayoutMediator(tabLayoutCourses, vpCourses) { tab, pos ->
tab.text =
tList[pos]//tab - нажатая кнопка, pos - позиция кнопки, tList[pos] - передаем название по полученной позиции
}.attach()// attach() - чтобы все переключалось, а не вывадило постоянно один экран
//Изменения цвета в зависомости на каком из tabLayout вы находитесь
binding.tabLayoutCourses.setTabTextColors(
getResources().getColor(R.color.black),
getResources().getColor(R.color.white)
);
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Проверка интернета
fun isOnline(context: Context): Boolean {
if (context == null) return false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val capabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
if (capabilities != null) {
when {
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> {
return true
}
}
}
} else {
val activeNetworkInfo = connectivityManager.activeNetworkInfo
if (activeNetworkInfo != null && activeNetworkInfo.isConnected) {
return true
}
}
return false
}
companion object {
fun newInstance() = EditCoursesFragment()
}
}

View File

@ -0,0 +1,107 @@
package com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Adapter
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.EditCoursesDoctorModel
import com.example.doctor.databinding.ItemEditSportYesBinding
class EditCoursesDoctorAllAdapter(val listener_sport: Listener) :
ListAdapter<EditCoursesDoctorModel, EditCoursesDoctorAllAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_sport: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemEditSportYesBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: EditCoursesDoctorModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
binding.btnYeyYes.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
itemTemp?.let { it1 -> listener_sport.onClickCoursesAll(it1) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: EditCoursesDoctorModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumber.text = item.number.toString()+"."
txtNameSport.text = item.name
txtDescriptionSport.text = item.description
if (item.expand) {
binding.txtDescriptionSport.maxLines = 100
} else {
binding.txtDescriptionSport.maxLines = 1
}
binding.CardViewOld.setOnClickListener {
if (item.expand == false) {
binding.txtDescriptionSport.maxLines = 100
item.expand = true
} else {
binding.txtDescriptionSport.maxLines = 1
item.expand = false
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_edit_sport_yes, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_sport)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<EditCoursesDoctorModel>() {
override fun areItemsTheSame(
oldItem: EditCoursesDoctorModel,
newItem: EditCoursesDoctorModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: EditCoursesDoctorModel,
newItem: EditCoursesDoctorModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickCoursesAll(item: EditCoursesDoctorModel)
}
}

View File

@ -0,0 +1,107 @@
package com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Adapter
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.EditCoursesDoctorModel
import com.example.doctor.databinding.ItemEditSportNoBinding
class EditCoursesDoctorYourAdapter(val listener_sport: Listener) :
ListAdapter<EditCoursesDoctorModel, EditCoursesDoctorYourAdapter.Holder>(
Comparator()
) {//Productitem - по этой форме будем заполнять.//ProductAdapter.holder - это создаваемый holder который хранит логику как нужно заполнять карточку
//В holder создаетс код с помошью которого мы будем заполнять и сохронять разметку
class Holder(view: View, val listener_sport: Listener) :
RecyclerView.ViewHolder(view) {//Класс который будет хранить сссылки на элементы, и отвечает за один элемент за 1 раз, то есть сначсало нулевой элемент заполнит, потом первый, потом второй и т.д.
//Для передачи данных
val binding = ItemEditSportNoBinding.bind(view)//view - здесь храянтся элементы и мы их bind заполним в ListItemBinding//ListItemBinding - это клласс даннйо разметки(карточки) которую мы будем заполнять, а нужна дання переменная(binding), чтобы мжно было при заполнение обращатся к элементам карточки
var itemTemp: EditCoursesDoctorModel? =
null//Глобальная переменная для нашего item, чтобы можно было передать данные для нажатия
//init - дает возможность внутри адаптера обращаться к элементам экрана
init {
binding.btnYeyNo.setOnClickListener {//Нажатие на ячейку//itemView - это весь элемент карточки из списка
itemTemp?.let { it1 -> listener_sport.onClickCoursesYour(it1) }
}
}
@SuppressLint("SuspiciousIndentation")
fun bind(item: EditCoursesDoctorModel) = with(binding) {//Productitem - перпедаем данные
itemTemp = item
txtNumber.text = item.number.toString()+"."
txtNameSport.text = item.name
txtDescriptionSport.text = item.description
if (item.expand) {
binding.txtDescriptionSport.maxLines = 100
} else {
binding.txtDescriptionSport.maxLines = 1
}
binding.CardViewOld.setOnClickListener {
if (item.expand == false) {
binding.txtDescriptionSport.maxLines = 100
item.expand = true
} else {
binding.txtDescriptionSport.maxLines = 1
item.expand = false
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_edit_sport_no, parent, false)//Создаем(надуваем) list_item
return Holder(view, listener_sport)//Через Holder возврощаем view
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val view = holder.bind(getItem(position))//Заполняем по позиции карточку
}
//Comparator - сравнивает старый список и новый и если что-то изменилось, то работает с конкретным изменением списке, а не весь список переписывает
class Comparator : DiffUtil.ItemCallback<EditCoursesDoctorModel>() {
override fun areItemsTheSame(
oldItem: EditCoursesDoctorModel,
newItem: EditCoursesDoctorModel
): Boolean {//Тут лучше всего сравнивать по id//oldItem - элементы старого списка, newItem - элементы нового списка//Возврощает Boolean, тоесть есть изменения или нет
return oldItem.id == newItem.id//Сравниваем полностью весь список новы и старый, по очередно по одной карточке и по элементно, то есть нулевой элемент, первый, второй и т.д.. Но лучше сравнивать по id списки, а не просто весь список, так как это эфективнее, так как id уникальный(oldItem.id == newItem.id)
}
override fun areContentsTheSame(
oldItem: EditCoursesDoctorModel,
newItem: EditCoursesDoctorModel
): Boolean {//Утут нужно сравнивать весь спсок старых элементов и новых
return oldItem == newItem//Сравниваем полностью весь список новы и старый
}
}
//Интерфейс нажатия на кнопку удалить товар из корзины
interface Listener {
fun onClickCoursesYour(item: EditCoursesDoctorModel)
}
}

View File

@ -0,0 +1,292 @@
package com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.example.doctor.Auth.AuthActivity
import com.example.doctor.CodeError.Code429Activity
import com.example.doctor.CodeError.Code500Activity
import com.example.doctor.DoctorViewModel
import com.example.doctor.Enternet.EnternetActivity
import com.example.doctor.Enternet.EnternetFragment
import com.example.doctor.Pref.ClearPref
import com.example.doctor.Pref.ConclusionPref
import com.example.doctor.Pref.SavePref
import com.example.doctor.R
import com.example.doctor.Retrofit.DoctorApi
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Adapter.EditCoursesDoctorAllAdapter
import com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model.EditCoursesDoctorModel
import com.example.doctor.Toast.showCustomInfoToast
import com.example.doctor.databinding.FragmentAllSportCoursesDoctorBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class AllSportCoursesDoctorFragment : Fragment(), EditCoursesDoctorAllAdapter.Listener{
private lateinit var binding:FragmentAllSportCoursesDoctorBinding
lateinit var adapterAll: EditCoursesDoctorAllAdapter
private lateinit var doctorApi: DoctorApi
private val model: DoctorViewModel by activityViewModels()
val prefDoctorConclusion = ConclusionPref()
val prefDoctorClear = ClearPref()
val prefDoctorSave = SavePref()
var id_patient = 0;
var id_courses = 0;
var id_activitis = 0;
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentAllSportCoursesDoctorBinding.inflate(layoutInflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRcView()
// id_courses = prefDoctorConclusion.conclusionIdCourses(requireContext())
// id_activitis = prefDoctorConclusion.conclusionIdActivitis(requireContext())
model.CoursesCustomDoctor.observe(viewLifecycleOwner){
id_courses = it.id
id_activitis = it.id_activity
GetEditCourseDoctorAll(id_courses)
}
model.EditCoursesDoctorAllList.observe(viewLifecycleOwner){
adapterAll.submitList(it)
}
// model.CoursesDoctorCA.observe(viewLifecycleOwner){
// requireActivity().runOnUiThread {
// id_courses = it.id_courses
// id_activitis = it.id_activitis
// }
// }
Log.i("2sadas","2sadasd")
}
override fun onResume() {
super.onResume()
Log.i("2sadas","22sadasd")
}
//Получения списка курсов созданных доктором
fun GetEditCourseDoctorAll(id:Int) {
if (isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetEditCourseDoctorAll("Bearer $Tokens",id)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctor.body()
val Nice = listCoursesDoctor.isSuccessful
val Code = listCoursesDoctor.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
//Если нету ошибок
if (List != null) {
model.EditCoursesDoctorAllList.value = List.set_of_sports_exercises_all
binding.txtNull.visibility = View.GONE
}
else{
binding.txtNull.visibility = View.VISIBLE
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Получения списка курсов созданных доктором
fun GetEditCourseDoctorYour(id:Int) {
if (isOnline(requireContext())) {
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctor = doctorApi.GetEditCourseDoctorYour("Bearer $Tokens",id)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val CoursesDoctorList = listCoursesDoctor.body()
//Если нету ошибок
if (CoursesDoctorList != null) {
model.EditCoursesDoctorYourList.value = CoursesDoctorList.set_of_sports_exercises_your
}
}
}
} else {
val intetn = Intent(requireContext(), EnternetActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
//Добавление упражнения в курс
fun AddCoursesCreatingDoctor(id:Int,id_activitis:Int) {
if (isOnline(requireContext())) {
initRetrofit()
val Tokens = prefDoctorConclusion.conclusionToken(requireContext())
CoroutineScope(Dispatchers.IO).launch {
val listCoursesDoctorAllAdd = doctorApi.AddCoursesCreatingDoctor("Bearer $Tokens",id,id_activitis)
requireActivity().runOnUiThread {
//Фиксируем полученные данные
val List = listCoursesDoctorAllAdd.body()
val Nice = listCoursesDoctorAllAdd.isSuccessful
val Code = listCoursesDoctorAllAdd.code()
if(Code==429){
val intetn = Intent(requireContext(), Code429Activity::class.java)
startActivity(intetn)
}
else if(Code==200) {
//Если нету ошибок
if (Nice) {
if (List != null) {
Toast(requireContext()).showCustomInfoToast(List.message, requireActivity())
GetEditCourseDoctorAll(id_courses)
GetEditCourseDoctorYour(id_courses)
}
}
}
else if (Code == 500) {
val intetn = Intent(requireContext(), Code500Activity::class.java)
startActivity(intetn)
}
else if (Code == 401) {
val intetn = Intent(requireContext(), AuthActivity::class.java)
activity?.finish()
startActivity(intetn)
}
}
}
} else {
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.CLMain, EnternetFragment.newInstance())
?.commit()
}
}
//Инициализируем Retrofit
private fun initRetrofit() {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
val client = OkHttpClient
.Builder()
.addInterceptor(interceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://rehabilitation.vmeda.org/api/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
doctorApi = retrofit.create(DoctorApi::class.java)
}
//Проверка интернета
fun isOnline(context: Context): Boolean {
if (context == null) return false
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val capabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
if (capabilities != null) {
when {
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> {
return true
}
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> {
return true
}
}
}
} else {
val activeNetworkInfo = connectivityManager.activeNetworkInfo
if (activeNetworkInfo != null && activeNetworkInfo.isConnected) {
return true
}
}
return false
}
//Инициализация списка
private fun initRcView() = with(binding) {
rcView.layoutManager = GridLayoutManager(requireContext(), 1)//По вертикали будет выводить по умолчанию
adapterAll = EditCoursesDoctorAllAdapter(this@AllSportCoursesDoctorFragment)
rcView.adapter = adapterAll
}
companion object {
fun newInstance() = AllSportCoursesDoctorFragment()
}
override fun onClickCoursesAll(item: EditCoursesDoctorModel) {
AddCoursesCreatingDoctor(item.id,id_activitis)
}
}

View File

@ -0,0 +1,8 @@
package com.example.doctor.Setting.Courses.EditCourses.TabLayoutEditCourses.Model
data class CoursesDoctorCA(
val id_courses: Int,
val id_activitis: Int,
)

Some files were not shown because too many files have changed in this diff Show More