swipe to refresh using androidx SwipeRefreshLayout (#645)
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
947e41105b
commit
09005f8043
5 changed files with 43 additions and 7 deletions
|
@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
|
||||||
### Added
|
### Added
|
||||||
- Copy implicit username (password filename) by long pressing
|
- Copy implicit username (password filename) by long pressing
|
||||||
- Create xkpasswd style passwords
|
- Create xkpasswd style passwords
|
||||||
|
- Swipe on password list to synchronize repository
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Can't delete folders containing a password
|
- Can't delete folders containing a password
|
||||||
|
|
|
@ -84,6 +84,7 @@ dependencies {
|
||||||
implementation deps.androidx.constraint_layout
|
implementation deps.androidx.constraint_layout
|
||||||
implementation deps.androidx.documentfile
|
implementation deps.androidx.documentfile
|
||||||
implementation deps.androidx.preference
|
implementation deps.androidx.preference
|
||||||
|
implementation deps.androidx.swiperefreshlayout
|
||||||
constraints {
|
constraints {
|
||||||
implementation(deps.androidx.recycler_view) {
|
implementation(deps.androidx.recycler_view) {
|
||||||
because 'versions above 1.0.0 have an accessibility related bug that causes crashes'
|
because 'versions above 1.0.0 have an accessibility related bug that causes crashes'
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
*/
|
*/
|
||||||
package com.zeapo.pwdstore
|
package com.zeapo.pwdstore
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -16,7 +18,10 @@ import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
import com.zeapo.pwdstore.git.GitActivity
|
||||||
import com.zeapo.pwdstore.ui.adapters.PasswordRecyclerAdapter
|
import com.zeapo.pwdstore.ui.adapters.PasswordRecyclerAdapter
|
||||||
import com.zeapo.pwdstore.utils.PasswordItem
|
import com.zeapo.pwdstore.utils.PasswordItem
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||||
|
@ -44,6 +49,7 @@ class PasswordFragment : Fragment() {
|
||||||
private lateinit var recyclerView: RecyclerView
|
private lateinit var recyclerView: RecyclerView
|
||||||
private lateinit var listener: OnFragmentInteractionListener
|
private lateinit var listener: OnFragmentInteractionListener
|
||||||
private lateinit var settings: SharedPreferences
|
private lateinit var settings: SharedPreferences
|
||||||
|
private lateinit var swipe_refresher: SwipeRefreshLayout
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -61,6 +67,19 @@ class PasswordFragment : Fragment() {
|
||||||
val view = inflater.inflate(R.layout.password_recycler_view, container, false)
|
val view = inflater.inflate(R.layout.password_recycler_view, container, false)
|
||||||
// use a linear layout manager
|
// use a linear layout manager
|
||||||
val layoutManager = LinearLayoutManager(requireContext())
|
val layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
swipe_refresher = view.findViewById(R.id.swipe_refresher)
|
||||||
|
swipe_refresher.setOnRefreshListener {
|
||||||
|
if (!PasswordRepository.isInitialized) {
|
||||||
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
|
.setMessage(getString(R.string.creation_dialog_text))
|
||||||
|
.setPositiveButton(getString(R.string.dialog_ok), null).show()
|
||||||
|
swipe_refresher.isRefreshing = false
|
||||||
|
} else {
|
||||||
|
val intent = Intent(context, GitActivity::class.java)
|
||||||
|
intent.putExtra("Operation", GitActivity.REQUEST_SYNC)
|
||||||
|
startActivityForResult(intent, GitActivity.REQUEST_SYNC)
|
||||||
|
}
|
||||||
|
}
|
||||||
recyclerView = view.findViewById(R.id.pass_recycler)
|
recyclerView = view.findViewById(R.id.pass_recycler)
|
||||||
recyclerView.layoutManager = layoutManager
|
recyclerView.layoutManager = layoutManager
|
||||||
// use divider
|
// use divider
|
||||||
|
@ -126,6 +145,14 @@ class PasswordFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
when (requestCode) {
|
||||||
|
GitActivity.REQUEST_SYNC -> swipe_refresher.isRefreshing = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** clears the adapter content and sets it back to the root view */
|
/** clears the adapter content and sets it back to the root view */
|
||||||
fun updateAdapter() {
|
fun updateAdapter() {
|
||||||
passListStack.clear()
|
passListStack.clear()
|
||||||
|
|
|
@ -10,13 +10,19 @@
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
tools:context="com.zeapo.pwdstore.PasswordFragment">
|
tools:context="com.zeapo.pwdstore.PasswordFragment">
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipe_refresher"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/pass_recycler"
|
android:id="@+id/pass_recycler"
|
||||||
android:scrollbars="none"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:listitem="@layout/password_row_layout"
|
android:scrollbars="none"
|
||||||
tools:itemCount="20" />
|
tools:itemCount="20"
|
||||||
|
tools:listitem="@layout/password_row_layout" />
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/create_options"
|
android:id="@+id/create_options"
|
||||||
|
|
|
@ -36,7 +36,8 @@ ext.deps = [
|
||||||
documentfile: 'androidx.documentfile:documentfile:1.0.1',
|
documentfile: 'androidx.documentfile:documentfile:1.0.1',
|
||||||
material: 'com.google.android.material:material:1.2.0-alpha05',
|
material: 'com.google.android.material:material:1.2.0-alpha05',
|
||||||
preference: 'androidx.preference:preference:1.1.0',
|
preference: 'androidx.preference:preference:1.1.0',
|
||||||
recycler_view: 'androidx.recyclerview:recyclerview:1.0.0'
|
recycler_view: 'androidx.recyclerview:recyclerview:1.0.0',
|
||||||
|
swiperefreshlayout: 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
|
||||||
],
|
],
|
||||||
|
|
||||||
third_party: [
|
third_party: [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue