2016-09-11 20:36:58 +02:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
import android.view.LayoutInflater;
|
2016-10-17 04:11:26 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-09-11 20:36:58 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-10-17 04:11:26 +02:00
|
|
|
import android.widget.SearchView;
|
2016-09-11 20:36:58 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2016-11-07 17:09:08 +01:00
|
|
|
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
2017-07-20 20:46:02 +02:00
|
|
|
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
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-09-11 20:36:58 +02:00
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2017-01-12 01:46:07 +01:00
|
|
|
import butterknife.Unbinder;
|
2016-09-11 20:36:58 +02:00
|
|
|
|
2017-08-03 18:12:11 +02:00
|
|
|
public class ReposFragment extends Fragment implements Topic.Subscriber {
|
2016-12-25 08:11:59 +01:00
|
|
|
|
2017-01-12 01:46:07 +01:00
|
|
|
private Unbinder unbinder;
|
2016-09-29 22:18:41 +02:00
|
|
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
2017-01-27 18:10:50 +01:00
|
|
|
@BindView(R.id.empty_rv) TextView emptyRv;
|
2016-09-29 22:18:41 +02:00
|
|
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
2016-10-17 04:11:26 +02:00
|
|
|
|
2017-09-29 19:15:34 +02:00
|
|
|
public static ReposAdapter adapter;
|
2016-09-11 20:36:58 +02:00
|
|
|
|
2017-01-11 22:22:55 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
2016-09-11 20:36:58 +02:00
|
|
|
|
2017-01-11 22:22:55 +01:00
|
|
|
@Nullable
|
2016-09-11 20:36:58 +02:00
|
|
|
@Override
|
|
|
|
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_repos, container, false);
|
2017-01-12 01:46:07 +01:00
|
|
|
unbinder = ButterKnife.bind(this, view);
|
2016-09-27 16:57:20 +02:00
|
|
|
|
|
|
|
mSwipeRefreshLayout.setRefreshing(true);
|
|
|
|
|
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
2017-09-29 19:15:34 +02:00
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
emptyRv.setVisibility(View.GONE);
|
2017-10-15 18:54:48 +02:00
|
|
|
new UpdateRepos(true).exec();
|
2016-09-25 15:59:54 +02:00
|
|
|
});
|
2016-09-27 16:57:20 +02:00
|
|
|
|
2017-07-22 18:12:15 +02:00
|
|
|
getActivity().setTitle(R.string.downloads);
|
2016-09-27 16:57:20 +02:00
|
|
|
|
2016-09-28 19:42:25 +02:00
|
|
|
return view;
|
2016-09-11 20:36:58 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 19:15:34 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
adapter = new ReposAdapter(getApplication().repoDB, getApplication().moduleMap);
|
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
adapter = null;
|
|
|
|
}
|
|
|
|
|
2016-12-25 08:11:59 +01:00
|
|
|
@Override
|
2017-10-07 11:12:36 +02:00
|
|
|
public void onTopicPublished(Topic topic, Object result) {
|
2017-07-20 20:46:02 +02:00
|
|
|
mSwipeRefreshLayout.setRefreshing(false);
|
|
|
|
recyclerView.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
|
|
|
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
2016-12-25 08:11:59 +01: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().repoLoadDone };
|
2017-07-22 18:12:15 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 22:44:07 +02:00
|
|
|
@Override
|
2016-10-17 04:11:26 +02:00
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_repo, menu);
|
2017-07-18 17:18:57 +02:00
|
|
|
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) {
|
2017-07-20 20:46:02 +02:00
|
|
|
adapter.filter(newText);
|
2017-07-18 17:18:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-09-13 22:44:07 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 01:46:07 +01:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
|
|
|
unbinder.unbind();
|
|
|
|
}
|
2016-09-11 20:36:58 +02:00
|
|
|
}
|