Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #24

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .idea/gradle.xml

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

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

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

9 changes: 9 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.

16 changes: 16 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'


android {
compileSdkVersion 30
buildToolsVersion "30.0.2"


defaultConfig {
applicationId "com.wellnesscity.health"
minSdkVersion 22
Expand All @@ -31,6 +33,13 @@ android {
}

dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
def nav_version = "2.3.1"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should move to the project level gradle


//navigation
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

//hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
Expand All @@ -42,8 +51,15 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
//noinspection GradleCompatible,GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//ViewPager2
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
//Material Design
implementation 'com.google.android.material:material:1.3.0-alpha03'
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.wellnesscity.health">

<application
Expand All @@ -10,13 +11,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity android:name=".MainActivity"></activity>
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OnboardingActivity"></activity>
</application>

</manifest>
7 changes: 7 additions & 0 deletions app/src/main/java/com/wellnesscity/health/IntroSlide.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wellnesscity.health

data class IntroSlide(
val title: String,
val description: String,
val icon: Int
)
43 changes: 43 additions & 0 deletions app/src/main/java/com/wellnesscity/health/IntroSliderAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.wellnesscity.health

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class IntroSliderAdapter(private val introSlides: List<IntroSlide>)
: RecyclerView.Adapter<IntroSliderAdapter.IntroSlideViewHolder>(){

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

override fun getItemCount(): Int {
return introSlides.size
}

override fun onBindViewHolder(holder: IntroSlideViewHolder, position: Int) {
holder.bind(introSlides[position])
}

inner class IntroSlideViewHolder(view: View) : RecyclerView.ViewHolder(view) {

private val textTitle = view.findViewById<TextView>(R.id.textTitle)
private val textDescription = view.findViewById<TextView>(R.id.textDescription)
private val imageIcon = view.findViewById<ImageView>(R.id.imageSlideIcon)

fun bind(introSlide: IntroSlide) {
textTitle.text = introSlide.title
textDescription.text = introSlide.description
imageIcon.setImageResource(introSlide.icon)
}
}
}
112 changes: 112 additions & 0 deletions app/src/main/java/com/wellnesscity/health/OnboardingActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.wellnesscity.health

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.core.view.get
import androidx.viewpager2.widget.ViewPager2
import kotlinx.android.synthetic.main.onboarding_screen.*

class OnboardingActivity : AppCompatActivity() {

private val introSliderAdapter = IntroSliderAdapter(
listOf(
IntroSlide(
"Health Tips / Advice",
"Discover tips and advice to help you to help maintain transform and main your health",
R.drawable.ic_bro
),
IntroSlide(
"Diet Tips / Advice",
"Find out basics of health diet and good nutrition, Start eating well and keep a balanced diet",
R.drawable.ic_amico
),
IntroSlide(
"Covid 19 Symptoms/Prevention tips",
"Get regular Reminders of Covid19 prevention tips ensuring you stay safe",
R.drawable.ic_pana
)
)
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.onboarding_screen)
introSliderViewPager.adapter = introSliderAdapter
setupIndicators()
setCurrentIndicator(0)
introSliderViewPager.registerOnPageChangeCallback(object :
ViewPager2.OnPageChangeCallback() {

override fun onPageSelected(position: Int) {
super.onPageSelected(position)
setCurrentIndicator(position)
}
})
buttonNext.setOnClickListener {
if(introSliderViewPager.currentItem + 1 < introSliderAdapter.itemCount) {
introSliderViewPager.currentItem += 1
} else {
Intent(applicationContext, MainActivity::class.java).also {
startActivity(it)
finish()
}
}
}
textSkipIntro.setOnClickListener {
Intent (applicationContext, MainActivity::class.java).also {
startActivity(it)
finish()
}
}
}

private fun setupIndicators() {
val indicators = arrayOfNulls<ImageView>(introSliderAdapter.itemCount)
val layoutParams: LinearLayout.LayoutParams =
LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
layoutParams.setMargins(8,0,8,0)
for(i in indicators.indices) {
indicators[i] = ImageView(applicationContext)
indicators[i].apply {
this?.setImageDrawable(
ContextCompat.getDrawable(
applicationContext,
R.drawable.indicator_inactive
)
)
this?.layoutParams = layoutParams
}
indicatorsContainer.addView(indicators[i])
}

}

private fun setCurrentIndicator(index: Int){
val childCount = indicatorsContainer.childCount
for (i in 0 until childCount) {
val imageView = indicatorsContainer[i] as ImageView
if (i == index){
imageView.setImageDrawable(
ContextCompat.getDrawable(
applicationContext,
R.drawable.indicator_active
)
)
} else {
imageView.setImageDrawable(
ContextCompat.getDrawable(
applicationContext,
R.drawable.indicator_inactive
)
)
}
}

}

}
18 changes: 18 additions & 0 deletions app/src/main/java/com/wellnesscity/health/OnboardingFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wellnesscity.health

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

class OnboardingFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_onboarding, container, false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using viewbinding instead

}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/wellnesscity/health/SplashScreenActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.wellnesscity.health

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler

class SplashScreenActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.splash_screen)

supportActionBar?.hide()

Handler().postDelayed({
val intent = Intent (this@SplashScreenActivity, OnboardingActivity::class.java)
startActivity(intent)
finish()
}, 3000)
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/wellnesscity/health/SplashScreenFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.wellnesscity.health

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.NavController
import androidx.navigation.Navigation

class SplashScreenFragment : Fragment() {

var navController : NavController? = null

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_splash_screen, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navController = Navigation.findNavController(view)

// supportActionBar?.hide()

Handler().postDelayed({
navController!!.navigate(R.id.action_splashScreenFragment_to_onboardingFragment)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! causes null pointer exception should be replaced with ? and also we are using safeargs for navigation to avoid runtime error which I already added the dependency

}, 3000)
}
}
Loading