1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

Fix result from image edit always null

This commit is contained in:
Ammar Githam 2021-01-03 20:29:41 +09:00
parent 33ec122a94
commit 0ec3691cac
2 changed files with 18 additions and 7 deletions

View File

@ -34,12 +34,14 @@ import com.yalantis.ucrop.UCropActivity;
import com.yalantis.ucrop.UCropFragment;
import com.yalantis.ucrop.UCropFragmentCallback;
import java.io.File;
import java.util.List;
import awais.instagrabber.R;
import awais.instagrabber.databinding.FragmentImageEditBinding;
import awais.instagrabber.fragments.imageedit.filters.filters.Filter;
import awais.instagrabber.models.SavedImageEditState;
import awais.instagrabber.utils.AppExecutors;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.ImageEditViewModel;
@ -173,18 +175,27 @@ public class ImageEditFragment extends Fragment {
binding.cancel.setOnClickListener(v -> {
viewModel.cancel();
final NavController navController = NavHostFragment.findNavController(this);
setNavControllerResult(navController, null);
navController.navigateUp();
});
binding.done.setOnClickListener(v -> {
final Context context = getContext();
if (context == null) return;
Utils.mediaScanFile(context, viewModel.getDestinationFile(), (path, uri) -> {
final NavBackStackEntry navBackStackEntry = NavHostFragment.findNavController(this).getPreviousBackStackEntry();
final Uri resultUri = viewModel.getResultUri().getValue();
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;
final SavedStateHandle savedStateHandle = navBackStackEntry.getSavedStateHandle();
savedStateHandle.set("result", uri);
});
});
savedStateHandle.set("result", resultUri);
}
private void setupCropFragment() {

View File

@ -148,7 +148,7 @@ public class ImageEditViewModel extends AndroidViewModel {
gpuImage.setFilter(new GPUImageFilterGroup(list));
final Uri uri = cropDestinationUri != null ? cropDestinationUri : originalUri;
gpuImage.setImage(uri);
gpuImage.saveToPictures(new File(destinationUri.toString()), false, uri1 -> setResultUri(uri));
gpuImage.saveToPictures(new File(destinationUri.toString()), false, uri1 -> setResultUri(destinationUri));
});
return;
}