@ -26,6 +26,7 @@ import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton ;
import android.support.design.widget.TabLayout ;
import android.support.graphics.drawable.VectorDrawableCompat ;
import android.support.text.emoji.EmojiCompat ;
import android.support.v4.app.Fragment ;
import android.support.v4.content.ContextCompat ;
import android.support.v4.view.ViewPager ;
@ -39,6 +40,7 @@ import com.keylesspalace.tusky.db.AccountEntity;
import com.keylesspalace.tusky.entity.Account ;
import com.keylesspalace.tusky.interfaces.ActionButtonActivity ;
import com.keylesspalace.tusky.pager.TimelinePagerAdapter ;
import com.keylesspalace.tusky.util.CustomEmojiHelper ;
import com.keylesspalace.tusky.util.NotificationHelper ;
import com.keylesspalace.tusky.util.ThemeUtils ;
import com.mikepenz.google_material_typeface_library.GoogleMaterial ;
@ -71,6 +73,7 @@ import retrofit2.Response;
public final class MainActivity extends BottomSheetActivity implements ActionButtonActivity ,
HasSupportFragmentInjector {
private static final String TAG = "MainActivity" ; // logging tag
private static final long DRAWER_ITEM_ADD_ACCOUNT = - 13 ;
private static final long DRAWER_ITEM_EDIT_PROFILE = 0 ;
@ -88,8 +91,6 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
@Inject
public DispatchingAndroidInjector < Fragment > fragmentInjector ;
private static int COMPOSE_RESULT = 1 ;
private FloatingActionButton composeButton ;
private AccountHeader headerResult ;
private Drawer drawer ;
@ -125,7 +126,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
floatingBtn . setOnClickListener ( v - > {
Intent composeIntent = new Intent ( getApplicationContext ( ) , ComposeActivity . class ) ;
startActivityForResult ( composeIntent , COMPOSE_RESULT ) ;
startActivity ( composeIntent ) ;
} ) ;
setupDrawer ( ) ;
@ -305,29 +306,25 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
R . drawable . ic_mute_24dp , getTheme ( ) ) ;
ThemeUtils . setDrawableTint ( this , muteDrawable , R . attr . toolbar_icon_tint ) ;
List < IDrawerItem > listItem = new ArrayList < > ( ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_EDIT_PROFILE ) . withName ( getString ( R . string . action_edit_profile ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_person ) ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_FAVOURITES ) . withName ( getString ( R . string . action_view_favourites ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_star ) ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_LISTS ) . withName ( R . string . action_lists ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_list ) ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_MUTED_USERS ) . withName ( getString ( R . string . action_view_mutes ) ) . withSelectable ( false ) . withIcon ( muteDrawable ) ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_BLOCKED_USERS ) . withName ( getString ( R . string . action_view_blocks ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_block ) ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_SEARCH ) . withName ( getString ( R . string . action_search ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_search ) ) ;
listItem . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_SAVED_TOOT ) . withName ( getString ( R . string . action_access_saved_toot ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_save ) ) ;
listItem . add ( new DividerDrawerItem ( ) ) ;
listItem . add ( new SecondaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_PREFERENCES ) . withName ( getString ( R . string . action_view_preferences ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_settings ) ) ;
listItem . add ( new SecondaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_ABOUT ) . withName ( getString ( R . string . about_title_activity ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_info ) ) ;
listItem . add ( new SecondaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_LOG_OUT ) . withName ( getString ( R . string . action_logout ) ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_exit_to_app ) ) ;
IDrawerItem [ ] array = new IDrawerItem [ listItem . size ( ) ] ;
listItem . toArray ( array ) ; // fill the array
List < IDrawerItem > listItems = new ArrayList < > ( 11 ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_EDIT_PROFILE ) . withName ( R . string . action_edit_profile ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_person ) ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_FAVOURITES ) . withName ( R . string . action_view_favourites ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_star ) ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_LISTS ) . withName ( R . string . action_lists ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_list ) ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_MUTED_USERS ) . withName ( R . string . action_view_mutes ) . withSelectable ( false ) . withIcon ( muteDrawable ) ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_BLOCKED_USERS ) . withName ( R . string . action_view_blocks ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_block ) ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_SEARCH ) . withName ( R . string . action_search ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_search ) ) ;
listItems . add ( new PrimaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_SAVED_TOOT ) . withName ( R . string . action_access_saved_toot ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_save ) ) ;
listItems . add ( new DividerDrawerItem ( ) ) ;
listItems . add ( new SecondaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_PREFERENCES ) . withName ( R . string . action_view_preferences ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_settings ) ) ;
listItems . add ( new SecondaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_ABOUT ) . withName ( R . string . about_title_activity ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_info ) ) ;
listItems . add ( new SecondaryDrawerItem ( ) . withIdentifier ( DRAWER_ITEM_LOG_OUT ) . withName ( R . string . action_logout ) . withSelectable ( false ) . withIcon ( GoogleMaterial . Icon . gmd_exit_to_app ) ) ;
drawer = new DrawerBuilder ( )
. withActivity ( this )
//.withToolbar(toolbar)
. withAccountHeader ( headerResult )
. withHasStableIds ( true )
. withSelectedItem ( - 1 )
. addDrawerItems ( array )
. withDrawerItems ( listItems )
. withOnDrawerItemClickListener ( ( view , position , drawerItem ) - > {
if ( drawerItem ! = null ) {
long drawerItemIdentifier = drawerItem . getIdentifier ( ) ;
@ -490,7 +487,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
. withSelectable ( false )
. withIcon ( GoogleMaterial . Icon . gmd_person_add ) ;
drawer . addItemAtPosition ( followRequestsItem , 3 ) ;
} else {
} else if ( ! me . getLocked ( ) ) {
drawer . removeItem ( DRAWER_ITEM_FOLLOW_REQUESTS ) ;
}
@ -502,24 +499,29 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
List < AccountEntity > allAccounts = accountManager . getAllAccountsOrderedByActive ( ) ;
//remove profiles before adding them again to avoid duplicates
List < IProfile > profiles = new ArrayList < > ( headerResult . getProfiles ( ) ) ;
for ( IProfile profile : profiles ) {
if ( profile . getIdentifier ( ) ! = DRAWER_ITEM_ADD_ACCOUNT ) {
headerResult . removeProfile ( profile ) ;
// reuse the already existing "add account" item
List < IProfile > profiles = new ArrayList < > ( allAccounts . size ( ) + 1 ) ;
for ( IProfile profile : headerResult . getProfiles ( ) ) {
if ( profile . getIdentifier ( ) = = DRAWER_ITEM_ADD_ACCOUNT ) {
profiles . add ( profile ) ;
break ;
}
}
for ( AccountEntity acc : allAccounts ) {
headerResult . addProfiles (
CharSequence emojifiedName = CustomEmojiHelper . emojifyString ( acc . getDisplayName ( ) , acc . getEmojis ( ) , headerResult . getView ( ) ) ;
emojifiedName = EmojiCompat . get ( ) . process ( emojifiedName ) ;
profiles . add ( 0 ,
new ProfileDrawerItem ( )
. withName ( acc . getDisplayName ( ) )
. withName ( emojifiedName )
. withIcon ( acc . getProfilePictureUrl ( ) )
. withNameShown ( true )
. withIdentifier ( acc . getId ( ) )
. withEmail ( acc . getFullName ( ) ) ) ;
}
headerResult . setProfiles ( profiles ) ;
}