Skip to content

Commit

Permalink
#Resolve conflict with main by adding NetworkFragment instead using i…
Browse files Browse the repository at this point in the history
…ts utilities on mainActivity#Adding SubscribeNotificationFragment, AddNotificationFragment, PastUserActionsFragment#Convert hard-coded strings as strings.xml resource for make them translatable later#
  • Loading branch information
egecan.serbester committed Oct 17, 2023
1 parent ceeeca2 commit dd7cbdf
Show file tree
Hide file tree
Showing 32 changed files with 329 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import com.example.disasterresponseplatform.ui.HomePageFragment
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private var homePageFragment = HomePageFragment()
private lateinit var homePageFragment: HomePageFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
//instead setContentView(R.layout.activity_main) doing that with binding
setContentView(binding.root)
homePageFragment = HomePageFragment(this)
replaceFragment(homePageFragment)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentTransaction
import com.example.disasterresponseplatform.MainActivity
import com.example.disasterresponseplatform.R
import com.example.disasterresponseplatform.databinding.FragmentHomePageBinding
import com.example.disasterresponseplatform.ui.activity.ActivityFragment
import com.example.disasterresponseplatform.ui.map.MapFragment
import com.example.disasterresponseplatform.ui.network.NetworkFragment
import com.example.disasterresponseplatform.ui.profile.ProfileFragment
import com.example.disasterresponseplatform.ui.registration.LoginFragment
import com.example.disasterresponseplatform.ui.authentication.LoginFragment


