@@ -0,0 +1,3589 @@
+package io.github.lonamiwebs.stringlate.utilities;%0A%0A%0Aimport android.app.NotificationManager;%0Aimport android.app.PendingIntent;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.os.AsyncTask;%0Aimport android.support.annotation.NonNull;%0Aimport android.support.v4.app.NotificationCompat;%0Aimport android.widget.Toast;%0A%0Aimport java.util.Random;%0A%0Aimport io.github.lonamiwebs.stringlate.R;%0A%0A// Helper class to run some code in the background and while it's running,%0A// show a notification. Once the code has been ran and if it succeeds,%0A// another clickable notification will spawn. Tapping it will take the%0A// user to the specified activity. If it didn't succeed, a toast will appear.%0Apublic abstract class NotificationRunner extends AsyncTask%3CVoid, Void, Boolean%3E %7B%0A%0A    protected final Context mContext;%0A    private final NotificationManager mNotificationManager;%0A    private final NotificationCompat.Builder mNotifyBuilder;%0A%0A    @NonNull%0A    private String mRunningTitle, mRunningText, mSuccessTitle, mSuccessText, mFailText;%0A    private Intent mLaunchOnSuccess;%0A%0A    private final int mNotificationId;%0A%0A    protected NotificationRunner(final Context context) %7B%0A        mContext = context;%0A%0A        mRunningTitle = mRunningText = mSuccessTitle = mSuccessText = mFailText = %22%22;%0A        mNotificationId = 200 + new Random().nextInt(100);%0A        mNotificationManager =%0A                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);%0A%0A        mNotifyBuilder =%0A                new NotificationCompat.Builder(context, %22async.task%22)%0A                        .setSmallIcon(R.mipmap.ic_launcher)%0A                        .setOngoing(true);%0A    %7D%0A%0A    public NotificationRunner setRunning(final String title, final String text) %7B%0A        mRunningTitle = title;%0A        mRunningText = text;%0A        return this;%0A    %7D%0A%0A    public NotificationRunner setSuccess(final String title, final String text, final Intent intent) %7B%0A        mSuccessTitle = title;%0A        mSuccessText = text;%0A        mLaunchOnSuccess = intent;%0A        return this;%0A    %7D%0A%0A    public NotificationRunner setFailure(final String text) %7B%0A        mFailText = text;%0A        return this;%0A    %7D%0A%0A    @Override%0A    protected void onPreExecute() %7B%0A        mNotifyBuilder%0A                .setContentTitle(mRunningTitle)%0A                .setContentText(mRunningText);%0A%0A        if (!mRunningTitle.isEmpty() %7C%7C !mRunningText.isEmpty())%0A            mNotificationManager.notify(mNotificationId, mNotifyBuilder.build());%0A    %7D%0A%0A    protected void updateProgress(final String title, final String text) %7B%0A        mNotifyBuilder%0A                .setContentTitle(title)%0A                .setContentText(text);%0A        publishProgress();%0A    %7D%0A%0A    @Override%0A    protected void onProgressUpdate(Void... values) %7B%0A        mNotificationManager.notify(mNotificationId, mNotifyBuilder.build());%0A    %7D%0A%0A    @Override%0A    protected void onPostExecute(Boolean success) %7B%0A        if (success) %7B%0A            mNotifyBuilder%0A                    .setContentTitle(mSuccessTitle)%0A                    .setContentText(mSuccessText)%0A                    .setOngoing(false)%0A                    .setAutoCancel(true)%0A                    .setContentIntent(PendingIntent.getActivity(%0A                            mContext, 0, mLaunchOnSuccess, PendingIntent.FLAG_CANCEL_CURRENT%0A                    ));%0A            mNotificationManager.notify(mNotificationId, mNotifyBuilder.build());%0A        %7D else if (!mFailText.isEmpty()) %7B%0A            Toast.makeText(mContext, mFailText, Toast.LENGTH_SHORT).show();%0A        %7D%0A    %7D%0A%7D%0A

Create a new NotificationRunner class to easily run things async