@Test public void defaultRepos() { int defaultRepoCount = RepoProviderTest.getDefaultRepoCount(context); List<Repo> defaultRepos = RepoProvider.Helper.all(context); assertEquals(defaultRepos.size(), defaultRepoCount); Repo gpRepo = RepoProvider.Helper.findByAddress(context, "https: setEnabled(gpRepo, true); assertEquals(2, RepoProvider.Helper.countEnabledRepos(context)); PanicResponderActivity.resetRepos(context); assertEquals(1, RepoProvider.Helper.countEnabledRepos(context)); defaultRepos = RepoProvider.Helper.all(context); assertEquals(defaultRepoCount, defaultRepos.size()); RepoProviderTest.insertRepo( context, "https: "Just a made up repo", "ABCDEF1234567890", "Mock Repo 1" ); defaultRepos = RepoProvider.Helper.all(context); assertEquals(defaultRepoCount + 1, defaultRepos.size()); assertEquals(2, RepoProvider.Helper.countEnabledRepos(context)); PanicResponderActivity.resetRepos(context); defaultRepos = RepoProvider.Helper.all(context); assertEquals(defaultRepoCount, defaultRepos.size()); assertEquals(1, RepoProvider.Helper.countEnabledRepos(context)); }
static void resetRepos(Context context) { HashSet<String> enabledAddresses = new HashSet<>(); HashSet<String> disabledAddresses = new HashSet<>(); String[] defaultReposItems = DBHelper.loadInitialRepos(context).toArray(new String[0]); for (int i = 1; i < defaultReposItems.length; i += DBHelper.REPO_XML_ITEM_COUNT) { if ("1".equals(defaultReposItems[i + 3])) { enabledAddresses.add(defaultReposItems[i]); } else { disabledAddresses.add(defaultReposItems[i]); } } List<Repo> repos = RepoProvider.Helper.all(context); for (Repo repo : repos) { ContentValues values = new ContentValues(1); if (enabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, true); RepoProvider.Helper.update(context, repo, values); } else if (disabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, false); RepoProvider.Helper.update(context, repo, values); } else { RepoProvider.Helper.remove(context, repo.getId()); } } }
PanicResponderActivity extends AppCompatActivity { static void resetRepos(Context context) { HashSet<String> enabledAddresses = new HashSet<>(); HashSet<String> disabledAddresses = new HashSet<>(); String[] defaultReposItems = DBHelper.loadInitialRepos(context).toArray(new String[0]); for (int i = 1; i < defaultReposItems.length; i += DBHelper.REPO_XML_ITEM_COUNT) { if ("1".equals(defaultReposItems[i + 3])) { enabledAddresses.add(defaultReposItems[i]); } else { disabledAddresses.add(defaultReposItems[i]); } } List<Repo> repos = RepoProvider.Helper.all(context); for (Repo repo : repos) { ContentValues values = new ContentValues(1); if (enabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, true); RepoProvider.Helper.update(context, repo, values); } else if (disabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, false); RepoProvider.Helper.update(context, repo, values); } else { RepoProvider.Helper.remove(context, repo.getId()); } } } }
PanicResponderActivity extends AppCompatActivity { static void resetRepos(Context context) { HashSet<String> enabledAddresses = new HashSet<>(); HashSet<String> disabledAddresses = new HashSet<>(); String[] defaultReposItems = DBHelper.loadInitialRepos(context).toArray(new String[0]); for (int i = 1; i < defaultReposItems.length; i += DBHelper.REPO_XML_ITEM_COUNT) { if ("1".equals(defaultReposItems[i + 3])) { enabledAddresses.add(defaultReposItems[i]); } else { disabledAddresses.add(defaultReposItems[i]); } } List<Repo> repos = RepoProvider.Helper.all(context); for (Repo repo : repos) { ContentValues values = new ContentValues(1); if (enabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, true); RepoProvider.Helper.update(context, repo, values); } else if (disabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, false); RepoProvider.Helper.update(context, repo, values); } else { RepoProvider.Helper.remove(context, repo.getId()); } } }  }
PanicResponderActivity extends AppCompatActivity { static void resetRepos(Context context) { HashSet<String> enabledAddresses = new HashSet<>(); HashSet<String> disabledAddresses = new HashSet<>(); String[] defaultReposItems = DBHelper.loadInitialRepos(context).toArray(new String[0]); for (int i = 1; i < defaultReposItems.length; i += DBHelper.REPO_XML_ITEM_COUNT) { if ("1".equals(defaultReposItems[i + 3])) { enabledAddresses.add(defaultReposItems[i]); } else { disabledAddresses.add(defaultReposItems[i]); } } List<Repo> repos = RepoProvider.Helper.all(context); for (Repo repo : repos) { ContentValues values = new ContentValues(1); if (enabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, true); RepoProvider.Helper.update(context, repo, values); } else if (disabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, false); RepoProvider.Helper.update(context, repo, values); } else { RepoProvider.Helper.remove(context, repo.getId()); } } }  @Override void onCreate(Bundle savedInstanceState); }
PanicResponderActivity extends AppCompatActivity { static void resetRepos(Context context) { HashSet<String> enabledAddresses = new HashSet<>(); HashSet<String> disabledAddresses = new HashSet<>(); String[] defaultReposItems = DBHelper.loadInitialRepos(context).toArray(new String[0]); for (int i = 1; i < defaultReposItems.length; i += DBHelper.REPO_XML_ITEM_COUNT) { if ("1".equals(defaultReposItems[i + 3])) { enabledAddresses.add(defaultReposItems[i]); } else { disabledAddresses.add(defaultReposItems[i]); } } List<Repo> repos = RepoProvider.Helper.all(context); for (Repo repo : repos) { ContentValues values = new ContentValues(1); if (enabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, true); RepoProvider.Helper.update(context, repo, values); } else if (disabledAddresses.contains(repo.address)) { values.put(Schema.RepoTable.Cols.IN_USE, false); RepoProvider.Helper.update(context, repo, values); } else { RepoProvider.Helper.remove(context, repo.getId()); } } }  @Override void onCreate(Bundle savedInstanceState);  }