mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Clean app data (keeping the PASSCODE untouched) from ManageSpaceActivity
This commit is contained in:
parent
d6653ef684
commit
96ce49707b
4 changed files with 139 additions and 2 deletions
|
@ -204,7 +204,8 @@
|
|||
android:resource="@xml/users_and_groups_searchable"/>
|
||||
</activity>
|
||||
<activity android:name=".ui.activity.ManageSpaceActivity"
|
||||
android:label="@string/manage_space"/>
|
||||
android:label="@string/manage_space_title"
|
||||
android:theme="@style/Theme.ownCloud" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -4,4 +4,26 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/general_description"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:singleLine="false"
|
||||
android:layout_margin="10dp"
|
||||
style="?android:attr/editTextPreferenceStyle"
|
||||
android:text="@string/manage_space_description"
|
||||
/>
|
||||
|
||||
<android.support.v7.widget.AppCompatButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/manage_space_clear_data"
|
||||
android:id="@+id/clearDataButton"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_margin="4dp"
|
||||
android:theme="@style/Button.Primary"
|
||||
style="@style/Button.Primary"
|
||||
android:contentDescription="@string/manage_space_clear_data"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -405,5 +405,8 @@
|
|||
<string name="action_switch_grid_view">Grid view</string>
|
||||
<string name="action_switch_list_view">List view</string>
|
||||
|
||||
<string name="manage_space">Manage space</string>
|
||||
<string name="manage_space_title">Manage space</string>
|
||||
<string name="manage_space_description"> All %1$s\'s data will be deleted permanentlty. \nThis includes all files, settings, accounts, databases, etc. \n\nThis process can take some minutes.</string>
|
||||
<string name="manage_space_clear_data">Clear data</string>
|
||||
<string name="manage_string_message">%1$s\'s data deleted</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,17 +1,128 @@
|
|||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ManageSpaceActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = ManageSpaceActivity.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_space);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setTitle(R.string.manage_space_title);
|
||||
|
||||
TextView descriptionTextView = (TextView) findViewById(R.id.general_description);
|
||||
descriptionTextView.setText(getString(R.string.manage_space_description, getString(R.string.app_name)));
|
||||
|
||||
Button clearDataButton = (Button) findViewById(R.id.clearDataButton);
|
||||
clearDataButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
clearData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Save passcode from Share preferences
|
||||
* Clear the rest of data
|
||||
*/
|
||||
private void clearData() {
|
||||
// Save passcode from Share preferences
|
||||
SharedPreferences appPrefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
boolean passCodeEnable = appPrefs.getBoolean("set_pincode", false);
|
||||
|
||||
String passCodeDigits[] = new String[4];
|
||||
if (passCodeEnable) {
|
||||
passCodeDigits[0] = appPrefs.getString("PrefPinCode1", null);
|
||||
passCodeDigits[1] = appPrefs.getString("PrefPinCode2", null);
|
||||
passCodeDigits[2] = appPrefs.getString("PrefPinCode3", null);
|
||||
passCodeDigits[3] = appPrefs.getString("PrefPinCode4", null);
|
||||
}
|
||||
|
||||
// Clear data
|
||||
clearApplicationData();
|
||||
|
||||
// Recover passcode
|
||||
SharedPreferences.Editor appPrefsEditor = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
if (passCodeEnable) {
|
||||
appPrefsEditor.putString("PrefPinCode1", passCodeDigits[0]);
|
||||
appPrefsEditor.putString("PrefPinCode2", passCodeDigits[1]);
|
||||
appPrefsEditor.putString("PrefPinCode3", passCodeDigits[2]);
|
||||
appPrefsEditor.putString("PrefPinCode4", passCodeDigits[3]);
|
||||
}
|
||||
|
||||
appPrefsEditor.putBoolean("set_pincode", passCodeEnable);
|
||||
appPrefsEditor.commit();
|
||||
|
||||
String message = getString(R.string.manage_string_message, getString(R.string.app_name));
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
|
||||
public void clearApplicationData() {
|
||||
File cache = getCacheDir();
|
||||
File appDir = new File(cache.getParent());
|
||||
if (appDir.exists()) {
|
||||
String[] children = appDir.list();
|
||||
for (String s : children) {
|
||||
if (!s.equals("lib")) {
|
||||
deleteDir(new File(appDir, s));
|
||||
Log_OC.i(TAG, "*******File /data/data/" + getString(R.string.app_name)+
|
||||
"/" + s + " DELETED *******");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteDir(File dir) {
|
||||
if (dir != null && dir.isDirectory()) {
|
||||
String[] children = dir.list();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
boolean success = deleteDir(new File(dir, children[i]));
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dir.delete();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
default:
|
||||
Log_OC.w(TAG, "Unknown menu item triggered");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue