-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
804 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/rfcx/ranger/data/remote/terms/TermsEndpoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.rfcx.ranger.data.remote.terms | ||
|
||
import io.reactivex.Single | ||
import org.rfcx.ranger.entity.terms.TermsRequest | ||
import org.rfcx.ranger.entity.terms.TermsResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface TermsEndpoint { | ||
@POST("v1/users/accept-terms") | ||
fun sendPayload(@Body body: TermsRequest): Single<TermsResponse> | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/rfcx/ranger/data/remote/terms/TermsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.rfcx.ranger.data.remote.terms | ||
|
||
import io.reactivex.Single | ||
import org.rfcx.ranger.entity.terms.TermsRequest | ||
import org.rfcx.ranger.entity.terms.TermsResponse | ||
|
||
interface TermsRepository { | ||
fun sendBodyPayload(sendBody: TermsRequest): Single<TermsResponse> | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/rfcx/ranger/data/remote/terms/TermsRepositoryImp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.rfcx.ranger.data.remote.terms | ||
|
||
import io.reactivex.Single | ||
import org.rfcx.ranger.entity.terms.TermsRequest | ||
import org.rfcx.ranger.entity.terms.TermsResponse | ||
|
||
class TermsRepositoryImp(private val termsEndpoint: TermsEndpoint) : TermsRepository { | ||
override fun sendBodyPayload(sendBody: TermsRequest): Single<TermsResponse> { | ||
return termsEndpoint.sendPayload(sendBody) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/rfcx/ranger/data/remote/terms/TermsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.rfcx.ranger.data.remote.terms | ||
|
||
import io.reactivex.Single | ||
import org.rfcx.ranger.data.remote.domain.SingleUseCase | ||
import org.rfcx.ranger.data.remote.domain.executor.PostExecutionThread | ||
import org.rfcx.ranger.data.remote.domain.executor.ThreadExecutor | ||
import org.rfcx.ranger.entity.terms.TermsRequest | ||
import org.rfcx.ranger.entity.terms.TermsResponse | ||
|
||
class TermsUseCase(private val termsRepository: TermsRepository, | ||
threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionThread | ||
) : SingleUseCase<TermsRequest, TermsResponse>(threadExecutor, postExecutionThread) { | ||
override fun buildUseCaseObservable(params: TermsRequest): Single<TermsResponse> { | ||
return termsRepository.sendBodyPayload(params) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.rfcx.ranger.entity.terms | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
open class TermsRequest( | ||
val app: String | ||
) | ||
|
||
open class TermsResponse( | ||
@SerializedName("success") | ||
val success: Boolean | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/org/rfcx/ranger/service/CleanupAudioCacheWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.rfcx.ranger.service | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.LiveData | ||
import androidx.work.* | ||
import java.io.File | ||
import java.util.* | ||
import java.util.concurrent.TimeUnit | ||
|
||
class CleanupAudioCacheWorker(val context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { | ||
|
||
private val audioDirectory = File(context.cacheDir, DownLoadEventWorker.AUDIOS_SUB_DIRECTORY) | ||
|
||
override fun doWork(): Result { | ||
removeAudioCache() | ||
removeAudioInCache(applicationContext) | ||
return Result.success() | ||
} | ||
|
||
/* | ||
/* for version higher or equal 1.2.6 | ||
remove .opus all opus in 'audios' cache directory | ||
*/ | ||
*/ | ||
private fun removeAudioCache() { | ||
val date = Date(System.currentTimeMillis()) | ||
audioDirectory.listFiles()?.forEach { | ||
if (it.isFile | ||
&& (it.name.substring(it.name.lastIndexOf(".") + 1) == "opus") | ||
&& it.isLastModifiedOlderThan2Weeks(date)) { | ||
try { | ||
it.delete() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* for old version below 1.2.6 | ||
remove .opus all opus in main cache directory | ||
*/ | ||
private fun removeAudioInCache(context: Context) { | ||
val date = Date(System.currentTimeMillis()) | ||
context.cacheDir.listFiles()?.forEach { | ||
if (it.isFile && it.isLastModifiedOlderThan2Weeks(date)) { | ||
try { | ||
it.delete() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun File.isLastModifiedOlderThan2Weeks(date: Date): Boolean { | ||
return (date.time - this.lastModified()) > TWO_WEEKS | ||
} | ||
|
||
companion object { | ||
const val TWO_WEEKS: Long = 60 * 1000 * 60 * 24 * 14 | ||
private const val UNIQUE_WORK_KEY = "CleanupAudioCacheWorker" | ||
const val AUDIOS_SUB_DIRECTORY = "audios" | ||
|
||
fun enqueuePeriodically() { | ||
val workRequest = PeriodicWorkRequestBuilder<CleanupAudioCacheWorker>(1, TimeUnit.DAYS).build() | ||
WorkManager.getInstance().enqueueUniquePeriodicWork(UNIQUE_WORK_KEY, ExistingPeriodicWorkPolicy.REPLACE, workRequest) | ||
} | ||
|
||
fun workInfos(): LiveData<List<WorkInfo>> { | ||
return WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData(UNIQUE_WORK_KEY) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.