RecentEmojicon not stored correctly bug fixed

This commit is contained in:
Ankush Sachdeva 2014-09-02 16:05:55 +05:30
parent 8d2bd8f978
commit caf5dee648
3 changed files with 12 additions and 28 deletions

View file

@ -75,23 +75,20 @@ public class EmojiconRecentsManager extends ArrayList<Emojicon> {
@Override
public boolean add(Emojicon object) {
boolean ret = super.add(object);
saveRecents();
return ret;
}
@Override
public void add(int index, Emojicon object) {
super.add(index, object);
saveRecents();
}
@Override
public boolean remove(Object object) {
boolean ret = super.remove(object);
saveRecents();
return ret;
}
private SharedPreferences getPreferences() {
return mContext.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
}
@ -102,21 +99,20 @@ public class EmojiconRecentsManager extends ArrayList<Emojicon> {
StringTokenizer tokenizer = new StringTokenizer(str, "~");
while (tokenizer.hasMoreTokens()) {
try {
int codepoint = Integer.parseInt(tokenizer.nextToken());
add(Emojicon.fromCodePoint(codepoint));
add(new Emojicon(tokenizer.nextToken()));
}
catch (NumberFormatException e) {
// ignored
}
}
}
private void saveRecents() {
public void saveRecents() {
StringBuilder str = new StringBuilder();
int c = size();
for (int i = 0; i < c; i++) {
Emojicon e = get(i);
str.append(e.getEmoji().codePointAt(0));
str.append(e.getEmoji());
if (i < (c - 1)) {
str.append('~');
}

View file

@ -46,8 +46,6 @@ import android.view.WindowManager.LayoutParams;
import android.widget.EditText;
import android.widget.PopupWindow;
import github.ankushsachdeva.emojicon.R;
/**
* @author Ankush Sachdeva (sankush@yahoo.co.in).
@ -100,6 +98,13 @@ public class EmojiconsPopup extends PopupWindow implements ViewPager.OnPageChang
return isOpened;
}
@Override
public void dismiss() {
super.dismiss();
EmojiconRecentsManager
.getInstance(mContext).saveRecents();
}
public void setSizeForSoftKeyboard(){
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override

View file

@ -23,20 +23,11 @@ import java.io.Serializable;
*/
public class Emojicon implements Serializable {
private static final long serialVersionUID = 1L;
private int icon;
private char value;
private String emoji;
private Emojicon() {
}
public static Emojicon fromResource(int icon, int value) {
Emojicon emoji = new Emojicon();
emoji.icon = icon;
emoji.value = (char) value;
return emoji;
}
public static Emojicon fromCodePoint(int codePoint) {
Emojicon emoji = new Emojicon();
emoji.emoji = newString(codePoint);
@ -59,14 +50,6 @@ public class Emojicon implements Serializable {
this.emoji = emoji;
}
public char getValue() {
return value;
}
public int getIcon() {
return icon;
}
public String getEmoji() {
return emoji;
}