Skip to content

Commit

Permalink
Merge pull request #77 from galadril/dev-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
galadril committed Dec 8, 2015
2 parents 37142c5 + 913505c commit 405258f
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,10 @@ public int getDrawableIcon(String type, String subtype, boolean state) {
return R.drawable.door;
case "lightbulb":
if (subtype != null && subtype.length() > 0 && subtype.equals(Device.Type.Name.DUSKSENSOR))
return R.drawable.uvdark;
if(state)
return R.drawable.uvdark;
else
return R.drawable.uvsunny;
else
return R.drawable.lights;
case "push":
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,19 @@ private void createListView(ArrayList<DevicesInfo> switches) {
String name = mExtendedStatusInfo.getName();
int switchTypeVal = mExtendedStatusInfo.getSwitchTypeVal();
String switchType = mExtendedStatusInfo.getSwitchType();

if (!name.startsWith(Domoticz.HIDDEN_CHARACTER) &&
(appSupportedSwitchesValues.contains(switchTypeVal) && appSupportedSwitchesNames.contains(switchType)) ||
(switchType == null || switchType.equals(null) || switchType.length() <= 0))//utilities
(switchType == null || switchType.equals(null) || switchType.length() <= 0))
{
supportedSwitches.add(mExtendedStatusInfo);
if(super.getSort().equals(null)||super.getSort().length()<=0||super.getSort().equals(getContext().getString(R.string.sort_all))) {
supportedSwitches.add(mExtendedStatusInfo);
}else{
Snackbar.make(coordinatorLayout, "Sorting on :" + super.getSort(), Snackbar.LENGTH_SHORT).show();
if((super.getSort().equals(getContext().getString(R.string.sort_on)) && mExtendedStatusInfo.getStatusBoolean()))
supportedSwitches.add(mExtendedStatusInfo);
if((super.getSort().equals(getContext().getString(R.string.sort_off)) && !mExtendedStatusInfo.getStatusBoolean()))
supportedSwitches.add(mExtendedStatusInfo);
}
}
}

Expand Down Expand Up @@ -187,7 +194,6 @@ public void onRefresh() {
hideProgressDialog();
}


