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,10 +8,11 @@ import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout
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
Expand All @@ -36,6 +37,7 @@ class LoginFragment : Fragment() {

private val loginViewModel by viewModel<LoginViewModel>()
private lateinit var rootView: View
private lateinit var CoordinatorLayout: CoordinatorLayout
private var bundle: Bundle? = null
private var ticketIdAndQty: List<Pair<Int, Int>>? = null
private var id: Long = -1
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Don't use findViewById

Copy link
Member

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?

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

Expand All @@ -81,13 +83,15 @@ class LoginFragment : Fragment() {
loginViewModel.error
.nonNull()
.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
Snackbar.make(
CoordinatorLayout, 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(
CoordinatorLayout, getString(R.string.welcome_back), Snackbar.LENGTH_LONG).show()
loginViewModel.fetchProfile()
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
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.coordinatorlayout.widget.CoordinatorLayout
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.avatar
import kotlinx.android.synthetic.main.fragment_profile.view.email
Expand All @@ -36,6 +37,7 @@ class ProfileFragment : Fragment() {
private val profileViewModel by viewModel<ProfileViewModel>()

private lateinit var rootView: View
private lateinit var CoordinatorLayout: CoordinatorLayout
private var emailSettings: String? = null
private val EMAIL: String = "EMAIL"

Expand All @@ -48,23 +50,24 @@ 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?,
savedInstanceState: Bundle?
): View? {
rootView = inflater.inflate(R.layout.fragment_profile, container, false)
CoordinatorLayout = rootView.findViewById(R.id.profileCoordinatorLayout)

setHasOptionsMenu(true)

if (!profileViewModel.isLoggedIn()) {
Snackbar.make(
CoordinatorLayout, "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 +77,8 @@ class ProfileFragment : Fragment() {
profileViewModel.error
.nonNull()
.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
Snackbar.make(
CoordinatorLayout, it, Snackbar.LENGTH_SHORT).show()
})

profileViewModel.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ 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.coordinatorlayout.widget.CoordinatorLayout
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.ordersRecycler
Expand All @@ -30,6 +32,7 @@ const val LAUNCH_TICKETS: String = "LAUNCH_TICKETS"
class OrdersUnderUserFragment : Fragment() {

private lateinit var rootView: View
private lateinit var CoordinatorLayout: CoordinatorLayout
private val ordersUnderUserVM by viewModel<OrdersUnderUserVM>()
private val ordersRecyclerAdapter: OrdersRecyclerAdapter = OrdersRecyclerAdapter()
private lateinit var linearLayoutManager: LinearLayoutManager
Expand All @@ -40,6 +43,7 @@ class OrdersUnderUserFragment : Fragment() {
savedInstanceState: Bundle?
): View? {
rootView = inflater.inflate(R.layout.fragment_orders_under_user, container, false)
CoordinatorLayout = rootView.findViewById(R.id.ordersUnderUserCoordinatorLayout)
val activity = activity as? AppCompatActivity
activity?.supportActionBar?.title = "Tickets"

Expand Down Expand Up @@ -79,7 +83,8 @@ class OrdersUnderUserFragment : Fragment() {
ordersUnderUserVM.message
.nonNull()
.observe(this, Observer {
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
Snackbar.make(
CoordinatorLayout, it, Snackbar.LENGTH_LONG).show()
})

ordersUnderUserVM.noTickets
Expand All @@ -102,8 +107,11 @@ 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(
CoordinatorLayout, "You need to log in first!", Snackbar.LENGTH_SHORT).show()
Handler().postDelayed({
redirectToLogin()
}, 500)
}

return rootView
Expand Down