From 8f6a5924f9791a3762e6b23c4d1b5c47ad9cd0fc Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 16 Sep 2018 15:05:33 +0200 Subject: [PATCH] Fix emoji issue and memory limit --- app/src/main/AndroidManifest.xml | 1 + .../etalab/mastodon/activities/BaseMainActivity.java | 9 ++++++++- .../main/java/fr/gouv/etalab/mastodon/client/API.java | 1 - .../fr/gouv/etalab/mastodon/client/Entities/Account.java | 2 -- .../main/java/fr/gouv/etalab/mastodon/helper/Helper.java | 5 ++++- .../java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java | 3 +++ .../main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java | 8 +++++--- app/src/main/res/values/strings.xml | 2 +- .../fr.gouv.etalab.mastodon/activities/MainActivity.java | 1 + 9 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7c6cb7e15..49e864050 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,6 +33,7 @@ tools:replace="android:allowBackup" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" + android:largeHeap="true" android:hardwareAccelerated="true" android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 56227e0e7..03a4ec3c9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -101,6 +101,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplaySearchFragment; import fr.gouv.etalab.mastodon.fragments.WhoToFollowFragment; import fr.gouv.etalab.mastodon.helper.CrossActions; import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; @@ -136,7 +137,7 @@ import android.support.v4.app.FragmentStatePagerAdapter; public abstract class BaseMainActivity extends BaseActivity - implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface, OnRetrieveRemoteAccountInterface { + implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface, OnRetrieveRemoteAccountInterface, OnRetrieveEmojiAccountInterface { private FloatingActionButton toot, delete_all, add_new; private HashMap tagTile = new HashMap<>(); @@ -1624,6 +1625,12 @@ public abstract class BaseMainActivity extends BaseActivity } } + @Override + public void onRetrieveEmojiAccount(Account account) { + TextView displayedName = headerLayout.findViewById(R.id.displayedName); + displayedName.setText(account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE); + } + /** * Page Adapter for settings diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index ed724526e..a83d0e281 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -16,7 +16,6 @@ package fr.gouv.etalab.mastodon.client; import android.content.Context; import android.content.SharedPreferences; -import android.util.Log; import org.json.JSONArray; import org.json.JSONException; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java index 4ec995a4d..a7c2f8ae7 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Account.java @@ -453,7 +453,6 @@ public class Account implements Parcelable { public void makeEmojisAccount(final Context context, final OnRetrieveEmojiAccountInterface listener){ - if( ((Activity)context).isFinishing() ) return; @@ -461,7 +460,6 @@ public class Account implements Parcelable { if( account.getDisplay_name() != null) displayNameSpan = new SpannableString(account.getDisplay_name()); - if( account.getFields() != null && account.getFields().size() > 0) { Iterator it = account.getFields().entrySet().iterator(); while (it.hasNext()) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index bd66764be..90e42494e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -1240,8 +1240,9 @@ public class Helper { activity.startActivity(myIntent); activity.finish(); //User is logged out to get a new token }else { + account.makeEmojisAccount(activity, ((BaseMainActivity)activity)); username.setText(String.format("@%s",account.getUsername() + "@" + account.getInstance())); - displayedName.setText(account.getDisplay_name()); + displayedName.setText(account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE); String url = account.getAvatar(); if( url.startsWith("/") ){ url = Helper.getLiveInstanceWithProtocol(activity) + account.getAvatar(); @@ -1639,6 +1640,8 @@ public class Helper { } } + + /** * Serialized a Status class * @param status Status to serialize diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java index 57c680d61..89ab6f413 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/AccountDAO.java @@ -68,6 +68,7 @@ public class AccountDAO { values.put(Sqlite.COL_HEADER_STATIC,account.getHeader_static()); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at())); values.put(Sqlite.COL_INSTANCE, account.getInstance()); + values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis())); if( account.getToken() != null) values.put(Sqlite.COL_OAUTHTOKEN, account.getToken()); @@ -104,6 +105,7 @@ public class AccountDAO { values.put(Sqlite.COL_HEADER_STATIC,account.getHeader_static()); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at())); values.put(Sqlite.COL_INSTANCE, account.getInstance()); + values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis())); if( account.getToken() != null) values.put(Sqlite.COL_OAUTHTOKEN, account.getToken()); @@ -239,6 +241,7 @@ public class AccountDAO { account.setHeader_static(c.getString(c.getColumnIndex(Sqlite.COL_HEADER_STATIC))); account.setCreated_at(Helper.stringToDate(context, c.getString(c.getColumnIndex(Sqlite.COL_CREATED_AT)))); account.setInstance(c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE))); + account.setEmojis(Helper.restoreEmojisFromString(c.getString(c.getColumnIndex(Sqlite.COL_EMOJIS)))); account.setToken(c.getString(c.getColumnIndex(Sqlite.COL_OAUTHTOKEN))); //Close the cursor diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java index 4f5d0dbd8..5c8252361 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java @@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper; public class Sqlite extends SQLiteOpenHelper { - public static final int DB_VERSION = 12; + public static final int DB_VERSION = 13; public static final String DB_NAME = "mastodon_etalab_db"; public static SQLiteDatabase db; private static Sqlite sInstance; @@ -69,7 +69,7 @@ public class Sqlite extends SQLiteOpenHelper { static final String COL_HEADER_STATIC = "HEADER_STATIC"; static final String COL_INSTANCE = "INSTANCE"; static final String COL_OAUTHTOKEN = "OAUTH_TOKEN"; - + static final String COL_EMOJIS = "EMOJIS"; private static final String CREATE_TABLE_USER_ACCOUNT = "CREATE TABLE " + TABLE_USER_ACCOUNT + " (" @@ -79,6 +79,7 @@ public class Sqlite extends SQLiteOpenHelper { + COL_NOTE + " TEXT NOT NULL, "+ COL_URL + " TEXT NOT NULL, " + COL_AVATAR + " TEXT NOT NULL, "+ COL_AVATAR_STATIC + " TEXT NOT NULL, " + COL_HEADER + " TEXT NOT NULL, "+ COL_HEADER_STATIC + " TEXT NOT NULL, " + + COL_EMOJIS + " TEXT, " + COL_INSTANCE + " TEXT NOT NULL, " + COL_OAUTHTOKEN + " TEXT NOT NULL, " + COL_CREATED_AT + " TEXT NOT NULL)"; @@ -127,7 +128,6 @@ public class Sqlite extends SQLiteOpenHelper { static final String COL_IN_REPLY_TO_ACCOUNT_ID = "IN_REPLY_TO_ACCOUNT_ID"; static final String COL_REBLOG = "REBLOG"; static final String COL_CONTENT = "CONTENT"; - static final String COL_EMOJIS = "EMOJIS"; static final String COL_REBLOGS_COUNT = "REBLOGS_COUNT"; static final String COL_FAVOURITES_COUNT = "FAVOURITES_COUNT"; static final String COL_REBLOGGED = "REBLOGGED"; @@ -224,6 +224,8 @@ public class Sqlite extends SQLiteOpenHelper { db.execSQL(CREATE_UNIQUE_CACHE_INDEX); case 11: db.execSQL(CREATE_TABLE_INSTANCES); + case 12: + db.execSQL("ALTER TABLE " + TABLE_USER_ACCOUNT + " ADD COLUMN "+ COL_EMOJIS + " TEXT"); default: break; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 591122fb3..f9f863a7d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -585,7 +585,7 @@ Delete filter? Update filter Create filter - Who to follow + Whom to follow There is no accounts listed for the moment! Follow Select all diff --git a/app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index eca35c05f..4070fc27a 100644 --- a/app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -18,6 +18,7 @@ package fr.gouv.etalab.mastodon.activities; import com.kobakei.ratethisapp.RateThisApp; + public class MainActivity extends BaseMainActivity { @Override