2018-08-30 09:57:48 +02:00
|
|
|
package com.topjohnwu.magisk.fragments;
|
2016-09-11 20:36:58 +02:00
|
|
|
|
2017-12-26 18:07:33 +01:00
|
|
|
import android.app.AlertDialog;
|
2016-09-11 20:36:58 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
2016-10-17 04:11:26 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2017-12-26 18:07:33 +01:00
|
|
|
import android.view.MenuItem;
|
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;
|
|
|
|
|
2019-01-30 09:10:12 +01:00
|
|
|
import com.topjohnwu.magisk.Config;
|
2018-08-30 09:57:48 +02:00
|
|
|
import com.topjohnwu.magisk.R;
|
2016-11-07 17:09:08 +01:00
|
|
|
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
2018-08-01 11:57:11 +02:00
|
|
|
import com.topjohnwu.magisk.components.BaseFragment;
|
2019-01-30 09:10:12 +01:00
|
|
|
import com.topjohnwu.magisk.container.Module;
|
|
|
|
import com.topjohnwu.magisk.tasks.UpdateRepos;
|
|
|
|
import com.topjohnwu.magisk.utils.Topic;
|
2016-09-11 20:36:58 +02:00
|
|
|
|
2018-08-01 18:41:10 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2018-09-10 08:27:45 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
2018-10-17 03:00:01 +02:00
|
|
|
import butterknife.BindView;
|
2016-09-11 20:36:58 +02:00
|
|
|
|
2018-08-01 11:57:11 +02:00
|
|
|
public class ReposFragment extends BaseFragment implements Topic.Subscriber {
|
2016-12-25 08:11:59 +01:00
|
|
|
|
2018-10-17 03:00:01 +02:00
|
|
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
|
|
|
@BindView(R.id.empty_rv) TextView emptyRv;
|
|
|
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
2016-10-17 04:11:26 +02:00
|
|
|
|
2018-08-03 17:04:35 +02:00
|
|
|
private 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
|
2018-08-01 18:41:10 +02:00
|
|
|
public View onCreateView(@NonNull 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);
|
2018-10-17 03:00:01 +02:00
|
|
|
unbinder = new ReposFragment_ViewBinding(this, view);
|
2016-09-27 16:57:20 +02:00
|
|
|
|
2018-07-31 18:47:31 +02:00
|
|
|
mSwipeRefreshLayout.setRefreshing(true);
|
2018-08-01 18:41:10 +02:00
|
|
|
recyclerView.setVisibility(View.GONE);
|
2016-09-27 16:57:20 +02:00
|
|
|
|
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
2017-09-29 19:15:34 +02:00
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
emptyRv.setVisibility(View.GONE);
|
2018-08-01 18:41:10 +02:00
|
|
|
new UpdateRepos().exec(true);
|
2016-09-25 15:59:54 +02:00
|
|
|
});
|
2016-09-27 16:57:20 +02:00
|
|
|
|
2018-08-01 18:41:10 +02:00
|
|
|
requireActivity().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
|
|
|
}
|
|
|
|
|
2016-12-25 08:11:59 +01:00
|
|
|
@Override
|
2018-07-31 18:47:31 +02:00
|
|
|
public int[] getSubscribedTopics() {
|
2018-08-01 18:41:10 +02:00
|
|
|
return new int[] {Topic.MODULE_LOAD_DONE, Topic.REPO_LOAD_DONE};
|
2016-12-25 08:11:59 +01:00
|
|
|
}
|
|
|
|
|
2017-07-22 18:12:15 +02:00
|
|
|
@Override
|
2018-07-31 18:47:31 +02:00
|
|
|
public void onPublish(int topic, Object[] result) {
|
2018-08-01 18:41:10 +02:00
|
|
|
if (topic == Topic.MODULE_LOAD_DONE) {
|
2018-12-13 10:35:50 +01:00
|
|
|
adapter = new ReposAdapter(app.repoDB, (Map<String, Module>) result[0]);
|
|
|
|
app.repoDB.registerAdapterCallback(adapter::notifyDBChanged);
|
2018-08-01 18:41:10 +02:00
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
emptyRv.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (Topic.isPublished(getSubscribedTopics())) {
|
|
|
|
mSwipeRefreshLayout.setRefreshing(false);
|
|
|
|
recyclerView.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
|
|
|
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
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-12-26 18:07:33 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if (item.getItemId() == R.id.repo_sort) {
|
|
|
|
new AlertDialog.Builder(getActivity())
|
|
|
|
.setTitle(R.string.sorting_order)
|
2019-01-21 21:49:03 +01:00
|
|
|
.setSingleChoiceItems(R.array.sorting_orders,
|
|
|
|
Config.get(Config.Key.REPO_ORDER), (d, which) -> {
|
|
|
|
Config.set(Config.Key.REPO_ORDER, which);
|
2017-12-26 18:07:33 +01:00
|
|
|
adapter.notifyDBChanged();
|
|
|
|
d.dismiss();
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-12 01:46:07 +01:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
2018-12-13 10:35:50 +01:00
|
|
|
app.repoDB.unregisterAdapterCallback();
|
2017-01-12 01:46:07 +01:00
|
|
|
}
|
2016-09-11 20:36:58 +02:00
|
|
|
}
|