//при инициализации, создаю список и добавляю
fun insertData(list:ArrayList<Content>){
val dfc = MyDiffUril(listOfContent,list)
val difResult = DiffUtil.calculateDiff(dfc)
listOfContent.addAll(list)
difResult.dispatchUpdatesTo(this)
}
//по нажатию на вью холдер обновляю список
fun updateData(list:ArrayList<Content>){
val dfc = MyDiffUril(listOfContent,list)
val difResult = DiffUtil.calculateDiff(dfc)
listOfContent.clear()
listOfContent.addAll(list)
difResult.dispatchUpdatesTo(this)
}
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="localhost"
android:scheme="http"/>
</intent-filter>
redirect_uri=http://localhost
<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
fab:defaultNavHost="false"
fab:navGraph="@navigation/nav_graph" />
open class MainActivity : AppCompatActivity() {
private lateinit var navController:NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//creating backArrow
navController=Navigation.findNavController(this,R.id.fragment)
NavigationUI.setupActionBarWithNavController(this,navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp()
}
//https://chetangupta.net/viewbinding/
abstract class ViewBindingFragment<VB : ViewBinding> : Fragment() {
private var _binding: ViewBinding? = null
abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB
@Suppress("UNCHECKED_CAST")
protected val binding: VB
get() = _binding as VB
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = bindingInflater.invoke(inflater, container, false)
return requireNotNull(_binding).root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setup()
}
abstract fun setup()
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
class ProfileFragment :ViewBindingFragment<ProfileLayoutBinding>() {
override val bindingInflater: (LayoutInflater) -> ViewBinding
= ProfileLayoutBinding::inflate
override fun setup(){
//.. do stuff with binding variable
}
}
onView(withId(R.id.menu_item_add)).check(
matches(
allOf(
isEnabled(),
isClickable()
)
)
).perform(
object : ViewAction {
override fun getDescription(): String {
return "click add button"
}
override fun getConstraints(): Matcher<View> {
return isEnabled()
}
override fun perform(uiController: UiController?, view: View?) {
view?.performClick()
}
}
)
//MainActivity
private lateinit var navController:NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navController=Navigation.findNavController(this,R.id.fragment)
NavigationUI.setupActionBarWithNavController(this,navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp()
}