Skip to content

Commit

Permalink
Merge pull request #17 from osik2000/11-add-clip-screen
Browse files Browse the repository at this point in the history
11 add clip screen
  • Loading branch information
osik2000 authored Dec 23, 2023
2 parents 1390e4c + 2a7617d commit 3dc0453
Show file tree
Hide file tree
Showing 17 changed files with 494 additions and 349 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ dependencies {
implementation("androidx.media3:media3-exoplayer-dash:1.2.0")
implementation("androidx.media3:media3-ui:1.2.0")


// Trim video
implementation("com.github.a914-gowtham:android-video-trimmer:1.7.17")
// testImplementation("junit:junit:4.13.2")
// androidTestImplementation("androidx.test.ext:junit:1.1.5")
// androidTestImplementation("androidx.compose.ui:ui-test-junit4")
Expand Down
7 changes: 6 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@

-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }


-dontwarn com.gowtham.library**
-keep class com.gowtham.library** { *; }
-keep interface com.gowtham.library** { *; }
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<queries>
<package android:name="com.bumptech.glide.request.target.NotificationTarget" />
</queries>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package pl.pawelosinski.skatefreak.model

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf

data class TrickInfo (
val id: String = "",
val name: String = "",
val description: String = "",
val difficulty: String = "",
val category: String = "",
val photoUrl: String = "",
)
) {
companion object {
var chosenOne = mutableStateOf(TrickInfo())
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package pl.pawelosinski.skatefreak.model

import androidx.compose.runtime.mutableStateOf

data class TrickRecord(
val id: String = "",
var id: String = "",
val userID: String = "",
val trickID: String = "",
val date: String = "",
val title: String = "",
val userDescription: String = "",
val videoUrl: String = "",
var videoUrl: String = "",
val usersWhoSetAsFavorite: MutableList<String> = mutableListOf(),
)
) {
companion object {
val trimmedVideoPath = mutableStateOf("")
var localFileUri = mutableStateOf("")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import com.google.firebase.storage.ktx.storage
import pl.pawelosinski.skatefreak.local.allTrickRecords
import pl.pawelosinski.skatefreak.local.allTrickInfo
import pl.pawelosinski.skatefreak.local.allTrickRecords
import pl.pawelosinski.skatefreak.local.loggedUser
import pl.pawelosinski.skatefreak.model.TrickInfo
import pl.pawelosinski.skatefreak.model.TrickRecord
import pl.pawelosinski.skatefreak.model.User
import pl.pawelosinski.skatefreak.ui.common.deleteTempFile
import java.io.File


lateinit var databaseService: DatabaseService
Expand Down Expand Up @@ -258,7 +260,7 @@ class DatabaseService {
val avatarRef = storageRef.child("userAvatar/$userID$fileExtension")

val uploadTask = avatarRef.putFile(file)
val urlTask = uploadTask.continueWithTask { task ->
uploadTask.continueWithTask { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
Expand All @@ -279,6 +281,71 @@ class DatabaseService {
}
}

private fun uploadTrickRecordVideo(
userID: String,
trickRecordID: String,
file: Uri,
onComplete: (String) -> Unit = {},
onFail: () -> Unit = {}
) {
val storageRef = storage.reference
val fileExtension = file.toString().substring(file.toString().lastIndexOf("."))
val videoRef = storageRef.child("trickRecord/video/$userID/$trickRecordID$fileExtension")

val uploadTask = videoRef.putFile(file)
uploadTask.continueWithTask { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
}
}
videoRef.downloadUrl
}.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d("DataService", "Video URL: ${task.result}")
val downloadUri = task.result
TrickRecord.localFileUri.value = ""
TrickRecord.trimmedVideoPath.value = ""
onComplete(downloadUri.toString())
} else {
Log.d("DataService", "Avatar URL failed: ${task.exception}")
onFail()
}
}
}

fun uploadTrickRecord(record: TrickRecord, onSuccess: () -> Unit = {}, onFail: () -> Unit = {}) {
val localFile = record.videoUrl
val databaseReference = database.getReference("your_collection_name")
val uniqueId = databaseReference.push().key
if(uniqueId == null) {
Log.e("DataService", "Error writing data. Unique ID is null")
return
}
record.id = uniqueId
val myRef = database.getReference("tricks/records/${record.id}")


val fileUri = Uri.fromFile(File(record.videoUrl))

uploadTrickRecordVideo(record.userID, record.id, fileUri, onComplete = { videoUrl ->
deleteTempFile(localFile)
record.videoUrl = videoUrl
myRef.setValue(record).addOnSuccessListener {
Log.d("DataService", "Trick record saved successfully.")
onSuccess()
}.addOnFailureListener {
Log.e("DataService", "Error writing data", it)
onFail()
}
}, onFail = {
Log.e("DataService", "Error writing data")
onFail()
})


}

// fun getUserByPhoneNumber(phoneNumber: String) : User {
// val myRef = database.getReference("users")
// var user: User? = null
Expand Down
Loading

0 comments on commit 3dc0453

Please sign in to comment.