Skip to content

Commit

Permalink
Use custom progress message
Browse files Browse the repository at this point in the history
Signed-off-by: sunilpaulmathew <sunil.kde@gmail.com>
  • Loading branch information
sunilpaulmathew committed Oct 15, 2020
1 parent ba65298 commit 3314a58
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -94,7 +95,8 @@ public abstract class RecyclerViewFragment extends BaseFragment {
private RecyclerViewAdapter mRecyclerViewAdapter;
private Scroller mScroller;

private View mProgress;
private LinearLayout mProgress;
private AppCompatTextView mProgressMessage;

private List<Fragment> mViewPagerFragments;
private ViewPagerAdapter mViewPagerAdapter;
Expand Down Expand Up @@ -174,7 +176,8 @@ public void onAdFailedToLoad(LoadAdError adError) {
mViewPagerParent.setVisibility(View.INVISIBLE);
ViewUtils.dismissDialog(getChildFragmentManager());

mProgress = mRootView.findViewById(R.id.progress);
mProgress = mRootView.findViewById(R.id.progress_layout);
mProgressMessage = mRootView.findViewById(R.id.progress_message);

mAppBarLayout = ((BaseActivity) requireActivity()).getAppBarLayout();
mToolBar = ((BaseActivity) requireActivity()).getToolBar();
Expand Down Expand Up @@ -616,6 +619,17 @@ protected void showProgress() {
}
}

protected void showProgressMessage(String message) {
mProgressMessage.setText(message);
mProgressMessage.setVisibility(View.VISIBLE);
mProgress.setVisibility(View.VISIBLE);
}

protected void hideProgressMessage() {
mProgress.setVisibility(View.GONE);
mProgressMessage.setVisibility(View.GONE);
}

protected void hideProgress() {
if (!isAdded()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
Expand Down Expand Up @@ -70,7 +69,7 @@ protected boolean showTopFab() {

@Override
protected Drawable getTopFabDrawable() {
return ViewUtils.getWhiteColoredIcon(R.drawable.ic_add, requireActivity());
return ViewUtils.getColoredIcon(R.drawable.ic_add, requireActivity());
}

@Override
Expand Down Expand Up @@ -501,14 +500,10 @@ public void onClick(String text) {
}
final String path = text;
new AsyncTask<Void, Void, Void>() {
private ProgressDialog mProgressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage(getString(R.string.exporting_settings, getString(R.string.klapse)) + "...");
mProgressDialog.setCancelable(false);
mProgressDialog.show();
showProgressMessage(getString(R.string.exporting_settings, getString(R.string.klapse)) + "...");
}
@Override
protected Void doInBackground(Void... voids) {
Expand All @@ -526,10 +521,7 @@ protected Void doInBackground(Void... voids) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
hideProgressMessage();
new Dialog(requireActivity())
.setMessage(getString(R.string.profile_created, KLapse.profileFolder().toString() + "/" + path))
.setCancelable(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
Expand Down Expand Up @@ -78,7 +77,7 @@ protected boolean showTopFab() {

@Override
protected Drawable getTopFabDrawable() {
return ViewUtils.getWhiteColoredIcon(R.drawable.ic_add, requireActivity());
return ViewUtils.getColoredIcon(R.drawable.ic_add, requireActivity());
}

@Override
Expand Down Expand Up @@ -287,16 +286,10 @@ private void restore(final Backup.PARTITION partition, final File file, final bo
@Override
public void onClick(DialogInterface dialogInterface, int i) {
new AsyncTask<Void, Void, Void>() {

private ProgressDialog mProgressDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage(getString(flashing ? R.string.flashing : R.string.restoring));
mProgressDialog.setCancelable(false);
mProgressDialog.show();
showProgressMessage(getString(flashing ? R.string.flashing : R.string.restoring));
}

@Override
Expand All @@ -308,10 +301,7 @@ protected Void doInBackground(Void... voids) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
hideProgressMessage();
// Show an option to reboot after flashing/restoring
Dialog dialog = new Dialog(requireActivity());
dialog.setIcon(R.mipmap.ic_launcher);
Expand All @@ -323,14 +313,10 @@ protected void onPostExecute(Void aVoid) {
dialog.setPositiveButton(getString(R.string.reboot), (dialog1, id1) -> {
Utils.snackbar(getRootView(), getString(R.string.rebooting_message));
new AsyncTask<Void, Void, Void>() {
private ProgressDialog mProgressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage(getString(R.string.executing) + ("..."));
mProgressDialog.setCancelable(false);
mProgressDialog.show();
showProgressMessage(getString(R.string.executing) + ("..."));
}
@Override
protected Void doInBackground(Void... voids) {
Expand All @@ -340,10 +326,7 @@ protected Void doInBackground(Void... voids) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
hideProgressMessage();
}
}.execute();
});
Expand Down Expand Up @@ -411,17 +394,10 @@ public void onClick(String text) {

final String path = text;
new AsyncTask<Void, Void, Void>() {

private ProgressDialog mProgressDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage(getString(R.string.backing_up));
mProgressDialog.setCancelable(false);
mProgressDialog.setOwnerActivity(requireActivity());
mProgressDialog.show();
showProgressMessage(getString(R.string.backing_up));
}

@Override
Expand All @@ -433,10 +409,7 @@ protected Void doInBackground(Void... voids) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
hideProgressMessage();
reload();
}
}.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class BuildpropFragment extends RecyclerViewFragment {

@Override
protected Drawable getBottomFabDrawable() {
return ViewUtils.getWhiteColoredIcon(R.drawable.ic_add, requireActivity());
return ViewUtils.getColoredIcon(R.drawable.ic_add, requireActivity());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected boolean showTopFab() {

@Override
protected Drawable getTopFabDrawable() {
return ViewUtils.getWhiteColoredIcon(R.drawable.ic_add, requireActivity());
return ViewUtils.getColoredIcon(R.drawable.ic_add, requireActivity());
}

@Override
Expand Down Expand Up @@ -145,7 +145,7 @@ private void switchItemsList(List<RecyclerViewItem> items) {
if (CustomControls.switchFile().length() > 0 && Utils.existFile(Utils.readFile(
CustomControls.switchFile().toString() + "/" + switchItems))) {
SwitchView itemslist = new SwitchView();
itemslist.setMenuIcon(getResources().getDrawable(R.drawable.ic_dots));
itemslist.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
itemslist.setSummary(Utils.readFile(CustomControls.switchFile().toString()+ "/" + switchItems));
itemslist.setChecked(CustomControls.isSwitchEnabled(Utils.readFile(
CustomControls.switchFile().toString() + "/" + switchItems)));
Expand Down Expand Up @@ -197,7 +197,7 @@ private void genericItemsList(List<RecyclerViewItem> items) {
if (CustomControls.switchFile().length() > 0 && Utils.existFile(Utils.readFile(
CustomControls.genericFile().toString() + "/" + genericItems))) {
GenericInputView itemslist = new GenericInputView();
itemslist.setMenuIcon(getResources().getDrawable(R.drawable.ic_dots));
itemslist.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
itemslist.setTitle(Utils.readFile(CustomControls.genericFile().toString()+ "/" + genericItems));
itemslist.setValue(CustomControls.getGenericValue(Utils.readFile(
CustomControls.genericFile().toString() + "/" + genericItems)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected BaseFragment getForegroundFragment() {

@Override
protected Drawable getTopFabDrawable() {
return ViewUtils.getWhiteColoredIcon(R.drawable.ic_add, requireActivity());
return ViewUtils.getColoredIcon(R.drawable.ic_add, requireActivity());
}

@Override
Expand Down Expand Up @@ -246,9 +246,9 @@ private void load(List<RecyclerViewItem> items) {
descriptionView.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_file, requireContext()));
descriptionView.setSummary(profileItems.get(i).getName());
if (Prefs.getBoolean("enable_onboot", true, getActivity()) && mProfiles.getAllProfiles().get(position).isOnBootEnabled()) {
descriptionView.setIndicator(getResources().getDrawable(R.drawable.ic_flash));
descriptionView.setIndicator(ViewUtils.getColoredIcon(R.drawable.ic_flash, requireActivity()));
}
descriptionView.setMenuIcon(getResources().getDrawable(R.drawable.ic_dots));
descriptionView.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
descriptionView.setOnMenuListener((cardView1, popupMenu) -> {
Menu menu = popupMenu.getMenu();
menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.apply));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -81,7 +80,7 @@ public class ScriptMangerFragment extends RecyclerViewFragment {

@Override
protected Drawable getTopFabDrawable() {
return ViewUtils.getWhiteColoredIcon(R.drawable.ic_add, requireActivity());
return ViewUtils.getColoredIcon(R.drawable.ic_add, requireActivity());
}

@Override
Expand Down Expand Up @@ -178,18 +177,19 @@ protected void onPostExecute(List<RecyclerViewItem> recyclerViewItems) {
}
}

@SuppressLint("UseCompatLoadingForDrawables")
private void load(List<RecyclerViewItem> items) {
final Set<String> onBootScripts = Prefs.getStringSet("on_boot_scripts", new HashSet<>(), requireContext());
for (final String script : ScriptManager.list()) {
if (Utils.getExtension(script).equals("sh")) {
DescriptionView descriptionView = new DescriptionView();
descriptionView.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_file, requireContext()));
descriptionView.setMenuIcon(getResources().getDrawable(R.drawable.ic_dots));
descriptionView.setMenuIcon(ViewUtils.getWhiteColoredIcon(R.drawable.ic_dots, requireActivity()));
descriptionView.setTitle(script);
descriptionView.setSummary(ScriptManager.scriptFile() + "/" + script);

if (Prefs.getBoolean("enable_onboot", true, getActivity()) && onBootScripts.contains(script)) {
descriptionView.setIndicator(getResources().getDrawable(R.drawable.ic_flash));
descriptionView.setIndicator(ViewUtils.getColoredIcon(R.drawable.ic_flash, requireActivity()));
}

descriptionView.setOnMenuListener((descriptionView1, popupMenu) -> {
Expand Down Expand Up @@ -271,15 +271,11 @@ private void load(List<RecyclerViewItem> items) {
@SuppressLint("StaticFieldLeak")
private void execute(final String script) {
new AsyncTask<Void, Void, Void>() {
private ProgressDialog mProgressDialog;
private String mResult;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage(getString(R.string.executing) + " " + script + "...");
mProgressDialog.setCancelable(false);
mProgressDialog.show();
showProgressMessage(getString(R.string.executing) + " " + script + "...");
}
@Override
protected Void doInBackground(Void... voids) {
Expand All @@ -289,10 +285,7 @@ protected Void doInBackground(Void... voids) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
mProgressDialog.dismiss();
} catch (IllegalArgumentException ignored) {
}
hideProgressMessage();
new Dialog(requireActivity())
.setMessage(mResult != null && !mResult.isEmpty() ? mResult : getString(R.string.script_executed, script))
.setCancelable(false)
Expand Down
Loading

0 comments on commit 3314a58

Please sign in to comment.