private void showInfoDialog(final DevicesInfo mSwitch) {
DeviceInfoDialog infoDialog = new DeviceInfoDialog(
getActivity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void handleImportExportButtons() {
public boolean onPreferenceClick(android.preference.Preference preference) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!PermissionsUtil.canAccessStorage(getActivity())) {
requestPermissions(PermissionsUtil.INITIAL_STORAGE_PERMS, PermissionsUtil.INITIAL_IMPORT_SETTINGS_REQUEST);
requestPermissions(PermissionsUtil.INITIAL_STORAGE_PERMS, PermissionsUtil.INITIAL_EXPORT_SETTINGS_REQUEST);
} else
exportSettings();
} else {
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/nl/hnogames/domoticz/Fragments/Scenes.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;

import nl.hnogames.domoticz.Adapters.SceneAdapter;
import nl.hnogames.domoticz.Containers.DevicesInfo;
import nl.hnogames.domoticz.Containers.SceneInfo;
import nl.hnogames.domoticz.Domoticz.Domoticz;
import nl.hnogames.domoticz.Interfaces.DomoticzFragmentListener;
Expand Down Expand Up @@ -103,6 +104,7 @@ public void onError(Exception error) {

public void createListView(final ArrayList<SceneInfo> scenes) {

ArrayList<SceneInfo> supportedScenes = new ArrayList<>();
if (getView() != null) {
mScenes = scenes;
mSwipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipe_refresh_layout);
Expand All @@ -111,7 +113,19 @@ public void createListView(final ArrayList<SceneInfo> scenes) {
.coordinatorLayout);
final ScenesClickListener listener = this;

adapter = new SceneAdapter(mActivity, scenes, listener);
for(SceneInfo s: scenes) {
if (super.getSort().equals(null) || super.getSort().length() <= 0 || super.getSort().equals(getContext().getString(R.string.sort_all))) {
supportedScenes.add(s);
} else {
Snackbar.make(coordinatorLayout, "Sorting on :" + super.getSort(), Snackbar.LENGTH_SHORT).show();
if ((super.getSort().equals(getContext().getString(R.string.sort_on)) && s.getStatusInBoolean()))
supportedScenes.add(s);
if ((super.getSort().equals(getContext().getString(R.string.sort_off)) && !s.getStatusInBoolean()))
supportedScenes.add(s);
}
}

adapter = new SceneAdapter(mActivity, supportedScenes, listener);
ListView listView = (ListView) getView().findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/nl/hnogames/domoticz/Fragments/Switches.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ private void createListView(ArrayList<ExtendedStatusInfo> switches) {
if (!name.startsWith(Domoticz.HIDDEN_CHARACTER) &&
appSupportedSwitchesValues.contains(switchTypeVal) &&
appSupportedSwitchesNames.contains(switchType)) {
supportedSwitches.add(mExtendedStatusInfo);
if(super.getSort().equals(null)||super.getSort().length()<=0||super.getSort().equals(getContext().getString(R.string.sort_all))) {
supportedSwitches.add(mExtendedStatusInfo);
}else{
Snackbar.make(coordinatorLayout, "Sorting on :" + super.getSort(), Snackbar.LENGTH_SHORT).show();
if((super.getSort().equals(getContext().getString(R.string.sort_on)) && mExtendedStatusInfo.getStatusBoolean())) {
supportedSwitches.add(mExtendedStatusInfo);
}if((super.getSort().equals(getContext().getString(R.string.sort_off)) && !mExtendedStatusInfo.getStatusBoolean())) {
supportedSwitches.add(mExtendedStatusInfo);
}
}
}
}

Expand Down
30 changes: 26 additions & 4 deletions app/src/main/java/nl/hnogames/domoticz/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.Menu;
Expand All @@ -50,7 +51,12 @@

import nl.hnogames.domoticz.Adapters.NavigationAdapter;
import nl.hnogames.domoticz.Domoticz.Domoticz;
import nl.hnogames.domoticz.Fragments.Dashboard;
import nl.hnogames.domoticz.Fragments.Scenes;
import nl.hnogames.domoticz.Fragments.Switches;
import nl.hnogames.domoticz.Interfaces.UpdateReceiver;
import nl.hnogames.domoticz.UI.SortDialog;
import nl.hnogames.domoticz.UI.SwitchsDialog;
import nl.hnogames.domoticz.Utils.SharedPrefUtil;
import nl.hnogames.domoticz.Welcome.WelcomeViewActivity;
import nl.hnogames.domoticz.app.DomoticzCardFragment;
Expand Down Expand Up @@ -307,13 +313,14 @@ public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_simple, menu);

} else {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
if((f instanceof Dashboard)||(f instanceof Scenes)||(f instanceof Switches))
getMenuInflater().inflate(R.menu.menu_main_sort, menu);
else
getMenuInflater().inflate(R.menu.menu_main, menu);

MenuItem searchMenuItem = menu.findItem(R.id.search);
searchViewAction = (SearchView) MenuItemCompat
.getActionView(searchMenuItem);

searchViewAction.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Expand All @@ -323,7 +330,6 @@ public boolean onQueryTextSubmit(String query) {
@Override
public boolean onQueryTextChange(String newText) {
Fragment n = getVisibleFragment();

if (n instanceof DomoticzFragment) {
((DomoticzFragment) n).Filter(newText);
}
Expand All @@ -343,6 +349,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_settings:
startActivityForResult(new Intent(this, SettingsActivity.class), this.iSettingsResultCode);
return true;
case R.id.action_sort:
SortDialog infoDialog = new SortDialog(
this,
R.layout.dialog_switch_logs);
infoDialog.onDismissListener(new SortDialog.DismissListener() {
@Override
public void onDismiss(String selectedSort) {
Log.i(TAG, "Sorting: "+selectedSort);
Fragment f = getVisibleFragment();
if (f instanceof DomoticzFragment) {
((DomoticzFragment) f).sortFragment(selectedSort);
}
}
});
infoDialog.show();
return true;
}

// Activate the navigation drawer toggle
Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/nl/hnogames/domoticz/UI/SortDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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.UI;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.afollestad.materialdialogs.MaterialDialog;

import nl.hnogames.domoticz.R;

/**
* Created by m.heinis on 11/12/2015.
*/
public class SortDialog implements DialogInterface.OnDismissListener {

private final MaterialDialog.Builder mdb;
private String idx;
private DismissListener dismissListener;
private Context mContext;
private String[] names;

public SortDialog(Context c,
int layout) {
this.mContext = c;

names = new String[]{mContext.getString(R.string.sort_on), mContext.getString(R.string.sort_off), mContext.getString(R.string.sort_all)};

mdb = new MaterialDialog.Builder(mContext);
mdb.customView(layout, true)
.negativeText(android.R.string.cancel);
mdb.dismissListener(this);
}

@Override
public void onDismiss(DialogInterface dialog) {
}

public void show() {
mdb.title("Sort Devices");
final MaterialDialog md = mdb.build();
View view = md.getCustomView();
ListView listView = (ListView) view.findViewById(R.id.list);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_list_item_1, android.R.id.text1, names);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (dismissListener != null)
dismissListener.onDismiss(names[position]);
md.dismiss();
}
});

listView.setAdapter(adapter);
md.show();
}

public void onDismissListener(DismissListener dismissListener) {
this.dismissListener = dismissListener;
}

public interface DismissListener {
void onDismiss(String selectedSort);
}
}
11 changes: 6 additions & 5 deletions app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public int getStartupScreenIndex() {
}

