Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easy to compose messages with mentions, emoji, etc. #108

Closed
wants to merge 8 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@kunall17
Copy link
Collaborator

kunall17 commented Jul 28, 2016

This allows to show hints for user mentions ("@") or adding emotics/Emoji's (":")

Also this branch creates a new table into the app's database so it would be recommended to have clean-signin install!

These are the old emojis bundled with the app previously, i'll look into the server code to find any more left emoticons!

Preview:

@smarx

This comment has been minimized.

Copy link

smarx commented Jul 28, 2016

Automated message from Dropbox CLA bot

@kunall17, it looks like you've already signed the Dropbox CLA. Thanks!

@niftynei

This comment has been minimized.

Copy link
Contributor

niftynei commented Jul 28, 2016

@kunall17 EDITED:

I got a crash at startup because the database structure was incorrect. You can fix this by bumping the DATABASE_VERSION number by one. :)

07-28 16:11:18.311 22187 22187 E AndroidRuntime: Caused by: android.database.sqlite.SQLiteException: no such table: emoji (code 1): , while compiling: SELECT * FROM `emoji`
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at com.j256.ormlite.android.compat.JellyBeanApiCompatibility.rawQuery(JellyBeanApiCompatibility.java:21)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:180)
07-28 16:11:18.311 22187 22187 E AndroidRuntime:    ... 20 more

public Emoji() {
}

public Emoji(String as) {

This comment has been minimized.

@niftynei

niftynei Jul 28, 2016

Contributor

as is probably better renamed as emojiName or something like that.

@@ -188,6 +212,7 @@ public void addToMutedTopics(JSONArray jsonArray) {
public void setEmail(String email) {
databaseHelper = new DatabaseHelper(this, email);
this.you = Person.getOrUpdate(this, email, null, null);
setupEmoji();

This comment has been minimized.

@niftynei

niftynei Jul 28, 2016

Contributor

this seems unrelated to the setEmail call. Can we move this to a more logical place?

}
return ((AndroidDatabaseResults) app
.getDao(Emoji.class)
.queryRaw("SELECT rowid _id,* FROM emoji WHERE name LIKE '%" + emoji + "%'")

This comment has been minimized.

@niftynei

niftynei Jul 28, 2016

Contributor

It's best practice to name the fields you're expecting to return, instead of using the * glob pattern.

Drawable drawable = Drawable.createFromStream(getApplicationContext().getAssets().open("emoji/" + name),
"emoji/" + name);
((ImageView) view).setImageDrawable(drawable);
} catch (Exception e) {

This comment has been minimized.

@niftynei

niftynei Jul 28, 2016

Contributor

What types of exceptions are you expecting?

@@ -50,6 +51,7 @@ public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
TableUtils.createTable(connectionSource, Stream.class);
TableUtils.createTable(connectionSource, Message.class);
TableUtils.createTable(connectionSource, MessageRange.class);
TableUtils.createTable(connectionSource, Emoji.class);

This comment has been minimized.

@niftynei

niftynei Jul 28, 2016

Contributor

If you bump the DATABASE_VERSION number, this will correctly rebuild your database for upgrades. :)

@niftynei

This comment has been minimized.

Copy link
Contributor

niftynei commented Jul 28, 2016

This looks great on the phone, @kunall17! If you can fix up the database issues, I think it's about ready to merge. 👍

@kunall17 kunall17 force-pushed the kunall17:patch-17-emoji branch from f04bb55 to 2e10bfc Aug 1, 2016

@kunall17

This comment has been minimized.

Copy link
Collaborator Author

kunall17 commented Aug 1, 2016

@niftynei I bumped up the version by 1 but I get this error if I try to run this from an existing old installation :(

 08-01 15:41:27.441 20758-20758/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.zulip.android.dev, PID: 20758
                                                   java.lang.RuntimeException: Unable to create application com.zulip.android.ZulipApp: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.zulip.android.dev/databases/zulip-af4f06322c177ef4e1e9b2c424986b54.db
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4664)
                                                       at android.app.ActivityThread.access$1500(ActivityThread.java:156)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:211)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5389)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
                                                    Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.zulip.android.dev/databases/zulip-af4f06322c177ef4e1e9b2c424986b54.db
                                                       at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
                                                       at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:520)
                                                       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:262)
                                                       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                                                       at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:66)
                                                       at com.j256.ormlite.android.AndroidConnectionSource.getReadOnlyConnection(AndroidConnectionSource.java:54)
                                                       at com.j256.ormlite.dao.BaseDaoImpl.queryForFirst(BaseDaoImpl.java:231)
                                                       at com.j256.ormlite.stmt.QueryBuilder.queryForFirst(QueryBuilder.java:375)
                                                       at com.j256.ormlite.stmt.Where.queryForFirst(Where.java:517)
                                                       at com.zulip.android.models.Person.getByEmail(Person.java:135)
                                                       at com.zulip.android.models.Person.getOrUpdate(Person.java:151)
                                                       at com.zulip.android.models.Person.getOrUpdate(Person.java:179)
                                                       at com.zulip.android.ZulipApp.setEmail(ZulipApp.java:215)
                                                       at com.zulip.android.ZulipApp.afterLogin(ZulipApp.java:140)
                                                       at com.zulip.android.ZulipApp.onCreate(ZulipApp.java:105)
                                                       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4661)
                                                       at android.app.ActivityThread.access$1500(ActivityThread.java:156) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:211) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5389) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 

This occurs because db.close here
https://github.com/kunall17/zulip-android/blob/2e10bfccd1d680934f9287a779a22f080979f4a9/app/src/main/java/com/zulip/android/database/DatabaseHelper.java#L92

Add/replace new emojis
These new emojis have been taken from my dev server
"static/third/gemoji"

@kunall17 kunall17 force-pushed the kunall17:patch-17-emoji branch from 2e10bfc to 81bb2d3 Aug 1, 2016

@niftynei

This comment has been minimized.

Copy link
Contributor

niftynei commented Aug 2, 2016

I went ahead and patched this to fix the database issue (it should be fine to leave the DB connection open).

Nice work! Really excited about this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.