forked from mirror/monocles_chat_clean
add button to delete own avatar (Christian Schneppe)
This commit is contained in:
parent
885f828670
commit
60cc346c7e
6 changed files with 68 additions and 2 deletions
|
@ -1311,6 +1311,12 @@ public class FileBackend {
|
|||
final File file = getAvatarFile(avatar.getFilename());
|
||||
return file.exists();
|
||||
}
|
||||
public boolean deleteAvatar(final File avatar) {
|
||||
if (avatar.exists()) {
|
||||
return avatar.delete();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean save(final Avatar avatar) {
|
||||
File file;
|
||||
|
@ -1389,7 +1395,7 @@ public class FileBackend {
|
|||
return new File(mXmppConnectionService.getFilesDir(), "/avatars/");
|
||||
}
|
||||
|
||||
private File getAvatarFile(String avatar) {
|
||||
public File getAvatarFile(String avatar) {
|
||||
return new File(mXmppConnectionService.getCacheDir(), "/avatars/" + avatar);
|
||||
}
|
||||
|
||||
|
|
|
@ -4077,6 +4077,31 @@ public class XmppConnectionService extends Service {
|
|||
});
|
||||
}
|
||||
|
||||
public void deleteAvatar(Account account) {
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": deleting avatar");
|
||||
IqPacket packet = this.mIqGenerator.deleteNode("urn:xmpp:avatar:data");
|
||||
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||
|
||||
@Override
|
||||
public void onIqPacketReceived(Account account, IqPacket result) {
|
||||
if (result.getType() == IqPacket.TYPE.RESULT) {
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar deletion succeed");
|
||||
if (account.getAvatar() != null) {
|
||||
if (getFileBackend().deleteAvatar(getFileBackend().getAvatarFile(account.getAvatar()))) {
|
||||
mAvatarService.clear(account);
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": local avatar cache deletion succeed");
|
||||
}
|
||||
}
|
||||
//todo callback
|
||||
} else {
|
||||
Element error = result.findChild("error");
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar deletion failed " + (error != null ? error.toString() : ""));
|
||||
// todo callback
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void publishAvatarMetadata(Account account, final Avatar avatar, final Bundle options, final boolean retry, final OnAvatarPublication callback) {
|
||||
final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar, options);
|
||||
sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||
|
|
|
@ -7,6 +7,8 @@ import android.net.Uri;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.widget.Button;
|
||||
|
@ -80,6 +82,11 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
togglePublishButton(true, R.string.publish);
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.activity_publish_avatar, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -226,7 +233,7 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
try {
|
||||
bm = xmppConnectionService.getFileBackend().cropCenterSquare(uri, getPixel(Config.AVATAR_SIZE));
|
||||
} catch (Exception e) {
|
||||
Log.d(Config.LOGTAG, "unable to load bitmap into image view", e);
|
||||
Log.d(Config.LOGTAG, "unable to load avatar into image view", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,5 +283,16 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
|
|||
public void onAccountUpdate() {
|
||||
refreshUi();
|
||||
}
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_delete_avatar:
|
||||
if (account != null) {
|
||||
xmppConnectionService.deleteAvatar(account);
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
|
@ -100,6 +100,12 @@
|
|||
android:layout_weight="1"
|
||||
android:text="@string/cancel" />
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_marginBottom="7dp"
|
||||
android:background="?attr/divider" />
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
|
|
10
src/main/res/menu/activity_publish_avatar.xml
Normal file
10
src/main/res/menu/activity_publish_avatar.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_delete_avatar"
|
||||
app:showAsAction="always"
|
||||
android:icon="?attr/icon_delete"
|
||||
android:orderInCategory="10"
|
||||
android:title="@string/delete_avatar" />
|
||||
</menu>
|
|
@ -1195,4 +1195,5 @@
|
|||
<string name="port_example" translatable="false">5222</string>
|
||||
<string name="pref_show_date_in_quotes_summary">Show date and time of your quoted messages.</string>
|
||||
<string name="pref_show_date_in_quotes">Show date and time of quotes</string>
|
||||
<string name="delete_avatar">Delete own avatar</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue