Replace fragment by FragmentContainerView

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-06-23 12:20:31 +02:00
parent 212b3a6ef9
commit 32a0d1c309
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
10 changed files with 49 additions and 53 deletions

View file

@ -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'

View file

@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 85 warnings</span>
<span class="mdl-layout-title">Lint Report: 86 warnings</span>

View file

@ -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
}

View file

@ -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
}

View file

@ -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);
}

View file

@ -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));
}
}
}

View file

@ -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);
}

View file

@ -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).

View file

@ -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);
}

View file

@ -25,9 +25,10 @@
<include layout="@layout/toolbar_standard" />
<fragment
android:id="@+id/local_files_list"
class="com.owncloud.android.ui.fragment.LocalFileListFragment"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/local_files_list_container"
android:name="com.owncloud.android.ui.fragment.LocalFileListFragment"
android:tag="local_files_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />