Initialize navigation with AuthenticationFragment

Also remove unused MainFragment-related code
This commit is contained in:
Kirill Kamakin
2021-11-06 23:01:02 +03:00
parent b4db681747
commit 645b676cdf
7 changed files with 66 additions and 58 deletions

View File

@@ -1,18 +1,13 @@
package gq.kirmanak.mealie package gq.kirmanak.mealie
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import gq.kirmanak.mealie.ui.main.MainFragment import androidx.appcompat.app.AppCompatActivity
import gq.kirmanak.mealie.databinding.MainActivityBinding
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity) val binding = MainActivityBinding.inflate(layoutInflater)
if (savedInstanceState == null) { setContentView(binding.root)
supportFragmentManager.beginTransaction()
.replace(R.id.container, MainFragment.newInstance())
.commitNow()
}
} }
} }

View File

@@ -0,0 +1,28 @@
package gq.kirmanak.mealie.ui.auth
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import gq.kirmanak.mealie.databinding.FragmentAuthenticationBinding
class AuthenticationFragment : Fragment() {
private var _binding: FragmentAuthenticationBinding? = null
private val binding: FragmentAuthenticationBinding
get() = checkNotNull(_binding) { "Binding requested when fragment is off screen" }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentAuthenticationBinding.inflate(inflater, container, false)
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

View File

@@ -1,32 +0,0 @@
package gq.kirmanak.mealie.ui.main
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import gq.kirmanak.mealie.R
class MainFragment : Fragment() {
companion object {
fun newInstance() = MainFragment()
}
private lateinit var viewModel: MainViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.main_fragment, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
// TODO: Use the ViewModel
}
}

View File

@@ -1,7 +0,0 @@
package gq.kirmanak.mealie.ui.main
import androidx.lifecycle.ViewModel
class MainViewModel : ViewModel() {
// TODO: Implement the ViewModel
}

View File

@@ -2,19 +2,19 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.main.MainFragment"> tools:context=".ui.auth.AuthenticationFragment">
<!-- TODO implement correct authentication screen -->
<TextView <TextView
android:id="@+id/message" android:id="@+id/textView"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="0dp"
android:text="MainFragment" android:gravity="center"
android:text="@string/app_name"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,7 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <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" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" /> tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,11 @@
<?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"
android:id="@+id/nav_graph"
app:startDestination="@id/authenticationFragment">
<fragment
android:id="@+id/authenticationFragment"
android:name="gq.kirmanak.mealie.ui.auth.AuthenticationFragment"
android:label="AuthenticationFragment" />
</navigation>