Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
LifeLogger
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
LifeLogger
Commits
86f046b5
Unverified
Commit
86f046b5
authored
Mar 04, 2018
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(model): Log, DataPoint, LogAdapter
parent
a031ebcf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
0 deletions
+113
-0
DataPoint.kt
app/src/main/java/fr/plnech/lifelogger/model/DataPoint.kt
+29
-0
Log.kt
app/src/main/java/fr/plnech/lifelogger/model/Log.kt
+15
-0
LogAdapter.kt
app/src/main/java/fr/plnech/lifelogger/model/LogAdapter.kt
+47
-0
LogViewModel.java
...rc/main/java/fr/plnech/lifelogger/model/LogViewModel.java
+22
-0
No files found.
app/src/main/java/fr/plnech/lifelogger/model/DataPoint.kt
0 → 100644
View file @
86f046b5
package
fr.plnech.lifelogger.model
import
java.util.*
import
kotlin.collections.HashMap
private
const
val
NONE
:
Int
=
Int
.
MIN_VALUE
data class
DataPoint
(
val
date
:
Date
=
Date
(),
private
val
metadata
:
HashMap
<
String
,
Any
>
=
HashMap
())
{
constructor
(
name
:
String
,
count
:
Int
=
NONE
)
:
this
()
{
metadata
[
"name"
]
=
name
metadata
[
"count"
]
=
count
}
private
val
name
:
String
get
()
=
metadata
[
"name"
]
as
String
private
val
count
:
Int
?
get
()
=
metadata
[
"count"
].
let
{
if
(
it
==
NONE
)
null
else
it
}
as
Int
?
override
fun
toString
():
String
{
val
b
=
StringBuilder
(
name
)
count
?.
let
{
b
.
append
(
"($count)"
)}
return
b
.
toString
()
}
}
\ No newline at end of file
app/src/main/java/fr/plnech/lifelogger/model/Log.kt
0 → 100644
View file @
86f046b5
package
fr.plnech.lifelogger.model
class
Log
(
val
name
:
String
,
private
val
dataPoints
:
ArrayList
<
DataPoint
>
=
ArrayList
())
{
fun
addPoint
(
dataPoint
:
DataPoint
)
{
dataPoints
.
add
(
dataPoint
)
}
override
fun
toString
():
String
{
val
b
=
StringBuilder
(
"$name: "
)
dataPoints
.
forEach
({
b
.
append
(
it
).
append
(
" | "
)})
return
b
.
removeSuffix
(
"| "
).
toString
()
}
}
\ No newline at end of file
app/src/main/java/fr/plnech/lifelogger/model/LogAdapter.kt
0 → 100644
View file @
86f046b5
package
fr.plnech.lifelogger.model
import
android.app.Activity
import
android.content.Context
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.BaseAdapter
import
android.widget.TextView
class
LogAdapter
(
private
var
activity
:
Activity
,
private
var
logs
:
List
<
Log
>)
:
BaseAdapter
()
{
override
fun
getView
(
position
:
Int
,
convertView
:
View
?,
parent
:
ViewGroup
?):
View
{
val
view
:
View
val
viewHolder
:
ViewHolder
if
(
convertView
==
null
)
{
val
inflater
=
activity
.
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
)
as
LayoutInflater
view
=
inflater
.
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
null
)
viewHolder
=
ViewHolder
(
view
)
view
?.
tag
=
viewHolder
}
else
{
view
=
convertView
viewHolder
=
view
.
tag
as
ViewHolder
}
var
log
=
logs
[
position
]
viewHolder
.
text1
.
text
=
log
.
toString
()
return
view
}
override
fun
getItem
(
position
:
Int
):
Any
{
return
logs
[
position
]
}
override
fun
getItemId
(
position
:
Int
):
Long
{
return
position
.
toLong
()
}
override
fun
getCount
():
Int
{
return
logs
.
size
}
class
ViewHolder
(
row
:
View
)
{
var
text1
:
TextView
=
row
.
findViewById
(
android
.
R
.
id
.
text1
)
!!
}
}
\ No newline at end of file
app/src/main/java/fr/plnech/lifelogger/model/LogViewModel.java
0 → 100644
View file @
86f046b5
package
fr
.
plnech
.
lifelogger
.
model
;
import
android.arch.lifecycle.LiveData
;
import
android.arch.lifecycle.MutableLiveData
;
import
android.arch.lifecycle.ViewModel
;
import
java.util.List
;
public
class
LogViewModel
extends
ViewModel
{
private
MutableLiveData
<
List
<
Log
>>
logs
;
public
LiveData
<
List
<
Log
>>
getLogs
()
{
if
(
logs
==
null
)
{
logs
=
new
MutableLiveData
<>();
loadLogs
();
}
return
logs
;
}
private
void
loadLogs
()
{
// TODO: Fetch from Room asyncronously.
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment