add login and board_list #26

Manually merged
norangebit merged 38 commits from feature_integrate_login into develop 2020-01-14 19:53:09 +00:00
4 changed files with 52 additions and 3 deletions
Showing only changes of commit 75e88ef617 - Show all commits

View File

@ -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

View File

@ -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)
}
}

View File

@ -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();
} }
} }

View File

@ -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>