mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Merge pull request #611 from neslihanturan/logoutFunctionality
Logout functionality
This commit is contained in:
commit
45a19620b9
7 changed files with 125 additions and 1 deletions
|
|
@ -5,9 +5,13 @@ import android.accounts.AccountManager;
|
||||||
import android.accounts.AuthenticatorException;
|
import android.accounts.AuthenticatorException;
|
||||||
import android.accounts.OperationCanceledException;
|
import android.accounts.OperationCanceledException;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.util.LruCache;
|
import android.support.v4.util.LruCache;
|
||||||
|
|
||||||
import com.android.volley.RequestQueue;
|
import com.android.volley.RequestQueue;
|
||||||
|
|
@ -20,7 +24,13 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.caching.CacheController;
|
||||||
|
import fr.free.nrw.commons.category.Category;
|
||||||
|
import fr.free.nrw.commons.contributions.Contribution;
|
||||||
|
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
|
import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||||
import fr.free.nrw.commons.auth.AccountUtil;
|
import fr.free.nrw.commons.auth.AccountUtil;
|
||||||
|
|
||||||
import org.acra.ACRA;
|
import org.acra.ACRA;
|
||||||
import org.acra.ReportingInteractionMode;
|
import org.acra.ReportingInteractionMode;
|
||||||
import org.acra.annotation.ReportsCrashes;
|
import org.acra.annotation.ReportsCrashes;
|
||||||
|
|
@ -35,9 +45,10 @@ import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.CoreProtocolPNames;
|
import org.apache.http.params.CoreProtocolPNames;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import fr.free.nrw.commons.caching.CacheController;
|
import fr.free.nrw.commons.utils.FileUtils;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
// TODO: Use ProGuard to rip out reporting when publishing
|
// TODO: Use ProGuard to rip out reporting when publishing
|
||||||
|
|
@ -217,4 +228,47 @@ public class CommonsApplication extends Application {
|
||||||
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) ||
|
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) ||
|
||||||
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
|
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearApplicationData(Context context) {
|
||||||
|
File cacheDirectory = context.getCacheDir();
|
||||||
|
File applicationDirectory = new File(cacheDirectory.getParent());
|
||||||
|
if (applicationDirectory.exists()) {
|
||||||
|
String[] fileNames = applicationDirectory.list();
|
||||||
|
for (String fileName : fileNames) {
|
||||||
|
if (!fileName.equals("lib")) {
|
||||||
|
FileUtils.deleteFile(new File(applicationDirectory, fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountManager accountManager = AccountManager.get(this);
|
||||||
|
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
|
||||||
|
for (int index = 0; index < allAccounts.length; index++) {
|
||||||
|
accountManager.removeAccount(allAccounts[index], null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: fix preference manager
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(app).edit().clear().commit();
|
||||||
|
SharedPreferences preferences = context
|
||||||
|
.getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
|
||||||
|
preferences.edit().clear().commit();
|
||||||
|
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
|
||||||
|
preferences.edit().putBoolean("firstrun", false).apply();
|
||||||
|
updateAllDatabases(context);
|
||||||
|
currentAccount = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all tables and re-creates them.
|
||||||
|
* @param context context
|
||||||
|
*/
|
||||||
|
public void updateAllDatabases(Context context) {
|
||||||
|
DBOpenHelper dbOpenHelper = DBOpenHelper.getInstance(context);
|
||||||
|
dbOpenHelper.getReadableDatabase().close();
|
||||||
|
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||||
|
|
||||||
|
ModifierSequence.Table.onDelete(db);
|
||||||
|
Category.Table.onDelete(db);
|
||||||
|
Contribution.Table.onDelete(db);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,11 @@ public class Category {
|
||||||
db.execSQL(CREATE_TABLE_STATEMENT);
|
db.execSQL(CREATE_TABLE_STATEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onDelete(SQLiteDatabase db) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
public static void onUpdate(SQLiteDatabase db, int from, int to) {
|
public static void onUpdate(SQLiteDatabase db, int from, int to) {
|
||||||
if(from == to) {
|
if(from == to) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,11 @@ public class Contribution extends Media {
|
||||||
db.execSQL(CREATE_TABLE_STATEMENT);
|
db.execSQL(CREATE_TABLE_STATEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onDelete(SQLiteDatabase db) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
public static void onUpdate(SQLiteDatabase db, int from, int to) {
|
public static void onUpdate(SQLiteDatabase db, int from, int to) {
|
||||||
if(from == to) {
|
if(from == to) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package fr.free.nrw.commons.hamburger;
|
package fr.free.nrw.commons.hamburger;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
@ -21,6 +23,7 @@ import fr.free.nrw.commons.AboutActivity;
|
||||||
import fr.free.nrw.commons.BuildConfig;
|
import fr.free.nrw.commons.BuildConfig;
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
import fr.free.nrw.commons.auth.LoginActivity;
|
||||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||||
import fr.free.nrw.commons.nearby.NearbyActivity;
|
import fr.free.nrw.commons.nearby.NearbyActivity;
|
||||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||||
|
|
@ -120,6 +123,34 @@ public class NavigationBaseFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.logout_item)
|
||||||
|
protected void onLogoutItemClicked() {
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
|
||||||
|
alertDialogBuilder.setMessage(R.string.logout_verification)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(R.string.yes,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
((CommonsApplication)getActivity().getApplicationContext())
|
||||||
|
.clearApplicationData(getContext());
|
||||||
|
Intent nearbyIntent = new Intent
|
||||||
|
(getActivity(), LoginActivity.class);
|
||||||
|
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(nearbyIntent);
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertDialogBuilder.setNegativeButton(R.string.no,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog alert = alertDialogBuilder.create();
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void closeDrawer() {
|
private void closeDrawer() {
|
||||||
if (drawerLayout != null) {
|
if (drawerLayout != null) {
|
||||||
drawerLayout.closeDrawer(drawerPane);
|
drawerLayout.closeDrawer(drawerPane);
|
||||||
|
|
|
||||||
|
|
@ -142,5 +142,10 @@ public class ModifierSequence {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onDelete(SQLiteDatabase db) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons.utils;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
|
@ -32,4 +33,26 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
return stringBuilder;
|
return stringBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes files.
|
||||||
|
* @param file context
|
||||||
|
*/
|
||||||
|
public static boolean deleteFile(File file) {
|
||||||
|
boolean deletedAll = true;
|
||||||
|
if (file != null) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
String[] children = file.list();
|
||||||
|
for (int i = 0; i < children.length; i++) {
|
||||||
|
deletedAll = deleteFile(new File(file, children[i])) && deletedAll;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deletedAll = file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deletedAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,7 @@ Tap this message (or hit back) to skip this step.</string>
|
||||||
<string name="maximum_limit_alert">Unable to display more than 500</string>
|
<string name="maximum_limit_alert">Unable to display more than 500</string>
|
||||||
<string name="set_limit">Set Recent Upload Limit</string>
|
<string name="set_limit">Set Recent Upload Limit</string>
|
||||||
<string name="login_failed_2fa_not_supported">Two factor authentication is currently not supported.</string>
|
<string name="login_failed_2fa_not_supported">Two factor authentication is currently not supported.</string>
|
||||||
|
<string name="logout_verification">Do you really want to logout?</string>
|
||||||
|
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="navigation_drawer_open">Open</string>
|
<string name="navigation_drawer_open">Open</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue