SourceManager.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package eu.kanade.mangafeed.data.source;
  2. import android.content.Context;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import eu.kanade.mangafeed.data.source.base.Source;
  7. import eu.kanade.mangafeed.data.source.online.english.Batoto;
  8. import eu.kanade.mangafeed.data.source.online.english.Kissmanga;
  9. import eu.kanade.mangafeed.data.source.online.english.Mangafox;
  10. import eu.kanade.mangafeed.data.source.online.english.Mangahere;
  11. public class SourceManager {
  12. public static final int BATOTO = 1;
  13. public static final int MANGAHERE = 2;
  14. public static final int MANGAFOX = 3;
  15. public static final int KISSMANGA = 4;
  16. private HashMap<Integer, Source> mSourcesMap;
  17. private Context context;
  18. public SourceManager(Context context) {
  19. mSourcesMap = new HashMap<>();
  20. this.context = context;
  21. initializeSources();
  22. }
  23. public Source get(int sourceKey) {
  24. if (!mSourcesMap.containsKey(sourceKey)) {
  25. mSourcesMap.put(sourceKey, createSource(sourceKey));
  26. }
  27. return mSourcesMap.get(sourceKey);
  28. }
  29. private Source createSource(int sourceKey) {
  30. switch (sourceKey) {
  31. case BATOTO:
  32. return new Batoto(context);
  33. case MANGAHERE:
  34. return new Mangahere(context);
  35. case MANGAFOX:
  36. return new Mangafox(context);
  37. case KISSMANGA:
  38. return new Kissmanga(context);
  39. }
  40. return null;
  41. }
  42. private void initializeSources() {
  43. mSourcesMap.put(BATOTO, createSource(BATOTO));
  44. mSourcesMap.put(MANGAHERE, createSource(MANGAHERE));
  45. mSourcesMap.put(MANGAFOX, createSource(MANGAFOX));
  46. mSourcesMap.put(KISSMANGA, createSource(KISSMANGA));
  47. }
  48. public List<Source> getSources() {
  49. return new ArrayList<>(mSourcesMap.values());
  50. }
  51. }