You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
5.8 KiB

/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import androidx.emoji.text.EmojiCompat;
import androidx.preference.PreferenceManager;
import androidx.room.Room;
import com.evernote.android.job.JobManager;
import com.keylesspalace.tusky.db.AccountManager;
import com.keylesspalace.tusky.db.AppDatabase;
import com.keylesspalace.tusky.di.AppInjector;
EmojiCompat support (#600) * Add EmojiCompat * EmojiCompat doesn' replace all emojis anymore * This app should be now capable of loading a EmojiCompat-font located in a file somewhere inside the device's storage * Should now replace all emojis * Add EmojiCompat support to EditTextTyped * Provide EmojiCompat fonts * The app won't crash anymore when no emoji font is available. Emoji font should now be located at [Private external app directory]/files/EmojiCompat.ttf * Removed BundledEmojiCompat dependency Since this EmojiCompat-implementation does not rely on BundledEmojiCompat, there's no reason to have it enabled. * Update EditTextTyped.kt Since connection isn't assigned to (I tried doing so), it can be declared final/val again. * Update README.md * Add some non-working emoji preferences * Add a short font list for testing * Finished implementation * Add Twemoji to font list * Update documentation, more comments * Delete AssetEmojiCompat which is obsolete now * Update the font list * Update the font list * Fix font list & add Exception handling for malformed JSON files (hopefully) * More fixes. It should work now... * Removed AssetEmojiCompat (again) * Add most of the changes * Improved the EmojiCompat dialog's style * The font list is now based on a static layout without external files * Re-add the real font URL for Twemoji * Emoji-font captions are now translatable * Removed one unused String (loading) * Removed emoji fonts from this repo * Applied changes from the PR change requests * The correct emoji font will be selected after cancelling a change * Add details on the EmojiCompat fonts available (not shown yet) * Add licensing information on Twemoji and Blobmoji * Reworked some strings * Moved FileEmojiCompat to its own library * Update FileEmojiCompat to the latest version (1.0.3) * EmojiCompat bug should be fixed * Better handling of failed downloads * Removed one TODO Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com> * Update emoji attribution strings Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com> * Fixed some misspelled strings Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com>
6 years ago
import com.keylesspalace.tusky.util.EmojiCompatFont;
import com.keylesspalace.tusky.util.LocaleManager;
import com.keylesspalace.tusky.util.NotificationPullJobCreator;
import com.keylesspalace.tusky.util.ThemeUtils;
import com.uber.autodispose.AutoDisposePlugins;
import org.conscrypt.Conscrypt;
import java.security.Security;
import javax.inject.Inject;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasAndroidInjector;
public class TuskyApplication extends Application implements HasAndroidInjector {
@Inject
DispatchingAndroidInjector<Object> androidInjector;
@Inject
NotificationPullJobCreator notificationPullJobCreator;
private AppDatabase appDatabase;
private AccountManager accountManager;
private ServiceLocator serviceLocator;
public static LocaleManager localeManager;
@Override
public void onCreate() {
super.onCreate();
initSecurityProvider();
appDatabase = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "tuskyDB")
.allowMainThreadQueries()
.addMigrations(AppDatabase.MIGRATION_2_3, AppDatabase.MIGRATION_3_4, AppDatabase.MIGRATION_4_5,
AppDatabase.MIGRATION_5_6, AppDatabase.MIGRATION_6_7, AppDatabase.MIGRATION_7_8,
AppDatabase.MIGRATION_8_9, AppDatabase.MIGRATION_9_10, AppDatabase.MIGRATION_10_11,
AppDatabase.MIGRATION_11_12, AppDatabase.MIGRATION_12_13, AppDatabase.MIGRATION_10_13,
AppDatabase.MIGRATION_13_14, AppDatabase.MIGRATION_14_15, AppDatabase.MIGRATION_15_16,
AppDatabase.MIGRATION_16_17, AppDatabase.MIGRATION_17_18, AppDatabase.MIGRATION_18_19,
AppDatabase.MIGRATION_19_20, AppDatabase.MIGRATION_20_21, AppDatabase.MIGRATION_21_22)
.build();
accountManager = new AccountManager(appDatabase);
serviceLocator = new ServiceLocator() {
@Override
public <T> T get(Class<T> clazz) {
if (clazz.equals(AccountManager.class)) {
//noinspection unchecked
return (T) accountManager;
} else if (clazz.equals(AppDatabase.class)) {
//noinspection unchecked
return (T) appDatabase;
} else {
throw new IllegalArgumentException("Unknown service " + clazz);
}
}
};
AutoDisposePlugins.setHideProxies(false);
ComposeActivity improvements (#548) * do not add media urls to status text * add scrolling to content * add arrow icon and animation to replying-to toggle * remove unnecessary compose_button_colors.xml * improve toot button * improve bottom bar, add bottom sheet for compose options, dedicated cw button * fix crash on Android < API 21 * move media picking from dialog to bottom sheet * add small style tootbutton * fix colors/button background for light theme * add icons to media chose bottom sheet * improve hide media button, delete unused styles * fix crash on dev build when taking photo * consolidate drawables * consolidate strings and ids, add tooltips to buttons * allow media only toots * change error message to show max size of upload correctly * fix button color * add emoji * code cleanup * Merge branch 'master' into compose_activity_refactoring # Conflicts: # app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java * fix hidden snackbar * improve hint text color * add SendTootService * fix timeline refreshing * toot saving and error handling for sendtootservice * restructure some code * convert EditTextTyped to Kotlin * fixed pick media button disabled color * force sensitive media when content warning is shown * add db cache for emojis & fix tests * reorder buttons to match mastodon web * add possibility to cancel sending of toot * correctly delete sent toots * refresh SavedTootActivity after toot was sent * remove unused resources * correct params for toot saving in SendTootService * consolidate strings * bugfix * remove unused resources * fix notifications on old android for SendTootService * fix crash
6 years ago
initAppInjector();
EmojiCompat support (#600) * Add EmojiCompat * EmojiCompat doesn' replace all emojis anymore * This app should be now capable of loading a EmojiCompat-font located in a file somewhere inside the device's storage * Should now replace all emojis * Add EmojiCompat support to EditTextTyped * Provide EmojiCompat fonts * The app won't crash anymore when no emoji font is available. Emoji font should now be located at [Private external app directory]/files/EmojiCompat.ttf * Removed BundledEmojiCompat dependency Since this EmojiCompat-implementation does not rely on BundledEmojiCompat, there's no reason to have it enabled. * Update EditTextTyped.kt Since connection isn't assigned to (I tried doing so), it can be declared final/val again. * Update README.md * Add some non-working emoji preferences * Add a short font list for testing * Finished implementation * Add Twemoji to font list * Update documentation, more comments * Delete AssetEmojiCompat which is obsolete now * Update the font list * Update the font list * Fix font list & add Exception handling for malformed JSON files (hopefully) * More fixes. It should work now... * Removed AssetEmojiCompat (again) * Add most of the changes * Improved the EmojiCompat dialog's style * The font list is now based on a static layout without external files * Re-add the real font URL for Twemoji * Emoji-font captions are now translatable * Removed one unused String (loading) * Removed emoji fonts from this repo * Applied changes from the PR change requests * The correct emoji font will be selected after cancelling a change * Add details on the EmojiCompat fonts available (not shown yet) * Add licensing information on Twemoji and Blobmoji * Reworked some strings * Moved FileEmojiCompat to its own library * Update FileEmojiCompat to the latest version (1.0.3) * EmojiCompat bug should be fixed * Better handling of failed downloads * Removed one TODO Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com> * Update emoji attribution strings Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com> * Fixed some misspelled strings Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com>
6 years ago
initEmojiCompat();
initNightMode();
JobManager.create(this).addJobCreator(notificationPullJobCreator);
Theming improvements (#502) * Split theme definitions into day and night * Add support for Night Mode in code * Add theme chooser in preferences * Fix translations * Adjust IDs * Adjust preferences for custom themes * UI tweaks for custom theme support * Added code for custom theme support 🍅 * Fixed resource display in Kotlin 🍅 * Restored styles * Updated strings * Fixed getIdentifier() to fit into setTheme() * Removed redundant resources * Reset default theme to "Dusky" * Fixed night mode handler to maintain compatibility * Refactor functions to use helper methods * Added license block * Added preview to theme selector * Added color identifier getter helper method * Fixed reference in AccountMediaFragment * Cleanup * Fixed navbar foreground not changing color * Fix fallback theme switch(){} * Enable location-based daylight trigger * Cleanup * Modified theming strategy to reduce clutter in preferences * Updated translations for latest version * Removed "Default" theme flavor from settings * Updated Polish translations 🇵🇱 * Modified TwilightManager handling code to support Android M's UiModeManager features and moved it to its own function * Updated Polish translations 🇵🇱 * Cleanup; Fixed hardcoded string * Added missing escape in string * Removed permission request dialog. As we now use native UiModeManager APIs that don't need special permission for Android 6.0 and above, we no longer need to bother user with Android M+ specific location permission request dialog. * Increased readability of ThemeUtil class * Refactored ThemeUtils.setAppNightMode method * Cleanup
6 years ago
}
protected void initSecurityProvider() {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
}
@Override
protected void attachBaseContext(Context base) {
localeManager = new LocaleManager(base);
super.attachBaseContext(localeManager.setLocale(base));
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
localeManager.setLocale(this);
}
EmojiCompat support (#600) * Add EmojiCompat * EmojiCompat doesn' replace all emojis anymore * This app should be now capable of loading a EmojiCompat-font located in a file somewhere inside the device's storage * Should now replace all emojis * Add EmojiCompat support to EditTextTyped * Provide EmojiCompat fonts * The app won't crash anymore when no emoji font is available. Emoji font should now be located at [Private external app directory]/files/EmojiCompat.ttf * Removed BundledEmojiCompat dependency Since this EmojiCompat-implementation does not rely on BundledEmojiCompat, there's no reason to have it enabled. * Update EditTextTyped.kt Since connection isn't assigned to (I tried doing so), it can be declared final/val again. * Update README.md * Add some non-working emoji preferences * Add a short font list for testing * Finished implementation * Add Twemoji to font list * Update documentation, more comments * Delete AssetEmojiCompat which is obsolete now * Update the font list * Update the font list * Fix font list & add Exception handling for malformed JSON files (hopefully) * More fixes. It should work now... * Removed AssetEmojiCompat (again) * Add most of the changes * Improved the EmojiCompat dialog's style * The font list is now based on a static layout without external files * Re-add the real font URL for Twemoji * Emoji-font captions are now translatable * Removed one unused String (loading) * Removed emoji fonts from this repo * Applied changes from the PR change requests * The correct emoji font will be selected after cancelling a change * Add details on the EmojiCompat fonts available (not shown yet) * Add licensing information on Twemoji and Blobmoji * Reworked some strings * Moved FileEmojiCompat to its own library * Update FileEmojiCompat to the latest version (1.0.3) * EmojiCompat bug should be fixed * Better handling of failed downloads * Removed one TODO Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com> * Update emoji attribution strings Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com> * Fixed some misspelled strings Signed-off-by: Constantin A <10349490+C1710@users.noreply.github.com>
6 years ago
/**
* This method will load the EmojiCompat font which has been selected.
* If this font does not work or if the user hasn't selected one (yet), it will use a
* fallback solution instead which won't make any visible difference to using no EmojiCompat at all.
*/
private void initEmojiCompat() {
int emojiSelection = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext())
.getInt(EmojiPreference.FONT_PREFERENCE, 0);
EmojiCompatFont font = EmojiCompatFont.byId(emojiSelection);
// FileEmojiCompat will handle any non-existing font and provide a fallback solution.
EmojiCompat.Config config = font.getConfig(getApplicationContext())
// The user probably wants to get a consistent experience
.setReplaceAll(true);
EmojiCompat.init(config);
}
ComposeActivity improvements (#548) * do not add media urls to status text * add scrolling to content * add arrow icon and animation to replying-to toggle * remove unnecessary compose_button_colors.xml * improve toot button * improve bottom bar, add bottom sheet for compose options, dedicated cw button * fix crash on Android < API 21 * move media picking from dialog to bottom sheet * add small style tootbutton * fix colors/button background for light theme * add icons to media chose bottom sheet * improve hide media button, delete unused styles * fix crash on dev build when taking photo * consolidate drawables * consolidate strings and ids, add tooltips to buttons * allow media only toots * change error message to show max size of upload correctly * fix button color * add emoji * code cleanup * Merge branch 'master' into compose_activity_refactoring # Conflicts: # app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java * fix hidden snackbar * improve hint text color * add SendTootService * fix timeline refreshing * toot saving and error handling for sendtootservice * restructure some code * convert EditTextTyped to Kotlin * fixed pick media button disabled color * force sensitive media when content warning is shown * add db cache for emojis & fix tests * reorder buttons to match mastodon web * add possibility to cancel sending of toot * correctly delete sent toots * refresh SavedTootActivity after toot was sent * remove unused resources * correct params for toot saving in SendTootService * consolidate strings * bugfix * remove unused resources * fix notifications on old android for SendTootService * fix crash
6 years ago
protected void initAppInjector() {
AppInjector.INSTANCE.init(this);
}
protected void initNightMode() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT);
ThemeUtils.setAppNightMode(theme);
}
public ServiceLocator getServiceLocator() {
return serviceLocator;
}
@Override
public AndroidInjector<Object> androidInjector() {
return androidInjector;
}
public interface ServiceLocator {
<T> T get(Class<T> clazz);
}
}