public void setStartupScreenIndex(int position) {

String[] startupScreenValues =
mContext.getResources().getStringArray(R.array.drawer_actions);
String startupScreenValue;
Expand Down Expand Up @@ -420,11 +419,13 @@ public Set<String> getLocalSsid() {
}

public void setLocalSsid(List<String> ssids) {
Set<String> set = new HashSet<>();
for (String ssid : ssids) {
set.add(ssid);
if(ssids!=null) {
Set<String> set = new HashSet<>();
for (String ssid : ssids) {
set.add(ssid);
}
editor.putStringSet(LOCAL_SERVER_SSID, set).apply();
}
editor.putStringSet(LOCAL_SERVER_SSID, set).apply();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/nl/hnogames/domoticz/app/DomoticzFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,23 @@ public class DomoticzFragment extends Fragment {
private TextView debugText;
private boolean debug;
private ViewGroup root;
private String sort = "";

public DomoticzFragment() {
}

public void refreshFragment() {
}

public String getSort() {
return sort;
}

public void sortFragment(String sort) {
this.sort = sort;
refreshFragment();
}

@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Expand Down
Binary file added app/src/main/res/drawable-xxhdpi/ic_sort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:orderInCategory="200"
android:title="@string/action_settings"
app:showAsAction="never" />

Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/menu/menu_main_sort.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<menu 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"
tools:context=".MainActivity">

<item
android:id="@+id/search"
android:title="Filter"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom" />

<item
android:id="@+id/action_settings"
android:orderInCategory="200"
android:title="@string/action_settings"
app:showAsAction="never" />

<item
android:id="@+id/action_sort"
android:orderInCategory="100"
android:title="@string/action_sort"
android:icon="@drawable/ic_sort"
app:showAsAction="always" />

</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@
<string name="connect_switch">Connect switch</string>


<string name="sort_on">ON</string>
<string name="sort_off">OFF</string>
<string name="sort_all">ALL</string>


</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings_actions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">Settings</string>
<string name="action_sort">Sort</string>
<string name="action_welcome">Welcome</string>

</resources>

0 comments on commit 405258f

Please sign in to comment.