UI tweaks

This commit is contained in:
topjohnwu 2016-10-17 16:07:47 +08:00
parent ef0ba9483f
commit 15cf8d2a6d
5 changed files with 90 additions and 98 deletions

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk;
import android.content.Context;
import android.os.AsyncTask;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
@ -9,6 +10,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
@ -27,32 +29,8 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
private View mView;
private Context context;
private Utils.ItemClickListener chboxListener, deleteBtnListener, unDeleteBtnListener;
public ModulesAdapter(List<Module> 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
@ -85,16 +63,66 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
}
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 -> {
if (module.willBeRemoved()) {
unDeleteBtnListener.onItemClick(holder.delete, holder.getAdapterPosition());
@Override
protected void onPostExecute(Void v) {
Snackbar.make(mView, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
} 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()) {

View File

@ -41,7 +41,6 @@ public class ReposFragment extends Fragment {
private List<Repo> fInstalledRepos = new ArrayList<>();
private List<Repo> fOthersRepos = new ArrayList<>();
private ReposAdapter mReposAdapter = new ReposAdapter(fUpdateRepos, fInstalledRepos, fOthersRepos);
private SimpleSectionedRecyclerViewAdapter mSectionedAdapter;
private SharedPreferences.OnSharedPreferenceChangeListener listener;
@ -57,7 +56,7 @@ public class ReposFragment extends Fragment {
ButterKnife.bind(this, view);
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);
@ -176,6 +175,7 @@ public class ReposFragment extends Fragment {
}
SimpleSectionedRecyclerViewAdapter.Section[] array = sections.toArray(new SimpleSectionedRecyclerViewAdapter.Section[sections.size()]);
mSectionedAdapter.setSections(array);
emptyTv.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
mSwipeRefreshLayout.setRefreshing(false);

View File

@ -28,42 +28,17 @@ public class Module extends BaseModule {
Logger.dev("Creating Module, id: " + mId);
try {
mEnable = !Utils.itemExist(mDisableFile);
} catch (Exception e) {
mEnable = false;
}
try {
mRemove = Utils.itemExist(mRemoveFile);
} catch (Exception e) {
mRemove = false;
}
try {
mUpdated = Utils.itemExist(mUpdateFile);
} catch (Exception e) {
mUpdated = false;
}
mEnable = !Utils.itemExist(mDisableFile);
mRemove = Utils.itemExist(mRemoveFile);
mUpdated = Utils.itemExist(mUpdateFile);
}
public void createDisableFile() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
mEnable = !Utils.createFile(mDisableFile);
return null;
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
mEnable = !Utils.createFile(mDisableFile);
}
public void removeDisableFile() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
mEnable = Utils.removeItem(mDisableFile);
return null;
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
mEnable = Utils.removeItem(mDisableFile);
}
public boolean isEnabled() {
@ -71,23 +46,11 @@ public class Module extends BaseModule {
}
public void createRemoveFile() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
mRemove = Utils.createFile(mRemoveFile);
return null;
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
mRemove = Utils.createFile(mRemoveFile);
}
public void deleteRemoveFile() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
mRemove = !Utils.removeItem(mRemoveFile);
return null;
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
mRemove = !Utils.removeItem(mRemoveFile);
}
public boolean willBeRemoved() {

View File

@ -135,10 +135,4 @@ public class Utils {
return secret;
}
public interface ItemClickListener {
void onItemClick(View view, int position);
}
}

View File

@ -7,23 +7,30 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="@dimen/card_divider_space"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
android:orientation="vertical">
<TextView
android:id="@+id/empty_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/no_modules_found"
android:textSize="20sp"
android:textStyle="italic"
android:visibility="gone"/>
<TextView
android:id="@+id/empty_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/no_modules_found"
android:textSize="20sp"
android:textStyle="italic"
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>