diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.java b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.java index 2618679b068096b5e3bebd06b7d0f36118ea0992..8ca278ea8635543965f3718ef794ec589e9ac012 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.java +++ b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.java @@ -10,6 +10,7 @@ package org.openhab.habdroid.ui; import android.annotation.SuppressLint; +import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.res.ColorStateList; @@ -40,6 +41,7 @@ import android.widget.NumberPicker; import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.TextView; +import android.widget.Toast; import android.widget.VideoView; import androidx.annotation.IdRes; import androidx.annotation.LayoutRes; @@ -49,6 +51,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SwitchCompat; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.snackbar.Snackbar; import com.larswerkman.holocolorpicker.ColorPicker; import com.larswerkman.holocolorpicker.SaturationBar; import com.larswerkman.holocolorpicker.ValueBar; @@ -68,11 +71,15 @@ import org.openhab.habdroid.util.Util; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; 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. @@ -116,12 +123,10 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder public WidgetAdapter(Context context, Connection connection, ItemClickListener itemClickListener) { super(); - mInflater = LayoutInflater.from(context); mItemClickListener = itemClickListener; mConnection = connection; mColorMapper = new ColorMapper(context); - TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.chartTheme, tv, true); mChartTheme = tv.string; @@ -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 View.OnTouchListener, Handler.Callback, ColorPicker.OnColorChangedListener { private Item mBoundItem; private final LayoutInflater mInflater; private final Handler mHandler = new Handler(this); + private AlertDialog mAlertDialog; ColorViewHolder(LayoutInflater inflater, ViewGroup parent, Connection conn, ColorMapper colorMapper) { @@ -1028,6 +1053,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder if (v.getTag() instanceof String) { final String cmd = (String) v.getTag(); Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, cmd); + WidgetAdapter.showSnackbar(v, DELAY_SNACKBAR, mAlertDialog); } else { showColorPickerDialog(); } @@ -1043,6 +1069,7 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder final String newColorValue = String.format(Locale.US, "%f,%f,%f", hsv[0], hsv[1] * 100, hsv[2] * 100); Util.sendItemCommand(mConnection.getAsyncHttpClient(), mBoundItem, newColorValue); + WidgetAdapter.showSnackbar(itemView, DELAY_SNACKBAR, mAlertDialog); return true; } @@ -1068,10 +1095,9 @@ public class WidgetAdapter extends RecyclerView.Adapter<WidgetAdapter.ViewHolder colorPicker.setColor(Color.HSVToColor(initialColor)); } - new AlertDialog.Builder(contentView.getContext()) + mAlertDialog = new AlertDialog.Builder(contentView.getContext()) .setView(contentView) - .setNegativeButton(R.string.close, null) - .show(); + .setNegativeButton(R.string.close, null).show(); } } diff --git a/mobile/src/main/java/org/openhab/habdroid/util/RetrofitClientInstance.java b/mobile/src/main/java/org/openhab/habdroid/util/RetrofitClientInstance.java index 6793289571f447248377b4a6735739ca186d6976..26ee0546bd823add5e64eb6b2ef457c8cff2b776 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/RetrofitClientInstance.java +++ b/mobile/src/main/java/org/openhab/habdroid/util/RetrofitClientInstance.java @@ -12,7 +12,7 @@ import retrofit2.converter.gson.GsonConverterFactory; public class RetrofitClientInstance { 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() { if (retrofit == null) { diff --git a/mobile/src/main/java/org/openhab/habdroid/util/Util.java b/mobile/src/main/java/org/openhab/habdroid/util/Util.java index 7bdd8393b392c5f19418e3d89b09e16c54c1caee..d6bcbfc6afc6537abed8459ab1d21e684e8d18d7 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/Util.java +++ b/mobile/src/main/java/org/openhab/habdroid/util/Util.java @@ -197,6 +197,8 @@ public class Util { sendItemCommand(client, item.link(), command); } + + public static void sendItemCommand(AsyncHttpClient client, String itemUrl, String command) { if (itemUrl == null || command == null) { return;