move refresh action to swipe action

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2021-08-31 18:30:39 +02:00 committed by Marcel Hibbe
parent d785d3aa21
commit 1b29038dbd
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 21 additions and 45 deletions

View File

@ -30,6 +30,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import autodagger.AutoInjector import autodagger.AutoInjector
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.activities.MainActivity import com.nextcloud.talk.activities.MainActivity
@ -73,6 +74,7 @@ abstract class BrowserController(args: Bundle) :
), ),
ListingInterface, ListingInterface,
FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemClickListener,
SwipeRefreshLayout.OnRefreshListener,
SelectionInterface { SelectionInterface {
private val binding: ControllerBrowserBinding by viewBinding(ControllerBrowserBinding::bind) private val binding: ControllerBrowserBinding by viewBinding(ControllerBrowserBinding::bind)
@ -136,7 +138,6 @@ abstract class BrowserController(args: Bundle) :
override fun onAttach(view: View) { override fun onAttach(view: View) {
super.onAttach(view) super.onAttach(view)
binding.bottomNavigation.menu.findItem(R.id.action_refresh)?.setOnMenuItemClickListener { refreshCurrentPath() }
binding.pathNavigation.menu.findItem(R.id.action_back)?.setOnMenuItemClickListener { goBack() } binding.pathNavigation.menu.findItem(R.id.action_back)?.setOnMenuItemClickListener { goBack() }
binding.sortButton.setOnClickListener { changeSorting() } binding.sortButton.setOnClickListener { changeSorting() }
@ -147,6 +148,10 @@ abstract class BrowserController(args: Bundle) :
refreshCurrentPath() refreshCurrentPath()
} }
override fun onRefresh() {
refreshCurrentPath()
}
fun changeSorting() { fun changeSorting() {
val newFragment: DialogFragment = SortingOrderDialogFragment val newFragment: DialogFragment = SortingOrderDialogFragment
.newInstance(FileSortOrder.getFileSortOrder(appPreferences?.sorting)) .newInstance(FileSortOrder.getFileSortOrder(appPreferences?.sorting))
@ -174,7 +179,6 @@ abstract class BrowserController(args: Bundle) :
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private fun changeEnabledStatusForBarItems(shouldBeEnabled: Boolean) { private fun changeEnabledStatusForBarItems(shouldBeEnabled: Boolean) {
binding.bottomNavigation.menu.findItem(R.id.action_refresh)?.isEnabled = shouldBeEnabled
binding.pathNavigation.menu.findItem(R.id.action_back)?.isEnabled = shouldBeEnabled && currentPath != "/" binding.pathNavigation.menu.findItem(R.id.action_back)?.isEnabled = shouldBeEnabled && currentPath != "/"
} }
@ -211,6 +215,8 @@ abstract class BrowserController(args: Bundle) :
changeEnabledStatusForBarItems(true) changeEnabledStatusForBarItems(true)
} }
} }
binding.swipeRefreshList.isRefreshing = false
} }
private fun shouldPathBeSelectedDueToParent(currentPath: String): Boolean { private fun shouldPathBeSelectedDueToParent(currentPath: String): Boolean {
@ -270,6 +276,8 @@ abstract class BrowserController(args: Bundle) :
return@setBubbleTextCreator "" return@setBubbleTextCreator ""
} }
} }
binding.swipeRefreshList.setOnRefreshListener(this)
} }
} }

View File

@ -82,23 +82,19 @@
app:itemTextColor="@color/fg_default" app:itemTextColor="@color/fg_default"
app:menu="@menu/file_browser_path" /> app:menu="@menu/file_browser_path" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/path_navigation"
android:footerDividersEnabled="false">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_above="@id/bottom_navigation"
android:layout_below="@id/path_navigation"
tools:listitem="@layout/rv_item_browser_file" /> tools:listitem="@layout/rv_item_browser_file" />
<com.google.android.material.bottomnavigation.BottomNavigationView </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
android:id="@+id/bottom_navigation"
style="@style/BottomNavigationView"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_alignParentBottom="true"
android:background="@color/bg_default"
app:itemTextColor="@color/fg_default"
app:itemIconTint="@color/fg_default"
app:menu="@menu/file_browser_bottom" />
</RelativeLayout> </RelativeLayout>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_refresh"
android:icon="@drawable/ic_refresh_black_24dp"
android:title="@string/nc_file_browser_refresh"/>
</menu>