New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: toast to snackbar for login work #788
Conversation
}) | ||
|
||
loginViewModel.loggedIn.observe(this, Observer { | ||
Toast.makeText(context, getString(R.string.welcome_back), Toast.LENGTH_LONG).show() | ||
Snackbar.make(getActivity()!!.findViewById(android.R.id.content), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use safe calls instead of !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then it is showing type mismatch as snackbar requires view of type View and we are giving View? Are non-null asserted calls allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, don't use findViewById. Secondly, that'll fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
android.R.id.content
This isn't to be used. Use coordinator layout of the current fragment/activity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I open an issue to change layout to coordinator layout or should do in this PR only. Also if we use coordinator layout of the current fragment as a view then snackbar will not be coming from bottom of the screen. Pls correct me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, OK. Use CoordinatorLayout of the root element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how to get CoordinatorLayout of the root element. when I try to use CoordinatorLayout of root element i.e rootLayout(activity_main.xml) It is becoming null
I'm facing
java.lang.IllegalStateException: rootView.findViewById(R.id.rootLayout) must not be null at org.fossasia.openevent.general.order.OrdersUnderUserFragment.onCreateView(OrdersUnderUserFragment.kt:48)
Need help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call findViewById on activity
Your PR has undone several changes |
Yes. Sorry for that I will correct them using different branch |
* chore: change to coordinator layout requires in #788 * Update fragment_login.xml * Update fragment_login.xml
@iamareebjamal the UI of login fragment is not fine with the requested changes in #790 The preview is not building correctly due to current changes in gradle which is making difficult to fix this Should I go with old way with scrollview wrapping coordinator layout which had fix this. Pls guide |
OK |
@@ -56,7 +58,7 @@ class LoginFragment : Fragment() { | |||
savedInstanceState: Bundle? | |||
): View? { | |||
rootView = inflater.inflate(R.layout.fragment_login, container, false) | |||
|
|||
CoordinatorLayout = rootView.findViewById(R.id.loginCoordinatorLayout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use findViewById
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why is this capital. Is this a class?
CoordinatorLayout, "You need to log in first!", Snackbar.LENGTH_SHORT).show() | ||
Handler().postDelayed({ | ||
redirectToLogin() | ||
}, 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will correct don't know why autoformat is going for this
@iamareebjamal I think the current way to show snackbar as shown in GIF is more apt as showing snackbar from bottom of screen will hinder the UI nor it is properly hiding it. It is hiding navigation buttons upto 3/4. If you agree with current way I will move toward for requested changes. Pls guide |
@@ -36,6 +38,7 @@ class LoginFragment : Fragment() { | |||
|
|||
private val loginViewModel by viewModel<LoginViewModel>() | |||
private lateinit var rootView: View | |||
private lateinit var coordinatorLayout: CoordinatorLayout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to initialize it?
You have access to rootView. Use it everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 'ktlint' found problem in 'app\src\main\java\org\fossasia\openevent\general\auth\LoginFragment.kt':
Error on line: 90, column: 1
Exceeded max line length (120)
@iamareebjamal can we increase this 120 length limit😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on directly using rootview.requiredCoordinatorLayout. I am getting above error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then break that line
Part for #785
fix #797
merge after #790
Screenshots for Login fragment UI fix
GIF for the Snackbar change: