Skip to content

Commit

Permalink
Added Connected Device Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
fin1te committed Jul 26, 2023
1 parent e326564 commit 3bf274b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 15 deletions.
14 changes: 0 additions & 14 deletions app/src/main/java/com/finite/nearbuddy/ui/EditProfileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ class EditProfileFragment : Fragment() {
binding!!.programmingDropDownAutoComplete.setOnClickListener { closeKeyboard() }
binding!!.moviesDropDownAutoComplete.setOnClickListener { closeKeyboard() }

// close the keyboard when the user clicks outside the textinputlayout



binding?.saveChanges?.setOnClickListener {

val sharedPreferences = requireActivity().getSharedPreferences(
Expand All @@ -150,11 +146,8 @@ class EditProfileFragment : Fragment() {
)
editor.putString("interestMovies", binding!!.moviesDropDown.editText?.text.toString())


val drawable: Drawable? = binding!!.profileImage.drawable


// Step 2: Convert the Drawable to a Bitmap
val bitmap: Bitmap = if (drawable is BitmapDrawable) {
drawable.bitmap
} else {
Expand All @@ -167,16 +160,9 @@ class EditProfileFragment : Fragment() {
}
}

// Step 3: Compress the Bitmap to a byte array (Choose the format as needed)
//val outputStream = ByteArrayOutputStream()
//bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
//val byteArray: ByteArray = outputStream.toByteArray()
val byteArray = compressImageTo300KB(bitmap)


// Save the ByteArray to SharedPreferences
editor.putString("profileImage", Base64.encodeToString(byteArray, Base64.DEFAULT))

editor.apply()

ncvm.user1 = UserProfile(
Expand Down
36 changes: 35 additions & 1 deletion app/src/main/java/com/finite/nearbuddy/ui/SearchFragment.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.finite.nearbuddy.ui

import android.app.AlertDialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import com.finite.nearbuddy.R
import com.finite.nearbuddy.databinding.FragmentSearchBinding

Expand Down Expand Up @@ -35,6 +40,7 @@ class SearchFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)


if (!ncvm.isAdvertising) {
ncvm.startAdvertising()
binding?.discoverBtn?.background?.setTint(resources.getColor(R.color.discoverBtn))
Expand All @@ -49,7 +55,7 @@ class SearchFragment : Fragment() {
// ncvm.isConnectionActive = true
// }
if (!ncvm._isConnected.value!!) {
Toast.makeText(context, "Connected with ${user2.name}", Toast.LENGTH_SHORT).show()
showCustomDialog()
ncvm._isConnected.value = true
}
binding?.searchLottie?.pauseAnimation()
Expand Down Expand Up @@ -84,6 +90,34 @@ class SearchFragment : Fragment() {
}
}

private fun showCustomDialog() {
val dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_user2_connected, null)
val dialogBuilder = AlertDialog.Builder(requireContext()).setView(dialogView)
val customDialog = dialogBuilder.create()
customDialog.setCancelable(false)

dialogView.findViewById<TextView>(R.id.dialogMessageTextView).text = "Connected with ${ncvm.user2.value?.name}"
customDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
// set the dialogwidth to wrap content
customDialog.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)

val paddingInDp = 50
val scale: Float = resources.displayMetrics.density
val paddingInPixels = (paddingInDp * scale + 0.5f).toInt()
// add horizontal padding to the dialog of 50dp not pixels (left and right)
customDialog.window?.decorView?.setPadding(paddingInPixels, 0, paddingInPixels, 0)

dialogView.findViewById<View>(R.id.buttonOK).setOnClickListener {
customDialog.dismiss()
findNavController().navigate(R.id.nav_chat)
}

customDialog.show()
}


override fun onResume() {
super.onResume()
Expand Down
64 changes: 64 additions & 0 deletions app/src/main/res/layout/dialog_user2_connected.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardElevation="5dp"
app:cardCornerRadius="20dp"
android:layout_marginHorizontal="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingVertical="20dp"
android:gravity="center">

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:lottie_rawRes="@raw/success_tick"
app:lottie_autoPlay="true"
app:lottie_loop="false" />

<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connected_dialog_title"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="8dp" />

<TextView
android:id="@+id/dialogMessageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textColor="@android:color/black"
android:textSize="14sp"
android:layout_marginTop="8dp" />

<TextView
android:id="@+id/compatibilityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Compatibility : 100%"
android:textColor="@android:color/black"
android:textSize="12sp"
android:layout_marginTop="8dp" />

<Button
android:id="@+id/buttonOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chat"
android:textColor="@android:color/white"
android:backgroundTint="@color/colorPrimary"
android:layout_marginTop="16dp" />

</LinearLayout>

</androidx.cardview.widget.CardView>
Loading

0 comments on commit 3bf274b

Please sign in to comment.