Add some content to automation plugin fragment

This commit is contained in:
Nico Schmitz 2018-09-19 22:29:35 +02:00
parent 4985864343
commit b5f30a0f46
6 changed files with 166 additions and 6 deletions

View file

@ -1,24 +1,100 @@
package info.nightscout.androidaps.plugins.general.automation;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog;
public class AutomationFragment extends SubscriberFragment {
private RecyclerView mEventListView;
private FloatingActionButton mFabAddEvent;
private EventListAdapter mEventListAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.automation_fragment, container, false);
mEventListView = view.findViewById(R.id.eventListView);
mFabAddEvent = view.findViewById(R.id.fabAddEvent);
mFabAddEvent.setOnClickListener(this::onClickAddEvent);
final AutomationPlugin plugin = AutomationPlugin.getPlugin();
mEventListAdapter = new EventListAdapter(plugin.getAutomationEvents());
mEventListView.setLayoutManager(new LinearLayoutManager(getContext()));
mEventListView.setAdapter(mEventListAdapter);
updateGUI();
return view;
}
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
mEventListAdapter.notifyDataSetChanged();
});
}
private void onClickAddEvent(View v) {
/*EditEventDialog dialog = EditEventDialog.newInstance();
FragmentManager manager = getFragmentManager();
dialog.show(manager, "EditEventDialog");*/
final AutomationPlugin plugin = AutomationPlugin.getPlugin();
plugin.getAutomationEvents().add(new AutomationEvent("Test"));
updateGUI();
}
public static class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder> {
private final List<AutomationEvent> mEvents;
EventListAdapter(List<AutomationEvent> events) {
this.mEvents = events;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.automation_event_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
final AutomationEvent event = mEvents.get(position);
holder.eventTitle.setText(event.getTitle());
}
@Override
public int getItemCount() {
return mEvents.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
TextView eventTitle;
public ViewHolder(View itemView) {
super(itemView);
eventTitle = itemView.findViewById(R.id.viewEventTitle);
}
}
}
}

View file

@ -31,10 +31,10 @@ public class AutomationPlugin extends PluginBase {
return plugin;
}
List<AutomationEvent> automationEvents = new ArrayList<>();
EventLocationChange eventLocationChange;
EventChargingState eventChargingState;
EventNetworkChange eventNetworkChange;
private final List<AutomationEvent> automationEvents = new ArrayList<>();
private EventLocationChange eventLocationChange;
private EventChargingState eventChargingState;
private EventNetworkChange eventNetworkChange;
private AutomationPlugin() {
super(new PluginDescription()
@ -64,6 +64,22 @@ public class AutomationPlugin extends PluginBase {
MainApp.bus().unregister(this);
}
public List<AutomationEvent> getAutomationEvents() {
return automationEvents;
}
public EventLocationChange getEventLocationChange() {
return eventLocationChange;
}
public EventChargingState getEventChargingState() {
return eventChargingState;
}
public EventNetworkChange getEventNetworkChange() {
return eventNetworkChange;
}
@Subscribe
public void onEventPreferenceChange(EventPreferenceChange e) {
if (e.isChanged(R.string.key_location)) {

View file

@ -0,0 +1,16 @@
package info.nightscout.androidaps.plugins.general.automation.dialogs;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
public class EditEventDialog extends DialogFragment {
public static EditEventDialog newInstance() {
Bundle args = new Bundle();
EditEventDialog fragment = new EditEventDialog();
fragment.setArguments(args);
return fragment;
}
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/viewEventTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

View file

@ -1,9 +1,32 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="info.nightscout.androidaps.plugins.general.automation.AutomationFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/eventListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_add_black_24dp"
android:backgroundTint="@color/defaulttext"/>
</RelativeLayout>
</FrameLayout>