package com.example.meinwald.ui.task; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Rect; import android.os.Build; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import com.example.meinwald.BuildConfig; import com.example.meinwald.R; import com.example.meinwald.ui.area.AreaAdapter; import com.example.meinwald.ui.area.OwnArea; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; import java.util.List; import androidx.annotation.RequiresApi; import androidx.appcompat.widget.AlertDialogLayout; import androidx.appcompat.widget.LinearLayoutCompat; import androidx.constraintlayout.widget.ConstraintLayout; import static java.security.AccessController.getContext; public class TaskAdapter extends BaseAdapter { private final static String TAG = TaskAdapter.class.getSimpleName(); List taskList; LayoutInflater inflater; Context context; public TaskAdapter(Context applicationContext, List taskList) { this.taskList = new ArrayList<>(); this.taskList = taskList; this.context = applicationContext; inflater = LayoutInflater.from(applicationContext); if (BuildConfig.DEBUG) { //Log.d("TaskAdapter",taskList.get(0).toString()); Log.d("TaskAdapter","size: " + taskList.size()); } } @Override public View getView(final int i, View view, final ViewGroup viewGroup) { view = inflater.inflate(R.layout.task_element, null); final ConstraintLayout elementView = view.findViewById(R.id.taskInfoView); final ConstraintLayout infovView = view.findViewById(R.id.taskInfoView); final TextView title = (TextView) view.findViewById(R.id.taskInfoTitle); final TextView notice = (TextView) view.findViewById(R.id.taskInfoNotice); final ImageView icon = (ImageView) view.findViewById(R.id.taskIcon); final ImageView manageTask = (ImageView) view.findViewById(R.id.taskManageTask); context = view.getContext(); if (BuildConfig.DEBUG) { Log.d("TaskAdapter",taskList.get(i).toString()); Log.d("TaskAdapter",taskList.get(i).getTitle()); Log.d("TaskAdapter",taskList.get(i).getNotice()); } title.setText(taskList.get(i).getTitle()); notice.setText(taskList.get(i).getNotice()); icon.setImageBitmap(taskList.get(i).getImage()); title.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); notice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); manageTask.setOnClickListener(new View.OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) @Override public void onClick(View v) { final AlertDialog.Builder builder = new AlertDialog.Builder(v.getRootView().getContext()); final View viewInflated = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.area_management, viewGroup, false); builder.setView(viewInflated); //get elements TextView title = viewInflated.findViewById(R.id.areaManageTitle); final TextView notice = viewInflated.findViewById(R.id.areaManageNotice); TextView gps = viewInflated.findViewById(R.id.areaManageGPSPoints); ImageView image = (ImageView) viewInflated.findViewById(R.id.areaManageImage); ImageView newNotice = (ImageView) viewInflated.findViewById(R.id.areaManageNewDescription); ImageView newGPS = (ImageView) viewInflated.findViewById(R.id.areaManageNewGPS); ImageView newImage = (ImageView) viewInflated.findViewById(R.id.areaManageNewImage); ImageView deleteArea = (ImageView) viewInflated.findViewById(R.id.areaManageDeleteArea); //set current vlues title.setText(taskList.get(i).getTitle()); notice.setText(taskList.get(i).getNotice()); if (taskList.get(i).getLocation() != null) { gps.setText(String.valueOf(taskList.get(i).getLocation())); } else { gps.setText("Kein Standort gespeichert!"); } if (taskList.get(i).getImage() != null) { image.setImageBitmap(taskList.get(i).getImage()); } newNotice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final AlertDialog.Builder newbuilder = new AlertDialog.Builder(v.getRootView().getContext()); final View viewInflated = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.area_management_notice, viewGroup, false); newbuilder.setView(viewInflated); final TextView noticeView = viewInflated.findViewById(R.id.areaManagementNoticeUserInput); newbuilder.setPositiveButton("Bestätigen", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { taskList.get(i).setNotice(noticeView.getText().toString()); notice.setText(taskList.get(i).getNotice()); dialog.dismiss(); } }); newbuilder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); newbuilder.show(); }}); deleteArea.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final AlertDialog.Builder newbuilder = new AlertDialog.Builder(v.getRootView().getContext()); newbuilder.setTitle("Das Grundstück wirklich löschen?"); newbuilder.setPositiveButton("Bestätigen", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { taskList.get(i).deleteFromExternalStorage(context); taskList.remove(i); notifyDataSetChanged(); if (BuildConfig.DEBUG) { for (OwnTask task: taskList) { Log.d(TAG, "areaList item: " + task.toString()); } } dialog.dismiss(); } }); newbuilder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); newbuilder.show(); }}); builder.setPositiveButton("Bestätigen", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (taskList.size()-1 > i && taskList.get(i) != null) { taskList.get(i).deleteFromExternalStorage(context); taskList.get(i).saveImageToExternalStorage(context); } if (BuildConfig.DEBUG) { for (OwnTask task: taskList) { Log.d(TAG, "areaList item: " + task.toString()); } } dialog.dismiss(); } }); builder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); } }); icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final AlertDialog.Builder builder = new AlertDialog.Builder(v.getRootView().getContext()); final View viewInflated = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.image_large, viewGroup, false); //viewInflated.setLayoutParams(new AlertDialogLayout.LayoutParams(taskList.get(i).getImage().getWidth(),5 * taskList.get(i).getImage().getHeight())); builder.setView(viewInflated); final ConstraintLayout imageViewLayout = viewInflated.findViewById(R.id.taskLargeImageLayout); final ImageView imageView = viewInflated.findViewById(R.id.taskLargeImage); Log.d("TaskAdapter", String.valueOf(taskList.get(i).getImage().getHeight())); //ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(taskList.get(i).getImage().getWidth(), taskList.get(i).getImage().getHeight()); //layoutParams.width = taskList.get(i).getImage().getWidth(); //layoutParams.height = taskList.get(i).getImage().getHeight(); //imageView.setLayoutParams(layoutParams); imageView.setImageBitmap(taskList.get(i).getImage()); builder.setNegativeButton("Zurück", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub return true; } }); return view; } @Override public int getCount() { return taskList.size(); } @Override public Object getItem(int i) { return taskList.get(i); } @Override public long getItemId(int i) { return i; } }