diff --git a/desk360/build.gradle b/desk360/build.gradle index 1869937..eddd5d8 100644 --- a/desk360/build.gradle +++ b/desk360/build.gradle @@ -76,7 +76,7 @@ dependencies { implementation 'io.reactivex.rxjava2:rxjava:2.2.14' implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.1.0-alpha01' + implementation 'com.google.android.material:material:1.2.0-alpha02' } diff --git a/desk360/src/main/java/com/teknasyon/desk360/view/fragment/Desk360AddNewTicketFragment.kt b/desk360/src/main/java/com/teknasyon/desk360/view/fragment/Desk360AddNewTicketFragment.kt index 2ca30fe..e5edef1 100644 --- a/desk360/src/main/java/com/teknasyon/desk360/view/fragment/Desk360AddNewTicketFragment.kt +++ b/desk360/src/main/java/com/teknasyon/desk360/view/fragment/Desk360AddNewTicketFragment.kt @@ -1,47 +1,74 @@ package com.teknasyon.desk360.view.fragment import android.content.Context.INPUT_METHOD_SERVICE +import android.content.res.ColorStateList +import android.graphics.Color +import android.graphics.PorterDuff +import android.graphics.drawable.Drawable +import android.graphics.drawable.GradientDrawable import android.os.Bundle -import android.text.method.ScrollingMovementMethod -import android.view.KeyEvent -import android.view.KeyEvent.* -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup +import android.text.Editable +import android.text.TextWatcher +import android.view.* +import android.view.KeyEvent.ACTION_UP +import android.view.KeyEvent.KEYCODE_DPAD_CENTER +import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.widget.AdapterView -import androidx.databinding.DataBindingUtil +import android.widget.LinearLayout +import android.widget.Spinner +import androidx.cardview.widget.CardView import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.NavOptions import androidx.navigation.Navigation +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout import com.teknasyon.desk360.R import com.teknasyon.desk360.databinding.Desk360AddNewTicketLayoutBinding +import com.teknasyon.desk360.helper.Desk360Config import com.teknasyon.desk360.helper.Desk360Constants +import com.teknasyon.desk360.model.Desk360TicketReq import com.teknasyon.desk360.model.Desk360Type +import com.teknasyon.desk360.modelv2.Desk360ScreenCreate import com.teknasyon.desk360.view.adapter.Desk360SupportTypeAdapter import com.teknasyon.desk360.viewmodel.AddNewTicketViewModel - +import kotlinx.android.synthetic.main.desk360_add_new_ticket_layout.view.* +import java.util.regex.Pattern /** * Created by seyfullah on 30,May,2019 * */ - open class Desk360AddNewTicketFragment : Fragment() { - private var viewModel: AddNewTicketViewModel? = null - - private var binding: Desk360AddNewTicketLayoutBinding? = null + private var nameField: TextInputEditText? = null + private var eMailField: TextInputEditText? = null + private var messageField: TextInputEditText? = null + private var subjectTypeSpinner: Spinner? = null + private lateinit var binding: Desk360AddNewTicketLayoutBinding private var typeList: ArrayList? = null + private val editTextStyleModel = + Desk360Config.instance.getDesk360Preferences()?.types?.data?.create_screen private var selectedTypeId: Int = 1 + //Validate variables + private var nameData: String? = null + private var emailData: String? = null + private var messageData: String? = null + private var messageLength: Int = 0 + private var nameFieldFill: Boolean = false + private var emailFieldFill: Boolean = false + private var messageFieldFill: Boolean = false + private val rootParamsLayout = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) private var observer = Observer> { - binding?.loadingProgress?.visibility = View.GONE + binding.loadingProgress?.visibility = View.GONE if (it != null) { typeList = it - val listOfType: ArrayList = arrayListOf() for (i in 0 until it.size) { listOfType.add(it[i].title.toString()) @@ -54,62 +81,40 @@ open class Desk360AddNewTicketFragment : Fragment() { listOfType ) } - binding?.subjectType?.adapter = myAdapter + subjectTypeSpinner?.adapter = myAdapter } } - private var observerName = Observer { - if (it != null) { - if (!it) { - binding?.nameEditText!!.isEnabled = true - binding?.nameEditText!!.requestFocus() - binding?.nameEditText!!.onKeyUp( - KEYCODE_DPAD_CENTER, - KeyEvent(ACTION_UP, KEYCODE_DPAD_CENTER) - ) - } - } + private fun observerName() { + nameField?.isEnabled = true + nameField?.requestFocus() + nameField?.onKeyUp( + KEYCODE_DPAD_CENTER, + KeyEvent(ACTION_UP, KEYCODE_DPAD_CENTER) + ) } - private var observerEMail = Observer { - it?.let { - if (!it) { - binding?.emailEditText!!.isEnabled = true - binding?.emailEditText!!.requestFocus() - binding?.emailEditText!!.onKeyUp( - KEYCODE_DPAD_CENTER, - KeyEvent(ACTION_UP, KEYCODE_DPAD_CENTER) - ) - } - } + private fun observerEMail() { + eMailField?.isEnabled = true + eMailField?.requestFocus() + eMailField?.onKeyUp( + KEYCODE_DPAD_CENTER, + KeyEvent(ACTION_UP, KEYCODE_DPAD_CENTER) + ) } - private var observerMessage = Observer { - if (it != null) { - when (Desk360Constants.currentTheme) { - 1, 4 -> { - setMessageTextTypeTwo(it) - } - 2, 3, 5 -> { - setMessageTextTypeOne(it) - } - else -> { - setMessageTextTypeTwo(it) - } - } - } + private fun observerMessage() { + messageField?.isEnabled = true + messageField?.requestFocus() + messageField?.onKeyUp( + KEYCODE_DPAD_CENTER, + KeyEvent(ACTION_UP, KEYCODE_DPAD_CENTER) + ) } private var observerAddedTicket = Observer { if (it != null) { view?.let { it1 -> -// RxBus.publish("backButtonActionKey") -// Navigation -// .findNavController(it1) -// .navigateUp() -// Navigation -// .findNavController(it1) -// .navigateUp() Navigation.findNavController(it1) .navigate( R.id.action_addNewTicketFragment_to_thanksFragment, @@ -117,7 +122,6 @@ open class Desk360AddNewTicketFragment : Fragment() { NavOptions.Builder().setPopUpTo(R.id.addNewTicketFragment, true).build() ) } - val imm = activity?.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager imm.hideSoftInputFromWindow(view!!.windowToken, 0) } @@ -128,31 +132,25 @@ open class Desk360AddNewTicketFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = - DataBindingUtil.inflate( - inflater, - com.teknasyon.desk360.R.layout.desk360_add_new_ticket_layout, - container, - false - ) - - return binding?.root + Desk360AddNewTicketLayoutBinding.inflate(inflater, container, false).also { + binding = it + binding.lifecycleOwner = viewLifecycleOwner + return it.root + } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewModel = AddNewTicketViewModel() viewModel?.typeList?.observe(this, observer) - viewModel?.nameFieldFill?.observe(this, observerName) - viewModel?.emailFieldFill?.observe(this, observerEMail) - viewModel?.messageFieldFill?.observe(this, observerMessage) viewModel?.addedTicket?.observe(this, observerAddedTicket) - binding?.subjectType?.prompt = "Gender" - binding?.subjectType?.onItemSelectedListener = +// binding.subjectType?.prompt = "Gender" + subjectTypeSpinner?.onItemSelectedListener = (object : AdapterView.OnItemSelectedListener { override fun onNothingSelected(parent: AdapterView<*>?) { } + override fun onItemSelected( parent: AdapterView<*>, view: View?, @@ -162,56 +160,117 @@ open class Desk360AddNewTicketFragment : Fragment() { typeList?.let { it[position].let { it1 -> selectedTypeId = it1.id!! } } } }) - - binding?.txtBottomFooterMessageForm?.movementMethod = ScrollingMovementMethod() - binding?.sendButton?.setOnClickListener { - viewModel?.validateAllField(selectedTypeId) +// binding.txtBottomFooterMessageForm?.movementMethod = ScrollingMovementMethod() + binding.createTicketButton?.setOnClickListener { + validateAllField(selectedTypeId) } + rootParamsLayout.setMargins(24, 24, 24, 24) + /** + * name filed + */ + nameField = createEditText("Name") + nameField?.setLines(1) + nameField?.setSingleLine(true) + nameField?.imeOptions = EditorInfo.IME_ACTION_NEXT + nameField?.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable) {} + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + } - binding?.viewModel = viewModel - } + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + nameQuality(s) + } + }) + /** + * email filed + */ + eMailField = createEditText("Email") + eMailField?.setLines(1) + eMailField?.setSingleLine(true) + eMailField?.imeOptions = EditorInfo.IME_ACTION_NEXT + eMailField?.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable) {} + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + } + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + emailQuality(s) + } + }) + /** + * subject filed + */ + subjectTypeSpinner = createSpinner() + /** + * message filed + */ + messageField = createEditText("Message", true) + messageField?.maxLines = 7 + messageField?.minLines = 6 + messageField?.imeOptions = EditorInfo.IME_ACTION_DONE + messageField?.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable) {} + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + } - private fun setMessageTextTypeTwo(it: Boolean) { - binding?.messageEditTextType1!!.isClickable = false - if (!it) { - binding?.messageEditTextType2!!.isEnabled = true - binding?.messageEditTextType2!!.requestFocus() - binding?.messageEditTextType2?.onKeyUp( - KEYCODE_DPAD_UP, KeyEvent(ACTION_UP, KEYCODE_DPAD_UP) - ) - } - binding?.messageEditTextType2?.setOnFocusChangeListener { _, hasFocus -> - if (hasFocus) { - binding?.baseLayout?.bottom?.let { it1 -> - binding?.baseLayout?.scrollTo( - 0, - it1 - ) - } + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + messageQuality(s) } - } + }) + messageField?.gravity = Gravity.TOP + binding.viewModel = viewModel } - private fun setMessageTextTypeOne(it: Boolean) { - binding?.messageEditTextType2!!.isClickable = false - if (!it) { - binding?.messageEditTextType1!!.isEnabled = true - binding?.messageEditTextType1!!.requestFocus() - binding?.messageEditTextType1?.onKeyUp( - KEYCODE_DPAD_UP, KeyEvent(ACTION_UP, KEYCODE_DPAD_UP) - ) + private fun createEditText(hintText: String, isMessage: Boolean = false): TextInputEditText? { + if (context == null) + return null + val textInputLayout = TextInputLayout(context!!) + textInputLayout.hint = hintText + textInputLayout.layoutParams = rootParamsLayout + textInputLayout.gravity = Gravity.CENTER_VERTICAL + editTextStyleModel?.let { textInputLayout.setDesk360InputStyle(it) } + if (editTextStyleModel!!.form_style_id == 1 && isMessage) { + textInputLayout.setPadding(24, 8, 24, 8) + textInputLayout.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_OUTLINE } - binding?.messageEditTextType1?.setOnFocusChangeListener { _, hasFocus -> - if (hasFocus) { - binding?.baseLayout?.bottom?.let { it1 -> - binding?.baseLayout?.scrollTo( - 0, - it1 - ) - } + val textInputEditText = TextInputEditText(context) + textInputEditText.setDesk360InputStyle(editTextStyleModel) + textInputLayout.addView(textInputEditText) + if (editTextStyleModel.form_style_id == 3) { + val cardView = CardView(context!!) + cardView.layoutParams = rootParamsLayout + cardView.setDesk360CardViewStyle() + cardView.addView(textInputLayout) + binding.root.create_screen_root_view.addView(cardView) + } else { + binding.root.create_screen_root_view.addView(textInputLayout) + } + return textInputEditText + } + + private fun createSpinner(): Spinner? { + if (context == null) + return null + val textInputLayoutSpinner = TextInputLayout(context!!) + textInputLayoutSpinner.layoutParams = rootParamsLayout + textInputLayoutSpinner.gravity = Gravity.CENTER_VERTICAL + val spinner = Spinner(context) + editTextStyleModel?.let { spinner.setDesk360SpinnerStyle(it) } + textInputLayoutSpinner.addView(spinner) + when (editTextStyleModel?.form_style_id) { + 3 -> { + val cardView = CardView(context!!) + cardView.layoutParams = rootParamsLayout + cardView.setDesk360CardViewStyle() + cardView.addView(textInputLayoutSpinner) + binding.root.create_screen_root_view.addView(cardView) + } + 2 -> { + binding.root.create_screen_root_view.addView(textInputLayoutSpinner) } + else -> binding.root.create_screen_root_view.addView(textInputLayoutSpinner) } + return spinner } override fun onDestroy() { @@ -219,12 +278,183 @@ open class Desk360AddNewTicketFragment : Fragment() { viewModel?.let { with(viewModel!!) { typeList?.removeObserver(observer) - nameFieldFill.removeObserver(observerName) - emailFieldFill.removeObserver(observerEMail) -// subjectFieldFill.removeObserver(observerSubject) - messageFieldFill.removeObserver(observerMessage) +// subjectFieldFill.removeObserver(observerSubject) addedTicket.removeObserver(observerAddedTicket) } } } + + fun nameQuality(s: CharSequence) { + nameData = s.toString().trim() + nameFieldFill = + when { + s.isEmpty() -> { + false + } + else -> { + true + } + } + } + + fun emailQuality(s: CharSequence) { + emailData = s.toString().trim() + emailFieldFill = + when { + s.isEmpty() -> false + !checkEmail(email = s.toString()) -> false + else -> { + true + } + } + } + + fun messageQuality(s: CharSequence) { + messageData = s.toString().trim() + messageLength = messageData!!.length + messageFieldFill = + when { + s.isEmpty() -> false + s.length < 3 -> false + else -> { + true + } + } + } + + private fun checkEmail(email: String): Boolean { + return EMAIL_ADDRESS_PATTERN.matcher(email).matches() + } + + val EMAIL_ADDRESS_PATTERN = Pattern.compile( + "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + + "\\@" + + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + + "(" + + "\\." + + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + + ")+" + ) + + private fun validateAllField(selectedTypeId: Int) { + val ticketItem = Desk360TicketReq() + if (nameFieldFill && emailFieldFill && messageLength > 0) { + ticketItem.email = emailData + ticketItem.name = nameData +// ticketItem.subject = subjectData + ticketItem.message = messageData + ticketItem.type_id = selectedTypeId.toString() + ticketItem.source = "App" + ticketItem.platform = "Android" + ticketItem.country_code = Desk360Constants.countryCode() + viewModel?.addSupportTicket(ticketItem) + } else when { + !nameFieldFill -> { + nameFieldFill = false + observerName() + } + !emailFieldFill -> { + emailFieldFill = false + observerEMail() + } + messageLength <= 0 -> { + messageFieldFill = false + observerMessage() + } + } + } +} + +fun CardView.setDesk360CardViewStyle() { + this.cardElevation = 20f + this.radius = 8f +} + +fun TextInputLayout.setDesk360InputStyle(style: Desk360ScreenCreate) { + val states = arrayOf( + intArrayOf(android.R.attr.state_focused), + intArrayOf(android.R.attr.state_hovered), + intArrayOf(android.R.attr.state_enabled), + intArrayOf() + ) + val colors = intArrayOf( + Color.parseColor(style.form_input_focus_border_color), + Color.parseColor(style.form_input_border_color), + Color.parseColor(style.form_input_focus_border_color), + Color.parseColor(style.form_input_border_color) + ) + val colorsHint = intArrayOf( + Color.parseColor(style.label_text_color), + Color.parseColor(style.form_input_border_color), + Color.parseColor(style.form_input_border_color), + Color.parseColor(style.label_text_color) + ) + val defaultHintColors = intArrayOf( + Color.parseColor(style.form_input_color), + Color.parseColor(style.form_input_color), + Color.parseColor(style.form_input_color), + Color.parseColor(style.form_input_color) + ) + val myColorList = ColorStateList(states, colors) + val myColorListDefault = ColorStateList(states, defaultHintColors) + val myColorListHint = ColorStateList(states, colorsHint) + this.setBoxStrokeColorStateList(myColorList) + this.defaultHintTextColor = myColorListDefault + this.hintTextColor = myColorListHint + this.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_NONE + when (style.form_style_id) { + 1 -> { + //line + this.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_NONE + } + 2 -> { + //box + this.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_OUTLINE + } + else -> { + //shadow + this.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_NONE + } + } +} + +fun TextInputEditText.setDesk360InputStyle(style: Desk360ScreenCreate) { + val drawable: Drawable = this.background + this.setTextColor(Color.parseColor(style.form_input_focus_color)) + when (style.form_style_id) { + 1 -> { + //line + drawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP) + } + 2 -> { + //box + this.background = null + this.setPadding(24, 24, 24, 24) + } + else -> { + //shadow + this.background = null + } + } +} + +fun Spinner.setDesk360SpinnerStyle(style: Desk360ScreenCreate) { + this.setPadding(24, 20, 24, 20) + when (style.form_style_id) { + 1 -> { + //line + } + 2 -> { + val gd = GradientDrawable() + gd.setColor(Color.TRANSPARENT) + gd.cornerRadius = 8f + gd.setStroke(3, Color.parseColor(style.form_input_focus_border_color)) + this.background = gd + //box + } + else -> { + //shadow + } + } + this.isActivated = style.added_file_is_hidden } \ No newline at end of file diff --git a/desk360/src/main/java/com/teknasyon/desk360/view/fragment/ExampleFragment.kt b/desk360/src/main/java/com/teknasyon/desk360/view/fragment/ExampleFragment.kt deleted file mode 100644 index eb1d67b..0000000 --- a/desk360/src/main/java/com/teknasyon/desk360/view/fragment/ExampleFragment.kt +++ /dev/null @@ -1,379 +0,0 @@ -package com.teknasyon.desk360.view.fragment - - -import android.content.Context -import android.content.res.ColorStateList -import android.graphics.Color -import android.graphics.Paint -import android.graphics.PorterDuff -import android.graphics.drawable.ShapeDrawable -import android.graphics.drawable.shapes.RectShape -import android.os.Bundle -import android.text.method.ScrollingMovementMethod -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.* -import androidx.cardview.widget.CardView -import androidx.fragment.app.Fragment -import com.google.android.material.textfield.TextInputLayout -import com.teknasyon.desk360.R -import com.teknasyon.desk360.databinding.FragmentExampleBinding -import com.teknasyon.desk360.helper.Desk360CustomStyle -import com.teknasyon.desk360.helper.Desk360Constants -import kotlinx.android.synthetic.main.fragment_example.view.* - -class ExampleFragment : Fragment() { - private val type = 3 - private lateinit var binding: FragmentExampleBinding - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - FragmentExampleBinding.inflate(inflater, container, false).also { - binding = it - binding.lifecycleOwner = viewLifecycleOwner - return it.root - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.textFooterCreateTicketScreen.movementMethod = ScrollingMovementMethod() - Desk360CustomStyle.setStyle( - Desk360Constants.currentType?.data?.create_pre_screen?.button_style_id, - binding.createTicketButton, - context!! - ) - binding.createScreenButtonIcon.setImageResource(R.drawable.zarf) - binding.createScreenButtonIcon.setColorFilter( - Color.parseColor(Desk360Constants.currentType?.data?.create_pre_screen?.button_text_color), - PorterDuff.Mode.SRC_ATOP - ) - val rootParamsLayout = LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT - ) - rootParamsLayout.setMargins(24, 24, 24, 24) - - //field email - - for (i in 0..0) { - val textInputLayoutEmail = TextInputLayout(context) - textInputLayoutEmail.layoutParams = rootParamsLayout - textInputLayoutEmail.gravity = Gravity.CENTER_VERTICAL - - textInputLayoutEmail.setDesk360InputStyle(InputLayoutStyle(), type) - - val editTexEmail = EditText(context) - editTexEmail.setDesk360EditTextStyle(EditTextStyle(), type) - textInputLayoutEmail.addView(editTexEmail) - - if (type == 3) { - val cardView = CardView(context!!) - cardView.layoutParams = rootParamsLayout - cardView.setDesk360CardViewStyle() - cardView.addView(textInputLayoutEmail) - binding.root.root_layout_ticket_create.addView(cardView) - } else { - binding.root.root_layout_ticket_create.addView(textInputLayoutEmail) - } - } - - for (i in 0..0) { - val textInputLayoutSpinner = TextInputLayout(context) - textInputLayoutSpinner.layoutParams = rootParamsLayout - textInputLayoutSpinner.gravity = Gravity.CENTER_VERTICAL - - textInputLayoutSpinner.setDesk360InputStyle(InputLayoutStyle(), type) - - val spinner = Spinner(context) - spinner.setDesk360SpinnerStyle(SpinnerStyle(), type) - textInputLayoutSpinner.addView(spinner) - - if (type == 3) { - val cardView = CardView(context!!) - cardView.layoutParams = rootParamsLayout - cardView.setDesk360CardViewStyle() - cardView.addView(textInputLayoutSpinner) - binding.root.root_layout_ticket_create.addView(cardView) - } else { - binding.root.root_layout_ticket_create.addView(textInputLayoutSpinner) - } - } - -// for (i in 0..0) { -// val spinner = Spinner(context) -// spinner.layoutParams = rootParamsLayout -// spinner.gravity = Gravity.CENTER_VERTICAL -// -// val spinnerArray = ArrayList() -// spinnerArray.add("Seciniz..") -// spinnerArray.add("two") -// spinnerArray.add("three") -// spinnerArray.add("four") -// spinnerArray.add("five") -// -// -// -// val spinnerArrayAdapter = -// ArrayAdapter(context, R.layout.dropdown_new, spinnerArray) -// -// spinner.adapter = spinnerArrayAdapter -// -// -// spinner.setDesk360SpinnerStyle(SpinnerStyle()) -// -// if (type == 2) { -// val cardViewSpinner = CardView(context!!) -// cardViewSpinner.layoutParams = rootParamsLayout -// cardViewSpinner.setDesk360SpinnerCardViewStyle() -// spinner.setPadding(24,24,24,24) -// cardViewSpinner.addView(spinner) -// binding.root.root_layout_ticket_create.addView(cardViewSpinner) -// } else { -// spinner.setPadding(24,8,24,0) -// val underLine = View(context) -// underLine.minimumHeight=5 -// underLine.setBackgroundColor(Color.parseColor("#000000")) -// binding.root.root_layout_ticket_create.addView(spinner) -// binding.root.root_layout_ticket_create.addView(underLine) -// } -// } - - - - for (i in 0..1) { - val messageStyleId = 3 - - when (messageStyleId) { - in listOf(1, 4) -> setMessageStyle( - context, - rootParamsLayout, - binding.root.root_layout_ticket_create, 2 - ) - in listOf(3, 5) -> setMessageStyle( - context, - rootParamsLayout, - binding.root.root_layout_ticket_create, 3 - ) - else -> setMessageStyle( - context, - rootParamsLayout, - binding.root.root_layout_ticket_create, 1 - - ) - } - } - - } - -} - - -//--------------------------------------------------------- -//INPUT STYLE -//--------------------------------------------------------- - - -class InputLayoutStyle { - var input_layout_email_hint_text: String = "Email" - var input_layout_email_hint_unactive_color: String = "#cecece" - var input_layout_email_radius: Int = 10 - var input_layout_email_style_id: Int = 1 - var input_layout_email_border_color: String = "#58b0fa" - -} - - -fun TextInputLayout.setDesk360InputStyle(style: InputLayoutStyle, type: Int) { - if (type == 3) { - this.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_NONE) - } else { - this.setBoxBackgroundMode(style.input_layout_email_style_id.textInputLayoutBoxMode()) - this.boxStrokeColor = Color.parseColor(style.input_layout_email_border_color) - } - - this.hint = style.input_layout_email_hint_text - val textInputLayoutEmailStates = arrayOf(intArrayOf()) - val textInputLayoutEmailColors = - intArrayOf(Color.parseColor(style.input_layout_email_hint_unactive_color)) - this.defaultHintTextColor = - ColorStateList(textInputLayoutEmailStates, textInputLayoutEmailColors) - this.setBoxCornerRadii( - style.input_layout_email_radius.toFloat(), - style.input_layout_email_radius.toFloat(), - style.input_layout_email_radius.toFloat(), - style.input_layout_email_radius.toFloat() - ) - -} - -class EditTextStyle { - var edit_text_email_text_color: String = "#000000" - var edit_text_email_text_size: Int = 18 - var edit_text_email_text_weight: Int = 400 -} - - -fun EditText.setDesk360EditTextStyle(style: EditTextStyle, type: Int) { - if (type == 3) { - this.background = null - this.setPadding(16, 16, 16, 16) - } else { - this.setPadding(48, 48, 48, 48) - } - - this.setTextColor(Color.parseColor(style.edit_text_email_text_color)) - this.textSize = style.edit_text_email_text_size.toFloat() - - -} - - -fun CardView.setDesk360CardViewStyle() { - this.cardElevation = 20f - this.radius = 4f -} - - -fun Int.textInputLayoutBoxMode(): Int { - - return if (this == 2) { - TextInputLayout.BOX_BACKGROUND_OUTLINE - - } else { - TextInputLayout.BOX_BACKGROUND_NONE - - } -} -//--------------------------------------------------------- -//INPUT STYLE -//--------------------------------------------------------- - -class SpinnerStyle { - var button_text_font_weight: Int = 600 - var added_file_is_hidden: Boolean = false - var padding: Int = 16 -} - -fun Spinner.setDesk360SpinnerStyle( - style: SpinnerStyle, - type: Int -) { - - if (type == 3) { - this.background = null - this.setPadding(16, 16, 16, 16) - } else { - this.setPadding(48, 48, 48, 48) - } - - this.isActivated = style.added_file_is_hidden - this.setPadding(style.padding, style.padding, style.padding, style.padding) -} - -fun CardView.setDesk360SpinnerCardViewStyle() { - this.cardElevation = 20f - this.radius = 4f -} - - - -//--------------------------------------------------------- -//MESSAGE TYPES -//--------------------------------------------------------- - -fun setMessageStyle( - context: Context?, - rootParamsLayout: LinearLayout.LayoutParams, - rootLayout: LinearLayout, - style: Int - -) { - - when (style) { - 1 -> { - val inputMessage = TextInputLayout(context) - inputMessage.layoutParams = rootParamsLayout - inputMessage.gravity = Gravity.CENTER_VERTICAL - inputMessage.hint = "Mesajınız" - - val statesMessage = arrayOf(intArrayOf()) - val colorsMessage = intArrayOf(Color.parseColor("#cecece")) - inputMessage.defaultHintTextColor = ColorStateList(statesMessage, colorsMessage) - - inputMessage.setBoxCornerRadii(10f, 10f, 10f, 10f) - - inputMessage.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_OUTLINE) - inputMessage.boxStrokeColor = Color.parseColor("#58b0fa") - - rootLayout.addView(inputMessage) - - - val editMessage = EditText(context) - editMessage.minLines = 6 - editMessage.maxLines = 7 - editMessage.gravity = Gravity.START - editMessage.setPadding(50, 50, 50, 50) - editMessage.setTextColor(Color.BLACK) - inputMessage.addView(editMessage) - } - 2 -> { - val messageLayout = LinearLayout(context) - messageLayout.layoutParams = rootParamsLayout - messageLayout.orientation = LinearLayout.VERTICAL - messageLayout.gravity = Gravity.CENTER_VERTICAL - rootLayout.addView(messageLayout) - - val hintTextMessage = TextView(context) - hintTextMessage.text = "Mesajınız" - hintTextMessage.setPadding(0, 0, 0, 24) - hintTextMessage.setTextColor(Color.GRAY) - - - messageLayout.addView(hintTextMessage) - - val shape = ShapeDrawable(RectShape()) - shape.paint.color = Color.GRAY - shape.paint.style = Paint.Style.STROKE - shape.paint.strokeWidth = 3f - - val editMessage2 = EditText(context) - editMessage2.minLines = 6 - editMessage2.maxLines = 7 - editMessage2.background = shape - editMessage2.gravity = Gravity.START - editMessage2.setPadding(32, 32, 32, 32) - editMessage2.setTextColor(Color.BLACK) - messageLayout.addView(editMessage2) - - } - else -> { - val cardViewMessage = CardView(context!!) - cardViewMessage.layoutParams = rootParamsLayout - cardViewMessage.cardElevation = 20f - cardViewMessage.radius = 4f - rootLayout.addView(cardViewMessage) - - val inputMessageType2 = TextInputLayout(context) - inputMessageType2.hint = "Mesajınız" - inputMessageType2.setBoxBackgroundMode(TextInputLayout.BOX_BACKGROUND_NONE) - inputMessageType2.setPadding(24, 16, 24, 8) - cardViewMessage.addView(inputMessageType2) - - val editMessageType2 = EditText(context) - editMessageType2.setTextColor(Color.BLACK) - editMessageType2.background = null - editMessageType2.minLines = 6 - editMessageType2.gravity = Gravity.START - editMessageType2.maxLines = 7 - inputMessageType2.addView(editMessageType2) - } - } - -} - - diff --git a/desk360/src/main/java/com/teknasyon/desk360/viewmodel/AddNewTicketViewModel.kt b/desk360/src/main/java/com/teknasyon/desk360/viewmodel/AddNewTicketViewModel.kt index e0916ce..26539a7 100644 --- a/desk360/src/main/java/com/teknasyon/desk360/viewmodel/AddNewTicketViewModel.kt +++ b/desk360/src/main/java/com/teknasyon/desk360/viewmodel/AddNewTicketViewModel.kt @@ -1,20 +1,15 @@ package com.teknasyon.desk360.viewmodel -import androidx.databinding.BaseObservable -import androidx.databinding.Bindable import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.teknasyon.desk360.BR import com.teknasyon.desk360.connection.BaseCallback import com.teknasyon.desk360.connection.Desk360RetrofitFactory -import com.teknasyon.desk360.helper.Desk360Constants import com.teknasyon.desk360.model.Desk360NewSupportResponse import com.teknasyon.desk360.model.Desk360TicketReq import com.teknasyon.desk360.model.Desk360Type import com.teknasyon.desk360.model.Desk360TypeResponse import retrofit2.Call import retrofit2.Response -import java.util.regex.Pattern /** * Created by seyfullah on 30,May,2019 @@ -24,23 +19,8 @@ import java.util.regex.Pattern open class AddNewTicketViewModel : ViewModel() { var typeList: MutableLiveData>? = MutableLiveData() var addedTicket: MutableLiveData = MutableLiveData() - private val ticketItem = Desk360TicketReq() - - var observable = NewSupportObservable() - val nameFieldFill: MutableLiveData = MutableLiveData() - val emailFieldFill: MutableLiveData = MutableLiveData() - var messageFieldFill: MutableLiveData = MutableLiveData() - - var nameData: String? = null - var emailData: String? = null - var messageData: String? = null - var messageLength: Int = 0 init { - messageFieldFill.postValue(false) - emailFieldFill.postValue(false) - nameFieldFill.postValue(false) - getTypeList() } @@ -60,7 +40,7 @@ open class AddNewTicketViewModel : ViewModel() { }) } - private fun addSupportTicket() { + fun addSupportTicket(ticketItem: Desk360TicketReq) { Desk360RetrofitFactory.instance.httpService.addTicket(ticketItem) .enqueue(object : BaseCallback() { override fun onResponseSuccess( @@ -73,103 +53,7 @@ open class AddNewTicketViewModel : ViewModel() { } else { addedTicket.value = null } - } - }) - } - - fun validateAllField(selectedTypeId: Int) { - if (nameFieldFill.value == true && emailFieldFill.value == true && messageLength > 0) { - ticketItem.email = emailData - ticketItem.name = nameData -// ticketItem.subject = subjectData - ticketItem.message = messageData - ticketItem.type_id = selectedTypeId.toString() - ticketItem.source = "App" - ticketItem.platform = "Android" - ticketItem.country_code = Desk360Constants.countryCode() - addSupportTicket() - } else { - when { - nameFieldFill.value == false -> nameFieldFill.postValue(false) - emailFieldFill.value == false -> emailFieldFill.postValue(false) - messageLength <= 0 -> messageFieldFill.postValue(false) - } - } - } - - inner class NewSupportObservable : BaseObservable() { - - val messageLengthData: String? - @Bindable - get() = "$messageLength/350" - - fun nameQuality(s: CharSequence) { - nameData = s.toString() - nameFieldFill.postValue( - when { - s.isEmpty() -> { - false - } - else -> { - true - } } - ) - } - - fun emailQuality(s: CharSequence) { - emailData = s.toString() - emailFieldFill.postValue( - when { - s.isEmpty() -> false - !checkEmail(email = s.toString()) -> false - else -> { - true - } - } - ) - } - -// fun subjectQuality(s: CharSequence) { -// subjectData = s.toString() -// subjectFieldFill.postValue( -// when { -// s.isEmpty() -> false -// else -> { -// true -// } -// } -// ) -// } - - fun messageQuality(s: CharSequence) { - messageData = s.toString() - messageLength = messageData!!.length - notifyPropertyChanged(BR._all) - messageFieldFill.postValue( - when { - s.isEmpty() -> false - s.length < 3 -> false - else -> { - true - } - } - ) - } - - private fun checkEmail(email: String): Boolean { - return EMAIL_ADDRESS_PATTERN.matcher(email).matches() - } - - - val EMAIL_ADDRESS_PATTERN = Pattern.compile( - "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + - "\\@" + - "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + - "(" + - "\\." + - "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + - ")+" - ) + }) } } \ No newline at end of file diff --git a/desk360/src/main/res/drawable-hdpi/incoming_message_background_1.png b/desk360/src/main/res/drawable-hdpi/incoming_message_background_1.png new file mode 100644 index 0000000..741b52e Binary files /dev/null and b/desk360/src/main/res/drawable-hdpi/incoming_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-hdpi/incoming_message_background_2.png b/desk360/src/main/res/drawable-hdpi/incoming_message_background_2.png new file mode 100644 index 0000000..590bf8c Binary files /dev/null and b/desk360/src/main/res/drawable-hdpi/incoming_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-hdpi/incoming_message_background_4.png b/desk360/src/main/res/drawable-hdpi/incoming_message_background_4.png new file mode 100644 index 0000000..9b8a3eb Binary files /dev/null and b/desk360/src/main/res/drawable-hdpi/incoming_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-hdpi/sent_message_background_1.png b/desk360/src/main/res/drawable-hdpi/sent_message_background_1.png new file mode 100644 index 0000000..4179e38 Binary files /dev/null and b/desk360/src/main/res/drawable-hdpi/sent_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-hdpi/sent_message_background_2.png b/desk360/src/main/res/drawable-hdpi/sent_message_background_2.png new file mode 100644 index 0000000..34fa03a Binary files /dev/null and b/desk360/src/main/res/drawable-hdpi/sent_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-hdpi/sent_message_background_4.png b/desk360/src/main/res/drawable-hdpi/sent_message_background_4.png new file mode 100644 index 0000000..1fe2f6f Binary files /dev/null and b/desk360/src/main/res/drawable-hdpi/sent_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-mdpi/incoming_message_background_1.png b/desk360/src/main/res/drawable-mdpi/incoming_message_background_1.png new file mode 100644 index 0000000..bff11e6 Binary files /dev/null and b/desk360/src/main/res/drawable-mdpi/incoming_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-mdpi/incoming_message_background_2.png b/desk360/src/main/res/drawable-mdpi/incoming_message_background_2.png new file mode 100644 index 0000000..c5865f8 Binary files /dev/null and b/desk360/src/main/res/drawable-mdpi/incoming_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-mdpi/incoming_message_background_4.png b/desk360/src/main/res/drawable-mdpi/incoming_message_background_4.png new file mode 100644 index 0000000..7a3b465 Binary files /dev/null and b/desk360/src/main/res/drawable-mdpi/incoming_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-mdpi/sent_message_background_1.png b/desk360/src/main/res/drawable-mdpi/sent_message_background_1.png new file mode 100644 index 0000000..796f6f4 Binary files /dev/null and b/desk360/src/main/res/drawable-mdpi/sent_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-mdpi/sent_message_background_2.png b/desk360/src/main/res/drawable-mdpi/sent_message_background_2.png new file mode 100644 index 0000000..d25dea7 Binary files /dev/null and b/desk360/src/main/res/drawable-mdpi/sent_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-mdpi/sent_message_background_4.png b/desk360/src/main/res/drawable-mdpi/sent_message_background_4.png new file mode 100644 index 0000000..b0e11f4 Binary files /dev/null and b/desk360/src/main/res/drawable-mdpi/sent_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-xhdpi/incoming_message_background_1.png b/desk360/src/main/res/drawable-xhdpi/incoming_message_background_1.png new file mode 100644 index 0000000..2b95a1f Binary files /dev/null and b/desk360/src/main/res/drawable-xhdpi/incoming_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-xhdpi/incoming_message_background_2.png b/desk360/src/main/res/drawable-xhdpi/incoming_message_background_2.png new file mode 100644 index 0000000..cc2bb16 Binary files /dev/null and b/desk360/src/main/res/drawable-xhdpi/incoming_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-xhdpi/incoming_message_background_4.png b/desk360/src/main/res/drawable-xhdpi/incoming_message_background_4.png new file mode 100644 index 0000000..d9d8f7f Binary files /dev/null and b/desk360/src/main/res/drawable-xhdpi/incoming_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-xhdpi/sent_message_background_1.png b/desk360/src/main/res/drawable-xhdpi/sent_message_background_1.png new file mode 100644 index 0000000..f553394 Binary files /dev/null and b/desk360/src/main/res/drawable-xhdpi/sent_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-xhdpi/sent_message_background_2.png b/desk360/src/main/res/drawable-xhdpi/sent_message_background_2.png new file mode 100644 index 0000000..325e9ed Binary files /dev/null and b/desk360/src/main/res/drawable-xhdpi/sent_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-xhdpi/sent_message_background_4.png b/desk360/src/main/res/drawable-xhdpi/sent_message_background_4.png new file mode 100644 index 0000000..afba97a Binary files /dev/null and b/desk360/src/main/res/drawable-xhdpi/sent_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_1.png b/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_1.png new file mode 100644 index 0000000..a358650 Binary files /dev/null and b/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_2.png b/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_2.png new file mode 100644 index 0000000..181931c Binary files /dev/null and b/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_4.png b/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_4.png new file mode 100644 index 0000000..7a0f98d Binary files /dev/null and b/desk360/src/main/res/drawable-xxhdpi/incoming_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-xxhdpi/sent_message_background_1.png b/desk360/src/main/res/drawable-xxhdpi/sent_message_background_1.png new file mode 100644 index 0000000..22709e3 Binary files /dev/null and b/desk360/src/main/res/drawable-xxhdpi/sent_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-xxhdpi/sent_message_background_2.png b/desk360/src/main/res/drawable-xxhdpi/sent_message_background_2.png new file mode 100644 index 0000000..26c08f9 Binary files /dev/null and b/desk360/src/main/res/drawable-xxhdpi/sent_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-xxhdpi/sent_message_background_4.png b/desk360/src/main/res/drawable-xxhdpi/sent_message_background_4.png new file mode 100644 index 0000000..693fee9 Binary files /dev/null and b/desk360/src/main/res/drawable-xxhdpi/sent_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_1.png b/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_1.png new file mode 100644 index 0000000..032a1ac Binary files /dev/null and b/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_2.png b/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_2.png new file mode 100644 index 0000000..e52b9e9 Binary files /dev/null and b/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_4.png b/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_4.png new file mode 100644 index 0000000..a3fa9b7 Binary files /dev/null and b/desk360/src/main/res/drawable-xxxhdpi/incoming_message_background_4.png differ diff --git a/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_1.png b/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_1.png new file mode 100644 index 0000000..78e3ab8 Binary files /dev/null and b/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_1.png differ diff --git a/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_2.png b/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_2.png new file mode 100644 index 0000000..0997526 Binary files /dev/null and b/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_2.png differ diff --git a/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_4.png b/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_4.png new file mode 100644 index 0000000..ccc818f Binary files /dev/null and b/desk360/src/main/res/drawable-xxxhdpi/sent_message_background_4.png differ diff --git a/desk360/src/main/res/layout/desk360_add_new_ticket_layout.xml b/desk360/src/main/res/layout/desk360_add_new_ticket_layout.xml index d170e2d..e237605 100644 --- a/desk360/src/main/res/layout/desk360_add_new_ticket_layout.xml +++ b/desk360/src/main/res/layout/desk360_add_new_ticket_layout.xml @@ -16,277 +16,113 @@ android:layout_height="match_parent" android:fillViewport="true"> - - - - - - - - + app:layout_constraintTop_toTopOf="parent" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toBottomOf="@+id/create_screen_root_view" + tools:ignore="MissingConstraints" /> + + + + app:layout_constraintTop_toBottomOf="@+id/create_screen_root_view" /> - - - + app:layout_constraintTop_toBottomOf="@+id/file_name_text_create_ticket_screen" + tools:text="Gönder"> + + + + + + + + + + - - - - - + tools:ignore="MissingConstraints,SmallSp" + tools:text="Destek mesajlarınız mesai saatleri içerisinde yanıtlar. Buraya buna benzer bir içerik mesajı ve alt kısa açıklama eklenir. Geliştirici istediği mesajı burada verebilir. Kullanılması zorunlu değildir. Destek mesajlarınız mesai saatleri içerisinde yanıtlar. Destek mesajlarınız mesai saatleri içerisinde yanıtlar. Buraya buna benzer bir içerik mesajı ve alt kısa açıklama eklenir. Geliştirici istediği mesajı burada verebilir. Kullanılması zorunlu değildir. Destek mesajlarınız mesai saatleri içerisinde yanıtlar. Destek mesajlarınız mesai saatleri içerisinde yanıtlar. Buraya buna benzer bir içerik mesajı ve alt kısa açıklama eklenir. Geliştirici istediği mesajı burada verebilir. Kullanılması zorunlu değildir. Destek mesajlarınız mesai saatleri içerisinde yanıtlar. " /> + + + + \ No newline at end of file