mirror of
https://github.com/Dark98/SliceBeam.git
synced 2026-07-03 00:38:53 +00:00
Add tooltips on long click (For booleans)
This commit is contained in:
@@ -34,6 +34,13 @@ public class ConfigObject implements ProfileListFragment.ProfileListItem {
|
|||||||
this.values.putAll(from.values);
|
this.values.putAll(from.values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: suitable only from "printer" config
|
||||||
|
*/
|
||||||
|
public int getExtruderCount() {
|
||||||
|
return get("nozzle_diameter") != null ? get("nozzle_diameter").replaceAll("[^.]+", "").length() : 1;
|
||||||
|
}
|
||||||
|
|
||||||
public String get(String key) {
|
public String get(String key) {
|
||||||
return values.get(key);
|
return values.get(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class PrinterConfigFragment extends ProfileListFragment {
|
|||||||
// TODO: m_supports_min_feedrates? <= marlin/marlin legacy
|
// TODO: m_supports_min_feedrates? <= marlin/marlin legacy
|
||||||
));
|
));
|
||||||
|
|
||||||
int count = currentConfig.get("nozzle_diameter") != null ? currentConfig.get("nozzle_diameter").replaceAll("[^.]+", "").length() : 1;
|
int count = currentConfig.getExtruderCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
int j = count == 1 ? -1 : i;
|
int j = count == 1 ? -1 : i;
|
||||||
list.addAll(Arrays.asList(
|
list.addAll(Arrays.asList(
|
||||||
|
|||||||
@@ -433,6 +433,7 @@ public abstract class ProfileListFragment extends Fragment {
|
|||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
SliceBeam.EVENT_BUS.unregisterListener(this);
|
SliceBeam.EVENT_BUS.unregisterListener(this);
|
||||||
|
unfolded.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
@@ -477,7 +478,9 @@ public abstract class ProfileListFragment extends Fragment {
|
|||||||
String v = getCurrentConfig().get(def.key);
|
String v = getCurrentConfig().get(def.key);
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
try {
|
try {
|
||||||
v = v.split(",")[i];
|
String ch = ",";
|
||||||
|
if (def.guiType == ConfigOptionDef.GUIType.COLOR) ch = ";";
|
||||||
|
v = v.split(ch)[i];
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
Log.w("ProfileListFragment", "Failed to parse mm option", e);
|
Log.w("ProfileListFragment", "Failed to parse mm option", e);
|
||||||
}
|
}
|
||||||
@@ -487,9 +490,11 @@ public abstract class ProfileListFragment extends Fragment {
|
|||||||
|
|
||||||
protected void updateConfigField(ConfigOptionDef def, int i, String value) {
|
protected void updateConfigField(ConfigOptionDef def, int i, String value) {
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
String[] vals = opt(def, -1).split(",");
|
String ch = ",";
|
||||||
|
if (def.guiType == ConfigOptionDef.GUIType.COLOR) ch = ";";
|
||||||
|
String[] vals = opt(def, -1).split(ch);
|
||||||
vals[i] = value;
|
vals[i] = value;
|
||||||
value = TextUtils.join(",", vals);
|
value = TextUtils.join(ch, vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(opt(def, i), value)) {
|
if (!Objects.equals(opt(def, i), value)) {
|
||||||
@@ -697,7 +702,14 @@ public abstract class ProfileListFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ref.set(builder.show());
|
ref.set(builder.show());
|
||||||
});
|
}).setOnLongClickListener(v -> {
|
||||||
|
new BeamAlertDialogBuilder(getContext())
|
||||||
|
.setTitle(Slic3rLocalization.getString(def.getFullLabel()))
|
||||||
|
.setMessage(Slic3rLocalization.getString(def.tooltip))
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
return true;
|
||||||
|
});;
|
||||||
|
|
||||||
if (def.type == ConfigOptionDef.ConfigOptionType.STRING || def.type == ConfigOptionDef.ConfigOptionType.STRINGS) {
|
if (def.type == ConfigOptionDef.ConfigOptionType.STRING || def.type == ConfigOptionDef.ConfigOptionType.STRINGS) {
|
||||||
((PreferenceItem) simpleItem).setSubtitleProvider(() -> opt(def, eIndex).trim());
|
((PreferenceItem) simpleItem).setSubtitleProvider(() -> opt(def, eIndex).trim());
|
||||||
@@ -727,11 +739,23 @@ public abstract class ProfileListFragment extends Fragment {
|
|||||||
case BOOLS:
|
case BOOLS:
|
||||||
simpleItem = new PreferenceSwitchItem().setTitle(Slic3rLocalization.getString(def.label))
|
simpleItem = new PreferenceSwitchItem().setTitle(Slic3rLocalization.getString(def.label))
|
||||||
.setValueProvider(() -> "1".equals(opt(def, eIndex)))
|
.setValueProvider(() -> "1".equals(opt(def, eIndex)))
|
||||||
.setChangeListener((buttonView, isChecked) -> updateConfigField(def, eIndex, String.valueOf(isChecked ? 1 : 0)));
|
.setChangeListener((buttonView, isChecked) -> updateConfigField(def, eIndex, String.valueOf(isChecked ? 1 : 0)))
|
||||||
|
.setLongClickListener(v -> {
|
||||||
|
new BeamAlertDialogBuilder(getContext())
|
||||||
|
.setTitle(Slic3rLocalization.getString(def.getFullLabel()))
|
||||||
|
.setMessage(Slic3rLocalization.getString(def.tooltip))
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OptionElement(int specialType) {
|
||||||
|
this.specialType = specialType;
|
||||||
|
}
|
||||||
|
|
||||||
public OptionElement(int icon, String title) {
|
public OptionElement(int icon, String title) {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
@@ -858,7 +882,6 @@ public abstract class ProfileListFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(Context ctx) {
|
public View onCreateView(Context ctx) {
|
||||||
FrameLayout v = new FrameLayout(ctx);
|
FrameLayout v = new FrameLayout(ctx);
|
||||||
v.setBackgroundColor(Color.GREEN);
|
|
||||||
v.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewUtils.dp(32)) {{
|
v.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewUtils.dp(32)) {{
|
||||||
bottomMargin = ViewUtils.dp(16);
|
bottomMargin = ViewUtils.dp(16);
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class PreferenceItem extends SimpleRecyclerItem<PreferenceItem.Preference
|
|||||||
private CharSequence mTitle;
|
private CharSequence mTitle;
|
||||||
private ValueProvider mSubtitle;
|
private ValueProvider mSubtitle;
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
private View.OnLongClickListener onLongClickListener;
|
||||||
private int textColorRes;
|
private int textColorRes;
|
||||||
private boolean noTint;
|
private boolean noTint;
|
||||||
private ValueProvider valueProvider;
|
private ValueProvider valueProvider;
|
||||||
@@ -90,6 +91,11 @@ public class PreferenceItem extends SimpleRecyclerItem<PreferenceItem.Preference
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PreferenceItem setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
|
||||||
|
this.onLongClickListener = onLongClickListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreferenceHolderView onCreateView(Context ctx) {
|
public PreferenceHolderView onCreateView(Context ctx) {
|
||||||
return new PreferenceHolderView(ctx);
|
return new PreferenceHolderView(ctx);
|
||||||
@@ -189,6 +195,7 @@ public class PreferenceItem extends SimpleRecyclerItem<PreferenceItem.Preference
|
|||||||
} else {
|
} else {
|
||||||
setClickable(false);
|
setClickable(false);
|
||||||
}
|
}
|
||||||
|
setOnLongClickListener(item.onLongClickListener);
|
||||||
|
|
||||||
if (item.textColorRes != 0) {
|
if (item.textColorRes != 0) {
|
||||||
title.setTextColor(ThemesRepo.getColor(item.textColorRes));
|
title.setTextColor(ThemesRepo.getColor(item.textColorRes));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -28,6 +29,7 @@ public class PreferenceSwitchItem extends SimpleRecyclerItem<PreferenceSwitchIte
|
|||||||
private String mKey;
|
private String mKey;
|
||||||
private boolean mDefaultValue;
|
private boolean mDefaultValue;
|
||||||
private CompoundButton.OnCheckedChangeListener mChangeListener;
|
private CompoundButton.OnCheckedChangeListener mChangeListener;
|
||||||
|
private View.OnLongClickListener mLongClickListener;
|
||||||
private ValueProvider valueProvider;
|
private ValueProvider valueProvider;
|
||||||
|
|
||||||
public PreferenceSwitchItem setValueProvider(ValueProvider valueProvider) {
|
public PreferenceSwitchItem setValueProvider(ValueProvider valueProvider) {
|
||||||
@@ -46,6 +48,11 @@ public class PreferenceSwitchItem extends SimpleRecyclerItem<PreferenceSwitchIte
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PreferenceSwitchItem setLongClickListener(View.OnLongClickListener longClickListener) {
|
||||||
|
mLongClickListener = longClickListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PreferenceSwitchItem setTitle(CharSequence title) {
|
public PreferenceSwitchItem setTitle(CharSequence title) {
|
||||||
mTitle = title;
|
mTitle = title;
|
||||||
return this;
|
return this;
|
||||||
@@ -154,6 +161,7 @@ public class PreferenceSwitchItem extends SimpleRecyclerItem<PreferenceSwitchIte
|
|||||||
item.mChangeListener.onCheckedChanged(matSwitch, check);
|
item.mChangeListener.onCheckedChanged(matSwitch, check);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setOnLongClickListener(item.mLongClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user