-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
ddc1174
commit 21eb950
Showing
146 changed files
with
2,033 additions
and
1,484 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
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/ismartcoding/plain/data/DownloadResult.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,3 @@ | ||
package com.ismartcoding.plain.data | ||
|
||
data class DownloadResult(val path : String, val success : Boolean, val message : String = "") |
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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/ismartcoding/plain/enums/RotationType.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,8 @@ | ||
package com.ismartcoding.plain.enums | ||
|
||
enum class RotationType(val value: Int) { | ||
ROTATION_0(0), | ||
ROTATION_90(90), | ||
ROTATION_180(180), | ||
ROTATION_270(270); | ||
} |
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
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/ismartcoding/plain/helpers/DownloadHelper.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,60 @@ | ||
package com.ismartcoding.plain.helpers | ||
|
||
import com.ismartcoding.lib.extensions.getFilenameExtension | ||
import com.ismartcoding.lib.extensions.isOk | ||
import com.ismartcoding.lib.extensions.scanFileByConnection | ||
import com.ismartcoding.lib.helpers.CryptoHelper | ||
import com.ismartcoding.lib.logcat.LogCat | ||
import com.ismartcoding.plain.MainApp | ||
import com.ismartcoding.plain.api.HttpClientManager | ||
import com.ismartcoding.plain.data.DownloadResult | ||
import io.ktor.client.request.get | ||
import io.ktor.client.statement.bodyAsChannel | ||
import io.ktor.util.cio.writeChannel | ||
import io.ktor.utils.io.copyAndClose | ||
import java.io.File | ||
|
||
object DownloadHelper { | ||
suspend fun downloadAsync(url: String, dir: String): DownloadResult { | ||
val httpClient = HttpClientManager.browserClient() | ||
return try { | ||
val r = httpClient.get(url) | ||
if (r.isOk()) { | ||
File(dir).mkdirs() | ||
var path = "$dir/${CryptoHelper.sha1(url.toByteArray())}" | ||
val extension = url.getFilenameExtension() | ||
if (extension.isNotEmpty()) { | ||
path += ".$extension" | ||
} | ||
val file = File(path) | ||
file.createNewFile() | ||
r.bodyAsChannel().copyAndClose(file.writeChannel()) | ||
MainApp.instance.scanFileByConnection(file, null) | ||
DownloadResult(path, true) | ||
} else { | ||
DownloadResult("", false, r.toString()) | ||
} | ||
} catch (ex: Exception) { | ||
LogCat.e(ex.toString()) | ||
ex.printStackTrace() | ||
DownloadResult("", false, ex.toString()) | ||
} | ||
} | ||
|
||
suspend fun downloadToTempAsync(url: String, tempFile: File): DownloadResult { | ||
val httpClient = HttpClientManager.browserClient() | ||
return try { | ||
val r = httpClient.get(url) | ||
if (r.isOk()) { | ||
r.bodyAsChannel().copyAndClose(tempFile.writeChannel()) | ||
DownloadResult(tempFile.absolutePath, true) | ||
} else { | ||
DownloadResult("", false, r.toString()) | ||
} | ||
} catch (ex: Exception) { | ||
LogCat.e(ex.toString()) | ||
ex.printStackTrace() | ||
DownloadResult("", false, ex.toString()) | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/ismartcoding/plain/helpers/PathHelper.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 com.ismartcoding.plain.helpers | ||
|
||
import android.os.Environment | ||
import java.io.File | ||
|
||
object PathHelper { | ||
fun getPlainPublicDir(dirName: String): File { | ||
val dir = Environment.getExternalStoragePublicDirectory(dirName) | ||
return File(dir, "PlainApp") | ||
} | ||
} |
Oops, something went wrong.