[app] Refactored list activity
This commit is contained in:
parent
bcb783586e
commit
4f3653bb3a
|
|
@ -40,14 +40,11 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.Filterable;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
|
||||||
import androidx.appcompat.widget.SearchView;
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
@ -63,20 +60,14 @@ import java.util.List;
|
||||||
import io.github.lsposed.manager.Constants;
|
import io.github.lsposed.manager.Constants;
|
||||||
import io.github.lsposed.manager.R;
|
import io.github.lsposed.manager.R;
|
||||||
import io.github.lsposed.manager.adapters.AppHelper;
|
import io.github.lsposed.manager.adapters.AppHelper;
|
||||||
import io.github.lsposed.manager.databinding.ActivityListBinding;
|
import io.github.lsposed.manager.ui.activity.base.ListActivity;
|
||||||
import io.github.lsposed.manager.ui.activity.base.BaseActivity;
|
|
||||||
import io.github.lsposed.manager.util.GlideApp;
|
import io.github.lsposed.manager.util.GlideApp;
|
||||||
import io.github.lsposed.manager.util.LinearLayoutManagerFix;
|
|
||||||
import io.github.lsposed.manager.util.ModuleUtil;
|
import io.github.lsposed.manager.util.ModuleUtil;
|
||||||
import rikka.recyclerview.RecyclerViewKt;
|
|
||||||
|
|
||||||
import static android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
|
import static android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
|
||||||
|
|
||||||
public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleListener {
|
public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleListener {
|
||||||
|
|
||||||
ActivityListBinding binding;
|
|
||||||
private SearchView searchView;
|
|
||||||
private SearchView.OnQueryTextListener mSearchListener;
|
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private ModuleUtil moduleUtil;
|
private ModuleUtil moduleUtil;
|
||||||
private ModuleAdapter adapter = null;
|
private ModuleAdapter adapter = null;
|
||||||
|
|
@ -84,40 +75,10 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
binding = ActivityListBinding.inflate(getLayoutInflater());
|
|
||||||
setContentView(binding.getRoot());
|
|
||||||
setAppBar(binding.appBar, binding.toolbar);
|
|
||||||
binding.getRoot().bringChildToFront(binding.appBar);
|
|
||||||
binding.toolbar.setNavigationOnClickListener(view -> onBackPressed());
|
|
||||||
binding.recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> binding.appBar.setRaised(!top));
|
|
||||||
ActionBar bar = getSupportActionBar();
|
|
||||||
if (bar != null) {
|
|
||||||
bar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
}
|
|
||||||
moduleUtil = ModuleUtil.getInstance();
|
moduleUtil = ModuleUtil.getInstance();
|
||||||
pm = getPackageManager();
|
pm = getPackageManager();
|
||||||
adapter = new ModuleAdapter();
|
|
||||||
adapter.setHasStableIds(true);
|
|
||||||
moduleUtil.addListener(this);
|
moduleUtil.addListener(this);
|
||||||
binding.recyclerView.setAdapter(adapter);
|
super.onCreate(savedInstanceState);
|
||||||
binding.recyclerView.setHasFixedSize(true);
|
|
||||||
binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this));
|
|
||||||
RecyclerViewKt.addFastScroller(binding.recyclerView, binding.recyclerView);
|
|
||||||
RecyclerViewKt.fixEdgeEffect(binding.recyclerView, false, true);
|
|
||||||
mSearchListener = new SearchView.OnQueryTextListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
adapter.getFilter().filter(query);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
adapter.getFilter().filter(newText);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -129,8 +90,6 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_modules, menu);
|
getMenuInflater().inflate(R.menu.menu_modules, menu);
|
||||||
searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
|
|
||||||
searchView.setOnQueryTextListener(mSearchListener);
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,15 +144,11 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
protected BaseAdapter<?> createAdapter() {
|
||||||
if (searchView.isIconified()) {
|
return adapter = new ModuleAdapter();
|
||||||
super.onBackPressed();
|
|
||||||
} else {
|
|
||||||
searchView.setIconified(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ModuleAdapter extends RecyclerView.Adapter<ModuleAdapter.ViewHolder> implements Filterable {
|
private class ModuleAdapter extends BaseAdapter<ModuleAdapter.ViewHolder> {
|
||||||
private List<ModuleUtil.InstalledModule> fullList, showList;
|
private List<ModuleUtil.InstalledModule> fullList, showList;
|
||||||
|
|
||||||
ModuleAdapter() {
|
ModuleAdapter() {
|
||||||
|
|
@ -324,7 +279,6 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
showList = fullList;
|
showList = fullList;
|
||||||
//binding.swipeRefreshLayout.setRefreshing(false);
|
|
||||||
String queryStr = searchView != null ? searchView.getQuery().toString() : "";
|
String queryStr = searchView != null ? searchView.getQuery().toString() : "";
|
||||||
runOnUiThread(() -> getFilter().filter(queryStr));
|
runOnUiThread(() -> getFilter().filter(queryStr));
|
||||||
moduleUtil.updateModulesList();
|
moduleUtil.updateModulesList();
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,10 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.Filterable;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
|
||||||
import androidx.appcompat.widget.SearchView;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -46,54 +43,23 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import io.github.lsposed.manager.R;
|
import io.github.lsposed.manager.R;
|
||||||
import io.github.lsposed.manager.databinding.ActivityListBinding;
|
|
||||||
import io.github.lsposed.manager.repo.RepoLoader;
|
import io.github.lsposed.manager.repo.RepoLoader;
|
||||||
import io.github.lsposed.manager.repo.model.OnlineModule;
|
import io.github.lsposed.manager.repo.model.OnlineModule;
|
||||||
import io.github.lsposed.manager.ui.activity.base.BaseActivity;
|
import io.github.lsposed.manager.ui.activity.base.ListActivity;
|
||||||
import io.github.lsposed.manager.util.LinearLayoutManagerFix;
|
|
||||||
import rikka.recyclerview.RecyclerViewKt;
|
|
||||||
|
|
||||||
public class RepoActivity extends BaseActivity implements RepoLoader.Listener {
|
public class RepoActivity extends ListActivity implements RepoLoader.Listener {
|
||||||
private final RepoLoader repoLoader = RepoLoader.getInstance();
|
private final RepoLoader repoLoader = RepoLoader.getInstance();
|
||||||
private SearchView searchView;
|
|
||||||
private SearchView.OnQueryTextListener searchListener;
|
|
||||||
private ActivityListBinding binding;
|
|
||||||
private RepoAdapter adapter;
|
private RepoAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
binding = ActivityListBinding.inflate(getLayoutInflater());
|
|
||||||
setContentView(binding.getRoot());
|
|
||||||
setAppBar(binding.appBar, binding.toolbar);
|
|
||||||
binding.getRoot().bringChildToFront(binding.appBar);
|
|
||||||
binding.toolbar.setNavigationOnClickListener(view -> onBackPressed());
|
|
||||||
binding.recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> binding.appBar.setRaised(!top));
|
|
||||||
ActionBar bar = getSupportActionBar();
|
|
||||||
assert bar != null;
|
|
||||||
bar.setDisplayHomeAsUpEnabled(true);
|
|
||||||
adapter = new RepoAdapter();
|
|
||||||
adapter.setHasStableIds(true);
|
|
||||||
binding.recyclerView.setAdapter(adapter);
|
|
||||||
binding.recyclerView.setHasFixedSize(true);
|
|
||||||
binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this));
|
|
||||||
binding.progress.setVisibilityAfterHide(View.GONE);
|
|
||||||
RecyclerViewKt.addFastScroller(binding.recyclerView, binding.recyclerView);
|
|
||||||
RecyclerViewKt.fixEdgeEffect(binding.recyclerView, false, true);
|
|
||||||
repoLoader.addListener(this);
|
repoLoader.addListener(this);
|
||||||
searchListener = new SearchView.OnQueryTextListener() {
|
super.onCreate(savedInstanceState);
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
adapter.getFilter().filter(query);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
protected BaseAdapter<?> createAdapter() {
|
||||||
adapter.getFilter().filter(newText);
|
return adapter = new RepoAdapter();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -129,12 +95,10 @@ public class RepoActivity extends BaseActivity implements RepoLoader.Listener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_repo, menu);
|
getMenuInflater().inflate(R.menu.menu_repo, menu);
|
||||||
searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
|
|
||||||
searchView.setOnQueryTextListener(searchListener);
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RepoAdapter extends RecyclerView.Adapter<RepoAdapter.ViewHolder> implements Filterable {
|
private class RepoAdapter extends BaseAdapter<RepoAdapter.ViewHolder> {
|
||||||
private List<OnlineModule> fullList, showList;
|
private List<OnlineModule> fullList, showList;
|
||||||
|
|
||||||
RepoAdapter() {
|
RepoAdapter() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
* This file is part of LSPosed.
|
||||||
|
*
|
||||||
|
* LSPosed 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.
|
||||||
|
*
|
||||||
|
* LSPosed 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 LSPosed. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 EdXposed Contributors
|
||||||
|
* Copyright (C) 2021 LSPosed Contributors
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.github.lsposed.manager.ui.activity.base;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Filterable;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.appcompat.widget.SearchView;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import io.github.lsposed.manager.R;
|
||||||
|
import io.github.lsposed.manager.databinding.ActivityListBinding;
|
||||||
|
import io.github.lsposed.manager.util.LinearLayoutManagerFix;
|
||||||
|
import rikka.recyclerview.RecyclerViewKt;
|
||||||
|
|
||||||
|
public abstract class ListActivity extends BaseActivity {
|
||||||
|
|
||||||
|
protected ActivityListBinding binding;
|
||||||
|
protected SearchView searchView;
|
||||||
|
private SearchView.OnQueryTextListener mSearchListener;
|
||||||
|
private BaseAdapter<?> adapter = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
binding = ActivityListBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
|
setAppBar(binding.appBar, binding.toolbar);
|
||||||
|
binding.getRoot().bringChildToFront(binding.appBar);
|
||||||
|
binding.toolbar.setNavigationOnClickListener(view -> onBackPressed());
|
||||||
|
binding.recyclerView.getBorderViewDelegate().setBorderVisibilityChangedListener((top, oldTop, bottom, oldBottom) -> binding.appBar.setRaised(!top));
|
||||||
|
ActionBar bar = getSupportActionBar();
|
||||||
|
if (bar != null) {
|
||||||
|
bar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
adapter = createAdapter();
|
||||||
|
adapter.setHasStableIds(true);
|
||||||
|
binding.recyclerView.setAdapter(adapter);
|
||||||
|
binding.recyclerView.setHasFixedSize(true);
|
||||||
|
binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this));
|
||||||
|
RecyclerViewKt.addFastScroller(binding.recyclerView, binding.recyclerView);
|
||||||
|
RecyclerViewKt.fixEdgeEffect(binding.recyclerView, false, true);
|
||||||
|
binding.progress.setVisibilityAfterHide(View.GONE);
|
||||||
|
mSearchListener = new SearchView.OnQueryTextListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextSubmit(String query) {
|
||||||
|
adapter.getFilter().filter(query);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextChange(String newText) {
|
||||||
|
adapter.getFilter().filter(newText);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
|
||||||
|
searchView.setOnQueryTextListener(mSearchListener);
|
||||||
|
return super.onPrepareOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (searchView.isIconified()) {
|
||||||
|
super.onBackPressed();
|
||||||
|
} else {
|
||||||
|
searchView.setIconified(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract static class BaseAdapter<T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> implements Filterable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract BaseAdapter<?> createAdapter();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue