use of org.telegram.ui.Components.SideMenultItemAnimator in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
ApplicationLoader.postInitApplication();
AndroidUtilities.checkDisplaySize(this, getResources().getConfiguration());
currentAccount = UserConfig.selectedAccount;
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
Intent intent = getIntent();
boolean isProxy = false;
if (intent != null && intent.getAction() != null) {
if (Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
super.onCreate(savedInstanceState);
finish();
return;
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
if (uri != null) {
String url = uri.toString().toLowerCase();
isProxy = url.startsWith("tg:proxy") || url.startsWith("tg://proxy") || url.startsWith("tg:socks") || url.startsWith("tg://socks");
}
}
}
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
long crashed_time = preferences.getLong("intro_crashed_time", 0);
boolean fromIntro = intent != null && intent.getBooleanExtra("fromIntro", false);
if (fromIntro) {
preferences.edit().putLong("intro_crashed_time", 0).commit();
}
if (!isProxy && Math.abs(crashed_time - System.currentTimeMillis()) >= 60 * 2 * 1000 && intent != null && !fromIntro) {
preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", MODE_PRIVATE);
Map<String, ?> state = preferences.getAll();
if (state.isEmpty()) {
Intent intent2 = new Intent(this, IntroActivity.class);
intent2.setData(intent.getData());
startActivity(intent2);
super.onCreate(savedInstanceState);
finish();
return;
}
}
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(R.style.Theme_TMessages);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
setTaskDescription(new ActivityManager.TaskDescription(null, null, Theme.getColor(Theme.key_actionBarDefault) | 0xff000000));
} catch (Exception ignore) {
}
try {
getWindow().setNavigationBarColor(0xff000000);
} catch (Exception ignore) {
}
}
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
try {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
FileLog.e(e);
}
}
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= 24) {
AndroidUtilities.isInMultiwindow = isInMultiWindowMode();
}
Theme.createCommonChatResources();
Theme.createDialogsResources(this);
if (SharedConfig.passcodeHash.length() != 0 && SharedConfig.appLocked) {
SharedConfig.lastPauseTime = (int) (SystemClock.elapsedRealtime() / 1000);
}
AndroidUtilities.fillStatusBarHeight(this);
actionBarLayout = new ActionBarLayout(this) {
@Override
public void setThemeAnimationValue(float value) {
super.setThemeAnimationValue(value);
if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
ArticleViewer.getInstance().updateThemeColors(value);
}
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
if (PhotoViewer.hasInstance()) {
PhotoViewer.getInstance().updateColors();
}
}
};
frameLayout = new FrameLayout(this);
setContentView(frameLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
if (Build.VERSION.SDK_INT >= 21) {
themeSwitchImageView = new ImageView(this);
themeSwitchImageView.setVisibility(View.GONE);
}
drawerLayoutContainer = new DrawerLayoutContainer(this) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
setDrawerPosition(getDrawerPosition());
}
};
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
frameLayout.addView(drawerLayoutContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
if (Build.VERSION.SDK_INT >= 21) {
themeSwitchSunView = new View(this) {
@Override
protected void onDraw(Canvas canvas) {
if (themeSwitchSunDrawable != null) {
themeSwitchSunDrawable.draw(canvas);
invalidate();
}
}
};
frameLayout.addView(themeSwitchSunView, LayoutHelper.createFrame(48, 48));
themeSwitchSunView.setVisibility(View.GONE);
}
if (AndroidUtilities.isTablet()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
RelativeLayout launchLayout = new RelativeLayout(this) {
private boolean inLayout;
@Override
public void requestLayout() {
if (inLayout) {
return;
}
super.requestLayout();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
inLayout = true;
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
tabletFullSize = false;
int leftWidth = width / 100 * 35;
if (leftWidth < AndroidUtilities.dp(320)) {
leftWidth = AndroidUtilities.dp(320);
}
actionBarLayout.measure(MeasureSpec.makeMeasureSpec(leftWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
shadowTabletSide.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
rightActionBarLayout.measure(MeasureSpec.makeMeasureSpec(width - leftWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
} else {
tabletFullSize = true;
actionBarLayout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
backgroundTablet.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
shadowTablet.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
layersActionBarLayout.measure(MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(530), width), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(528), height), MeasureSpec.EXACTLY));
inLayout = false;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
if (!AndroidUtilities.isInMultiwindow && (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
int leftWidth = width / 100 * 35;
if (leftWidth < AndroidUtilities.dp(320)) {
leftWidth = AndroidUtilities.dp(320);
}
shadowTabletSide.layout(leftWidth, 0, leftWidth + shadowTabletSide.getMeasuredWidth(), shadowTabletSide.getMeasuredHeight());
actionBarLayout.layout(0, 0, actionBarLayout.getMeasuredWidth(), actionBarLayout.getMeasuredHeight());
rightActionBarLayout.layout(leftWidth, 0, leftWidth + rightActionBarLayout.getMeasuredWidth(), rightActionBarLayout.getMeasuredHeight());
} else {
actionBarLayout.layout(0, 0, actionBarLayout.getMeasuredWidth(), actionBarLayout.getMeasuredHeight());
}
int x = (width - layersActionBarLayout.getMeasuredWidth()) / 2;
int y = (height - layersActionBarLayout.getMeasuredHeight()) / 2;
layersActionBarLayout.layout(x, y, x + layersActionBarLayout.getMeasuredWidth(), y + layersActionBarLayout.getMeasuredHeight());
backgroundTablet.layout(0, 0, backgroundTablet.getMeasuredWidth(), backgroundTablet.getMeasuredHeight());
shadowTablet.layout(0, 0, shadowTablet.getMeasuredWidth(), shadowTablet.getMeasuredHeight());
}
};
drawerLayoutContainer.addView(launchLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
backgroundTablet = new SizeNotifierFrameLayout(this) {
@Override
protected boolean isActionBarVisible() {
return false;
}
};
backgroundTablet.setOccupyStatusBar(false);
backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
launchLayout.addView(backgroundTablet, LayoutHelper.createRelative(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
launchLayout.addView(actionBarLayout);
rightActionBarLayout = new ActionBarLayout(this);
rightActionBarLayout.init(rightFragmentsStack);
rightActionBarLayout.setDelegate(this);
launchLayout.addView(rightActionBarLayout);
shadowTabletSide = new FrameLayout(this);
shadowTabletSide.setBackgroundColor(0x40295274);
launchLayout.addView(shadowTabletSide);
shadowTablet = new FrameLayout(this);
shadowTablet.setVisibility(layerFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
shadowTablet.setBackgroundColor(0x7f000000);
launchLayout.addView(shadowTablet);
shadowTablet.setOnTouchListener((v, event) -> {
if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) {
float x = event.getX();
float y = event.getY();
int[] location = new int[2];
layersActionBarLayout.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) {
return false;
} else {
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
a--;
}
layersActionBarLayout.closeLastFragment(true);
}
return true;
}
}
return false;
});
shadowTablet.setOnClickListener(v -> {
});
layersActionBarLayout = new ActionBarLayout(this);
layersActionBarLayout.setRemoveActionBarExtraHeight(true);
layersActionBarLayout.setBackgroundView(shadowTablet);
layersActionBarLayout.setUseAlphaAnimations(true);
layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow);
layersActionBarLayout.init(layerFragmentsStack);
layersActionBarLayout.setDelegate(this);
layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
layersActionBarLayout.setVisibility(layerFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
launchLayout.addView(layersActionBarLayout);
} else {
drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
sideMenuContainer = new FrameLayout(this);
sideMenu = new RecyclerListView(this) {
@Override
public boolean drawChild(Canvas canvas, View child, long drawingTime) {
int restore = -1;
if (itemAnimator != null && itemAnimator.isRunning() && itemAnimator.isAnimatingChild(child)) {
restore = canvas.save();
canvas.clipRect(0, itemAnimator.getAnimationClipTop(), getMeasuredWidth(), getMeasuredHeight());
}
boolean result = super.drawChild(canvas, child, drawingTime);
if (restore >= 0) {
canvas.restoreToCount(restore);
invalidate();
invalidateViews();
}
return result;
}
};
itemAnimator = new SideMenultItemAnimator(sideMenu);
sideMenu.setItemAnimator(itemAnimator);
sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
sideMenu.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
sideMenu.setAllowItemsInteractionDuringAnimation(false);
sideMenu.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this, itemAnimator));
sideMenuContainer.addView(sideMenu, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
drawerLayoutContainer.setDrawerLayout(sideMenuContainer);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) sideMenuContainer.getLayoutParams();
Point screenSize = AndroidUtilities.getRealScreenSize();
layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(AndroidUtilities.dp(320), Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56));
layoutParams.height = LayoutHelper.MATCH_PARENT;
sideMenuContainer.setLayoutParams(layoutParams);
sideMenu.setOnItemClickListener((view, position, x, y) -> {
if (position == 0) {
DrawerProfileCell profileCell = (DrawerProfileCell) view;
if (profileCell.isInAvatar(x, y)) {
openSettings(profileCell.hasAvatar());
} else {
drawerLayoutAdapter.setAccountsShown(!drawerLayoutAdapter.isAccountsShown(), true);
}
} else if (view instanceof DrawerUserCell) {
switchToAccount(((DrawerUserCell) view).getAccountNumber(), true);
drawerLayoutContainer.closeDrawer(false);
} else if (view instanceof DrawerAddCell) {
int freeAccount = -1;
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
if (!UserConfig.getInstance(a).isClientActivated()) {
freeAccount = a;
break;
}
}
if (freeAccount >= 0) {
presentFragment(new LoginActivity(freeAccount));
}
drawerLayoutContainer.closeDrawer(false);
} else {
int id = drawerLayoutAdapter.getId(position);
if (id == 2) {
Bundle args = new Bundle();
presentFragment(new GroupCreateActivity(args));
drawerLayoutContainer.closeDrawer(false);
} else if (id == 3) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("createSecretChat", true);
args.putBoolean("allowBots", false);
args.putBoolean("allowSelf", false);
presentFragment(new ContactsActivity(args));
drawerLayoutContainer.closeDrawer(false);
} else if (id == 4) {
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
if (!BuildVars.DEBUG_VERSION && preferences.getBoolean("channel_intro", false)) {
Bundle args = new Bundle();
args.putInt("step", 0);
presentFragment(new ChannelCreateActivity(args));
} else {
presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANNEL_CREATE));
preferences.edit().putBoolean("channel_intro", true).commit();
}
drawerLayoutContainer.closeDrawer(false);
} else if (id == 6) {
presentFragment(new ContactsActivity(null));
drawerLayoutContainer.closeDrawer(false);
} else if (id == 7) {
presentFragment(new InviteContactsActivity());
drawerLayoutContainer.closeDrawer(false);
} else if (id == 8) {
openSettings(false);
} else if (id == 9) {
Browser.openUrl(LaunchActivity.this, LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl));
drawerLayoutContainer.closeDrawer(false);
} else if (id == 10) {
presentFragment(new CallLogActivity());
drawerLayoutContainer.closeDrawer(false);
} else if (id == 11) {
Bundle args = new Bundle();
args.putLong("user_id", UserConfig.getInstance(currentAccount).getClientUserId());
presentFragment(new ChatActivity(args));
drawerLayoutContainer.closeDrawer(false);
} else if (id == 12) {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ACCESS));
drawerLayoutContainer.closeDrawer(false);
return;
}
}
boolean enabled = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
enabled = lm.isLocationEnabled();
} else if (Build.VERSION.SDK_INT >= 19) {
try {
int mode = Settings.Secure.getInt(ApplicationLoader.applicationContext.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
} catch (Throwable e) {
FileLog.e(e);
}
}
if (enabled) {
presentFragment(new PeopleNearbyActivity());
} else {
presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ENABLED));
}
drawerLayoutContainer.closeDrawer(false);
} else if (id == 13) {
Browser.openUrl(LaunchActivity.this, LocaleController.getString("TelegramFeaturesUrl", R.string.TelegramFeaturesUrl));
drawerLayoutContainer.closeDrawer(false);
}
}
});
final ItemTouchHelper sideMenuTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0) {
private RecyclerView.ViewHolder selectedViewHolder;
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
if (viewHolder.getItemViewType() != target.getItemViewType()) {
return false;
}
drawerLayoutAdapter.swapElements(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return true;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
clearSelectedViewHolder();
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
selectedViewHolder = viewHolder;
final View view = viewHolder.itemView;
sideMenu.cancelClickRunnables(false);
view.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
if (Build.VERSION.SDK_INT >= 21) {
ObjectAnimator.ofFloat(view, "elevation", AndroidUtilities.dp(1)).setDuration(150).start();
}
}
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
clearSelectedViewHolder();
}
private void clearSelectedViewHolder() {
if (selectedViewHolder != null) {
final View view = selectedViewHolder.itemView;
selectedViewHolder = null;
view.setTranslationX(0f);
view.setTranslationY(0f);
if (Build.VERSION.SDK_INT >= 21) {
final ObjectAnimator animator = ObjectAnimator.ofFloat(view, "elevation", 0f);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setBackground(null);
}
});
animator.setDuration(150).start();
}
}
}
@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
final View view = viewHolder.itemView;
if (drawerLayoutAdapter.isAccountsShown()) {
RecyclerView.ViewHolder topViewHolder = recyclerView.findViewHolderForAdapterPosition(drawerLayoutAdapter.getFirstAccountPosition() - 1);
RecyclerView.ViewHolder bottomViewHolder = recyclerView.findViewHolderForAdapterPosition(drawerLayoutAdapter.getLastAccountPosition() + 1);
if (topViewHolder != null && topViewHolder.itemView != null && topViewHolder.itemView.getBottom() == view.getTop() && dY < 0f) {
dY = 0f;
} else if (bottomViewHolder != null && bottomViewHolder.itemView != null && bottomViewHolder.itemView.getTop() == view.getBottom() && dY > 0f) {
dY = 0f;
}
}
view.setTranslationX(dX);
view.setTranslationY(dY);
}
});
sideMenuTouchHelper.attachToRecyclerView(sideMenu);
sideMenu.setOnItemLongClickListener((view, position) -> {
if (view instanceof DrawerUserCell) {
final int accountNumber = ((DrawerUserCell) view).getAccountNumber();
if (accountNumber == currentAccount || AndroidUtilities.isTablet()) {
sideMenuTouchHelper.startDrag(sideMenu.getChildViewHolder(view));
} else {
final BaseFragment fragment = new DialogsActivity(null) {
@Override
protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
super.onTransitionAnimationEnd(isOpen, backward);
if (!isOpen && backward) {
// closed
drawerLayoutContainer.setDrawCurrentPreviewFragmentAbove(false);
}
}
@Override
protected void onPreviewOpenAnimationEnd() {
super.onPreviewOpenAnimationEnd();
drawerLayoutContainer.setAllowOpenDrawer(false, false);
drawerLayoutContainer.setDrawCurrentPreviewFragmentAbove(false);
switchToAccount(accountNumber, true);
}
};
fragment.setCurrentAccount(accountNumber);
actionBarLayout.presentFragmentAsPreview(fragment);
drawerLayoutContainer.setDrawCurrentPreviewFragmentAbove(true);
return true;
}
}
return false;
});
drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
actionBarLayout.init(mainFragmentsStack);
actionBarLayout.setDelegate(this);
Theme.loadWallpaper();
checkCurrentAccount();
updateCurrentConnectionState(currentAccount);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this);
currentConnectionState = ConnectionsManager.getInstance(currentAccount).getConnectionState();
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.needShowAlert);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.reloadInterface);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.suggestedLangpack);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewTheme);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.needSetDayNightTheme);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.needCheckSystemBarColors);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetPasscode);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.notificationsCountUpdated);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.screenStateChanged);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.showBulletin);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.appUpdateAvailable);
if (actionBarLayout.fragmentsStack.isEmpty()) {
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
actionBarLayout.addFragmentToStack(new LoginActivity());
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
DialogsActivity dialogsActivity = new DialogsActivity(null);
dialogsActivity.setSideMenu(sideMenu);
actionBarLayout.addFragmentToStack(dialogsActivity);
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
try {
if (savedInstanceState != null) {
String fragmentName = savedInstanceState.getString("fragment");
if (fragmentName != null) {
Bundle args = savedInstanceState.getBundle("args");
switch(fragmentName) {
case "chat":
if (args != null) {
ChatActivity chat = new ChatActivity(args);
if (actionBarLayout.addFragmentToStack(chat)) {
chat.restoreSelfArgs(savedInstanceState);
}
}
break;
case "settings":
{
args.putLong("user_id", UserConfig.getInstance(currentAccount).clientUserId);
ProfileActivity settings = new ProfileActivity(args);
actionBarLayout.addFragmentToStack(settings);
settings.restoreSelfArgs(savedInstanceState);
break;
}
case "group":
if (args != null) {
GroupCreateFinalActivity group = new GroupCreateFinalActivity(args);
if (actionBarLayout.addFragmentToStack(group)) {
group.restoreSelfArgs(savedInstanceState);
}
}
break;
case "channel":
if (args != null) {
ChannelCreateActivity channel = new ChannelCreateActivity(args);
if (actionBarLayout.addFragmentToStack(channel)) {
channel.restoreSelfArgs(savedInstanceState);
}
}
break;
case "chat_profile":
if (args != null) {
ProfileActivity profile = new ProfileActivity(args);
if (actionBarLayout.addFragmentToStack(profile)) {
profile.restoreSelfArgs(savedInstanceState);
}
}
break;
case "wallpapers":
{
WallpapersListActivity settings = new WallpapersListActivity(WallpapersListActivity.TYPE_ALL);
actionBarLayout.addFragmentToStack(settings);
settings.restoreSelfArgs(savedInstanceState);
break;
}
}
}
}
} catch (Exception e) {
FileLog.e(e);
}
} else {
BaseFragment fragment = actionBarLayout.fragmentsStack.get(0);
if (fragment instanceof DialogsActivity) {
((DialogsActivity) fragment).setSideMenu(sideMenu);
}
boolean allowOpen = true;
if (AndroidUtilities.isTablet()) {
allowOpen = actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty();
if (layersActionBarLayout.fragmentsStack.size() == 1 && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
allowOpen = false;
}
}
if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
allowOpen = false;
}
drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false);
}
checkLayout();
checkSystemBarColors();
handleIntent(getIntent(), false, savedInstanceState != null, false);
try {
String os1 = Build.DISPLAY;
String os2 = Build.USER;
if (os1 != null) {
os1 = os1.toLowerCase();
} else {
os1 = "";
}
if (os2 != null) {
os2 = os1.toLowerCase();
} else {
os2 = "";
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("OS name " + os1 + " " + os2);
}
if ((os1.contains("flyme") || os2.contains("flyme")) && Build.VERSION.SDK_INT <= 24) {
AndroidUtilities.incorrectDisplaySizeFix = true;
final View view = getWindow().getDecorView().getRootView();
view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener = () -> {
int height = view.getMeasuredHeight();
FileLog.d("height = " + height + " displayHeight = " + AndroidUtilities.displaySize.y);
if (Build.VERSION.SDK_INT >= 21) {
height -= AndroidUtilities.statusBarHeight;
}
if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) {
AndroidUtilities.displaySize.y = height;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("fix display size y to " + AndroidUtilities.displaySize.y);
}
}
});
}
} catch (Exception e) {
FileLog.e(e);
}
MediaController.getInstance().setBaseActivity(this, true);
AndroidUtilities.startAppCenter(this);
updateAppUpdateViews(false);
}
Aggregations