mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-04 22:47:38 +00:00
UI tweaks
This commit is contained in:
parent
ef0ba9483f
commit
15cf8d2a6d
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
@ -9,6 +10,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -27,32 +29,8 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
private View mView;
|
private View mView;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private Utils.ItemClickListener chboxListener, deleteBtnListener, unDeleteBtnListener;
|
|
||||||
|
|
||||||
public ModulesAdapter(List<Module> list) {
|
public ModulesAdapter(List<Module> list) {
|
||||||
mList = list;
|
mList = list;
|
||||||
chboxListener = (chk, position) -> {
|
|
||||||
// On Checkbox change listener
|
|
||||||
CheckBox chbox = (CheckBox) chk;
|
|
||||||
|
|
||||||
if (!chbox.isChecked()) {
|
|
||||||
mList.get(position).createDisableFile();
|
|
||||||
Snackbar.make(mView, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
mList.get(position).removeDisableFile();
|
|
||||||
Snackbar.make(mView, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
deleteBtnListener = (deleteBtn, position) -> {
|
|
||||||
// On delete button click listener
|
|
||||||
mList.get(position).createRemoveFile();
|
|
||||||
Snackbar.make(mView, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
|
|
||||||
};
|
|
||||||
unDeleteBtnListener = (undeleteBtn, position) -> {
|
|
||||||
// On undelete button click listener
|
|
||||||
mList.get(position).deleteRemoveFile();
|
|
||||||
Snackbar.make(mView, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -85,16 +63,66 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
}
|
}
|
||||||
|
|
||||||
holder.checkBox.setChecked(module.isEnabled());
|
holder.checkBox.setChecked(module.isEnabled());
|
||||||
holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> chboxListener.onItemClick(compoundButton, holder.getAdapterPosition()));
|
holder.checkBox.setOnCheckedChangeListener((compoundButton, isChecked) -> {
|
||||||
|
if (isChecked) {
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
module.removeDisableFile();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
holder.delete.setOnClickListener(view -> {
|
@Override
|
||||||
if (module.willBeRemoved()) {
|
protected void onPostExecute(Void v) {
|
||||||
unDeleteBtnListener.onItemClick(holder.delete, holder.getAdapterPosition());
|
Snackbar.make(mView, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||||
} else {
|
} else {
|
||||||
deleteBtnListener.onItemClick(holder.delete, holder.getAdapterPosition());
|
new AsyncTask<Void, Void, Void>() {
|
||||||
}
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
module.createDisableFile();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
updateDeleteButton(holder, module);
|
@Override
|
||||||
|
protected void onPostExecute(Void v) {
|
||||||
|
Snackbar.make(mView, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
holder.delete.setOnClickListener(v -> {
|
||||||
|
if (module.willBeRemoved()) {
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
module.deleteRemoveFile();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void v) {
|
||||||
|
Snackbar.make(mView, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
||||||
|
updateDeleteButton(holder, module);
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||||
|
} else {
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
module.createRemoveFile();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void v) {
|
||||||
|
Snackbar.make(mView, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
|
||||||
|
updateDeleteButton(holder, module);
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (module.isUpdated()) {
|
if (module.isUpdated()) {
|
||||||
|
@ -41,7 +41,6 @@ public class ReposFragment extends Fragment {
|
|||||||
private List<Repo> fInstalledRepos = new ArrayList<>();
|
private List<Repo> fInstalledRepos = new ArrayList<>();
|
||||||
private List<Repo> fOthersRepos = new ArrayList<>();
|
private List<Repo> fOthersRepos = new ArrayList<>();
|
||||||
|
|
||||||
private ReposAdapter mReposAdapter = new ReposAdapter(fUpdateRepos, fInstalledRepos, fOthersRepos);
|
|
||||||
private SimpleSectionedRecyclerViewAdapter mSectionedAdapter;
|
private SimpleSectionedRecyclerViewAdapter mSectionedAdapter;
|
||||||
|
|
||||||
private SharedPreferences.OnSharedPreferenceChangeListener listener;
|
private SharedPreferences.OnSharedPreferenceChangeListener listener;
|
||||||
@ -57,7 +56,7 @@ public class ReposFragment extends Fragment {
|
|||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
mSectionedAdapter = new
|
mSectionedAdapter = new
|
||||||
SimpleSectionedRecyclerViewAdapter(getActivity(), R.layout.section, R.id.section_text, mReposAdapter);
|
SimpleSectionedRecyclerViewAdapter(getActivity(), R.layout.section, R.id.section_text, new ReposAdapter(fUpdateRepos, fInstalledRepos, fOthersRepos));
|
||||||
|
|
||||||
recyclerView.setAdapter(mSectionedAdapter);
|
recyclerView.setAdapter(mSectionedAdapter);
|
||||||
|
|
||||||
@ -176,6 +175,7 @@ public class ReposFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
SimpleSectionedRecyclerViewAdapter.Section[] array = sections.toArray(new SimpleSectionedRecyclerViewAdapter.Section[sections.size()]);
|
SimpleSectionedRecyclerViewAdapter.Section[] array = sections.toArray(new SimpleSectionedRecyclerViewAdapter.Section[sections.size()]);
|
||||||
mSectionedAdapter.setSections(array);
|
mSectionedAdapter.setSections(array);
|
||||||
|
emptyTv.setVisibility(View.GONE);
|
||||||
recyclerView.setVisibility(View.VISIBLE);
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
|
@ -28,42 +28,17 @@ public class Module extends BaseModule {
|
|||||||
|
|
||||||
Logger.dev("Creating Module, id: " + mId);
|
Logger.dev("Creating Module, id: " + mId);
|
||||||
|
|
||||||
try {
|
mEnable = !Utils.itemExist(mDisableFile);
|
||||||
mEnable = !Utils.itemExist(mDisableFile);
|
mRemove = Utils.itemExist(mRemoveFile);
|
||||||
} catch (Exception e) {
|
mUpdated = Utils.itemExist(mUpdateFile);
|
||||||
mEnable = false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
mRemove = Utils.itemExist(mRemoveFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
mRemove = false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
mUpdated = Utils.itemExist(mUpdateFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
mUpdated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createDisableFile() {
|
public void createDisableFile() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
mEnable = !Utils.createFile(mDisableFile);
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
mEnable = !Utils.createFile(mDisableFile);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDisableFile() {
|
public void removeDisableFile() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
mEnable = Utils.removeItem(mDisableFile);
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
mEnable = Utils.removeItem(mDisableFile);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@ -71,23 +46,11 @@ public class Module extends BaseModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createRemoveFile() {
|
public void createRemoveFile() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
mRemove = Utils.createFile(mRemoveFile);
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
mRemove = Utils.createFile(mRemoveFile);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteRemoveFile() {
|
public void deleteRemoveFile() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
mRemove = !Utils.removeItem(mRemoveFile);
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
mRemove = !Utils.removeItem(mRemoveFile);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean willBeRemoved() {
|
public boolean willBeRemoved() {
|
||||||
|
@ -135,10 +135,4 @@ public class Utils {
|
|||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ItemClickListener {
|
|
||||||
|
|
||||||
void onItemClick(View view, int position);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -7,23 +7,30 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<LinearLayout
|
||||||
android:id="@+id/recyclerView"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:dividerHeight="@dimen/card_divider_space"
|
android:orientation="vertical">
|
||||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/empty_rv"
|
android:id="@+id/empty_rv"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:fontFamily="sans-serif-light"
|
android:fontFamily="sans-serif-light"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/no_modules_found"
|
android:text="@string/no_modules_found"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:textStyle="italic"
|
android:textStyle="italic"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:dividerHeight="@dimen/card_divider_space"
|
||||||
|
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</android.support.v4.widget.SwipeRefreshLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
Loading…
x
Reference in New Issue
Block a user