// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/OnAlertDialogClickListener.java
// public interface OnAlertDialogClickListener {
//     void onDialogFragmentClick(DialogFragment fragment, int which);
// }
// 
// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/ProgressDialog.java
// public class ProgressDialog extends DialogFragment implements DialogInterface.OnClickListener {
// 
//     public static ProgressDialog getExistingInstance(FragmentManager fragmentManager, String tag){
//         return (ProgressDialog) fragmentManager.findFragmentByTag(tag);
//     }
// 
//     public static ProgressDialog showIfNotShowing(FragmentManager fragmentManager, String tag){
//         ProgressDialog fragment = (ProgressDialog) fragmentManager.findFragmentByTag(tag);
// 
//         if (fragment == null) {
//             fragment = new ProgressDialog();
//         } else if(fragment.isAdded()){
//             return fragment;
//         }
// 
//         fragment.show(fragmentManager, tag);
//         return fragment;
//     }
// 
//     private TextView progressPercentage;
//     private TextView progressCount;
//     private ProgressBar progressBar;
//     private int progress = 0;
// 
//     @NonNull
//     @Override
//     public Dialog onCreateDialog(Bundle savedInstanceState) {
//         final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
// 
//         @SuppressLint("InflateParams")
//         final View view = LayoutInflater.from(builder.getContext()).inflate(R.layout.dialog_progress, null, false);
//         progressPercentage = (TextView) view.findViewById(R.id.progress_percentage);
//         progressCount = (TextView) view.findViewById(R.id.progress_count);
//         progressBar = (ProgressBar) view.findViewById(android.R.id.progress);
//         progressBar.setMax(100);
//         progressBar.setIndeterminate(false);
// 
//         builder.setView(view);
//         builder.setTitle(R.string.dialog_progress_title);
//         builder.setPositiveButton(R.string.action_cancel, this);
//         setCancelable(false);
//         return builder.create();
//     }
// 
//     @Override
//     public void onViewCreated(View view, Bundle savedInstanceState) {
//         if(savedInstanceState != null) {
//             progress = savedInstanceState.getInt("progress");
//         }
//         setProgress(progress);
//     }
// 
//     @Override
//     public void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         outState.putInt("progress", progress);
//     }
// 
//     @SuppressLint("SetTextI18n")
//     public void setProgress(int progress){
//         if(getDialog() != null) {
//             progressBar.setProgress(progress);
//             int percentage = (int) Math.round(((double) progress / (double) progressBar.getMax()) * 100.0);
//             progressPercentage.setText("" + percentage + "%");
//             progressCount.setText(progress + "/" + progressBar.getMax());
//         }
//         this.progress = progress;
//     }
// 
//     @Override
//     public void onClick(DialogInterface dialog, int which) {
//         ((OnAlertDialogClickListener) getActivity()).onDialogFragmentClick(this, which);
//     }
// }
// 
// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/tasks/SimpleTask.java
// public class SimpleTask extends Task<Integer, String> {
// 
//     public SimpleTask(String tag) {
//         super(tag);
//     }
// 
//     @Override
//     protected String doInBackground() {
//         for(int i = 0; i < 100; i++) {
//             if(isCancelled()){
//                 break;
//             }
//             SystemClock.sleep(50);
//             publishProgress(i);
//         }
//         return "Result";
//     }
// 
//     @Override
//     protected void onPostExecute() {
//         Log.i("SimpleTask", "SimpleTask.onPostExecute()");
//     }
// }


