<commit_before>package org.lodder.subtools.multisubdownloader.serviceproviders;

import org.lodder.subtools.multisubdownloader.framework.Container;
import org.lodder.subtools.multisubdownloader.framework.service.providers.ServiceProvider;
import org.lodder.subtools.multisubdownloader.subtitleproviders.SubtitleProvider;
import org.lodder.subtools.multisubdownloader.subtitleproviders.SubtitleProviderStore;
import org.lodder.subtools.multisubdownloader.subtitleproviders.adapters.JAddic7edAdapter;

public class Addic7edServiceProvider implements ServiceProvider {
  @Override
  public int getPriority() {
    /* We define a priority lower than SubtitleServiceProvider */
    return 1;
  }

  @Override
  public void register(Container app) {
    /* Resolve the SubtitleProviderStore from the IoC Container */
    SubtitleProviderStore subtitleProviderStore = (SubtitleProviderStore) app.make("SubtitleProviderStore");

    /* Create the SubtitleProvider */
    SubtitleProvider addic7edAdapter = new JAddic7edAdapter(false, "", "");

    /* Add the SubtitleProvider to the store */
    subtitleProviderStore.addProvider(addic7edAdapter);
  }
}<commit_msg>Addic7ed listen for settings change<commit_after>package org.lodder.subtools.multisubdownloader.serviceproviders;

import org.lodder.subtools.multisubdownloader.framework.Container;
import org.lodder.subtools.multisubdownloader.framework.event.Emitter;
import org.lodder.subtools.multisubdownloader.framework.event.Event;
import org.lodder.subtools.multisubdownloader.framework.event.Handler;
import org.lodder.subtools.multisubdownloader.framework.service.providers.ServiceProvider;
import org.lodder.subtools.multisubdownloader.settings.model.Settings;
import org.lodder.subtools.multisubdownloader.subtitleproviders.SubtitleProvider;
import org.lodder.subtools.multisubdownloader.subtitleproviders.SubtitleProviderStore;
import org.lodder.subtools.multisubdownloader.subtitleproviders.adapters.JAddic7edAdapter;

public class Addic7edServiceProvider implements ServiceProvider {

  protected Container app;
  protected SubtitleProvider subtitleProvider;

  @Override
  public int getPriority() {
    /* We define a priority lower than SubtitleServiceProvider */
    return 1;
  }

  @Override
  public void register(Container app) {

    this.app = app;

    /* Resolve the SubtitleProviderStore from the IoC Container */
    final SubtitleProviderStore subtitleProviderStore = (SubtitleProviderStore) app.make("SubtitleProviderStore");

    /* Create the SubtitleProvider */
    subtitleProvider = createProvider();

    /* Add the SubtitleProvider to the store */
    subtitleProviderStore.addProvider(subtitleProvider);

    /* Listen for settings-change event */
    this.registerListener(subtitleProviderStore);
  }

  private SubtitleProvider createProvider() {
    Settings settings = (Settings) this.app.make("Settings");

    boolean loginEnabled = false;
    String username = "";
    String password = "";
    if (settings.isLoginAddic7edEnabled()) {
      loginEnabled = true;
      username = settings.getLoginAddic7edUsername();
      password = <PASSWORD>();
    }

    /* Nullpointer safety */
    username = username == null ? "" : username.trim();
    password = password == null ? "" : password.trim();

    /* Protect against empty login */
    if (loginEnabled && (username.isEmpty() || password.isEmpty())) {
      loginEnabled = false;
    }

    return new JAddic7edAdapter(loginEnabled, username, password);
  }

  private void registerListener(final SubtitleProviderStore subtitleProviderStore) {
    /* Resolve the EventEmitter from the IoC Container */
    Emitter emitter = (Emitter) app.make("EventEmitter");

    /* Listen for settings-change */
    emitter.listen("providers.settings.change", new Handler() {
      @Override
      public void handle(Event event) {
        /* Change occured, delete outdated provider from store */
        subtitleProviderStore.deleteProvider(subtitleProvider);

        /* Re-create subtitleprovider */
        subtitleProvider = createProvider();

        /* Re-add provider to store */
        subtitleProviderStore.addProvider(subtitleProvider);
      }
    });
  }
}
{'fraction_non_alphanumeric': 0.09199237368922783, 'fraction_numerical': 0.003098188751191611, 'mean_word_length': 4.500655307994758, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7255934', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1132, 'n_words': 235}