Skip to content
Snippets Groups Projects
Commit 40aade86 authored by Muhammad Ibrahim Rahman's avatar Muhammad Ibrahim Rahman
Browse files

update Recognitions

parent 82364db3
Branches
No related tags found
No related merge requests found
Showing
with 273 additions and 29 deletions
......@@ -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
......
#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
<?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>
<?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>
#Mon Jan 28 18:23:09 CET 2019
connection.project.dir=..
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;
}
}
package org.openhab.habdroid.model;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
......@@ -9,8 +10,9 @@ import com.google.gson.annotations.SerializedName;
* By Muhammad Ibrahim Rahman
*/
public class Recognitions {@SerializedName("identifier")
public class Recognitions {
@SerializedName("identifier")
@Expose
private Integer identifier;
@SerializedName("type")
......@@ -18,24 +20,18 @@ private Integer identifier;
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;
}
}
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;
}
}
......@@ -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);
......
......@@ -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
......
......@@ -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();
}
<?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" />
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment