Innopolis University DevOps Playground
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blood glucose app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
glucose
blood glucose app
Commits
43f873d7
Commit
43f873d7
authored
1 year ago
by
Evgeny Bobkunov
Browse files
Options
Downloads
Plain Diff
Merge branch 'AdviceActivity' into 'main'
Updated: See merge request
!26
parents
dcd1b80f
26d48360
Branches
Branches containing commit
No related tags found
1 merge request
!26
Updated:
Pipeline
#3457
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/example/bloodglucose/AdviceActivity.kt
+47
-0
47 additions, 0 deletions
app/src/main/java/com/example/bloodglucose/AdviceActivity.kt
with
47 additions
and
0 deletions
app/src/main/java/com/example/bloodglucose/AdviceActivity.kt
+
47
−
0
View file @
43f873d7
...
...
@@ -4,7 +4,16 @@ import android.content.Context
import
android.content.Intent
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.util.Log
import
android.widget.Button
import
android.widget.ImageView
import
android.widget.TextView
import
com.bumptech.glide.Glide
import
com.google.firebase.firestore.ktx.firestore
import
com.google.firebase.ktx.Firebase
import
kotlin.random.Random
import
java.text.SimpleDateFormat
import
java.util.*
class
AdviceActivity
:
AppCompatActivity
()
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -16,6 +25,44 @@ class AdviceActivity : AppCompatActivity() {
val
homeIntent
=
Intent
(
this
@AdviceActivity
,
TodayActivity
::
class
.
java
)
startActivity
(
homeIntent
)
}
val
imageView
:
ImageView
=
findViewById
(
R
.
id
.
imageView
)
val
textView
:
TextView
=
findViewById
(
R
.
id
.
textView
)
val
sharedPreferences
=
getSharedPreferences
(
"MyApp"
,
Context
.
MODE_PRIVATE
)
val
savedDate
=
sharedPreferences
.
getString
(
"date"
,
""
)
val
savedTip
=
sharedPreferences
.
getString
(
"tip"
,
""
)
val
savedImageUrl
=
sharedPreferences
.
getString
(
"imageUrl"
,
""
)
val
dateFormat
=
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
US
)
val
currentDate
=
dateFormat
.
format
(
Date
())
if
(
savedDate
==
currentDate
&&
savedTip
!=
""
&&
savedImageUrl
!=
""
)
{
// Load the saved tip and image
textView
.
text
=
savedTip
Glide
.
with
(
this
@AdviceActivity
).
load
(
savedImageUrl
).
into
(
imageView
)
}
else
{
// Fetch a new random tip and image
Firebase
.
firestore
.
collection
(
"tips"
).
get
().
addOnSuccessListener
{
advice
->
val
randomIndex
=
Random
.
nextInt
(
0
,
advice
.
size
()
-
1
)
val
item
=
advice
.
documents
[
randomIndex
]
val
url
=
item
.
getString
(
"image"
)
val
tipText
=
item
.
getString
(
"text"
)
Glide
.
with
(
this
@AdviceActivity
).
load
(
url
).
into
(
imageView
)
textView
.
text
=
tipText
// Save the new tip and image URL
with
(
sharedPreferences
.
edit
())
{
putString
(
"date"
,
currentDate
)
putString
(
"tip"
,
tipText
)
putString
(
"imageUrl"
,
url
)
apply
()
}
}.
addOnFailureListener
{
exception
->
println
(
"Error getting documents: $exception"
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment