Skip to content

Commit be2b944

Browse files
committed
Fix codacy
1 parent aec4300 commit be2b944

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
2525
import com.nostra13.universalimageloader.utils.StorageUtils;
2626

27+
import fr.free.nrw.commons.caching.CacheController;
28+
import fr.free.nrw.commons.category.Category;
29+
import fr.free.nrw.commons.contributions.Contribution;
30+
import fr.free.nrw.commons.data.DBOpenHelper;
31+
import fr.free.nrw.commons.modifications.ModifierSequence;
2732
import fr.free.nrw.commons.auth.AccountUtil;
33+
2834
import org.acra.ACRA;
2935
import org.acra.ReportingInteractionMode;
3036
import org.acra.annotation.ReportsCrashes;
@@ -42,11 +48,7 @@
4248
import java.io.File;
4349
import java.io.IOException;
4450

45-
import fr.free.nrw.commons.caching.CacheController;
46-
import fr.free.nrw.commons.category.Category;
47-
import fr.free.nrw.commons.contributions.Contribution;
48-
import fr.free.nrw.commons.data.DBOpenHelper;
49-
import fr.free.nrw.commons.modifications.ModifierSequence;
51+
import fr.free.nrw.commons.utils.FileUtils;
5052
import timber.log.Timber;
5153

5254
// TODO: Use ProGuard to rip out reporting when publishing
@@ -234,7 +236,7 @@ public void clearApplicationData(Context context) {
234236
String[] fileNames = applicationDirectory.list();
235237
for (String fileName : fileNames) {
236238
if (!fileName.equals("lib")) {
237-
deleteFile(new File(applicationDirectory, fileName));
239+
FileUtils.deleteFile(new File(applicationDirectory, fileName));
238240
}
239241
}
240242
}
@@ -247,14 +249,19 @@ public void clearApplicationData(Context context) {
247249

248250
//TODO: fix preference manager
249251
PreferenceManager.getDefaultSharedPreferences(app).edit().clear().commit();
250-
SharedPreferences preferences = context.getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
252+
SharedPreferences preferences = context
253+
.getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
251254
preferences.edit().clear().commit();
252-
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();;
255+
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
253256
preferences.edit().putBoolean("firstrun", false).apply();
254257
updateAllDatabases(context);
255258
currentAccount = null;
256259
}
257260

261+
/**
262+
* Deletes all tables and re-creates them.
263+
* @param context context
264+
*/
258265
public void updateAllDatabases(Context context) {
259266
DBOpenHelper dbOpenHelper = DBOpenHelper.getInstance(context);
260267
dbOpenHelper.getReadableDatabase().close();
@@ -264,20 +271,4 @@ public void updateAllDatabases(Context context) {
264271
Category.Table.onDelete(db);
265272
Contribution.Table.onDelete(db);
266273
}
267-
268-
public static boolean deleteFile(File file) {
269-
boolean deletedAll = true;
270-
if (file != null) {
271-
if (file.isDirectory()) {
272-
String[] children = file.list();
273-
for (int i = 0; i < children.length; i++) {
274-
deletedAll = deleteFile(new File(file, children[i])) && deletedAll;
275-
}
276-
} else {
277-
deletedAll = file.delete();
278-
}
279-
}
280-
281-
return deletedAll;
282-
}
283274
}

app/src/main/java/fr/free/nrw/commons/hamburger/NavigationBaseFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ protected void onLogoutItemClicked() {
131131
.setPositiveButton(R.string.yes,
132132
new DialogInterface.OnClickListener() {
133133
public void onClick(DialogInterface dialog, int id) {
134-
((CommonsApplication)getActivity().getApplicationContext()).clearApplicationData(getContext());
135-
Intent nearbyIntent = new Intent(getActivity(), LoginActivity.class);
134+
((CommonsApplication)getActivity().getApplicationContext())
135+
.clearApplicationData(getContext());
136+
Intent nearbyIntent = new Intent
137+
(getActivity(), LoginActivity.class);
136138
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
137139
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
138140
startActivity(nearbyIntent);

app/src/main/java/fr/free/nrw/commons/utils/FileUtils.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44

55
import java.io.BufferedReader;
6+
import java.io.File;
67
import java.io.IOException;
78
import java.io.InputStreamReader;
89

@@ -32,4 +33,26 @@ public static String readFromFile(Context context, String fileName) {
3233
}
3334
return stringBuilder;
3435
}
36+
37+
/**
38+
* Deletes files.
39+
* @param file context
40+
*/
41+
public static boolean deleteFile(File file) {
42+
boolean deletedAll = true;
43+
if (file != null) {
44+
if (file.isDirectory()) {
45+
String[] children = file.list();
46+
for (int i = 0; i < children.length; i++) {
47+
deletedAll = deleteFile(new File(file, children[i])) && deletedAll;
48+
}
49+
} else {
50+
deletedAll = file.delete();
51+
}
52+
}
53+
54+
return deletedAll;
55+
}
56+
57+
3558
}

0 commit comments

Comments
 (0)