Add a navigation to the commit activity

main
Clément FRÉVILLE 2 years ago
parent 35462dfe00
commit 7a0acc9a2b

@ -1,11 +1,11 @@
package fr.uca.iut.clfreville2.teaiswarm
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import androidx.fragment.app.commit
import androidx.navigation.fragment.NavHostFragment
import fr.uca.iut.clfreville2.teaiswarm.fragment.RepositoryListFragment
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
@ -20,17 +20,16 @@ class MainActivity : AppCompatActivity() {
}
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportFragmentManager.commit {
setReorderingAllowed(true)
replace(R.id.fragment_container_view, RepositoryListFragment::class.java, null)
}
}
private fun adapterOnClick(repository: Repository) {
val intent = Intent(this, RepositoryDetailActivity()::class.java)
intent.putExtra(REPOSITORY_OWNER, repository.owner.login)
intent.putExtra(REPOSITORY_NAME, repository.name)
startActivity(intent)
val bundle =
bundleOf(
REPOSITORY_OWNER to repository.owner.login,
REPOSITORY_NAME to repository.name
)
val nav = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
nav.navController.navigate(R.id.activity_list_fragment, bundle)
}
class RepositoryListFragmentFactory(private val onClick: (Repository) -> Unit) : FragmentFactory() {

@ -15,6 +15,8 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import fr.uca.iut.clfreville2.teaiswarm.R
import fr.uca.iut.clfreville2.teaiswarm.REPOSITORY_NAME
import fr.uca.iut.clfreville2.teaiswarm.REPOSITORY_OWNER
import fr.uca.iut.clfreville2.teaiswarm.model.CommitActivity
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifier
import fr.uca.iut.clfreville2.teaiswarm.network.GiteaService
@ -32,6 +34,10 @@ class ActivityListFragment : Fragment(R.layout.activity_list) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
repository = RepositoryIdentifier(
requireArguments().getString(REPOSITORY_OWNER)!!,
requireArguments().getString(REPOSITORY_NAME)!!
)
updateCommits()
}
@ -101,14 +107,17 @@ class ActivityListFragment : Fragment(R.layout.activity_list) {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private val commitNameView: TextView
private val commitAuthorView: TextView
init {
commitNameView = view.findViewById(R.id.commit_name)
commitAuthorView = view.findViewById(R.id.commit_author)
}
fun bind(commit: CommitActivity?) {
commit?.let {
commitNameView.text = it.commit.message
commitAuthorView.text = it.commit.author.name
}
}
}

@ -7,7 +7,14 @@
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container_view" />
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
</LinearLayout>

@ -1,9 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingHorizontal="@dimen/row_item_margin_horizontal"
android:paddingTop="@dimen/row_item_margin_vertical">
<TextView
android:id="@+id/commit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commit_name" />
</LinearLayout>
android:textColor="?android:textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/commit_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:paddingVertical="@dimen/row_item_margin_vertical"
android:text="@string/unknown"
android:textSize="@dimen/repo_description_size"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/commit_name" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,19 @@
<?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/repository_ist_fragment">
<fragment
android:id="@+id/repository_ist_fragment"
android:name="fr.uca.iut.clfreville2.teaiswarm.fragment.RepositoryListFragment"
android:label="RepositoryListFragment" >
<action
android:id="@+id/action_repositoryListFragment_to_activityListFragment3"
app:destination="@id/activity_list_fragment" />
</fragment>
<fragment
android:id="@+id/activity_list_fragment"
android:name="fr.uca.iut.clfreville2.teaiswarm.fragment.ActivityListFragment"
android:label="ActivityListFragment" />
</navigation>
Loading…
Cancel
Save