Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package org.fossasia.openevent.general.auth
import android.Manifest
import android.app.Activity
import android.arch.lifecycle.Observer
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
Expand All @@ -24,6 +22,8 @@ import kotlinx.android.synthetic.main.fragment_edit_profile.view.*
import org.fossasia.openevent.general.CircleTransform
import org.fossasia.openevent.general.R
import org.fossasia.openevent.general.utils.Utils
import org.fossasia.openevent.general.utils.Utils.hideSoftKeyboard
import org.fossasia.openevent.general.utils.nullToEmpty
import org.koin.android.architecture.ext.viewModel
import timber.log.Timber
import java.io.ByteArrayOutputStream
Expand All @@ -33,6 +33,7 @@ import java.io.InputStream

class EditProfileFragment : Fragment() {

private val profileFragmentViewModel by viewModel<ProfileFragmentViewModel>()
private val editProfileViewModel by viewModel<EditProfileViewModel>()
private lateinit var rootView: View
private var permissionGranted = false
Expand All @@ -44,6 +45,16 @@ class EditProfileFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
rootView = inflater.inflate(R.layout.fragment_edit_profile, container, false)

profileFragmentViewModel.user.observe(this, Observer {
it?.let {
val userFirstName = it.firstName.nullToEmpty()
val userLastName = it.lastName.nullToEmpty()
rootView.firstName.setText(userFirstName)
rootView.lastName.setText(userLastName)
}
})
profileFragmentViewModel.fetchProfile()

editProfileViewModel.progress.observe(this, Observer {
it?.let {
Utils.showProgressBar(rootView.progressBar, it)
Expand All @@ -59,6 +70,7 @@ class EditProfileFragment : Fragment() {
}

rootView.buttonUpdate.setOnClickListener {
hideSoftKeyboard(context, rootView)
editProfileViewModel.updateProfile(encodedImage, rootView.firstName.text.toString(), rootView.lastName.text.toString())
}

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

import android.arch.lifecycle.Observer
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
Expand All @@ -10,7 +9,6 @@ import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import kotlinx.android.synthetic.main.fragment_login.*
import kotlinx.android.synthetic.main.fragment_login.view.*
Expand All @@ -20,6 +18,7 @@ import org.fossasia.openevent.general.order.LAUNCH_TICKETS
import org.fossasia.openevent.general.ticket.EVENT_ID
import org.fossasia.openevent.general.ticket.TICKET_ID_AND_QTY
import org.fossasia.openevent.general.utils.Utils
import org.fossasia.openevent.general.utils.Utils.hideSoftKeyboard
import org.koin.android.architecture.ext.viewModel

const val LAUNCH_ATTENDEE: String = "LAUNCH_ATTENDEE"
Expand Down Expand Up @@ -50,7 +49,7 @@ class LoginFragment : Fragment() {

rootView.loginButton.setOnClickListener {
loginActivityViewModel.login(email.text.toString(), password.text.toString())
hideSoftKeyboard()
hideSoftKeyboard(context, rootView)
}

loginActivityViewModel.progress.observe(this, Observer {
Expand Down Expand Up @@ -110,11 +109,6 @@ class LoginFragment : Fragment() {
return rootView
}

private fun hideSoftKeyboard() {
val inputManager: InputMethodManager = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.hideSoftInputFromWindow(view?.windowToken, InputMethodManager.SHOW_FORCED)
}

private fun redirectToMain(bundle: Bundle?) {
val intent = Intent(activity, MainActivity::class.java)
if (bundle != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.fossasia.openevent.general.utils

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.graphics.BitmapFactory
import android.net.Uri
import android.support.customtabs.CustomTabsIntent
import android.support.v4.content.ContextCompat
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.ProgressBar
import org.fossasia.openevent.general.R

Expand Down Expand Up @@ -38,4 +38,9 @@ object Utils {
.setPositiveButton(context?.resources?.getString(R.string.ok)) { dialog, _ -> dialog.cancel() }
builder.show()
}

fun hideSoftKeyboard(context: Context?, view: View) {
val inputManager: InputMethodManager = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal Please review.

inputManager.hideSoftInputFromWindow(view.windowToken, InputMethodManager.SHOW_FORCED)
}
}