Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Feb 9, 2023
1 parent fcf73a9 commit bec305d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/andrew/apollo/cache/ImageCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static String hashKeyForDisk(String key) {
}

/**
* http://stackoverflow.com/questions/332079
* <a href="http://stackoverflow.com/questions/332079">...</a>
*
* @param bytes The bytes to convert.
* @return A {@link String} converted from the bytes of a hashable key used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import android.view.View;
import android.view.View.OnClickListener;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
Expand Down Expand Up @@ -75,13 +79,9 @@
*
* @author Andrew Neal (andrewdneal@gmail.com)
*/
public class ProfileActivity extends ActivityBase implements OnPageChangeListener,
Listener, OnClickListener, DeleteDialogCallback {
public class ProfileActivity extends ActivityBase implements ActivityResultCallback<ActivityResult>,
OnPageChangeListener, Listener, OnClickListener, DeleteDialogCallback {

/**
* request code to load new photo
*/
private static final int NEW_PHOTO = 0x487B;
/**
* page index of the {@link com.andrew.apollo.ui.fragments.profile.ArtistSongFragment}
* if {@link Type#ARTIST} is set
Expand Down Expand Up @@ -123,6 +123,11 @@ public class ProfileActivity extends ActivityBase implements OnPageChangeListene
*/
private static final String[] GET_MEDIA = {MediaColumns.DATA};

/**
*
*/
private ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this);

/**
* View pager
*/
Expand Down Expand Up @@ -653,8 +658,20 @@ public void onTabSelected(int position) {
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
if (requestCode == NEW_PHOTO && intent != null && intent.getData() != null) {
if (requestCode == REQUEST_DELETE_FILES && resultCode == RESULT_OK) {
MusicUtils.onPostDelete(this);
refreshAll();
}
}

/**
* {@inheritDoc}
*/
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == RESULT_OK) {
Intent intent = result.getData();
if (intent != null && intent.getData() != null) {
Cursor cursor = getContentResolver().query(intent.getData(), GET_MEDIA, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
Expand All @@ -677,9 +694,6 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
} else {
selectOldPhoto();
}
} else if (requestCode == REQUEST_DELETE_FILES) {
MusicUtils.onPostDelete(this);
refreshAll();
}
}
}
Expand Down Expand Up @@ -724,7 +738,7 @@ public void selectNewPhoto() {
// Now open the gallery
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType(MIME_IMAGE);
startActivityForResult(intent, NEW_PHOTO);
activityResultLauncher.launch(intent);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/devspark/appmsg/AppMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

/**
* In-layout notifications. Based on {@link android.widget.Toast} notifications
* and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).
* and article by Cyril Mottier (<a href="http://android.cyrilmottier.com/?p=773">...</a>).
*
* @author e.shishkin
*/
Expand Down

0 comments on commit bec305d

Please sign in to comment.