handle swipe to refresh inline

This commit is contained in:
tibbi 2016-11-19 21:22:48 +01:00
parent 80a1d286e6
commit 828b4f4256
2 changed files with 5 additions and 15 deletions

View File

@ -10,7 +10,6 @@ import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.support.design.widget.Snackbar import android.support.design.widget.Snackbar
import android.support.v4.app.ActivityCompat import android.support.v4.app.ActivityCompat
import android.support.v4.widget.SwipeRefreshLayout
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.MotionEvent import android.view.MotionEvent
@ -27,7 +26,7 @@ import kotlinx.android.synthetic.main.activity_main.*
import java.io.File import java.io.File
import java.util.* import java.util.*
class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, GetDirectoriesAsynctask.GetDirectoriesListener, View.OnTouchListener, DirectoryAdapter.DirOperationsListener { class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesListener, View.OnTouchListener, DirectoryAdapter.DirOperationsListener {
companion object { companion object {
private val STORAGE_PERMISSION = 1 private val STORAGE_PERMISSION = 1
private val PICK_MEDIA = 2 private val PICK_MEDIA = 2
@ -62,7 +61,7 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
mIsGetAnyContentIntent || mIsSetWallpaperIntent mIsGetAnyContentIntent || mIsSetWallpaperIntent
mToBeDeleted = ArrayList<String>() mToBeDeleted = ArrayList<String>()
directories_holder.setOnRefreshListener(this) directories_holder.setOnRefreshListener({ getDirectories() })
mDirs = ArrayList<Directory>() mDirs = ArrayList<Directory>()
} }
@ -287,12 +286,8 @@ class MainActivity : SimpleActivity(), SwipeRefreshLayout.OnRefreshListener, Get
} }
} }
override fun onRefresh() {
getDirectories()
directories_holder.isRefreshing = false
}
override fun gotDirectories(dirs: ArrayList<Directory>) { override fun gotDirectories(dirs: ArrayList<Directory>) {
directories_holder.isRefreshing = false
mIsGettingDirs = false mIsGettingDirs = false
if (dirs.toString() == mDirs.toString()) { if (dirs.toString() == mDirs.toString()) {
return return

View File

@ -10,7 +10,6 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.support.design.widget.Snackbar import android.support.design.widget.Snackbar
import android.support.v4.widget.SwipeRefreshLayout
import android.util.Log import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -32,7 +31,7 @@ import java.io.IOException
import java.util.* import java.util.*
import java.util.regex.Pattern import java.util.regex.Pattern
class MediaActivity : SimpleActivity(), View.OnTouchListener, SwipeRefreshLayout.OnRefreshListener, MediaAdapter.MediaOperationsListener { class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.MediaOperationsListener {
companion object { companion object {
private val TAG = MediaActivity::class.java.simpleName private val TAG = MediaActivity::class.java.simpleName
@ -57,7 +56,7 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, SwipeRefreshLayout
mIsGetAnyIntent = getBooleanExtra(Constants.GET_ANY_INTENT, false) mIsGetAnyIntent = getBooleanExtra(Constants.GET_ANY_INTENT, false)
} }
media_holder.setOnRefreshListener(this) media_holder.setOnRefreshListener({ refreshDir() })
mPath = intent.getStringExtra(Constants.DIRECTORY) mPath = intent.getStringExtra(Constants.DIRECTORY)
mToBeDeleted = ArrayList<String>() mToBeDeleted = ArrayList<String>()
mMedia = ArrayList<Medium>() mMedia = ArrayList<Medium>()
@ -363,10 +362,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, SwipeRefreshLayout
refreshDir() refreshDir()
} }
override fun onRefresh() {
refreshDir()
}
private fun refreshDir() { private fun refreshDir() {
val dir = File(mPath) val dir = File(mPath)
if (dir.isDirectory) { if (dir.isDirectory) {