Search in sources :

Example 1 with TokenSQLiteOpenHelper

use of com.github.moko256.twicalico.database.TokenSQLiteOpenHelper in project twicalico by moko256.

the class SettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    String preferenceRoot = getArguments() != null ? getArguments().getString(ARG_PREFERENCE_ROOT, null) : null;
    if (preferenceRoot == null) {
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
        TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(getContext());
        AccessToken[] accessTokens = helper.getAccessTokens();
        CharSequence[] entries = new CharSequence[accessTokens.length + 1];
        CharSequence[] entryValues = new CharSequence[accessTokens.length + 1];
        for (int i = 0; i < accessTokens.length; i++) {
            AccessToken accessToken = accessTokens[i];
            entries[i] = TwitterStringUtils.plusAtMark(accessToken.getScreenName(), accessToken.getUrl());
            entryValues[i] = accessToken.getKeyString();
        }
        entries[entries.length - 1] = getString(R.string.add_account);
        entryValues[entryValues.length - 1] = "-1";
        ListPreference nowAccountList = (ListPreference) findPreference("AccountKey");
        nowAccountList.setEntries(entries);
        nowAccountList.setEntryValues(entryValues);
        nowAccountList.setDefaultValue(defaultSharedPreferences.getString("AccountKey", "-1"));
        nowAccountList.setOnPreferenceChangeListener((preference, newValue) -> {
            if (newValue.equals("-1")) {
                GlobalApplication.twitter = null;
                startActivity(new Intent(getContext(), OAuthActivity.class));
            } else {
                TokenSQLiteOpenHelper tokenOpenHelper = new TokenSQLiteOpenHelper(this.getContext());
                AccessToken accessToken = tokenOpenHelper.getAccessToken((String) newValue);
                tokenOpenHelper.close();
                ((GlobalApplication) getActivity().getApplication()).initTwitter(accessToken);
                startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
            }
            return true;
        });
        findPreference("logout").setOnPreferenceClickListener(preference -> {
            new AlertDialog.Builder(getContext()).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
                helper.deleteAccessToken(helper.getAccessToken(defaultSharedPreferences.getString("AccountKey", "-1")));
                int point = helper.getSize() - 1;
                if (point != -1) {
                    AccessToken accessToken = helper.getAccessTokens()[point];
                    defaultSharedPreferences.edit().putString("AccountKey", accessToken.getKeyString()).apply();
                    ((GlobalApplication) getActivity().getApplication()).initTwitter(accessToken);
                    startActivity(new Intent(getContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
                } else {
                    defaultSharedPreferences.edit().putString("AccountKey", "-1").apply();
                    GlobalApplication.twitter = null;
                    startActivity(new Intent(getContext(), OAuthActivity.class));
                }
            }).setNeutralButton(R.string.back, (dialog, i) -> dialog.cancel()).show();
            return false;
        });
        ListPreference nowThemeMode = (ListPreference) findPreference("nightModeType");
        nowThemeMode.setOnPreferenceChangeListener((preference, newValue) -> {
            switch(String.valueOf(newValue)) {
                case "mode_night_no":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    break;
                case "mode_night_auto":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
                    break;
                case "mode_night_follow_system":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
                    break;
                case "mode_night_yes":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    break;
                default:
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            }
            return true;
        });
        Preference causeError = findPreference("cause_error");
        causeError.setOnPreferenceClickListener(preference -> {
            getActivity().finish();
            throw new NullPointerException();
        });
        Preference licenseThisApp = findPreference("license_at_this_app");
        licenseThisApp.setOnPreferenceClickListener(preference -> {
            getContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", getResources().getText(R.string.app_name)).putExtra("library_name", "twicalico"));
            return true;
        });
        Preference sourceCodeLink = findPreference("source_code_link");
        sourceCodeLink.setOnPreferenceClickListener(preference -> {
            AppCustomTabsKt.launchChromeCustomTabs(getContext(), "https://github.com/moko256/twicalico");
            return false;
        });
        Preference version = findPreference("app_version");
        version.setSummary(BuildConfig.VERSION_NAME);
        version.setOnPreferenceClickListener(preference -> {
            Date birthday = new Date(1446956982000L);
            Toast.makeText(getContext(), getString(R.string.birthday_of_this_app_is, birthday) + "\n\n" + getString(R.string.age_of_this_app_is, (int) Math.floor((new Date().getTime() - birthday.getTime()) / (31557600000L))), Toast.LENGTH_LONG).show();
            return false;
        });
    } else if (preferenceRoot.equals("license")) {
        PreferenceScreen license = getPreferenceScreen();
        for (int i = 0, length = license.getPreferenceCount(); i < length; i++) {
            license.getPreference(i).setOnPreferenceClickListener(preference -> {
                getContext().startActivity(new Intent(getContext(), LicensesActivity.class).putExtra("title", preference.getTitle()).putExtra("library_name", // "license_lib_".length
                preference.getKey().substring(12)));
                return true;
            });
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) AccessToken(com.github.moko256.twicalico.entity.AccessToken) PreferenceFragmentCompat(android.support.v7.preference.PreferenceFragmentCompat) Date(java.util.Date) ListPreference(android.support.v7.preference.ListPreference) Intent(android.content.Intent) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) AppCompatDelegate(android.support.v7.app.AppCompatDelegate) Preference(android.support.v7.preference.Preference) PreferenceManager(android.support.v7.preference.PreferenceManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) AppCustomTabsKt(com.github.moko256.twicalico.intent.AppCustomTabsKt) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Toast(android.widget.Toast) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) Date(java.util.Date) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) AccessToken(com.github.moko256.twicalico.entity.AccessToken) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)

