Skip to content

Commit

Permalink
Finish download functionality <3
Browse files Browse the repository at this point in the history
  • Loading branch information
kl3jvi committed Oct 25, 2023
1 parent 45e671b commit decbed0
Show file tree
Hide file tree
Showing 92 changed files with 3,328 additions and 2,232 deletions.
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: # Replace with up detekt 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: kl3jvi
Expand All @@ -10,4 +10,4 @@ liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: # Replace with up detekt 4 custom sponsorship URLs e.g., ['link1', 'link2']
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Bug report
about: Create a report to help us improve
about: Create a report detekt help us improve
title: "[Bug]"
labels: bug
assignees: kl3jvi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint-and-build-job.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & upload to Firebase App Distribution
name: Build & upload detekt Firebase App Distribution

on:
push:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}

- name: Upload Artifact to Firebase App Distribution
- name: Upload Artifact detekt Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{ secrets.FIREBASE_APP_ID }}
Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ dependencies {


implementation libs.hilt.android
implementation libs.fragment.ktx
kapt(libs.hilt.android.compiler)

implementation libs.retrofit2.retrofit
Expand Down Expand Up @@ -266,6 +267,7 @@ dependencies {
implementation libs.androidx.startup.runtime
implementation libs.android.joda


testImplementation libs.turbine
testImplementation libs.junit
testImplementation libs.androidx.core
Expand All @@ -274,4 +276,5 @@ dependencies {
testImplementation libs.mockk
testImplementation libs.kotlinx.coroutines.test
testImplementation(libs.apollo.testing.support)

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
Expand Down
138 changes: 69 additions & 69 deletions app/src/main/java/com/kl3jvi/animity/analytics/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,84 @@ import kotlin.contracts.contract
* @property firebaseAnalytics An instance of Firebase Analytics.
*/
class Analytics
@Inject
constructor(
private val firebaseAnalytics: FirebaseAnalytics,
) {
/**
* Removes special characters from the given string, except for underscores (_).
*
* @param string The string to remove special characters from.
* @return The string with special characters removed.
*/
private fun String.removeSpecialCharacters() = replace("[ ,:](?!_)".toRegex(), "")
@Inject
constructor(
private val firebaseAnalytics: FirebaseAnalytics,
) {
/**
* Removes special characters from the given string, except for underscores (_).
*
* @param string The string to remove special characters from.
* @return The string with special characters removed.
*/
private fun String.removeSpecialCharacters() = replace("[ ,:](?!_)".toRegex(), "")

/**
* Logs an event with the given name and parameters to Firebase Analytics.
*
* @param event The name of the event to log.
* @param params A map of parameters to include with the event (optional).
*/
fun logEvent(
event: String,
params: Map<String, Any?>? = null,
) {
val bundle = params?.let { createBundle(it) }
/**
* Logs an event with the given name and parameters to Firebase Analytics.
*
* @param event The name of the event to log.
* @param params A map of parameters to include with the event (optional).
*/
fun logEvent(
event: String,
params: Map<String, Any?>? = null,
) {
val bundle = params?.let { createBundle(it) }

firebaseAnalytics.logEvent(event.removeSpecialCharacters(), bundle)
}
// firebaseAnalytics.logEvent(event.removeSpecialCharacters(), bundle)
}

/**
* Sets a user property with the given name and value in Firebase Analytics.
*
* @param name The name of the user property to set.
* @param value The value to set the user property to (optional).
*/
fun setUserProperty(
name: String,
value: String?,
) {
firebaseAnalytics.setUserPropertyRelease(name, value)
}
/**
* Sets a user property with the given name and value in Firebase Analytics.
*
* @param name The name of the user property to set.
* @param value The value to set the user property to (optional).
*/
fun setUserProperty(
name: String,
value: String?,
) {
// firebaseAnalytics.setUserPropertyRelease(name, value)
}

/**
* Logs the current screen to Firebase Analytics.
*
* @param context The current Context object.
* @param screenName A string representing the name of the current screen.
* @param screenClassOverride An optional string representing the name of the screen class to use in logs. If null, the class name of the Context will be used.
*/
fun logCurrentScreen(screenName: String) {
val screenDetails = mapOf(FirebaseAnalytics.Param.SCREEN_NAME to screenName)
if (BuildConfig.BUILD_TYPE == "release") {
logEvent(
FirebaseAnalytics.Event.SCREEN_VIEW,
screenDetails,
)
}
/**
* Logs the current screen to Firebase Analytics.
*
* @param context The current Context object.
* @param screenName A string representing the name of the current screen.
* @param screenClassOverride An optional string representing the name of the screen class to use in logs. If null, the class name of the Context will be used.
*/
fun logCurrentScreen(screenName: String) {
val screenDetails = mapOf(FirebaseAnalytics.Param.SCREEN_NAME to screenName)
if (BuildConfig.BUILD_TYPE == "release") {
logEvent(
FirebaseAnalytics.Event.SCREEN_VIEW,
screenDetails,
)
}
}

/**
* Creates a Bundle from the given map of parameters.
*
* @param params A map of parameters to include in the Bundle.
* @return A Bundle containing the given parameters.
*/
private fun createBundle(params: Map<String, Any?>): Bundle {
val bundle = Bundle()
params.forEach { (key, value) ->
when (value) {
is String -> bundle.putString(key, value)
is Boolean -> bundle.putBoolean(key, value)
is Int -> bundle.putInt(key, value)
is Long -> bundle.putLong(key, value)
is Double -> bundle.putDouble(key, value)
is Float -> bundle.putFloat(key, value)
}
/**
* Creates a Bundle from the given map of parameters.
*
* @param params A map of parameters to include in the Bundle.
* @return A Bundle containing the given parameters.
*/
private fun createBundle(params: Map<String, Any?>): Bundle {
val bundle = Bundle()
params.forEach { (key, value) ->
when (value) {
is String -> bundle.putString(key, value)
is Boolean -> bundle.putBoolean(key, value)
is Int -> bundle.putInt(key, value)
is Long -> bundle.putLong(key, value)
is Double -> bundle.putDouble(key, value)
is Float -> bundle.putFloat(key, value)
}
return bundle
}
return bundle
}
}

private fun FirebaseAnalytics.setUserPropertyRelease(
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Context
import android.os.Build
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.util.Consumer
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import androidx.work.Constraints
Expand Down Expand Up @@ -49,7 +50,7 @@ class AnimityApplication : Application(), Configuration.Provider {
}

private fun initOneSignal() {
FirebaseApp.initializeApp(this)
// FirebaseApp.initializeApp(this)
// OneSignal.initWithContext(this)
// OneSignal.setLogLevel(OneSignal.LOG_LEVEL.NONE, OneSignal.LOG_LEVEL.NONE)
// OneSignal.setAppId(Secrets.oneSignalKey)
Expand Down Expand Up @@ -115,7 +116,12 @@ class AnimityApplication : Application(), Configuration.Provider {
override fun getWorkManagerConfiguration() =
Configuration.Builder()
.setWorkerFactory(workerFactory)
.setMinimumLoggingLevel(Log.DEBUG)
.setInitializationExceptionHandler(
Consumer { throwable ->
Log.e("WorkManager", "Initialization error: ", throwable)
}
)
.setMinimumLoggingLevel(Log.INFO)
.build()

companion object {
Expand Down
22 changes: 0 additions & 22 deletions app/src/main/java/com/kl3jvi/animity/data/downloader/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ package com.kl3jvi.animity.data.downloader

import android.content.Context
import android.net.Uri
import android.util.Log
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.offline.DownloadRequest
import com.google.android.exoplayer2.offline.DownloadService
Expand Down Expand Up @@ -61,11 +58,6 @@ constructor(
private val appContext: Context,
private val downloadManager: DownloadManager,
) {
init {
getDownloadedVideos().forEach {
Log.e("Downloader", "Downloaded video: ${it.mediaId}")
}
}

fun downloadVideoUrl(url: String, downloadManagerListener: DownloadManager.Listener) {
DownloadService.sendAddDownload(
Expand All @@ -80,18 +72,4 @@ constructor(
)
downloadManager.addListener(downloadManagerListener)
}

fun getDownloadedVideos(): List<MediaItem> {
val downloads = downloadManager.currentDownloads
return downloads.mapNotNull { download ->
if (download.state == Download.STATE_COMPLETED) {
MediaItem.Builder()
.setUri(download.request.uri)
.setMediaId(download.request.id)
.build()
} else {
null
}
}
}
}
28 changes: 14 additions & 14 deletions app/src/main/java/com/kl3jvi/animity/data/enums/DnsTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ enum class DnsTypes(
GOOGLE_DNS(
url = "https://dns.google/dns-query",
ipAddresses =
listOf(
"8.8.4.4",
"8.8.8.8",
),
listOf(
"8.8.4.4",
"8.8.8.8",
),
),
CLOUD_FLARE_DNS(
url = "https://cloudflare-dns.com/dns-query",
ipAddresses =
listOf(
"1.1.1.1",
"1.0.0.1",
"2606:4700:4700::1111",
"2606:4700:4700::1001",
),
listOf(
"1.1.1.1",
"1.0.0.1",
"2606:4700:4700::1111",
"2606:4700:4700::1001",
),
),
AD_GUARD_DNS(
url = "https://dns.adguard.com/dns-query",
ipAddresses =
listOf(
"94.140.14.140",
"94.140.14.141",
),
listOf(
"94.140.14.140",
"94.140.14.141",
),
),
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ fun ApolloResponse<GetFollowersListQuery.Data>.convert(): List<Pair<List<User>,
id = it.id,
name = it.name,
avatar =
UserAvatar(
large = it.avatar?.large.orEmpty(),
),
UserAvatar(
large = it.avatar?.large.orEmpty(),
),
)
}
} ?: emptyList()
Expand All @@ -27,9 +27,9 @@ fun ApolloResponse<GetFollowersListQuery.Data>.convert(): List<Pair<List<User>,
id = it.id,
name = it.name,
avatar =
UserAvatar(
large = it.avatar?.large.orEmpty(),
),
UserAvatar(
large = it.avatar?.large.orEmpty(),
),
)
}
} ?: emptyList()
Expand Down
Loading

0 comments on commit decbed0

Please sign in to comment.