class HomePageFragment : Fragment() {
class HomePageFragment(val mainActivity: MainActivity) : Fragment() {

private lateinit var binding: FragmentHomePageBinding
private lateinit var networkFragment: NetworkFragment

private val loginFragment = LoginFragment()
private val mapFragment = MapFragment()
private val activityFragment = ActivityFragment()
Expand Down Expand Up @@ -59,6 +63,10 @@ class HomePageFragment : Fragment() {
binding.btProfile.setOnClickListener {
addFragment(profileFragment)
}
binding.btNetwork.setOnClickListener {
networkFragment = NetworkFragment(mainActivity)
addFragment(networkFragment)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.disasterresponseplatform.ui.registration
package com.example.disasterresponseplatform.ui.authentication

import androidx.fragment.app.Fragment
import com.example.disasterresponseplatform.R
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.disasterresponseplatform.ui.registration
package com.example.disasterresponseplatform.ui.authentication

import android.os.Bundle
import androidx.fragment.app.Fragment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.disasterresponseplatform.ui.registration
package com.example.disasterresponseplatform.ui.authentication

import android.graphics.Color
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.disasterresponseplatform.ui.registration
package com.example.disasterresponseplatform.ui.authentication

import android.graphics.Color
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.example.disasterresponseplatform.ui.network

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 com.example.disasterresponseplatform.MainActivity
import com.example.disasterresponseplatform.R
import com.example.disasterresponseplatform.databinding.FragmentNetworkBinding
import com.example.disasterresponseplatform.managers.DataResponse
import com.example.disasterresponseplatform.managers.NetworkManager
import com.example.disasterresponseplatform.models.enums.Endpoint
import com.example.disasterresponseplatform.models.enums.RequestType
import retrofit2.Call
import retrofit2.Response


class NetworkFragment(val mainActivity: MainActivity) : Fragment() {

private lateinit var binding: FragmentNetworkBinding

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentNetworkBinding.inflate(inflater,container,false)
// Inflate the layout for this fragment
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
clickButton()
}

private fun clickButton(){
binding.btNetwork.setOnClickListener {
// Handle the button click event

val networkManager = NetworkManager()

val headers = mapOf("Authorization" to "Bearer YOUR_TOKEN")

networkManager.makeRequest(
endpoint = Endpoint.DATA,
requestType = RequestType.GET, // Specify the type of request here
headers = headers,
callback = object : retrofit2.Callback<DataResponse> {
override fun onFailure(call: Call<DataResponse>, t: Throwable) {
Toast.makeText(mainActivity, "Network error: ${t.message}", Toast.LENGTH_SHORT).show()
}

override fun onResponse(call: Call<DataResponse>, response: Response<DataResponse>) {
if (response.isSuccessful) {
Toast.makeText(mainActivity, "Status Code: ${response.code()}, Successful Response!", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(mainActivity, "Status Code: ${response.code()}, Error Message: ${response.message()}", Toast.LENGTH_SHORT).show()
}
}
}
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentTransaction
import com.example.disasterresponseplatform.R
import com.example.disasterresponseplatform.databinding.FragmentProfileBinding
import com.example.disasterresponseplatform.ui.profile.notification.SubscribeNotificationFragment
import com.example.disasterresponseplatform.ui.profile.pastUserActions.PastUserActionsFragment


class ProfileFragment : Fragment() {

private lateinit var binding: FragmentProfileBinding
private val pastUserActionsFragment = PastUserActionsFragment()
private val subscribeNotificationFragment = SubscribeNotificationFragment()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -23,7 +29,23 @@ class ProfileFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
clickButtons()
}

private fun clickButtons(){
binding.btUserActivities.setOnClickListener {
addFragment(pastUserActionsFragment)
}
binding.btSubscribedNotification.setOnClickListener {
addFragment(subscribeNotificationFragment)
}
}

private fun addFragment(fragment: Fragment) {
val ft: FragmentTransaction = parentFragmentManager.beginTransaction()
ft.replace(R.id.container, fragment)
ft.addToBackStack(null)
ft.commit()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.disasterresponseplatform.ui.profile.notification

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.disasterresponseplatform.R


class AddNotificationFragment : Fragment(R.layout.fragment_add_notification)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.disasterresponseplatform.ui.profile.notification

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.FragmentTransaction
import com.example.disasterresponseplatform.R
import com.example.disasterresponseplatform.databinding.FragmentSubscribeNotificationBinding


class SubscribeNotificationFragment : Fragment() {

private lateinit var binding: FragmentSubscribeNotificationBinding
private val addNotificationFragment = AddNotificationFragment()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentSubscribeNotificationBinding.inflate(inflater,container,false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
clickButtons()
}

private fun clickButtons(){
binding.btAddNotification.setOnClickListener {
addFragment(addNotificationFragment)
}
}

private fun addFragment(fragment: Fragment) {
val ft: FragmentTransaction = parentFragmentManager.beginTransaction()
ft.replace(R.id.container, fragment)
ft.addToBackStack(null)
ft.commit()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.disasterresponseplatform.ui.profile.pastUserActions

import androidx.fragment.app.Fragment
import com.example.disasterresponseplatform.R

class PastUserActionsFragment : Fragment(R.layout.fragment_past_user_actions)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/btAddAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Action"
android:text="@string/add_action"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:id="@+id/tvAddAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Action Page"
android:text="@string/add_action_page"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/tvAddEmergency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Emergency Page"
android:text="@string/add_emergency_page"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/tvAddEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Event Page"
android:text="@string/add_event_page"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:id="@+id/tvAddNeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Need Page"
android:text="@string/add_need_page"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.profile.notification.AddNotificationFragment">


<TextView
android:id="@+id/tvAddNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/adding_notification_page"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:id="@+id/tvAddResource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Resource Page"
android:text="@string/add_resource_page"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.registration.ChangePasswordFragment">
tools:context=".ui.authentication.ChangePasswordFragment">


<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/btAddEmergency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Emergency"
android:text="@string/add_emergency"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
Expand All @@ -23,7 +23,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="Emergency List"
android:text="@string/emergency_list"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/btAddEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Event"
android:text="@string/add_event"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -20,7 +20,7 @@
android:id="@+id/tvEventList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event List"
android:text="@string/event_list"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.registration.ForgotPasswordFragment">
tools:context=".ui.authentication.ForgotPasswordFragment">


<TextView
Expand Down
Loading

0 comments on commit dd7cbdf

Please sign in to comment.