Adds cache clear feature
This commit is contained in:
parent
a1e1a3bd06
commit
e6ff90c0d7
|
@ -16,8 +16,6 @@ android {
|
|||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -15,6 +15,7 @@
|
|||
package fr.gouv.etalab.mastodon.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
@ -23,6 +24,7 @@ import android.os.Bundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
@ -37,6 +39,7 @@ import android.view.MenuItem;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
|
@ -46,7 +49,7 @@ import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
@ -321,6 +324,39 @@ public class MainActivity extends AppCompatActivity
|
|||
}else if(id == R.id.action_about_instance){
|
||||
Intent intent = new Intent(getApplicationContext(), InstanceActivity.class);
|
||||
startActivity(intent);
|
||||
} else if( id == R.id.action_cache){ //Cache clear feature
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||
builder.setTitle(R.string.cache_title);
|
||||
long sizeCache = Helper.cacheSize(getCacheDir());
|
||||
float cacheSize = 0;
|
||||
if( sizeCache > 0 ) {
|
||||
if (sizeCache > 0) {
|
||||
cacheSize = (float) sizeCache / 1000000.0f;
|
||||
}
|
||||
}
|
||||
final float finalCacheSize = cacheSize;
|
||||
builder.setMessage(getString(R.string.cache_message, String.format("%s Mo", String.format(Locale.getDefault(), "%.2f", cacheSize))))
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// continue with delete
|
||||
try {
|
||||
String path = getCacheDir().getPath();
|
||||
File dir = new File(path);
|
||||
if (dir.isDirectory()) {
|
||||
Helper.deleteDir(dir);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
Toast.makeText(MainActivity.this, getString(R.string.toast_cache_clear,String.format("%s Mo", String.format(Locale.getDefault(), "%.2f", finalCacheSize))), Toast.LENGTH_LONG).show();
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
} else if(id == R.id.action_search){
|
||||
|
||||
if( toolbar.getChildCount() > 0){
|
||||
|
|
|
@ -315,7 +315,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
//Text depending if toots is sensitive or not
|
||||
String textShowMore = (status.getReblog().isSensitive()) ? context.getString(R.string.load_sensitive_attachment) : context.getString(R.string.load_attachment);
|
||||
holder.status_show_more.setText(textShowMore);
|
||||
if (!status.getReblog().isAttachmentShown()) {
|
||||
if (!status.isAttachmentShown()) {
|
||||
holder.status_show_more.setVisibility(View.VISIBLE);
|
||||
holder.status_document_container.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.Resources;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -42,7 +41,6 @@ import android.support.design.widget.NavigationView;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
@ -59,7 +57,6 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
|
@ -173,7 +170,7 @@ public class Helper {
|
|||
private static final Pattern SHORTNAME_PATTERN = Pattern.compile(":([-+\\w]+):");
|
||||
|
||||
/**
|
||||
* Convert emojis in input to unicode
|
||||
* Converts emojis in input to unicode
|
||||
* @param input String
|
||||
* @param removeIfUnsupported boolean
|
||||
* @return String
|
||||
|
@ -198,21 +195,20 @@ public class Helper {
|
|||
private static Map<String, String> emoji = new HashMap<>();
|
||||
|
||||
public static void fillMapEmoji(Context context) {
|
||||
// here comes file reading code with loop
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(context.getAssets().open("emoji.csv")));
|
||||
String line;
|
||||
while( (line = br.readLine()) != null) {
|
||||
String str[] = line.split(",");
|
||||
String unicode = null;
|
||||
if(str.length == 4)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16)},Integer.parseInt(str[2].trim()),Integer.parseInt(str[3].trim()));
|
||||
if(str.length == 2)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16)}, 0, 1);
|
||||
else if(str.length == 3)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16), Integer.parseInt(str[2].replace("0x","").trim(), 16)}, 0, 2);
|
||||
else if(str.length == 4)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16), Integer.parseInt(str[2].replace("0x","").trim(), 16), Integer.parseInt(str[3].replace("0x","").trim(), 16)}, 0, 3);
|
||||
else if(str.length == 5)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16), Integer.parseInt(str[2].replace("0x","").trim(), 16)},Integer.parseInt(str[3].trim()), Integer.parseInt(str[4].trim()));
|
||||
else if(str.length == 6)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16), Integer.parseInt(str[2].replace("0x","").trim(), 16), Integer.parseInt(str[3].replace("0x","").trim(), 16)}, Integer.parseInt(str[4].trim()), Integer.parseInt(str[5].trim()));
|
||||
else if(str.length == 7)
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16), Integer.parseInt(str[2].replace("0x","").trim(), 16), Integer.parseInt(str[3].replace("0x","").trim(), 16), Integer.parseInt(str[4].replace("0x","").trim(), 16)}, Integer.parseInt(str[5].trim()),Integer.parseInt(str[6].trim()));
|
||||
unicode = new String(new int[] {Integer.parseInt(str[1].replace("0x","").trim(), 16), Integer.parseInt(str[2].replace("0x","").trim(), 16), Integer.parseInt(str[3].replace("0x","").trim(), 16), Integer.parseInt(str[4].replace("0x","").trim(), 16)}, 0, 4);
|
||||
if( unicode != null)
|
||||
emoji.put(str[0],unicode);
|
||||
}
|
||||
|
@ -736,4 +732,44 @@ public class Helper {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the cache size
|
||||
* @param directory File
|
||||
* @return long value in Mo
|
||||
*/
|
||||
public static long cacheSize(File directory) {
|
||||
long length = 0;
|
||||
if( directory == null || directory.length() == 0 )
|
||||
return -1;
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isFile())
|
||||
try {
|
||||
length += file.length();
|
||||
}catch (NullPointerException e){
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
length += cacheSize(file);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
public static boolean deleteDir(File dir) {
|
||||
if (dir != null && dir.isDirectory()) {
|
||||
String[] children = dir.list();
|
||||
for (String aChildren : children) {
|
||||
boolean success = deleteDir(new File(dir, aChildren));
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return dir.delete();
|
||||
} else{
|
||||
return dir != null && dir.isFile() && dir.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
android:id="@+id/action_about_instance"
|
||||
android:title="@string/action_about_instance"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_cache"
|
||||
android:title="@string/action_cache"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_logout"
|
||||
android:title="@string/action_logout"
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<string name="action_about">A propos</string>
|
||||
<string name="action_about_instance">A propos de l\'instance</string>
|
||||
<string name="action_privacy">Confidentialité</string>
|
||||
<string name="action_cache">Cache</string>
|
||||
<string name="action_logout">Déconnexion</string>
|
||||
|
||||
<string name="login">Connexion</string>
|
||||
|
@ -35,6 +36,8 @@
|
|||
<string name="clipboard">Le contenu du pouet a été copié dans le presse-papier</string>
|
||||
<string name="change">Changer</string>
|
||||
<string name="choose_picture">Changer l\'image…</string>
|
||||
<string name="clear">Nettoyer</string>
|
||||
|
||||
<!--- Menu -->
|
||||
<string name="home_menu">Accueil</string>
|
||||
<string name="home_timeline">Accueil</string>
|
||||
|
@ -254,7 +257,10 @@
|
|||
|
||||
<string name="action_search">Recherche</string>
|
||||
|
||||
|
||||
<!-- CACHE -->
|
||||
<string name="cache_title">Nettoyage du cache</string>
|
||||
<string name="cache_message">Il y a %1$s de données en cache.\n\nSouhaitez-vous les supprimer ?</string>
|
||||
<string name="toast_cache_clear">Le cache a été nettoyé ! %1$s ont été libérés</string>
|
||||
|
||||
<!-- PRIVACY -->
|
||||
<string name="privacy_data_title">Données enregistrées</string>
|
||||
|
|
Loading…
Reference in New Issue