Search in sources :

Example 1 with AppConfiguration

use of com.github.moko256.twicalico.config.AppConfiguration in project twicalico by moko256.

the class GlobalApplication method onCreate.

@Override
public void onCreate() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("crash_log", getString(R.string.crash_log), NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription(getString(R.string.crash_log_channel_description));
        channel.setLightColor(Color.RED);
        channel.enableLights(true);
        channel.setShowBadge(false);
        channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if (manager != null) {
            manager.createNotificationChannel(channel);
        }
    }
    final Thread.UncaughtExceptionHandler defaultUnCaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
        try {
            new ExceptionNotification().create(e, getApplicationContext());
        } catch (Throwable fe) {
            fe.printStackTrace();
        } finally {
            defaultUnCaughtExceptionHandler.uncaughtException(t, e);
        }
    });
    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    configuration = new AppConfiguration();
    configuration.isPatternTweetMuteEnabled = defaultSharedPreferences.getBoolean("patternTweetMuteEnabled", false);
    if (configuration.isPatternTweetMuteEnabled) {
        try {
            configuration.tweetMutePattern = Pattern.compile(defaultSharedPreferences.getString("tweetMutePattern", ""));
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            configuration.isPatternTweetMuteEnabled = false;
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
    configuration.isPatternTweetMuteShowOnlyImageEnabled = defaultSharedPreferences.getBoolean("patternTweetMuteShowOnlyImageEnabled", false);
    if (configuration.isPatternTweetMuteShowOnlyImageEnabled) {
        try {
            configuration.tweetMuteShowOnlyImagePattern = Pattern.compile(defaultSharedPreferences.getString("tweetMuteShowOnlyImagePattern", ""));
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            configuration.isPatternTweetMuteShowOnlyImageEnabled = false;
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
    configuration.isPatternUserScreenNameMuteEnabled = defaultSharedPreferences.getBoolean("patternUserScreenNameMuteEnabled", false);
    if (configuration.isPatternUserScreenNameMuteEnabled) {
        try {
            configuration.userScreenNameMutePattern = Pattern.compile(defaultSharedPreferences.getString("userScreenNameMutePattern", ""));
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            configuration.isPatternUserScreenNameMuteEnabled = false;
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
    configuration.isPatternUserNameMuteEnabled = defaultSharedPreferences.getBoolean("patternUserNameMuteEnabled", false);
    if (configuration.isPatternUserNameMuteEnabled) {
        try {
            configuration.userNameMutePattern = Pattern.compile(defaultSharedPreferences.getString("userNameMutePattern", ""));
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            configuration.isPatternUserNameMuteEnabled = false;
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
    configuration.isPatternTweetSourceMuteEnabled = defaultSharedPreferences.getBoolean("patternTweetSourceMuteEnabled", false);
    if (configuration.isPatternTweetSourceMuteEnabled) {
        try {
            configuration.tweetSourceMutePattern = Pattern.compile(defaultSharedPreferences.getString("tweetSourceMutePattern", ""));
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            configuration.isPatternTweetSourceMuteEnabled = false;
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
    configuration.isTimelineImageLoad = Boolean.valueOf(defaultSharedPreferences.getString("isTimelineImageLoad", "true"));
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    @AppCompatDelegate.NightMode int mode = AppCompatDelegate.MODE_NIGHT_NO;
    switch(defaultSharedPreferences.getString("nightModeType", "mode_night_no_value")) {
        case "mode_night_no":
            mode = AppCompatDelegate.MODE_NIGHT_NO;
            break;
        case "mode_night_auto":
            mode = AppCompatDelegate.MODE_NIGHT_AUTO;
            break;
        case "mode_night_follow_system":
            mode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
            break;
        case "mode_night_yes":
            mode = AppCompatDelegate.MODE_NIGHT_YES;
            break;
    }
    AppCompatDelegate.setDefaultNightMode(mode);
    String accountKey = defaultSharedPreferences.getString("AccountKey", "-1");
    if (accountKey.equals("-1"))
        return;
    TokenSQLiteOpenHelper tokenOpenHelper = new TokenSQLiteOpenHelper(this);
    AccessToken accessToken = tokenOpenHelper.getAccessToken(accountKey);
    tokenOpenHelper.close();
    if (accessToken == null)
        return;
    initTwitter(accessToken);
    super.onCreate();
}
Also used : NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) NotificationChannel(android.app.NotificationChannel) AccessToken(com.github.moko256.twicalico.entity.AccessToken) ExceptionNotification(com.github.moko256.twicalico.notification.ExceptionNotification) AppConfiguration(com.github.moko256.twicalico.config.AppConfiguration) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with AppConfiguration

use of com.github.moko256.twicalico.config.AppConfiguration in project twicalico by moko256.

the class StatusesAdapter method getItemViewType.

@Override
public int getItemViewType(int position) {
    if (data.get(position) == -1L) {
        return 1;
    }
    Status status = GlobalApplication.statusCache.get(data.get(position));
    if (status == null) {
        return 1;
    }
    Status item = status.isRetweet() ? status.getRetweetedStatus() : status;
    if (item == null) {
        return 1;
    }
    AppConfiguration conf = GlobalApplication.configuration;
    if ((conf.isPatternTweetMuteEnabled && conf.tweetMutePattern.matcher(item.getText()).find()) || (conf.isPatternUserScreenNameMuteEnabled && conf.userScreenNameMutePattern.matcher(item.getUser().getScreenName()).find()) || (conf.isPatternUserNameMuteEnabled && conf.userNameMutePattern.matcher(item.getUser().getName()).find()) || (conf.isPatternTweetSourceMuteEnabled && conf.tweetSourceMutePattern.matcher(item.getSource()).find())) {
        return 2;
    }
    if (shouldShowMediaOnly || (conf.isPatternTweetMuteShowOnlyImageEnabled && item.getMediaEntities().length > 0 && conf.tweetMuteShowOnlyImagePattern.matcher(item.getText()).find())) {
        return 3;
    }
    return super.getItemViewType(position);
}
Also used : Status(twitter4j.Status) AppConfiguration(com.github.moko256.twicalico.config.AppConfiguration)

Aggregations

AppConfiguration (com.github.moko256.twicalico.config.AppConfiguration)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 SharedPreferences (android.content.SharedPreferences)1 TokenSQLiteOpenHelper (com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)1 AccessToken (com.github.moko256.twicalico.entity.AccessToken)1 ExceptionNotification (com.github.moko256.twicalico.notification.ExceptionNotification)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Status (twitter4j.Status)1