Skip to content

Commit

Permalink
My Dialog Library
Browse files Browse the repository at this point in the history
  • Loading branch information
professorDeveloper committed Mar 4, 2023
0 parents commit 2471737
Show file tree
Hide file tree
Showing 63 changed files with 1,863 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

16 changes: 16 additions & 0 deletions .idea/misc.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

1 change: 1 addition & 0 deletions DialogGit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
44 changes: 44 additions & 0 deletions DialogGit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android-extensions'
}

android {
namespace 'com.azamovhud.dialoggit'
compileSdk 33

defaultConfig {
minSdk 24
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'


}
Empty file added DialogGit/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions DialogGit/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.dialoggit

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.azamovhud.dialoggit.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions DialogGit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.azamovhud.dialoggit.adapters

import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.azamovhud.dialoggit.R

class ColorAdapter(val list: List<Int>, val listener: OnItemClickListener) :
RecyclerView.Adapter<ColorAdapter.ColorIV>() {

var item: CardView? = null
var lastPosition = 0
private val TAG = "ColorAdapter"

inner class ColorIV(itemView: View) : RecyclerView.ViewHolder(itemView.rootView) {
fun onBind(color: Int, position: Int) {
Log.d(TAG, "onBind: $position")

val cardView = itemView.findViewById<CardView>(R.id.card_view)
val backCard = itemView.findViewById<CardView>(R.id.back_card)
cardView.setCardBackgroundColor(color)

itemView.setOnClickListener {
listener.OnItemClicked(color)
if (item != null) {
if (lastPosition != position) {
item!!.setCardBackgroundColor(Color.BLACK)
item = backCard
lastPosition = position
backCard.setCardBackgroundColor(Color.WHITE)
} else backCard.setCardBackgroundColor(Color.WHITE)
} else {
item = backCard
lastPosition = position
backCard.setCardBackgroundColor(Color.WHITE)
}
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ColorIV {
return ColorIV(
LayoutInflater.from(parent.context)
.inflate(R.layout.color_rv_item, parent, false)
)
}

override fun onBindViewHolder(holder: ColorIV, position: Int) {
holder.onBind(list[position], position)
}

override fun getItemCount(): Int = list.size

interface OnItemClickListener {
fun OnItemClicked(color: Int)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.azamovhud.dialoggit.classes

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDialog
import androidx.appcompat.app.AppCompatDialogFragment
import com.azamovhud.dialoggit.R
import kotlinx.android.synthetic.main.basic_dialog.*

class BasicDialog(context: Context) : AppCompatDialogFragment() {
var basicDialogListeners: BasicDialogListeners? = null

var dialogTitle: String? = null
var mainText: String? = null
var okBtnText: String? = null
var cancelBtn: String? = null

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(requireActivity())
val layoutInflater = activity?.layoutInflater

val view = layoutInflater?.inflate(R.layout.basic_dialog, null)!!
builder.setView(view)
val titleTv: TextView = view.findViewById(R.id.title_tv)
val mainTextTV: TextView = view.findViewById(R.id.message_tv)
val okBtnTV: TextView = view.findViewById(R.id.positive_btn)
val cancelBtnTV: TextView = view.findViewById(R.id.negative_btn)

titleTv.text = dialogTitle
mainTextTV.text = mainText
okBtnTV.text = okBtnText
cancelBtnTV.text = cancelBtn

okBtnTV.setOnClickListener {
dismiss()
basicDialogListeners?.okButtonClicked()
}

cancelBtnTV.setOnClickListener {
dismiss()
basicDialogListeners?.cancelButtonClicked()
}

return builder.create()
}

fun createDialog(title:String, mainTxt:String, okBtnTxt:String, cancelBtnTxt:String){
this.dialogTitle = title
this.mainText = mainTxt
this.cancelBtn = okBtnTxt
this.okBtnText = cancelBtnTxt

}
fun setOnButtonClickListener(listener:BasicDialogListeners){
this.basicDialogListeners = listener
}

interface BasicDialogListeners {
fun okButtonClicked()
fun cancelButtonClicked()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.azamovhud.dialoggit.classes

import android.app.Dialog
import android.os.Bundle
import android.widget.CheckBox
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.core.view.forEach
import com.azamovhud.dialoggit.R

class CheckBoxDialog(val list: List<String>, val title: String) : AppCompatDialogFragment() {

var listener: OnChooseClickListener? = null

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(requireContext())
val inflater = activity?.layoutInflater!!

val view = inflater.inflate(R.layout.check_box_dialog, null)
val linear = view.findViewById<LinearLayout>(R.id.linear)

for (i in list) {
val params = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
params.setMargins(0, 24, 0, 0)

val checkBox = CheckBox(activity)
checkBox.tag = i
checkBox.text = i
checkBox.layoutParams = params
linear.addView(checkBox)
}
builder.setView(view)
val titleTV = view.findViewById<TextView>(R.id.title_tv)
val chooseTV = view.findViewById<TextView>(R.id.choose_tv)
chooseTV.setOnClickListener {
val list = arrayListOf<String>()
linear.forEach {
val checkBox = it as CheckBox
if (checkBox.isChecked) {
list.add(checkBox.text.toString())
}
}
listener?.chooseClick(list)
dismiss()
}

titleTV.text = title

return builder.create()
}

fun setOnChooseClickListener(listener: OnChooseClickListener) {
this.listener = listener
}

interface OnChooseClickListener {
fun chooseClick(chosenList: List<String>)
}

}
Loading

0 comments on commit 2471737

Please sign in to comment.