-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mo/feature/nav route
- Loading branch information
Showing
49 changed files
with
1,484 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 36 additions & 36 deletions
72
...erResponsePlatform/app/src/main/java/com/example/disasterresponseplatform/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
package com.example.disasterresponseplatform | ||
|
||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
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 | ||
|
||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentTransaction | ||
import com.example.disasterresponseplatform.databinding.ActivityMainBinding | ||
import com.example.disasterresponseplatform.ui.HomePageFragment | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityMainBinding | ||
private lateinit var homePageFragment: HomePageFragment | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
val button: Button = findViewById(R.id.myButton) | ||
|
||
button.setOnClickListener { | ||
// Handle the button click event | ||
binding = ActivityMainBinding.inflate(layoutInflater) | ||
//instead setContentView(R.layout.activity_main) doing that with binding | ||
setContentView(binding.root) | ||
homePageFragment = HomePageFragment(this) | ||
replaceFragment(homePageFragment) | ||
} | ||
|
||
val networkManager = NetworkManager() | ||
|
||
val headers = mapOf("Authorization" to "Bearer YOUR_TOKEN") | ||
/** This adds fragments to the back stack, in this way user can return this fragment after the view has been changed. | ||
* and replace fragment. | ||
*/ | ||
fun addFragment(fragment: Fragment) { | ||
val ft: FragmentTransaction = supportFragmentManager.beginTransaction() | ||
ft.replace(R.id.container, fragment) | ||
ft.addToBackStack(null) | ||
ft.commit() | ||
} | ||
|
||
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(this@MainActivity, "Network error: ${t.message}", Toast.LENGTH_SHORT).show() | ||
} | ||
/** | ||
* This pops the fragment from fragment stack | ||
*/ | ||
fun popFragment() { | ||
supportFragmentManager.popBackStack() | ||
} | ||
|
||
override fun onResponse(call: Call<DataResponse>, response: Response<DataResponse>) { | ||
if (response.isSuccessful) { | ||
Toast.makeText(this@MainActivity, "Status Code: ${response.code()}, Successful Response!", Toast.LENGTH_SHORT).show() | ||
} else { | ||
Toast.makeText(this@MainActivity, "Status Code: ${response.code()}, Error Message: ${response.message()}", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} | ||
) | ||
/** | ||
* This is for replacing the fragment without adding it to the stack | ||
* .apply means ft. in addFragment | ||
*/ | ||
fun replaceFragment(fragment: Fragment) { | ||
supportFragmentManager.beginTransaction().apply { | ||
replace(R.id.container, fragment) //replacing fragment | ||
commit() //call signals to the FragmentManager that all operations have been added to the transaction | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...nsePlatform/app/src/main/java/com/example/disasterresponseplatform/ui/HomePageFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.example.disasterresponseplatform.ui | ||
|
||
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.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.authentication.LoginFragment | ||
|
||
|
||
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() | ||
private val profileFragment = ProfileFragment() | ||
|
||
/** | ||
* This defines the layout | ||
*/ | ||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentHomePageBinding.inflate(inflater,container,false) | ||
return binding.root | ||
} | ||
|
||
/** | ||
* This defines what this fragment will be do when your view is Created ( n the screen) | ||
* like onCreate method of activities | ||
*/ | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
clickButtons() | ||
} | ||
|
||
/** | ||
* This defines what buttons will do when they are clicked, you can do that easily by observing it | ||
* with setOnClickListener method. | ||
*/ | ||
private fun clickButtons(){ | ||
binding.btLogin.setOnClickListener { | ||
addFragment(loginFragment) | ||
} | ||
binding.btMap.setOnClickListener { | ||
addFragment(mapFragment) | ||
} | ||
binding.btActivity.setOnClickListener { | ||
addFragment(activityFragment) | ||
} | ||
binding.btProfile.setOnClickListener { | ||
addFragment(profileFragment) | ||
} | ||
binding.btNetwork.setOnClickListener { | ||
networkFragment = NetworkFragment(mainActivity) | ||
addFragment(networkFragment) | ||
} | ||
} | ||
|
||
/** | ||
* This method adds a fragment to parentFragmentManager which is our FragmentManager on MainActivity. | ||
* It can do that by adding a backStack | ||
*/ | ||
private fun addFragment(fragment: Fragment) { | ||
val ft: FragmentTransaction = parentFragmentManager.beginTransaction() | ||
ft.replace(R.id.container, fragment) | ||
ft.addToBackStack(null) | ||
ft.commit() | ||
} | ||
|
||
/** | ||
* This method can be used for back buttons. It pop one fragment from backStack | ||
*/ | ||
fun popFragment() { | ||
parentFragmentManager.popBackStack() | ||
} | ||
|
||
/** | ||
* This method only replace a fragment, because it doesn't add anything on backStack | ||
*/ | ||
fun replaceFragment(fragment: Fragment) { | ||
parentFragmentManager.beginTransaction().apply { | ||
replace(R.id.container, fragment) //replacing fragment | ||
commit() //call signals to the FragmentManager that all operations have been added to the transaction | ||
} | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...rm/app/src/main/java/com/example/disasterresponseplatform/ui/activity/ActivityFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.example.disasterresponseplatform.ui.activity | ||
|
||
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.FragmentActivityBinding | ||
import com.example.disasterresponseplatform.ui.activity.action.ActionFragment | ||
import com.example.disasterresponseplatform.ui.activity.emergency.EmergencyFragment | ||
import com.example.disasterresponseplatform.ui.activity.event.EventFragment | ||
import com.example.disasterresponseplatform.ui.activity.need.NeedFragment | ||
import com.example.disasterresponseplatform.ui.activity.resource.ResourceFragment | ||
|
||
class ActivityFragment : Fragment() { | ||
|
||
private lateinit var binding: FragmentActivityBinding | ||
private val emergencyFragment = EmergencyFragment() | ||
private val actionFragment = ActionFragment() | ||
private val eventFragment = EventFragment() | ||
private val needFragment = NeedFragment() | ||
private val resourceFragment = ResourceFragment() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentActivityBinding.inflate(inflater,container,false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.btEmergency.setOnClickListener { | ||
addFragment(emergencyFragment) | ||
} | ||
binding.btAction.setOnClickListener { | ||
addFragment(actionFragment) | ||
} | ||
binding.btEvent.setOnClickListener { | ||
addFragment(eventFragment) | ||
} | ||
binding.btNeed.setOnClickListener { | ||
addFragment(needFragment) | ||
} | ||
binding.btResource.setOnClickListener { | ||
addFragment(resourceFragment) | ||
} | ||
} | ||
|
||
private fun addFragment(fragment: Fragment) { | ||
val ft: FragmentTransaction = parentFragmentManager.beginTransaction() | ||
ft.replace(R.id.container, fragment) | ||
ft.addToBackStack(null) | ||
ft.commit() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...p/src/main/java/com/example/disasterresponseplatform/ui/activity/action/ActionFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.disasterresponseplatform.ui.activity.action | ||
|
||
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.FragmentActionBinding | ||
|
||
class ActionFragment : Fragment() { | ||
|
||
private lateinit var binding: FragmentActionBinding | ||
private val addActionFragment = AddActionFragment() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentActionBinding.inflate(inflater,container,false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.btAddAction.setOnClickListener { | ||
addFragment(addActionFragment) | ||
} | ||
} | ||
|
||
private fun addFragment(fragment: Fragment) { | ||
val ft: FragmentTransaction = parentFragmentManager.beginTransaction() | ||
ft.replace(R.id.container, fragment) | ||
ft.addToBackStack(null) | ||
ft.commit() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rc/main/java/com/example/disasterresponseplatform/ui/activity/action/AddActionFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.disasterresponseplatform.ui.activity.action | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.example.disasterresponseplatform.R | ||
|
||
|
||
class AddActionFragment : Fragment(R.layout.fragment_add_action) |
7 changes: 7 additions & 0 deletions
7
...n/java/com/example/disasterresponseplatform/ui/activity/emergency/AddEmergencyFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.disasterresponseplatform.ui.activity.emergency | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.example.disasterresponseplatform.R | ||
|
||
|
||
class AddEmergencyFragment : Fragment(R.layout.fragment_add_emergency) |
38 changes: 38 additions & 0 deletions
38
...main/java/com/example/disasterresponseplatform/ui/activity/emergency/EmergencyFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.disasterresponseplatform.ui.activity.emergency | ||
|
||
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.FragmentEmergencyBinding | ||
|
||
class EmergencyFragment : Fragment() { | ||
|
||
private lateinit var binding: FragmentEmergencyBinding | ||
private val addEmergencyFragment = AddEmergencyFragment() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentEmergencyBinding.inflate(inflater,container,false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.btAddEmergency.setOnClickListener { | ||
addFragment(addEmergencyFragment) | ||
} | ||
} | ||
|
||
private fun addFragment(fragment: Fragment) { | ||
val ft: FragmentTransaction = parentFragmentManager.beginTransaction() | ||
ft.replace(R.id.container, fragment) | ||
ft.addToBackStack(null) | ||
ft.commit() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../src/main/java/com/example/disasterresponseplatform/ui/activity/event/AddEventFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.disasterresponseplatform.ui.activity.event | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.example.disasterresponseplatform.R | ||
|
||
class AddEventFragment : Fragment(R.layout.fragment_add_event) |
Oops, something went wrong.