2016-10-22 16:05:34 +00:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
2016-11-11 13:45:03 +00:00
|
|
|
import android.support.v4.view.MenuItemCompat;
|
2016-11-07 13:06:18 +00:00
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2017-01-08 15:17:01 +00:00
|
|
|
import android.text.TextUtils;
|
2016-10-22 16:05:34 +00:00
|
|
|
import android.view.LayoutInflater;
|
2016-11-11 13:45:03 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-10-22 16:05:34 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-11-11 13:45:03 +00:00
|
|
|
import android.widget.SearchView;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 16:09:08 +00:00
|
|
|
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
2017-02-06 18:01:32 +00:00
|
|
|
import com.topjohnwu.magisk.components.Fragment;
|
2016-11-07 13:06:18 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Async;
|
2017-02-06 20:09:49 +00:00
|
|
|
import com.topjohnwu.magisk.utils.CallbackEvent;
|
2017-01-06 16:29:53 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Logger;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2017-01-12 00:46:07 +00:00
|
|
|
import butterknife.Unbinder;
|
2016-10-22 18:04:58 +00:00
|
|
|
|
2017-02-06 20:09:49 +00:00
|
|
|
public class MagiskHideFragment extends Fragment implements CallbackEvent.Listener<Void> {
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-24 20:27:05 +00:00
|
|
|
private Unbinder unbinder;
|
|
|
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
|
|
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
2017-01-06 16:29:53 +00:00
|
|
|
|
2017-01-08 13:47:56 +00:00
|
|
|
private ApplicationAdapter appAdapter;
|
2016-11-11 13:45:03 +00:00
|
|
|
|
|
|
|
private SearchView.OnQueryTextListener searchListener;
|
2017-01-08 15:17:01 +00:00
|
|
|
private String lastFilter;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-11 21:22:55 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
@Nullable
|
2016-10-22 16:05:34 +00:00
|
|
|
@Override
|
2016-11-07 13:06:18 +00:00
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2017-01-25 09:07:23 +00:00
|
|
|
View view = inflater.inflate(R.layout.fragment_magisk_hide, container, false);
|
2017-01-12 00:46:07 +00:00
|
|
|
unbinder = ButterKnife.bind(this, view);
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-08 13:47:56 +00:00
|
|
|
PackageManager packageManager = getActivity().getPackageManager();
|
2016-11-07 13:06:18 +00:00
|
|
|
|
|
|
|
mSwipeRefreshLayout.setRefreshing(true);
|
2017-02-06 18:01:32 +00:00
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(() -> new Async.LoadApps(getApplication()).exec());
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-08 13:47:56 +00:00
|
|
|
appAdapter = new ApplicationAdapter(packageManager);
|
2017-01-06 16:29:53 +00:00
|
|
|
recyclerView.setAdapter(appAdapter);
|
2016-11-11 13:45:03 +00:00
|
|
|
|
|
|
|
searchListener = new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
2017-01-08 15:17:01 +00:00
|
|
|
lastFilter = query;
|
2017-01-08 13:41:19 +00:00
|
|
|
appAdapter.filter(query);
|
2016-11-11 13:45:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
2017-01-08 15:17:01 +00:00
|
|
|
lastFilter = newText;
|
2017-01-08 13:41:19 +00:00
|
|
|
appAdapter.filter(newText);
|
2016-11-11 13:45:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-06 20:09:49 +00:00
|
|
|
if (getApplication().packageLoadDone.isTriggered)
|
|
|
|
onTrigger(getApplication().packageLoadDone);
|
|
|
|
|
2017-01-08 13:45:08 +00:00
|
|
|
return view;
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 13:45:03 +00:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_magiskhide, menu);
|
|
|
|
SearchView search = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.app_search));
|
|
|
|
search.setOnQueryTextListener(searchListener);
|
|
|
|
}
|
|
|
|
|
2016-10-22 16:05:34 +00:00
|
|
|
@Override
|
2017-01-11 23:13:23 +00:00
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2016-12-24 19:05:22 +00:00
|
|
|
getActivity().setTitle(R.string.magiskhide);
|
2017-02-06 20:09:49 +00:00
|
|
|
getApplication().packageLoadDone.register(this);
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
@Override
|
2017-01-11 23:13:23 +00:00
|
|
|
public void onStop() {
|
2017-02-06 20:09:49 +00:00
|
|
|
getApplication().packageLoadDone.unRegister(this);
|
2017-01-11 23:13:23 +00:00
|
|
|
super.onStop();
|
2017-01-06 16:29:53 +00:00
|
|
|
}
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-12 00:46:07 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
|
|
|
unbinder.unbind();
|
|
|
|
}
|
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
@Override
|
2017-02-06 20:09:49 +00:00
|
|
|
public void onTrigger(CallbackEvent<Void> event) {
|
2017-01-06 16:29:53 +00:00
|
|
|
Logger.dev("MagiskHideFragment: UI refresh");
|
2017-02-06 18:01:32 +00:00
|
|
|
appAdapter.setLists(getApplication().appList, getApplication().magiskHideList);
|
2016-11-07 13:06:18 +00:00
|
|
|
mSwipeRefreshLayout.setRefreshing(false);
|
2017-01-08 15:17:01 +00:00
|
|
|
if (!TextUtils.isEmpty(lastFilter)) {
|
|
|
|
appAdapter.filter(lastFilter);
|
|
|
|
}
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
2017-01-08 13:41:19 +00:00
|
|
|
}
|