Example 2 with TokenSQLiteOpenHelper

use of com.github.moko256.twicalico.database.TokenSQLiteOpenHelper 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 3 with TokenSQLiteOpenHelper

use of com.github.moko256.twicalico.database.TokenSQLiteOpenHelper in project twicalico by moko256.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    subscription = new CompositeSubscription();
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.getChildAt(0).setOnClickListener(v -> {
        Fragment fragment = getMainFragment();
        if (fragment instanceof MovableTopInterface) {
            ((MovableTopInterface) fragment).moveToTop();
        }
    });
    drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    drawer.addDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
        }

        @Override
        public void onDrawerOpened(@NonNull View drawerView) {
        }

        @Override
        public void onDrawerClosed(@NonNull View drawerView) {
            if (isDrawerAccountsSelection) {
                changeIsDrawerAccountsSelection();
            }
        }

        @Override
        public void onDrawerStateChanged(int newState) {
        }
    });
    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(item -> {
        int id = item.getItemId();
        if (!item.isChecked()) {
            switch(id) {
                case R.id.nav_timeline:
                    replaceFragment(new HomeTimeLineFragment());
                    break;
                case R.id.nav_mentions:
                    replaceFragment(new MentionsFragment());
                    break;
                case R.id.nav_account:
                    startMyUserActivity();
                    break;
                case R.id.nav_follow_and_follower:
                    replaceFragment(new MyFollowFollowerFragment());
                    break;
                case R.id.nav_like:
                    replaceFragment(UserLikeFragment.newInstance(GlobalApplication.userId));
                    break;
                case R.id.nav_settings:
                    startActivity(new Intent(this, SettingsActivity.class));
                    break;
            }
        }
        drawer.closeDrawer(GravityCompat.START);
        return (id != R.id.nav_settings) && (id != R.id.nav_account);
    });
    headerView = navigationView.inflateHeaderView(R.layout.nav_header_main);
    userNameText = headerView.findViewById(R.id.user_name);
    userIdText = headerView.findViewById(R.id.user_id);
    userImage = headerView.findViewById(R.id.user_image);
    userBackgroundImage = headerView.findViewById(R.id.user_bg_image);
    userBackgroundImage.setOnClickListener(v -> changeIsDrawerAccountsSelection());
    updateDrawerImage();
    accountListView = new RecyclerView(this);
    accountListView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    accountListView.setLayoutManager(new LinearLayoutManager(this));
    accountListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    accountListView.setVisibility(View.GONE);
    navigationView.addHeaderView(accountListView);
    SelectAccountsAdapter adapter = new SelectAccountsAdapter(this);
    adapter.setOnImageButtonClickListener(accessToken -> {
        drawer.closeDrawer(GravityCompat.START);
        if (accessToken.getUserId() != GlobalApplication.userId) {
            PreferenceManager.getDefaultSharedPreferences(this).edit().putString("AccountKey", accessToken.getKeyString()).apply();
            ((GlobalApplication) getApplication()).initTwitter(accessToken);
            updateDrawerImage();
            clearAndPrepareFragment();
        }
    });
    adapter.setOnAddButtonClickListener(v -> {
        PreferenceManager.getDefaultSharedPreferences(this).edit().putString("AccountKey", "-1").apply();
        GlobalApplication.twitter = null;
        startActivity(new Intent(this, OAuthActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
    });
    adapter.setOnRemoveButtonClickListener(v -> new AlertDialog.Builder(this).setMessage(R.string.confirm_logout).setCancelable(true).setPositiveButton(R.string.do_logout, (dialog, i) -> {
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(this);
        helper.deleteAccessToken(helper.getAccessToken(defaultSharedPreferences.getString("AccountKey", "-1")));
        int point = helper.getSize() - 1;
        if (point != -1) {
            AccessToken accessToken = helper.getAccessTokens()[point];
            defaultSharedPreferences.edit().putString("AccountKey", accessToken.getKeyString()).apply();
            ((GlobalApplication) getApplication()).initTwitter(accessToken);
            updateDrawerImage();
            clearAndPrepareFragment();
        } else {
            adapter.getOnAddButtonClickListener().onClick(v);
        }
        helper.close();
    }).setNeutralButton(R.string.back, (dialog, i) -> dialog.cancel()).show());
    accountListView.setAdapter(adapter);
    subscription.add(Single.create(singleSubscriber -> {
        TokenSQLiteOpenHelper helper = new TokenSQLiteOpenHelper(this);
        AccessToken[] accessTokens = helper.getAccessTokens();
        helper.close();
        ArrayList<Pair<User, AccessToken>> r = new ArrayList<>(accessTokens.length);
        for (AccessToken accessToken : accessTokens) {
            long id = accessToken.getUserId();
            CachedUsersSQLiteOpenHelper userHelper = new CachedUsersSQLiteOpenHelper(this, id, accessToken.getType() == Type.TWITTER);
            User user = userHelper.getCachedUser(id);
            if (user == null) {
                try {
                    user = ((GlobalApplication) getApplication()).getTwitterInstance(accessToken).verifyCredentials();
                    userHelper.addCachedUser(user);
                } catch (TwitterException e) {
                    singleSubscriber.onError(e);
                    return;
                } finally {
                    userHelper.close();
                }
            }
            r.add(new Pair<>(user, accessToken));
        }
        singleSubscriber.onSuccess(r);
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(o -> {
        ArrayList<Pair<User, AccessToken>> pairs = (ArrayList<Pair<User, AccessToken>>) o;
        adapter.getImagesList().addAll(pairs);
        adapter.notifyDataSetChanged();
    }, Throwable::printStackTrace));
    findViewById(R.id.fab).setOnClickListener(v -> startActivity(new Intent(this, PostActivity.class)));
    tabLayout = findViewById(R.id.toolbar_tab);
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            Fragment fragment = ((FragmentPagerAdapter) ((UseTabsInterface) getMainFragment()).getTabsViewPager().getAdapter()).getFragment(tab.getPosition());
            if (fragment instanceof MovableTopInterface) {
                ((MovableTopInterface) fragment).moveToTop();
            }
        }
    });
    tweetListViewPool = new RecyclerView.RecycledViewPool();
    userListViewPool = new RecyclerView.RecycledViewPool();
    getSupportFragmentManager().addOnBackStackChangedListener(() -> attachFragment(getMainFragment()));
    if (savedInstanceState == null) {
        prepareFragment();
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) LinearLayout(android.widget.LinearLayout) Type(com.github.moko256.twicalico.entity.Type) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) CachedUsersSQLiteOpenHelper(com.github.moko256.twicalico.database.CachedUsersSQLiteOpenHelper) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) TwitterStringUtils(com.github.moko256.twicalico.text.TwitterStringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) GravityCompat(android.support.v4.view.GravityCompat) Single(rx.Single) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) User(twitter4j.User) View(android.view.View) TwitterException(twitter4j.TwitterException) PreferenceManager(android.preference.PreferenceManager) DrawerLayout(android.support.v4.widget.DrawerLayout) AccessToken(com.github.moko256.twicalico.entity.AccessToken) Fragment(android.support.v4.app.Fragment) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) FragmentPagerAdapter(com.github.moko256.twicalico.widget.FragmentPagerAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) User(twitter4j.User) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) AccessToken(com.github.moko256.twicalico.entity.AccessToken) TabLayout(android.support.design.widget.TabLayout) DrawerLayout(android.support.v4.widget.DrawerLayout) TwitterException(twitter4j.TwitterException) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper) Pair(android.support.v4.util.Pair) SharedPreferences(android.content.SharedPreferences) CachedUsersSQLiteOpenHelper(com.github.moko256.twicalico.database.CachedUsersSQLiteOpenHelper) Intent(android.content.Intent) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayout(android.widget.LinearLayout)

