1
1
/*
2
2
* Nextcloud - Android Client
3
3
*
4
+ * SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
4
5
* SPDX-FileCopyrightText: 2022 Álvaro Brey <alvaro.brey@nextcloud.com>
5
6
* SPDX-FileCopyrightText: 2018-2021 Tobias Kaminsky <tobias@kaminsky.me>
6
7
* SPDX-FileCopyrightText: 2019 Chris Narkiewicz <hello@ezaquarii.com>
13
14
* SPDX-FileCopyrightText: 2012 Bartosz Przybylski <bart.p.pl@gmail.com>
14
15
* SPDX-License-Identifier: GPL-2.0-only AND (AGPL-3.0-or-later OR GPL-2.0-only)
15
16
*/
16
- package com.owncloud.android.ui.fragment ;
17
-
18
- import android.animation.LayoutTransition;
19
- import android.app.Activity;
20
- import android.content.Context;
21
- import android.content.res.Configuration;
22
- import android.os.Bundle;
23
- import android.os.Handler;
24
- import android.os.Looper;
25
- import android.text.TextUtils;
26
- import android.util.DisplayMetrics;
27
- import android.view.LayoutInflater;
28
- import android.view.Menu;
29
- import android.view.MenuInflater;
30
- import android.view.MenuItem;
31
- import android.view.MotionEvent;
32
- import android.view.ScaleGestureDetector;
33
- import android.view.View;
34
- import android.view.ViewGroup;
35
- import android.view.inputmethod.InputMethodManager;
36
- import android.widget.AdapterView;
37
- import android.widget.AdapterView.OnItemClickListener;
38
- import android.widget.GridView;
39
- import android.widget.ImageView;
40
- import android.widget.LinearLayout;
41
- import android.widget.TextView;
42
-
43
- import com.google.android.material.button.MaterialButton;
44
- import com.nextcloud.client.account.UserAccountManager;
45
- import com.nextcloud.client.di.Injectable;
46
- import com.nextcloud.client.preferences.AppPreferences;
47
- import com.nextcloud.client.preferences.AppPreferencesImpl;
48
- import com.nextcloud.utils.extensions.FragmentExtensionsKt;
49
- import com.owncloud.android.MainApp;
50
- import com.owncloud.android.R;
51
- import com.owncloud.android.databinding.ListFragmentBinding;
52
- import com.owncloud.android.lib.common.utils.Log_OC;
53
- import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
54
- import com.owncloud.android.lib.resources.status.OwnCloudVersion;
55
- import com.owncloud.android.ui.EmptyRecyclerView;
56
- import com.owncloud.android.ui.activity.FileActivity;
57
- import com.owncloud.android.ui.activity.FileDisplayActivity;
58
- import com.owncloud.android.ui.activity.FolderPickerActivity;
59
- import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
60
- import com.owncloud.android.ui.activity.UploadFilesActivity;
61
- import com.owncloud.android.ui.adapter.LocalFileListAdapter;
62
- import com.owncloud.android.ui.adapter.OCFileListAdapter;
63
- import com.owncloud.android.ui.events.SearchEvent;
64
- import com.owncloud.android.utils.theme.ViewThemeUtils;
65
-
66
- import org.greenrobot.eventbus.EventBus;
67
-
68
- import java.util.ArrayList;
69
-
70
- import javax.inject.Inject;
71
-
72
- import androidx.annotation.DrawableRes;
73
- import androidx.annotation.NonNull;
74
- import androidx.annotation.Nullable;
75
- import androidx.annotation.StringRes;
76
- import androidx.appcompat.widget.SearchView;
77
- import androidx.core.content.ContextCompat;
78
- import androidx.core.view.MenuItemCompat;
79
- import androidx.fragment.app.Fragment;
80
- import androidx.recyclerview.widget.GridLayoutManager;
81
- import androidx.recyclerview.widget.LinearLayoutManager;
82
- import androidx.recyclerview.widget.RecyclerView;
83
- import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
84
-
85
- public class ExtendedListFragment extends Fragment implements
86
- OnItemClickListener ,
87
- OnEnforceableRefreshListener ,
88
- SearchView .OnQueryTextListener ,
89
- SearchView .OnCloseListener ,
90
- Injectable {
91
-
92
- protected static final String TAG = ExtendedListFragment .class .getSimpleName();
93
-
94
- protected static final String KEY_SAVED_LIST_POSITION = " SAVED_LIST_POSITION" ;
95
-
96
- private static final String KEY_INDEXES = " INDEXES" ;
97
- private static final String KEY_FIRST_POSITIONS = " FIRST_POSITIONS" ;
98
- private static final String KEY_TOPS = " TOPS" ;
99
- private static final String KEY_HEIGHT_CELL = " HEIGHT_CELL" ;
100
- private static final String KEY_EMPTY_LIST_MESSAGE = " EMPTY_LIST_MESSAGE" ;
101
- private static final String KEY_IS_GRID_VISIBLE = " IS_GRID_VISIBLE" ;
102
- public static final float minColumnSize = 2.0f ;
103
-
104
- private int maxColumnSize = 5 ;
105
-
106
- @Inject AppPreferences preferences;
107
- @Inject UserAccountManager accountManager;
108
- @Inject ViewThemeUtils viewThemeUtils;
109
-
110
- private ScaleGestureDetector mScaleGestureDetector;
111
- protected SwipeRefreshLayout mRefreshListLayout;
112
- protected MaterialButton mSortButton;
113
- protected MaterialButton mSwitchGridViewButton;
114
- protected ViewGroup mEmptyListContainer;
115
- protected TextView mEmptyListMessage;
116
- protected TextView mEmptyListHeadline;
117
- protected ImageView mEmptyListIcon;
17
+ package com.owncloud.android.ui.fragment
18
+
19
+ import android.animation.LayoutTransition
20
+ import android.annotation.SuppressLint
21
+ import android.app.Activity
22
+ import android.content.Context
23
+ import android.content.res.Configuration
24
+ import android.os.Bundle
25
+ import android.os.Handler
26
+ import android.os.Looper
27
+ import android.text.TextUtils
28
+ import android.util.DisplayMetrics
29
+ import android.view.LayoutInflater
30
+ import android.view.Menu
31
+ import android.view.MenuInflater
32
+ import android.view.MotionEvent
33
+ import android.view.ScaleGestureDetector
34
+ import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener
35
+ import android.view.View
36
+ import android.view.View.OnTouchListener
37
+ import android.view.ViewGroup
38
+ import android.view.inputmethod.InputMethodManager
39
+ import android.widget.AdapterView
40
+ import android.widget.GridView
41
+ import android.widget.ImageView
42
+ import android.widget.LinearLayout
43
+ import android.widget.TextView
44
+ import androidx.annotation.DrawableRes
45
+ import androidx.annotation.StringRes
46
+ import androidx.appcompat.widget.SearchView
47
+ import androidx.core.content.ContextCompat
48
+ import androidx.core.view.MenuItemCompat
49
+ import androidx.fragment.app.Fragment
50
+ import androidx.recyclerview.widget.GridLayoutManager
51
+ import androidx.recyclerview.widget.LinearLayoutManager
52
+ import androidx.recyclerview.widget.RecyclerView
53
+ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
54
+ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener
55
+ import com.google.android.material.button.MaterialButton
56
+ import com.nextcloud.android.common.ui.theme.utils.ColorRole
57
+ import com.nextcloud.client.account.UserAccountManager
58
+ import com.nextcloud.client.di.Injectable
59
+ import com.nextcloud.client.network.ConnectivityService.GenericCallback
60
+ import com.nextcloud.client.preferences.AppPreferences
61
+ import com.nextcloud.client.preferences.AppPreferencesImpl
62
+ import com.nextcloud.utils.extensions.getTypedActivity
63
+ import com.owncloud.android.MainApp
64
+ import com.owncloud.android.R
65
+ import com.owncloud.android.databinding.ListFragmentBinding
66
+ import com.owncloud.android.lib.common.utils.Log_OC
67
+ import com.owncloud.android.lib.resources.files.SearchRemoteOperation
68
+ import com.owncloud.android.lib.resources.status.OwnCloudVersion
69
+ import com.owncloud.android.ui.EmptyRecyclerView
70
+ import com.owncloud.android.ui.activity.FileActivity
71
+ import com.owncloud.android.ui.activity.FileDisplayActivity
72
+ import com.owncloud.android.ui.activity.FolderPickerActivity
73
+ import com.owncloud.android.ui.activity.OnEnforceableRefreshListener
74
+ import com.owncloud.android.ui.activity.UploadFilesActivity
75
+ import com.owncloud.android.ui.adapter.LocalFileListAdapter
76
+ import com.owncloud.android.ui.adapter.OCFileListAdapter
77
+ import com.owncloud.android.ui.events.SearchEvent
78
+ import com.owncloud.android.utils.theme.ViewThemeUtils
79
+ import org.greenrobot.eventbus.EventBus
80
+ import javax.inject.Inject
81
+ import kotlin.math.max
82
+ import kotlin.math.min
83
+ import kotlin.math.roundToInt
84
+
85
+ @Suppress(" MagicNumber" , " TooManyFunctions" )
86
+ open class ExtendedListFragment : Fragment (), AdapterView.OnItemClickListener, OnEnforceableRefreshListener,
87
+ SearchView .OnQueryTextListener , SearchView .OnCloseListener , Injectable {
88
+ private var maxColumnSize = 5
89
+
90
+ @Inject
91
+ lateinit var preferences: AppPreferences
92
+
93
+ @Inject
94
+ lateinit var accountManager: UserAccountManager
95
+
96
+ @Inject
97
+ lateinit var viewThemeUtils: ViewThemeUtils
98
+
99
+ private var mScaleGestureDetector: ScaleGestureDetector ? = null
100
+
101
+ @JvmField
102
+ protected var mRefreshListLayout: SwipeRefreshLayout ? = null
103
+
104
+ @JvmField
105
+ protected var mSortButton: MaterialButton ? = null
106
+
107
+ @JvmField
108
+ protected var mSwitchGridViewButton: MaterialButton ? = null
109
+
110
+ protected var mEmptyListContainer: ViewGroup ? = null
111
+ protected var mEmptyListMessage: TextView ? = null
112
+ protected var mEmptyListHeadline: TextView ? = null
113
+ protected var mEmptyListIcon: ImageView ? = null
118
114
119
115
// Save the state of the scroll in browsing
120
- private ArrayList <Integer > mIndexes = new ArrayList <> ();
121
- private ArrayList <Integer > mFirstPositions = new ArrayList <> ();
122
- private ArrayList <Integer > mTops = new ArrayList <> ();
123
- private int mHeightCell = 0 ;
116
+ private var mIndexes : ArrayList <Int ?> ? = ArrayList <Int ? >()
117
+ private var mFirstPositions : ArrayList <Int ?> ? = ArrayList <Int ? >()
118
+ private var mTops : ArrayList <Int ?> ? = ArrayList <Int ? >()
119
+ private var mHeightCell = 0
124
120
125
- private SwipeRefreshLayout . OnRefreshListener mOnRefreshListener;
121
+ private var mOnRefreshListener: OnRefreshListener ? = null
126
122
127
- private EmptyRecyclerView mRecyclerView;
123
+ private var mRecyclerView: EmptyRecyclerView ? = null
128
124
129
- protected SearchView searchView;
130
- private ImageView closeButton;
131
- private final Handler handler = new Handler (Looper .getMainLooper());
125
+ protected var searchView: SearchView ? = null
126
+ private var closeButton: ImageView ? = null
127
+ private val handler = Handler (Looper .getMainLooper())
132
128
133
- private float mScale = AppPreferencesImpl .DEFAULT_GRID_COLUMN ;
129
+ private var mScale = AppPreferencesImpl .DEFAULT_GRID_COLUMN
134
130
135
- private ListFragmentBinding binding;
131
+ var binding: ListFragmentBinding ? = null
132
+ private set
136
133
137
- public ListFragmentBinding getBinding( ) {
138
- return binding;
134
+ protected fun setRecyclerViewAdapter ( recyclerViewAdapter : RecyclerView . Adapter < * > ? ) {
135
+ mRecyclerView?.setAdapter(recyclerViewAdapter)
139
136
}
140
137
141
- protected void setRecyclerViewAdapter(RecyclerView .Adapter recyclerViewAdapter) {
142
- mRecyclerView.setAdapter(recyclerViewAdapter);
143
- }
144
-
145
- protected RecyclerView getRecyclerView() {
146
- return mRecyclerView;
147
- }
138
+ protected val recyclerView: RecyclerView
139
+ get() = mRecyclerView!!
148
140
149
- public void setLoading(boolean enabled) {
150
- mRefreshListLayout.setRefreshing( enabled);
141
+ open fun setLoading (enabled : Boolean ) {
142
+ mRefreshListLayout?.isRefreshing = enabled
151
143
}
152
144
153
- public void switchToGridView() {
154
- if (! isGridEnabled() ) {
155
- getRecyclerView() .setLayoutManager(new GridLayoutManager (getContext(), getColumnsCount()));
145
+ open fun switchToGridView () {
146
+ if (! isGridEnabled) {
147
+ recyclerView .setLayoutManager(GridLayoutManager (context, columnsCount))
156
148
}
157
149
}
158
150
159
- public void switchToListView() {
160
- if (isGridEnabled() ) {
161
- getRecyclerView() .setLayoutManager(new LinearLayoutManager (getContext()));
151
+ open fun switchToListView () {
152
+ if (isGridEnabled) {
153
+ recyclerView .setLayoutManager(LinearLayoutManager (context))
162
154
}
163
155
}
164
156
165
- public boolean isGridEnabled() {
166
- if (getRecyclerView() != null ) {
167
- return getRecyclerView().getLayoutManager() instanceof GridLayoutManager ;
168
- } else {
169
- return false ;
157
+ val isGridEnabled: Boolean
158
+ get() {
159
+ return recyclerView.layoutManager is GridLayoutManager
170
160
}
171
- }
172
161
173
- @Override
174
- public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
175
- final MenuItem item = menu.findItem(R .id.action_search);
176
- searchView = (SearchView ) MenuItemCompat .getActionView(item);
177
- viewThemeUtils.androidx.themeToolbarSearchView(searchView);
178
- closeButton = searchView.findViewById(androidx.appcompat.R .id.search_close_btn);
179
- searchView.setOnQueryTextListener(this );
180
- searchView.setOnCloseListener(this );
181
-
182
- final Handler handler = new Handler (Looper .getMainLooper());
183
-
184
- DisplayMetrics displaymetrics = new DisplayMetrics ();
185
- Activity activity;
186
- if ((activity = getActivity()) != null ) {
187
- activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
188
- int width = displaymetrics.widthPixels;
189
- if (getResources().getConfiguration().orientation == Configuration .ORIENTATION_LANDSCAPE ) {
190
- searchView.setMaxWidth((int) (width * 0.4 ));
162
+ override fun onCreateOptionsMenu (menu : Menu , inflater : MenuInflater ) {
163
+ val item = menu.findItem(R .id.action_search)
164
+ searchView = MenuItemCompat .getActionView(item) as SearchView ?
165
+ viewThemeUtils.androidx.themeToolbarSearchView(searchView!! )
166
+ closeButton = searchView?.findViewById<ImageView >(androidx.appcompat.R .id.search_close_btn)
167
+ searchView?.setOnQueryTextListener(this )
168
+ searchView?.setOnCloseListener(this )
169
+
170
+ val handler = Handler (Looper .getMainLooper())
171
+
172
+ val displaymetrics = DisplayMetrics ()
173
+ val activity: Activity ?
174
+ if ((getActivity().also { activity = it }) != null ) {
175
+ activity?.windowManager?.defaultDisplay?.getMetrics(displaymetrics)
176
+ val width = displaymetrics.widthPixels
177
+ if (resources.configuration.orientation == Configuration .ORIENTATION_LANDSCAPE ) {
178
+ searchView?.setMaxWidth((width * 0.4 ).toInt())
191
179
} else {
192
- if (activity instanceof FolderPickerActivity ) {
193
- searchView.setMaxWidth((int) ( width * 0.8 ));
180
+ if (activity is FolderPickerActivity ) {
181
+ searchView? .setMaxWidth((width * 0.8 ).toInt())
194
182
} else {
195
- searchView.setMaxWidth(width);
183
+ searchView? .setMaxWidth(width)
196
184
}
197
185
}
198
186
}
199
187
200
- searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> handler.post(() -> {
201
- if (getActivity() != null && ! (getActivity() instanceof FolderPickerActivity )
202
- && ! (getActivity() instanceof UploadFilesActivity )) {
203
- if (getActivity() instanceof FileDisplayActivity ) {
204
- Fragment fragment = ((FileDisplayActivity ) getActivity()).getLeftFragment();
205
- if (fragment instanceof OCFileListFragment ) {
206
- ((OCFileListFragment ) fragment).setFabVisible(! hasFocus);
188
+ searchView?.setOnQueryTextFocusChangeListener(View .OnFocusChangeListener { v: View ? , hasFocus: Boolean ->
189
+ handler.post(
190
+ Runnable {
191
+ if (getActivity() != null &&
192
+ (getActivity() !is FolderPickerActivity ) &&
193
+ (getActivity() !is UploadFilesActivity )
194
+ ) {
195
+ if (getActivity() is FileDisplayActivity ) {
196
+ val fragment = (getActivity() as FileDisplayActivity ).leftFragment
197
+ if (fragment is OCFileListFragment ) {
198
+ fragment.setFabVisible(! hasFocus)
199
+ }
200
+ }
201
+
202
+ if (TextUtils .isEmpty(searchView?.query)) {
203
+ closeButton?.setVisibility(View .INVISIBLE )
204
+ }
207
205
}
208
206
}
209
- if (TextUtils .isEmpty(searchView.getQuery())) {
210
- closeButton.setVisibility(View .INVISIBLE );
211
- }
212
- }
213
- }));
207
+ )
208
+ })
214
209
215
210
// On close -> empty field, show keyboard and
216
- closeButton.setOnClickListener(view -> {
217
- searchView.setQuery(" " , true );
218
- searchView.requestFocus();
219
- searchView.onActionViewExpanded();
211
+ closeButton? .setOnClickListener(View . OnClickListener { view: View ? ->
212
+ searchView? .setQuery(" " , true )
213
+ searchView? .requestFocus()
214
+ searchView? .onActionViewExpanded()
220
215
221
- InputMethodManager inputMethodManager =
222
- (InputMethodManager ) getActivity().getSystemService(Context .INPUT_METHOD_SERVICE );
216
+ val inputMethodManager =
217
+ getActivity()?.getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager ?
218
+ inputMethodManager?.showSoftInput(searchView, InputMethodManager .SHOW_IMPLICIT )
219
+ })
223
220
224
- if (inputMethodManager != null ) {
225
- inputMethodManager.showSoftInput(searchView, InputMethodManager .SHOW_IMPLICIT );
226
- }
227
- });
228
-
229
- LinearLayout searchBar = searchView.findViewById(R .id.search_bar);
230
- searchBar.setLayoutTransition(new LayoutTransition ());
221
+ val searchBar = searchView?.findViewById<LinearLayout >(R .id.search_bar)
222
+ searchBar?.setLayoutTransition(LayoutTransition ())
231
223
}
232
224
233
- public boolean onQueryTextChange(final String query) {
225
+ override fun onQueryTextChange (query : String ): Boolean {
234
226
// After 300 ms, set the query
235
227
236
- closeButton.setVisibility(View .VISIBLE );
228
+ closeButton? .setVisibility(View .VISIBLE )
237
229
if (query.isEmpty()) {
238
- closeButton.setVisibility(View .INVISIBLE );
230
+ closeButton? .setVisibility(View .INVISIBLE )
239
231
}
240
- return false ;
232
+ return false
241
233
}
242
234
243
- @Override
244
- public boolean onQueryTextSubmit(String query) {
245
- RecyclerView . Adapter adapter = getRecyclerView().getAdapter();
246
- if (adapter instanceof OCFileListAdapter ) {
247
- ArrayList < String > listOfHiddenFiles = (( OCFileListAdapter ) adapter) .listOfHiddenFiles;
248
- performSearch(query, listOfHiddenFiles, false );
249
- return true ;
235
+ @Suppress( " ReturnCount " )
236
+ override fun onQueryTextSubmit (query : String ): Boolean {
237
+ val adapter = recyclerView.adapter
238
+ if (adapter is OCFileListAdapter ) {
239
+ val listOfHiddenFiles = adapter.listOfHiddenFiles
240
+ performSearch(query, listOfHiddenFiles, false )
241
+ return true
250
242
}
251
- if (adapter instanceof LocalFileListAdapter ) {
252
- performSearch(query, new ArrayList <> (), false );
253
- return true ;
243
+ if (adapter is LocalFileListAdapter ) {
244
+ performSearch(query, ArrayList <String ? >(), false )
245
+ return true
254
246
}
255
- return false ;
247
+ return false
256
248
}
257
249
258
- public void performSearch(final String query, final ArrayList <String > listOfHiddenFiles, boolean isBackPressed) {
259
- handler.removeCallbacksAndMessages(null );
260
- RecyclerView . Adapter adapter = getRecyclerView().getAdapter();
261
- Activity activity = getActivity();
250
+ fun performSearch (query : String , listOfHiddenFiles : ArrayList <String ?> ? , isBackPressed : Boolean ) {
251
+ handler.removeCallbacksAndMessages(null )
252
+ val adapter = recyclerView.adapter
253
+ val activity: Activity ? = getActivity()
262
254
263
255
if (activity != null ) {
264
- if (activity instanceof FileDisplayActivity ) {
256
+ if (activity is FileDisplayActivity ) {
265
257
if (isBackPressed && TextUtils .isEmpty(query)) {
266
- FileDisplayActivity fileDisplayActivity = ( FileDisplayActivity ) activity;
267
- fileDisplayActivity.resetSearchView();
268
- fileDisplayActivity.updateListOfFilesFragment(true );
258
+ val fileDisplayActivity = activity
259
+ fileDisplayActivity.resetSearchView()
260
+ fileDisplayActivity.updateListOfFilesFragment(true )
269
261
} else {
270
- handler.post(() -> {
271
- if (adapter instanceof OCFileListAdapter ) {
262
+ handler.post(Runnable {
263
+ if (adapter is OCFileListAdapter ) {
272
264
if (accountManager
273
- .getUser()
274
- .getServer()
275
- .getVersion()
276
- .isNewerOrEqual(OwnCloudVersion .nextcloud_20)
265
+ .user
266
+ .server
267
+ .version
268
+ .isNewerOrEqual(OwnCloudVersion .nextcloud_20)
277
269
) {
278
- (( FileDisplayActivity ) activity) .performUnifiedSearch(query, listOfHiddenFiles);
270
+ activity.performUnifiedSearch(query, listOfHiddenFiles)
279
271
} else {
280
272
EventBus .getDefault().post(
281
- new SearchEvent (query, SearchRemoteOperation .SearchType .FILE_SEARCH )
282
- );
273
+ SearchEvent (query, SearchRemoteOperation .SearchType .FILE_SEARCH )
274
+ )
283
275
}
284
- } else if (adapter instanceof LocalFileListAdapter localFileListAdapter ) {
285
- localFileListAdapter .filter(query);
276
+ } else if (adapter is LocalFileListAdapter ) {
277
+ adapter .filter(query)
286
278
}
287
- });
279
+ })
288
280
289
- if (searchView != null ) {
290
- searchView.clearFocus();
291
- }
281
+ searchView?.clearFocus()
292
282
}
293
- } else if (activity instanceof UploadFilesActivity uploadFilesActivity ) {
294
- LocalFileListAdapter localFileListAdapter = ( LocalFileListAdapter ) adapter;
283
+ } else if (activity is UploadFilesActivity ) {
284
+ val localFileListAdapter = adapter as LocalFileListAdapter ?
295
285
if (localFileListAdapter != null ) {
296
- localFileListAdapter.filter(query);
297
- uploadFilesActivity.getFileListFragment() .setLoading(false );
286
+ localFileListAdapter.filter(query)
287
+ activity.fileListFragment .setLoading(false )
298
288
}
299
- } else if (activity instanceof FolderPickerActivity ) {
300
- (( FolderPickerActivity ) activity) .search(query);
289
+ } else if (activity is FolderPickerActivity ) {
290
+ activity.search(query)
301
291
}
302
292
}
303
293
}
304
294
305
- @Override
306
- public boolean onClose() {
307
- RecyclerView .Adapter adapter = getRecyclerView().getAdapter();
308
- if (adapter instanceof OCFileListAdapter ) {
309
- ArrayList <String > listOfHiddenFiles = ((OCFileListAdapter ) adapter).listOfHiddenFiles;
310
- performSearch(" " , listOfHiddenFiles,true );
311
- return false ;
295
+ override fun onClose (): Boolean {
296
+ val adapter = recyclerView.adapter
297
+ if (adapter is OCFileListAdapter ) {
298
+ val listOfHiddenFiles = adapter.listOfHiddenFiles
299
+ performSearch(" " , listOfHiddenFiles, true )
300
+ return false
312
301
}
313
- return true ;
302
+ return true
314
303
}
315
304
316
- @Override
317
- public void onAttach(@NonNull Context context) {
318
- super .onAttach(context);
305
+ override fun onAttach (context : Context ) {
306
+ super .onAttach(context)
319
307
}
320
308
321
- @Override
322
- public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
323
- Log_OC .d(TAG , " onCreateView" );
309
+ @SuppressLint( " ClickableViewAccessibility " )
310
+ override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
311
+ Log_OC .d(TAG , " onCreateView" )
324
312
325
- binding = ListFragmentBinding .inflate(inflater, container, false );
326
- View v = binding.getRoot();
313
+ binding = ListFragmentBinding .inflate(inflater, container, false )
314
+ val v = binding!! .getRoot()
327
315
328
- setupEmptyList(v);
316
+ setupEmptyList()
329
317
330
- mRecyclerView = binding.listRoot;
331
- mRecyclerView.setHasFooter(true );
332
- mRecyclerView.setEmptyView(binding.emptyList.emptyListView);
333
- mRecyclerView.setHasFixedSize(true );
334
- mRecyclerView.setLayoutManager(new LinearLayoutManager (getContext()));
318
+ mRecyclerView = binding? .listRoot
319
+ mRecyclerView? .setHasFooter(true )
320
+ mRecyclerView? .setEmptyView(binding? .emptyList? .emptyListView)
321
+ mRecyclerView? .setHasFixedSize(true )
322
+ mRecyclerView? .setLayoutManager(LinearLayoutManager (context))
335
323
336
- mScale = preferences.getGridColumns();
337
- setGridViewColumns(1f );
324
+ mScale = preferences.getGridColumns()
325
+ setGridViewColumns(1f )
338
326
339
- mScaleGestureDetector = new ScaleGestureDetector (MainApp .getAppContext(), new ScaleListener ());
327
+ mScaleGestureDetector = ScaleGestureDetector (MainApp .getAppContext(), ScaleListener ())
340
328
341
- getRecyclerView().setOnTouchListener((view, motionEvent) -> {
342
- mScaleGestureDetector.onTouchEvent(motionEvent);
343
-
344
- if (motionEvent.getAction() == MotionEvent .ACTION_UP ) {
345
- view.performClick();
329
+ recyclerView.setOnTouchListener(OnTouchListener { view: View , motionEvent: MotionEvent ->
330
+ mScaleGestureDetector?.onTouchEvent(motionEvent)
331
+ if (motionEvent.action == MotionEvent .ACTION_UP ) {
332
+ view.performClick()
346
333
}
347
-
348
- return false ;
349
- });
334
+ false
335
+ })
350
336
351
337
// Pull-down to refresh layout
352
- mRefreshListLayout = binding.swipeContainingList;
353
- viewThemeUtils.androidx.themeSwipeRefreshLayout(mRefreshListLayout);
354
- mRefreshListLayout.setOnRefreshListener(this );
338
+ mRefreshListLayout = binding?.swipeContainingList
339
+ mRefreshListLayout?.let {
340
+ viewThemeUtils.androidx.themeSwipeRefreshLayout(it)
341
+ it.setOnRefreshListener(this )
342
+ }
355
343
356
- mSortButton = getActivity() .findViewById(R .id.sort_button);
357
- if ( mSortButton != null ) {
358
- viewThemeUtils.material.colorMaterialTextButton(mSortButton);
344
+ mSortButton = activity? .findViewById< MaterialButton ?> (R .id.sort_button)
345
+ mSortButton?. let {
346
+ viewThemeUtils.material.colorMaterialTextButton(it)
359
347
}
360
- mSwitchGridViewButton = getActivity().findViewById(R .id.switch_grid_view_button);
361
- if (mSwitchGridViewButton != null ) {
362
- viewThemeUtils.material.colorMaterialTextButton(mSwitchGridViewButton);
348
+
349
+ mSwitchGridViewButton = activity?.findViewById<MaterialButton ?>(R .id.switch_grid_view_button)
350
+ mSwitchGridViewButton?.let {
351
+ viewThemeUtils.material.colorMaterialTextButton(it)
363
352
}
364
353
365
- return v;
354
+ return v
366
355
}
367
356
368
- @Override
369
- public void onDestroyView() {
370
- super .onDestroyView();
371
- binding = null ;
357
+ override fun onDestroyView () {
358
+ super .onDestroyView()
359
+ binding = null
372
360
}
373
361
374
- private class ScaleListener extends ScaleGestureDetector . SimpleOnScaleGestureListener {
375
- @Override
376
- public boolean onScale(ScaleGestureDetector detector) {
377
- setGridViewColumns(detector.getScaleFactor());
362
+ private inner class ScaleListener : SimpleOnScaleGestureListener () {
363
+ @SuppressLint( " NotifyDataSetChanged " )
364
+ override fun onScale (detector : ScaleGestureDetector ): Boolean {
365
+ setGridViewColumns(detector.getScaleFactor())
378
366
379
- preferences.setGridColumns(mScale);
367
+ preferences.setGridColumns(mScale)
380
368
381
- getRecyclerView().getAdapter() .notifyDataSetChanged();
369
+ recyclerView.adapter? .notifyDataSetChanged()
382
370
383
- return true ;
371
+ return true
384
372
}
385
373
}
386
374
387
- protected void setGridViewColumns(float scaleFactor) {
388
- if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager gridLayoutManager) {
375
+ @SuppressLint(" NotifyDataSetChanged" )
376
+ protected open fun setGridViewColumns (scaleFactor : Float ) {
377
+ if (mRecyclerView?.layoutManager is GridLayoutManager ) {
378
+ val gridLayoutManager = mRecyclerView?.layoutManager as GridLayoutManager
389
379
if (mScale == - 1f ) {
390
- gridLayoutManager.setSpanCount(GridView .AUTO_FIT );
391
- mScale = gridLayoutManager.getSpanCount();
380
+ gridLayoutManager.setSpanCount(GridView .AUTO_FIT )
381
+ mScale = gridLayoutManager.spanCount.toFloat()
392
382
}
393
- mScale * = 1 .f - (scaleFactor - 1 .f);
394
- mScale = Math . max(minColumnSize, Math . min(mScale, maxColumnSize));
395
- Integer scaleInt = Math .round(mScale);
396
- gridLayoutManager.setSpanCount(scaleInt);
397
- mRecyclerView.getAdapter() .notifyDataSetChanged();
383
+ mScale * = 1f - (scaleFactor - 1f )
384
+ mScale = max(MIN_COLUMN_SIZE .toDouble(), min(mScale.toDouble() , maxColumnSize.toDouble())).toFloat()
385
+ val scaleInt = mScale.roundToInt()
386
+ gridLayoutManager.setSpanCount(scaleInt)
387
+ mRecyclerView?.adapter? .notifyDataSetChanged()
398
388
}
399
389
}
400
390
401
- protected void setupEmptyList(View view) {
402
- mEmptyListContainer = binding.emptyList.emptyListView;
403
- mEmptyListMessage = binding.emptyList.emptyListViewText;
404
- mEmptyListHeadline = binding.emptyList.emptyListViewHeadline;
405
- mEmptyListIcon = binding.emptyList.emptyListIcon;
391
+ protected fun setupEmptyList () {
392
+ binding?.emptyList?.run {
393
+ mEmptyListContainer = emptyListView
394
+ mEmptyListMessage = emptyListViewText
395
+ mEmptyListHeadline = emptyListViewHeadline
396
+ mEmptyListIcon = emptyListIcon
397
+ }
406
398
}
407
399
408
- @Override
409
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
410
- super .onViewCreated(view, savedInstanceState);
400
+ override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
401
+ super .onViewCreated(view, savedInstanceState)
411
402
if (savedInstanceState == null ) {
412
- return ;
403
+ return
413
404
}
414
405
415
- mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES );
416
- mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS );
417
- mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS );
418
- mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL );
419
- setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE ));
406
+ mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES )
407
+ mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS )
408
+ mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS )
409
+ mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL )
410
+ setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE ))
420
411
421
- if (savedInstanceState.getBoolean(KEY_IS_GRID_VISIBLE , false ) && getRecyclerView().getAdapter() != null ) {
422
- switchToGridView();
412
+ if (savedInstanceState.getBoolean(KEY_IS_GRID_VISIBLE , false ) && recyclerView.adapter != null ) {
413
+ switchToGridView()
423
414
}
424
415
425
- int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION );
426
- Log_OC .v(TAG , " Setting grid position " + referencePosition);
427
- scrollToPosition(referencePosition);
416
+ val referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION )
417
+ Log_OC .v(TAG , " Setting grid position $ referencePosition" )
418
+ scrollToPosition(referencePosition)
428
419
}
429
420
430
- @Override
431
- public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
432
- super .onSaveInstanceState(savedInstanceState);
433
- Log_OC .d(TAG , " onSaveInstanceState()" );
434
- savedInstanceState.putBoolean(KEY_IS_GRID_VISIBLE , isGridEnabled());
435
- savedInstanceState.putIntegerArrayList(KEY_INDEXES , mIndexes);
436
- savedInstanceState.putIntegerArrayList(KEY_FIRST_POSITIONS , mFirstPositions);
437
- savedInstanceState.putIntegerArrayList(KEY_TOPS , mTops);
438
- savedInstanceState.putInt(KEY_HEIGHT_CELL , mHeightCell);
439
- savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE , getEmptyViewText());
421
+ override fun onSaveInstanceState (savedInstanceState : Bundle ) {
422
+ super .onSaveInstanceState(savedInstanceState)
423
+ Log_OC .d(TAG , " onSaveInstanceState()" )
424
+
425
+ savedInstanceState.run {
426
+ putBoolean(KEY_IS_GRID_VISIBLE , isGridEnabled)
427
+ putIntegerArrayList(KEY_INDEXES , mIndexes)
428
+ putIntegerArrayList(KEY_FIRST_POSITIONS , mFirstPositions)
429
+ putIntegerArrayList(KEY_TOPS , mTops)
430
+ putInt(KEY_HEIGHT_CELL , mHeightCell)
431
+ putString(KEY_EMPTY_LIST_MESSAGE , emptyViewText)
432
+ }
440
433
441
- preferences.setGridColumns(mScale);
434
+ preferences.setGridColumns(mScale)
442
435
}
443
436
444
- public int getColumnsCount() {
445
- if (mScale == - 1 ) {
446
- return Math .round(AppPreferencesImpl .DEFAULT_GRID_COLUMN );
437
+ open val columnsCount: Int
438
+ get() {
439
+ if (mScale == - 1f ) {
440
+ return AppPreferencesImpl .DEFAULT_GRID_COLUMN .roundToInt()
441
+ }
442
+ return mScale.roundToInt()
447
443
}
448
- return Math .round(mScale);
449
- }
450
444
451
445
/*
452
- * Restore index and position
453
- */
454
- protected void restoreIndexAndTopPosition() {
455
- if (mIndexes == null || mIndexes.isEmpty()) {
456
- Log_OC .d(TAG ," Indexes is null or empty" );
457
- return ;
446
+ * Restore index and position
447
+ */
448
+ protected fun restoreIndexAndTopPosition () {
449
+ if (mIndexes == null || mIndexes? .isEmpty() == true ) {
450
+ Log_OC .d(TAG , " Indexes is null or empty" )
451
+ return
458
452
}
459
453
460
454
// needs to be checked; not every browse-up had a browse-down before
455
+ val index = mIndexes?.removeAt(mIndexes!! .size - 1 )
456
+ val firstPosition = mFirstPositions?.removeAt(mFirstPositions!! .size - 1 )!!
457
+ val top = mTops?.removeAt(mTops!! .size - 1 )
461
458
462
- int index = mIndexes.remove(mIndexes.size() - 1 );
463
- final int firstPosition = mFirstPositions.remove(mFirstPositions.size() - 1 );
464
- int top = mTops.remove(mTops.size() - 1 );
465
-
466
- Log_OC .v(TAG , " Setting selection to position: " + firstPosition + " ; top: "
467
- + top + " ; index: " + index);
459
+ Log_OC .v(
460
+ TAG , (" Setting selection to position: " + firstPosition + " ; top: "
461
+ + top + " ; index: " + index)
462
+ )
468
463
469
- scrollToPosition(firstPosition);
464
+ scrollToPosition(firstPosition)
470
465
}
471
466
472
- private void scrollToPosition(int position) {
473
- LinearLayoutManager linearLayoutManager = ( LinearLayoutManager ) mRecyclerView.getLayoutManager();
467
+ private fun scrollToPosition (position : Int ) {
468
+ val linearLayoutManager = mRecyclerView?.layoutManager as LinearLayoutManager ?
474
469
475
470
if (linearLayoutManager != null ) {
476
- int visibleItemCount = linearLayoutManager.findLastCompletelyVisibleItemPosition() -
477
- linearLayoutManager.findFirstCompletelyVisibleItemPosition();
478
- linearLayoutManager.scrollToPositionWithOffset(position, (visibleItemCount / 2 ) * mHeightCell);
471
+ val visibleItemCount = linearLayoutManager.findLastCompletelyVisibleItemPosition() -
472
+ linearLayoutManager.findFirstCompletelyVisibleItemPosition()
473
+ linearLayoutManager.scrollToPositionWithOffset(position, (visibleItemCount / 2 ) * mHeightCell)
479
474
}
480
475
}
481
476
482
477
/*
483
478
* Save index and top position
484
479
*/
485
- protected void saveIndexAndTopPosition(int index) {
480
+ protected fun saveIndexAndTopPosition (index : Int ) {
486
481
if (mIndexes != null ) {
487
- mIndexes.add(index);
482
+ mIndexes? .add(index)
488
483
}
489
484
490
- RecyclerView .LayoutManager layoutManager = mRecyclerView.getLayoutManager();
491
- int firstPosition;
492
- if (layoutManager instanceof GridLayoutManager ) {
493
- firstPosition = ((GridLayoutManager ) layoutManager).findFirstCompletelyVisibleItemPosition();
485
+ val layoutManager = mRecyclerView?.layoutManager
486
+ val firstPosition: Int = if (layoutManager is GridLayoutManager ) {
487
+ layoutManager.findFirstCompletelyVisibleItemPosition()
494
488
} else {
495
- firstPosition = (( LinearLayoutManager ) layoutManager) .findFirstCompletelyVisibleItemPosition();
489
+ (layoutManager as LinearLayoutManager ).findFirstCompletelyVisibleItemPosition()
496
490
}
497
491
498
- mFirstPositions.add(firstPosition);
492
+ mFirstPositions? .add(firstPosition)
499
493
500
- View view = mRecyclerView.getChildAt(0 );
501
- int top = ( view == null ) ? 0 : view.getTop();
494
+ val view = mRecyclerView? .getChildAt(0 )
495
+ val top = view?.top ? : 0
502
496
503
- mTops.add(top);
497
+ mTops? .add(top)
504
498
505
499
// Save the height of a cell
506
- mHeightCell = (view == null || mHeightCell != 0 ) ? mHeightCell : view.getHeight();
500
+ mHeightCell = if (view == null || mHeightCell != 0 ) mHeightCell else view.height
507
501
}
508
502
509
-
510
- public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {
503
+ override fun onItemClick (parent : AdapterView <* >? , view : View ? , position : Int , id : Long ) {
511
504
// to be @overridden
512
505
}
513
506
514
- @Override
515
- public void onRefresh() {
516
-
507
+ override fun onRefresh () {
517
508
if (searchView != null ) {
518
- searchView.onActionViewCollapsed();
509
+ searchView? .onActionViewCollapsed()
519
510
520
- Activity activity;
521
- if ((activity = getActivity()) != null && activity instanceof FileDisplayActivity fileDisplayActivity ) {
522
- fileDisplayActivity .setDrawerIndicatorEnabled(fileDisplayActivity .isDrawerIndicatorAvailable());
523
- fileDisplayActivity .hideSearchView(fileDisplayActivity .getCurrentDir());
511
+ val activity: Activity ?
512
+ if ((getActivity(). also { activity = it }) != null && activity is FileDisplayActivity ) {
513
+ activity .setDrawerIndicatorEnabled(activity .isDrawerIndicatorAvailable)
514
+ activity .hideSearchView(activity .getCurrentDir())
524
515
}
525
516
}
526
- if (mOnRefreshListener != null ) {
527
- mOnRefreshListener.onRefresh();
528
- }
517
+ mOnRefreshListener?.onRefresh()
529
518
}
530
519
531
- public void setOnRefreshListener(OnEnforceableRefreshListener listener) {
532
- mOnRefreshListener = listener;
520
+ fun setOnRefreshListener (listener : OnEnforceableRefreshListener ? ) {
521
+ mOnRefreshListener = listener
533
522
}
534
523
535
-
536
524
/* *
537
525
* Disables swipe gesture.
538
- * <p>
526
+ *
527
+ *
539
528
* Sets the 'enabled' state of the refresh layouts contained in the fragment.
540
- * <p>
529
+ *
530
+ *
541
531
* When 'false' is set, prevents user gestures but keeps the option to refresh programmatically,
542
532
*
543
533
* @param enabled Desired state for capturing swipe gesture.
544
534
*/
545
- public void setSwipeEnabled(boolean enabled) {
546
- mRefreshListLayout.setEnabled(enabled);
535
+ fun setSwipeEnabled (enabled : Boolean ) {
536
+ mRefreshListLayout? .setEnabled(enabled)
547
537
}
548
538
549
-
550
-
551
539
/* *
552
- * /** Set message for empty list view.
540
+ * / ** Set message for empty list view.
553
541
*/
554
- public void setMessageForEmptyList(String message) {
542
+ fun setMessageForEmptyList (message : String? ) {
555
543
if (mEmptyListContainer != null && mEmptyListMessage != null ) {
556
- mEmptyListMessage.setText( message);
544
+ mEmptyListMessage?.text = message
557
545
}
558
546
}
559
547
@@ -564,9 +552,11 @@ public class ExtendedListFragment extends Fragment implements
564
552
* @param message the message
565
553
* @param icon the icon to be shown
566
554
*/
567
- public void setMessageForEmptyList(@StringRes final int headline, @StringRes final int message,
568
- @DrawableRes final int icon) {
569
- setMessageForEmptyList(headline, message, icon, false);
555
+ fun setMessageForEmptyList (
556
+ @StringRes headline : Int , @StringRes message : Int ,
557
+ @DrawableRes icon : Int
558
+ ) {
559
+ setMessageForEmptyList(headline, message, icon, false )
570
560
}
571
561
572
562
/* *
@@ -577,133 +567,165 @@ public class ExtendedListFragment extends Fragment implements
577
567
* @param icon the icon to be shown
578
568
* @param tintIcon flag if the given icon should be tinted with primary color
579
569
*/
580
- public void setMessageForEmptyList(@StringRes final int headline, @StringRes final int message,
581
- @DrawableRes final int icon, final boolean tintIcon) {
582
- new Handler(Looper.getMainLooper()).post(() -> {
583
-
570
+ fun setMessageForEmptyList (
571
+ @StringRes headline : Int , @StringRes message : Int ,
572
+ @DrawableRes icon : Int , tintIcon : Boolean
573
+ ) {
574
+ Handler (Looper .getMainLooper()).post(Runnable {
584
575
if (mEmptyListContainer != null && mEmptyListMessage != null ) {
585
- mEmptyListHeadline.setText(headline);
586
- mEmptyListMessage.setText(message);
576
+ mEmptyListHeadline? .setText(headline)
577
+ mEmptyListMessage? .setText(message)
587
578
588
579
if (tintIcon) {
589
- if (getContext() != null) {
590
- mEmptyListIcon.setImageDrawable(
591
- viewThemeUtils.platform.tintPrimaryDrawable(getContext(), icon));
580
+ if (context != null ) {
581
+ mEmptyListIcon?.setImageDrawable(
582
+ viewThemeUtils.platform.tintDrawable(requireContext(), icon, ColorRole .PRIMARY )
583
+ )
592
584
}
593
585
} else {
594
- mEmptyListIcon.setImageResource(icon);
586
+ mEmptyListIcon? .setImageResource(icon)
595
587
}
596
588
597
- mEmptyListIcon.setVisibility(View.VISIBLE);
598
- mEmptyListMessage.setVisibility( View.VISIBLE);
589
+ mEmptyListIcon? .setVisibility(View .VISIBLE )
590
+ mEmptyListMessage?.visibility = View .VISIBLE
599
591
}
600
- });
592
+ })
601
593
}
602
594
603
- public void setEmptyListMessage(final SearchType searchType) {
604
- new Handler(Looper.getMainLooper()).post(() -> {
595
+ @Suppress(" LongMethod" )
596
+ fun setEmptyListMessage (searchType : SearchType ? ) {
597
+ Handler (Looper .getMainLooper()).post(Runnable {
605
598
if (searchType == SearchType .OFFLINE_MODE ) {
606
- setMessageForEmptyList(R.string.offline_mode_info_title,
607
- R.string.offline_mode_info_description,
608
- R.drawable.ic_cloud_sync,
609
- true);
599
+ setMessageForEmptyList(
600
+ R .string.offline_mode_info_title,
601
+ R .string.offline_mode_info_description,
602
+ R .drawable.ic_cloud_sync,
603
+ true
604
+ )
610
605
} else if (searchType == SearchType .NO_SEARCH ) {
611
- setMessageForEmptyList(R.string.file_list_empty_headline,
612
- R.string.file_list_empty,
613
- R.drawable.ic_list_empty_folder,
614
- true);
606
+ setMessageForEmptyList(
607
+ R .string.file_list_empty_headline,
608
+ R .string.file_list_empty,
609
+ R .drawable.ic_list_empty_folder,
610
+ true
611
+ )
615
612
} else if (searchType == SearchType .FILE_SEARCH ) {
616
- setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
617
- R.string.file_list_empty,
618
- R.drawable.ic_search_light_grey);
613
+ setMessageForEmptyList(
614
+ R .string.file_list_empty_headline_server_search,
615
+ R .string.file_list_empty,
616
+ R .drawable.ic_search_light_grey
617
+ )
619
618
} else if (searchType == SearchType .FAVORITE_SEARCH ) {
620
- setMessageForEmptyList(R.string.file_list_empty_favorite_headline,
621
- R.string.file_list_empty_favorites_filter_list,
622
- R.drawable.ic_star_light_yellow);
619
+ setMessageForEmptyList(
620
+ R .string.file_list_empty_favorite_headline,
621
+ R .string.file_list_empty_favorites_filter_list,
622
+ R .drawable.ic_star_light_yellow
623
+ )
623
624
} else if (searchType == SearchType .RECENTLY_MODIFIED_SEARCH ) {
624
- setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
625
- R.string.file_list_empty_recently_modified,
626
- R.drawable.ic_list_empty_recent);
625
+ setMessageForEmptyList(
626
+ R .string.file_list_empty_headline_server_search,
627
+ R .string.file_list_empty_recently_modified,
628
+ R .drawable.ic_list_empty_recent
629
+ )
627
630
} else if (searchType == SearchType .REGULAR_FILTER ) {
628
- setMessageForEmptyList(R.string.file_list_empty_headline_search,
629
- R.string.file_list_empty_search,
630
- R.drawable.ic_search_light_grey);
631
+ setMessageForEmptyList(
632
+ R .string.file_list_empty_headline_search,
633
+ R .string.file_list_empty_search,
634
+ R .drawable.ic_search_light_grey
635
+ )
631
636
} else if (searchType == SearchType .SHARED_FILTER ) {
632
- setMessageForEmptyList(R.string.file_list_empty_shared_headline,
633
- R.string.file_list_empty_shared,
634
- R.drawable.ic_list_empty_shared);
637
+ setMessageForEmptyList(
638
+ R .string.file_list_empty_shared_headline,
639
+ R .string.file_list_empty_shared,
640
+ R .drawable.ic_list_empty_shared
641
+ )
635
642
} else if (searchType == SearchType .GALLERY_SEARCH ) {
636
- setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
637
- R.string.file_list_empty_gallery,
638
- R.drawable.file_image);
643
+ setMessageForEmptyList(
644
+ R .string.file_list_empty_headline_server_search,
645
+ R .string.file_list_empty_gallery,
646
+ R .drawable.file_image
647
+ )
639
648
} else if (searchType == SearchType .LOCAL_SEARCH ) {
640
- setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
641
- R.string.file_list_empty_local_search,
642
- R.drawable.ic_search_light_grey);
649
+ setMessageForEmptyList(
650
+ R .string.file_list_empty_headline_server_search,
651
+ R .string.file_list_empty_local_search,
652
+ R .drawable.ic_search_light_grey
653
+ )
643
654
}
644
- });
655
+ })
645
656
}
646
657
647
658
/* *
648
659
* Set message for empty list view.
649
660
*/
650
- public void setEmptyListLoadingMessage() {
651
- new Handler(Looper.getMainLooper()).post(() -> {
652
- FileActivity fileActivity = FragmentExtensionsKt.getTypedActivity(this, FileActivity.class);
653
- if (fileActivity != null) {
654
- fileActivity.connectivityService.isNetworkAndServerAvailable(result -> {
655
- if (!result || mEmptyListContainer == null || mEmptyListMessage == null) return;
656
-
657
- mEmptyListHeadline.setText(R.string.file_list_loading);
658
- mEmptyListMessage.setText("");
659
- mEmptyListIcon.setVisibility(View.GONE);
660
- });
661
- }
662
- });
663
- }
664
-
665
- /**
666
- * Get the text of EmptyListMessage TextView.
667
- *
668
- * @return String empty text view text-value
669
- */
670
- public String getEmptyViewText() {
671
- return (mEmptyListContainer != null && mEmptyListMessage != null) ? mEmptyListMessage.getText().toString() : "";
672
- }
673
-
674
- @Override
675
- public void onRefresh(boolean ignoreETag) {
661
+ fun setEmptyListLoadingMessage () {
662
+ Handler (Looper .getMainLooper()).post(Runnable {
663
+ val fileActivity = getTypedActivity<FileActivity >(FileActivity ::class .java)
664
+ fileActivity?.connectivityService?.isNetworkAndServerAvailable(GenericCallback { result: Boolean? ->
665
+ if (result == false || mEmptyListContainer == null || mEmptyListMessage == null ) return @GenericCallback
666
+ mEmptyListHeadline?.setText(R .string.file_list_loading)
667
+ mEmptyListMessage?.text = " "
668
+ mEmptyListIcon?.setVisibility(View .GONE )
669
+ })
670
+ })
671
+ }
672
+
673
+ val emptyViewText: String
674
+ /* *
675
+ * Get the text of EmptyListMessage TextView.
676
+ *
677
+ * @return String empty text view text-value
678
+ */
679
+ get() = if (mEmptyListContainer != null && mEmptyListMessage != null ) mEmptyListMessage?.getText()
680
+ .toString() else " "
681
+
682
+ override fun onRefresh (ignoreETag : Boolean ) {
676
683
if (mOnRefreshListener != null ) {
677
- if (mOnRefreshListener instanceof FileDisplayActivity) {
678
- (( FileDisplayActivity) mOnRefreshListener) .onRefresh(ignoreETag);
684
+ if (mOnRefreshListener is FileDisplayActivity ) {
685
+ (mOnRefreshListener as FileDisplayActivity ).onRefresh(ignoreETag)
679
686
} else {
680
- mOnRefreshListener.onRefresh();
687
+ mOnRefreshListener? .onRefresh()
681
688
}
682
689
}
683
690
}
684
691
685
- @Override
686
- public void onConfigurationChanged(@NonNull Configuration newConfig) {
687
- super.onConfigurationChanged(newConfig);
692
+ override fun onConfigurationChanged (newConfig : Configuration ) {
693
+ super .onConfigurationChanged(newConfig)
688
694
689
695
if (newConfig.orientation == Configuration .ORIENTATION_LANDSCAPE ) {
690
- maxColumnSize = 10;
696
+ maxColumnSize = 10
691
697
} else if (newConfig.orientation == Configuration .ORIENTATION_PORTRAIT ) {
692
- maxColumnSize = 5;
698
+ maxColumnSize = 5
693
699
}
694
700
695
- if (isGridEnabled() && getColumnsCount() > maxColumnSize) {
696
- (( GridLayoutManager) getRecyclerView().getLayoutManager()). setSpanCount(maxColumnSize);
701
+ if (isGridEnabled && columnsCount > maxColumnSize) {
702
+ (recyclerView.layoutManager as GridLayoutManager ). setSpanCount(maxColumnSize)
697
703
}
698
704
}
699
705
700
- protected void setGridSwitchButton() {
701
- if (isGridEnabled()) {
702
- mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_list_view));
703
- mSwitchGridViewButton.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_list));
704
- } else {
705
- mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_grid_view));
706
- mSwitchGridViewButton.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_module));
706
+ protected fun setGridSwitchButton () {
707
+ mSwitchGridViewButton?.let {
708
+ if (isGridEnabled) {
709
+ it.setContentDescription(getString(R .string.action_switch_list_view))
710
+ it.setIcon(ContextCompat .getDrawable(requireContext(), R .drawable.ic_view_list))
711
+ } else {
712
+ it.setContentDescription(getString(R .string.action_switch_grid_view))
713
+ it.setIcon(ContextCompat .getDrawable(requireContext(), R .drawable.ic_view_module))
714
+ }
707
715
}
708
716
}
717
+
718
+ companion object {
719
+ protected val TAG : String = ExtendedListFragment ::class .java.getSimpleName()
720
+
721
+ protected const val KEY_SAVED_LIST_POSITION : String = " SAVED_LIST_POSITION"
722
+
723
+ private const val KEY_INDEXES = " INDEXES"
724
+ private const val KEY_FIRST_POSITIONS = " FIRST_POSITIONS"
725
+ private const val KEY_TOPS = " TOPS"
726
+ private const val KEY_HEIGHT_CELL = " HEIGHT_CELL"
727
+ private const val KEY_EMPTY_LIST_MESSAGE = " EMPTY_LIST_MESSAGE"
728
+ private const val KEY_IS_GRID_VISIBLE = " IS_GRID_VISIBLE"
729
+ private const val MIN_COLUMN_SIZE : Float = 2.0f
730
+ }
709
731
}
0 commit comments