Skip to content
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ abstract class ActivityBuildersModule {

@AuthScope
@ContributesAndroidInjector(
modules = arrayOf(AuthModule::class, AuthFragmentBuildersModule::class, AuthViewModelModule::class)
modules = [AuthModule::class, AuthFragmentBuildersModule::class, AuthViewModelModule::class]
)
abstract fun contributeAuthActivity(): AuthActivity

@MainScope
@ContributesAndroidInjector(
modules = arrayOf(MainModule::class, MainFragmentBuildersModule::class, MainViewModelModule::class)
modules = [MainModule::class, MainFragmentBuildersModule::class, MainViewModelModule::class]
)
abstract fun contributeMainActivity(): MainActivity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.widget.Toast
import com.afollestad.materialdialogs.MaterialDialog
import com.codingwithmitch.openapi.R
import com.codingwithmitch.openapi.session.SessionManager
import com.codingwithmitch.openapi.util.displayToast
import dagger.android.support.DaggerAppCompatActivity
import javax.inject.Inject

Expand Down Expand Up @@ -153,9 +154,10 @@ abstract class BaseActivity : DaggerAppCompatActivity(),
}
}

private fun displayToast(message: String?){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
//Using kotlin extention for toast aka dsl
// private fun displayTost(message: String?){
// Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
// }

override fun hideSoftKeyboard() {
if (currentFocus != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders

import com.codingwithmitch.openapi.R
import com.codingwithmitch.openapi.viewmodels.ViewModelProviderFactory
import dagger.android.support.DaggerFragment
import com.codingwithmitch.openapi.ui.auth.state.AuthStateEvent.*
import com.codingwithmitch.openapi.ui.auth.state.LoginFields
import kotlinx.android.synthetic.main.fragment_login.*
import javax.inject.Inject


class LoginFragment : BaseAuthFragment() {
class LoginFragment : DaggerFragment() {

@Inject
lateinit var providerFactory: ViewModelProviderFactory

lateinit var viewModel: AuthViewModel



// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// viewModel = activity?.run {
// ViewModelProviders.of(this, providerFactory).get(AuthViewModel::class.java)
// }?: throw Exception("Invalid Activity")
// }
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -27,11 +43,8 @@ class LoginFragment : BaseAuthFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<Button>(R.id.login_button).setOnClickListener {
login()
}

viewModel= ViewModelProviders.of(this, providerFactory).get(AuthViewModel::class.java)
login_button.setOnClickListener { login() }
subscribeObservers()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class RegisterFragment : BaseAuthFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<Button>(R.id.register_button).setOnClickListener {
register()
}
register_button.setOnClickListener { register() }
subscribeObservers()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class MainActivity : BaseActivity(),
setupActionBar()
Log.d(TAG, "MainActivity: onCreate: called.")

bottomNavController.setNavGraphProvider(this)
bottomNavController.setNavGraphChangeListener(this)
bottomNavController.apply {
setNavGraphProvider(this@MainActivity)
setNavGraphChangeListener(this@MainActivity)
}
bottomNavigationView.setUpNavigation(bottomNavController)
if (savedInstanceState == null) {
bottomNavController.onNavigationItemSelected()
Expand Down Expand Up @@ -82,8 +84,7 @@ class MainActivity : BaseActivity(),
}

private fun setupActionBar(){
val toolbar = findViewById<Toolbar>(R.id.tool_bar)
setSupportActionBar(toolbar)
setSupportActionBar(tool_bar)
}

override fun getNavGraphId(itemId: Int) = when (itemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ sealed class GenericApiResponse<T> {

if(response.isSuccessful){
val body = response.body()
if (body == null || response.code() == 204) {
return ApiEmptyResponse()
}
else if(response.code() == 401){
return ApiErrorResponse("401 Unauthorized. Token may be invalid.")
}
else {
return ApiSuccessResponse(body = body)
return if (body == null || response.code() == 204) {
ApiEmptyResponse()
} else if(response.code() == 401){
ApiErrorResponse("401 Unauthorized. Token may be invalid.")
} else {
ApiSuccessResponse(body = body)
}
}
else{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codingwithmitch.openapi.util

import android.content.Context
import android.widget.Toast
import androidx.annotation.StringRes


fun Context.displayToast(@StringRes message:Int){
Toast.makeText(this,message,Toast.LENGTH_LONG).show()
}

fun Context.displayToast(message:String){
Toast.makeText(this,message,Toast.LENGTH_LONG).show()
}