From 67b8659d894c602835f4a9d49ae9298552528fdf Mon Sep 17 00:00:00 2001 From: Arjun Gupta Date: Thu, 4 Apr 2024 20:24:14 +0530 Subject: [PATCH] Module SetUp Done --- .idea/compiler.xml | 2 +- .idea/gradle.xml | 6 +- .idea/kotlinc.xml | 6 ++ .idea/migrations.xml | 10 +++ .idea/misc.xml | 2 +- .../horizontalcalendardate/CalendarAdapter.kt | 4 +- horizontal_calendar_date/.gitignore | 1 + horizontal_calendar_date/build.gradle | 41 ++++++++++ horizontal_calendar_date/consumer-rules.pro | 0 horizontal_calendar_date/proguard-rules.pro | 21 +++++ .../ExampleInstrumentedTest.kt | 24 ++++++ .../src/main/AndroidManifest.xml | 4 + .../CalendarAdapter.kt | 80 +++++++++++++++++++ .../CalendarDateModel.kt | 20 +++++ .../src/main/res/drawable/left_arrow.xml | 5 ++ .../src/main/res/drawable/rectangle_fill.xml | 8 ++ .../main/res/drawable/rectangle_outline.xml | 8 ++ .../src/main/res/drawable/right_arrow.xml | 5 ++ .../src/main/res/layout/date_layout.xml | 27 +++++++ .../src/main/res/values-night/themes.xml | 16 ++++ .../src/main/res/values/colors.xml | 10 +++ .../src/main/res/values/strings.xml | 3 + .../src/main/res/values/themes.xml | 16 ++++ .../ExampleUnitTest.kt | 17 ++++ settings.gradle | 1 + 25 files changed, 331 insertions(+), 6 deletions(-) create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/migrations.xml create mode 100644 horizontal_calendar_date/.gitignore create mode 100644 horizontal_calendar_date/build.gradle create mode 100644 horizontal_calendar_date/consumer-rules.pro create mode 100644 horizontal_calendar_date/proguard-rules.pro create mode 100644 horizontal_calendar_date/src/androidTest/java/com/arjungupta08/horizontal_calendar_date/ExampleInstrumentedTest.kt create mode 100644 horizontal_calendar_date/src/main/AndroidManifest.xml create mode 100644 horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarAdapter.kt create mode 100644 horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarDateModel.kt create mode 100644 horizontal_calendar_date/src/main/res/drawable/left_arrow.xml create mode 100644 horizontal_calendar_date/src/main/res/drawable/rectangle_fill.xml create mode 100644 horizontal_calendar_date/src/main/res/drawable/rectangle_outline.xml create mode 100644 horizontal_calendar_date/src/main/res/drawable/right_arrow.xml create mode 100644 horizontal_calendar_date/src/main/res/layout/date_layout.xml create mode 100644 horizontal_calendar_date/src/main/res/values-night/themes.xml create mode 100644 horizontal_calendar_date/src/main/res/values/colors.xml create mode 100644 horizontal_calendar_date/src/main/res/values/strings.xml create mode 100644 horizontal_calendar_date/src/main/res/values/themes.xml create mode 100644 horizontal_calendar_date/src/test/java/com/arjungupta08/horizontal_calendar_date/ExampleUnitTest.kt diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b589d56 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index a9f4e52..e92b264 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,17 +1,19 @@ + diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..0e65cea --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index b1f8730..0ad17cb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + diff --git a/app/src/main/java/com/arjun/horizontalcalendardate/CalendarAdapter.kt b/app/src/main/java/com/arjun/horizontalcalendardate/CalendarAdapter.kt index d5194d9..9a938bc 100644 --- a/app/src/main/java/com/arjun/horizontalcalendardate/CalendarAdapter.kt +++ b/app/src/main/java/com/arjun/horizontalcalendardate/CalendarAdapter.kt @@ -54,11 +54,11 @@ class CalendarAdapter(private val listener: (calendarDateModel: CalendarDateMode if (position == adapterPosition){ holder.calendarDay.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.white)) holder.calendarDate.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.white)) - holder.linear.background = holder.itemView.context.getDrawable(R.drawable.rectangle_fill) + holder.linear.setBackgroundResource(R.drawable.rectangle_fill) }else { holder.calendarDay.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.black)) holder.calendarDate.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.black)) - holder.linear.background = holder.itemView.context.getDrawable(R.drawable.rectangle_outline) + holder.linear.setBackgroundResource(R.drawable.rectangle_outline) } } diff --git a/horizontal_calendar_date/.gitignore b/horizontal_calendar_date/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/horizontal_calendar_date/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/horizontal_calendar_date/build.gradle b/horizontal_calendar_date/build.gradle new file mode 100644 index 0000000..e45dad4 --- /dev/null +++ b/horizontal_calendar_date/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.arjungupta08.horizontal_calendar_date' + compileSdk 34 + + defaultConfig { + minSdk 24 + + 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.12.0' + implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0') + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.11.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' +} \ No newline at end of file diff --git a/horizontal_calendar_date/consumer-rules.pro b/horizontal_calendar_date/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/horizontal_calendar_date/proguard-rules.pro b/horizontal_calendar_date/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/horizontal_calendar_date/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/horizontal_calendar_date/src/androidTest/java/com/arjungupta08/horizontal_calendar_date/ExampleInstrumentedTest.kt b/horizontal_calendar_date/src/androidTest/java/com/arjungupta08/horizontal_calendar_date/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..f47a651 --- /dev/null +++ b/horizontal_calendar_date/src/androidTest/java/com/arjungupta08/horizontal_calendar_date/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.arjungupta08.horizontal_calendar_date + +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.arjungupta08.horizontal_calendar_date.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/AndroidManifest.xml b/horizontal_calendar_date/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/horizontal_calendar_date/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarAdapter.kt b/horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarAdapter.kt new file mode 100644 index 0000000..8a6d9ee --- /dev/null +++ b/horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarAdapter.kt @@ -0,0 +1,80 @@ +package com.arjungupta08.horizontal_calendar_date + +import android.os.Build +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.TextView +import androidx.annotation.RequiresApi +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import kotlin.collections.ArrayList + +class CalendarAdapter(private val listener: (calendarDateModel: CalendarDateModel, position: Int) -> Unit): + RecyclerView.Adapter(){ + + private var list = ArrayList() + private var adapterPosition = -1 + + + interface OnItemClickListener{ + fun onItemClick(text: String, date: String, day: String) + } + + private var mListener: OnItemClickListener? = null + + fun setOnItemClickListener(listener: OnItemClickListener){ + mListener = listener + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CalendarViewHolder { + val inflater : LayoutInflater = LayoutInflater.from(parent.context) + val view: View = inflater.inflate(R.layout.date_layout,parent,false) + return CalendarViewHolder(view) + } + + + @RequiresApi(Build.VERSION_CODES.O) + override fun onBindViewHolder(holder: CalendarViewHolder, position: Int) { + val itemList = list[position] + holder.calendarDay.text = itemList.calendarDay + holder.calendarDate.text = itemList.calendarDate + + holder.itemView.setOnClickListener { + adapterPosition = position + notifyItemRangeChanged(0, list.size) + + val text = itemList.calendarYear + val date = itemList.calendarDate + val day = itemList.calendarDay + mListener?.onItemClick(text,date,day) + } + if (position == adapterPosition){ + holder.calendarDay.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.white)) + holder.calendarDate.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.white)) + holder.linear.setBackgroundResource(R.drawable.rectangle_fill) + }else { + holder.calendarDay.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.black)) + holder.calendarDate.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.black)) + holder.linear.setBackgroundResource(R.drawable.rectangle_outline) + } + } + override fun getItemCount(): Int { + return list.size + } + + class CalendarViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val calendarDay : TextView= itemView.findViewById(R.id.tv_calendar_day) + val calendarDate : TextView= itemView.findViewById(R.id.tv_calendar_date) + val linear : LinearLayout= itemView.findViewById(R.id.linear_calendar) + } + + fun setData(calendarList: ArrayList) { + list.clear() + list.addAll(calendarList) + notifyDataSetChanged() + } +} + + diff --git a/horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarDateModel.kt b/horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarDateModel.kt new file mode 100644 index 0000000..4504578 --- /dev/null +++ b/horizontal_calendar_date/src/main/java/com/arjungupta08/horizontal_calendar_date/CalendarDateModel.kt @@ -0,0 +1,20 @@ +package com.arjungupta08.horizontal_calendar_date + +import java.text.SimpleDateFormat +import java.util.* + +data class CalendarDateModel(var data: Date, var isSelected: Boolean = true) { + + val calendarDay: String + get() = SimpleDateFormat("EE", Locale.getDefault()).format(data) + + val calendarYear: String + get() = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(data) + + val calendarDate: String + get() { + val cal = Calendar.getInstance() + cal.time = data + return cal[Calendar.DAY_OF_MONTH].toString() + } +} \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/res/drawable/left_arrow.xml b/horizontal_calendar_date/src/main/res/drawable/left_arrow.xml new file mode 100644 index 0000000..6febbb7 --- /dev/null +++ b/horizontal_calendar_date/src/main/res/drawable/left_arrow.xml @@ -0,0 +1,5 @@ + + + diff --git a/horizontal_calendar_date/src/main/res/drawable/rectangle_fill.xml b/horizontal_calendar_date/src/main/res/drawable/rectangle_fill.xml new file mode 100644 index 0000000..2bdb573 --- /dev/null +++ b/horizontal_calendar_date/src/main/res/drawable/rectangle_fill.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/res/drawable/rectangle_outline.xml b/horizontal_calendar_date/src/main/res/drawable/rectangle_outline.xml new file mode 100644 index 0000000..abae5a1 --- /dev/null +++ b/horizontal_calendar_date/src/main/res/drawable/rectangle_outline.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/res/drawable/right_arrow.xml b/horizontal_calendar_date/src/main/res/drawable/right_arrow.xml new file mode 100644 index 0000000..5d47b4d --- /dev/null +++ b/horizontal_calendar_date/src/main/res/drawable/right_arrow.xml @@ -0,0 +1,5 @@ + + + diff --git a/horizontal_calendar_date/src/main/res/layout/date_layout.xml b/horizontal_calendar_date/src/main/res/layout/date_layout.xml new file mode 100644 index 0000000..b8036ec --- /dev/null +++ b/horizontal_calendar_date/src/main/res/layout/date_layout.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/horizontal_calendar_date/src/main/res/values-night/themes.xml b/horizontal_calendar_date/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..353f890 --- /dev/null +++ b/horizontal_calendar_date/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/res/values/colors.xml b/horizontal_calendar_date/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/horizontal_calendar_date/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/res/values/strings.xml b/horizontal_calendar_date/src/main/res/values/strings.xml new file mode 100644 index 0000000..e52fd25 --- /dev/null +++ b/horizontal_calendar_date/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Horizontal CalendarDate + \ No newline at end of file diff --git a/horizontal_calendar_date/src/main/res/values/themes.xml b/horizontal_calendar_date/src/main/res/values/themes.xml new file mode 100644 index 0000000..c47ec5b --- /dev/null +++ b/horizontal_calendar_date/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/horizontal_calendar_date/src/test/java/com/arjungupta08/horizontal_calendar_date/ExampleUnitTest.kt b/horizontal_calendar_date/src/test/java/com/arjungupta08/horizontal_calendar_date/ExampleUnitTest.kt new file mode 100644 index 0000000..ff18fcf --- /dev/null +++ b/horizontal_calendar_date/src/test/java/com/arjungupta08/horizontal_calendar_date/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.arjungupta08.horizontal_calendar_date + +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) + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index d3b295f..95b496b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,3 +14,4 @@ dependencyResolutionManagement { } rootProject.name = "Horizontal CalendarDate" include ':app' +include ':horizontal_calendar_date'