mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-23 07:07:30 +00:00
Fix result from image edit always null
This commit is contained in:
parent
33ec122a94
commit
0ec3691cac
@ -34,12 +34,14 @@ import com.yalantis.ucrop.UCropActivity;
|
|||||||
import com.yalantis.ucrop.UCropFragment;
|
import com.yalantis.ucrop.UCropFragment;
|
||||||
import com.yalantis.ucrop.UCropFragmentCallback;
|
import com.yalantis.ucrop.UCropFragmentCallback;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.databinding.FragmentImageEditBinding;
|
import awais.instagrabber.databinding.FragmentImageEditBinding;
|
||||||
import awais.instagrabber.fragments.imageedit.filters.filters.Filter;
|
import awais.instagrabber.fragments.imageedit.filters.filters.Filter;
|
||||||
import awais.instagrabber.models.SavedImageEditState;
|
import awais.instagrabber.models.SavedImageEditState;
|
||||||
|
import awais.instagrabber.utils.AppExecutors;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
import awais.instagrabber.viewmodels.ImageEditViewModel;
|
import awais.instagrabber.viewmodels.ImageEditViewModel;
|
||||||
|
|
||||||
@ -173,18 +175,27 @@ public class ImageEditFragment extends Fragment {
|
|||||||
binding.cancel.setOnClickListener(v -> {
|
binding.cancel.setOnClickListener(v -> {
|
||||||
viewModel.cancel();
|
viewModel.cancel();
|
||||||
final NavController navController = NavHostFragment.findNavController(this);
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
|
setNavControllerResult(navController, null);
|
||||||
navController.navigateUp();
|
navController.navigateUp();
|
||||||
});
|
});
|
||||||
binding.done.setOnClickListener(v -> {
|
binding.done.setOnClickListener(v -> {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
Utils.mediaScanFile(context, viewModel.getDestinationFile(), (path, uri) -> {
|
final Uri resultUri = viewModel.getResultUri().getValue();
|
||||||
final NavBackStackEntry navBackStackEntry = NavHostFragment.findNavController(this).getPreviousBackStackEntry();
|
if (resultUri == null) return;
|
||||||
|
Utils.mediaScanFile(context, new File(resultUri.toString()), (path, uri) -> AppExecutors.getInstance().mainThread().execute(() -> {
|
||||||
|
final NavController navController = NavHostFragment.findNavController(this);
|
||||||
|
setNavControllerResult(navController, resultUri);
|
||||||
|
navController.navigateUp();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNavControllerResult(@NonNull final NavController navController, final Uri resultUri) {
|
||||||
|
final NavBackStackEntry navBackStackEntry = navController.getPreviousBackStackEntry();
|
||||||
if (navBackStackEntry == null) return;
|
if (navBackStackEntry == null) return;
|
||||||
final SavedStateHandle savedStateHandle = navBackStackEntry.getSavedStateHandle();
|
final SavedStateHandle savedStateHandle = navBackStackEntry.getSavedStateHandle();
|
||||||
savedStateHandle.set("result", uri);
|
savedStateHandle.set("result", resultUri);
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCropFragment() {
|
private void setupCropFragment() {
|
||||||
|
@ -148,7 +148,7 @@ public class ImageEditViewModel extends AndroidViewModel {
|
|||||||
gpuImage.setFilter(new GPUImageFilterGroup(list));
|
gpuImage.setFilter(new GPUImageFilterGroup(list));
|
||||||
final Uri uri = cropDestinationUri != null ? cropDestinationUri : originalUri;
|
final Uri uri = cropDestinationUri != null ? cropDestinationUri : originalUri;
|
||||||
gpuImage.setImage(uri);
|
gpuImage.setImage(uri);
|
||||||
gpuImage.saveToPictures(new File(destinationUri.toString()), false, uri1 -> setResultUri(uri));
|
gpuImage.saveToPictures(new File(destinationUri.toString()), false, uri1 -> setResultUri(destinationUri));
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user