diff --git a/build.gradle b/build.gradle index 48eb5adde33edfca6c929c3b6495ae911f8d1391..ee423bea63c2e046c55b510109c4e878c49be36d 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.dicedmelon.gradle:jacoco-android:0.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5fabf38db9e965a4b0c17e3fd27c3fc4eb099acd..425aeae6a77817d01c336d1dfe88b9ec88ca773f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ -#Thu Mar 29 16:35:24 CEST 2018 +#Mon Jan 14 23:58:27 CET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip distributionSha256Sum=9af7345c199f1731c187c96d3fe3d31f5405192a42046bafa71d846c3d9adacb diff --git a/mobile/.classpath b/mobile/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..eb19361b5711e614b090eac2f1b51309da2ec1e4 --- /dev/null +++ b/mobile/.classpath @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/> + <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> + <classpathentry kind="output" path="bin/default"/> +</classpath> diff --git a/mobile/.project b/mobile/.project new file mode 100644 index 0000000000000000000000000000000000000000..b1a14e0645d7bc9321b559e9884b19b61f4dbd87 --- /dev/null +++ b/mobile/.project @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>mobile</name> + <comment>Project mobile created by Buildship.</comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.buildship.core.gradleprojectbuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.buildship.core.gradleprojectnature</nature> + </natures> +</projectDescription> diff --git a/mobile/.settings/org.eclipse.buildship.core.prefs b/mobile/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..7f0034958b2aaacb13d73192cf9e815734d3303c --- /dev/null +++ b/mobile/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +#Mon Jan 28 18:23:09 CET 2019 +connection.project.dir=.. diff --git a/mobile/src/main/java/org/openhab/habdroid/model/ChangedItem.java b/mobile/src/main/java/org/openhab/habdroid/model/ChangedItem.java new file mode 100644 index 0000000000000000000000000000000000000000..61935d965491ec3357ef01c93fbd9c91137a714b --- /dev/null +++ b/mobile/src/main/java/org/openhab/habdroid/model/ChangedItem.java @@ -0,0 +1,41 @@ +package org.openhab.habdroid.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class ChangedItem { + + @SerializedName("name") + @Expose + private String name; + @SerializedName("label") + @Expose + private String label; + @SerializedName("state") + @Expose + private String state; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } +} diff --git a/mobile/src/main/java/org/openhab/habdroid/model/Recognitions.java b/mobile/src/main/java/org/openhab/habdroid/model/Recognitions.java index b91d00ff58d80006b3e693d0d032247972980484..f2c0c7d5852f3f3b2b1af14f70eacea9407ed09e 100644 --- a/mobile/src/main/java/org/openhab/habdroid/model/Recognitions.java +++ b/mobile/src/main/java/org/openhab/habdroid/model/Recognitions.java @@ -1,5 +1,6 @@ package org.openhab.habdroid.model; +import java.util.List; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; @@ -9,33 +10,28 @@ import com.google.gson.annotations.SerializedName; * By Muhammad Ibrahim Rahman */ -public class Recognitions {@SerializedName("identifier") +public class Recognitions { -@Expose -private Integer identifier; + @SerializedName("identifier") + @Expose + private Integer identifier; @SerializedName("type") @Expose private String type; @SerializedName("activity") @Expose - private String activity; + private Object activity; @SerializedName("description") @Expose - private String description; + private Object description; @SerializedName("timestamp") @Expose private Integer timestamp; - - public Recognitions(Integer identifier, String type, String activity, String description, Integer timestamp) { - this.identifier = identifier; - this.type = type; - this.activity = activity; - this.description = description; - this.timestamp = timestamp; - } + @SerializedName("changed_items") + @Expose + private List<ChangedItem> changedItems = null; public Integer getIdentifier() { - return identifier; } @@ -51,19 +47,19 @@ private Integer identifier; this.type = type; } - public String getActivity() { + public Object getActivity() { return activity; } - public void setActivity(String activity) { + public void setActivity(Object activity) { this.activity = activity; } - public String getDescription() { + public Object getDescription() { return description; } - public void setDescription(String description) { + public void setDescription(Object description) { this.description = description; } @@ -74,4 +70,12 @@ private Integer identifier; public void setTimestamp(Integer timestamp) { this.timestamp = timestamp; } + + public List<ChangedItem> getChangedItems() { + return changedItems; + } + + public void setChangedItems(List<ChangedItem> changedItems) { + this.changedItems = changedItems; + } } diff --git a/mobile/src/main/java/org/openhab/habdroid/model/RecognitionsOld.java b/mobile/src/main/java/org/openhab/habdroid/model/RecognitionsOld.java new file mode 100644 index 0000000000000000000000000000000000000000..288a938422df35b9f5df75a4c1cd8f4f17356644 --- /dev/null +++ b/mobile/src/main/java/org/openhab/habdroid/model/RecognitionsOld.java @@ -0,0 +1,78 @@ +package org.openhab.habdroid.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/* + * OpenLicht + * Recognition data as POJO + * By Muhammad Ibrahim Rahman + */ + +public class RecognitionsOld { + + @SerializedName("identifier") + @Expose + private Integer identifier; + @SerializedName("type") + @Expose + private String type; + @SerializedName("activity") + @Expose + private String activity; + @SerializedName("description") + @Expose + private String description; + @SerializedName("timestamp") + @Expose + private Integer timestamp; + + public RecognitionsOld(Integer identifier, String type, String activity, String description, Integer timestamp) { + this.identifier = identifier; + this.type = type; + this.activity = activity; + this.description = description; + this.timestamp = timestamp; + } + + public Integer getIdentifier() { + + return identifier; + } + + public void setIdentifier(Integer identifier) { + this.identifier = identifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getActivity() { + return activity; + } + + public void setActivity(String activity) { + this.activity = activity; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getTimestamp() { + return timestamp; + } + + public void setTimestamp(Integer timestamp) { + this.timestamp = timestamp; + } +} diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsActivity.java b/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsActivity.java index 730829bbadd7121ac66b496be7b0886a3634a9c0..e885776c5663cffcdd700443b03243ab10acd07a 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsActivity.java +++ b/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.view.MenuItem; import org.openhab.habdroid.R; +import org.openhab.habdroid.model.ChangedItem; import org.openhab.habdroid.util.Util; import org.openhab.habdroid.model.Recognitions; import org.openhab.habdroid.util.GetDataService; @@ -12,6 +13,7 @@ import org.openhab.habdroid.util.RetrofitClientInstance; import java.util.List; +import androidx.cardview.widget.CardView; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -54,9 +56,11 @@ public class RecognitionsActivity extends AppCompatActivity{ setResult(RESULT_OK); } + + private void getRESTData() { progressDialog = new ProgressDialog(RecognitionsActivity.this); - progressDialog.setMessage("Loading...."); + progressDialog.setMessage("Loading"); progressDialog.show(); // Interface for the RetrofitInstance @@ -67,8 +71,10 @@ public class RecognitionsActivity extends AppCompatActivity{ @Override public void onResponse(Call<List<Recognitions>> call, Response<List<Recognitions>> response) { + progressDialog.dismiss(); generateDataList(response.body()); + } @Override @@ -80,7 +86,7 @@ public class RecognitionsActivity extends AppCompatActivity{ } - // generates a List using RecyclerView with the RecognitionsAdapter + // Generates a List using RecyclerView with the RecognitionsAdapter private void generateDataList(List<Recognitions> recognitionsList) { recyclerView = findViewById(R.id.customRecyclerView); adapter = new RecognitionsAdapter(this,recognitionsList); diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsAdapter.java b/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsAdapter.java index 4b5ac2358f59637463dc03a92b20842deab5697c..752f0798540ec9fd11b33de37ca71fab2418c87d 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsAdapter.java +++ b/mobile/src/main/java/org/openhab/habdroid/ui/RecognitionsAdapter.java @@ -4,11 +4,19 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; +import org.json.JSONArray; import org.openhab.habdroid.R; +import org.openhab.habdroid.model.ChangedItem; import org.openhab.habdroid.model.Recognitions; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import androidx.recyclerview.widget.RecyclerView; @@ -23,10 +31,12 @@ public class RecognitionsAdapter extends RecyclerView.Adapter<RecognitionsAdapte private List<Recognitions> dataList; private Context context; + private ArrayList<String> changedStates = new ArrayList<>(); - public RecognitionsAdapter(Context context, List<Recognitions> dataList){ + public RecognitionsAdapter(Context context, List<Recognitions> dataList/*, List<ChangedItem> changedItemList*/){ this.context = context; this.dataList = dataList; + } class CustomViewHolder extends RecyclerView.ViewHolder { @@ -37,6 +47,13 @@ public class RecognitionsAdapter extends RecyclerView.Adapter<RecognitionsAdapte TextView recType; TextView recActivity; TextView recTimestamp; + TextView recChangedState1; + TextView recChangedState2; + TextView recChangedState3; + +// ArrayList<String> cS = new ArrayList<>(); + + CustomViewHolder(View itemView) { super(itemView); @@ -46,6 +63,10 @@ public class RecognitionsAdapter extends RecyclerView.Adapter<RecognitionsAdapte recType = mView.findViewById(R.id.recognitionType); recActivity = mView.findViewById(R.id.recognitionActivity); recTimestamp = mView.findViewById(R.id.recognitionTimestamp); + recChangedState1 = mView.findViewById(R.id.recognitionChangedState1); + recChangedState2 = mView.findViewById(R.id.recognitionChangedState2); + recChangedState3 = mView.findViewById(R.id.recognitionChangedState3); + } } @@ -58,10 +79,41 @@ public class RecognitionsAdapter extends RecyclerView.Adapter<RecognitionsAdapte @Override public void onBindViewHolder(CustomViewHolder holder, int position) { - holder.recDescription.setText(dataList.get(position).getDescription()); - holder.recType.setText(dataList.get(position).getType()); - holder.recActivity.setText(dataList.get(position).getActivity()); - holder.recTimestamp.setText(String.valueOf(dataList.get(position).getTimestamp())); + int identifier = dataList.get(position).getIdentifier(); + String type = dataList.get(position).getType(); + Object activity = dataList.get(position).getActivity(); + Object description = dataList.get(position).getDescription(); + int timestamp = dataList.get(position).getTimestamp(); + + // ChangedItem + String name; + String state; + String label; + + +// String changedItem = String.join(",", name, state, label); +// if (dataList.get(position).getChangedItems().size() == 3) { + for (int i = 0; i < dataList.get(position).getChangedItems().size(); i++) { + name = dataList.get(position).getChangedItems().get(i).getName(); + state = dataList.get(position).getChangedItems().get(i).getState(); + label = dataList.get(position).getChangedItems().get(i).getLabel(); + String changedItem = String.join(",", name, state, label); + + changedStates.add(changedItem); + +// Uncomment line 104 and comment out line 114 and 115 to see the alternate behavior +// holder.recChangedState1.setText(changedItem); + + } + + + holder.recDescription.setText((CharSequence) description); + holder.recType.setText(type); + holder.recActivity.setText((CharSequence) activity); + holder.recTimestamp.setText(DateFormat.getDateTimeInstance().format(timestamp)); + holder.recChangedState1.setText(changedStates.get(0)); + holder.recChangedState2.setText(changedStates.get(1)); + } @Override diff --git a/mobile/src/main/java/org/openhab/habdroid/util/GetDataService.java b/mobile/src/main/java/org/openhab/habdroid/util/GetDataService.java index 4669e06575fd2d29015450fc382a500369ebfd1b..9f8ae061c8a4769e44fa3da6b34308d1f1a400e8 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/GetDataService.java +++ b/mobile/src/main/java/org/openhab/habdroid/util/GetDataService.java @@ -15,6 +15,9 @@ import retrofit2.http.GET; public interface GetDataService { - @GET("/recognitions") + @GET("/events/long") Call<List<Recognitions>> getAllRecognitions(); + +// @GET("/recognitions") +// Call<List<Recognitions>> getAllRecognitions(); } diff --git a/mobile/src/main/res/layout/changed_item.xml b/mobile/src/main/res/layout/changed_item.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c0ca0f6efd65152677429d980f8041f559fefec --- /dev/null +++ b/mobile/src/main/res/layout/changed_item.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> + +<TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/changedItem" + tools:text="Sample Text" + xmlns:android="http://schemas.android.com/apk/res/android" /> + diff --git a/mobile/src/main/res/layout/custom_row.xml b/mobile/src/main/res/layout/custom_row.xml index 3151bbf94c37b074369ddee9cbc8a93c6825e356..d2187691531784e9a940817f0b252961f9d6c7c8 100644 --- a/mobile/src/main/res/layout/custom_row.xml +++ b/mobile/src/main/res/layout/custom_row.xml @@ -53,6 +53,26 @@ android:layout_below="@+id/recognitionActivity" tools:text="Sample Text"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/recognitionChangedState1" + android:layout_below="@+id/recognitionTimestamp" + tools:text="Sample Text"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/recognitionChangedState2" + android:layout_below="@+id/recognitionChangedState1" + tools:text="Sample Text"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/recognitionChangedState3" + android:layout_below="@+id/recognitionChangedState2" + tools:text="Sample Text"/> + </RelativeLayout> </androidx.cardview.widget.CardView> </LinearLayout>