-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a feature to dispose recyclers without any hussle
- Loading branch information
FunkyMuse
committed
Feb 15, 2021
1 parent
3b04c96
commit aea261e
Showing
21 changed files
with
274 additions
and
8 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
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
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/crazylegend/setofusefulkotlinextensions/nav/NavActivity.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,71 @@ | ||
package com.crazylegend.setofusefulkotlinextensions.nav | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.LiveData | ||
import androidx.navigation.NavController | ||
import com.crazylegend.navigation.setupWithNavController | ||
import com.crazylegend.setofusefulkotlinextensions.R | ||
import com.crazylegend.setofusefulkotlinextensions.databinding.ActivityNavBinding | ||
import com.crazylegend.viewbinding.viewBinder | ||
|
||
/** | ||
* Created by Hristijan, date 2/15/21 | ||
*/ | ||
class NavActivity : AppCompatActivity() { | ||
private var currentNavController: LiveData<NavController>? = null | ||
|
||
private val binding by viewBinder(ActivityNavBinding::inflate) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
if (savedInstanceState == null) { | ||
setupBottomNavigationBar() | ||
} // Else, need to wait for onRestoreInstanceState | ||
} | ||
|
||
@SuppressLint("ResourceType") | ||
private fun setupBottomNavigationBar() { | ||
|
||
val navGraphIds = listOf( | ||
R.navigation.test01, | ||
R.navigation.test02, | ||
R.navigation.test03, | ||
R.navigation.test04, | ||
R.navigation.test05) | ||
// Setup the bottom navigation view with a list of navigation graphs | ||
|
||
val controller = binding.bottomNav.setupWithNavController( | ||
navGraphIds = navGraphIds, | ||
fragmentManager = supportFragmentManager, | ||
containerId = R.id.fragmentContainer, | ||
intent = intent, | ||
R.anim.nav_default_enter_anim, | ||
R.anim.nav_default_exit_anim, | ||
R.anim.nav_default_pop_enter_anim, | ||
R.anim.nav_default_pop_exit_anim | ||
) | ||
|
||
// Whenever the selected controller changes, setup the action bar. | ||
controller.observe(this) { navController -> | ||
listenToDestinationChanges(navController) | ||
} | ||
currentNavController = controller | ||
|
||
} | ||
|
||
private fun listenToDestinationChanges(navController: NavController?) { | ||
navController ?: return | ||
|
||
} | ||
|
||
override fun onRestoreInstanceState(savedInstanceState: Bundle) { | ||
super.onRestoreInstanceState(savedInstanceState) | ||
setupBottomNavigationBar() | ||
} | ||
|
||
|
||
override fun onSupportNavigateUp() = currentNavController?.value?.navigateUp() ?: false | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/crazylegend/setofusefulkotlinextensions/nav/TestFragment.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,32 @@ | ||
package com.crazylegend.setofusefulkotlinextensions.nav | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
import com.crazylegend.customviews.databinding.CustomizableCardViewBinding | ||
import com.crazylegend.kotlinextensions.collections.generateRandomStringList | ||
import com.crazylegend.recyclerview.generateRecyclerWithHolder | ||
import com.crazylegend.setofusefulkotlinextensions.R | ||
import com.crazylegend.setofusefulkotlinextensions.databinding.FragmentTestBinding | ||
import com.crazylegend.viewbinding.viewBinding | ||
|
||
/** | ||
* Created by Hristijan, date 2/15/21 | ||
*/ | ||
class TestFragment : Fragment(R.layout.fragment_test) { | ||
|
||
private val binding by viewBinding(FragmentTestBinding::bind) | ||
|
||
private val testAdapter by lazy { | ||
generateRecyclerWithHolder<String, CustomizableCardViewBinding>(CustomizableCardViewBinding::inflate){ | ||
item, position, _, binding, _ -> | ||
binding.title.text = "Title ${position+1}" | ||
binding.content.text = item | ||
} | ||
} | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.recycler.adapter = testAdapter | ||
testAdapter.submitList(generateRandomStringList(100)) | ||
} | ||
} |
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,31 @@ | ||
<?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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/fragmentContainer" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_above="@id/bottomNav" | ||
android:layout_margin="0dp" | ||
app:layout_constraintBottom_toTopOf="@+id/bottomNav" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.google.android.material.bottomnavigation.BottomNavigationView | ||
android:id="@+id/bottomNav" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
app:elevation="15dp" | ||
app:itemIconTint="@color/colorAccent" | ||
app:labelVisibilityMode="selected" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:menu="@menu/bottom_nav_menu" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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,13 @@ | ||
<?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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recycler" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<item | ||
android:id="@+id/test01" | ||
android:title="1" /> | ||
<item | ||
android:id="@+id/test02" | ||
android:title="2" /> | ||
<item | ||
android:id="@+id/test03" | ||
android:title="3" /> | ||
<item | ||
android:id="@+id/test04" | ||
android:title="4" /> | ||
<item | ||
android:id="@+id/test05" | ||
android:title="5" /> | ||
</menu> |
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,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/test01" | ||
app:startDestination="@id/testFragment"> | ||
|
||
<fragment | ||
android:id="@+id/testFragment" | ||
android:name="com.crazylegend.setofusefulkotlinextensions.nav.TestFragment" | ||
android:label="TestFragment" /> | ||
</navigation> |
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,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/test02" | ||
app:startDestination="@id/testFragment2"> | ||
|
||
<fragment | ||
android:id="@+id/testFragment2" | ||
android:name="com.crazylegend.setofusefulkotlinextensions.nav.TestFragment" | ||
android:label="TestFragment" /> | ||
</navigation> |
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,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/test03" | ||
app:startDestination="@id/testFragment3"> | ||
|
||
<fragment | ||
android:id="@+id/testFragment3" | ||
android:name="com.crazylegend.setofusefulkotlinextensions.nav.TestFragment" | ||
android:label="TestFragment" /> | ||
</navigation> |
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,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/test04" | ||
app:startDestination="@id/testFragment4"> | ||
|
||
<fragment | ||
android:id="@+id/testFragment4" | ||
android:name="com.crazylegend.setofusefulkotlinextensions.nav.TestFragment" | ||
android:label="TestFragment" /> | ||
</navigation> |
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,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/test05" | ||
app:startDestination="@id/testFragment5"> | ||
|
||
<fragment | ||
android:id="@+id/testFragment5" | ||
android:name="com.crazylegend.setofusefulkotlinextensions.nav.TestFragment" | ||
android:label="TestFragment" /> | ||
</navigation> |
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
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
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
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
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
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
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
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
Oops, something went wrong.