Skip to content

Commit

Permalink
Merge pull request #168 from galadril/development-branch
Browse files Browse the repository at this point in the history
Development branch
  • Loading branch information
galadril committed Dec 31, 2015
2 parents 9343c9c + b43418e commit 2cb0ef8
Show file tree
Hide file tree
Showing 43 changed files with 333 additions and 415 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 49
versionName '0.1.204'
versionCode 50
versionName '0.1.205'
multiDexEnabled true
}

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
Expand Down Expand Up @@ -73,7 +75,12 @@ public void onBindViewHolder(DataObjectHolder holder, int position) {
String text = mContext.getResources().getQuantityString(R.plurals.devices, numberOfDevices, numberOfDevices);

holder.name.setText(name);
Picasso.with(mContext).load(cameraInfo.getFullURL()).into(holder.camera);

Picasso.with(mContext)
.load(cameraInfo.getFullURL())
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(holder.camera);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private void setDefaultRowData(DevicesInfo mDeviceInfo,
if (holder.signal_level != null)
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDeviceInfo.getData());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);
Expand Down Expand Up @@ -488,7 +488,7 @@ private void setOnOffSwitchRowData(final DevicesInfo mDeviceInfo,
if (holder.signal_level != null)
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDeviceInfo.getData());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);
Expand Down Expand Up @@ -600,7 +600,7 @@ private void setPushOnOffSwitchRowData(DevicesInfo mDeviceInfo, ViewHolder holde
if (holder.signal_level != null)
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDeviceInfo.getData());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);
Expand Down Expand Up @@ -673,7 +673,7 @@ private void setBlindsRowData(DevicesInfo mDeviceInfo,
if (holder.switch_status != null)
holder.switch_status.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDeviceInfo.getData());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);
Expand Down Expand Up @@ -754,8 +754,8 @@ private void setDimmerRowData(final DevicesInfo mDeviceInfo,
if (holder.signal_level != null)
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
String.valueOf(mDeviceInfo.getData());
text = context.getString(R.string.status) + ": " +
String.valueOf(mDeviceInfo.getStatus());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private void setOnOffSwitchRowData(final DevicesInfo mDevicesInfo,
String.valueOf(mDevicesInfo.getLastUpdate().substring(mDevicesInfo.getLastUpdate().indexOf(" ") + 1));
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDevicesInfo.getData());
holder.switch_battery_level.setText(text);

Expand Down Expand Up @@ -401,7 +401,7 @@ private void setPushOnOffSwitchRowData(DevicesInfo mDevicesInfo, ViewHolder hold
String.valueOf(mDevicesInfo.getLastUpdate().substring(mDevicesInfo.getLastUpdate().indexOf(" ") + 1));
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDevicesInfo.getData());
holder.switch_battery_level.setText(text);

Expand Down Expand Up @@ -471,7 +471,7 @@ private void setBlindsRowData(DevicesInfo mDevicesInfo,
String.valueOf(mDevicesInfo.getLastUpdate().substring(mDevicesInfo.getLastUpdate().indexOf(" ") + 1));
holder.switch_status.setText(text);

text = context.getString(R.string.data) + ": " +
text = context.getString(R.string.status) + ": " +
String.valueOf(mDevicesInfo.getData());
holder.switch_battery_level.setText(text);

Expand Down Expand Up @@ -549,8 +549,8 @@ private void setDimmerRowData(final DevicesInfo mDevicesInfo,
String.valueOf(mDevicesInfo.getLastUpdate().substring(mDevicesInfo.getLastUpdate().indexOf(" ") + 1));
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
String.valueOf(mDevicesInfo.getData());
text = context.getString(R.string.status) + ": " +
String.valueOf(mDevicesInfo.getStatus());
holder.switch_battery_level.setText(text);

holder.switch_dimmer_level.setId(mDevicesInfo.getIdx() + ID_TEXTVIEW);
Expand Down
197 changes: 197 additions & 0 deletions app/src/main/java/nl/hnogames/domoticz/Adapters/WidgetsAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* Copyright (C) 2015 Domoticz
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

package nl.hnogames.domoticz.Adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import nl.hnogames.domoticz.Containers.DevicesInfo;
import nl.hnogames.domoticz.Domoticz.Domoticz;
import nl.hnogames.domoticz.R;
import nl.hnogames.domoticz.Utils.SharedPrefUtil;

public class WidgetsAdapter extends BaseAdapter implements Filterable {
public ArrayList<DevicesInfo> filteredData = null;
private Domoticz domoticz;
private Context context;
private ArrayList<DevicesInfo> data = null;
private int layoutResourceId;
private ItemFilter mFilter = new ItemFilter();
private SharedPrefUtil mSharedPrefs;

public WidgetsAdapter(Context context,
ArrayList<DevicesInfo> data) {
super();
mSharedPrefs = new SharedPrefUtil(context);

this.context = context;
domoticz = new Domoticz(context);

Collections.sort(data, new Comparator<DevicesInfo>() {
@Override
public int compare(DevicesInfo left, DevicesInfo right) {
return left.getName().compareTo(right.getName());
}
});
this.filteredData = data;
this.data = data;
}

@Override
public int getCount() {
return filteredData.size();
}

@Override
public Object getItem(int i) {
return filteredData.get(i);
}

@Override
public long getItemId(int i) {
return 0;
}

public Filter getFilter() {
return mFilter;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
DevicesInfo deviceInfo = filteredData.get(position);

holder = new ViewHolder();
convertView = setDefaultRowId(holder);
convertView.setTag(holder);

setDefaultRowData(deviceInfo, holder);
return convertView;
}

private View setDefaultRowId(ViewHolder holder) {
layoutResourceId = R.layout.widget_configuration_row;

LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View row = inflater.inflate(layoutResourceId, null);

holder.signal_level = (TextView) row.findViewById(R.id.switch_signal_level);
holder.iconRow = (ImageView) row.findViewById(R.id.rowIcon);
holder.switch_name = (TextView) row.findViewById(R.id.switch_name);
holder.switch_battery_level = (TextView) row.findViewById(R.id.switch_battery_level);

return row;
}

private void setDefaultRowData(DevicesInfo mDeviceInfo,
ViewHolder holder) {
holder.isProtected = mDeviceInfo.isProtected();
if (holder.switch_name != null)
holder.switch_name.setText(mDeviceInfo.getName());

String text = context.getString(R.string.last_update) + ": " +
String.valueOf(mDeviceInfo.getLastUpdate().substring(mDeviceInfo.getLastUpdate().indexOf(" ") + 1));
if (holder.signal_level != null)
holder.signal_level.setText(text);

text = context.getString(R.string.data) + ": " +
String.valueOf(mDeviceInfo.getData());
if (holder.switch_battery_level != null)
holder.switch_battery_level.setText(text);

if (mDeviceInfo.getUsage() != null && mDeviceInfo.getUsage().length() > 0)
holder.switch_battery_level.setText(context.getString(R.string.usage) + ": " + mDeviceInfo.getUsage());
if (mDeviceInfo.getCounterToday() != null && mDeviceInfo.getCounterToday().length() > 0)
holder.switch_battery_level.append(" " + context.getString(R.string.today) + ": " + mDeviceInfo.getCounterToday());
if (mDeviceInfo.getCounter() != null && mDeviceInfo.getCounter().length() > 0 &&
!mDeviceInfo.getCounter().equals(mDeviceInfo.getData()))
holder.switch_battery_level.append(" " + context.getString(R.string.total) + ": " + mDeviceInfo.getCounter());

Picasso.with(context).load(domoticz.getDrawableIcon(mDeviceInfo.getTypeImg(),
mDeviceInfo.getType(),
mDeviceInfo.getSubType(),
mDeviceInfo.getStatusBoolean(),
mDeviceInfo.getUseCustomImage(),
mDeviceInfo.getImage())).into(holder.iconRow);

holder.iconRow.setAlpha(1f);
if (!mDeviceInfo.getStatusBoolean())
holder.iconRow.setAlpha(0.5f);
else
holder.iconRow.setAlpha(1f);
}

static class ViewHolder {
TextView switch_name, signal_level, switch_battery_level;
Boolean isProtected;
ImageView iconRow;
}

private class ItemFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {

String filterString = constraint.toString().toLowerCase();

FilterResults results = new FilterResults();

final ArrayList<DevicesInfo> list = data;

int count = list.size();
final ArrayList<DevicesInfo> nlist = new ArrayList<DevicesInfo>(count);

DevicesInfo filterableObject;
for (int i = 0; i < count; i++) {
filterableObject = list.get(i);
if (filterableObject.getName().toLowerCase().contains(filterString)) {
nlist.add(filterableObject);
}
}
results.values = nlist;
results.count = nlist.size();

return results;
}

@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
filteredData = (ArrayList<DevicesInfo>) results.values;
notifyDataSetChanged();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ public DevicesInfo(JSONObject row) throws JSONException {
signalLevel = 0;
}

if (row.has("SetPoint"))
setPoint = row.getLong("SetPoint");
try {
if (row.has("SetPoint")){
setPoint = Double.parseDouble(row.getString("SetPoint"));
}
} catch (Exception ex) {
}
}

public boolean getFavoriteBoolean() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public UtilitiesInfo(JSONObject row) throws JSONException {
HardwareName = row.getString("HardwareName");
if (row.has("LastUpdate"))
LastUpdate = row.getString("LastUpdate");
if (row.has("SetPoint"))
setPoint = row.getLong("SetPoint");

if (row.has("SetPoint")){
setPoint = Double.parseDouble(row.getString("SetPoint"));
}

if (row.has("Name"))
Name = row.getString("Name");
if (row.has("Data"))
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/nl/hnogames/domoticz/Fragments/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

import java.io.File;
Expand Down Expand Up @@ -114,7 +116,11 @@ private void processImage() {
public void setImage(String url) {
this.url = url;
if (root != null && !root.equals(null))
Picasso.with(getActivity()).load(url).into(root);
Picasso.with(getActivity())
.load(url)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(root);
}

// Returns the URI path to the Bitmap displayed in specified ImageView
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/nl/hnogames/domoticz/PlanActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle bundle = getIntent().getExtras();
if (bundle == null)
this.finish();

//noinspection SpellCheckingInspection
String selectedPlan = bundle.getString("PLANNAME");
//noinspection SpellCheckingInspection
Expand Down
Loading

0 comments on commit 2cb0ef8

Please sign in to comment.