content
stringlengths
0
3.9M
path
stringlengths
4
242
contentHash
stringlengths
1
10
package com.ese12.gilgitapp.selectcategory import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.PetsModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Pets : AppCompatActivity() { private lateinit var selectImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var location: TextView private lateinit var etPetPrice: EditText private lateinit var male: TextView private lateinit var feMale: TextView private lateinit var additionalInformation: TextView private lateinit var linear: LinearLayout private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var petBreed: EditText private lateinit var petAge: EditText private lateinit var sellNowPets: TextView var imgUri:Uri = Uri.parse("") var locationClickedWord:String="" var hide:Boolean=true private var genderMale: Boolean = false private var genderFeMale: Boolean = false private lateinit var selectedGenderTextView: TextView private var selectedGenderText: String = "" private var negoYesBool: Boolean = false private var negoNoBool: Boolean = false private lateinit var selectedNegoTextView: TextView private var selectedNegoText: String = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_pets) selectImage = findViewById(R.id.selectImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) location = findViewById(R.id.location) etPetPrice = findViewById(R.id.etPetPrice) male = findViewById(R.id.male) feMale = findViewById(R.id.feMale) additionalInformation = findViewById(R.id.additionalInformation) linear = findViewById(R.id.linear) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) petBreed = findViewById(R.id.petBreed) petAge = findViewById(R.id.petAge) sellNowPets = findViewById(R.id.sellNowPets) additionalInformation.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } location.setOnClickListener { showBottomSheet() } selectImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } male.setOnClickListener { onTextViewClicked(it) } feMale.setOnClickListener { onTextViewClicked(it) } selectedGenderTextView = male updateSelectedTextView() negoYes.setOnClickListener { onTextViewClicked1(it) } negoNo.setOnClickListener { onTextViewClicked1(it) } selectedNegoTextView = negoYes updateSelectedTextView1() sellNowPets.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Pets") val key = ref.push().key val model = PetsModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),etPetPrice.text.toString(), locationClickedWord,genderMale,genderFeMale,negoYesBool,negoNoBool,petBreed.text.toString(),petAge.text.toString()) ref.child(key!!).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedGenderTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedGenderTextView.setBackgroundResource(R.drawable.selected_background) selectedGenderTextView.setTextColor(selectedColor) val otherTextView = if (selectedGenderTextView.id == R.id.male) { findViewById<TextView>(R.id.feMale) } else { findViewById<TextView>(R.id.male) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedGenderText = selectedGenderTextView.text.toString() genderMale = selectedGenderText.equals("Male", ignoreCase = true) genderFeMale = selectedGenderText.equals("Female", ignoreCase = true) } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() negoYesBool = selectedNegoText.equals("Yes", ignoreCase = true) negoNoBool = selectedNegoText.equals("No", ignoreCase = true) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Pets.kt
3859409175
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.FurnitureModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Furniture : AppCompatActivity() { private lateinit var selectedImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etManufacture: EditText private lateinit var etLocation: TextView private lateinit var etPrice: EditText private lateinit var newTextView: TextView private lateinit var usedTextView: TextView private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var additional: TextView private lateinit var linear: LinearLayout private lateinit var etItemColor: EditText private lateinit var sellNow: TextView private var newCondition: Boolean = false private var usedCondition: Boolean = false var imgUri:Uri = Uri.parse("") var locationClickedWord:String="" private var hide: Boolean = true private var yesNego: Boolean = false private var noNego: Boolean = false private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private lateinit var selectedConditionTextView: TextView private lateinit var selectedConditionText: String @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_furniture) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etManufacture = findViewById(R.id.etManufacture) etLocation = findViewById(R.id.etLocation) etPrice = findViewById(R.id.etPrice) newTextView = findViewById(R.id.newCondition) usedTextView = findViewById(R.id.used) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) additional = findViewById(R.id.additional) linear = findViewById(R.id.linear) etItemColor = findViewById(R.id.etItemColor) sellNow = findViewById(R.id.sellNow) etLocation.setOnClickListener { showBottomSheet() } additional.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } newTextView.setOnClickListener { onTextViewClicked(it) } usedTextView.setOnClickListener { onTextViewClicked(it) } selectedConditionTextView = newTextView updateSelectedTextView() negoYes.setOnClickListener { onTextViewClicked2(it) } negoNo.setOnClickListener { onTextViewClicked2(it) } selectedNegoTextView = negoYes updateSelectedTextView2() selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } sellNow.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Furniture") val key = ref.push().key val model = FurnitureModel(key!!,imgUri.toString(),etTitle.text.toString(),etManufacture.text.toString(),etDescription.text.toString(),locationClickedWord,etPrice.text.toString(),newCondition,usedCondition,yesNego,noNego,etItemColor.text.toString()) ref.child(key).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.newCondition) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.newCondition) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() etLocation.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Furniture.kt
279752013
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.R import com.ese12.gilgitapp.Models.ShopModel import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Shop : AppCompatActivity() { private lateinit var selectedImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etPrice: EditText private lateinit var etLocation: TextView private lateinit var forRent: TextView private lateinit var forSale: TextView private lateinit var etSecuirtyDeposit: EditText private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var personName: EditText private lateinit var contactNumber: EditText private lateinit var sellShop: TextView private lateinit var additional: TextView private lateinit var linear: LinearLayout var locationClickedWord:String="" var imgUri:Uri= Uri.parse("") private var forSaleBool: Boolean = false private var forRentBool: Boolean = false private var hide: Boolean = true private lateinit var selectedForSaleTextView: TextView private lateinit var selectedForSaleText: String private var yesNego: Boolean = false private var noNego: Boolean = false private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_shop) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) etLocation = findViewById(R.id.etLocation) forRent = findViewById(R.id.forRent) additional = findViewById(R.id.additional) forSale = findViewById(R.id.forSale) etSecuirtyDeposit = findViewById(R.id.etSecuirtyDeposit) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) personName = findViewById(R.id.personName) contactNumber = findViewById(R.id.contactNumber) sellShop = findViewById(R.id.sellShop) linear = findViewById(R.id.linear) etLocation.setOnClickListener { showBottomSheet() } additional.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } forSale.setOnClickListener { onTextViewClicked(it) } forRent.setOnClickListener { onTextViewClicked(it) } selectedForSaleTextView = forSale updateSelectedTextView() negoYes.setOnClickListener { onTextViewClicked1(it) } negoNo.setOnClickListener { onTextViewClicked1(it) } selectedNegoTextView = negoYes updateSelectedTextView1() sellShop.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Shop") val key = ref.push().key val model = ShopModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),etPrice.text.toString(), etLocation.text.toString(),forSaleBool,forRentBool,etSecuirtyDeposit.text.toString(),yesNego,noNego,personName.text.toString(),contactNumber.text.toString()) ref.child(key).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() etLocation.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedForSaleTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedForSaleTextView.setBackgroundResource(R.drawable.selected_background) selectedForSaleTextView.setTextColor(selectedColor) val otherTextView = if (selectedForSaleTextView.id == R.id.forSale) { findViewById<TextView>(R.id.forRent) } else { findViewById<TextView>(R.id.forSale) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedForSaleText = selectedForSaleTextView.text.toString() forSaleBool = selectedForSaleText.equals("For Sale", ignoreCase = true) forRentBool = selectedForSaleText.equals("For Rent", ignoreCase = true) } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Shop.kt
3050606530
package com.ese12.gilgitapp.selectcategory sealed class MyResult { data class Success(var message : String): MyResult() data class Error(var message : String): MyResult() }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/MyResult.kt
1973962175
package com.ese12.gilgitapp.selectcategory import java.util.Locale.Category data class ProductModel( var key : String, var modelName : MyCategory)
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/ProductModel.kt
327135174
package com.ese12.gilgitapp.selectcategory enum class MyCategory(){ BUYERREQUEST, }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/MyCategory.kt
588057854
package com.ese12.gilgitapp.selectcategory import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.PlotModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Plot : AppCompatActivity() { private lateinit var selectedImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etPrice: EditText private lateinit var etLocation: TextView private lateinit var rent: TextView private lateinit var sale: TextView private lateinit var etSecuirtyDeposit: EditText private lateinit var additional: TextView private lateinit var linear: LinearLayout private lateinit var tvKanal: TextView private lateinit var tvMarla: TextView private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var tvResidential: TextView private lateinit var tvCommercial: TextView private lateinit var tvAgricultural: TextView private lateinit var etPersonName: EditText private lateinit var etContactNumber: EditText private lateinit var sellNowPlot: TextView var imgUri:Uri = Uri.parse("") var locationClickedWord:String="" private var forSaleBool: Boolean = false private var forRentBool: Boolean = false private var hide: Boolean = true private lateinit var selectedForSaleTextView: TextView private lateinit var selectedForSaleText: String private var forKanalBool: Boolean = false private var forMarlaBool: Boolean = false private lateinit var selectedForKanalTextView: TextView private lateinit var selectedForKanalText: String private var yesNego: Boolean = false private var noNego: Boolean = false private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private var resid: Boolean = false private var commer: Boolean = false private var aggricul: Boolean = false private lateinit var selectedResidTextView: TextView private lateinit var selectedResidText: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_plot) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) etLocation = findViewById(R.id.etLocation) rent = findViewById(R.id.rent) sale = findViewById(R.id.sale) etSecuirtyDeposit = findViewById(R.id.etSecuirtyDeposit) additional = findViewById(R.id.additional) linear = findViewById(R.id.linear) tvKanal = findViewById(R.id.tvKanal) tvMarla = findViewById(R.id.tvMarla) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) tvResidential = findViewById(R.id.tvResidential) tvCommercial = findViewById(R.id.tvCommercial) tvAgricultural = findViewById(R.id.tvAgricultural) etPersonName = findViewById(R.id.etPersonName) etContactNumber = findViewById(R.id.etContactNumber) sellNowPlot = findViewById(R.id.sellNowPlot) additional.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } etLocation.setOnClickListener { showBottomSheet() } sale.setOnClickListener { onTextViewClicked(it) } rent.setOnClickListener { onTextViewClicked(it) } selectedForSaleTextView = sale updateSelectedTextView() tvKanal.setOnClickListener { onTextViewClicked1(it) } tvMarla.setOnClickListener { onTextViewClicked1(it) } selectedForKanalTextView = tvKanal updateSelectedTextView1() negoYes.setOnClickListener { onTextViewClicked2(it) } negoNo.setOnClickListener { onTextViewClicked2(it) } selectedNegoTextView = negoYes updateSelectedTextView2() tvResidential.setOnClickListener { onTextViewClicked3(it) } tvCommercial.setOnClickListener { onTextViewClicked3(it) } tvAgricultural.setOnClickListener { onTextViewClicked3(it) } selectedResidTextView = tvResidential updateSelectedTextView3() sellNowPlot.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Plots") val key = ref.push().key val model = PlotModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),locationClickedWord,etPrice.text.toString(),forRentBool,forSaleBool,forKanalBool,forMarlaBool,resid,commer,aggricul,etPersonName.text.toString(),etContactNumber.text.toString()) ref.child(key).setValue(model) Toast.makeText(this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedForSaleTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedForSaleTextView.setBackgroundResource(R.drawable.selected_background) selectedForSaleTextView.setTextColor(selectedColor) val otherTextView = if (selectedForSaleTextView.id == R.id.sale) { findViewById<TextView>(R.id.rent) } else { findViewById<TextView>(R.id.sale) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedForSaleText = selectedForSaleTextView.text.toString() forSaleBool = selectedForSaleText.equals("For Sale", ignoreCase = true) forRentBool = selectedForSaleText.equals("For Rent", ignoreCase = true) } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedForKanalTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedForKanalTextView.setBackgroundResource(R.drawable.selected_background) selectedForKanalTextView.setTextColor(selectedColor) val otherTextView = if (selectedForKanalTextView.id == R.id.tvKanal) { findViewById<TextView>(R.id.tvMarla) } else { findViewById<TextView>(R.id.tvKanal) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedForKanalText = selectedForKanalTextView.text.toString() forKanalBool = selectedForKanalText.equals("Kanal", ignoreCase = true) forMarlaBool = selectedForKanalText.equals("Marla", ignoreCase = true) } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() etLocation.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) } private fun onTextViewClicked3(view: View) { // Set the selected TextView based on the clicked view selectedResidTextView = view as TextView updateSelectedTextView3() } private fun updateSelectedTextView3() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedResidTextView.setBackgroundResource(R.drawable.selected_background) selectedResidTextView.setTextColor(selectedColor) val otherTextViews = listOf( tvResidential, tvCommercial, tvAgricultural, ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != selectedResidTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text selectedResidText = selectedResidTextView.text.toString() resid = selectedResidText.equals("7 Days", ignoreCase = true) commer = selectedResidText.equals("15 Days", ignoreCase = true) aggricul = selectedResidText.equals("30 Days", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Plot.kt
537398830
package com.ese12.gilgitapp.selectcategory //1224625694 import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.MobileModels import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class MobileAccessories : AppCompatActivity() { private lateinit var spinner : Spinner private lateinit var slist:ArrayList<String> private lateinit var additionalInformation: TextView private lateinit var selectedImage: ImageView private lateinit var hide_linear: LinearLayout private var hide = true private var selectedManufactureItem : String = "" private var locationClickedWord : String = "" private var imgUri:Uri = Uri.parse("") lateinit var etTitle:EditText lateinit var etDescription:EditText lateinit var location:TextView lateinit var etPrice:EditText lateinit var etModel:EditText private lateinit var tvNewCondition: TextView private lateinit var tvUsedCondition: TextView private lateinit var tvNegoYes: TextView private lateinit var tvNegoNo: TextView private lateinit var tvMarchaYes: TextView private lateinit var tvMarchaNo: TextView private var newCondition: Boolean = false private var usedCondition: Boolean = false private var marchaYes: Boolean = false private var marchaNo: Boolean = false private var negoYes: Boolean = false private var negoNo: Boolean = false private lateinit var selectedConditionTextView: TextView private lateinit var selectedConditionText: String private lateinit var selectedMarchaTextView: TextView private lateinit var selectedMarchaText: String private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private lateinit var selectedWarrantyTextView: TextView private lateinit var selectedWarrantyText: String private lateinit var sevenDaysWarranty: TextView private lateinit var fifteenDaysWarranty: TextView private lateinit var thirtyDaysWarranty: TextView private lateinit var noWarranty: TextView private var sevenWarranty: Boolean = false private var fifteenWarranty: Boolean = false private var thirtyWarranty: Boolean = false private var noWarrantyBool: Boolean = false private lateinit var mobile: TextView private lateinit var tablet: TextView private lateinit var accessory: TextView private var mobileBool: Boolean = false private var tabletBool: Boolean = false private var accessoryBool: Boolean = false private lateinit var mobileTextView: TextView private lateinit var mobileText: String private lateinit var twoGB: TextView private lateinit var threeGB: TextView private lateinit var fourGB: TextView private lateinit var sixGB: TextView private lateinit var eightGB: TextView private lateinit var sixteenGB: TextView private lateinit var thirtyTwoGB: TextView private lateinit var sixtyFourGB: TextView private var twoGbBool: Boolean = false private var threeGbBool: Boolean = false private var fourGbBool: Boolean = false private var sixGbBool: Boolean = false private var eightGbBool: Boolean = false private var sixteenGbBool: Boolean = false private var thirtyTwoGbBool: Boolean = false private var sixtyFourGbBool: Boolean = false private lateinit var twoGBTextView: TextView private lateinit var twoGBText: String private lateinit var memoryEight: TextView private lateinit var memorySixteen: TextView private lateinit var memoryThirtyTwo: TextView private lateinit var memorySixtyFour: TextView private lateinit var memoryOTE: TextView private lateinit var memoryTFS: TextView private lateinit var memoryOneTb: TextView private lateinit var memoryEightTextView: TextView private lateinit var memoryEightText: String // Additional Boolean variables private var memoryEightBool: Boolean = false private var memorySixteenBool: Boolean = false private var memoryThirtyTwoBool: Boolean = false private var memorySixtyFourBool: Boolean = false private var memoryOTEBool: Boolean = false private var memoryTFSBool: Boolean = false private var memoryOneTbBool: Boolean = false lateinit var sellBike:TextView @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_mobile_accessories) supportActionBar?.hide() spinner = findViewById(R.id.spinner) additionalInformation = findViewById(R.id.additional) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) location = findViewById(R.id.location) hide_linear = findViewById(R.id.hide_linear) selectedImage = findViewById(R.id.selectedImage) etModel = findViewById(R.id.etModel) twoGB = findViewById(R.id.twoGB) threeGB = findViewById(R.id.threeGB) fourGB = findViewById(R.id.fourGB) sixGB = findViewById(R.id.sixGB) eightGB = findViewById(R.id.eightGB) sixteenGB = findViewById(R.id.sixteenGB) thirtyTwoGB = findViewById(R.id.thirtyTwoGB) sixtyFourGB = findViewById(R.id.sixtyFourGB) tvNewCondition = findViewById(R.id.New) tvUsedCondition = findViewById(R.id.used) mobile = findViewById(R.id.mobile) tablet = findViewById(R.id.tablet) accessory = findViewById(R.id.accessory) tvMarchaYes = findViewById(R.id.marchaYes) tvMarchaNo = findViewById(R.id.marchaNo) tvNegoYes = findViewById(R.id.negoYes) tvNegoNo = findViewById(R.id.negoNo) sevenDaysWarranty = findViewById(R.id.sevenDays) fifteenDaysWarranty = findViewById(R.id.fifteenDays) thirtyDaysWarranty = findViewById(R.id.thirtyDays) noWarranty = findViewById(R.id.noWarranty) // Initialize additional variables memoryEight = findViewById(R.id.memoryEight) memorySixteen = findViewById(R.id.memorySixteen) memoryThirtyTwo = findViewById(R.id.memoryThirtyTwo) memorySixtyFour = findViewById(R.id.memorySixtyFour) memoryOTE = findViewById(R.id.memoryOTE) memoryTFS = findViewById(R.id.memoryTFS) memoryOneTb = findViewById(R.id.memoryOneTb) sellBike = findViewById(R.id.sellBike) tvNewCondition.setOnClickListener { onTextViewClicked(it) } tvUsedCondition.setOnClickListener { onTextViewClicked(it) } mobile.setOnClickListener { onTextViewClicked5(it) } tablet.setOnClickListener { onTextViewClicked5(it) } accessory.setOnClickListener { onTextViewClicked5(it) } tvNegoYes.setOnClickListener { onTextViewClicked3(it) } tvNegoNo.setOnClickListener { onTextViewClicked3(it) } tvMarchaYes.setOnClickListener { onTextViewClicked4(it) } tvMarchaNo.setOnClickListener { onTextViewClicked4(it) } sevenDaysWarranty.setOnClickListener { onTextViewClicked2(it) } fifteenDaysWarranty.setOnClickListener { onTextViewClicked2(it) } thirtyDaysWarranty.setOnClickListener { onTextViewClicked2(it) } noWarranty.setOnClickListener { onTextViewClicked2(it) } twoGB.setOnClickListener { onTextViewClicked6(it) } threeGB.setOnClickListener { onTextViewClicked6(it) } fourGB.setOnClickListener { onTextViewClicked6(it) } sixGB.setOnClickListener { onTextViewClicked6(it) } eightGB.setOnClickListener { onTextViewClicked6(it) } sixteenGB.setOnClickListener { onTextViewClicked6(it) } thirtyTwoGB.setOnClickListener { onTextViewClicked6(it) } sixtyFourGB.setOnClickListener { onTextViewClicked6(it) } memoryEight.setOnClickListener { onTextViewClicked7(it) } memorySixteen.setOnClickListener { onTextViewClicked7(it) } memoryThirtyTwo.setOnClickListener { onTextViewClicked7(it) } memorySixtyFour.setOnClickListener { onTextViewClicked7(it) } memoryOTE.setOnClickListener { onTextViewClicked7(it) } memoryTFS.setOnClickListener { onTextViewClicked7(it) } memoryOneTb.setOnClickListener { onTextViewClicked7(it) } selectedConditionTextView = tvNewCondition updateSelectedTextView() memoryEightTextView = memoryEight updateSelectedTextView7() twoGBTextView = twoGB updateSelectedTextView6() mobileTextView = mobile updateSelectedTextView5() selectedMarchaTextView = tvMarchaYes updateSelectedTextView4() selectedWarrantyTextView = sevenDaysWarranty updateSelectedTextView2() selectedNegoTextView = tvNegoYes updateSelectedTextView3() selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } location.setOnClickListener{ showBottomSheet() } additionalInformation.setOnClickListener { if (hide) { hide_linear.visibility = View.VISIBLE hide = false } else { hide_linear.visibility = View.GONE hide = true } } slist = arrayListOf() slist.add("Apple") slist.add("Xiaomi") slist.add("Huawei") slist.add("Vivo") slist.add("Sanmsung") slist.add("Nokia") slist.add("Realme") slist.add("Infinix") slist.add("Oppo") slist.add("Opne Plus") slist.add("Poco") slist.add("other") val adapter = ArrayAdapter(this, com.google.android.material.R.layout.support_simple_spinner_dropdown_item, slist) adapter.setDropDownViewResource(androidx.constraintlayout.widget.R.layout.support_simple_spinner_dropdown_item) spinner.adapter = adapter spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>?, view: android.view.View?, position: Int, id: Long) { // Get the selected item from the spinner selectedManufactureItem = parent?.getItemAtPosition(position).toString() // Do something with the selected item // For example, you can log it or perform an action } override fun onNothingSelected(parent: AdapterView<*>?) { // Handle the case where nothing is selected } } sellBike.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Mobiles") val key = ref.push().key val model = MobileModels(key!!, imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),selectedManufactureItem,locationClickedWord,etPrice.text.toString(), newCondition,usedCondition,sevenWarranty,fifteenWarranty,thirtyWarranty,noWarrantyBool,negoYes,negoNo,marchaYes,marchaNo,mobileBool,tabletBool,accessoryBool, twoGbBool,threeGbBool,fourGbBool,eightGbBool,sixteenGbBool,thirtyTwoGbBool,sixtyFourGbBool,memoryEightBool,memorySixteenBool,memoryThirtyTwoBool,memorySixtyFourBool, memoryOTEBool,memoryTFSBool,memoryOneTbBool,etModel.text.toString()) ref.child(key!!).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.New) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.New) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedWarrantyTextView = view as TextView updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedWarrantyTextView.setBackgroundResource(R.drawable.selected_background) selectedWarrantyTextView.setTextColor(selectedColor) val otherTextViews = listOf( sevenDaysWarranty, fifteenDaysWarranty, thirtyDaysWarranty, noWarranty ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != selectedWarrantyTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text selectedWarrantyText = selectedWarrantyTextView.text.toString() sevenWarranty = selectedWarrantyText.equals("7 Days", ignoreCase = true) fifteenWarranty = selectedWarrantyText.equals("15 Days", ignoreCase = true) thirtyWarranty = selectedWarrantyText.equals("30 Days", ignoreCase = true) noWarrantyBool = selectedWarrantyText.equals("No Warrenty", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked3(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = view as TextView updateSelectedTextView3() } private fun updateSelectedTextView3() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() negoYes = selectedNegoText.equals("Yes", ignoreCase = true) negoNo = selectedNegoText.equals("No", ignoreCase = true) } private fun onTextViewClicked4(view: View) { // Set the selected TextView based on the clicked view selectedMarchaTextView = view as TextView updateSelectedTextView4() } private fun updateSelectedTextView4() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedMarchaTextView.setBackgroundResource(R.drawable.selected_background) selectedMarchaTextView.setTextColor(selectedColor) val otherTextView = if (selectedMarchaTextView.id == R.id.marchaYes) { findViewById<TextView>(R.id.marchaNo) } else { findViewById<TextView>(R.id.marchaYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedMarchaText = selectedMarchaTextView.text.toString() marchaYes = selectedMarchaText.equals("Yes", ignoreCase = true) marchaNo = selectedMarchaText.equals("No", ignoreCase = true) } private fun onTextViewClicked5(view: View) { // Set the selected TextView based on the clicked view mobileTextView = view as TextView updateSelectedTextView5() } private fun updateSelectedTextView5() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) mobileTextView.setBackgroundResource(R.drawable.selected_background) mobileTextView.setTextColor(selectedColor) val otherTextViews = listOf( mobile, tablet, accessory, ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != mobileTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text mobileText = mobileTextView.text.toString() mobileBool = mobileText.equals("Mobile", ignoreCase = true) tabletBool = mobileText.equals("Tablet", ignoreCase = true) accessoryBool = mobileText.equals("Accessory", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked6(view: View) { // Set the selected TextView based on the clicked view twoGBTextView = view as TextView updateSelectedTextView6() } private fun updateSelectedTextView6() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) twoGBTextView.setBackgroundResource(R.drawable.selected_background) twoGBTextView.setTextColor(selectedColor) val otherTextViews = listOf( twoGB, threeGB, fourGB, sixGB, eightGB, sixteenGB, thirtyTwoGB, sixtyFourGB, ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != twoGBTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text twoGBText = twoGBTextView.text.toString() twoGbBool = twoGBText.equals("2GB", ignoreCase = true) threeGbBool = twoGBText.equals("3GB", ignoreCase = true) fourGbBool = twoGBText.equals("4GB", ignoreCase = true) sixGbBool = twoGBText.equals("6GB", ignoreCase = true) eightGbBool = twoGBText.equals("8GB", ignoreCase = true) sixteenGbBool = twoGBText.equals("16GB", ignoreCase = true) thirtyTwoGbBool = twoGBText.equals("32GB", ignoreCase = true) sixtyFourGbBool = twoGBText.equals("64GB", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked7(view: View) { // Set the selected TextView based on the clicked view memoryEightTextView = view as TextView updateSelectedTextView7() } private fun updateSelectedTextView7() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) memoryEightTextView.setBackgroundResource(R.drawable.selected_background) memoryEightTextView.setTextColor(selectedColor) val otherTextViews = listOf( memoryEight, memorySixteen, memoryThirtyTwo, memorySixtyFour, memoryOTE, memoryTFS, memoryOneTb, ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != memoryEightTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text memoryEightText = memoryEightTextView.text.toString() memoryEightBool = memoryEightText.equals("8GB", ignoreCase = true) memorySixteenBool = memoryEightText.equals("16GB", ignoreCase = true) memoryThirtyTwoBool = memoryEightText.equals("32GB", ignoreCase = true) memorySixtyFourBool = memoryEightText.equals("64GB", ignoreCase = true) memoryOTEBool = memoryEightText.equals("128GB", ignoreCase = true) memoryTFSBool = memoryEightText.equals("256GB", ignoreCase = true) memoryOneTbBool = memoryEightText.equals("1TB", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/MobileAccessories.kt
2050005654
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.BikeModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Bikes : AppCompatActivity() { private lateinit var spinner: Spinner private lateinit var additionalInformation: TextView private lateinit var hide_linear: LinearLayout private lateinit var selectImage: ImageView private lateinit var slist: ArrayList<String> private lateinit var location: TextView private lateinit var locationClickedWord: String private var hide = true private var imgUri: Uri = Uri.parse("") private var newCondition: Boolean = false private var usedCondition: Boolean = false private lateinit var sevenDaysWarranty: TextView private lateinit var fifteenDaysWarranty: TextView private lateinit var thirtyDaysWarranty: TextView private lateinit var noWarranty: TextView private var sevenWarranty: Boolean = false private var fifteenWarranty: Boolean = false private var thirtyWarranty: Boolean = false private var noWarrantyBool: Boolean = false private var yesNego: Boolean = false private var noNego: Boolean = false private var yesMarcha: Boolean = false private var noMarcha: Boolean = false private var selectedManufactureItem: String = "" private lateinit var tvNegotiableYes: TextView private lateinit var tvNegotiableNo: TextView private lateinit var tvMarchaYes: TextView private lateinit var tvMarchaNo: TextView private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private lateinit var selectedMarchaTextView: TextView private lateinit var selectedMarchaText: String private lateinit var selectedWarrantyTextView: TextView private lateinit var selectedWarrantyText: String private lateinit var tvNewCondition: TextView private lateinit var tvUsedCondition: TextView private lateinit var selectedConditionTextView: TextView private lateinit var selectedConditionText: String lateinit var etTitle:EditText lateinit var etDescription:EditText lateinit var etPrice:EditText lateinit var etModelYear:EditText lateinit var etEngine:EditText lateinit var etBikeColor:EditText lateinit var etRegistrationCity:EditText lateinit var etMilage:EditText lateinit var sellNowBike:TextView @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_bikes) supportActionBar?.hide() etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) etModelYear = findViewById(R.id.etModelYear) etEngine = findViewById(R.id.etEngine) etBikeColor = findViewById(R.id.etBikeColor) etRegistrationCity = findViewById(R.id.etRegistrationCity) etMilage = findViewById(R.id.etMilage) sellNowBike = findViewById(R.id.sellNowBike) spinner = findViewById(R.id.spinner) additionalInformation = findViewById(R.id.additionalInformation) hide_linear = findViewById(R.id.hide_linear) location = findViewById(R.id.productLocation) selectImage = findViewById(R.id.selectImage) tvNewCondition = findViewById(R.id.New) tvUsedCondition = findViewById(R.id.used) tvNegotiableYes = findViewById(R.id.yesNego) tvNegotiableNo = findViewById(R.id.noNego) tvMarchaYes = findViewById(R.id.marchaYes) tvMarchaNo = findViewById(R.id.marchaNo) tvMarchaYes.setOnClickListener { onTextViewClicked4(it) } tvMarchaNo.setOnClickListener { onTextViewClicked4(it) } tvNewCondition.setOnClickListener { onTextViewClicked(it) } tvUsedCondition.setOnClickListener { onTextViewClicked(it) } tvNegotiableYes.setOnClickListener { onTextViewClicked3(it) } tvNegotiableNo.setOnClickListener { onTextViewClicked3(it) } sevenDaysWarranty = findViewById(R.id.sevenDays) fifteenDaysWarranty = findViewById(R.id.fifteenDays) thirtyDaysWarranty = findViewById(R.id.thirtyDays) noWarranty = findViewById(R.id.noWarranty) sevenDaysWarranty.setOnClickListener { onTextViewClicked2(it) } fifteenDaysWarranty.setOnClickListener { onTextViewClicked2(it) } thirtyDaysWarranty.setOnClickListener { onTextViewClicked2(it) } noWarranty.setOnClickListener { onTextViewClicked2(it) } selectedWarrantyTextView = sevenDaysWarranty updateSelectedTextView2() selectedMarchaTextView = tvMarchaYes updateSelectedTextView4() selectedNegoTextView = tvNegotiableYes updateSelectedTextView3() selectedConditionTextView = tvNewCondition updateSelectedTextView() location.setOnClickListener { showBottomSheet() } selectImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } additionalInformation.setOnClickListener { if (hide) { hide_linear.visibility = View.VISIBLE hide = false } else { hide_linear.visibility = View.GONE hide = true } } slist = arrayListOf() slist.add("Yahma") slist.add("Honda") slist.add("unique") slist.add("united") slist.add("Suzuki") slist.add("Road prince") slist.add("Zxcmo") val adapter = ArrayAdapter( this, com.google.android.material.R.layout.support_simple_spinner_dropdown_item, slist ) adapter.setDropDownViewResource(androidx.constraintlayout.widget.R.layout.support_simple_spinner_dropdown_item) spinner.adapter = adapter spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>?, view: android.view.View?, position: Int, id: Long) { // Get the selected item from the spinner selectedManufactureItem = parent?.getItemAtPosition(position).toString() // Do something with the selected item // For example, you can log it or perform an action } override fun onNothingSelected(parent: AdapterView<*>?) { // Handle the case where nothing is selected } } sellNowBike.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Bikes") var key = ref.push().key val model = BikeModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),selectedManufactureItem,locationClickedWord,etPrice.text.toString(),newCondition, usedCondition,sevenWarranty,fifteenWarranty,thirtyWarranty,noWarrantyBool,yesNego,noNego,yesMarcha,noMarcha,etModelYear.text.toString(),etEngine.text.toString(),etBikeColor.text.toString(),etRegistrationCity.text.toString(),etMilage.text.toString()) ref.child(key!!).setValue(model) Toast.makeText(this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show() finish() } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.New) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.New) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedWarrantyTextView = view as TextView updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedWarrantyTextView.setBackgroundResource(R.drawable.selected_background) selectedWarrantyTextView.setTextColor(selectedColor) val otherTextViews = listOf( sevenDaysWarranty, fifteenDaysWarranty, thirtyDaysWarranty, noWarranty ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != selectedWarrantyTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text selectedWarrantyText = selectedWarrantyTextView.text.toString() sevenWarranty = selectedWarrantyText.equals("7 Days", ignoreCase = true) fifteenWarranty = selectedWarrantyText.equals("15 Days", ignoreCase = true) thirtyWarranty = selectedWarrantyText.equals("30 Days", ignoreCase = true) noWarrantyBool = selectedWarrantyText.equals("No Warrenty", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked3(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView3() } private fun updateSelectedTextView3() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.yesNego) { findViewById<TextView>(R.id.noNego) } else { findViewById<TextView>(R.id.yesNego) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked4(view: View) { // Set the selected TextView based on the clicked view selectedMarchaTextView = (view as TextView) updateSelectedTextView4() } private fun updateSelectedTextView4() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedMarchaTextView.setBackgroundResource(R.drawable.selected_background) selectedMarchaTextView.setTextColor(selectedColor) val otherTextView = if (selectedMarchaTextView.id == R.id.marchaYes) { findViewById<TextView>(R.id.marchaNo) } else { findViewById<TextView>(R.id.marchaYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedMarchaText = selectedMarchaTextView.text.toString() yesMarcha = selectedMarchaText.equals("Yes", ignoreCase = true) noMarcha = selectedMarchaText.equals("No", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Bikes.kt
1875434693
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.MainActivity import com.ese12.gilgitapp.R import com.ese12.gilgitapp.domain.models.BuyerRequestModel import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.auth.FirebaseAuth import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout import de.hdodenhof.circleimageview.CircleImageView import kotlinx.coroutines.* import java.util.* import kotlin.collections.ArrayList class BuyerRequest : AppCompatActivity(){ private lateinit var spinner: Spinner private lateinit var slist: ArrayList<String> private lateinit var location: TextView private lateinit var edtLooking: EditText private lateinit var edtPrice: EditText private lateinit var edtUserName: EditText private lateinit var postARequest: TextView private lateinit var imageBack: ImageView private lateinit var profileImage: CircleImageView private lateinit var categorySelectedItem: String private lateinit var locationClickedWord: String private lateinit var buyerRequestModel: BuyerRequestModel private lateinit var imgUri: Uri @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_buyer_request) supportActionBar?.hide() buyerRequestModel = BuyerRequestModel() spinner = findViewById(R.id.spinner) postARequest = findViewById(R.id.postARequest) location = findViewById(R.id.location) edtLooking = findViewById(R.id.edtLooking) edtPrice = findViewById(R.id.etdPrice) profileImage = findViewById(R.id.profile_image) imageBack = findViewById(R.id.imageBack) edtUserName = findViewById(R.id.edtUserName) slist = arrayListOf() slist.add("Cars") slist.add("Bikes") slist.add("Laptops") slist.add("Mobiles") slist.add("Appliances") slist.add("Plot") slist.add("Home") slist.add("Shops") slist.add("Offices") slist.add("Furniture") slist.add("Pets") slist.add("Fashion") slist.add("Books") slist.add("Dry Fruits") slist.add("other") imageBack.setOnClickListener { finish() } val adapter = ArrayAdapter( this, com.google.android.material.R.layout.support_simple_spinner_dropdown_item, slist ) adapter.setDropDownViewResource(androidx.constraintlayout.widget.R.layout.support_simple_spinner_dropdown_item) spinner.adapter = adapter spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected( parent: AdapterView<*>?, view: android.view.View?, position: Int, id: Long ) { // Get the selected item from the spinner categorySelectedItem = slist[position] Log.i("TAG", "onItemSelected: item from category $categorySelectedItem") } override fun onNothingSelected(parent: AdapterView<*>?) { // Do nothing here if you don't need to handle the case where nothing is selected } } location.setOnClickListener { showBottomSheet() } profileImage.setOnClickListener { ImagePicker.Companion.with(this) .crop() .start() } postARequest.setOnClickListener { var lookingFor = edtLooking.text.toString() var price = edtPrice.text.toString() var userName = edtUserName.text.toString() if (lookingFor.isEmpty()||price.isEmpty()||userName.isEmpty()||locationClickedWord.isEmpty()||categorySelectedItem.isEmpty()){ Toast.makeText(this, "Filed Must Not Be Empty", Toast.LENGTH_SHORT).show() }else { val ref = FirebaseDatabase.getInstance().getReference("Buyer Requests") var key = ref.push().key val uid = FirebaseAuth.getInstance().currentUser!!.uid val model = BuyerRequestModel( uid, userName, imgUri.toString(), lookingFor, categorySelectedItem, price.toString().toInt(), locationClickedWord ) ref.child(uid).child(key!!).setValue(model) startActivity(Intent(this,MainActivity::class.java)) Toast.makeText(this, "Data Added Successfully", Toast.LENGTH_SHORT).show() } // locationClickedWord // categorySelectedItem } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! profileImage.setImageURI(imgUri) } catch (e: Exception) { } } } // ali hamza uid = h7PNQnOGJxSVyXLzZGPWB8468Ov1
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/BuyerRequest.kt
1648602871
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.OfficeModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Office : AppCompatActivity() { private lateinit var selectedImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var location: TextView private lateinit var etPrice: EditText private lateinit var forRent: TextView private lateinit var forSale: TextView private lateinit var secuirtyDeposit: EditText private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var additional: TextView private lateinit var linear: LinearLayout private lateinit var personName: EditText private lateinit var contactNumber: EditText private lateinit var sellNowOffice: TextView private lateinit var etNumberOfRooms: EditText var imgUri:Uri= Uri.parse("") var locationClickedWord:String="" var hide:Boolean=true private var forSaleBool: Boolean = false private var forRentBool: Boolean = false private lateinit var selectedForSaleTextView: TextView private lateinit var selectedForSaleText: String private var yesNego: Boolean = false private var noNego: Boolean = false private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_office) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) location = findViewById(R.id.location) etPrice = findViewById(R.id.etPrice) forRent = findViewById(R.id.forRent) forSale = findViewById(R.id.forSale) etNumberOfRooms = findViewById(R.id.numberOfRooms) secuirtyDeposit = findViewById(R.id.secuirtyDeposit) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) additional = findViewById(R.id.additional) linear = findViewById(R.id.linear) personName = findViewById(R.id.personName) contactNumber = findViewById(R.id.contactNumber) sellNowOffice = findViewById(R.id.sellNowOffice) selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } forSale.setOnClickListener { onTextViewClicked(it) } forRent.setOnClickListener { onTextViewClicked(it) } selectedForSaleTextView = forSale updateSelectedTextView() negoYes.setOnClickListener { onTextViewClicked1(it) } negoNo.setOnClickListener { onTextViewClicked1(it) } selectedNegoTextView = negoYes updateSelectedTextView1() additional.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } location.setOnClickListener { showBottomSheet() } sellNowOffice.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Office") val key = ref.push().key val model = OfficeModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),etPrice.text.toString(), locationClickedWord,forSaleBool,forRentBool,secuirtyDeposit.text.toString(),yesNego,noNego,etNumberOfRooms.text.toString(), personName.text.toString(),contactNumber.text.toString()) ref.child(key!!).setValue(model) Toast.makeText(this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedForSaleTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedForSaleTextView.setBackgroundResource(R.drawable.selected_background) selectedForSaleTextView.setTextColor(selectedColor) val otherTextView = if (selectedForSaleTextView.id == R.id.forSale) { findViewById<TextView>(R.id.forRent) } else { findViewById<TextView>(R.id.forSale) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedForSaleText = selectedForSaleTextView.text.toString() forSaleBool = selectedForSaleText.equals("For Sale", ignoreCase = true) forRentBool = selectedForSaleText.equals("For Rent", ignoreCase = true) } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Office.kt
4097575420
package com.ese12.gilgitapp.selectcategory import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.ese12.gilgitapp.R class Other : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_other) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Other.kt
1855043635
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.HouseModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class House : AppCompatActivity() { lateinit var selectedImage:ImageView var imageUri:Uri = Uri.parse("") lateinit var etTitle:EditText lateinit var etDescription:EditText lateinit var etPrice:EditText lateinit var personName:EditText lateinit var contactNumber:EditText lateinit var securityDeposit:EditText lateinit var location:TextView var locationClickedWord:String = "" private var forSale: Boolean = false private var forRent: Boolean = false private var yesNego: Boolean = false private var noNego: Boolean = false private lateinit var tvNegotiableYes: TextView private lateinit var tvNegotiableNo: TextView private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private lateinit var tvForSale: TextView private lateinit var tvForRent: TextView private lateinit var additionalInformation: TextView private lateinit var linear: LinearLayout private var hide: Boolean = true private lateinit var sellHouse: TextView private lateinit var selectedForSaleTextView: TextView private lateinit var selectedForSaleText: String @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_house) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) location = findViewById(R.id.location) tvForSale = findViewById(R.id.forSale) tvForRent = findViewById(R.id.forRent) personName = findViewById(R.id.personName) contactNumber = findViewById(R.id.contactNumber) additionalInformation = findViewById(R.id.additionalInformation) linear = findViewById(R.id.linear) securityDeposit = findViewById(R.id.securityDeposit) sellHouse = findViewById(R.id.sellHouse) tvNegotiableYes = findViewById(R.id.negoYes) tvNegotiableNo = findViewById(R.id.negoNo) tvForSale.setOnClickListener { onTextViewClicked(it) } tvForRent.setOnClickListener { onTextViewClicked(it) } tvNegotiableYes.setOnClickListener { onTextViewClicked1(it) } tvNegotiableNo.setOnClickListener { onTextViewClicked1(it) } selectedForSaleTextView = tvForSale updateSelectedTextView() additionalInformation.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } selectedNegoTextView = tvNegotiableYes updateSelectedTextView1() location.setOnClickListener { showBottomSheet() } selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } sellHouse.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("House") val key = ref.push().key val model = HouseModel(key!!, imageUri.toString(),etTitle.text.toString(),etDescription.text.toString(),etPrice.text.toString(),locationClickedWord,forSale, forRent,securityDeposit.text.toString(),yesNego,noNego,personName.text.toString(),contactNumber.text.toString()) ref.child(key!!).setValue(model) Toast.makeText(this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show() finish() } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imageUri = data!!.data!! selectedImage.setImageURI(imageUri) } catch (e: Exception) { } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedForSaleTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedForSaleTextView.setBackgroundResource(R.drawable.selected_background) selectedForSaleTextView.setTextColor(selectedColor) val otherTextView = if (selectedForSaleTextView.id == R.id.forSale) { findViewById<TextView>(R.id.forRent) } else { findViewById<TextView>(R.id.forSale) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedForSaleText = selectedForSaleTextView.text.toString() forSale = selectedForSaleText.equals("For Sale", ignoreCase = true) forRent = selectedForSaleText.equals("For Rent", ignoreCase = true) } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/House.kt
3084796968
package com.ese12.gilgitapp.selectcategory import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.ese12.gilgitapp.R class FashionBeauty : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_fashion_beauty) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/FashionBeauty.kt
3632613105
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.CarsSuvsModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class CarsSuvs : AppCompatActivity() { private lateinit var spinner: Spinner private lateinit var slist: ArrayList<String> private lateinit var additional: TextView private lateinit var productTitle: EditText private lateinit var productDescription: EditText private lateinit var edtMilage: EditText private lateinit var edtRegistrationCity: EditText private lateinit var productPrice: EditText private lateinit var edtEngine: EditText private lateinit var location: TextView private lateinit var hide_linear: LinearLayout private lateinit var carImage: ImageView private lateinit var selectedManfactureItem: String private lateinit var locationClickedWord: String private lateinit var selectedConditionText: String private lateinit var selectedWarrantyText: String private lateinit var selectedNegoText: String private lateinit var selectedMarchaText: String private lateinit var selectedPetrolText: String private var hide = true private lateinit var imgUri: Uri private lateinit var tvNewCondition: TextView private lateinit var tvUsedCondition: TextView private lateinit var sevenDaysWarranty: TextView private lateinit var fifteenDaysWarranty: TextView private lateinit var thirtyDaysWarranty: TextView private lateinit var noWarranty: TextView private var newCondition:Boolean=false private var usedCondition:Boolean=false private var yesNego:Boolean=false private var noNego:Boolean=false private var yesMarcha:Boolean=false private var noMarcha:Boolean=false private var petrol:Boolean=false private var diesel:Boolean=false private var hybrid:Boolean=false private var cng:Boolean=false private var sevenWarranty:Boolean=false private var fifteenWarranty:Boolean=false private var thirtyWarranty:Boolean=false private var noWarrantyBool:Boolean=false private lateinit var tvNegotiableYes: TextView private lateinit var tvNegotiableNo: TextView private lateinit var marchaYes: TextView private lateinit var marchaNo: TextView private lateinit var tvPetrol: TextView private lateinit var tvDiesel: TextView private lateinit var tvHybrid: TextView private lateinit var tvCng: TextView private lateinit var selectedConditionTextView: TextView private lateinit var selectedWarrantyTextView: TextView private lateinit var selectedNegoTextView: TextView private lateinit var selectedMarchaTextView: TextView private lateinit var selectedPetrolTextView: TextView private lateinit var airBagBox: CheckBox private lateinit var powerBag: CheckBox private lateinit var absBag: CheckBox private lateinit var conditioningBag: CheckBox private lateinit var mirrorBags: CheckBox private lateinit var usbBags: CheckBox private var airBoxBo : Boolean = false private var powerBagBo : Boolean = false private var absBagBo : Boolean = false private var coBagBo : Boolean = false private var mirBagBo : Boolean = false private var usbBagBo : Boolean = false private lateinit var tvSellNow: TextView @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_cars_suvs) supportActionBar?.hide() spinner = findViewById(R.id.spinner) additional = findViewById(R.id.additional) hide_linear = findViewById(R.id.hide_linear) carImage = findViewById(R.id.carImage) productTitle = findViewById(R.id.productTitle) edtEngine = findViewById(R.id.edtEngine) edtRegistrationCity = findViewById(R.id.edtRegistrationCity) edtMilage = findViewById(R.id.edtMilage) productDescription = findViewById(R.id.productDescription) location = findViewById(R.id.productLocation) tvNewCondition = findViewById(R.id.New) productPrice = findViewById(R.id.productPrice) tvUsedCondition = findViewById(R.id.used) tvSellNow = findViewById(R.id.tvSellNow) sevenDaysWarranty = findViewById(R.id.sevenDays) fifteenDaysWarranty = findViewById(R.id.fifteenDays) thirtyDaysWarranty = findViewById(R.id.thirtyDays) noWarranty = findViewById(R.id.noWarrenty) airBagBox = findViewById(R.id.airBagBox) powerBag = findViewById(R.id.powerBag) absBag = findViewById(R.id.absBag) conditioningBag = findViewById(R.id.conditioningBag) mirrorBags = findViewById(R.id.mirrorBags) usbBags = findViewById(R.id.usbBags) tvPetrol = findViewById(R.id.tvPetrol) tvDiesel = findViewById(R.id.tvDiesel) tvHybrid = findViewById(R.id.tvHybrid) tvCng = findViewById(R.id.tvCNG) tvNegotiableYes = findViewById(R.id.tvNegotiableYes) tvNegotiableNo = findViewById(R.id.tvNegotiableNo) tvNewCondition.setOnClickListener { onTextViewClicked(it) } tvUsedCondition.setOnClickListener { onTextViewClicked(it) } marchaYes = findViewById(R.id.marchaYes) marchaNo = findViewById(R.id.marchaNo) marchaYes.setOnClickListener { onTextViewClicked4(it) } marchaNo.setOnClickListener { onTextViewClicked4(it) } tvNegotiableYes.setOnClickListener { onTextViewClicked3(it) } tvNegotiableNo.setOnClickListener { onTextViewClicked3(it) } sevenDaysWarranty.setOnClickListener { onTextViewClicked2(it) } fifteenDaysWarranty.setOnClickListener { onTextViewClicked2(it) } thirtyDaysWarranty.setOnClickListener { onTextViewClicked2(it) } noWarranty.setOnClickListener { onTextViewClicked2(it) } tvPetrol.setOnClickListener { onTextViewClicked5(it) } tvDiesel.setOnClickListener { onTextViewClicked5(it) } tvHybrid.setOnClickListener { onTextViewClicked5(it) } tvCng.setOnClickListener { onTextViewClicked5(it) } // Initialize the selected TextView (default to 'sevenDaysWarranty') selectedNegoTextView = tvNegotiableYes updateSelectedTextView3() // Initialize the selected TextView (default to 'sevenDaysWarranty') selectedPetrolTextView = tvPetrol updateSelectedTextView5() // Initialize the selected TextView (default to 'sevenDaysWarranty') selectedMarchaTextView = marchaYes updateSelectedTextView4() // Initialize the selected TextView (default to 'sevenDaysWarranty') selectedWarrantyTextView = sevenDaysWarranty updateSelectedTextView2() selectedConditionTextView = tvNewCondition updateSelectedTextView() slist = arrayListOf() slist.add("Toyota") slist.add("Honda") slist.add("Nissan") slist.add("Hyundai") slist.add("Suzuki") slist.add("Jeep") slist.add("Mazda") slist.add("Civic") slist.add("Ford") slist.add("Mitsubishi") slist.add("Audi") slist.add("other") location.setOnClickListener { showBottomSheet() } carImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } val adapter = ArrayAdapter( this, com.google.android.material.R.layout.support_simple_spinner_dropdown_item, slist ) adapter.setDropDownViewResource(androidx.constraintlayout.widget.R.layout.support_simple_spinner_dropdown_item) spinner.adapter = adapter spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected( parent: AdapterView<*>?, view: android.view.View?, position: Int, id: Long ) { // Get the selected item from the spinner selectedManfactureItem = slist[position] Log.i("TAG", "onItemSelected: item from category $selectedManfactureItem") } override fun onNothingSelected(parent: AdapterView<*>?) { // Do nothing here if you don't need to handle the case where nothing is selected } } additional.setOnClickListener { if (hide) { hide_linear.visibility = View.VISIBLE hide = false } else { hide_linear.visibility = View.GONE hide = true } } airBagBox.setOnCheckedChangeListener { compoundButton, b -> if (compoundButton.isChecked){ airBoxBo = true }else{ airBoxBo = false } } powerBag.setOnCheckedChangeListener { compoundButton, b -> if (compoundButton.isChecked){ powerBagBo = true }else{ powerBagBo = false } } mirrorBags.setOnCheckedChangeListener { compoundButton, b -> if (compoundButton.isChecked){ mirBagBo = true }else{ mirBagBo = false } } conditioningBag.setOnCheckedChangeListener { compoundButton, b -> if (compoundButton.isChecked){ coBagBo = true }else{ coBagBo = false } } absBag.setOnCheckedChangeListener { compoundButton, b -> if (compoundButton.isChecked){ absBagBo = true }else{ absBagBo = false } } usbBags.setOnCheckedChangeListener { compoundButton, b -> if (compoundButton.isChecked){ usbBagBo = true }else{ usbBagBo = false } } tvSellNow.setOnClickListener { var ref = FirebaseDatabase.getInstance().getReference("Cars") var key = ref.push().key var model = CarsSuvsModel(imgUri.toString(),productTitle.text.toString(),productDescription.text.toString(),selectedManfactureItem,locationClickedWord, productPrice.text.toString(),newCondition,usedCondition,sevenWarranty,fifteenWarranty,thirtyWarranty,noWarrantyBool,yesNego,noNego,yesMarcha, noMarcha,edtEngine.text.toString(),edtRegistrationCity.text.toString(),petrol, diesel, hybrid, cng,edtMilage.text.toString(),airBoxBo,coBagBo, powerBagBo,mirBagBo,absBagBo,usbBagBo) ref.child(key!!).setValue(model) Toast.makeText(this, "Data Uploaded Successfull", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.New) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.New) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked4(view: View) { // Set the selected TextView based on the clicked view selectedMarchaTextView = (view as TextView) updateSelectedTextView4() } private fun updateSelectedTextView4() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedMarchaTextView.setBackgroundResource(R.drawable.selected_background) selectedMarchaTextView.setTextColor(selectedColor) val otherTextView = if (selectedMarchaTextView.id == R.id.marchaYes) { findViewById<TextView>(R.id.marchaNo) } else { findViewById<TextView>(R.id.marchaYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedMarchaText = selectedMarchaTextView.text.toString() yesMarcha = selectedMarchaText.equals("Yes", ignoreCase = true) noMarcha = selectedMarchaText.equals("No", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked3(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView3() } private fun updateSelectedTextView3() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.tvNegotiableYes) { findViewById<TextView>(R.id.tvNegotiableNo) } else { findViewById<TextView>(R.id.tvNegotiableYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedWarrantyTextView = view as TextView updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedWarrantyTextView.setBackgroundResource(R.drawable.selected_background) selectedWarrantyTextView.setTextColor(selectedColor) val otherTextViews = listOf( sevenDaysWarranty, fifteenDaysWarranty, thirtyDaysWarranty, noWarranty ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != selectedWarrantyTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text selectedWarrantyText = selectedWarrantyTextView.text.toString() sevenWarranty = selectedWarrantyText.equals("7 Days", ignoreCase = true) fifteenWarranty = selectedWarrantyText.equals("15 Days", ignoreCase = true) thirtyWarranty = selectedWarrantyText.equals("30 Days", ignoreCase = true) noWarrantyBool = selectedWarrantyText.equals("No Warrenty", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } private fun onTextViewClicked5(view: View) { // Set the selected TextView based on the clicked view selectedPetrolTextView = view as TextView updateSelectedTextView5() } private fun updateSelectedTextView5() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedPetrolTextView.setBackgroundResource(R.drawable.selected_background) selectedPetrolTextView.setTextColor(selectedColor) val otherTextViews = listOf( tvPetrol, tvDiesel, tvHybrid, tvCng ) // Iterate through other TextViews to find the unselected one for (textView in otherTextViews) { if (textView != selectedPetrolTextView) { textView.setBackgroundResource(R.drawable.rounded_background) textView.setTextColor(selectedColor) } } // Now you can use 'selectedTextView' to get the selected text selectedPetrolText = selectedPetrolTextView.text.toString() petrol = selectedPetrolText.equals("Petrol", ignoreCase = true) diesel = selectedPetrolText.equals("Diesel", ignoreCase = true) hybrid = selectedPetrolText.equals("Hybrid", ignoreCase = true) cng = selectedPetrolText.equals("CNG", ignoreCase = true) // You can store this selectedText in a variable or use it as needed } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! carImage.setImageURI(imgUri) } catch (e: Exception) { } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/CarsSuvs.kt
1268688656
package com.ese12.gilgitapp.selectcategory import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.BooksModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Books : AppCompatActivity() { private lateinit var selectedImages: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etPrice: EditText private lateinit var etLocation: TextView private lateinit var newTextView: TextView private lateinit var usedTextView: TextView private lateinit var negoYes: TextView private lateinit var noNego: TextView private lateinit var sellNowBook: TextView var imgUri: Uri = Uri.parse("") var locationClickedWord: String = "" private var newCondition: Boolean = false private var usedCondition: Boolean = false private lateinit var selectedConditionTextView: TextView private lateinit var selectedConditionText: String private var yesNegoBool: Boolean = false private var noNegoBool: Boolean = false private lateinit var selectedNegoTextView: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_books) selectedImages = findViewById(R.id.selectedImages) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) etLocation = findViewById(R.id.etLocation) newTextView = findViewById(R.id.New) usedTextView = findViewById(R.id.used) negoYes = findViewById(R.id.negoYes) noNego = findViewById(R.id.noNego) sellNowBook = findViewById(R.id.sellNowBook) selectedImages.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } etLocation.setOnClickListener { showBottomSheet() } newTextView.setOnClickListener { onTextViewClicked(it) } usedTextView.setOnClickListener { onTextViewClicked(it) } selectedConditionTextView = newTextView updateSelectedTextView() negoYes.setOnClickListener { onTextViewClicked1(it) } noNego.setOnClickListener { onTextViewClicked1(it) } selectedNegoTextView = negoYes updateSelectedTextView1() sellNowBook.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Books") val key = ref.push().key val model = BooksModel( key!!, imgUri.toString(), etTitle.text.toString(), etDescription.text.toString(), etPrice.text.toString(), locationClickedWord, newCondition, usedCondition, yesNegoBool, noNegoBool ) ref.child(key).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } private lateinit var selectedNegoText: String private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.New) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.New) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.noNego) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNegoBool = selectedNegoText.equals("Yes", ignoreCase = true) noNegoBool = selectedNegoText.equals("No", ignoreCase = true) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImages.setImageURI(imgUri) } catch (e: Exception) { } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() etLocation.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Books.kt
2911515980
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.LaptopsModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class LaptopsAccessories : AppCompatActivity() { private lateinit var spinner: Spinner private lateinit var selectImage: ImageView private lateinit var location: TextView private lateinit var etModel: EditText private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etPrice: EditText private lateinit var additionalInformation: TextView private lateinit var hide_leaner: LinearLayout private var hide: Boolean = true private lateinit var slist: ArrayList<String> private var locationClickedWord: String = "" private var selectedManufactureItem: String = "" private var imgUri: Uri = Uri.parse("") private var newCondition: Boolean = false private var usedCondition: Boolean = false private lateinit var tvNewCondition: TextView private lateinit var tvUsedCondition: TextView private lateinit var selectedConditionTextView: TextView private lateinit var selectedConditionText: String private var negoYes: Boolean = false private var negoNO: Boolean = false private lateinit var tvNegoYes: TextView private lateinit var tvNegoNo: TextView private lateinit var sellLaptop: TextView private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private var marchaYes: Boolean = false private var marchaNo: Boolean = false private lateinit var tvMarchaYes: TextView private lateinit var tvMarchaNo: TextView private lateinit var selectedMarchaTextView: TextView private lateinit var selectedMarchaText: String private var productLaptop: Boolean = false private var productAccessory: Boolean = false private lateinit var tvProductLaptop: TextView private lateinit var tvProductAccessory: TextView private lateinit var selectedProductTextView: TextView private lateinit var selectedProductText: String @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_laptops_accessories) supportActionBar?.hide() spinner = findViewById(R.id.spinner) additionalInformation = findViewById(R.id.additionalInformation) selectImage = findViewById(R.id.selectImage) location = findViewById(R.id.location) hide_leaner = findViewById(R.id.hide_linear) sellLaptop = findViewById(R.id.sellLaptop) tvNewCondition = findViewById(R.id.New) tvUsedCondition = findViewById(R.id.used) etModel = findViewById(R.id.etModel) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) tvNewCondition.setOnClickListener { onTextViewClicked(it) } tvUsedCondition.setOnClickListener { onTextViewClicked(it) } selectedConditionTextView = tvNewCondition updateSelectedTextView() tvMarchaYes = findViewById(R.id.marchaYes) tvMarchaNo = findViewById(R.id.marchaNo) tvMarchaYes.setOnClickListener { onTextViewClicked2(it) } tvMarchaNo.setOnClickListener { onTextViewClicked2(it) } selectedMarchaTextView = tvMarchaYes updateSelectedTextView2() tvNegoYes = findViewById(R.id.negoYes) tvNegoNo = findViewById(R.id.negoNo) tvNegoYes.setOnClickListener { onTextViewClicked1(it) } tvNegoNo.setOnClickListener { onTextViewClicked1(it) } tvProductLaptop = findViewById(R.id.laptopProduct) tvProductAccessory = findViewById(R.id.accessoryProduct) tvProductLaptop.setOnClickListener { onTextViewClicked3(it) } tvProductAccessory.setOnClickListener { onTextViewClicked3(it) } selectedConditionTextView = tvNewCondition updateSelectedTextView() selectedNegoTextView = tvNegoYes updateSelectedTextView1() selectedMarchaTextView = tvMarchaYes updateSelectedTextView2() selectedProductTextView = tvProductLaptop updateSelectedTextView3() slist = arrayListOf() slist.add("Macbook") slist.add("Dell") slist.add("HP") slist.add("Asus") slist.add("Acer") slist.add("Lenovo") slist.add("Samsung") slist.add("Toshiba") slist.add("LG") slist.add("Sony") slist.add("Panasonic") slist.add("Razer") slist.add("other") val adapter = ArrayAdapter( this, com.google.android.material.R.layout.support_simple_spinner_dropdown_item, slist ) adapter.setDropDownViewResource(androidx.constraintlayout.widget.R.layout.support_simple_spinner_dropdown_item) spinner.adapter = adapter spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected( parent: AdapterView<*>?, view: android.view.View?, position: Int, id: Long ) { // Get the selected item from the spinner selectedManufactureItem = parent?.getItemAtPosition(position).toString() // Do something with the selected item // For example, you can log it or perform an action } override fun onNothingSelected(parent: AdapterView<*>?) { // Handle the case where nothing is selected } } location.setOnClickListener { showBottomSheet() } selectImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } additionalInformation.setOnClickListener { if (hide) { hide_leaner.visibility = View.VISIBLE hide = false } else { hide_leaner.visibility = View.GONE hide = true } } sellLaptop.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Laptops") val key = ref.push().key val model = LaptopsModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),selectedManufactureItem,locationClickedWord,etPrice.text.toString(),newCondition,usedCondition,negoYes,negoNO,marchaYes,marchaNo,productLaptop,productAccessory,etModel.text.toString()) ref.child(key!!).setValue(model) finish() Toast.makeText(this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show() } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() location.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.New) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.New) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() negoYes = selectedNegoText.equals("Yes", ignoreCase = true) negoNO = selectedNegoText.equals("No", ignoreCase = true) } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedMarchaTextView = (view as TextView) updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedMarchaTextView.setBackgroundResource(R.drawable.selected_background) selectedMarchaTextView.setTextColor(selectedColor) val otherTextView = if (selectedMarchaTextView.id == R.id.marchaYes) { findViewById<TextView>(R.id.marchaNo) } else { findViewById<TextView>(R.id.marchaYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedMarchaText = selectedMarchaTextView.text.toString() marchaYes = selectedMarchaText.equals("Yes", ignoreCase = true) marchaNo = selectedMarchaText.equals("No", ignoreCase = true) } private fun onTextViewClicked3(view: View) { // Set the selected TextView based on the clicked view selectedProductTextView = (view as TextView) updateSelectedTextView3() } private fun updateSelectedTextView3() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedProductTextView.setBackgroundResource(R.drawable.selected_background) selectedProductTextView.setTextColor(selectedColor) val otherTextView = if (selectedProductTextView.id == R.id.laptopProduct) { findViewById<TextView>(R.id.accessoryProduct) } else { findViewById<TextView>(R.id.laptopProduct) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedProductText = selectedProductTextView.text.toString() productLaptop = selectedProductText.equals("Laptop", ignoreCase = true) productAccessory = selectedProductText.equals("Accessory", ignoreCase = true) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/LaptopsAccessories.kt
1004870585
package com.ese12.gilgitapp.selectcategory import android.annotation.SuppressLint import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.AppliancesModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Appliances : AppCompatActivity() { private lateinit var selectedImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etManufacture: EditText private lateinit var etLocation: TextView private lateinit var etPrice: EditText private lateinit var newTextView: TextView private lateinit var usedTextView: TextView private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var additional: TextView private lateinit var linear: LinearLayout private lateinit var etItemColor: EditText private lateinit var sellNow: TextView private var newCondition: Boolean = false private var usedCondition: Boolean = false var imgUri:Uri = Uri.parse("") var locationClickedWord:String="" private var hide: Boolean = true private var yesNego: Boolean = false private var noNego: Boolean = false private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String private lateinit var selectedConditionTextView: TextView private lateinit var selectedConditionText: String @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_appliances) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etManufacture = findViewById(R.id.etManufacture) etLocation = findViewById(R.id.etLocation) etPrice = findViewById(R.id.etPrice) newTextView = findViewById(R.id.newCondition) usedTextView = findViewById(R.id.used) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) additional = findViewById(R.id.additional) linear = findViewById(R.id.linear) etItemColor = findViewById(R.id.etItemColor) sellNow = findViewById(R.id.sellNow) etLocation.setOnClickListener { showBottomSheet() } additional.setOnClickListener { if (hide) { linear.visibility = View.VISIBLE hide = false } else { linear.visibility = View.GONE hide = true } } newTextView.setOnClickListener { onTextViewClicked(it) } usedTextView.setOnClickListener { onTextViewClicked(it) } selectedConditionTextView = newTextView updateSelectedTextView() negoYes.setOnClickListener { onTextViewClicked2(it) } negoNo.setOnClickListener { onTextViewClicked2(it) } selectedNegoTextView = negoYes updateSelectedTextView2() selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } sellNow.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Appliances") val key = ref.push().key val model = AppliancesModel(key!!,imgUri.toString(),etTitle.text.toString(),etManufacture.text.toString(),etDescription.text.toString(),locationClickedWord,etPrice.text.toString(),newCondition,usedCondition,yesNego,noNego,etItemColor.text.toString()) ref.child(key).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked(view: View) { // Set the selected TextView based on the clicked view selectedConditionTextView = (view as TextView) updateSelectedTextView() } private fun updateSelectedTextView() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedConditionTextView.setBackgroundResource(R.drawable.selected_background) selectedConditionTextView.setTextColor(selectedColor) val otherTextView = if (selectedConditionTextView.id == R.id.newCondition) { findViewById<TextView>(R.id.used) } else { findViewById<TextView>(R.id.newCondition) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedConditionText = selectedConditionTextView.text.toString() newCondition = selectedConditionText.equals("New", ignoreCase = true) usedCondition = selectedConditionText.equals("Used", ignoreCase = true) } private fun onTextViewClicked2(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView2() } private fun updateSelectedTextView2() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNego = selectedNegoText.equals("Yes", ignoreCase = true) noNego = selectedNegoText.equals("No", ignoreCase = true) } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() etLocation.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Appliances.kt
137079406
package com.ese12.gilgitapp.selectcategory import android.app.Dialog import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.Window import android.widget.* import androidx.core.content.res.ResourcesCompat import com.ese12.gilgitapp.Models.FruitsModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase import com.nex3z.flowlayout.FlowLayout class Dry_Friut : AppCompatActivity() { private lateinit var selectedImage: ImageView private lateinit var etTitle: EditText private lateinit var etDescription: EditText private lateinit var etPrice: EditText private lateinit var etLocation: TextView private lateinit var negoYes: TextView private lateinit var negoNo: TextView private lateinit var sellFruits: TextView var imgUri:Uri = Uri.parse("") var locationClickedWord:String="" private var yesNegoBool: Boolean = false private var noNegoBool: Boolean = false private lateinit var selectedNegoTextView: TextView private lateinit var selectedNegoText: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_dry_friut) selectedImage = findViewById(R.id.selectedImage) etTitle = findViewById(R.id.etTitle) etDescription = findViewById(R.id.etDescription) etPrice = findViewById(R.id.etPrice) etLocation = findViewById(R.id.etLocation) negoYes = findViewById(R.id.negoYes) negoNo = findViewById(R.id.negoNo) sellFruits = findViewById(R.id.sellFruits) selectedImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } etLocation.setOnClickListener { showBottomSheet() } negoYes.setOnClickListener { onTextViewClicked1(it) } negoNo.setOnClickListener { onTextViewClicked1(it) } selectedNegoTextView = negoYes updateSelectedTextView1() sellFruits.setOnClickListener { val ref = FirebaseDatabase.getInstance().getReference("Fruits") val key = ref.push().key val model = FruitsModel(key!!,imgUri.toString(),etTitle.text.toString(),etDescription.text.toString(),etPrice.text.toString(),locationClickedWord,yesNegoBool,noNegoBool) ref.child(key).setValue(model) Toast.makeText(this, "Data Uploaded Sucessfully", Toast.LENGTH_SHORT).show() finish() } } private fun onTextViewClicked1(view: View) { // Set the selected TextView based on the clicked view selectedNegoTextView = (view as TextView) updateSelectedTextView1() } private fun updateSelectedTextView1() { // Update the background and text color of the selected TextView val selectedColor = getColor(R.color.black) selectedNegoTextView.setBackgroundResource(R.drawable.selected_background) selectedNegoTextView.setTextColor(selectedColor) val otherTextView = if (selectedNegoTextView.id == R.id.negoYes) { findViewById<TextView>(R.id.negoNo) } else { findViewById<TextView>(R.id.negoYes) } otherTextView.setBackgroundResource(R.drawable.rounded_background) otherTextView.setTextColor(selectedColor) // Now you can use 'selectedTextView' to get the selected text selectedNegoText = selectedNegoTextView.text.toString() yesNegoBool = selectedNegoText.equals("Yes", ignoreCase = true) noNegoBool = selectedNegoText.equals("No", ignoreCase = true) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! selectedImage.setImageURI(imgUri) } catch (e: Exception) { } } private fun showBottomSheet() { val dialog = Dialog(this) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.bottomsheetforlocation) var autoCompleteTextView = dialog.findViewById<AutoCompleteTextView>(R.id.autoCompleteTextView1) val flow = dialog.findViewById<FlowLayout>(R.id.flow) var text = "Karachi,Lahore,Islamabad,Faisalabad,Rawalpindi,Multan,Peshawar,Quetta,Sialkot,Gujranwala,Hyderabad,Abbottabad,Bahawalpur,Sargodha,Sahiwal,Jhang,Okara,Gujrat,Mirpur,Sheikhupura,Sialkot,Rahim Yar Khan,Marian,Sukkur,Larkana,Nawabshah,Mingora,Dera Ghazi Khan,Bhimber,Chiniot" val words = text.split(",").toTypedArray() var countries = arrayOf( "Pakistan", "India", "United States", "United Kingdom", "Canada", "Australia" ) val adapter1 = ArrayAdapter(this, android.R.layout.simple_list_item_1, countries) autoCompleteTextView.setAdapter(adapter1) for (i in words.indices) { val textView = TextView(this) textView.text = words[i].trim() textView.textSize = 15f textView.setBackgroundResource(R.drawable.rounded_background) textView.minWidth = 170 textView.gravity = Gravity.CENTER_HORIZONTAL visi(textView) textView.setPadding(20, 10, 20, 15) flow.setPadding(16, 25, 16, 25) textView.setTextColor(resources.getColor(R.color.black)) val customFont = ResourcesCompat.getFont(this, R.font.nunitolight) textView.setTypeface(customFont) flow.addView(textView) for (j in 0 until flow.childCount) { val innerTextView = flow.getChildAt(j) as TextView var isSelected = false innerTextView.setOnClickListener { locationClickedWord = innerTextView.text.toString() etLocation.text = locationClickedWord dialog.dismiss() } } } dialog.show() dialog.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.window!!.attributes.windowAnimations = R.style.DialogAnimation dialog.window!!.setGravity(Gravity.BOTTOM) } private fun visi(textView: TextView) { if (textView.text.toString().isEmpty()) { textView.visibility = View.GONE } else { textView.visibility = View.VISIBLE } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/selectcategory/Dry_Friut.kt
2220644096
package com.ese12.gilgitapp.Activities import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.widget.Button import android.widget.EditText import android.widget.Toast import com.ese12.gilgitapp.R import com.google.firebase.FirebaseException import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.PhoneAuthCredential import com.google.firebase.auth.PhoneAuthOptions import com.google.firebase.auth.PhoneAuthProvider import com.google.firebase.auth.ktx.auth import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase import com.google.firebase.ktx.Firebase import com.hbb20.CountryCodePicker import java.util.concurrent.TimeUnit class LoginWithPhoneNumber : AppCompatActivity() { private lateinit var btnSend: Button private lateinit var phoneNumberWithCountryCode:String private lateinit var etPhone: EditText private lateinit var userName: EditText private lateinit var ccp: CountryCodePicker private lateinit var mAuth: FirebaseAuth private lateinit var mResendingToken: PhoneAuthProvider.ForceResendingToken private lateinit var mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks private var mVerificationId: String? = null private lateinit var databaseReference: DatabaseReference override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login_with_phone_number) ccp = findViewById(R.id.ccp) mAuth = Firebase.auth btnSend = findViewById(R.id.login) etPhone = findViewById(R.id.etPhone) userName = findViewById(R.id.userName) databaseReference = FirebaseDatabase.getInstance().getReference("Users") btnSend.setOnClickListener { Toast.makeText(this, "Please Wait...", Toast.LENGTH_SHORT).show() val number = etPhone.text.toString().trim() val countryCode = ccp.selectedCountryCodeWithPlus val phoneNumber = getPhoneNumber(number) phoneNumberWithCountryCode = "$countryCode$phoneNumber" otpSend(phoneNumberWithCountryCode) } mCallbacks = object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() { override fun onVerificationCompleted(credential: PhoneAuthCredential) { Log.d("TAG", "onVerificationCompleted: ${credential.smsCode}") // You can automatically sign in the user here if verification is completed instantly } override fun onVerificationFailed(e: FirebaseException) { Log.i("TAG", e.localizedMessage) Toast.makeText(this@LoginWithPhoneNumber, e.localizedMessage, Toast.LENGTH_SHORT).show() Toast.makeText(this@LoginWithPhoneNumber, "Verification Failed", Toast.LENGTH_SHORT).show() } override fun onCodeSent( verificationId: String, token: PhoneAuthProvider.ForceResendingToken ) { Toast.makeText(this@LoginWithPhoneNumber, "OTP has been successfully sent.", Toast.LENGTH_SHORT).show() mVerificationId = verificationId mResendingToken = token startActivity( Intent(this@LoginWithPhoneNumber, UserOtpVerifyActivity::class.java) .putExtra("phone", phoneNumberWithCountryCode) .putExtra("verificationId", mVerificationId) .putExtra("userName", userName.text.toString()) .putExtra("forceResendingToken", mResendingToken) ) } } } private fun getPhoneNumber(phone: String): String? { val phoneNumberPattern = "^[0-9]{10}\$" if (phone.isEmpty()) { Toast.makeText(this, "Phone number is required!", Toast.LENGTH_SHORT).show() return null } else if (!phone.matches(phoneNumberPattern.toRegex())) { Toast.makeText(this, "Please enter a valid phone number!", Toast.LENGTH_SHORT).show() return null } else { return phone } } private fun otpSend(phoneNumberWithCountryCode: String) { PhoneAuthProvider.verifyPhoneNumber( PhoneAuthOptions.newBuilder(mAuth) .setPhoneNumber(phoneNumberWithCountryCode) .setTimeout(60L, TimeUnit.SECONDS) .setActivity(this) .setCallbacks(mCallbacks) .build() ) } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/LoginWithPhoneNumber.kt
3469391040
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.R import com.ese12.gilgitapp.Models.ShopModel class ShopDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_shop_details) val receivedData = intent.getParcelableExtra<ShopModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.image, "")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title if (receivedData.forSale == true) { tvManufacture.text = "For Sale" }else{ tvManufacture.text = "For Rent" } tvCondition.text=receivedData.secuirtyDeposit if (receivedData.negoYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } tvMarcha.text = receivedData.contactNumber tvWarranty.text = receivedData.personName tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/ShopDetails.kt
2743014699
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.MobileModels import com.ese12.gilgitapp.R class MobilesDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_mobiles_details) val receivedData = intent.getParcelableExtra<MobileModels>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.image,"")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title tvManufacture.text = receivedData.manufacture if (receivedData.conditionNew == true) { tvCondition.text = "New" }else{ tvCondition.text = "Used" } if (receivedData.negoYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } if (receivedData.marchaYes == true) { tvMarcha.text = "Yes" } else { tvMarcha.text = "No" } if (receivedData.warrantySevenDays == true) { tvWarranty.text = "7 Days" }else if (receivedData.fifDaysWar==true){ tvWarranty.text = "15 Days" }else if (receivedData.thiryDaysWar==true){ tvWarranty.text = "30 Days" }else{ tvWarranty.text = "No Warranty" } tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/MobilesDetails.kt
866479166
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.BikeModel import com.ese12.gilgitapp.R class BikesDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_bikes_details) val receivedData = intent.getParcelableExtra<BikeModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.bikeImage,"")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title tvManufacture.text = receivedData.manufacture if (receivedData.newCondition == true) { tvCondition.text = "New" }else{ tvCondition.text = "Used" } if (receivedData.negotiableYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } if (receivedData.marchaYes == true) { tvMarcha.text = "Yes" } else { tvMarcha.text = "No" } if (receivedData.sevenDays == true) { tvWarranty.text = "7 Days" }else if (receivedData.fifteenDays==true){ tvWarranty.text = "15 Days" }else if (receivedData.thirtyDays==true){ tvWarranty.text = "30 Days" }else{ tvWarranty.text = "No Warranty" } tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/BikesDetails.kt
2194796240
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.HouseModel import com.ese12.gilgitapp.R class HouseDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_house_details) val receivedData = intent.getParcelableExtra<HouseModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.image, "")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title if (receivedData.forSale == true) { tvManufacture.text = "For Sale" }else{ tvManufacture.text = "For Rent" } tvCondition.text=receivedData.secuirtyDeposit if (receivedData.negoYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } tvMarcha.text = receivedData.contactNumber tvWarranty.text = receivedData.personName tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/HouseDetails.kt
3147633044
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.OfficeModel import com.ese12.gilgitapp.R class OfficeDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_pets_details) val receivedData = intent.getParcelableExtra<OfficeModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.image, "")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/OfficeDetails.kt
3303056788
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.LaptopsModel import com.ese12.gilgitapp.R class LaptopsDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_laptops_details) val receivedData = intent.getParcelableExtra<LaptopsModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.img,"")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title tvManufacture.text = receivedData.manufacture if (receivedData.conditionNew == true) { tvCondition.text = "New" }else{ tvCondition.text = "Used" } if (receivedData.negoYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } if (receivedData.marchaYes == true) { tvMarcha.text = "Yes" } else { tvMarcha.text = "No" } if (receivedData.productLaptop == true) { tvWarranty.text = "Laptop" }else if (receivedData.productAccessory==true){ tvWarranty.text = "Accessory" } tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/LaptopsDetails.kt
3236819080
package com.ese12.gilgitapp.Activities import android.content.Intent import android.os.Build import android.os.Bundle import android.os.CountDownTimer import android.util.Log import android.widget.EditText import android.widget.ProgressBar import android.widget.TextView import android.widget.Toast import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.core.view.isVisible import androidx.core.widget.doOnTextChanged import com.ese12.gilgitapp.MainActivity import com.ese12.gilgitapp.Models.Callback import com.ese12.gilgitapp.R import com.google.firebase.FirebaseException import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.PhoneAuthCredential import com.google.firebase.auth.PhoneAuthOptions import com.google.firebase.auth.PhoneAuthProvider import com.google.firebase.auth.ktx.auth import com.google.firebase.ktx.Firebase import java.util.concurrent.TimeUnit class UserOtpVerifyActivity : AppCompatActivity() { companion object { private const val TAG = "Nww" /** CountDown Timer */ const val DELAY: Long = 60000 const val INTERVAL: Long = 1000 } private lateinit var etC1: EditText private lateinit var etC2: EditText private lateinit var etC3: EditText private lateinit var etC4: EditText private lateinit var etC5: EditText private lateinit var etC6: EditText private lateinit var tvMobile: TextView private lateinit var textView7: TextView private lateinit var btnVerify: TextView // private var user: UserModel? = null private lateinit var tvResendBtn: TextView private lateinit var progressBarVerify: ProgressBar private lateinit var mAuth: FirebaseAuth private lateinit var mResendingToken: PhoneAuthProvider.ForceResendingToken private lateinit var mCallbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks private lateinit var countDownTimer: CountDownTimer private lateinit var mVerificationId: String private lateinit var mPhoneNumber: String private lateinit var mUserName: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_otp_verify_user) // Find views by their IDs etC1 = findViewById(R.id.etC1) etC2 = findViewById(R.id.etC2) etC3 = findViewById(R.id.etC3) etC4 = findViewById(R.id.etC4) etC5 = findViewById(R.id.etC5) etC6 = findViewById(R.id.etC6) tvMobile = findViewById(R.id.tvMobile) textView7 = findViewById(R.id.textView7) btnVerify = findViewById(R.id.btnVerify) tvResendBtn = findViewById(R.id.tvResendBtn) progressBarVerify = findViewById(R.id.progressBarVerify) editTextInput() mAuth = Firebase.auth mPhoneNumber = intent.getStringExtra("phone").toString() mUserName = intent.getStringExtra("userName").toString() mVerificationId = intent.getStringExtra("verificationId").toString() mResendingToken = intent.getParcelableExtra("forceResendingToken")!! // user = UserModel(mUserName,mPhoneNumber) tvMobile.text = mPhoneNumber /** countDownTimer */ countDownTimer() btnVerify.setOnClickListener { val c1 = etC1.text.toString().trim() val c2 = etC2.text.toString().trim() val c3 = etC3.text.toString().trim() val c4 = etC4.text.toString().trim() val c5 = etC5.text.toString().trim() val c6 = etC6.text.toString().trim() if (c1.isEmpty() || c2.isEmpty() || c3.isEmpty() || c4.isEmpty() || c5.isEmpty() || c6.isEmpty()) Toast.makeText(this, "Filed Must Not be empty", Toast.LENGTH_SHORT).show() else { if (mVerificationId != null) { val smsCode = "$c1$c2$c3$c4$c5$c6" val credential = PhoneAuthProvider.getCredential(mVerificationId, smsCode) Firebase.auth.signInWithCredential(credential) .addOnCompleteListener { task -> if (task.isSuccessful) { Log.i(TAG, " if (task.isSuccessful)") isVisible(true) Toast.makeText( this, "Welcome... ${task.result}", Toast.LENGTH_SHORT ).show() startActivity(Intent(this, MainActivity::class.java)) } else { isVisible(false) Toast.makeText(this, "Otp is not Valid!", Toast.LENGTH_SHORT).show() } } } } } } private fun countDownTimer() { countDownTimer = object : CountDownTimer(DELAY, INTERVAL) { override fun onTick(millisUntilFinished: Long) { textView7.text = Callback(this@UserOtpVerifyActivity).elapsedCountDownTimer( millisUntilFinished.div( INTERVAL ) ) tvResendBtn.isVisible = false } @RequiresApi(Build.VERSION_CODES.M) override fun onFinish() { textView7.text = "Don't get the OTP?" tvResendBtn.isVisible = true tvResendBtn.setTextColor(resources.getColor(R.color.red_400, theme)) tvResendBtn.setOnClickListener { isVisible(true) forceResendingToken() } } } countDownTimer.start() } private fun forceResendingToken() { mCallbacks = object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() { override fun onVerificationCompleted(credential: PhoneAuthCredential) { Log.d("TAG", "onVerificationCompleted: ${credential.smsCode}") } override fun onVerificationFailed(e: FirebaseException) { isVisible(false) Toast.makeText(this@UserOtpVerifyActivity, e.localizedMessage, Toast.LENGTH_SHORT) .show() } override fun onCodeSent( verificationId: String, token: PhoneAuthProvider.ForceResendingToken ) { // super.onCodeSent(verificationId, token) isVisible(false) Toast.makeText( this@UserOtpVerifyActivity, "Otp is Successfully Send!", Toast.LENGTH_SHORT ).show() mResendingToken = token mVerificationId = verificationId } } PhoneAuthProvider.verifyPhoneNumber( PhoneAuthOptions.newBuilder(mAuth) .setPhoneNumber(mPhoneNumber) .setTimeout(60L, TimeUnit.SECONDS) .setActivity(this) .setCallbacks(mCallbacks) .setForceResendingToken(mResendingToken) .build() ) } private fun isVisible(visible: Boolean) { progressBarVerify.isVisible = visible btnVerify.isVisible = !visible } private fun editTextInput() { etC1.doOnTextChanged { text, _, count, _ -> if (count == 6) { etC1.setText(text!![0].toString()) etC2.setText(text[1].toString()) etC3.setText(text[2].toString()) etC4.setText(text[3].toString()) etC5.setText(text[4].toString()) etC6.setText(text[5].toString()) } else { etC2.requestFocus() } } etC2.doOnTextChanged { _, _, _, _ -> etC3.requestFocus() } etC3.doOnTextChanged { _, _, _, _ -> etC4.requestFocus() } etC4.doOnTextChanged { _, _, _, _ -> etC5.requestFocus() } etC5.doOnTextChanged { _, _, _, _ -> etC6.requestFocus() } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/UserOtpVerifyActivity.kt
2735605055
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.PetsModel import com.ese12.gilgitapp.R class PetsDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_pets_details) val receivedData = intent.getParcelableExtra<PetsModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.imageUri, "")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title if (receivedData.male == true) { tvManufacture.text = "Male" }else{ tvManufacture.text = "FeMale" } tvCondition.text=receivedData.petBreed if (receivedData.negoYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } // tvMarcha.text = receivedData.contactNumber tvWarranty.text = receivedData.petAge tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/PetsDetails.kt
4032360487
package com.ese12.gilgitapp.Activities import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.denzcoskun.imageslider.ImageSlider import com.denzcoskun.imageslider.constants.ScaleTypes import com.denzcoskun.imageslider.models.SlideModel import com.ese12.gilgitapp.Models.CarsSuvsModel import com.ese12.gilgitapp.R class CarsSuvsDetails : AppCompatActivity() { private lateinit var img: ImageSlider private lateinit var shareImage: ImageView private lateinit var img3: ImageView private lateinit var tvPrice: TextView private lateinit var tvCondition: TextView private lateinit var tvWarranty: TextView private lateinit var tvTitle: TextView private lateinit var tvManufacture: TextView private lateinit var tvLocation: TextView private lateinit var tvMarcha: TextView private lateinit var tvDate: TextView private lateinit var tvDescription: TextView private lateinit var tvNegotiable: TextView private lateinit var btnChat: Button private lateinit var btnContact: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_cars_suvs_details) val receivedData = intent.getParcelableExtra<CarsSuvsModel>("list") val imageList = ArrayList<SlideModel>() img = findViewById(R.id.imageSlider) img3 = findViewById(R.id.img3) tvPrice = findViewById(R.id.tvPrice) tvNegotiable = findViewById(R.id.tvNegotiable) tvTitle = findViewById(R.id.tvTitle) tvCondition = findViewById(R.id.tvCondition) tvWarranty = findViewById(R.id.tvWarranty) tvMarcha = findViewById(R.id.tvMarcha) tvManufacture = findViewById(R.id.tvManufacture) tvLocation = findViewById(R.id.tvLocation) tvDate = findViewById(R.id.tvDate) tvDescription = findViewById(R.id.tvDescription) btnChat = findViewById(R.id.btnChat) btnContact = findViewById(R.id.btnContact) shareImage = findViewById(R.id.img2) imageList.add(SlideModel(receivedData!!.carImage,"")) img.setImageList(imageList, ScaleTypes.CENTER_CROP) btnChat.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to chat with, including the country code // Create a Uri for the WhatsApp chat val uri = "https://api.whatsapp.com/send?phone=$phoneNumber" // Create an Intent with the ACTION_VIEW action val intent = Intent(Intent.ACTION_VIEW) // Set the data for the intent (the URI for the WhatsApp chat) intent.data = Uri.parse(uri) // Check if WhatsApp is installed on the device if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // WhatsApp is not installed, handle this case Toast.makeText(this, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show() } } btnContact.setOnClickListener { val phoneNumber = "+923016826762" // Replace with the phone number you want to call // Create an Intent with the ACTION_DIAL action val intent = Intent(Intent.ACTION_DIAL) // Set the data for the intent (the phone number) intent.data = Uri.parse("tel:$phoneNumber") // Check if there is an app to handle the dial action (phone app) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } else { // Handle the case where there is no app to make the call Toast.makeText(this, "No app available to make the call.", Toast.LENGTH_SHORT) .show() } } img3.setOnClickListener { finish() } // tvDate.text = receivedData!!.date tvPrice.text = "PKR " + receivedData.price tvTitle.text = receivedData.title tvManufacture.text = receivedData.manufacturer if (receivedData.new == true) { tvCondition.text = "New" }else{ tvCondition.text = "Used" } if (receivedData.negotiableYes == true) { tvNegotiable.text = "Yes" } else { tvNegotiable.text = "No" } if (receivedData.availableForMarchaYes == true) { tvMarcha.text = "Yes" } else { tvMarcha.text = "No" } if (receivedData.sevenDaysWarranty == true) { tvWarranty.text = "7 Days" }else if (receivedData.fifteenDaysWarranty==true){ tvWarranty.text = "15 Days" }else if (receivedData.thirtyDaysWarranty==true){ tvWarranty.text = "30 Days" }else{ tvWarranty.text = "No Warranty" } tvLocation.text = receivedData.location tvDescription.text = receivedData.description shareImage.setOnClickListener { // Assuming you have the URL of the image you want to share } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/CarsSuvsDetails.kt
1216933218
package com.ese12.gilgitapp.Activities import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.Toast import com.ese12.gilgitapp.R import com.ese12.gilgitapp.selectcategory.BuyerRequest import com.google.android.gms.auth.api.Auth import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInClient import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.GoogleAuthProvider class SignUpActivity : AppCompatActivity() { private var RCSIGNIN: Int = 123 private lateinit var mAuth: FirebaseAuth private lateinit var mGoogleSignInClient: GoogleSignInClient private lateinit var googleLoginBtn: Button private lateinit var phoneLogin: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_sign_up) mAuth = FirebaseAuth.getInstance() googleLoginBtn = findViewById(R.id.googleLoginBtn) phoneLogin = findViewById(R.id.phoneLogin) googleLoginBtn.setOnClickListener { loginUser() } phoneLogin.setOnClickListener { startActivity(Intent(this, LoginWithPhoneNumber::class.java)) } } private fun loginUser() { val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken("304729930591-771mr2c6u759skvi5bj13vkr8ev10pcd.apps.googleusercontent.com") .requestEmail() .build() mGoogleSignInClient = GoogleSignIn.getClient(this, gso) val signInIntent = mGoogleSignInClient.signInIntent startActivityForResult(signInIntent, RCSIGNIN) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == RCSIGNIN) { val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data) if (result?.isSuccess!!) { val acct = result.signInAccount firebaseAuthWithGoogle(acct) } else { Toast.makeText(this, "There was a trouble signing-in Please try again", Toast.LENGTH_SHORT).show() } } } private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount?) { val credential = GoogleAuthProvider.getCredential(acct!!.idToken, null) mAuth.signInWithCredential(credential).addOnCompleteListener { task -> run { if (task.isSuccessful) { saveEmailInSharedPref(acct) startActivity(Intent(this@SignUpActivity,BuyerRequest::class.java)) }else { Toast.makeText(this@SignUpActivity,"Something went wrong, Please try again!", Toast.LENGTH_SHORT).show() } } } } private fun saveEmailInSharedPref(acct: GoogleSignInAccount?){ val preferences = getSharedPreferences(getString(R.string.preference_name), AppCompatActivity.MODE_PRIVATE) preferences?.edit()?.putString("email",acct?.email.toString())?.apply() } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/SignUpActivity.kt
4218186944
package com.ese12.gilgitapp.Activities import android.annotation.SuppressLint import android.content.Intent import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.EditText import android.widget.ImageView import android.widget.TextView import android.widget.Toast import com.ese12.gilgitapp.Models.OfferModel import com.ese12.gilgitapp.R import com.github.dhaval2404.imagepicker.ImagePicker import com.google.firebase.database.FirebaseDatabase class MakeAnOffer : AppCompatActivity() { lateinit var imgUri:Uri lateinit var profileImage:ImageView @SuppressLint("MissingInflatedId", "WrongViewCast") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_make_an_offer) var uid = intent.getStringExtra("uid") var close = findViewById<ImageView>(R.id.imageBack) close.setOnClickListener { finish() } var title = findViewById<EditText>(R.id.edtTitle) var price = findViewById<EditText>(R.id.edtPrice) profileImage = findViewById(R.id.profile_image) var description = findViewById<EditText>(R.id.edtDescription) var postARequest = findViewById<TextView>(R.id.postARequest) profileImage.setOnClickListener { ImagePicker.Companion.with(this).crop().start() } postARequest.setOnClickListener { var title = title.text.toString() var price = price.text.toString() var description = description.text.toString() if (title.isEmpty() || price.isEmpty() || description.isEmpty() || imgUri.toString().isEmpty()){ Toast.makeText(this,"Filed Must Not Be Empty", Toast.LENGTH_SHORT).show() }else{ var ref = FirebaseDatabase.getInstance().getReference("Offers") val key = ref.push().key val model = OfferModel(uid!!,key!!,title, price,imgUri.toString(),description) ref.child(uid!!).setValue(model) Toast.makeText(this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show() finish() } } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) try { imgUri = data!!.data!! profileImage.setImageURI(imgUri) } catch (e: Exception) { } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Activities/MakeAnOffer.kt
1380698927
package com.ese12.gilgitapp class Logic { }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/Logic.kt
2025318251
package com.ese12.gilgitapp.domain import com.ese12.gilgitapp.domain.models.OrderModel import com.ese12.gilgitapp.domain.models.ProductModel import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase object BuySellUtil { var database = FirebaseDatabase.getInstance().reference // Assume this method fetches the user's cart and processes the purchase // OrderModel(key,System.currentTimeMillis(),quantity*product.price ,quantity,product,buyerUid ,OrderStatus.PENDING,location,) suspend fun processPurchase(orderModel: OrderModel): MyResult { // Step 1: Decrease stock amount val decreaseResult = decreaseInStock(orderModel.productModel, orderModel.quantity) if (decreaseResult is MyResult.Error) { // Handle the error (e.g., insufficient stock) return decreaseResult } var key = database.child("pendingOrders").push().key.toString() // Step 2: Add product to seller's pendingOrders val addToPendingOrdersResult = addToSellerAndBuyerPendingOrders(orderModel) if (addToPendingOrdersResult is MyResult.Error) { // Handle the error (e.g., unable to add to pendingOrders) return addToPendingOrdersResult } // Step 3: Notify the seller notifySeller(orderModel) // Step 4: Remove the purchased items from the user's cart val removeFromCartResult = removeFromCart(orderModel.buyerUid, orderModel.productModel, orderModel.quantity) if (removeFromCartResult is MyResult.Error) { // Handle the error (e.g., unable to remove from cart) return removeFromCartResult } return MyResult.Success("Purchase processed successfully") } private suspend fun decreaseInStock(product: ProductModel, amount: Double): MyResult { val reference: DatabaseReference = database.child("products/${product.modelName}/${product.key}") return try { // Fetch the current stock amount val currentStock = product.stockAmount.toDouble() // Check if there's enough stock if (currentStock >= amount) { // Calculate the new stock amount after decrease val newStock = currentStock - amount // Update the stock amount in the database reference.child("stockAmount").setValue(newStock) MyResult.Success("Stock updated successfully") } else { MyResult.Error("Not enough stock available") } } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to update stock: ${e.message}") } } private suspend fun addToSellerAndBuyerPendingOrders(orderModel: OrderModel): MyResult { val buyerRef = database.child("pendingOrders/${orderModel.buyerUid}") val sellerRef = database.child("pendingOrders/${orderModel.productModel.sellerUid}") return try { buyerRef.child(orderModel.key).setValue(orderModel) sellerRef.child(orderModel.key).setValue(orderModel) MyResult.Success("Product added to seller's and buyer's pending orders successfully") } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to add product to seller's and buyer's pending orders: ${e.message}") } } private suspend fun notifySeller(orderModel: OrderModel) : MyResult { val buyerRef = database.child("notifications/${orderModel.buyerUid}") val sellerRef = database.child("notifications/${orderModel.productModel.sellerUid}") return try { buyerRef.child(orderModel.key).setValue(orderModel) sellerRef.child(orderModel.key).setValue(orderModel) MyResult.Success("Product added to seller's and buyer's pending orders successfully") } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to add product to seller's and buyer's pending orders: ${e.message}") } } private suspend fun removeFromCart(userId: String, product: ProductModel, quantity: Double): MyResult { // Implementation of removeFromCart function // ... return try { MyResult.Success("Product added to seller's and buyer's pending orders successfully") } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to add product to seller's and buyer's pending orders: ${e.message}") } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/BuySellUtil.kt
1642912837
package com.ese12.gilgitapp.domain sealed class MyResult { data class Success(val message: String) : MyResult() data class Error(val message: String) : MyResult() }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/MyResult.kt
4041505613
package com.ese12.gilgitapp.domain.models import android.location.Location import com.google.android.material.internal.ManufacturerUtils data class VehicleModel( val key: String = "", // Unique identifier for the product val name: String = "", // Product name val description: String = "", // Product description val price: Int = 0, // Product price val timeStamp: String = "", // time val category: String = "", // Category or type of the product val location: String = "", // Category or type of the product val city: String = "", // Category or type of the product val rating: Int = 0, // Average user rating val views: Int = 0, // Average user rating val inStock: Boolean = true, // Availability status val manufacturer: String = "", val warranty: String = "", val Negotiable: Boolean = true, val condition: String = "", val availableForMarcha: Boolean = true, val model: String = "", val imageUrl1: String = "", val additionalDetails: String = "", val imageUrl2: String = "", val imageUrl3: String = "", val imageUrl4: String = "", val imageUrl5: String = "", )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/VehicleModel.kt
3560385840
package com.ese12.gilgitapp.domain.models data class MobilesModel( val key1: String , // Unique identifier for the product val name: String = "", // Product name val description: String = "", // Product description val price: Int = 0, // Product price val timeStamp: String = "", // time val category1: String = "", // Category or type of the product val location: String = "", // Category or type of the product val city: String = "", // Category or type of the product val rating: Int = 0, // Average user rating val views: Int = 0, // Average user rating val inStock: Boolean = true, // Availability status val manufacturer: String = "", val warranty: String = "", val Negotiable: Boolean = true, val condition: String = "", val availableForMarcha: Boolean = true, val model: String = "", val imageUrl1: String = "", val additionalDetails: String = "", val imageUrl2: String = "", val imageUrl3: String = "", val imageUrl4: String = "", val imageUrl5: String = "", )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/MobilesModel.kt
3390005504
package com.ese12.gilgitapp.domain.models data class ReviewModel( val key: String, val productKey: String, val userId: String, val userName: String, // Assuming you want to store the user's name val rating: Int, // Rating given by the user (e.g., out of 5 stars) val reviewText: String, val reviewDate: Long // Timestamp or date of the review )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/ReviewModel.kt
835734579
package com.ese12.gilgitapp.domain.models open class ProductModel( var key: String, var modelName: String, var title: String, var price: Double, var timeStamp: String, var stockAmount: Double, var sellerUid: String, )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/ProductModel.kt
3582316770
package com.ese12.gilgitapp.domain.models import android.location.Location import com.google.android.material.internal.ManufacturerUtils data class FeaturedModel( val key: String = "", // Unique identifier for the product val name: String = "", // Product name val description: String = "", // Product description val price: Int = 0, // Product price val timeStamp: String = "", // time val category: String = "", // Category or type of the product val location: String = "", // Category or type of the product val city: String = "", // Category or type of the product val rating: Int = 0, // Average user rating val views: Int = 0, // Average user rating val inStock: Boolean = true, // Availability status val manufacturer: String = "", val warranty: String = "", val Negotiable: Boolean = true, val condition: String = "", val availableForMarcha: Boolean = true, val model: String = "", val imageUrl1: String = "", val additionalDetails: String = "", val imageUrl2: String = "", val imageUrl3: String = "", val imageUrl4: String = "", val imageUrl5: String = "", )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/FeaturedModel.kt
565344628
package com.ese12.gilgitapp.domain.models import android.location.Location import com.google.android.material.internal.ManufacturerUtils data class RealEstateModel( val key: String = "", // Unique identifier for the product val name: String = "", // Product name val description: String = "", // Product description val price: Int = 0, // Product price val timeStamp: String = "", // time val category: String = "", // Category or type of the product val location: String = "", // Category or type of the product val city: String = "", // Category or type of the product val rating: Int = 0, // Average user rating val views: Int = 0, // Average user rating val inStock: Boolean = true, // Availability status val manufacturer: String = "", val warranty: String = "", val Negotiable: Boolean = true, val condition: String = "", val availableForMarcha: Boolean = true, val model: String = "", val imageUrl1: String = "", val additionalDetails: String = "", val imageUrl2: String = "", val imageUrl3: String = "", val imageUrl4: String = "", val imageUrl5: String = "", )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/RealEstateModel.kt
2860752033
package com.ese12.gilgitapp.domain.models import android.location.Location import com.google.android.material.internal.ManufacturerUtils data class PetsModel( val key: String = "", // Unique identifier for the product val name: String = "", // Product name val description: String = "", // Product description val price: Int = 0, // Product price val timeStamp: String = "", // time val category: String = "", // Category or type of the product val location: String = "", // Category or type of the product val city: String = "", // Category or type of the product val rating: Int = 0, // Average user rating val views: Int = 0, // Average user rating val inStock: Boolean = true, // Availability status val manufacturer: String = "", val warranty: String = "", val Negotiable: Boolean = true, val condition: String = "", val availableForMarcha: Boolean = true, val model: String = "", val imageUrl1: String = "", val additionalDetails: String = "", val imageUrl2: String = "", val imageUrl3: String = "", val imageUrl4: String = "", val imageUrl5: String = "", )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/PetsModel.kt
1889148742
package com.ese12.gilgitapp.domain.models data class UserModel( val userUid: String, var userName: String, var email: String, var profileImage: String?, var phone: String?, var city: String?, var location: String )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/UserModel.kt
3350044283
package com.ese12.gilgitapp.domain.models //data class BuyerRequestModel( // val key: String = "", // Unique identifier for the product // val owner:String = "", // val name: String = "", // Product name // val description: String = "", // Product description // val price: Int = 0, // Product price // val timeStamp: String = "", // time // val category: String = "", // Category or type of the product // val location: String = "", // Category or type of the product // val city: String = "", // Category or type of the product // val rating: Int = 0, // Average user rating // val views: Int = 0, // Average user rating // val inStock: Boolean = true, // Availability status // val manufacturer: String = "", // val warranty: String = "", // val Negotiable: Boolean = true, // val condition: String = "", // val availableForMarcha: Boolean = true, // val model: String = "", // val imageUrl1: String = "", // val additionalDetails: String = "", // val imageUrl2: String = "", // val imageUrl3: String = "", // val imageUrl4: String = "", // val imageUrl5: String = "", //) data class BuyerRequestModel( val uid: String = "", val userName: String = "", val profileImage: String = "", val looking_item: String = "", val category: String = "", val price: Int = 0, var location: String = "" )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/BuyerRequestModel.kt
21131252
package com.ese12.gilgitapp.domain.models enum class OrderStatus { INCART, ACCEPTED, PENDING, PROCESSING, SHIPPING, DELIVERED, CANCELED }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/OrderStatus.kt
3967374341
package com.ese12.gilgitapp.domain.models data class CartModel ( var key: String, val buyerUid: String, val timeStamp: Long, // Timestamp or date val totalPrice: Double, val quantity: Double, val productModel: ProductModel, ) // history/userUid/productModel
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/CartModel.kt
132390641
package com.ese12.gilgitapp.domain.models data class OrderModel( val key: String, val orderDate: Long, // Timestamp or date val totalPrice: Double, val quantity: Double, val productModel: ProductModel, val buyerUid: String, val status: OrderStatus, val deliveryAddress: String, val deliveryLocation: String, )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/models/OrderModel.kt
3172359241
package com.ese12.gilgitapp.domain enum class MyCategory { MOBILES, CARS, BIKES, }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/MyCategory.kt
2989706640
package com.ese12.gilgitapp.domain data class FilterOptions( val modelName: String?, val minPrice: Double?, val maxPrice: Double?, val sortBy: SortByOption? )
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/FilterOptions.kt
3166804252
package com.ese12.gilgitapp.domain enum class SortByOption { PRICE_LOW_TO_HIGH, PRICE_HIGH_TO_LOW, NAME_A_TO_Z, NAME_Z_TO_A, OLDER, NEWER, }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/SortByOption.kt
606110993
package com.ese12.gilgitapp.domain import android.graphics.Bitmap import java.io.ByteArrayOutputStream class Util { companion object{ fun bitmapToByteArray(bitmap: Bitmap): ByteArray { val stream = ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream) // You can change the format and quality here return stream.toByteArray() } } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/domain/Util.kt
1266746409
package com.ese12.gilgitapp.repo import android.graphics.Bitmap import com.ese12.gilgitapp.domain.models.* import com.ese12.gilgitapp.domain.FilterOptions import com.ese12.gilgitapp.domain.MyResult import com.ese12.gilgitapp.domain.MyCategory import kotlinx.coroutines.flow.Flow interface MainRepository { suspend fun uploadImageToFirebaseStorage(uri:String): MyResult suspend fun uploadImageToFirebaseStorage(bitmap: Bitmap): MyResult suspend fun deleteImageToFirebaseStorage(url: String): MyResult suspend fun uploadProduct(productModel: ProductModel): MyResult suspend fun updateProduct(productModel: ProductModel): MyResult suspend fun deleteProduct(productModel: ProductModel): MyResult suspend fun getProductDetailsByKey(key: String): ProductModel suspend fun getUserDetailsByUid(uid: String): UserModel suspend fun getAllProductsList(): List<ProductModel> fun collectAllProductsList(): Flow<List<ProductModel>> fun collectProductsByModel(myCategory: MyCategory): Flow<List<ProductModel>> suspend fun getProductsOfCategory(myCategory: MyCategory): List<ProductModel> suspend fun filterProducts(filters: FilterOptions): List<ProductModel> fun collectCartItems(userId: String): Flow<List<ProductModel>> suspend fun decreaseInStock(product: ProductModel, amount:Int): MyResult suspend fun increaseInStock(product: ProductModel, amount:Int): MyResult suspend fun addToCart(cartModel: CartModel): MyResult // also seller to see who added in is cart his products suspend fun updateToCart(cartModel: CartModel): MyResult // change the quantity etc suspend fun deleteFromCart(cartModel: CartModel): MyResult // when order is completed or canceled suspend fun getCartDetailsByKey(userUid: String , key: String): CartModel // when order is completed or canceled suspend fun buy( orderModel: OrderModel): MyResult suspend fun deliver( orderModel: OrderModel): MyResult // handle his cart and change status suspend fun removeFromCart(userId: String, productId: String): MyResult suspend fun placeOrder(userId: String, cartItems: List<ProductModel>): Flow<OrderModel> suspend fun getOrderHistory(userId: String): Flow<List<OrderModel>> suspend fun addToOrderHistory(orderModel: OrderModel): Flow<List<OrderModel>> suspend fun addToFavorites(userId: String, productKey: String): MyResult suspend fun removeFromFavorites(userId: String, productId: String): MyResult fun collectProductReviews(productId: String): Flow<List<ReviewModel>> suspend fun submitProductReview(productId: String, review: ReviewModel): MyResult fun getUserInfoByKey(key: String): Flow<UserModel> fun getProductByKey(key: String): Flow<UserModel> }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/repo/MainRepository.kt
3748003228
package com.ese12.gilgitapp.repo import android.graphics.Bitmap import android.net.Uri import com.ese12.gilgitapp.domain.FilterOptions import com.ese12.gilgitapp.domain.MyCategory import com.ese12.gilgitapp.domain.MyResult import com.ese12.gilgitapp.domain.SortByOption import com.ese12.gilgitapp.domain.models.* import com.ese12.gilgitapp.domain.Util.Companion.bitmapToByteArray import com.google.firebase.storage.FirebaseStorage import com.google.firebase.storage.StorageReference import com.google.firebase.storage.UploadTask import com.google.android.gms.tasks.Task import com.google.android.gms.tasks.Tasks import com.google.firebase.database.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.tasks.await import kotlinx.coroutines.withContext class MainRepositoryImpl : MainRepository { private val storage = FirebaseStorage.getInstance() private val storageReference: StorageReference = storage.reference private val database = FirebaseDatabase.getInstance() override suspend fun uploadImageToFirebaseStorage(uri: String): MyResult { return try { // Upload an image from a file URI to Firebase Storage val imageRef = storageReference.child("images/${System.currentTimeMillis()}.jpg") val uploadTask = imageRef.putFile(Uri.parse(uri)) // Wait for the upload to complete val result: UploadTask.TaskSnapshot = uploadTask.await() // Get the download URL of the uploaded image val downloadUrl = result.storage.downloadUrl.await() // Return a Success with the download URL as a String MyResult.Success(downloadUrl.toString()) } catch (e: Exception) { // In case of an error, return an Error instance with the error message MyResult.Error(e.message ?: "Unknown error occurred") } } override suspend fun uploadImageToFirebaseStorage(bitmap: Bitmap): MyResult { return try { // Convert the Bitmap to a ByteArray val byteArray = bitmapToByteArray(bitmap) // Upload the ByteArray to Firebase Storage val imageRef = storageReference.child("images/${System.currentTimeMillis()}.jpg") val uploadTask = imageRef.putBytes(byteArray) // Wait for the upload to complete val result: UploadTask.TaskSnapshot = uploadTask.await() // Get the download URL of the uploaded image val downloadUrl = result.storage.downloadUrl.await() // Return a Success with the download URL as a String MyResult.Success(downloadUrl.toString()) } catch (e: Exception) { // In case of an error, return an Error instance with the error message MyResult.Error(e.message ?: "Unknown error occurred") } } override suspend fun deleteImageToFirebaseStorage(url: String): MyResult { return try { val storage = FirebaseStorage.getInstance() val storageRef = storage.getReferenceFromUrl(url) val deleteTask: Task<Void> = storageRef.delete() Tasks.await(deleteTask) // If the task completes without an exception, consider it a success MyResult.Success("Image deleted successfully") } catch (e: Exception) { // Handle the exception or error here and return an Error result e.printStackTrace() // Replace this with proper error handling MyResult.Error("Failed to delete image: ${e.message}") } } override suspend fun uploadProduct(productModel: ProductModel): MyResult { val reference: DatabaseReference = database.getReference("products").child(productModel.modelName) return try { val k = reference.push().key // Set the value of the product using await to wait for the operation to complete reference.child(k!!).setValue(productModel).await() // Return a success MyResult MyResult.Success("Product uploaded successfully") } catch (e: Exception) { // Handle any errors and return an Error MyResult e.printStackTrace() // Replace this with proper error handling MyResult.Error("Failed to upload product: ${e.message}") } } override suspend fun updateProduct(productModel: ProductModel): MyResult { val reference: DatabaseReference = database.getReference("products").child(productModel.modelName) return try { // Set the value of the product using await to wait for the operation to complete reference.child(productModel.key).setValue(productModel).await() // Return a success MyResult MyResult.Success("Product uploaded successfully") } catch (e: Exception) { // Handle any errors and return an Error MyResult e.printStackTrace() // Replace this with proper error handling MyResult.Error("Failed to upload product: ${e.message}") } } override suspend fun deleteProduct(productModel: ProductModel): MyResult { // Assuming you have a reference to the database val reference: DatabaseReference = database.getReference("products") return try { val key = productModel.key // Assuming 'key' is the property within ProductModel containing the unique key if (key != null) { reference.child(key).removeValue().await() MyResult.Success("Product deleted successfully") } else { MyResult.Error("Invalid key for product") } } catch (e: Exception) { e.printStackTrace() // Replace this with proper error handling MyResult.Error("Failed to delete product: ${e.message}") } } override suspend fun getProductDetailsByKey(key: String): ProductModel { TODO("Not yet implemented") } override suspend fun getUserDetailsByUid(key: String): UserModel { TODO("Not yet implemented") } override suspend fun getAllProductsList(): List<ProductModel> { return try { val reference: DatabaseReference = database.getReference("products") val productList = mutableListOf<ProductModel>() val snapshot = reference.get().await() for (categorySnapshot in snapshot.children) { for (modelSnapshot in categorySnapshot.children) { val product = modelSnapshot.getValue(ProductModel::class.java) product?.let { productList.add(it) } } } productList } catch (e: Exception) { // Handle the exception or log the error emptyList() // Return an empty list or handle the error according to your use case } } override fun collectAllProductsList(): Flow<List<ProductModel>> = callbackFlow { val reference: DatabaseReference = database.getReference("products") val eventListener = object : ValueEventListener { override fun onDataChange(snapshot: DataSnapshot) { val productList = mutableListOf<ProductModel>() for (categorySnapshot in snapshot.children) { for (modelSnapshot in categorySnapshot.children) { val product = modelSnapshot.getValue(ProductModel::class.java) product?.let { productList.add(it) } } } try { trySend(productList).isSuccess // Emit the list of ProductModel objects to the flow close() // Close the flow when data emission is completed } catch (e: Exception) { close(e) // Close the flow with an exception if emission fails } } override fun onCancelled(error: DatabaseError) { close(error.toException()) // Close the flow with an exception in case of cancellation } } reference.addListenerForSingleValueEvent(eventListener) awaitClose { reference.removeEventListener(eventListener) } } override fun collectProductsByModel(myCategory: MyCategory): Flow<List<ProductModel>> = callbackFlow { val reference: DatabaseReference = database.getReference("products").child(myCategory.name) val eventListener = object : ValueEventListener { override fun onDataChange(categorySnapshot: DataSnapshot) { val productList = mutableListOf<ProductModel>() for (modelSnapshot in categorySnapshot.children) { val product = modelSnapshot.getValue(ProductModel::class.java) product?.let { productList.add(it) } } try { trySend(productList).isSuccess // Emit the list of ProductModel objects to the flow close() // Close the flow when data emission is completed } catch (e: Exception) { close(e) // Close the flow with an exception if emission fails } } override fun onCancelled(error: DatabaseError) { close(error.toException()) // Close the flow with an exception in case of cancellation } } reference.addListenerForSingleValueEvent(eventListener) awaitClose { reference.removeEventListener(eventListener) } } override suspend fun getProductsOfCategory(category: MyCategory): List<ProductModel> { return try { val reference: DatabaseReference = database.getReference("products").child(category.name) val productList = mutableListOf<ProductModel>() val categorySnapshot = reference.get().await() for (modelSnapshot in categorySnapshot.children) { val product = modelSnapshot.getValue(ProductModel::class.java) product?.let { productList.add(it) } } productList } catch (e: Exception) { // Handle the exception or log the error emptyList() // Return an empty list or handle the error according to your use case } } override suspend fun filterProducts(filters: FilterOptions): List<ProductModel> { val allProducts = getAllProductsList() return allProducts.filter { product -> // Apply filters based on FilterOptions val categoryMatch = filters.modelName.isNullOrBlank() || product.modelName == filters.modelName val minPriceMatch = filters.minPrice == null || product.price >= filters.minPrice val maxPriceMatch = filters.maxPrice == null || product.price <= filters.maxPrice categoryMatch && minPriceMatch && maxPriceMatch }.sortedWith(getProductComparator(filters.sortBy) ?: compareBy { it.timeStamp }) } private fun getProductComparator(sortBy: SortByOption?): Comparator<ProductModel>? { return when (sortBy) { SortByOption.PRICE_LOW_TO_HIGH -> compareBy { it.price } SortByOption.PRICE_HIGH_TO_LOW -> compareByDescending { it.price } SortByOption.NAME_A_TO_Z -> compareBy { it.title } SortByOption.NAME_Z_TO_A -> compareByDescending { it.title } SortByOption.OLDER -> compareBy { it.timeStamp } SortByOption.NEWER -> compareByDescending { it.timeStamp } else -> null } } override fun collectCartItems(userUid: String): Flow<List<ProductModel>> = callbackFlow { val reference: DatabaseReference = database.getReference("cart").child(userUid) val eventListener = object : ValueEventListener { override fun onDataChange(snapshot: DataSnapshot) { val productList = mutableListOf<ProductModel>() for (categorySnapshot in snapshot.children) { for (modelSnapshot in categorySnapshot.children) { val product = modelSnapshot.getValue(ProductModel::class.java) product?.let { productList.add(it) } } } try { trySend(productList).isSuccess // Emit the list of ProductModel objects to the flow close() // Close the flow when data emission is completed } catch (e: Exception) { close(e) // Close the flow with an exception if emission fails } } override fun onCancelled(error: DatabaseError) { close(error.toException()) // Close the flow with an exception in case of cancellation } } reference.addListenerForSingleValueEvent(eventListener) awaitClose { reference.removeEventListener(eventListener) } } override suspend fun decreaseInStock(product: ProductModel, amount: Int): MyResult { val reference: DatabaseReference = database.getReference("products/${product.modelName}/${product.key}") try { // Fetch the current stock amount val currentStock = product.stockAmount if (currentStock >= amount) { // Calculate the new stock amount after decrease val newStock = currentStock - amount // Update the stock amount in the database reference.child("stockAmount").setValue(newStock) return MyResult.Success("Stock updated successfully") } else { return MyResult.Error("Not enough stock available") } } catch (e: Exception) { e.printStackTrace() return MyResult.Error("Failed to update stock: ${e.message}") } } override suspend fun increaseInStock(product: ProductModel, amount: Int): MyResult { val database = FirebaseDatabase.getInstance() val reference: DatabaseReference = database.getReference("products/${product.modelName}/${product.key}") return try { // Fetch the current stock amount val currentStock = product.stockAmount // Calculate the new stock amount after increase val newStock = currentStock + amount // Update the stock amount in the database reference.child("stockAmount").setValue(newStock) MyResult.Success("Stock updated successfully") } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to update stock: ${e.message}") } } override suspend fun addToCart(cartModel: CartModel): MyResult { cartModel.key = cartModel.productModel.key val reference: DatabaseReference = database.getReference("userCarts/${cartModel.buyerUid}/${cartModel.key}") return try { // Update the cart entry in the user's cart in the database reference.setValue(cartModel) MyResult.Success("Product added to cart successfully") } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to add product to cart: ${e.message}") } } override suspend fun updateToCart(cartModel: CartModel): MyResult { TODO("Not yet implemented") } override suspend fun deleteFromCart(cartModel: CartModel): MyResult { TODO("Not yet implemented") } override suspend fun getCartDetailsByKey(userUid: String, key: String): CartModel { TODO("Not yet implemented") } override suspend fun buy(orderModel: OrderModel): MyResult { val userId = orderModel.buyerUid val cartReference: DatabaseReference = database.getReference("userCarts/$userId/${orderModel.productModel.key}") return try { // Fetch the current quantity in the cart // var cart // val currentQuantity = orderModel.productModel.cartQuantity.toInt() // // // Check if there's enough quantity in the cart // if (currentQuantity >= orderModel.quantity) { // // Calculate the new quantity in the cart after purchase // val newQuantity = currentQuantity - orderModel.quantity.toInt() // // // Update the quantity in the user's cart // cartReference.child("cartQuantity").setValue(newQuantity) // // // Create an order // val orderKey = generateOrderKey() // val orderReference: DatabaseReference = database.getReference("orders/$orderKey") // // // Set the order key before saving to Firebase // orderModel.key = orderKey // // orderReference.setValue(orderModel) // MyResult.Success("Order placed successfully") // } else { // MyResult.Error("Not enough quantity available in the cart") // } } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to place order: ${e.message}") } } override suspend fun deliver(orderModel: OrderModel): MyResult { return try { // Fetch the current quantity in the cart // var cart // val currentQuantity = orderModel.productModel.cartQuantity.toInt() // // // Check if there's enough quantity in the cart // if (currentQuantity >= orderModel.quantity) { // // Calculate the new quantity in the cart after purchase // val newQuantity = currentQuantity - orderModel.quantity.toInt() // // // Update the quantity in the user's cart // cartReference.child("cartQuantity").setValue(newQuantity) // // // Create an order // val orderKey = generateOrderKey() // val orderReference: DatabaseReference = database.getReference("orders/$orderKey") // // // Set the order key before saving to Firebase // orderModel.key = orderKey // // orderReference.setValue(orderModel) MyResult.Success("Order placed successfully") // } else { // MyResult.Error("Not enough quantity available in the cart") // } } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to place order: ${e.message}") } } override suspend fun removeFromCart(userId: String, productId: String): MyResult { val reference: DatabaseReference = database.getReference("userCarts/$userId/$productId") return try { // Remove the product from the user's cart in the database reference.removeValue() MyResult.Success("Product removed from cart successfully") } catch (e: Exception) { e.printStackTrace() MyResult.Error("Failed to remove product from cart: ${e.message}") } } override suspend fun placeOrder( userId: String, cartItems: List<ProductModel> ): Flow<OrderModel> { TODO("Not yet implemented") } override suspend fun getOrderHistory(userId: String): Flow<List<OrderModel>> { TODO("Not yet implemented") } override suspend fun addToOrderHistory(orderModel: OrderModel): Flow<List<OrderModel>> { TODO("Not yet implemented") } override suspend fun addToFavorites(userId: String, productKey: String): MyResult { TODO("Not yet implemented") } override suspend fun removeFromFavorites(userId: String, productId: String): MyResult { TODO("Not yet implemented") } override fun collectProductReviews(productId: String): Flow<List<ReviewModel>> { TODO("Not yet implemented") } override suspend fun submitProductReview(productId: String, review: ReviewModel): MyResult { TODO("Not yet implemented") } override fun getUserInfoByKey(key: String): Flow<UserModel> { TODO("Not yet implemented") } override fun getProductByKey(key: String): Flow<UserModel> { TODO("Not yet implemented") } }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/repo/MainRepositoryImpl.kt
2108982211
package com.ese12.gilgitapp.repo import com.ese12.gilgitapp.domain.MyResult import com.ese12.gilgitapp.domain.models.UserModel interface AuthRepository { suspend fun signInWithMailAndPassword(userModel: UserModel): MyResult suspend fun signInWithPhone(userModel: UserModel): MyResult suspend fun signUpWithMailAndPassword(userModel: UserModel): UserModel suspend fun signOut(): MyResult }
Ghizer_App/app/src/main/java/com/ese12/gilgitapp/repo/AuthRepository.kt
3097889289
package com.jemutai.simpleapp import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.jemutai.simpleapp", appContext.packageName) } }
Simple-App/app/src/androidTest/java/com/jemutai/simpleapp/ExampleInstrumentedTest.kt
147863138
package com.jemutai.simpleapp import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
Simple-App/app/src/test/java/com/jemutai/simpleapp/ExampleUnitTest.kt
576764179
package com.jemutai.simpleapp // Extensions.kt import androidx.compose.runtime.MutableState import androidx.compose.runtime.State fun <T> MutableState<T>.collectAsState(): T { return this.value }
Simple-App/app/src/main/java/com/jemutai/simpleapp/Extension.kt
3008459634
package com.jemutai.simpleapp.ui.theme import androidx.compose.ui.graphics.Color val Purple80 = Color(0xFFD0BCFF) val PurpleGrey80 = Color(0xFFCCC2DC) val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) val Pink40 = Color(0xFF7D5260)
Simple-App/app/src/main/java/com/jemutai/simpleapp/ui/theme/Color.kt
465540253
package com.jemutai.simpleapp.ui.theme import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80 ) private val LightColorScheme = lightColorScheme( primary = Purple40, secondary = PurpleGrey40, tertiary = Pink40 /* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), onPrimary = Color.White, onSecondary = Color.White, onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), */ ) @Composable fun SimpleAppTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -> Unit ) { val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) } darkTheme -> DarkColorScheme else -> LightColorScheme } val view = LocalView.current if (!view.isInEditMode) { SideEffect { val window = (view.context as Activity).window window.statusBarColor = colorScheme.primary.toArgb() WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme } } MaterialTheme( colorScheme = colorScheme, typography = Typography, content = content ) }
Simple-App/app/src/main/java/com/jemutai/simpleapp/ui/theme/Theme.kt
2737321651
package com.jemutai.simpleapp.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp // Set of Material typography styles to start with val Typography = Typography( bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, letterSpacing = 0.5.sp ) /* Other default text styles to override titleLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 22.sp, lineHeight = 28.sp, letterSpacing = 0.sp ), labelSmall = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Medium, fontSize = 11.sp, lineHeight = 16.sp, letterSpacing = 0.5.sp ) */ )
Simple-App/app/src/main/java/com/jemutai/simpleapp/ui/theme/Type.kt
3239624271
package com.jemutai.simpleapp import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.viewModels import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.jemutai.simpleapp.ui.theme.SimpleAppTheme import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainActivity : ComponentActivity() { private val viewModel: PostViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { // val posts by viewModel.posts.collectAsState() // PostList(posts = posts) } } }
Simple-App/app/src/main/java/com/jemutai/simpleapp/MainActivity.kt
3024609727
package com.jemutai.simpleapp import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.android.HiltAndroidApp import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import javax.inject.Singleton @Module //@InstallIn(ApplicationComponent::class) object AppModule { @Provides @Singleton fun provideApiService(): ApiService { return Retrofit.Builder() .baseUrl("https://jsonplaceholder.typicode.com/") .addConverterFactory(GsonConverterFactory.create()) .build() .create(ApiService::class.java) } @Provides @Singleton fun providePostRepository(apiService: ApiService): PostRepository { return PostRepositoryImpl(apiService) } }
Simple-App/app/src/main/java/com/jemutai/simpleapp/AppModule.kt
475755390
package com.jemutai.simpleapp import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class PostViewModel @Inject constructor( private val postRepository: PostRepository ) : ViewModel() { val posts: MutableState<List<Post>> = mutableStateOf(emptyList()) init { viewModelScope.launch { posts.value = postRepository.getPosts() } } }
Simple-App/app/src/main/java/com/jemutai/simpleapp/PostViewModel.kt
2145979224
package com.jemutai.simpleapp interface PostRepository { suspend fun getPosts(): List<Post> }
Simple-App/app/src/main/java/com/jemutai/simpleapp/PostRepository.kt
3344267140
package com.jemutai.simpleapp data class Post( val id: Int, val userId: Int, val title: String, // Adding title property val body: String )
Simple-App/app/src/main/java/com/jemutai/simpleapp/Post.kt
3019764239
package com.jemutai.simpleapp import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.runtime.Composable @Composable fun PostList(posts: List<Post>) { LazyColumn { items(posts) { post -> Text(text = post.title) } } }
Simple-App/app/src/main/java/com/jemutai/simpleapp/PostList.kt
2729001844
package com.jemutai.simpleapp import retrofit2.http.GET interface ApiService { @GET("posts") suspend fun getPosts(): List<Post> }
Simple-App/app/src/main/java/com/jemutai/simpleapp/ApiService.kt
116885093
package com.jemutai.simpleapp class PostRepositoryImpl(private val apiService: ApiService) : PostRepository { override suspend fun getPosts(): List<Post> { return apiService.getPosts() } }
Simple-App/app/src/main/java/com/jemutai/simpleapp/PostRepositoryImp.kt
2168195595
package com.example.eduapp_nur import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.eduapp_nur", appContext.packageName) } }
Something/app/src/androidTest/java/com/example/eduapp_nur/ExampleInstrumentedTest.kt
2543246008
package com.example.eduapp_nur import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
Something/app/src/test/java/com/example/eduapp_nur/ExampleUnitTest.kt
137157637
package com.example.eduapp_nur import androidx.appcompat.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }
Something/app/src/main/java/com/example/eduapp_nur/MainActivity.kt
3468143394
package com.example.eduapp_nur.fragments.settings import android.os.Bundle import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class UserAccountFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/settings/UserAccountFragment.kt
981516904
package com.example.eduapp_nur.fragments.settings import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class AllOrdersFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/settings/AllOrdersFragment.kt
915994091
package com.example.eduapp_nur.fragments.settings import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment class OrderDetailFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/settings/OrderDetailFragment.kt
2234170552
package com.example.eduapp_nur.fragments.shopping import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class ProductDetailsFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/ProductDetailsFragment.kt
3986347926
package com.example.eduapp_nur.fragments.shopping import android.os.Bundle import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class BillingFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/BillingFragment.kt
1648564197
package com.example.eduapp_nur.fragments.shopping import androidx.fragment.app.Fragment import com.example.eduapp_nur.R class SearchFragment: Fragment(R.layout.fragment_search) { }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/SearchFragment.kt
2974437374
package com.example.eduapp_nur.fragments.shopping import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R class CartFragment : Fragment(R.layout.fragment_cart) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/CartFragment.kt
792105931
package com.example.eduapp_nur.fragments.shopping import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R class HomeFragment : Fragment(R.layout.fragment_home) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/HomeFragment.kt
1228524232
package com.example.eduapp_nur.fragments.shopping import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class ProfileFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/ProfileFragment.kt
499109631
package com.example.eduapp_nur.fragments.shopping import android.os.Bundle import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class AddressFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/shopping/AddressFragment.kt
4086842827
package com.example.eduapp_nur.fragments.lognRegister import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class LoginFragment : Fragment(R.layout.fragment_login) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/lognRegister/LoginFragment.kt
1213505062
package com.example.eduapp_nur.fragments.lognRegister import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class IntroductionFragment : Fragment(R.layout.fragment_introdcution) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/lognRegister/IntroductionFragment.kt
2364194246
package com.example.eduapp_nur.fragments.lognRegister import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class RegisterFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/lognRegister/RegisterFragment.kt
385761541
package com.example.eduapp_nur.fragments.lognRegister import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R class AccountOptionsFragment: Fragment(R.layout.fragment_account_options) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/lognRegister/AccountOptionsFragment.kt
2092888438
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class AccessoryFragment: BaseCategoryFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } override fun onBestProductsPagingRequest() { } override fun onOfferPagingRequest() { } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/AccessoryFragment.kt
3208778335
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R open class BaseCategoryFragment: Fragment(R.layout.fragment_base_category) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/BaseCategoryFragment.kt
406187670
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class CupboardFragment: BaseCategoryFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/CupboardFragment.kt
3635381230
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class ChairFragment : BaseCategoryFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/ChairFragment.kt
1472172463
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment import com.example.eduapp_nur.R import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainCategoryFragment : Fragment(R.layout.fragment_main_category) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/MainCategoryFragment.kt
3412458435
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class FurnitureFragment: BaseCategoryFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/FurnitureFragment.kt
609240506
package com.example.eduapp_nur.fragments.categories import android.os.Bundle import android.view.View import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class TableFragment: BaseCategoryFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) } }
Something/app/src/main/java/com/example/eduapp_nur/fragments/categories/TableFragment.kt
3243948743
package com.puffy.util import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.text.Text import net.minecraft.util.Formatting fun ServerPlayerEntity.disconnectForExploit(mitigationName: String) { val headerStart = Text.literal("PAE - ").formatted(Formatting.GOLD, Formatting.BOLD) val packetName = Text.literal(mitigationName).formatted(Formatting.DARK_PURPLE) val headerEnd = Text.literal("\n\n").formatted(Formatting.GOLD, Formatting.BOLD) val message = Text.literal( "Too much suspicious activity was generated from you.\nThis can be the result from using a hacked or 'utility' client.\nVerify your client's integrity and rejoin." ) val disconnectText = Text.empty().append(headerStart).append(packetName).append(headerEnd).append(message) this.networkHandler.disconnect(disconnectText) }
puffy-anti-exploit/src/main/kotlin/com/puffy/util/DisconnectForExploit.kt
2930232651
package com.puffy.util fun <T> MutableList<T>.trimToLength(length: Int) { if (this.count() >= length) { this.removeAt(0) } }
puffy-anti-exploit/src/main/kotlin/com/puffy/util/TrimToLength.kt
696927139
package com.puffy.util import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket fun PlayerInteractEntityC2SPacket.isAttack(): Boolean { return this.type.type == PlayerInteractEntityC2SPacket.InteractType.ATTACK }
puffy-anti-exploit/src/main/kotlin/com/puffy/util/IsInteractPacketAttack.kt
2172448486
package com.puffy.mitigations import com.puffy.events.DetectionEventEmitter import com.puffy.events.DetectionInfo import com.puffy.events.PacketEventEmitter import com.puffy.util.isAttack import kotlin.math.abs import kotlin.math.acos import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.EndTick import net.minecraft.entity.Entity import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket import net.minecraft.server.network.ServerPlayerEntity const val MAXIMUM_SUSPICIOUS_HITS_IN_PERIOD = 6 const val PERIOD_TIME_IN_TICKS = 150 const val AIM_DEGREE_TOLERANCE = 45 const val MAXIMUM_DISTANCE_METERS = 6 private const val MITIGATION_NAME = "KillAura" class AntiKillAuraMitigation(val player: ServerPlayerEntity) { private var suspiciousHitCountInPeriod = 0 private var periodTickCounter = 0 init { PacketEventEmitter.addListener(player, PlayerInteractEntityC2SPacket::class) { (_, packet) -> if (!packet.isAttack()) { return@addListener } val targetEntity = packet.getEntity(player.serverWorld) ?: return@addListener recordHitIfSuspicious(targetEntity) if (suspiciousHitCountInPeriod >= MAXIMUM_SUSPICIOUS_HITS_IN_PERIOD) { DetectionEventEmitter.sendEvent(DetectionInfo(MITIGATION_NAME, player)) } } ServerTickEvents.END_SERVER_TICK.register( EndTick { periodTickCounter++ if (periodTickCounter >= PERIOD_TIME_IN_TICKS) { suspiciousHitCountInPeriod = 0 periodTickCounter = 0 } } ) } private fun recordHitIfSuspicious(targetEntity: Entity) { if (isHitSuspicious(targetEntity)) { suspiciousHitCountInPeriod++ } } private fun isHitSuspicious(targetEntity: Entity): Boolean { if (!targetEntity.isAlive()) { return false } val playerEye = player.getCameraPosVec(0.0F) val playerLookVector = player.cameraEntity.getRotationVec(0.0F) val directionTowardsEntity = targetEntity.boundingBox.center.subtract(playerEye).normalize() val angleOfError = Math.toDegrees(acos(playerLookVector.dotProduct(directionTowardsEntity))) val distanceBetweenPlayerAndTarget = targetEntity.pos.squaredDistanceTo(player.pos) return abs(angleOfError) > AIM_DEGREE_TOLERANCE || distanceBetweenPlayerAndTarget > MAXIMUM_DISTANCE_METERS * MAXIMUM_DISTANCE_METERS || isTargetBehindWallFromPlayer(player, targetEntity) } private fun isTargetBehindWallFromPlayer( player: ServerPlayerEntity, targetEntity: Entity ): Boolean { return false // TODO: Make a way to do this well } }
puffy-anti-exploit/src/main/kotlin/com/puffy/mitigations/AntiKillAuraMitigation.kt
2528782095
package com.puffy.mitigations import com.puffy.events.DetectionEventEmitter import com.puffy.events.DetectionInfo import com.puffy.events.PacketEventEmitter import com.puffy.mitigations.antispeed.MagnitudeWeighter import com.puffy.util.trimToLength import kotlin.math.abs import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.EndTick import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket import net.minecraft.server.network.ServerPlayerEntity const val SLIDING_WINDOW_LENGTH = 20 const val MAXIMUM_AVERAGE_MAGNITUDE = 0.95 const val MAXIMUM_SUSPICIOUS_MAGNITUDE_TICKS = 25 // Used if minecraft reports a XYZ before the player loads (usually garbage) const val FALSE_MAGNITUDE_THRESHOLD = 100 private const val MITIGATION_NAME = "Speed" class AntiSpeedMitigation(val player: ServerPlayerEntity) { private var magnitudeWindow: MutableList<Double> = mutableListOf() private val averageMagnitude get() = magnitudeWindow.average() private var lastX = 0.0 private var lastY = 0.0 private var lastZ = 0.0 private var suspiciousMagnitudeTicks = 0 private var firstIteration = false init { PacketEventEmitter.addListener(player, PlayerMoveC2SPacket::class) { _ -> if (isSpeedHacking()) { DetectionEventEmitter.sendEvent(DetectionInfo(MITIGATION_NAME, player)) } } ServerTickEvents.END_SERVER_TICK.register( EndTick { if (firstIteration) { updateLastPositionWithCurrentPosition() firstIteration = true } addCurrentMagnitudeToWindow() updateLastPositionWithCurrentPosition() updateSuspiciousTicksCount() } ) } private fun isSpeedHacking(): Boolean = suspiciousMagnitudeTicks > MAXIMUM_SUSPICIOUS_MAGNITUDE_TICKS private fun updateSuspiciousTicksCount() { if (!averageMagnitude.isNaN() && averageMagnitude >= MAXIMUM_AVERAGE_MAGNITUDE) { suspiciousMagnitudeTicks++ } else { suspiciousMagnitudeTicks = 0 } } private fun addCurrentMagnitudeToWindow() { val magnitude = calculateMagnitudeForPlayer() if (magnitude >= FALSE_MAGNITUDE_THRESHOLD) { return } magnitudeWindow.trimToLength(SLIDING_WINDOW_LENGTH) magnitudeWindow.add(magnitude) } private fun calculateMagnitudeForPlayer(): Double { val xDiff = player.x - lastX val yDiff = player.y - lastY val zDiff = player.z - lastZ val magnitude = abs(xDiff) * abs(xDiff) + abs(yDiff) * abs(yDiff) + abs(zDiff) * abs(zDiff) return MagnitudeWeighter.getWeightedMagnitude(magnitude, player, lastY) } private fun updateLastPositionWithCurrentPosition() { lastX = player.x lastY = player.y lastZ = player.z } }
puffy-anti-exploit/src/main/kotlin/com/puffy/mitigations/AntiSpeedMitigation.kt
3924007608
package com.puffy.mitigations interface MitigationPlayerEntity { fun addMitigation(mitigation: Any): Unit }
puffy-anti-exploit/src/main/kotlin/com/puffy/mitigations/MitigationPlayerEntity.kt
2659335699
package com.puffy.mitigations import com.puffy.events.DetectionEventEmitter import com.puffy.events.DetectionInfo import com.puffy.events.PacketEventEmitter import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.EndTick import net.minecraft.entity.effect.StatusEffect import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket import net.minecraft.server.network.ServerPlayerEntity const val MAXIMUM_TICKS_SPENT_FLOATING = 85 const val MAXIMUM_TICKS_SPENT_ASCENDING = 20 private const val FLOATING_Y_TOLERANCE = 1 private const val MITIGATION_NAME = "Flight" // https://minecraft.fandom.com/wiki/Levitation private const val LEVITATION_STATUS_ID = 25 // Likely, once the player's velocity reaches this threshold it's probably from a tnt jump or mod private const val FLIGHT_SPEED_THRESHOLD = 5 class AntiFlyMitigation(val player: ServerPlayerEntity) { private var ticksSpentFloating = 0 private var ticksSpentAscending = 0 private var lastY = 0.0 private var isAllowedToFly = false init { PacketEventEmitter.addListener(player, PlayerMoveC2SPacket::class) { _ -> if (isFlyHacking()) { DetectionEventEmitter.sendEvent(DetectionInfo(MITIGATION_NAME, player)) } } ServerTickEvents.END_SERVER_TICK.register( EndTick { updateTicksFloating() updateTicksAscending() resetCountersWhenFlightRemoved() isAllowedToFly = isFlightAllowedAtCurrentTick() } ) } private fun isFlyHacking(): Boolean { return (ticksSpentFloating >= MAXIMUM_TICKS_SPENT_FLOATING || ticksSpentAscending >= MAXIMUM_TICKS_SPENT_ASCENDING) && !isAllowedToFly } private fun updateTicksFloating() { val world = player.entityWorld val boundingBox = player.boundingBox.expand(0.0, 0.2, 0.0) val collidingBlocks = world.getBlockCollisions(player, boundingBox) val collidingEntities = world.getOtherEntities(player, boundingBox) { entity -> !entity.equals(player) } if ( !collidingBlocks.any() && !collidingEntities.any() && player.y - lastY <= FLOATING_Y_TOLERANCE ) { ticksSpentFloating++ } else { ticksSpentFloating = 0 } } private fun updateTicksAscending() { if (player.y > lastY && !isFlightAllowedAtCurrentTick()) { ticksSpentAscending++ } else { ticksSpentAscending = 0 } lastY = player.y } private fun isFlightAllowedAtCurrentTick(): Boolean { return (player.abilities.flying || player.abilities.allowFlying) || player.isTouchingWater || player.isSubmergedInWater || player.isSwimming || player.isFallFlying || player.hasStatusEffect(StatusEffect.byRawId(LEVITATION_STATUS_ID)) || player.velocity.length() >= FLIGHT_SPEED_THRESHOLD || player.fallDistance > 0 } private fun resetCountersWhenFlightRemoved() { if (isAllowedToFly != isFlightAllowedAtCurrentTick()) { ticksSpentFloating = 0 ticksSpentAscending = 0 } } }
puffy-anti-exploit/src/main/kotlin/com/puffy/mitigations/AntiFlyMitigation.kt
4256162736
package com.puffy.mitigations.antispeed import java.util.function.BiPredicate import net.minecraft.server.network.ServerPlayerEntity import org.slf4j.LoggerFactory data class Weight( val title: String, val multiplier: Double, val predicate: BiPredicate<ServerPlayerEntity, Double> ) const val MAX_FALLING_Y_DIFFERENCE = -0.5 const val MAX_ASCENDING_Y_DIFFERENCE = 0.2 const val SERVER_VELOCITY_THRESHOLD = 3 object MagnitudeWeighter { private val logger = LoggerFactory.getLogger("puffy-anti-exploit") private val weights = listOf( Weight("Elytra Bias", 0.20) { player, _ -> player.isFallFlying }, Weight("Falling Bias", 0.55) { player, lastY -> player.y - lastY < MAX_FALLING_Y_DIFFERENCE }, Weight("Elytra Flyhack Bias", 6.0) { player, lastY -> player.isFallFlying && player.y - lastY > MAX_ASCENDING_Y_DIFFERENCE }, Weight("Creative Mode Bias", 0.0) { player, _ -> player.isCreative }, Weight("Server-permitted Flight Bias", 0.25) { player, _ -> player.abilities.flying || player.abilities.allowFlying }, Weight("Server-permitted Velocity Bias", 0.25) { player, _ -> player.velocity.length() > SERVER_VELOCITY_THRESHOLD } ) private fun getActiveWeightsForPlayer(player: ServerPlayerEntity, lastY: Double) = weights.filter { weight -> weight.predicate.test(player, lastY) } private fun getTotalWeightedMultiplier(weights: List<Weight>) = weights.fold(1.0) { acc, weight -> weight.multiplier * acc } fun getWeightedMagnitude( initialMagnitude: Double, player: ServerPlayerEntity, lastY: Double ): Double { val activeWeights = getActiveWeightsForPlayer(player, lastY) activeWeights.forEach { weight -> logger.debug("Weight '${weight.title}' is active for player ${player.name.string}") } return initialMagnitude * getTotalWeightedMultiplier(activeWeights) } }
puffy-anti-exploit/src/main/kotlin/com/puffy/mitigations/antispeed/MagnitudeWeighter.kt
976577202
package com.puffy import com.puffy.events.DetectionEventEmitter import com.puffy.mitigations.AntiFlyMitigation import com.puffy.mitigations.AntiKillAuraMitigation import com.puffy.mitigations.AntiSpeedMitigation import com.puffy.mitigations.MitigationPlayerEntity import com.puffy.util.disconnectForExploit import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents.Join import org.slf4j.LoggerFactory object PuffyAntiExploit : ModInitializer { private val logger = LoggerFactory.getLogger("puffy-anti-exploit") override fun onInitialize() { ServerPlayConnectionEvents.JOIN.register( Join { handler, _, _ -> val mitigationPlayerEntity = handler.player as MitigationPlayerEntity mitigationPlayerEntity.addMitigation(AntiFlyMitigation(handler.player)) mitigationPlayerEntity.addMitigation(AntiSpeedMitigation(handler.player)) mitigationPlayerEntity.addMitigation(AntiKillAuraMitigation(handler.player)) logger.info("Initialized ${handler.player.name.string}") } ) DetectionEventEmitter.addListener("kick-on-detect") { (source, player) -> logger.warn( "Player ${player.name.string} was kicked for sending significant amounts of unusual client activity to the server. (source: $source)" ) player.disconnectForExploit(source) } logger.info("Puffy Anti Exploit initialized!") } }
puffy-anti-exploit/src/main/kotlin/com/puffy/PuffyAntiExploit.kt
1681064377