Search in sources :

Example 1 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class PreferencesFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    accountManager = TuskyApplication.getInstance(getActivity()).getServiceLocator().get(AccountManager.class);
    int preference = getArguments().getInt("preference");
    addPreferencesFromResource(preference);
    Preference notificationPreferences = findPreference("notificationPreferences");
    if (notificationPreferences != null) {
        AccountEntity activeAccount = accountManager.getActiveAccount();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && activeAccount != null) {
            notificationPreferences.setSummary(getString(R.string.pref_summary_notifications, activeAccount.getFullName()));
        }
        // on Android O and newer, launch the system notification settings instead of the app settings
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationPreferences.setOnPreferenceClickListener(pref -> {
                Intent intent = new Intent();
                intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                intent.putExtra("android.provider.extra.APP_PACKAGE", BuildConfig.APPLICATION_ID);
                startActivity(intent);
                return true;
            });
        } else {
            notificationPreferences.setOnPreferenceClickListener(pref -> {
                PreferencesActivity activity = (PreferencesActivity) getActivity();
                if (activity != null) {
                    activity.showFragment(R.xml.notification_preferences, R.string.pref_title_edit_notification_settings);
                }
                return true;
            });
        }
    }
    Preference timelineFilterPreferences = findPreference("timelineFilterPreferences");
    if (timelineFilterPreferences != null) {
        timelineFilterPreferences.setOnPreferenceClickListener(pref -> {
            PreferencesActivity activity = (PreferencesActivity) getActivity();
            if (activity != null) {
                activity.showFragment(R.xml.timeline_filter_preferences, R.string.pref_title_status_tabs);
            }
            return true;
        });
    }
    Preference httpProxyPreferences = findPreference("httpProxyPreferences");
    if (httpProxyPreferences != null) {
        httpProxyPreferences.setOnPreferenceClickListener(pref -> {
            PreferencesActivity activity = (PreferencesActivity) getActivity();
            if (activity != null) {
                pendingRestart = false;
                activity.showFragment(R.xml.http_proxy_preferences, R.string.pref_title_http_proxy_settings);
            }
            return true;
        });
    }
    if (preference == R.xml.notification_preferences) {
        AccountEntity activeAccount = accountManager.getActiveAccount();
        if (activeAccount != null) {
            CheckBoxPreference notificationPref = (CheckBoxPreference) findPreference("notificationsEnabled");
            notificationPref.setChecked(activeAccount.getNotificationsEnabled());
            CheckBoxPreference mentionedPref = (CheckBoxPreference) findPreference("notificationFilterMentions");
            mentionedPref.setChecked(activeAccount.getNotificationsMentioned());
            CheckBoxPreference followedPref = (CheckBoxPreference) findPreference("notificationFilterFollows");
            followedPref.setChecked(activeAccount.getNotificationsFollowed());
            CheckBoxPreference boostedPref = (CheckBoxPreference) findPreference("notificationFilterReblogs");
            boostedPref.setChecked(activeAccount.getNotificationsReblogged());
            CheckBoxPreference favoritedPref = (CheckBoxPreference) findPreference("notificationFilterFavourites");
            favoritedPref.setChecked(activeAccount.getNotificationsFavorited());
            CheckBoxPreference soundPref = (CheckBoxPreference) findPreference("notificationAlertSound");
            soundPref.setChecked(activeAccount.getNotificationSound());
            CheckBoxPreference vibrationPref = (CheckBoxPreference) findPreference("notificationAlertVibrate");
            vibrationPref.setChecked(activeAccount.getNotificationVibration());
            CheckBoxPreference lightPref = (CheckBoxPreference) findPreference("notificationAlertLight");
            lightPref.setChecked(activeAccount.getNotificationLight());
        }
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) Preference(android.preference.Preference) PreferencesActivity(com.keylesspalace.tusky.PreferencesActivity) CheckBoxPreference(android.preference.CheckBoxPreference) AccountManager(com.keylesspalace.tusky.db.AccountManager) Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 2 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class NotificationsFragment method saveNewestNotificationId.

private void saveNewestNotificationId(List<Notification> notifications) {
    AccountManager accountManager = TuskyApplication.getInstance(getContext()).getServiceLocator().get(AccountManager.class);
    AccountEntity account = accountManager.getActiveAccount();
    BigInteger lastNoti = new BigInteger(account.getLastNotificationId());
    for (Notification noti : notifications) {
        BigInteger a = new BigInteger(noti.getId());
        if (isBiggerThan(a, lastNoti)) {
            lastNoti = a;
        }
    }
    Log.d(TAG, "saving newest noti id: " + lastNoti);
    account.setLastNotificationId(lastNoti.toString());
    accountManager.saveAccount(account);
}
Also used : BigInteger(java.math.BigInteger) AccountManager(com.keylesspalace.tusky.db.AccountManager) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Notification(com.keylesspalace.tusky.entity.Notification)

Example 3 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class InstanceSwitchAuthInterceptor method intercept.

