From 00f33cab3eeb0d99e1ac634e8d51df4c1c826721 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Thu, 11 Jul 2019 00:37:21 +0530 Subject: [PATCH] Fix Crashing on profile/banner selecting --- app/src/main/assets/retro-changelog.html | 2 +- .../retromusic/activities/UserInfoActivity.kt | 99 +++++-------------- .../res/layout-xlarge/activity_user_info.xml | 11 ++- .../main/res/layout/activity_user_info.xml | 4 +- .../res/layout/item_list_quick_actions.xml | 4 +- 5 files changed, 37 insertions(+), 83 deletions(-) diff --git a/app/src/main/assets/retro-changelog.html b/app/src/main/assets/retro-changelog.html index bb48150a..4d77c2dd 100644 --- a/app/src/main/assets/retro-changelog.html +++ b/app/src/main/assets/retro-changelog.html @@ -1 +1 @@ -

We're really sorry for Announcing this Retro Music is driving towards pure Android Material Design guidelines we don't want any unnecessary UI elements that don't need for Music player.

v3.2.120

v3.2.105

v3.2.100

v3.2.000

v3.1.900

v3.1.850

v3.1.800

v3.1.700

v3.1.400

v3.1.300

v3.1.240

v3.1.200

v3.0.570

If you see entire app white or dark or black select same theme in settings to fix

FAQ's

*If you face any UI related issues you clear app data and cache, if its not working try to uninstall and install again.

\ No newline at end of file +

We're really sorry for Announcing this Retro Music is driving towards pure Android Material Design guidelines we don't want any unnecessary UI elements that don't need for Music player.

v3.2.120

v3.2.105

v3.2.100

v3.2.000

v3.1.900

v3.1.850

v3.1.800

v3.1.700

v3.1.400

v3.1.300

v3.1.240

v3.1.200

v3.0.570

If you see entire app white or dark or black select same theme in settings to fix

FAQ's

*If you face any UI related issues you clear app data and cache, if its not working try to uninstall and install again.

\ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt index 1b4dc5dd..5030e32d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt @@ -1,18 +1,20 @@ package code.name.monkey.retromusic.activities import android.app.Activity -import android.content.* +import android.content.ContentUris +import android.content.Context +import android.content.ContextWrapper +import android.content.Intent import android.content.res.ColorStateList import android.graphics.Bitmap import android.net.Uri import android.os.Bundle import android.provider.DocumentsContract -import android.provider.MediaStore +import android.provider.MediaStore.Images.Media import android.provider.MediaStore.Images.Media.getBitmap import android.text.TextUtils import android.view.MenuItem import android.widget.Toast -import androidx.core.content.FileProvider import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialUtil @@ -56,10 +58,10 @@ class UserInfoActivity : AbsBaseActivity() { name.setText(PreferenceUtil.getInstance().userName) bio.setText(PreferenceUtil.getInstance().userBio) - if (!PreferenceUtil.getInstance().profileImage.isEmpty()) { + if (PreferenceUtil.getInstance().profileImage.isNotEmpty()) { loadImageFromStorage(PreferenceUtil.getInstance().profileImage) } - if (!PreferenceUtil.getInstance().bannerImage.isEmpty()) { + if (PreferenceUtil.getInstance().bannerImage.isNotEmpty()) { loadBannerFromStorage(PreferenceUtil.getInstance().bannerImage) } userImage.setOnClickListener { @@ -129,7 +131,7 @@ class UserInfoActivity : AbsBaseActivity() { private fun selectBannerImage() { if (TextUtils.isEmpty(PreferenceUtil.getInstance().bannerImage)) { - val pickImageIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + val pickImageIntent = Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI) pickImageIntent.type = "image/*" //pickImageIntent.putExtra("crop", "true") pickImageIntent.putExtra("outputX", 1290) @@ -147,7 +149,7 @@ class UserInfoActivity : AbsBaseActivity() { private fun pickNewPhoto() { - val pickImageIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + val pickImageIntent = Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI) pickImageIntent.type = "image/*" pickImageIntent.putExtra("crop", "true") pickImageIntent.putExtra("outputX", 512) @@ -163,42 +165,30 @@ class UserInfoActivity : AbsBaseActivity() { if (resultCode == Activity.RESULT_OK && data != null) { when (requestCode) { PICK_IMAGE_REQUEST -> { - val uri = data.data try { - val bitmap = getResizedBitmap(getBitmap(contentResolver, uri), PROFILE_ICON_SIZE) - val profileImagePath = saveToInternalStorage(bitmap, USER_PROFILE) - PreferenceUtil.getInstance().saveProfileImage(profileImagePath) - loadImageFromStorage(profileImagePath) + data.data?.let { + val bitmap = getResizedBitmap(getBitmap(contentResolver, it), PROFILE_ICON_SIZE) + val profileImagePath = saveToInternalStorage(bitmap, USER_PROFILE) + PreferenceUtil.getInstance().saveProfileImage(profileImagePath) + loadImageFromStorage(profileImagePath) + } + } catch (e: IOException) { e.printStackTrace() } } - CROP_IMAGE_REQUEST -> { - val extras: Bundle = data.extras!! - val selectedBitmap: Bitmap = extras.getParcelable("data") - val profileImagePath = saveToInternalStorage(selectedBitmap, USER_PROFILE) - PreferenceUtil.getInstance().saveProfileImage(profileImagePath) - loadImageFromStorage(profileImagePath) - } PICK_BANNER_REQUEST -> { - val uri = data.data try { - val bitmap = getBitmap(contentResolver, uri) - val profileImagePath = saveToInternalStorage(bitmap, USER_BANNER) - PreferenceUtil.getInstance().setBannerImagePath(profileImagePath) - loadBannerFromStorage(profileImagePath) + data.data?.let { + val bitmap = getBitmap(contentResolver, it) + val profileImagePath = saveToInternalStorage(bitmap, USER_BANNER) + PreferenceUtil.getInstance().setBannerImagePath(profileImagePath) + loadBannerFromStorage(profileImagePath) + } } catch (e: IOException) { e.printStackTrace() } } - CROP_BANNER_REQUEST -> { - val selectedBitmap: Bitmap? = data.extras?.getParcelable("date") - val profileImagePath = selectedBitmap?.let { saveToInternalStorage(it, USER_BANNER) } - profileImagePath?.let { - PreferenceUtil.getInstance().saveProfileImage(it) - loadImageFromStorage(it) - } - } } } } @@ -213,8 +203,8 @@ class UserInfoActivity : AbsBaseActivity() { val documentId = DocumentsContract.getDocumentId(aUri) if ("com.android.providers.media.documents" == aUri.authority) { val id = documentId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1] - val selection = MediaStore.Images.Media._ID + "=" + id - imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection) + val selection = Media._ID + "=" + id + imagePath = getImagePath(Media.EXTERNAL_CONTENT_URI, selection) } else if ("com.android.providers.downloads.documents" == aUri.authority) { val contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), java.lang.Long.valueOf(documentId)) @@ -233,50 +223,13 @@ class UserInfoActivity : AbsBaseActivity() { val cursor = App.context.contentResolver.query(aUri, null, aSelection, null, null) if (cursor != null) { if (cursor.moveToFirst()) { - path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)) + path = cursor.getString(cursor.getColumnIndex(Media.DATA)) } cursor.close() } return path } - private fun performBannerCrop(picturePath: Uri?) { - val photoUri = FileProvider.getUriForFile(this, "$packageName.provider", File(getImagePathFromUri(picturePath))) - try { - - val cropIntent = Intent("com.android.camera.action.CROP") - cropIntent.setDataAndType(photoUri, "image/*") - cropIntent.putExtra("crop", "true") - cropIntent.putExtra("aspectX", 1) - cropIntent.putExtra("aspectY", 1) - cropIntent.putExtra("return-data", true) - cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(cropIntent, CROP_BANNER_REQUEST) - } catch (anfe: ActivityNotFoundException) { - val errorMessage = "your device doesn't support the crop action!" - Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show() - } - } - - private fun performCrop(imageUri: Uri) { - val photoUri = FileProvider.getUriForFile(this, "$packageName.provider", File(getImagePathFromUri(imageUri))) - try { - val cropIntent = Intent("com.android.camera.action.CROP") - cropIntent.setDataAndType(photoUri, "image/*") - cropIntent.putExtra("crop", "true") - cropIntent.putExtra("aspectX", 1) - cropIntent.putExtra("aspectY", 1) - cropIntent.putExtra("outputX", 280) - cropIntent.putExtra("outputY", 280) - cropIntent.putExtra("return-data", true) - cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(cropIntent, CROP_IMAGE_REQUEST) - } catch (anfe: ActivityNotFoundException) { - val errorMessage = "your device doesn't support the crop action!" - Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show() - } - } - private fun loadBannerFromStorage(profileImagePath: String) { disposable.add(Compressor(this) .setQuality(100) @@ -323,9 +276,7 @@ class UserInfoActivity : AbsBaseActivity() { companion object { private const val PICK_IMAGE_REQUEST = 9002 - private const val CROP_IMAGE_REQUEST = 9003 private const val PICK_BANNER_REQUEST = 9004 - private const val CROP_BANNER_REQUEST = 9005 private const val PROFILE_ICON_SIZE = 400 } } diff --git a/app/src/main/res/layout-xlarge/activity_user_info.xml b/app/src/main/res/layout-xlarge/activity_user_info.xml index 5655da6e..80bda0ba 100644 --- a/app/src/main/res/layout-xlarge/activity_user_info.xml +++ b/app/src/main/res/layout-xlarge/activity_user_info.xml @@ -98,12 +98,12 @@ @@ -119,12 +119,12 @@ @@ -135,7 +135,8 @@ android:background="@null" android:hint="@string/bio" android:inputType="textPersonName|textCapWords|text" - android:textAppearance="@style/TextAppearance.AppCompat.Subhead" /> + android:textAppearance="@style/TextAppearance.AppCompat.Subhead" + android:visibility="gone" /> @@ -147,8 +148,8 @@ android:layout_gravity="bottom" android:layout_margin="16dp" android:gravity="center" - app:iconGravity="textStart" android:padding="16dp" android:text="@string/save" - app:icon="@drawable/ic_save_white_24dp" /> + app:icon="@drawable/ic_save_white_24dp" + app:iconGravity="textStart" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_user_info.xml b/app/src/main/res/layout/activity_user_info.xml index 708ed465..6e2e4121 100644 --- a/app/src/main/res/layout/activity_user_info.xml +++ b/app/src/main/res/layout/activity_user_info.xml @@ -35,7 +35,9 @@ diff --git a/app/src/main/res/layout/item_list_quick_actions.xml b/app/src/main/res/layout/item_list_quick_actions.xml index 354ef1a1..bd1a81b2 100644 --- a/app/src/main/res/layout/item_list_quick_actions.xml +++ b/app/src/main/res/layout/item_list_quick_actions.xml @@ -26,7 +26,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="4dp" - android:layout_marginEnd="8dp" + android:layout_marginEnd="4dp" android:layout_weight="1" android:padding="10dp" android:text="@string/action_play_all" @@ -41,7 +41,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="4dp" - android:layout_marginEnd="8dp" + android:layout_marginEnd="4dp" android:layout_weight="1" android:padding="10dp" android:text="@string/shuffle"