Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Bug Fixes: Download/Wallpaper ones (trello.com/c/KZzyhyZW)
Browse files Browse the repository at this point in the history
  • Loading branch information
DawnImpulse committed Jan 5, 2019
1 parent 9d4d0c7 commit 822d565
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 50 deletions.
6 changes: 6 additions & 0 deletions app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 23 additions & 0 deletions app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions app/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@
</intent-filter>
</activity>

<!-- User Profile -->
<activity
android:name=".activities.UserActivity"
android:theme="@style/AppTheme.Fullscreen" />

<!-- Settings -->
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ import org.greenrobot.eventbus.ThreadMode
/**
* @author Saksham
*
* @note Last Branch Update - recent
* @note Last Branch Update - hotfixes
* @note Created on 2018-07-20 by Saksham
*
* @note Updates :
* Saksham - 2019 01 15 - hotfixes - issue in content uri & other bugs
*/
class CropActivity : AppCompatActivity(), View.OnClickListener {
private val NAME = "CropActivity"
Expand All @@ -54,11 +55,6 @@ class CropActivity : AppCompatActivity(), View.OnClickListener {
setContentView(R.layout.activity_crop)

displayDimen = displayRatio()
L.d(NAME, "${displayDimen.first} : ${displayDimen.second}")
/*cropImageView.setAspectRatio(displayDimen.second, displayDimen.first)
cropImageView.setFixedAspectRatio(true)
cropImageView.scaleType = CropImageView.ScaleType.CENTER_INSIDE
cropImageView.isAutoZoomEnabled = false*/

cropDefault.setOnClickListener(this)
cropSelected.setOnClickListener(this)
Expand All @@ -71,8 +67,10 @@ class CropActivity : AppCompatActivity(), View.OnClickListener {
if (it) {
getImage()
} else {
toast("Unable to complete download , please try again!!")
finish()
runOnUiThread {
toast("Unable to complete download , please try again!!")
finish()
}
}
}
} else
Expand Down Expand Up @@ -117,19 +115,14 @@ class CropActivity : AppCompatActivity(), View.OnClickListener {
//get image from storage
private fun getImage() {
launch {
//val bmOptions = BitmapFactory.Options()
//val bitmap = BitmapFactory.decodeFile("$path/$id.jpg", bmOptions)
runOnUiThread {
/*cropLayout.show()
cropProgress.gone()
cropImageView.setImageBitmap(bitmap)
image = bitmap*/
val intent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
intent.data = "$path/$id.jpg".toFileUri()
sendBroadcast(intent)

val context = this@CropActivity
WallpaperHandler.cropAndSetWallpaper(context, "$path/$id.jpg".toContentUri(context))
val contentUri = "$path/$id.jpg".toContentUri(context)
WallpaperHandler.cropAndSetWallpaper(context, contentUri)
context.finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import kotlinx.coroutines.experimental.launch
/**
* @author Saksham
*
* @note Last Branch Update - master
* @note Last Branch Update - hotfixes
* @note Created on 2018-07-22 by Saksham
*
* @note Updates :
* 2018 08 03 - recent - Saksham - using android default download manager
* 2018 12 16 - master - Saksham - using dynamic path
* 2019 01 05 - hotfixes - Saksham - handling of null cursor in download manager
*/
object DownloadHandler {

Expand Down Expand Up @@ -105,32 +106,34 @@ object DownloadHandler {

if (downloadManager.query(q) != null) {
val cursor = downloadManager.query(q)
cursor.moveToFirst()

if (cursor.count > 0) {
val bytes_downloaded = cursor.getInt(cursor
.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))

if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) === DownloadManager.STATUS_SUCCESSFUL) {
downloading = false
callback(true)
}
if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) === DownloadManager.STATUS_FAILED) {
cursor?.let {
if (cursor.count > 0) {
cursor.moveToFirst()

val bytes_downloaded = cursor.getInt(cursor
.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))

if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) === DownloadManager.STATUS_SUCCESSFUL) {
downloading = false
callback(true)
}
if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) === DownloadManager.STATUS_FAILED) {
downloading = false
callback(false)
}

context as AppCompatActivity
context.runOnUiThread {
if (bytes_total > 0)
progress(Pair(bytes_downloaded, bytes_total))
}

cursor.close()
} else {
cursor.close()
downloading = false
callback(false)
}

context as AppCompatActivity
context.runOnUiThread {
if (bytes_total > 0)
progress(Pair(bytes_downloaded, bytes_total))
}

cursor.close()
} else {
cursor.close()
downloading = false
}
} else {
downloading = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import java.io.IOException
/**
* @author Saksham
*
* @note Last Branch Update - master
* @note Last Branch Update - hotfixes
* @note Created on 2018-10-02 by Saksham
*
* @note Updates :
* Saksham - 2019 01 05 - hotfixes - general exception for unsplash auth error
*/
object ErrorUtils {

Expand All @@ -49,7 +50,7 @@ object ErrorUtils {

try {
error = converter.convert(response.errorBody())
} catch (e: IOException) {
} catch (e: Exception) {
return UnsplashAuthError()
}

Expand Down
10 changes: 6 additions & 4 deletions app/src/main/kotlin/com/dawnimpulse/wallup/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.provider.MediaStore
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import androidx.core.net.toUri
import androidx.core.widget.toast
import androidx.fragment.app.FragmentManager
Expand Down Expand Up @@ -76,21 +77,22 @@ fun String.toFileUri(): Uri {

// file path string to content uri
fun String.toContentUri(context: Context): Uri {
return this.toFileUri().toContentUri(context)
return FileProvider.getUriForFile(context,"com.dawnimpulse.wallup",toFile())
//return this.toFileUri().toContentUri(context)
}

// tree uri path to file uri path
fun String.toFileString(): String {
if (this.contains(":")) {
return if (this.contains(":")) {
var substring = split(":")
var tree = substring[0]

return if (tree.contains("primary"))
if (tree.contains("primary"))
Environment.getExternalStorageDirectory().path + "/${substring[1]}"
else
"/storage/${tree.replace("/tree/", "")}/${substring[1]}"
} else
return this
this
}

//convert to content uri
Expand Down

0 comments on commit 822d565

Please sign in to comment.