@Override
public Response intercept(@NonNull Chain chain) throws IOException {
    Request originalRequest = chain.request();
    AccountEntity currentAccount = accountManager.getActiveAccount();
    Request.Builder builder = originalRequest.newBuilder();
    String instanceHeader = originalRequest.header(MastodonApi.DOMAIN_HEADER);
    if (instanceHeader != null) {
        // use domain explicitly specified in custom header
        builder.url(swapHost(originalRequest.url(), instanceHeader));
        builder.removeHeader(MastodonApi.DOMAIN_HEADER);
    } else if (currentAccount != null) {
        // use domain of current account
        builder.url(swapHost(originalRequest.url(), currentAccount.getDomain())).header("Authorization", String.format("Bearer %s", currentAccount.getAccessToken()));
    }
    Request newRequest = builder.build();
    return chain.proceed(newRequest);
}
Also used : Request(okhttp3.Request) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 4 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class MainActivity method handleProfileClick.

private boolean handleProfileClick(IProfile profile, boolean current) {
    AccountEntity activeAccount = accountManager.getActiveAccount();
    // open profile when active image was clicked
    if (current && activeAccount != null) {
        Intent intent = new Intent(MainActivity.this, AccountActivity.class);
        intent.putExtra("id", activeAccount.getAccountId());
        startActivity(intent);
        return true;
    }
    // open LoginActivity to add new account
    if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) {
        startActivity(LoginActivity.getIntent(this, true));
        return true;
    }
    // change Account
    changeAccount(profile.getIdentifier());
    return false;
}
Also used : Intent(android.content.Intent) AccountEntity(com.keylesspalace.tusky.db.AccountEntity)

Example 5 with AccountEntity

use of com.keylesspalace.tusky.db.AccountEntity in project Tusky by tuskyapp.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    int tabPosition = 0;
    accountManager = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class);
    if (intent != null) {
        long accountId = intent.getLongExtra(NotificationHelper.ACCOUNT_ID, -1);
        if (accountId != -1) {
            // user clicked a notification, show notification tab and switch user if necessary
            tabPosition = 1;
            AccountEntity account = accountManager.getActiveAccount();
            if (account == null || accountId != account.getId()) {
                accountManager.setActiveAccount(accountId);
            }
        }
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FloatingActionButton floatingBtn = findViewById(R.id.floating_btn);
    ImageButton drawerToggle = findViewById(R.id.drawer_toggle);
    TabLayout tabLayout = findViewById(R.id.tab_layout);
    viewPager = findViewById(R.id.pager);
    floatingBtn.setOnClickListener(v -> {
        Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class);
        startActivityForResult(composeIntent, COMPOSE_RESULT);
    });
    setupDrawer();
    // Setup the navigation drawer toggle button.
    ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint);
    drawerToggle.setOnClickListener(v -> drawer.openDrawer());
    /* Fetch user info while we're doing other things. This has to be done after setting up the
         * drawer, though, because its callback touches the header in the drawer. */
    fetchUserInfo();
    // Setup the tabs and timeline pager.
    TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
    int[] tabIcons = { R.drawable.ic_home_24dp, R.drawable.ic_notifications_24dp, R.drawable.ic_local_24dp, R.drawable.ic_public_24dp };
    String[] pageTitles = { getString(R.string.title_home), getString(R.string.title_notifications), getString(R.string.title_public_local), getString(R.string.title_public_federated) };
    for (int i = 0; i < 4; i++) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        tab.setIcon(tabIcons[i]);
        tab.setContentDescription(pageTitles[i]);
    }
    if (tabPosition != 0) {
        TabLayout.Tab tab = tabLayout.getTabAt(tabPosition);
        if (tab != null) {
            tab.select();
        } else {
            tabPosition = 0;
        }
    }
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
            tintTab(tab, true);
            if (tab.getPosition() == 1) {
                NotificationHelper.clearNotificationsForActiveAccount(MainActivity.this);
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            tintTab(tab, false);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    for (int i = 0; i < 4; i++) {
        tintTab(tabLayout.getTabAt(i), i == tabPosition);
    }
    // Setup push notifications
    if (NotificationHelper.areNotificationsEnabled(this)) {
        enablePushNotifications();
    } else {
        disablePushNotifications();
    }
    composeButton = floatingBtn;
}
Also used : Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) ImageButton(android.widget.ImageButton) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) AccountManager(com.keylesspalace.tusky.db.AccountManager)

Aggregations

AccountEntity (com.keylesspalace.tusky.db.AccountEntity)23 Intent (android.content.Intent)12 AccountManager (com.keylesspalace.tusky.db.AccountManager)9 ArrayList (java.util.ArrayList)4 NotificationManager (android.app.NotificationManager)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3 Status (com.keylesspalace.tusky.entity.Status)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 Bundle (android.os.Bundle)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 TabLayout (android.support.design.widget.TabLayout)2 ActionBar (android.support.v7.app.ActionBar)2 Toolbar (android.support.v7.widget.Toolbar)2 Log (android.util.Log)2 Menu (android.view.Menu)2 View (android.view.View)2 ImageView (android.widget.ImageView)2