Skip to content
Snippets Groups Projects
Commit b868fe20 authored by Julian Catoni's avatar Julian Catoni
Browse files

Updated ip, added snackbar after changing light color

parent 1f6fd3ab
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package org.openhab.habdroid.ui; package org.openhab.habdroid.ui;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
...@@ -40,6 +41,7 @@ import android.widget.NumberPicker; ...@@ -40,6 +41,7 @@ import android.widget.NumberPicker;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView; import android.widget.VideoView;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes; import androidx.annotation.LayoutRes;
...@@ -49,6 +51,7 @@ import androidx.appcompat.app.AlertDialog; ...@@ -49,6 +51,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SwitchCompat; import androidx.appcompat.widget.SwitchCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import com.larswerkman.holocolorpicker.ColorPicker; import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.SaturationBar; import com.larswerkman.holocolorpicker.SaturationBar;
import com.larswerkman.holocolorpicker.ValueBar; import com.larswerkman.holocolorpicker.ValueBar;
...@@ -68,11 +71,15 @@ import org.openhab.habdroid.util.Util; ...@@ -68,11 +71,15 @@ import org.openhab.habdroid.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/** /**
* This class provides openHAB widgets adapter for list view. * This class provides openHAB widgets adapter for list view.
...@@ -116,12 +123,10 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder ...@@ -116,12 +123,10 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
public WidgetAdapter(Context context, Connection connection, public WidgetAdapter(Context context, Connection connection,
ItemClickListener itemClickListener) { ItemClickListener itemClickListener) {
super(); super();
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
mItemClickListener = itemClickListener; mItemClickListener = itemClickListener;
mConnection = connection; mConnection = connection;
mColorMapper = new ColorMapper(context); mColorMapper = new ColorMapper(context);
TypedValue tv = new TypedValue(); TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(R.attr.chartTheme, tv, true); context.getTheme().resolveAttribute(R.attr.chartTheme, tv, true);
mChartTheme = tv.string; mChartTheme = tv.string;
...@@ -995,11 +1000,31 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder ...@@ -995,11 +1000,31 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
} }
} }
private final static Handler handler = new Handler();
private final static int DELAY_SNACKBAR = 3000;
private static void showSnackbar(View v, int delay, AlertDialog dialog) {
handler.removeCallbacksAndMessages(null);
final View currentView = v.getRootView().findFocus();
handler.postDelayed(() -> {
Snackbar snackbar = Snackbar.make(currentView, "Soll die manuelle Änderung als neuer Standardwert genutzt werden?", Snackbar.LENGTH_LONG);
snackbar.setAction("Setze als Standard", v1 -> {
Toast.makeText(currentView.getContext(), "Änderung wurde als neuer Standardwert gesetzt!", Toast.LENGTH_SHORT).show();
});
snackbar.show();
if (dialog != null) dialog.dismiss();
}, delay);
}
public static class ColorViewHolder extends LabeledItemBaseViewHolder implements public static class ColorViewHolder extends LabeledItemBaseViewHolder implements
View.OnTouchListener, Handler.Callback, ColorPicker.OnColorChangedListener { View.OnTouchListener, Handler.Callback, ColorPicker.OnColorChangedListener {
private Item mBoundItem; private Item mBoundItem;
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
private final Handler mHandler = new Handler(this); private final Handler mHandler = new Handler(this);
private AlertDialog mAlertDialog;
ColorViewHolder(LayoutInflater inflater, ViewGroup parent, ColorViewHolder(LayoutInflater inflater, ViewGroup parent,
Connection conn, ColorMapper colorMapper) { Connection conn, ColorMapper colorMapper) {
...@@ -1028,6 +1053,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder ...@@ -1028,6 +1053,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
if (v.getTag() instanceof String) { if (v.getTag() instanceof String) {
final String cmd = (String) v.getTag(); final String cmd = (String) v.getTag();
Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, cmd); Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, cmd);
WidgetAdapter.showSnackbar(v, DELAY_SNACKBAR, mAlertDialog);
} else { } else {
showColorPickerDialog(); showColorPickerDialog();
} }
...@@ -1043,6 +1069,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder ...@@ -1043,6 +1069,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
final String newColorValue = String.format(Locale.US, "%f,%f,%f", final String newColorValue = String.format(Locale.US, "%f,%f,%f",
hsv[0], hsv[1] * 100, hsv[2] * 100); hsv[0], hsv[1] * 100, hsv[2] * 100);
Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, newColorValue); Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, newColorValue);
WidgetAdapter.showSnackbar(itemView, DELAY_SNACKBAR, mAlertDialog);
return true; return true;
} }
...@@ -1068,10 +1095,9 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder ...@@ -1068,10 +1095,9 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder
colorPicker.setColor(Color.HSVToColor(initialColor)); colorPicker.setColor(Color.HSVToColor(initialColor));
} }
new AlertDialog.Builder(contentView.getContext()) mAlertDialog = new AlertDialog.Builder(contentView.getContext())
.setView(contentView) .setView(contentView)
.setNegativeButton(R.string.close, null) .setNegativeButton(R.string.close, null).show();
.show();
} }
} }
......
...@@ -12,7 +12,7 @@ import retrofit2.converter.gson.GsonConverterFactory; ...@@ -12,7 +12,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClientInstance { public class RetrofitClientInstance {
private static Retrofit retrofit; private static Retrofit retrofit;
private static final String BASE_URL = "http://141.76.65.46:5000"; //"http://10.0.2.2:5000"; private static final String BASE_URL = "http://192.168.1.250:5000"; //"http://10.0.2.2:5000";
public static Retrofit getRetrofitInstance() { public static Retrofit getRetrofitInstance() {
if (retrofit == null) { if (retrofit == null) {
......
...@@ -197,6 +197,8 @@ public class Util { ...@@ -197,6 +197,8 @@ public class Util {
sendItemCommand(client, item.link(), command); sendItemCommand(client, item.link(), command);
} }
public static void sendItemCommand(AsyncHttpClient client, String itemUrl, String command) { public static void sendItemCommand(AsyncHttpClient client, String itemUrl, String command) {
if (itemUrl == null || command == null) { if (itemUrl == null || command == null) {
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment