Skip to content

Commit

Permalink
Merge pull request #20 from DavayPosmotrim/8_navigation
Browse files Browse the repository at this point in the history
8 navigation
  • Loading branch information
n-shvedov27 authored May 2, 2024
2 parents c5c0914 + f07f0f2 commit d149c1b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:theme="@style/Theme.DavayPosmotrim"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".app.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.davay.android
package com.davay.android.app

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.fragment.NavHostFragment
import com.davay.android.R
import com.davay.android.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
Expand All @@ -11,5 +13,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(binding.root)
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragment_container_view) as NavHostFragment
val navController = navHostFragment.navController
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.davay.android.feature.load.presentation

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.davay.android.databinding.FragmentLoadBinding

class LoadFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return FragmentLoadBinding.inflate(inflater, container, false).root
}
}
21 changes: 10 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".app.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_navigation_graph" />

</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
18 changes: 18 additions & 0 deletions app/src/main/res/layout/fragment_load.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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=".feature.load.presentation.LoadFragment">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Fragment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/navigation/main_navigation_graph.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/main_navigation_graph"
app:startDestination="@id/loadFragment">

<fragment
android:id="@+id/loadFragment"
android:name="com.davay.android.feature.load.presentation.LoadFragment"
android:label="fragment_load"
tools:layout="@layout/fragment_load" />
</navigation>

0 comments on commit d149c1b

Please sign in to comment.