add delete and refresh
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- add swipe to delete - add pull to refresh
This commit is contained in:
parent
90e31fbf16
commit
75e88ef617
@ -54,6 +54,8 @@ dependencies {
|
|||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutines"
|
||||||
// UI
|
// UI
|
||||||
implementation "com.google.android.material:material:$rootProject.materialVersion"
|
implementation "com.google.android.material:material:$rootProject.materialVersion"
|
||||||
|
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TESTING
|
// TESTING
|
||||||
|
@ -4,7 +4,9 @@ import android.os.Bundle
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import it.unisannio.ding.ids.wedroid.app.R
|
import it.unisannio.ding.ids.wedroid.app.R
|
||||||
import it.unisannio.ding.ids.wedroid.app.view.adapter.BoardsListAdapter
|
import it.unisannio.ding.ids.wedroid.app.view.adapter.BoardsListAdapter
|
||||||
import it.unisannio.ding.ids.wedroid.app.viewmodel.BoardsListViewModel
|
import it.unisannio.ding.ids.wedroid.app.viewmodel.BoardsListViewModel
|
||||||
@ -25,14 +27,45 @@ class BoardsListsActivity : AppCompatActivity() {
|
|||||||
boardList.adapter = adapter
|
boardList.adapter = adapter
|
||||||
boardList.layoutManager = LinearLayoutManager(this)
|
boardList.layoutManager = LinearLayoutManager(this)
|
||||||
|
|
||||||
|
swipeLeftToDelete()
|
||||||
|
|
||||||
|
pullToRefresh.setColorSchemeColors(getColor(R.color.colorAccent))
|
||||||
|
|
||||||
viewModel.allBoards.observe(this, Observer {
|
viewModel.allBoards.observe(this, Observer {
|
||||||
it.let { adapter.setBoards(it) }
|
it.let { adapter.setBoards(it) }
|
||||||
|
pullToRefresh.isRefreshing = false
|
||||||
})
|
})
|
||||||
|
|
||||||
fab.setOnClickListener { view ->
|
fab.setOnClickListener {
|
||||||
viewModel.insertBoard("New board")
|
viewModel.insertBoard("New board")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pullToRefresh.setOnRefreshListener {
|
||||||
|
viewModel.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun swipeLeftToDelete() {
|
||||||
|
val swipeToDelete = ItemTouchHelper(
|
||||||
|
object : ItemTouchHelper.SimpleCallback(
|
||||||
|
0, ItemTouchHelper.LEFT
|
||||||
|
) {
|
||||||
|
override fun onMove(
|
||||||
|
recyclerView: RecyclerView,
|
||||||
|
viewHolder: RecyclerView.ViewHolder,
|
||||||
|
target: RecyclerView.ViewHolder
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
||||||
|
val pos = viewHolder.adapterPosition
|
||||||
|
viewModel.deleteBoard(pos)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
swipeToDelete.attachToRecyclerView(boardList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,11 @@ public class BoardsListViewModel extends AndroidViewModel {
|
|||||||
repository.insertBoard(title);
|
repository.insertBoard(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBoard(String id) {
|
public void deleteBoard(int position) {
|
||||||
repository.deleteBoard(id);
|
repository.deleteBoard(allBoards.getValue().get(position).getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
repository.synchronize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,14 @@
|
|||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context=".view.BoardsListsActivity"
|
tools:context=".view.BoardsListsActivity"
|
||||||
tools:showIn="@layout/activity_boards_lists">
|
tools:showIn="@layout/activity_boards_lists">
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:id="@+id/pullToRefresh"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@ -16,4 +24,6 @@
|
|||||||
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.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user