import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import org.neotech.app.retainabletasksdemo.OnAlertDialogClickListener;
import org.neotech.app.retainabletasksdemo.ProgressDialog;
import org.neotech.app.retainabletasksdemo.R;
import org.neotech.app.retainabletasksdemo.tasks.SimpleTask;
import org.neotech.library.retainabletasks.*;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_annotations);
        findViewById(R.id.button_progress_task).setOnClickListener(this);

        if (savedInstanceState == null) {
            // After starting this activity directly start the task.
            execute();
        }
    }

    @Override
    public void onClick(View v) {
        // On click execute the task
        execute();
    }

    @Override
    public void onDialogFragmentClick(DialogFragment fragment, int which) {
        getTaskManager().cancel(TASK_PROGRESS);
    }

    @Override
    public TaskManager getTaskManager() {
        return taskManagerLifeCycleProxy.getTaskManager();
    }

    @Override
    public Task.Callback onPreAttach(@NonNull Task<?, ?> task) {
// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/OnAlertDialogClickListener.java
// public interface OnAlertDialogClickListener {
//     void onDialogFragmentClick(DialogFragment fragment, int which);
// }
// 
// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/ProgressDialog.java
// public class ProgressDialog extends DialogFragment implements DialogInterface.OnClickListener {
// 
//     public static ProgressDialog getExistingInstance(FragmentManager fragmentManager, String tag){
//         return (ProgressDialog) fragmentManager.findFragmentByTag(tag);
//     }
// 
//     public static ProgressDialog showIfNotShowing(FragmentManager fragmentManager, String tag){
//         ProgressDialog fragment = (ProgressDialog) fragmentManager.findFragmentByTag(tag);
// 
//         if (fragment == null) {
//             fragment = new ProgressDialog();
//         } else if(fragment.isAdded()){
//             return fragment;
//         }
// 
//         fragment.show(fragmentManager, tag);
//         return fragment;
//     }
// 
//     private TextView progressPercentage;
//     private TextView progressCount;
//     private ProgressBar progressBar;
//     private int progress = 0;
// 
//     @NonNull
//     @Override
//     public Dialog onCreateDialog(Bundle savedInstanceState) {
//         final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
// 
//         @SuppressLint("InflateParams")
//         final View view = LayoutInflater.from(builder.getContext()).inflate(R.layout.dialog_progress, null, false);
//         progressPercentage = (TextView) view.findViewById(R.id.progress_percentage);
//         progressCount = (TextView) view.findViewById(R.id.progress_count);
//         progressBar = (ProgressBar) view.findViewById(android.R.id.progress);
//         progressBar.setMax(100);
//         progressBar.setIndeterminate(false);
// 
//         builder.setView(view);
//         builder.setTitle(R.string.dialog_progress_title);
//         builder.setPositiveButton(R.string.action_cancel, this);
//         setCancelable(false);
//         return builder.create();
//     }
// 
//     @Override
//     public void onViewCreated(View view, Bundle savedInstanceState) {
//         if(savedInstanceState != null) {
//             progress = savedInstanceState.getInt("progress");
//         }
//         setProgress(progress);
//     }
// 
//     @Override
//     public void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         outState.putInt("progress", progress);
//     }
// 
//     @SuppressLint("SetTextI18n")
//     public void setProgress(int progress){
//         if(getDialog() != null) {
//             progressBar.setProgress(progress);
//             int percentage = (int) Math.round(((double) progress / (double) progressBar.getMax()) * 100.0);
//             progressPercentage.setText("" + percentage + "%");
//             progressCount.setText(progress + "/" + progressBar.getMax());
//         }
//         this.progress = progress;
//     }
// 
//     @Override
//     public void onClick(DialogInterface dialog, int which) {
//         ((OnAlertDialogClickListener) getActivity()).onDialogFragmentClick(this, which);
//     }
// }
// 
// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/tasks/SimpleTask.java
// public class SimpleTask extends Task<Integer, String> {
// 
//     public SimpleTask(String tag) {
//         super(tag);
//     }
// 
//     @Override
//     protected String doInBackground() {
//         for(int i = 0; i < 100; i++) {
//             if(isCancelled()){
//                 break;
//             }
//             SystemClock.sleep(50);
//             publishProgress(i);
//         }
//         return "Result";
//     }
// 
//     @Override
//     protected void onPostExecute() {
//         Log.i("SimpleTask", "SimpleTask.onPostExecute()");
//     }
// }


// Path: demo/src/main/java/org/neotech/app/retainabletasksdemo/activity/DemoActivityLifeCycleLibrary.java
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import org.neotech.app.retainabletasksdemo.OnAlertDialogClickListener;
import org.neotech.app.retainabletasksdemo.ProgressDialog;
import org.neotech.app.retainabletasksdemo.R;
import org.neotech.app.retainabletasksdemo.tasks.SimpleTask;
import org.neotech.library.retainabletasks.*;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_annotations);
        findViewById(R.id.button_progress_task).setOnClickListener(this);

        if (savedInstanceState == null) {
            // After starting this activity directly start the task.
            execute();
        }
    }

    @Override
    public void onClick(View v) {
        // On click execute the task
        execute();
    }

    @Override
    public void onDialogFragmentClick(DialogFragment fragment, int which) {
        getTaskManager().cancel(TASK_PROGRESS);
    }

    @Override
    public TaskManager getTaskManager() {
        return taskManagerLifeCycleProxy.getTaskManager();
    }

    @Override
    public Task.Callback onPreAttach(@NonNull Task<?, ?> task) {
        return null;