2016-08-22 21:18:28 +00:00
|
|
|
package com.topjohnwu.magisk;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
import android.content.SharedPreferences;
|
2016-08-17 11:00:55 +00:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
2016-09-18 14:56:12 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2016-09-18 14:56:12 +00:00
|
|
|
import android.support.design.widget.Snackbar;
|
2016-08-21 14:42:50 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
2016-09-18 14:56:12 +00:00
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-09-18 14:56:12 +00:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.TextView;
|
2016-08-20 15:26:49 +00:00
|
|
|
|
2016-08-22 21:18:28 +00:00
|
|
|
import com.topjohnwu.magisk.module.Module;
|
2016-08-24 21:58:15 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-25 10:40:00 +00:00
|
|
|
import java.util.ArrayList;
|
2016-08-17 11:00:55 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
public class ModulesFragment extends Fragment {
|
2016-09-18 14:56:12 +00:00
|
|
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
|
|
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
|
|
|
@BindView(R.id.empty_rv) TextView emptyTv;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
private SharedPreferences prefs;
|
2016-08-28 22:35:07 +00:00
|
|
|
public static List<Module> listModules = new ArrayList<>();
|
2016-08-21 14:08:45 +00:00
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
@Nullable
|
2016-08-17 11:00:55 +00:00
|
|
|
@Override
|
2016-08-21 13:29:42 +00:00
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2016-09-18 14:56:12 +00:00
|
|
|
View viewMain = inflater.inflate(R.layout.modules_fragment, container, false);
|
2016-09-06 21:54:08 +00:00
|
|
|
|
2016-09-15 17:52:58 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
ButterKnife.bind(this, viewMain);
|
2016-09-14 22:12:47 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
2016-09-14 22:12:47 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
recyclerView.setVisibility(View.GONE);
|
|
|
|
new Utils.LoadModules(getActivity()).execute();
|
|
|
|
new updateUI().execute();
|
|
|
|
prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply();
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
});
|
2016-09-15 17:52:58 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, s) -> {
|
|
|
|
if (s.contains("updated")) {
|
|
|
|
viewMain.invalidate();
|
|
|
|
viewMain.requestLayout();
|
2016-09-15 17:52:58 +00:00
|
|
|
|
|
|
|
}
|
2016-09-18 14:56:12 +00:00
|
|
|
});
|
2016-09-14 22:12:47 +00:00
|
|
|
|
2016-09-13 12:31:43 +00:00
|
|
|
new updateUI().execute();
|
2016-08-21 14:42:50 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
return viewMain;
|
2016-08-21 14:42:50 +00:00
|
|
|
}
|
2016-09-10 04:40:57 +00:00
|
|
|
|
2016-09-08 19:47:04 +00:00
|
|
|
private class updateUI extends AsyncTask<Void, Void, Void> {
|
2016-08-17 11:00:55 +00:00
|
|
|
|
|
|
|
@Override
|
2016-08-22 21:18:28 +00:00
|
|
|
protected Void doInBackground(Void... voids) {
|
|
|
|
return null;
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-22 21:18:28 +00:00
|
|
|
protected void onPostExecute(Void v) {
|
|
|
|
super.onPostExecute(v);
|
2016-09-09 21:49:25 +00:00
|
|
|
|
2016-09-19 02:08:46 +00:00
|
|
|
if (listModules.size() == 0) {
|
2016-09-18 14:56:12 +00:00
|
|
|
emptyTv.setVisibility(View.VISIBLE);
|
|
|
|
recyclerView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2016-09-19 02:08:46 +00:00
|
|
|
recyclerView.setAdapter(new ModulesAdapter(listModules, (chk, position) -> {
|
2016-09-18 14:56:12 +00:00
|
|
|
// On Checkbox change listener
|
|
|
|
CheckBox chbox = (CheckBox) chk;
|
2016-08-21 14:42:50 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
if (!chbox.isChecked()) {
|
2016-09-19 02:08:46 +00:00
|
|
|
listModules.get(position).createDisableFile();
|
2016-09-18 14:56:12 +00:00
|
|
|
Snackbar.make(chk, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
|
|
|
|
} else {
|
2016-09-19 02:08:46 +00:00
|
|
|
listModules.get(position).removeDisableFile();
|
2016-09-18 14:56:12 +00:00
|
|
|
Snackbar.make(chk, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}, (deleteBtn, position) -> {
|
|
|
|
// On delete button click listener
|
2016-09-19 02:08:46 +00:00
|
|
|
listModules.get(position).createRemoveFile();
|
2016-09-18 14:56:12 +00:00
|
|
|
Snackbar.make(deleteBtn, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
|
|
|
|
}, (undeleteBtn, position) -> {
|
|
|
|
// On undelete button click listener
|
2016-09-19 02:08:46 +00:00
|
|
|
listModules.get(position).deleteRemoveFile();
|
2016-09-18 14:56:12 +00:00
|
|
|
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
|
|
|
}));
|
2016-08-21 14:42:50 +00:00
|
|
|
|
2016-09-18 14:56:12 +00:00
|
|
|
if (mSwipeRefreshLayout.isRefreshing())
|
|
|
|
mSwipeRefreshLayout.setRefreshing(false);
|
2016-08-21 14:42:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 22:12:47 +00:00
|
|
|
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|