Example 4 with TokenSQLiteOpenHelper

use of com.github.moko256.twicalico.database.TokenSQLiteOpenHelper in project twicalico by moko256.

the class OAuthActivity method storeAccessToken.

private void storeAccessToken(AccessToken accessToken) {
    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    TokenSQLiteOpenHelper tokenOpenHelper = new TokenSQLiteOpenHelper(this);
    tokenOpenHelper.addAccessToken(accessToken);
    tokenOpenHelper.close();
    defaultSharedPreferences.edit().putString("AccountKey", accessToken.getKeyString()).apply();
    ((GlobalApplication) getApplication()).initTwitter(accessToken);
    startActivity(new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
    finish();
}
Also used : SharedPreferences(android.content.SharedPreferences) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) TokenSQLiteOpenHelper(com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)

Aggregations

SharedPreferences (android.content.SharedPreferences)4 TokenSQLiteOpenHelper (com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)4 Intent (android.content.Intent)3 AccessToken (com.github.moko256.twicalico.entity.AccessToken)3 Bundle (android.os.Bundle)2 AlertDialog (android.support.v7.app.AlertDialog)2 TwitterStringUtils (com.github.moko256.twicalico.text.TwitterStringUtils)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PreferenceManager (android.preference.PreferenceManager)1 NonNull (android.support.annotation.NonNull)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 NavigationView (android.support.design.widget.NavigationView)1 TabLayout (android.support.design.widget.TabLayout)1 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 Pair (android.support.v4.util.Pair)1 GravityCompat (android.support.v4.view.GravityCompat)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1