-
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
1 parent
57a949e
commit d82ae3b
Showing
10 changed files
with
273 additions
and
62 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
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
4 changes: 4 additions & 0 deletions
4
app/src/main/java/io/vonley/mi/ui/screens/packages/domain/remote/RepoService.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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package io.vonley.mi.ui.screens.packages.domain.remote | ||
|
||
import io.vonley.mi.ui.screens.packages.data.local.entity.Repo | ||
import okhttp3.ResponseBody | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Url | ||
|
||
interface RepoService { | ||
@GET | ||
suspend fun search(@Url url: String): Response<Repo> | ||
|
||
@GET | ||
suspend fun downloadFile(@Url url: String): Response<ResponseBody> | ||
} |
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
96 changes: 96 additions & 0 deletions
96
app/src/main/java/io/vonley/mi/ui/screens/packages/domain/usecase/SendPackageUseCase.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,96 @@ | ||
package io.vonley.mi.ui.screens.packages.domain.usecase | ||
|
||
import io.vonley.mi.common.Resource | ||
import io.vonley.mi.di.network.MiServer | ||
import io.vonley.mi.di.network.PSXService | ||
import io.vonley.mi.di.network.callbacks.PayloadCallback | ||
import io.vonley.mi.models.Payload | ||
import io.vonley.mi.models.enums.PlatformType | ||
import io.vonley.mi.ui.screens.consoles.domain.model.Console | ||
import io.vonley.mi.ui.screens.packages.data.local.entity.Package | ||
import io.vonley.mi.ui.screens.packages.data.local.entity.PackageType | ||
import io.vonley.mi.ui.screens.packages.domain.repository.PackageRepository | ||
import io.vonley.mi.utils.SharedPreferenceManager | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
class SendPackageUseCase @Inject constructor( | ||
val repo: PackageRepository, | ||
val service: PSXService, | ||
val miServer: MiServer, | ||
val manager: SharedPreferenceManager | ||
) { | ||
operator fun invoke(pkg: Package, onPayloadCallback: PayloadCallback): Flow<Resource<String>> = flow { | ||
when (pkg.type) { | ||
PackageType.APP -> { | ||
|
||
} | ||
|
||
PackageType.TOOL -> { | ||
|
||
|
||
} | ||
|
||
PackageType.PLUGIN -> { | ||
val console = (service.sync.target as? Console) | ||
|
||
if (console == null) { | ||
this@flow.emit( | ||
Resource.Error( | ||
"An Error Occurred", | ||
"Something went wrong with sending the payload" | ||
) | ||
) | ||
return@flow | ||
} | ||
|
||
if (console.type != PlatformType.PS4) { | ||
this@flow.emit( | ||
Resource.Error( | ||
"Unsupported Console", | ||
"Console is not supported" | ||
) | ||
) | ||
return@flow | ||
} | ||
|
||
val version = manager.targetVersion?.replace(".", "") | ||
if(version.isNullOrEmpty()) { | ||
this@flow.emit( | ||
Resource.Error( | ||
"Target is not connected", | ||
"Unknown console version... usually we get the target by connecting to the phone server" | ||
) | ||
) | ||
return@flow | ||
} | ||
|
||
if(!pkg.dl.containsKey(version)) { | ||
this@flow.emit( | ||
Resource.Error( | ||
"Package not found", | ||
"There are no legitimate versions for your console associated with this package." | ||
) | ||
) | ||
return@flow | ||
} | ||
|
||
val payload: Payload? = repo.fromPackage(pkg, version) | ||
|
||
if(payload == null) { | ||
this@flow.emit( | ||
Resource.Error( | ||
"Download Failed", | ||
"Could not download the file" | ||
) | ||
) | ||
return@flow | ||
} | ||
|
||
service.uploadBin(miServer, arrayListOf(payload), onPayloadCallback) | ||
} | ||
} | ||
|
||
} | ||
} |
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.