mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Read emojis json with context
This commit is contained in:
parent
0d58aac9b9
commit
58a69f2da6
@ -171,7 +171,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
|
|||||||
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
||||||
// Initialise the internal map
|
// Initialise the internal map
|
||||||
AppExecutors.getInstance().tasksThread().execute(() -> {
|
AppExecutors.getInstance().tasksThread().execute(() -> {
|
||||||
EmojiParser.getInstance();
|
EmojiParser.setup(this);
|
||||||
EmojiVariantManager.getInstance();
|
EmojiVariantManager.getInstance();
|
||||||
});
|
});
|
||||||
initEmojiCompat();
|
initEmojiCompat();
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package awais.instagrabber.utils.emoji;
|
package awais.instagrabber.utils.emoji;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.gson.FieldNamingPolicy;
|
import com.google.gson.FieldNamingPolicy;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@ -18,6 +21,7 @@ import java.util.function.Function;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.customviews.emoji.Emoji;
|
import awais.instagrabber.customviews.emoji.Emoji;
|
||||||
import awais.instagrabber.customviews.emoji.EmojiCategory;
|
import awais.instagrabber.customviews.emoji.EmojiCategory;
|
||||||
import awais.instagrabber.customviews.emoji.EmojiCategoryType;
|
import awais.instagrabber.customviews.emoji.EmojiCategoryType;
|
||||||
@ -33,25 +37,25 @@ public final class EmojiParser {
|
|||||||
private Map<EmojiCategoryType, EmojiCategory> categoryMap = Collections.emptyMap();
|
private Map<EmojiCategoryType, EmojiCategory> categoryMap = Collections.emptyMap();
|
||||||
private ImmutableList<EmojiCategory> categories;
|
private ImmutableList<EmojiCategory> categories;
|
||||||
|
|
||||||
public static EmojiParser getInstance() {
|
public static void setup(@NonNull final Context context) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new EmojiParser();
|
instance = new EmojiParser(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EmojiParser getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
throw new RuntimeException("Setup not done!");
|
||||||
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmojiParser() {
|
private EmojiParser(final Context context) {
|
||||||
final String file = "res/raw/emojis.json";
|
try (final InputStream in = context.getResources().openRawResource(R.raw.emojis)) {
|
||||||
final ClassLoader classLoader = getClass().getClassLoader();
|
|
||||||
if (classLoader == null) {
|
|
||||||
Log.e(TAG, "Emoji: classLoader is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try (final InputStream in = classLoader.getResourceAsStream(file)) {
|
|
||||||
final String json = NetworkUtils.readFromInputStream(in);
|
final String json = NetworkUtils.readFromInputStream(in);
|
||||||
final Gson gson = new GsonBuilder()
|
final Gson gson = new GsonBuilder()
|
||||||
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
||||||
|
Loading…
Reference in New Issue
Block a user