diff --git a/build.gradle b/build.gradle index 9248070398..7ea9314d0b 100644 --- a/build.gradle +++ b/build.gradle @@ -295,6 +295,7 @@ dependencies { implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" implementation "androidx.work:work-runtime:2.3.4" implementation "androidx.work:work-runtime-ktx:2.3.4" + implementation "androidx.fragment:fragment:1.2.5" implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7 compileOnly 'com.google.code.findbugs:annotations:2.0.1' implementation 'commons-io:commons-io:2.7' diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index bf24c5db3f..f7531aa09b 100644 --- a/scripts/analysis/lint-results.txt +++ b/scripts/analysis/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 85 warnings + Lint Report: 86 warnings diff --git a/src/main/java/com/nextcloud/client/etm/EtmMenuFragment.kt b/src/main/java/com/nextcloud/client/etm/EtmMenuFragment.kt index bb1db79536..019f6cca08 100644 --- a/src/main/java/com/nextcloud/client/etm/EtmMenuFragment.kt +++ b/src/main/java/com/nextcloud/client/etm/EtmMenuFragment.kt @@ -33,11 +33,11 @@ class EtmMenuFragment : EtmBaseFragment() { private lateinit var list: RecyclerView override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - adapter = EtmMenuAdapter(context!!, this::onClickedItem) + adapter = EtmMenuAdapter(requireContext(), this::onClickedItem) adapter.pages = vm.pages val view = inflater.inflate(R.layout.fragment_etm_menu, container, false) list = view.findViewById(R.id.etm_menu_list) - list.layoutManager = LinearLayoutManager(context!!) + list.layoutManager = LinearLayoutManager(requireContext()) list.adapter = adapter return view } diff --git a/src/main/java/com/nextcloud/client/etm/pages/EtmBackgroundJobsFragment.kt b/src/main/java/com/nextcloud/client/etm/pages/EtmBackgroundJobsFragment.kt index 5febc07097..725627cb66 100644 --- a/src/main/java/com/nextcloud/client/etm/pages/EtmBackgroundJobsFragment.kt +++ b/src/main/java/com/nextcloud/client/etm/pages/EtmBackgroundJobsFragment.kt @@ -112,7 +112,7 @@ class EtmBackgroundJobsFragment : EtmBaseFragment() { list.layoutManager = LinearLayoutManager(context) list.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL)) list.adapter = adapter - vm.backgroundJobs.observe(this, Observer { onBackgroundJobsUpdated(it) }) + vm.backgroundJobs.observe(viewLifecycleOwner, Observer { onBackgroundJobsUpdated(it) }) return view } diff --git a/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java b/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java index aa00757e3f..59438dd0a6 100644 --- a/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -21,6 +21,7 @@ package com.owncloud.android.ui.activity; import android.accounts.Account; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.content.res.ColorStateList; @@ -51,7 +52,6 @@ import com.owncloud.android.ui.dialog.LocalStoragePathPickerDialogFragment; import com.owncloud.android.ui.dialog.SortingOrderDialogFragment; import com.owncloud.android.ui.fragment.ExtendedListFragment; import com.owncloud.android.ui.fragment.LocalFileListFragment; -import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileSortOrder; import com.owncloud.android.utils.ThemeUtils; @@ -64,14 +64,11 @@ import javax.inject.Inject; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; -import androidx.core.content.res.ResourcesCompat; import androidx.core.view.MenuItemCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; -import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment; - /** * Displays local files and let the user choose what of them wants to upload to the current ownCloud account. */ @@ -107,7 +104,6 @@ public class UploadFilesActivity extends FileActivity implements LocalFileListFr private Menu mOptionsMenu; private SearchView mSearchView; private Spinner mBehaviourSpinner; - private MaterialButton sortButton; /** * Helper to launch the UploadFilesActivity for which you would like a result when it finished. Your @@ -125,6 +121,7 @@ public class UploadFilesActivity extends FileActivity implements LocalFileListFr } @Override + @SuppressLint("WrongViewCast") // wrong error on finding local_files_list public void onCreate(Bundle savedInstanceState) { Log_OC.d(TAG, "onCreate() start"); super.onCreate(savedInstanceState); @@ -170,7 +167,7 @@ public class UploadFilesActivity extends FileActivity implements LocalFileListFr ((MaterialButton) findViewById(R.id.upload_files_btn_upload)).setText(R.string.uploader_btn_alternative_text); } - mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentById(R.id.local_files_list); + mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentByTag("local_files_list"); // Set input controllers MaterialButton cancelButton = findViewById(R.id.upload_files_btn_cancel); @@ -181,27 +178,6 @@ public class UploadFilesActivity extends FileActivity implements LocalFileListFr ThemeUtils.colorPrimaryButton(uploadButton, this); uploadButton.setOnClickListener(this); - sortButton = findViewById(R.id.sort_button); - FileSortOrder fileSortOrder = preferences.getSortOrderByType(FileSortOrder.Type.uploadFilesView); - sortButton.setText(DisplayUtils.getSortOrderStringId(fileSortOrder)); - sortButton.setOnClickListener(l -> openSortingOrderDialogFragment(getSupportFragmentManager(), fileSortOrder)); - - MaterialButton switchButton = findViewById(R.id.switch_grid_view_button); - switchButton.setOnClickListener(l -> { - if (isGridView()) { - switchButton.setIcon(ResourcesCompat.getDrawable(getResources(), - R.drawable.ic_view_module, - null)); - mFileListFragment.switchToListView(); - } else { - switchButton.setIcon(ResourcesCompat.getDrawable(getResources(), - R.drawable.ic_view_list, - null)); - mFileListFragment.switchToGridView(); - - } - }); - int localBehaviour = preferences.getUploaderBehaviour(); // file upload spinner @@ -339,7 +315,6 @@ public class UploadFilesActivity extends FileActivity implements LocalFileListFr @Override public void onSortingOrderChosen(FileSortOrder selection) { preferences.setSortOrder(FileSortOrder.Type.uploadFilesView, selection); - sortButton.setText(DisplayUtils.getSortOrderStringId(selection)); mFileListFragment.sortFiles(selection); } diff --git a/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java index dcdd585bbc..b80eccc781 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -82,6 +82,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.appcompat.widget.SearchView; +import androidx.core.content.ContextCompat; import androidx.core.view.MenuItemCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; @@ -188,7 +189,7 @@ public class ExtendedListFragment extends Fragment implements } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) { final MenuItem item = menu.findItem(R.id.action_search); searchView = (SearchView) MenuItemCompat.getActionView(item); closeButton = searchView.findViewById(androidx.appcompat.R.id.search_close_btn); @@ -748,4 +749,14 @@ public class ExtendedListFragment extends Fragment implements ((GridLayoutManager) getRecyclerView().getLayoutManager()).setSpanCount(maxColumnSize); } } + + protected void setGridSwitchButton() { + if (isGridEnabled()) { + mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_list_view)); + mSwitchGridViewButton.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_list)); + } else { + mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_grid_view)); + mSwitchGridViewButton.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_module)); + } + } } diff --git a/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java index 835e2829f6..1fa2f1e558 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@ -36,6 +36,7 @@ import com.owncloud.android.R; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.adapter.LocalFileListAdapter; import com.owncloud.android.ui.interfaces.LocalFileListFragmentInterface; +import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileSortOrder; import java.io.File; @@ -46,13 +47,15 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFragment; + /** * A Fragment that lists all files and folders in a given LOCAL path. */ public class LocalFileListFragment extends ExtendedListFragment implements - LocalFileListFragmentInterface, - Injectable { + LocalFileListFragmentInterface, + Injectable { private static final String TAG = LocalFileListFragment.class.getSimpleName(); @@ -82,13 +85,13 @@ public class LocalFileListFragment extends ExtendedListFragment implements * {@inheritDoc} */ @Override - public void onAttach(Activity activity) { + public void onAttach(@NonNull Activity activity) { super.onAttach(activity); try { mContainerActivity = (ContainerActivity) activity; } catch (ClassCastException e) { throw new IllegalArgumentException(activity.toString() + " must implement " + - LocalFileListFragment.ContainerActivity.class.getSimpleName(), e); + LocalFileListFragment.ContainerActivity.class.getSimpleName(), e); } } @@ -125,11 +128,25 @@ public class LocalFileListFragment extends ExtendedListFragment implements super.onActivityCreated(savedInstanceState); mAdapter = new LocalFileListAdapter(mContainerActivity.isFolderPickerMode(), - mContainerActivity.getInitialDirectory(), this, preferences, getActivity()); + mContainerActivity.getInitialDirectory(), this, preferences, getActivity()); setRecyclerViewAdapter(mAdapter); listDirectory(mContainerActivity.getInitialDirectory()); + FileSortOrder sortOrder = preferences.getSortOrderByType(FileSortOrder.Type.uploadFilesView); + mSortButton.setOnClickListener(v -> openSortingOrderDialogFragment(requireFragmentManager(), sortOrder)); + mSortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder)); + + setGridSwitchButton(); + mSwitchGridViewButton.setOnClickListener(v -> { + if (isGridEnabled()) { + switchToListView(); + } else { + switchToGridView(); + } + setGridSwitchButton(); + }); + Log_OC.i(TAG, "onActivityCreated() stop"); } @@ -137,7 +154,7 @@ public class LocalFileListFragment extends ExtendedListFragment implements * {@inheritDoc} */ @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) { if (mContainerActivity.isFolderPickerMode()) { menu.removeItem(R.id.action_select_all); menu.removeItem(R.id.action_search); @@ -265,6 +282,7 @@ public class LocalFileListFragment extends ExtendedListFragment implements } public void sortFiles(FileSortOrder sortOrder) { + mSortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder)); mAdapter.setSortOrder(sortOrder); } diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 935083d1ee..e01f6758df 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -1315,16 +1315,6 @@ public class OCFileListFragment extends ExtendedListFragment implements mAdapter.setSortOrder(mFile, sortOrder); } - private void setGridSwitchButton() { - if (isGridEnabled()) { - mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_list_view)); - mSwitchGridViewButton.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_list)); - } else { - mSwitchGridViewButton.setContentDescription(getString(R.string.action_switch_grid_view)); - mSwitchGridViewButton.setIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_view_module)); - } - } - /** * Determines if user set folder to grid or list view. If folder is not set itself, * it finds a parent that is set (at least root is set). diff --git a/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java index 0958093e24..c48381dcf3 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java @@ -162,7 +162,7 @@ public class ContactListFragment extends FileFragment implements Injectable { * {@inheritDoc} */ @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.fragment_contact_list, menu); } diff --git a/src/main/res/layout/upload_files_layout.xml b/src/main/res/layout/upload_files_layout.xml index 72dbd78525..03c214e504 100644 --- a/src/main/res/layout/upload_files_layout.xml +++ b/src/main/res/layout/upload_files_layout.xml @@ -25,9 +25,10 @@ -