Skip to content

Commit

Permalink
Merge pull request #47 from FazziCLAY/special_widget
Browse files Browse the repository at this point in the history
Special widget
  • Loading branch information
FazziCLAY authored Sep 21, 2023
2 parents 1fe5e64 + 4387682 commit 3b0c207
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 32 deletions.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ plugins {
}

// =====
var isDev = false
var isDev = true
var beta = false
var appIdSuffix = "" // EMPTY FOR RELEASES!!!!
var verBuild = 136
var verName = "1.2+[patches:[fix-tick]"
var verBranch = "RELEASE" // use "RELEASE" for releases versions
var verReleaseTime = 1689778441 // in seconds
var verBuild = 140
var verName = "1.2+[patches:[fix-tick] + [special_widget]"
var verBranch = "special_widget" // use "RELEASE" for releases versions
var verReleaseTime = 1689778441+9999 // in seconds
// =====

android {
Expand Down Expand Up @@ -60,6 +60,7 @@ dependencies {
implementation files("./libs/OpenTodayTelemetry-v2-v11.jar")
implementation files("./libs/NeoSocket-1.0.jar")
implementation files("./libs/JavaNeoUtil-1.1.jar")
implementation files("./libs/WarningRose-v0.4.1.jar")
implementation 'com.github.martin-stone:hsv-alpha-color-picker-android:3.0.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
Expand Down
Binary file added app/libs/WarningRose-v0.4.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.fazziclay.opentoday.util.annotation.Getter;
import com.fazziclay.opentoday.util.annotation.RequireSave;
import com.fazziclay.opentoday.util.annotation.SaveKey;
import com.fazziclay.warningrose.Rose;
import com.fazziclay.warningrose.WarningRose;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -22,7 +24,8 @@ public static class DebugTickCounterItemCodec extends TextItemCodec {
public Cherry exportItem(@NonNull Item item) {
DebugTickCounterItem debugTickCounterItem = (DebugTickCounterItem) item;
return super.exportItem(debugTickCounterItem)
.put("counter", debugTickCounterItem.counter);
.put("counter", debugTickCounterItem.counter)
.put("debug_isRoseEnabled", debugTickCounterItem.rose != null);
}

private final DebugTickCounterItem defaultValues = new DebugTickCounterItem();
Expand All @@ -32,6 +35,9 @@ public Item importItem(@NonNull Cherry cherry, Item item) {
DebugTickCounterItem debugTickCounterItem = item != null ? (DebugTickCounterItem) item : new DebugTickCounterItem();
super.importItem(cherry, debugTickCounterItem);
debugTickCounterItem.counter = cherry.optInt("counter", defaultValues.counter);
if (cherry.optBoolean("debug_isRoseEnabled", false)) {
debugTickCounterItem.rose = _createRose();
}
return debugTickCounterItem;
}
}
Expand All @@ -44,6 +50,7 @@ public static DebugTickCounterItem createEmpty() {

@SaveKey(key = "counter") @RequireSave private int counter;
private String debugStat = "";
private Rose rose;

protected DebugTickCounterItem() {
super();
Expand All @@ -65,6 +72,7 @@ public DebugTickCounterItem(DebugTickCounterItem copy) {
super(copy);
this.counter = copy.counter;
this.debugStat = "";
this.rose = copy.rose; // warning!
}

@Override
Expand All @@ -74,37 +82,62 @@ public void tick(TickSession tickSession) {
visibleChanged();
return;
}
counter++;
final List<String> targets = new ArrayList<>();
for (TickTarget value : TickTarget.values()) {
boolean allow = tickSession.isTickTargetAllowed(value);
if (allow) {
targets.add("$[-#00ff00]"+value.name()+"$[||]");
} else {
targets.add("$[-#ff0000]"+value.name()+"$[||]");


if (rose != null) {
debugStat = String.format("$[S20]%s\n | %s hours\n | %s weeks (C: %s)\n | %s%%", rose.elapsedSummaryText(), (int)rose.elapsedTotalHours(), (int)rose.elapsedWeeks(), rose.getCurrentWeekday(), (float)rose.endlessPercentage());

} else {
counter++;
final List<String> targets = new ArrayList<>();
for (TickTarget value : TickTarget.values()) {
boolean allow = tickSession.isTickTargetAllowed(value);
if (allow) {
targets.add("$[-#00ff00]"+value.name()+"$[||]");
} else {
targets.add("$[-#ff0000]"+value.name()+"$[||]");
}
}

debugStat = String.format("""
=== Debug tick counter ===
ID: %s
$[-#ffff00;S16]Counter: $[-#00aaff] %s$[||]
$[-#f0f0f0]Allowed targets: %s$[||]
$[-#00ffff]Whitelist(%s): %s$[||]
$[-$fff00f]PathToMe: %s$[||]
""", getId(), counter, targets, tickSession._isWhitelist(), tickSession._getWhitelist(),
Arrays.toString(ItemUtil.getPathToItem(this)));
}
debugStat = String.format("""
=== Debug tick counter ===
ID: %s
$[-#ffff00;S16]Counter: $[-#00aaff] %s$[||]
$[-#f0f0f0]Allowed targets: %s$[||]
$[-#00ffff]Whitelist(%s): %s$[||]
$[-$fff00f]PathToMe: %s$[||]
""", getId(), counter, targets, tickSession._isWhitelist(), tickSession._getWhitelist(),
Arrays.toString(ItemUtil.getPathToItem(this)));

visibleChanged();

super.tick(tickSession);
if (tickSession.isTickTargetAllowed(TickTarget.ITEM_DEBUG_TICK_COUNTER_UPDATE)) {
if (tickSession.isTickTargetAllowed(TickTarget.ITEM_DEBUG_TICK_COUNTER_UPDATE) && (rose == null)) {
tickSession.saveNeeded();
}
}

public void setRoseEnabled(boolean b) {
if (b) {
rose = _createRose();
} else {
rose = null;
}
}

public boolean isRoseEnabled() {
return rose != null;
}

@Getter
public int getCounter() { return counter; }

@Getter public String getDebugStat() {
return debugStat;
}

private static Rose _createRose() {
return new Rose(WarningRose.TEN_CLASS_START, WarningRose.EGE_PREPARE_END_MILLIS, System::currentTimeMillis);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ public static List<Item> importItemList(CherryOrchard orchard) {

// import item (JSON -> Item)
public static Item importItem(Cherry cherry) {
/*get itemType form json*/String itemType = cherry.getString(KEY_ITEMTYPE);
/*get class by itemType*/Class<? extends Item> itemClass = ItemsRegistry.REGISTRY.get(itemType).getClassType();
/*get IETool by class*/
AbstractItemCodec codec = ItemsRegistry.REGISTRY.get(itemClass).getCodec();
return codec.importItem(cherry, null);
try {
/*get itemType form json*/String itemType = cherry.getString(KEY_ITEMTYPE);
/*get class by itemType*/Class<? extends Item> itemClass = ItemsRegistry.REGISTRY.get(itemType).getClassType();
/*get IETool by class*/
AbstractItemCodec codec = ItemsRegistry.REGISTRY.get(itemClass).getCodec();
return codec.importItem(cherry, null);
} catch (Exception e) {
return ((MissingNoItem)ItemsRegistry.REGISTRY.get(ItemType.MISSING_NO).getCodec().importItem(cherry, null))
.putException(e);
}
}

// export item (Item -> JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum ItemType {
CYCLE_LIST(TEXT),
GROUP(TEXT),
FILTER_GROUP(TEXT),
MATH_GAME(TEXT);
MATH_GAME(TEXT),
MISSING_NO;

private final List<ItemType> parents = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ItemsRegistry {
new ItemInfo(GroupItem.class, "GroupItem", ItemType.GROUP, GroupItem.CODEC, GroupItem::createEmpty, (i) -> new GroupItem((GroupItem) i)),
new ItemInfo(FilterGroupItem.class, "FilterGroupItem", ItemType.FILTER_GROUP, FilterGroupItem.CODEC, FilterGroupItem::createEmpty, (i) -> new FilterGroupItem((FilterGroupItem) i)),
new ItemInfo(MathGameItem.class, "MathGameItem", ItemType.MATH_GAME, MathGameItem.CODEC, MathGameItem::createEmpty, (i) -> new MathGameItem((MathGameItem) i)),
new ItemInfo(MissingNoItem.class, "MissingNoItem", ItemType.MISSING_NO, MissingNoItem.CODEC, TextItem::createEmpty, (i) -> new TextItem("'missing no' item not support copy :(")).noAvailableToCreate(),
};

private ItemsRegistry() {}
Expand Down Expand Up @@ -82,6 +83,7 @@ public static class ItemInfo {
private final AbstractItemCodec codec;
private final ItemCreateInterface createInterface;
private final ItemCopyInterface copyInterface;
private boolean noAvailableToCreate;
private FeatureFlag requiredFeatureFlag;

public ItemInfo(@NonNull Class<? extends Item> classType, @NonNull String stringType, @NonNull ItemType itemType, @NonNull AbstractItemCodec codec, @NonNull ItemCreateInterface createInterface, @NonNull ItemCopyInterface copyInterface) {
Expand Down Expand Up @@ -132,6 +134,7 @@ public boolean isCompatibility(List<FeatureFlag> flags) {
}

public boolean isCompatibility(FeatureFlag[] flags) {
if (noAvailableToCreate) return false;
if (requiredFeatureFlag == null) return true;
for (FeatureFlag f : flags) {
if (f == requiredFeatureFlag) {
Expand All @@ -140,6 +143,11 @@ public boolean isCompatibility(FeatureFlag[] flags) {
}
return false;
}

public ItemInfo noAvailableToCreate() {
this.noAvailableToCreate = true;
return this;
}
}

private interface ItemCopyInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.fazziclay.opentoday.app.items.item;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.fazziclay.opentoday.app.data.Cherry;

import java.util.ArrayList;
import java.util.List;

public class MissingNoItem extends Item {
public static final MissingNoItemCodec CODEC = new MissingNoItemCodec();
private static class MissingNoItemCodec extends AbstractItemCodec {

@NonNull
@Override
public Cherry exportItem(@NonNull Item item) {
MissingNoItem missingNoItem = (MissingNoItem) item;
return missingNoItem.cherry;
}

@NonNull
@Override
public Item importItem(@NonNull Cherry cherry, @Nullable Item item) {
return new MissingNoItem(cherry);
}
}

private final Cherry cherry;
private final List<Exception> exceptionList = new ArrayList<>();

public MissingNoItem(Cherry cherry) {
this.cherry = cherry;
}

public MissingNoItem putException(Exception e) {
exceptionList.add(e);
return this;
}

public Exception[] getExceptionList() {
return exceptionList.toArray(new Exception[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object EnumsRegistry {
EnumInfo(ItemType.GROUP, R.string.item_group).setItemDescription(R.string.item_group_description),
EnumInfo(ItemType.FILTER_GROUP, R.string.item_filterGroup).setItemDescription(R.string.item_filterGroup_description),
EnumInfo(ItemType.MATH_GAME, R.string.item_mathGame).setItemDescription(R.string.item_mathGame_description),
EnumInfo(ItemType.MISSING_NO, R.string.item_missingNo).setItemDescription(R.string.item_missingNo_description),

EnumInfo(FilterGroupItem.TickBehavior.ALL, R.string.item_filterGroup_tickBehavior_ALL),
EnumInfo(FilterGroupItem.TickBehavior.NOTHING, R.string.item_filterGroup_tickBehavior_NOTHING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand All @@ -37,11 +39,13 @@
import com.fazziclay.opentoday.app.items.item.CounterItem;
import com.fazziclay.opentoday.app.items.item.CycleListItem;
import com.fazziclay.opentoday.app.items.item.DayRepeatableCheckboxItem;
import com.fazziclay.opentoday.app.items.item.DebugTickCounterItem;
import com.fazziclay.opentoday.app.items.item.FilterGroupItem;
import com.fazziclay.opentoday.app.items.item.Item;
import com.fazziclay.opentoday.app.items.item.ItemsRegistry;
import com.fazziclay.opentoday.app.items.item.LongTextItem;
import com.fazziclay.opentoday.app.items.item.MathGameItem;
import com.fazziclay.opentoday.app.items.item.MissingNoItem;
import com.fazziclay.opentoday.app.items.item.TextItem;
import com.fazziclay.opentoday.app.items.notification.DayItemNotification;
import com.fazziclay.opentoday.app.items.notification.ItemNotification;
Expand Down Expand Up @@ -210,7 +214,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

navigationHost = UI.findFragmentInParents(this, MainRootFragment.class);

if (item instanceof Item) {
if (item instanceof Item && (!(item instanceof MissingNoItem)) ) {
binding.modules.addView(addEditModule(new ItemEditModule()));
}
if (item instanceof TextItem) {
Expand All @@ -237,6 +241,19 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (item instanceof MathGameItem) {
binding.modules.addView(addEditModule(new MathGameItemEditModule()));
}
if (item instanceof DebugTickCounterItem) {
binding.modules.addView(addEditModule(new DebugTickCounterItemEditModule()));
}
if (item instanceof MissingNoItem missingNoItem) {
TextView textView = new TextView(getActivity());
StringBuilder text = new StringBuilder();
for (Exception exception : missingNoItem.getExceptionList()) {
text.append(exception.getMessage()).append("\n\n");
}
textView.setText(text.toString());

binding.modules.addView(textView);
}

UI.getUIRoot(this).pushActivitySettings(a -> {
a.setNotificationsVisible(false);
Expand Down Expand Up @@ -1064,4 +1081,43 @@ public void setOnStartEditListener(Runnable o) {
this.onEditStart = o;
}
}

private static class DebugTickCounterItemEditModule extends BaseEditUiModule {
private LinearLayout layout;
private CheckBox check;
private Runnable edit;

@Override
public View getView() {
return layout;
}

@Override
public void setup(Item item, Activity activity, View view) {
final var debugTickCounter = (DebugTickCounterItem) item;

layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);

var t = new TextView(activity);
t.setText("DEBUG: rose is enabled");
layout.addView(t);

check = new CheckBox(activity);
check.setChecked(debugTickCounter.isRoseEnabled());
layout.addView(check);
viewClick(check, edit);
}

@Override
public void commit(Item item) {
final var debugTickCounter = (DebugTickCounterItem) item;
debugTickCounter.setRoseEnabled(check.isChecked());
}

@Override
public void setOnStartEditListener(Runnable o) {
this.edit = o;
}
}
}
Loading

0 comments on commit 3b0c207

Please sign in to comment.