2016-10-22 18:05:34 +02:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
2016-11-07 14:06:18 +01:00
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2016-10-22 18:05:34 +02:00
|
|
|
import android.view.LayoutInflater;
|
2016-11-11 14:45:03 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-10-22 18:05:34 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-11-11 14:45:03 +01:00
|
|
|
import android.widget.SearchView;
|
2016-10-22 18:05:34 +02:00
|
|
|
|
2016-11-07 17:09:08 +01:00
|
|
|
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
2017-02-06 19:01:32 +01:00
|
|
|
import com.topjohnwu.magisk.components.Fragment;
|
2017-08-03 18:12:11 +02:00
|
|
|
import com.topjohnwu.magisk.utils.Topic;
|
2016-10-22 18:05:34 +02:00
|
|
|
|
2016-11-07 14:06:18 +01:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2017-01-12 01:46:07 +01:00
|
|
|
import butterknife.Unbinder;
|
2016-10-22 20:04:58 +02:00
|
|
|
|
2017-08-03 18:12:11 +02:00
|
|
|
public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
2016-10-22 18:05:34 +02:00
|
|
|
|
2017-01-24 21:27:05 +01:00
|
|
|
private Unbinder unbinder;
|
|
|
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
|
|
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
2017-01-06 17:29:53 +01:00
|
|
|
|
2017-01-08 14:47:56 +01:00
|
|
|
private ApplicationAdapter appAdapter;
|
2016-11-11 14:45:03 +01:00
|
|
|
|
|
|
|
private SearchView.OnQueryTextListener searchListener;
|
2017-01-08 16:17:01 +01:00
|
|
|
private String lastFilter;
|
2016-10-22 18:05:34 +02:00
|
|
|
|
2017-01-11 22:22:55 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
2016-11-07 14:06:18 +01:00
|
|
|
@Nullable
|
2016-10-22 18:05:34 +02:00
|
|
|
@Override
|
2016-11-07 14:06:18 +01:00
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2017-01-25 10:07:23 +01:00
|
|
|
View view = inflater.inflate(R.layout.fragment_magisk_hide, container, false);
|
2017-01-12 01:46:07 +01:00
|
|
|
unbinder = ButterKnife.bind(this, view);
|
2017-07-20 23:08:39 +02:00
|
|
|
lastFilter = "";
|
2016-11-07 14:06:18 +01:00
|
|
|
|
|
|
|
mSwipeRefreshLayout.setRefreshing(true);
|
2017-07-20 23:08:39 +02:00
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(() -> appAdapter.refresh());
|
2016-10-22 18:05:34 +02:00
|
|
|
|
2017-07-20 23:08:39 +02:00
|
|
|
appAdapter = new ApplicationAdapter(getActivity());
|
2017-01-06 17:29:53 +01:00
|
|
|
recyclerView.setAdapter(appAdapter);
|
2016-11-11 14:45:03 +01:00
|
|
|
|
|
|
|
searchListener = new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
2017-01-08 16:17:01 +01:00
|
|
|
lastFilter = query;
|
2017-01-08 14:41:19 +01:00
|
|
|
appAdapter.filter(query);
|
2016-11-11 14:45:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
2017-01-08 16:17:01 +01:00
|
|
|
lastFilter = newText;
|
2017-01-08 14:41:19 +01:00
|
|
|
appAdapter.filter(newText);
|
2016-11-11 14:45:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-22 18:12:15 +02:00
|
|
|
getActivity().setTitle(R.string.magiskhide);
|
|
|
|
|
2017-01-08 14:45:08 +01:00
|
|
|
return view;
|
2016-10-22 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2016-11-11 14:45:03 +01:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_magiskhide, menu);
|
2017-07-22 18:12:15 +02:00
|
|
|
SearchView search = (SearchView) menu.findItem(R.id.app_search).getActionView();
|
2016-11-11 14:45:03 +01:00
|
|
|
search.setOnQueryTextListener(searchListener);
|
|
|
|
}
|
|
|
|
|
2017-01-12 01:46:07 +01:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
|
|
|
unbinder.unbind();
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:29:53 +01:00
|
|
|
@Override
|
2017-10-07 11:12:36 +02:00
|
|
|
public void onTopicPublished(Topic topic, Object result) {
|
2016-11-07 14:06:18 +01:00
|
|
|
mSwipeRefreshLayout.setRefreshing(false);
|
2017-07-20 23:08:39 +02:00
|
|
|
appAdapter.filter(lastFilter);
|
2016-10-22 18:05:34 +02:00
|
|
|
}
|
2017-07-22 18:12:15 +02:00
|
|
|
|
|
|
|
@Override
|
2017-08-03 18:12:11 +02:00
|
|
|
public Topic[] getSubscription() {
|
|
|
|
return new Topic[] { getApplication().magiskHideDone };
|
2017-07-22 18:12:15 +02:00
|
|
|
}
|
2017-01-08 14:41:19 +01:00
|
|
|
}
|