extracted adapter for main view into its own class
This commit is contained in:
parent
362b41fd13
commit
68baa9e06f
@ -50,11 +50,12 @@ public class AllIOsFragment extends Fragment {
|
|||||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||||
false);
|
false);
|
||||||
ListView lv = (ListView) view.findViewById(R.id.idListView);
|
ListView lv = (ListView) view.findViewById(R.id.idListView);
|
||||||
CustomAdapter customAdapter = new CustomAdapter();
|
MainListViewAdapter mainListViewAdapter = new MainListViewAdapter(mainActivity);
|
||||||
lv.setAdapter(customAdapter);
|
lv.setAdapter(mainListViewAdapter);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** REMOVE AT LATER DATE **/
|
||||||
class CustomAdapter extends BaseAdapter {
|
class CustomAdapter extends BaseAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,156 +0,0 @@
|
|||||||
package com.example.aped.ui.all_IOs;
|
|
||||||
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.example.aped.MainActivity;
|
|
||||||
import com.example.aped.R;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class AllIOsFragment2 extends Fragment {
|
|
||||||
/**
|
|
||||||
* Einbinden der MainActivity.
|
|
||||||
*/
|
|
||||||
private MainActivity mainActivity;
|
|
||||||
/**
|
|
||||||
* Genutzt für Signallampe.
|
|
||||||
*/
|
|
||||||
private int image;
|
|
||||||
/**
|
|
||||||
* Genutzt für Favoriten icons.
|
|
||||||
*/
|
|
||||||
private int favoriteImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param inflater
|
|
||||||
* @param container
|
|
||||||
* @param savedInstanceState
|
|
||||||
* @return view
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public View onCreateView(final LayoutInflater inflater,
|
|
||||||
final ViewGroup container,
|
|
||||||
final Bundle savedInstanceState) {
|
|
||||||
this.mainActivity = (MainActivity) getActivity();
|
|
||||||
View view = inflater.inflate(R.layout.listview_layout, container,
|
|
||||||
false);
|
|
||||||
ListView lv = (ListView) view.findViewById(R.id.idListViewPins);
|
|
||||||
CustomAdapter customAdapter = new CustomAdapter();
|
|
||||||
lv.setAdapter(customAdapter);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CustomAdapter extends BaseAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
int count=0;
|
|
||||||
count += ((List<String>)mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(1)).get("pins")).size();
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getItem(final int position) {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getItemId(final int position) {
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getView(final int i, View view,
|
|
||||||
final ViewGroup viewGroup) {
|
|
||||||
view = getLayoutInflater().inflate(R.layout.listview2_layout,
|
|
||||||
null);
|
|
||||||
ImageView imageView = (ImageView) view.findViewById(
|
|
||||||
R.id.images);
|
|
||||||
TextView textViewPin = (TextView) view.findViewById(
|
|
||||||
R.id.textPin);
|
|
||||||
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
|
||||||
get(i), new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(final JSONObject response) {
|
|
||||||
try {
|
|
||||||
String firstpinvalue = response.getJSONObject("state").getString(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
|
||||||
if(firstpinvalue.equals("1")) {
|
|
||||||
image=R.drawable.green_signal;
|
|
||||||
}else if (firstpinvalue.equals("0")) {
|
|
||||||
image = R.drawable.red_signal;
|
|
||||||
} else{ image = R.drawable.off_signal; }
|
|
||||||
imageView.setImageResource(image);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
image = R.drawable.off_signal;
|
|
||||||
imageView.setImageResource(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verarbeitung/ Änderung der Zustände DO
|
|
||||||
*/
|
|
||||||
imageView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(final View view) {
|
|
||||||
Toast.makeText(getContext(), "Click auf: " + i,
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TextView_State.setText(mainActivity.uebergabe.read(
|
|
||||||
// mainActivity.xml.getDeviceNames().get(i)));
|
|
||||||
/** mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
|
||||||
get(i), new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(final JSONObject response) {
|
|
||||||
try {
|
|
||||||
JSONObject pins = response.getJSONObject("state");
|
|
||||||
String devicename = mainActivity.xml.getDeviceNames().get(i);
|
|
||||||
Dictionary<String,Object> portinfo = mainActivity.xml.getPort(devicename);
|
|
||||||
List<String> pinnames = (List<String>) portinfo.get("pins");
|
|
||||||
String firstpinname = pinnames.get(0);
|
|
||||||
int groesse = pinnames.size();
|
|
||||||
for(String pinname : pinnames){
|
|
||||||
|
|
||||||
}//anstatt for mit laufvariable
|
|
||||||
for(int h; h < pinnames.size();h++){
|
|
||||||
String pinname = pinnames.get(h);
|
|
||||||
}
|
|
||||||
String firstpinvalue = pins.getString(firstpinname);
|
|
||||||
textViewState.setText(firstpinvalue);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,114 @@
|
|||||||
|
package com.example.aped.ui.all_IOs;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.example.aped.MainActivity;
|
||||||
|
import com.example.aped.R;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainListViewAdapter extends BaseAdapter {
|
||||||
|
|
||||||
|
private MainActivity mainActivity;
|
||||||
|
|
||||||
|
private int image;
|
||||||
|
|
||||||
|
private int favoriteImage;
|
||||||
|
|
||||||
|
public MainListViewAdapter(MainActivity pMainActivity){
|
||||||
|
this.mainActivity = pMainActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mainActivity.xml.getDeviceNames().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(final int position) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(final int position) {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(final int i, View view,
|
||||||
|
final ViewGroup viewGroup) {
|
||||||
|
view = mainActivity.getLayoutInflater().inflate(R.layout.listview_layout,
|
||||||
|
null);
|
||||||
|
ImageView imageView = (ImageView) view.findViewById(
|
||||||
|
R.id.images);
|
||||||
|
TextView textViewName = (TextView) view.findViewById(
|
||||||
|
R.id.textName);
|
||||||
|
TextView textViewPin = (TextView) view.findViewById(
|
||||||
|
R.id.textPin);
|
||||||
|
ImageView buttonViewFavoriten = (ImageView) view.findViewById(
|
||||||
|
R.id.imageButtonFavoriten);
|
||||||
|
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
||||||
|
get(i), new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(final JSONObject response) {
|
||||||
|
try {
|
||||||
|
String firstpinvalue = response.getJSONObject("state").getString(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
if(firstpinvalue.equals("1")) {
|
||||||
|
image=R.drawable.green_signal;
|
||||||
|
}else if (firstpinvalue.equals("0")) {
|
||||||
|
image = R.drawable.red_signal;
|
||||||
|
} else{ image = R.drawable.off_signal; }
|
||||||
|
imageView.setImageResource(image);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
image = R.drawable.off_signal;
|
||||||
|
imageView.setImageResource(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mainActivity.favorite.getFavorites().contains(
|
||||||
|
mainActivity.xml.getDeviceNames().get(i))) {
|
||||||
|
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||||
|
} else {
|
||||||
|
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonViewFavoriten.setOnClickListener(
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final View view) {
|
||||||
|
if (mainActivity.favorite.getFavorites().contains(
|
||||||
|
mainActivity.xml.getDeviceNames().get(i))) {
|
||||||
|
mainActivity.favorite.removeFavorite(
|
||||||
|
mainActivity.xml.getDeviceNames().get(i));
|
||||||
|
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||||
|
buttonViewFavoriten.setImageResource(
|
||||||
|
favoriteImage);
|
||||||
|
} else {
|
||||||
|
mainActivity.favorite.addFavorite(
|
||||||
|
mainActivity.xml.getDeviceNames().get(i));
|
||||||
|
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||||
|
buttonViewFavoriten.setImageResource(
|
||||||
|
favoriteImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
textViewName.setText(mainActivity.xml.getDeviceNames().get(i));
|
||||||
|
buttonViewFavoriten.setImageResource(favoriteImage);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.example.aped.ui.all_IOs;
|
||||||
|
|
||||||
|
public class PinListViewAdapter {
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user