-
Notifications
You must be signed in to change notification settings - Fork 0
Laurislopata/upload image #184
Changes from all commits
7a08106
9f37236
7d03ee6
3eb8f60
7119708
9cc7ce0
272b76b
221cf77
e06de9d
8172990
1c5b5a2
5699a4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ch.sdp.vibester | ||
|
||
import ch.sdp.vibester.util.Util | ||
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 UtilTest { | ||
@Test | ||
fun newIdIsCorrectLength() { | ||
assertEquals(Util.createNewId().length, 10) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ch.sdp.vibester.database | ||
|
||
import android.content.ContentValues | ||
import android.net.Uri | ||
import android.util.Log | ||
import ch.sdp.vibester.profile.UserProfile | ||
import com.google.firebase.database.DataSnapshot | ||
import com.google.firebase.database.DatabaseError | ||
import com.google.firebase.database.ValueEventListener | ||
import com.google.firebase.database.ktx.getValue | ||
import javax.inject.Inject | ||
|
||
/** | ||
* The users class which handled all the interactions with the database that are linked to users | ||
*/ | ||
|
||
class ImageRepo @Inject constructor() { | ||
private val storageRef = Storage.get().reference | ||
|
||
fun uploadFile(filePath: String, fileUri: Uri, callback: () -> Unit): Unit { | ||
val profilePicRef = storageRef.child(filePath) | ||
|
||
var uploadTask = profilePicRef.putFile(fileUri) | ||
|
||
// taskSnapshot.metadata contains file metadata such as size, content-type, etc. | ||
uploadTask.addOnSuccessListener { taskSnapshot -> | ||
callback() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you will add the task later but you can put everything in one line here since the callback() is short, it will not affect the readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Also, since testing these calls is hard, maybe consider concatenating some operations or lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also agreed, it's an easy way to make the coverage of external calls better. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ch.sdp.vibester.database | ||
|
||
import com.google.firebase.ktx.Firebase | ||
import com.google.firebase.storage.FirebaseStorage | ||
import com.google.firebase.storage.ktx.storage | ||
|
||
/** | ||
* The Database objects that returns our storage instance | ||
*/ | ||
|
||
object Storage { | ||
fun get(): FirebaseStorage { | ||
return Firebase.storage("gs://vibester-sdp.appspot.com") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ch.sdp.vibester.util | ||
|
||
class Util { | ||
companion object { | ||
/** | ||
* A function that generates a random ID for database storage | ||
*/ | ||
fun createNewId(): String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider adding documentation for this (explaining the form of the id, etc) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
val charPool : List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9') | ||
val newId = (1..10) | ||
.map { i -> kotlin.random.Random.nextInt(0, charPool.size) } | ||
.map(charPool::get) | ||
.joinToString(""); | ||
|
||
return newId | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.