Skip to content

Commit

Permalink
Fixed the bug on Android 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Jan 8, 2018
1 parent 059544e commit 93b0a45
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void resetOSMDroidTest() throws IOException {
}

private void resetAppState(List<Integer> resetActions) {
List<Integer> failedResetActions = new ResetUtility().reset(resetActions);
List<Integer> failedResetActions = new ResetUtility().reset(InstrumentationRegistry.getTargetContext(), resetActions);
assertEquals(0, failedResetActions.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.odk.collect.android.dao;

import android.database.Cursor;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
Expand Down Expand Up @@ -306,7 +307,7 @@ private void resetAppState() {
ResetUtility.ResetAction.RESET_CACHE, ResetUtility.ResetAction.RESET_OSM_DROID
);

List<Integer> failedResetActions = new ResetUtility().reset(resetActions);
List<Integer> failedResetActions = new ResetUtility().reset(InstrumentationRegistry.getTargetContext(), resetActions);
assertEquals(0, failedResetActions.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void resetSelected() {
Runnable runnable = new Runnable() {
@Override
public void run() {
List<Integer> failedResetActions = new ResetUtility().reset(resetActions);
List<Integer> failedResetActions = new ResetUtility().reset(getContext(), resetActions);
hideProgressDialog();
handleResult(resetActions, failedResetActions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.odk.collect.android.utilities;

import android.content.Context;

import org.odk.collect.android.application.Collect;
import org.odk.collect.android.dao.FormsDao;
import org.odk.collect.android.dao.InstancesDao;
Expand All @@ -32,15 +34,15 @@ public class ResetUtility {

private List<Integer> failedResetActions;

public List<Integer> reset(List<Integer> resetActions) {
public List<Integer> reset(Context context, List<Integer> resetActions) {

failedResetActions = new ArrayList<>();
failedResetActions.addAll(resetActions);

for (int action : resetActions) {
switch (action) {
case ResetAction.RESET_PREFERENCES:
resetPreferences();
resetPreferences(context);
break;
case ResetAction.RESET_INSTANCES:
resetInstances();
Expand Down Expand Up @@ -69,7 +71,7 @@ public List<Integer> reset(List<Integer> resetActions) {
return failedResetActions;
}

private void resetPreferences() {
private void resetPreferences(Context context) {
GeneralSharedPreferences.getInstance().loadDefaultPreferences();
AdminSharedPreferences.getInstance().loadDefaultPreferences();

Expand All @@ -79,7 +81,7 @@ private void resetPreferences() {
boolean deletedSettingsFile = !new File(Collect.ODK_ROOT + "/collect.settings").exists()
|| (new File(Collect.ODK_ROOT + "/collect.settings").delete());

new LocaleHelper().updateLocale(Collect.getInstance());
new LocaleHelper().updateLocale(context);

if (deletedSettingsFolderContest && deletedSettingsFile) {
failedResetActions.remove(failedResetActions.indexOf(ResetAction.RESET_PREFERENCES));
Expand Down

0 comments on commit 93b0a45

Please sign in to comment.