From 61dbab7d47bd242a7ca5971eb942ffb6f1ef1ae1 Mon Sep 17 00:00:00 2001 From: Shahzaib Ahmad Date: Fri, 7 Jul 2023 16:48:56 +0500 Subject: [PATCH] updated method of getting instance of firebase --- .idea/compiler.xml | 2 +- .idea/kotlinc.xml | 6 ++++++ .idea/misc.xml | 2 +- app/build.gradle | 6 ++++-- app/src/main/java/com/example/bustracking/Admin.kt | 4 +++- .../java/com/example/bustracking/AdminComplaintBox.kt | 4 +++- .../main/java/com/example/bustracking/ComplaintBox.kt | 4 +++- app/src/main/java/com/example/bustracking/Home.kt | 4 +++- .../main/java/com/example/bustracking/MapsActivity.kt | 4 +++- .../java/com/example/bustracking/RouteSchedule.kt | 4 +++- .../main/java/com/example/bustracking/StudentHome.kt | 4 +++- .../java/com/example/bustracking/UpdateSchedule.kt | 11 ++++++++++- .../java/com/example/bustracking/WriteComplain.kt | 4 +++- app/src/main/res/layout/activity_route_schedule.xml | 1 - app/src/main/res/layout/activity_update_schedule.xml | 6 ++++-- app/src/main/res/values/strings.xml | 2 +- 16 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 .idea/kotlinc.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b589d56 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..b1077fb --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 571724b..b3d1eee 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -34,7 +34,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 4a263ce..f0766d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,14 +47,16 @@ dependencies { // androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' // Firebase - implementation platform('com.google.firebase:firebase-bom:30.2.0') + implementation(platform("com.google.firebase:firebase-bom:32.1.1")) + implementation("com.google.firebase:firebase-database-ktx") implementation 'com.google.firebase:firebase-analytics-ktx' // Firebase Auth implementation 'com.google.firebase:firebase-auth-ktx:21.0.6' + + // Google play services for Google maps implementation 'com.google.android.gms:play-services-maps:18.0.2' - implementation 'com.google.firebase:firebase-database-ktx:20.0.5' // Getting current location implementation 'com.karumi:dexter:6.0.1' diff --git a/app/src/main/java/com/example/bustracking/Admin.kt b/app/src/main/java/com/example/bustracking/Admin.kt index 06c560a..828e9d9 100644 --- a/app/src/main/java/com/example/bustracking/Admin.kt +++ b/app/src/main/java/com/example/bustracking/Admin.kt @@ -13,6 +13,8 @@ import com.example.bustracking.databinding.ActivityAdminBinding import com.example.bustracking.modals.RVBusDriverModal import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.* +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class Admin : AppCompatActivity(), RecyclerAdapter.RecyclerAdapterInterface{ private lateinit var binding: ActivityAdminBinding @@ -34,7 +36,7 @@ class Admin : AppCompatActivity(), RecyclerAdapter.RecyclerAdapterInterface{ //! firebase initializations. mAuth = FirebaseAuth.getInstance() - firebaseDatabase = FirebaseDatabase.getInstance() + firebaseDatabase = Firebase.database databaseReference = firebaseDatabase.getReference("Locations") //! recycler View for bus drivers diff --git a/app/src/main/java/com/example/bustracking/AdminComplaintBox.kt b/app/src/main/java/com/example/bustracking/AdminComplaintBox.kt index 7480013..8373583 100644 --- a/app/src/main/java/com/example/bustracking/AdminComplaintBox.kt +++ b/app/src/main/java/com/example/bustracking/AdminComplaintBox.kt @@ -10,6 +10,8 @@ import com.example.bustracking.databinding.ActivityComplaintBoxBinding import com.example.bustracking.modals.ComplainModal import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.* +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class AdminComplaintBox : AppCompatActivity() { @@ -30,7 +32,7 @@ class AdminComplaintBox : AppCompatActivity() { complainModalArrayList = ArrayList() //! firebase - firebaseDatabase = FirebaseDatabase.getInstance() + firebaseDatabase = Firebase.database databaseReference = firebaseDatabase.getReference("Complains") //! Recycler View diff --git a/app/src/main/java/com/example/bustracking/ComplaintBox.kt b/app/src/main/java/com/example/bustracking/ComplaintBox.kt index 0cc6203..4fb1d0f 100644 --- a/app/src/main/java/com/example/bustracking/ComplaintBox.kt +++ b/app/src/main/java/com/example/bustracking/ComplaintBox.kt @@ -10,6 +10,8 @@ import com.example.bustracking.databinding.ActivityComplaintBoxBinding import com.example.bustracking.modals.ComplainModal import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.* +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class ComplaintBox : AppCompatActivity() { private lateinit var binding: ActivityComplaintBoxBinding @@ -45,7 +47,7 @@ class ComplaintBox : AppCompatActivity() { firebaseAuth = FirebaseAuth.getInstance() email = firebaseAuth.currentUser?.email.toString() username = email.split("@")[0] - firebaseDatabase = FirebaseDatabase.getInstance() + firebaseDatabase = Firebase.database databaseReference = firebaseDatabase.getReference("Complains") //! recyclerView diff --git a/app/src/main/java/com/example/bustracking/Home.kt b/app/src/main/java/com/example/bustracking/Home.kt index f2c4585..8a37560 100644 --- a/app/src/main/java/com/example/bustracking/Home.kt +++ b/app/src/main/java/com/example/bustracking/Home.kt @@ -21,6 +21,8 @@ import com.example.bustracking.modals.RVBusDriverModal import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase import com.karumi.dexter.Dexter import com.karumi.dexter.MultiplePermissionsReport import com.karumi.dexter.PermissionToken @@ -50,7 +52,7 @@ class Home : AppCompatActivity() { setContentView(binding.root) supportActionBar?.title = "Driver Home" mAuth = FirebaseAuth.getInstance() - databaseReference = FirebaseDatabase.getInstance().getReference("Locations") + databaseReference = Firebase.database.getReference("Locations") sharingLocation = false checkLocationSharing() diff --git a/app/src/main/java/com/example/bustracking/MapsActivity.kt b/app/src/main/java/com/example/bustracking/MapsActivity.kt index ec03b0a..8a53a9b 100644 --- a/app/src/main/java/com/example/bustracking/MapsActivity.kt +++ b/app/src/main/java/com/example/bustracking/MapsActivity.kt @@ -11,6 +11,8 @@ import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MarkerOptions import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.* +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class MapsActivity : AppCompatActivity(), OnMapReadyCallback { @@ -38,7 +40,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback { mapFragment.getMapAsync(this) mAuth = FirebaseAuth.getInstance() - databaseReference = FirebaseDatabase.getInstance().getReference("Locations") + databaseReference = Firebase.database.getReference("Locations") } diff --git a/app/src/main/java/com/example/bustracking/RouteSchedule.kt b/app/src/main/java/com/example/bustracking/RouteSchedule.kt index 05daa78..8223b22 100644 --- a/app/src/main/java/com/example/bustracking/RouteSchedule.kt +++ b/app/src/main/java/com/example/bustracking/RouteSchedule.kt @@ -5,6 +5,8 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.bustracking.databinding.ActivityRouteScheduleBinding import com.google.firebase.database.* +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class RouteSchedule : AppCompatActivity() { private lateinit var binding: ActivityRouteScheduleBinding @@ -17,7 +19,7 @@ class RouteSchedule : AppCompatActivity() { setContentView(binding.root) supportActionBar?.title = "Route Schedule" - databaseReference = FirebaseDatabase.getInstance().getReference("RouteSchedule") + databaseReference = Firebase.database.getReference("RouteSchedule") databaseReference.addValueEventListener( object: ValueEventListener { override fun onDataChange(snapshot: DataSnapshot) { diff --git a/app/src/main/java/com/example/bustracking/StudentHome.kt b/app/src/main/java/com/example/bustracking/StudentHome.kt index c754da6..c6e331d 100644 --- a/app/src/main/java/com/example/bustracking/StudentHome.kt +++ b/app/src/main/java/com/example/bustracking/StudentHome.kt @@ -13,6 +13,8 @@ import com.example.bustracking.databinding.ActivityStudentHomeBinding import com.example.bustracking.modals.RVBusDriverModal import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.* +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class StudentHome : AppCompatActivity(), RecyclerAdapter.RecyclerAdapterInterface { private lateinit var binding: ActivityStudentHomeBinding @@ -35,7 +37,7 @@ class StudentHome : AppCompatActivity(), RecyclerAdapter.RecyclerAdapterInterfac //! firebase Initializations mAuth = FirebaseAuth.getInstance() - firebaseDatabase = FirebaseDatabase.getInstance() + firebaseDatabase = Firebase.database databaseReference = firebaseDatabase.getReference("Locations") //! recycler View diff --git a/app/src/main/java/com/example/bustracking/UpdateSchedule.kt b/app/src/main/java/com/example/bustracking/UpdateSchedule.kt index 8488a78..7512aa0 100644 --- a/app/src/main/java/com/example/bustracking/UpdateSchedule.kt +++ b/app/src/main/java/com/example/bustracking/UpdateSchedule.kt @@ -1,12 +1,17 @@ package com.example.bustracking import android.os.Bundle +import android.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.bustracking.databinding.ActivityUpdateScheduleBinding import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase +import com.google.firebase.database.ktx.database +import com.google.firebase.database.ktx.snapshots +import com.google.firebase.database.ktx.values +import com.google.firebase.ktx.Firebase class UpdateSchedule : AppCompatActivity() { private lateinit var binding: ActivityUpdateScheduleBinding @@ -19,7 +24,11 @@ class UpdateSchedule : AppCompatActivity() { setContentView(binding.root) - databaseReference = FirebaseDatabase.getInstance().getReference("RouteSchedule") + databaseReference = Firebase.database.getReference("RouteSchedule") + databaseReference.get().addOnSuccessListener { + dataSnapshot -> + binding.etRouteSchedule.setText(dataSnapshot.value.toString()) + } binding.btnUpdate.setOnClickListener { if (binding.etRouteSchedule.text.toString().isEmpty()) { diff --git a/app/src/main/java/com/example/bustracking/WriteComplain.kt b/app/src/main/java/com/example/bustracking/WriteComplain.kt index 5973da4..cf68f86 100644 --- a/app/src/main/java/com/example/bustracking/WriteComplain.kt +++ b/app/src/main/java/com/example/bustracking/WriteComplain.kt @@ -8,6 +8,8 @@ import com.example.bustracking.modals.ComplainModal import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase +import com.google.firebase.database.ktx.database +import com.google.firebase.ktx.Firebase class WriteComplain : AppCompatActivity() { private lateinit var binding: ActivityWriteComplainBinding @@ -25,7 +27,7 @@ class WriteComplain : AppCompatActivity() { supportActionBar?.title = "Write Complain" firebaseAuth = FirebaseAuth.getInstance() - firebaseDatabase = FirebaseDatabase.getInstance() + firebaseDatabase = Firebase.database databaseReference = firebaseDatabase.getReference("Complains") diff --git a/app/src/main/res/layout/activity_route_schedule.xml b/app/src/main/res/layout/activity_route_schedule.xml index bb9b130..64a3ce3 100644 --- a/app/src/main/res/layout/activity_route_schedule.xml +++ b/app/src/main/res/layout/activity_route_schedule.xml @@ -11,7 +11,6 @@ android:id="@+id/tvRouteSchedule" android:layout_width="match_parent" android:layout_height="match_parent" - android:text="@string/route_schedule" android:background="@drawable/et_background" android:layout_margin="40dp" android:textSize="16sp" diff --git a/app/src/main/res/layout/activity_update_schedule.xml b/app/src/main/res/layout/activity_update_schedule.xml index f4a5f3d..e6c1052 100644 --- a/app/src/main/res/layout/activity_update_schedule.xml +++ b/app/src/main/res/layout/activity_update_schedule.xml @@ -14,13 +14,15 @@ android:id="@+id/etRouteSchedule" android:layout_width="match_parent" android:layout_height="500dp" - android:text="@string/route_schedule" android:background="@drawable/et_background" android:layout_margin="30dp" android:textSize="16sp" android:padding="15dp" + android:hint="@string/add_schedule" android:gravity="top" - android:textColor="@color/black"/> + android:textColor="@color/black" + android:autofillHints="none" + android:inputType="textImeMultiLine|textMultiLine" />