Skip to content
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

Merged
merged 10 commits into from
Dec 30, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.fragment_login.email
import kotlinx.android.synthetic.main.fragment_login.loginButton
import kotlinx.android.synthetic.main.fragment_login.password
import kotlinx.android.synthetic.main.fragment_login.view.email
import kotlinx.android.synthetic.main.fragment_login.view.loginCoordinatorLayout
import kotlinx.android.synthetic.main.fragment_login.view.forgotPassword
import kotlinx.android.synthetic.main.fragment_login.view.loginButton
import kotlinx.android.synthetic.main.fragment_login.view.loginLayout
Expand Down Expand Up @@ -56,7 +57,6 @@ class LoginFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
rootView = inflater.inflate(R.layout.fragment_login, container, false)

if (loginViewModel.isLoggedIn())
redirectToMain(bundle)

Expand All @@ -81,13 +81,15 @@ class LoginFragment : Fragment() {
loginViewModel.error
.nonNull()
.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
Snackbar.make(rootView.loginCoordinatorLayout, it, Snackbar.LENGTH_LONG).show()
})

loginViewModel.loggedIn
.nonNull()
.observe(this, Observer {
Toast.makeText(context, getString(R.string.welcome_back), Toast.LENGTH_LONG).show()
Snackbar.make(
rootView.loginCoordinatorLayout, getString(R.string.welcome_back), Snackbar.LENGTH_LONG
).show()
loginViewModel.fetchProfile()
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package org.fossasia.openevent.general.auth

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import com.google.android.material.snackbar.Snackbar
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.fragment_profile.view.profileCoordinatorLayout
import kotlinx.android.synthetic.main.fragment_profile.view.avatar
import kotlinx.android.synthetic.main.fragment_profile.view.email
import kotlinx.android.synthetic.main.fragment_profile.view.name
Expand Down Expand Up @@ -48,14 +49,6 @@ class ProfileFragment : Fragment() {
startActivity(Intent(activity, MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
}

override fun onAttach(context: Context) {
super.onAttach(context)
if (!profileViewModel.isLoggedIn()) {
Toast.makeText(context, "You need to Login!", Toast.LENGTH_LONG).show()
redirectToLogin()
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -65,6 +58,13 @@ class ProfileFragment : Fragment() {

setHasOptionsMenu(true)

if (!profileViewModel.isLoggedIn()) {
Snackbar.make(rootView.profileCoordinatorLayout, "You need to log in first!", Snackbar.LENGTH_SHORT).show()
Handler().postDelayed({
redirectToLogin()
}, 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange indentation

Copy link
Member Author

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

}

profileViewModel.progress
.nonNull()
.observe(this, Observer {
Expand All @@ -74,7 +74,7 @@ class ProfileFragment : Fragment() {
profileViewModel.error
.nonNull()
.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
Snackbar.make(rootView.profileCoordinatorLayout, it, Snackbar.LENGTH_SHORT).show()
})

profileViewModel.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package org.fossasia.openevent.general.order

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.content_no_tickets.findMyTickets
import kotlinx.android.synthetic.main.fragment_orders_under_user.noTicketsScreen
import kotlinx.android.synthetic.main.fragment_orders_under_user.view.ordersUnderUserCoordinatorLayout
import kotlinx.android.synthetic.main.fragment_orders_under_user.view.ordersRecycler
import kotlinx.android.synthetic.main.fragment_orders_under_user.view.progressBar
import org.fossasia.openevent.general.AuthActivity
Expand Down Expand Up @@ -79,7 +81,9 @@ class OrdersUnderUserFragment : Fragment() {
ordersUnderUserVM.message
.nonNull()
.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
Snackbar.make(
rootView.ordersUnderUserCoordinatorLayout, it, Snackbar.LENGTH_LONG
).show()
})

ordersUnderUserVM.noTickets
Expand All @@ -102,8 +106,12 @@ class OrdersUnderUserFragment : Fragment() {
Timber.d("Fetched events of size %s", ordersRecyclerAdapter.itemCount)
})
} else {
redirectToLogin()
Toast.makeText(context, "You need to log in first!", Toast.LENGTH_LONG).show()
Snackbar.make(
rootView.ordersUnderUserCoordinatorLayout, "You need to log in first!", Snackbar.LENGTH_SHORT
).show()
Handler().postDelayed({
redirectToLogin()
}, 500)
}

return rootView
Expand Down