mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Converted SimilarImageDialogFragment to kotlin
This commit is contained in:
parent
76670f8bf8
commit
90c2e041f3
2 changed files with 105 additions and 109 deletions
|
|
@ -1,109 +0,0 @@
|
||||||
package fr.free.nrw.commons.upload;
|
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.Window;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
|
||||||
import fr.free.nrw.commons.R;
|
|
||||||
import fr.free.nrw.commons.databinding.FragmentSimilarImageDialogBinding;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by harisanker on 14/2/18.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class SimilarImageDialogFragment extends DialogFragment {
|
|
||||||
|
|
||||||
Callback callback;//Implemented interface from shareActivity
|
|
||||||
Boolean gotResponse = false;
|
|
||||||
|
|
||||||
private FragmentSimilarImageDialogBinding binding;
|
|
||||||
|
|
||||||
public SimilarImageDialogFragment() {
|
|
||||||
}
|
|
||||||
public interface Callback {
|
|
||||||
void onPositiveResponse();
|
|
||||||
|
|
||||||
void onNegativeResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(Callback callback) {
|
|
||||||
this.callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
||||||
binding = FragmentSimilarImageDialogBinding.inflate(inflater, container, false);
|
|
||||||
|
|
||||||
|
|
||||||
binding.orginalImage.setHierarchy(GenericDraweeHierarchyBuilder
|
|
||||||
.newInstance(getResources())
|
|
||||||
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
|
||||||
R.drawable.ic_image_black_24dp,getContext().getTheme()))
|
|
||||||
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
|
||||||
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
|
||||||
.build());
|
|
||||||
binding.possibleImage.setHierarchy(GenericDraweeHierarchyBuilder
|
|
||||||
.newInstance(getResources())
|
|
||||||
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
|
||||||
R.drawable.ic_image_black_24dp,getContext().getTheme()))
|
|
||||||
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
|
||||||
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
|
||||||
.build());
|
|
||||||
|
|
||||||
binding.orginalImage.setImageURI(Uri.fromFile(new File(getArguments().getString("originalImagePath"))));
|
|
||||||
binding.possibleImage.setImageURI(Uri.fromFile(new File(getArguments().getString("possibleImagePath"))));
|
|
||||||
|
|
||||||
binding.postiveButton.setOnClickListener(v -> onPositiveButtonClicked());
|
|
||||||
binding.negativeButton.setOnClickListener(v -> onNegativeButtonClicked());
|
|
||||||
|
|
||||||
return binding.getRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
|
||||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
// I user dismisses dialog by pressing outside the dialog.
|
|
||||||
if (!gotResponse) {
|
|
||||||
callback.onNegativeResponse();
|
|
||||||
}
|
|
||||||
super.onDismiss(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNegativeButtonClicked() {
|
|
||||||
callback.onNegativeResponse();
|
|
||||||
gotResponse = true;
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPositiveButtonClicked() {
|
|
||||||
callback.onPositiveResponse();
|
|
||||||
gotResponse = true;
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
binding = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.Window
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
||||||
|
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder
|
||||||
|
import fr.free.nrw.commons.R
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentSimilarImageDialogBinding
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by harisanker on 14/2/18.
|
||||||
|
*/
|
||||||
|
class SimilarImageDialogFragment : DialogFragment() {
|
||||||
|
var callback: Callback? = null //Implemented interface from shareActivity
|
||||||
|
var gotResponse: Boolean = false
|
||||||
|
|
||||||
|
private var _binding: FragmentSimilarImageDialogBinding? = null
|
||||||
|
private val binding: FragmentSimilarImageDialogBinding get() = _binding!!
|
||||||
|
|
||||||
|
interface Callback {
|
||||||
|
fun onPositiveResponse()
|
||||||
|
|
||||||
|
fun onNegativeResponse()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View {
|
||||||
|
_binding = FragmentSimilarImageDialogBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
|
binding.orginalImage.hierarchy =
|
||||||
|
GenericDraweeHierarchyBuilder.newInstance(resources).setPlaceholderImage(
|
||||||
|
VectorDrawableCompat.create(
|
||||||
|
resources, R.drawable.ic_image_black_24dp, requireContext().theme
|
||||||
|
)
|
||||||
|
).setFailureImage(
|
||||||
|
VectorDrawableCompat.create(
|
||||||
|
resources, R.drawable.ic_error_outline_black_24dp, requireContext().theme
|
||||||
|
)
|
||||||
|
).build()
|
||||||
|
|
||||||
|
binding.possibleImage.hierarchy =
|
||||||
|
GenericDraweeHierarchyBuilder.newInstance(resources).setPlaceholderImage(
|
||||||
|
VectorDrawableCompat.create(
|
||||||
|
resources, R.drawable.ic_image_black_24dp, requireContext().theme
|
||||||
|
)
|
||||||
|
).setFailureImage(
|
||||||
|
VectorDrawableCompat.create(
|
||||||
|
resources, R.drawable.ic_error_outline_black_24dp, requireContext().theme
|
||||||
|
)
|
||||||
|
).build()
|
||||||
|
|
||||||
|
arguments?.let {
|
||||||
|
binding.orginalImage.setImageURI(
|
||||||
|
Uri.fromFile(File(it.getString("originalImagePath")!!))
|
||||||
|
)
|
||||||
|
binding.possibleImage.setImageURI(
|
||||||
|
Uri.fromFile(File(it.getString("possibleImagePath")!!))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.postiveButton.setOnClickListener {
|
||||||
|
callback?.onPositiveResponse()
|
||||||
|
gotResponse = true
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.negativeButton.setOnClickListener {
|
||||||
|
callback?.onNegativeResponse()
|
||||||
|
gotResponse = true
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
val dialog = super.onCreateDialog(savedInstanceState)
|
||||||
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
|
return dialog
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDismiss(dialog: DialogInterface) {
|
||||||
|
// I user dismisses dialog by pressing outside the dialog.
|
||||||
|
if (!gotResponse) {
|
||||||
|
callback?.onNegativeResponse()
|
||||||
|
}
|
||||||
|
super.onDismiss(dialog)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
_binding = null
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue