Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
Dunbar
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
Dunbar
Commits
f7f464bd
Unverified
Commit
f7f464bd
authored
Nov 02, 2019
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Messages): Fetch, although not needed now
parent
0543837d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
6 deletions
+63
-6
MainActivity.kt
app/src/main/java/fr/plnech/dunbar/MainActivity.kt
+14
-6
Messages.kt
app/src/main/java/fr/plnech/dunbar/Messages.kt
+49
-0
No files found.
app/src/main/java/fr/plnech/dunbar/MainActivity.kt
View file @
f7f464bd
...
...
@@ -5,7 +5,6 @@ import android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.os.Bundle
import
android.provider.ContactsContract
import
android.util.Log
import
android.view.Menu
import
android.view.MenuItem
import
android.widget.Toast
...
...
@@ -18,6 +17,7 @@ import java.io.IOException
class
MainActivity
:
AppCompatActivity
()
{
private
lateinit
var
messages
:
Messages
private
val
friends
=
mutableListOf
<
Friend
>()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -25,6 +25,8 @@ class MainActivity : AppCompatActivity() {
setContentView
(
R
.
layout
.
activity_main
)
setSupportActionBar
(
toolbar
)
// messages = Messages(applicationContext)
fab
.
setOnClickListener
{
view
->
reloadFriends
()
}
...
...
@@ -51,8 +53,15 @@ class MainActivity : AppCompatActivity() {
private
fun
reloadFriends
()
{
fetchFriends
()
displayFriends
()
// fetchMessages()
}
Toast
.
makeText
(
this
,
"Friends reloaded."
,
Toast
.
LENGTH_SHORT
).
show
()
private
fun
fetchMessages
()
{
messages
.
fetchAll
()
Toast
.
makeText
(
this
,
"${messages.sent.size} messages sent, "
+
"${messages.inbox.size} messages received."
,
Toast
.
LENGTH_SHORT
).
show
()
}
private
fun
fetchFriends
()
{
...
...
@@ -102,8 +111,6 @@ class MainActivity : AppCompatActivity() {
val
nbFriends
=
adapter
.
itemCount
welcomeTitle
.
text
=
"$nbFriends ${"
friend
".plural(nbFriends)} on Dunbar"
Toast
.
makeText
(
this
@MainActivity
,
"$nbFriends "
,
Toast
.
LENGTH_LONG
).
show
()
}
private
fun
getPhoto
(
id
:
Long
):
Bitmap
?
{
...
...
@@ -111,7 +118,8 @@ class MainActivity : AppCompatActivity() {
try
{
val
inputStream
=
ContactsContract
.
Contacts
.
openContactPhotoInputStream
(
contentResolver
,
ContentUris
.
withAppendedId
(
contentResolver
,
ContentUris
.
withAppendedId
(
ContactsContract
.
Contacts
.
CONTENT_URI
,
java
.
lang
.
Long
.
valueOf
(
id
)
)
...
...
@@ -125,7 +133,7 @@ class MainActivity : AppCompatActivity() {
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
Log
.
d
(
"--> "
,
photo
.
toString
()
)
println
(
"Photo for $id: $photo"
)
return
photo
}
}
app/src/main/java/fr/plnech/dunbar/Messages.kt
0 → 100644
View file @
f7f464bd
package
fr.plnech.dunbar
import
android.content.Context
import
android.net.Uri
import
android.provider.Telephony
class
Messages
(
context
:
Context
)
{
private
val
contentResolver
=
context
.
contentResolver
var
inbox
:
MutableList
<
Map
<
String
,
String
?>>
=
mutableListOf
()
var
sent
:
MutableList
<
Map
<
String
,
String
?>>
=
mutableListOf
()
fun
fetchAll
()
{
inbox
=
fetchMessages
(
Telephony
.
Sms
.
Inbox
.
CONTENT_URI
)
sent
=
fetchMessages
(
Telephony
.
Sms
.
Sent
.
CONTENT_URI
)
}
private
fun
fetchMessages
(
uri
:
Uri
):
MutableList
<
Map
<
String
,
String
?>>
{
val
messages
=
mutableListOf
<
Map
<
String
,
String
?>>()
contentResolver
.
query
(
uri
,
null
,
null
,
null
,
null
).
let
{
if
(
it
!=
null
)
{
if
(
it
.
moveToFirst
())
{
while
(
it
.
moveToNext
())
{
println
(
"Processing message."
)
val
msg
=
mutableMapOf
<
String
,
String
?>()
for
(
i
in
0
until
it
.
count
)
{
for
(
col
in
it
.
columnNames
)
{
val
index
=
it
.
getColumnIndex
(
col
)
msg
[
col
]
=
it
.
getString
(
index
)
}
}
messages
.
add
(
msg
)
}
}
else
{
println
(
"No messages in ${uri.toString().replace("
content
:
//sms/", "")}.")
}
it
.
close
()
}
else
{
println
(
"Null cursor."
)
}
}
return
messages
}
}
\ No newline at end of file
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