// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/dictionary/DictionaryProvider.java
// public class DictionaryProvider {
// 
//     private static final String DB_NAME = "DictionaryProvider.mapdb";
//     private static final Scheduler SCHEDULER = Schedulers.from(
//             new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()));
// 
//     private static DictionaryProvider instance;
// 
//     private final NamedDictionary[] dictionaries;
//     private final Set<String> enabledDictionaries;
// 
//     private DictionaryProvider(@NonNull Context context) {
//         dictionaries = new NamedDictionary[]{
//                 new NamedDictionary(context, DictionaryEnglish.getInstance(context)),
//                 new NamedDictionary(context, DictionaryEnglishNames.getInstance(context)),
//         };
// 
//         File dbFile = new File(context.getFilesDir(), DB_NAME);
//         DB db = DBMaker.fileDB(dbFile)
//                 .closeOnJvmShutdown()
//                 .asyncWriteEnable()
//                 .cacheLRUEnable()
//                 .make();
// 
//         boolean exists = db.exists(DB_NAME);
//         enabledDictionaries = db.hashSet(DB_NAME);
// 
//         Observable.just(Pair.with(exists, dictionaries))
//                 .filter(new Func1<Pair<Boolean, NamedDictionary[]>, Boolean>() {
//                     @Override
//                     public Boolean call(Pair<Boolean, NamedDictionary[]> pair) {
//                         return !pair.getValue0();
//                     }
//                 })
//                 .flatMap(new Func1<Pair<Boolean, NamedDictionary[]>, Observable<NamedDictionary>>() {
//                     @Override
//                     public Observable<NamedDictionary> call(Pair<Boolean, NamedDictionary[]> pair) {
//                         return Observable.from(pair.getValue1());
//                     }
//                 })
//                 .subscribe(new Action1<NamedDictionary>() {
//                     @Override
//                     public void call(NamedDictionary namedDictionary) {
//                         enabledDictionaries.add(namedDictionary.getDictionary().getUUID());
//                     }
//                 });
//     }
// 
//     public static DictionaryProvider getInstance(@NonNull Context context) {
//         if (instance == null) {
//             synchronized (DictionaryProvider.class) {
//                 if (instance == null) {
//                     instance = new DictionaryProvider(context.getApplicationContext());
//                 }
//             }
//         }
// 
//         return instance;
//     }
// 
//     public Observable<Boolean> setDictionaryEnabled(@NonNull String uuid, boolean enabled) {
//         return Observable.zip(
//                 Observable.just(uuid).repeat(),
//                 Observable.just(enabled).repeat(),
//                 Observable.from(dictionaries),
//                 RxTuples.<String, Boolean, NamedDictionary>toTriplet())
//                 .filter(new Func1<Triplet<String, Boolean, NamedDictionary>, Boolean>() {
//                     @Override
//                     public Boolean call(Triplet<String, Boolean, NamedDictionary> triplet) {
//                         String uuid = triplet.getValue0();
//                         return enabledDictionaries.contains(uuid);
//                     }
//                 })
//                 .map(new Func1<Triplet<String, Boolean, NamedDictionary>, Boolean>() {
//                     @Override
//                     public Boolean call(Triplet<String, Boolean, NamedDictionary> triplet) {
//                         String uuid = triplet.getValue0();
//                         Boolean enabled = triplet.getValue1();
//                         return enabled ? enabledDictionaries.add(uuid) : enabledDictionaries.remove(uuid);
//                     }
//                 })
//                 .subscribeOn(SCHEDULER);
//     }
// 
//     public Observable<IDictionaryStatus> getDictionaries() {
//         return Observable.from(dictionaries)
//                 .map(new Func1<NamedDictionary, IDictionaryStatus>() {
//                     @Override
//                     public IDictionaryStatus call(NamedDictionary namedDictionary) {
//                         String uuid = namedDictionary.getDictionary()
//                                 .getUUID();
// 
//                         boolean enabled = enabledDictionaries.contains(uuid);
//                         return new DictionaryStatus(namedDictionary, enabled);
//                     }
//                 })
//                 .subscribeOn(SCHEDULER)
//                 .asObservable();
//     }
// 
// }
// 
// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/dictionary/IDictionary.java
// public interface IDictionary {
// 
//     /**
//      * Determine if a word should be redacted.
//      *
//      * @param word the word in question
//      * @return true if the word should be redacted
//      */
//     boolean shouldRedact(@NonNull String word);
// 
//     /**
//      * The name of the dictionary.
//      *
//      * @return a string resource representation of the dictionary name.
//      */
//     @StringRes
//     int getName();
// 
//     /**
//      * A constant UUID of the dictionary.
//      *
//      * @return a constant UUID
//      */
//     @NonNull
//     String getUUID();
// 
// }
// 
// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/dictionary/IDictionaryStatus.java
// public interface IDictionaryStatus {
// 
//     IDictionary getDictionary();
// 
//     String getName();
// 
//     boolean isEnabled();
// 
// }


import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.ToxicBakery.app.screenshot_redaction.R;
import com.ToxicBakery.app.screenshot_redaction.dictionary.DictionaryProvider;
import com.ToxicBakery.app.screenshot_redaction.dictionary.IDictionary;
import com.ToxicBakery.app.screenshot_redaction.dictionary.IDictionaryStatus;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
package com.ToxicBakery.app.screenshot_redaction.widget;





public class DictionarySelectionDialog extends DialogFragment implements DialogInterface.OnMultiChoiceClickListener {

    public static final String TAG = "DictionarySelectionDialog";

// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/dictionary/DictionaryProvider.java
// public class DictionaryProvider {
// 
//     private static final String DB_NAME = "DictionaryProvider.mapdb";
//     private static final Scheduler SCHEDULER = Schedulers.from(
//             new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()));
// 
//     private static DictionaryProvider instance;
// 
//     private final NamedDictionary[] dictionaries;
//     private final Set<String> enabledDictionaries;
// 
//     private DictionaryProvider(@NonNull Context context) {
//         dictionaries = new NamedDictionary[]{
//                 new NamedDictionary(context, DictionaryEnglish.getInstance(context)),
//                 new NamedDictionary(context, DictionaryEnglishNames.getInstance(context)),
//         };
// 
//         File dbFile = new File(context.getFilesDir(), DB_NAME);
//         DB db = DBMaker.fileDB(dbFile)
//                 .closeOnJvmShutdown()
//                 .asyncWriteEnable()
//                 .cacheLRUEnable()
//                 .make();
// 
//         boolean exists = db.exists(DB_NAME);
//         enabledDictionaries = db.hashSet(DB_NAME);
// 
//         Observable.just(Pair.with(exists, dictionaries))
//                 .filter(new Func1<Pair<Boolean, NamedDictionary[]>, Boolean>() {
//                     @Override
//                     public Boolean call(Pair<Boolean, NamedDictionary[]> pair) {
//                         return !pair.getValue0();
//                     }
//                 })
//                 .flatMap(new Func1<Pair<Boolean, NamedDictionary[]>, Observable<NamedDictionary>>() {
//                     @Override
//                     public Observable<NamedDictionary> call(Pair<Boolean, NamedDictionary[]> pair) {
//                         return Observable.from(pair.getValue1());
//                     }
//                 })
//                 .subscribe(new Action1<NamedDictionary>() {
//                     @Override
//                     public void call(NamedDictionary namedDictionary) {
//                         enabledDictionaries.add(namedDictionary.getDictionary().getUUID());
//                     }
//                 });
//     }
// 
//     public static DictionaryProvider getInstance(@NonNull Context context) {
//         if (instance == null) {
//             synchronized (DictionaryProvider.class) {
//                 if (instance == null) {
//                     instance = new DictionaryProvider(context.getApplicationContext());
//                 }
//             }
//         }
// 
//         return instance;
//     }
// 
//     public Observable<Boolean> setDictionaryEnabled(@NonNull String uuid, boolean enabled) {
//         return Observable.zip(
//                 Observable.just(uuid).repeat(),
//                 Observable.just(enabled).repeat(),
//                 Observable.from(dictionaries),
//                 RxTuples.<String, Boolean, NamedDictionary>toTriplet())
//                 .filter(new Func1<Triplet<String, Boolean, NamedDictionary>, Boolean>() {
//                     @Override
//                     public Boolean call(Triplet<String, Boolean, NamedDictionary> triplet) {
//                         String uuid = triplet.getValue0();
//                         return enabledDictionaries.contains(uuid);
//                     }
//                 })
//                 .map(new Func1<Triplet<String, Boolean, NamedDictionary>, Boolean>() {
//                     @Override
//                     public Boolean call(Triplet<String, Boolean, NamedDictionary> triplet) {
//                         String uuid = triplet.getValue0();
//                         Boolean enabled = triplet.getValue1();
//                         return enabled ? enabledDictionaries.add(uuid) : enabledDictionaries.remove(uuid);
//                     }
//                 })
//                 .subscribeOn(SCHEDULER);
//     }
// 
//     public Observable<IDictionaryStatus> getDictionaries() {
//         return Observable.from(dictionaries)
//                 .map(new Func1<NamedDictionary, IDictionaryStatus>() {
//                     @Override
//                     public IDictionaryStatus call(NamedDictionary namedDictionary) {
//                         String uuid = namedDictionary.getDictionary()
//                                 .getUUID();
// 
//                         boolean enabled = enabledDictionaries.contains(uuid);
//                         return new DictionaryStatus(namedDictionary, enabled);
//                     }
//                 })
//                 .subscribeOn(SCHEDULER)
//                 .asObservable();
//     }
// 
// }
// 
// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/dictionary/IDictionary.java
// public interface IDictionary {
// 
//     /**
//      * Determine if a word should be redacted.
//      *
//      * @param word the word in question
//      * @return true if the word should be redacted
//      */
//     boolean shouldRedact(@NonNull String word);
// 
//     /**
//      * The name of the dictionary.
//      *
//      * @return a string resource representation of the dictionary name.
//      */
//     @StringRes
//     int getName();
// 
//     /**
//      * A constant UUID of the dictionary.
//      *
//      * @return a constant UUID
//      */
//     @NonNull
//     String getUUID();
// 
// }
// 
// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/dictionary/IDictionaryStatus.java
// public interface IDictionaryStatus {
// 
//     IDictionary getDictionary();
// 
//     String getName();
// 
//     boolean isEnabled();
// 
// }


// Path: app/src/main/java/com/ToxicBakery/app/screenshot_redaction/widget/DictionarySelectionDialog.java
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.ToxicBakery.app.screenshot_redaction.R;
import com.ToxicBakery.app.screenshot_redaction.dictionary.DictionaryProvider;
import com.ToxicBakery.app.screenshot_redaction.dictionary.IDictionary;
import com.ToxicBakery.app.screenshot_redaction.dictionary.IDictionaryStatus;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

package com.ToxicBakery.app.screenshot_redaction.widget;





public class DictionarySelectionDialog extends DialogFragment implements DialogInterface.OnMultiChoiceClickListener {

    public static final String TAG = "DictionarySelectionDialog";

    private DictionaryProvider dictionaryProvider;