parent
8ac3aaf36c
commit
f36ce905aa
@ -58,7 +58,7 @@ public class MainActivity extends BaseActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
new MainActivity_ViewBinding(this);
|
||||
|
||||
checkHideSection();
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.magisk, R.string.magisk) {
|
||||
@ -90,12 +90,6 @@ public class MainActivity extends BaseActivity
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
checkHideSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (drawer.isDrawerOpen(navigationView)) {
|
||||
|
@ -74,7 +74,7 @@ public class SplashActivity extends BaseActivity {
|
||||
// Magisk working as expected
|
||||
if (Shell.rootAccess() && Config.magiskVersionCode > 0) {
|
||||
// Load modules
|
||||
Utils.loadModules();
|
||||
Utils.loadModules(false);
|
||||
// Load repos
|
||||
if (Networking.checkNetworkStatus(this))
|
||||
new UpdateRepos().exec();
|
||||
|
@ -10,6 +10,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -23,14 +24,18 @@ import com.topjohnwu.magisk.container.Repo;
|
||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||
import com.topjohnwu.magisk.dialogs.CustomAlertDialog;
|
||||
import com.topjohnwu.magisk.uicomponents.MarkDownWindow;
|
||||
import com.topjohnwu.magisk.utils.Event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, ReposAdapter.RepoHolder> {
|
||||
public class ReposAdapter
|
||||
extends SectionedAdapter<ReposAdapter.SectionHolder, ReposAdapter.RepoHolder>
|
||||
implements Event.AutoListener, SearchView.OnQueryTextListener {
|
||||
|
||||
private static final int UPDATES = 0;
|
||||
private static final int INSTALLED = 1;
|
||||
@ -41,11 +46,10 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
||||
private RepoDatabaseHelper repoDB;
|
||||
private List<Pair<Integer, List<Repo>>> repoPairs;
|
||||
|
||||
public ReposAdapter(RepoDatabaseHelper db, Map<String, Module> map) {
|
||||
public ReposAdapter(RepoDatabaseHelper db) {
|
||||
repoDB = db;
|
||||
moduleMap = map;
|
||||
moduleMap = Collections.emptyMap();
|
||||
repoPairs = new ArrayList<>();
|
||||
notifyDBChanged();
|
||||
}
|
||||
|
||||
|
||||
@ -136,10 +140,27 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
||||
if (repoCursor != null)
|
||||
repoCursor.close();
|
||||
repoCursor = repoDB.getRepoCursor();
|
||||
filter("");
|
||||
onQueryTextChange("");
|
||||
}
|
||||
|
||||
public void filter(String s) {
|
||||
@Override
|
||||
public void onEvent(int event) {
|
||||
moduleMap = Event.getResult(event);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getListeningEvents() {
|
||||
return new int[] {Event.MODULE_LOAD_DONE};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String s) {
|
||||
List<Repo> updates = new ArrayList<>();
|
||||
List<Repo> installed = new ArrayList<>();
|
||||
List<Repo> others = new ArrayList<>();
|
||||
@ -150,7 +171,7 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
||||
if (repo.getName().toLowerCase().contains(s.toLowerCase())
|
||||
|| repo.getAuthor().toLowerCase().contains(s.toLowerCase())
|
||||
|| repo.getDescription().toLowerCase().contains(s.toLowerCase())
|
||||
) {
|
||||
) {
|
||||
// Passed the repoFilter
|
||||
Module module = moduleMap.get(repo.getId());
|
||||
if (module != null) {
|
||||
@ -175,6 +196,7 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
||||
repoPairs.add(new Pair<>(OTHERS, others));
|
||||
|
||||
notifyDataSetChanged();
|
||||
return false;
|
||||
}
|
||||
|
||||
static class SectionHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -46,56 +46,43 @@ public class ReposFragment extends BaseFragment {
|
||||
unbinder = new ReposFragment_ViewBinding(this, view);
|
||||
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> new UpdateRepos().exec(true));
|
||||
|
||||
adapter = new ReposAdapter(app.repoDB);
|
||||
Event.register(adapter);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
|
||||
requireActivity().setTitle(R.string.downloads);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Event.unregister(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getListeningEvents() {
|
||||
return new int[] {Event.MODULE_LOAD_DONE, Event.REPO_LOAD_DONE};
|
||||
return new int[] {Event.REPO_LOAD_DONE};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int event) {
|
||||
switch (event) {
|
||||
case Event.MODULE_LOAD_DONE:
|
||||
adapter = new ReposAdapter(app.repoDB, Event.getResult(event));
|
||||
recyclerView.setAdapter(adapter);
|
||||
break;
|
||||
case Event.REPO_LOAD_DONE:
|
||||
if (adapter != null)
|
||||
adapter.notifyDBChanged();
|
||||
break;
|
||||
}
|
||||
if (Event.isTriggered(this)) {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
boolean empty = adapter.getItemCount() == 0;
|
||||
recyclerView.setVisibility(empty ? View.GONE : View.VISIBLE);
|
||||
emptyRv.setVisibility(empty ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
adapter.notifyDBChanged();
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
boolean empty = adapter.getItemCount() == 0;
|
||||
recyclerView.setVisibility(empty ? View.GONE : View.VISIBLE);
|
||||
emptyRv.setVisibility(empty ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_repo, menu);
|
||||
SearchView search = (SearchView) menu.findItem(R.id.repo_search).getActionView();
|
||||
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
adapter.filter(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
search.setOnQueryTextListener(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,8 +95,12 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void loadModules() {
|
||||
loadModules(true);
|
||||
}
|
||||
|
||||
public static void loadModules(boolean async) {
|
||||
Event.reset(Event.MODULE_LOAD_DONE);
|
||||
App.THREAD_POOL.execute(() -> {
|
||||
Runnable run = () -> {
|
||||
Map<String, Module> moduleMap = new ValueSortedMap<>();
|
||||
SuFile path = new SuFile(Const.MAGISK_PATH);
|
||||
SuFile[] modules = path.listFiles(
|
||||
@ -107,7 +111,11 @@ public class Utils {
|
||||
moduleMap.put(module.getId(), module);
|
||||
}
|
||||
Event.trigger(Event.MODULE_LOAD_DONE, moduleMap);
|
||||
});
|
||||
};
|
||||
if (async)
|
||||
App.THREAD_POOL.execute(run);
|
||||
else
|
||||
run.run();
|
||||
}
|
||||
|
||||
public static boolean showSuperUser() {
|
||||
|
@ -18,7 +18,8 @@
|
||||
<item
|
||||
android:id="@+id/magiskhide"
|
||||
android:icon="@drawable/ic_magiskhide"
|
||||
android:title="@string/magiskhide" />
|
||||
android:title="@string/magiskhide"
|
||||
android:visible="false"/>
|
||||
|
||||
</group>
|
||||
|
||||
@ -29,7 +30,8 @@
|
||||
<item
|
||||
android:id="@+id/modules"
|
||||
android:icon="@drawable/ic_extension"
|
||||
android:title="@string/modules"/>
|
||||
android:title="@string/modules"
|
||||
android:visible="false"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/downloads"
|
||||
|
Loading…
Reference in New Issue
Block a user