Skip to content

Commit b5fd545

Browse files
authored
Issue 128 new screen wizard (#132)
* some refactoring / fixing of hard coded import paths implementing the new screen wizard has started * initial work on building UI for new screen wizard * working on building UI for general * orientation button updates * staring on layout widget put in example table (to be removed) * built layout widget * removed unnecessary code * temporarily holding off on building the control design, will need to wait until i redo the "game" view * cleaning up unused translation code setting up for wizard control view * finalized translations for layoutWidget.dart * implemented basic code - but crashes due to not setting button/switch/background details (at least) * added default controls code compiles, sort of runs. need to work on positioning and importing of default values from native * refreshes view after creating new screen properly lays out buttons * uses a default image, wrong, but better than nothing bug fixes around null * fixed importing defaults tweaked margins on new * removed restrictions on requiring text/command for controls added separate text control for switches * customizable screen dimensions * fixed unit tests * removed comment * update version
1 parent 9e38803 commit b5fd545

34 files changed

+1130
-132
lines changed

gic_flutter/android/app/src/main/kotlin/ca/coffeeshopstudio/gaminginterfaceclient/MainActivity.kt

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Intent
44
import android.os.Bundle
55
import android.os.Environment
66
import android.preference.PreferenceManager
7+
import ca.coffeeshopstudio.gaminginterfaceclient.models.ControlDefaults
78
import ca.coffeeshopstudio.gaminginterfaceclient.models.screen.ScreenRepository
89
import ca.coffeeshopstudio.gaminginterfaceclient.utils.CryptoHelper
910
import ca.coffeeshopstudio.gaminginterfaceclient.views.DonateActivity
@@ -31,6 +32,7 @@ class MainActivity: FlutterActivity() {
3132
const val actionGetDownloadFolder = "downloadFolder"
3233
const val actionUpdateDarkMode = "darkmode/set"
3334
const val actionUtilUpdateScreens = "screens/upgrade"
35+
const val actionCheckDefaults = "defaults"
3436
}
3537

3638
private lateinit var _result: MethodChannel.Result
@@ -105,6 +107,9 @@ class MainActivity: FlutterActivity() {
105107
actionGetDownloadFolder -> {
106108
result.success(Environment.getExternalStorageDirectory().absolutePath);
107109
}
110+
actionCheckDefaults -> {
111+
ControlDefaults(applicationContext);
112+
}
108113
actionUpdateDarkMode -> {
109114
val defaultPrefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
110115
val editor = defaultPrefs.edit()

gic_flutter/android/app/src/main/kotlin/ca/coffeeshopstudio/gaminginterfaceclient/models/ControlDefaults.java

+58-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5+
import android.util.Log;
56
import android.widget.Toast;
67

78
import com.fasterxml.jackson.core.JsonProcessingException;
89
import com.fasterxml.jackson.databind.ObjectMapper;
910

1011
import java.io.IOException;
12+
import java.util.Map;
13+
14+
import ca.coffeeshopstudio.gaminginterfaceclient.R;
1115

1216
import static android.content.Context.MODE_PRIVATE;
1317

@@ -27,14 +31,56 @@
2731
* limitations under the License.
2832
*/
2933
public class ControlDefaults {
30-
private final String PREFS_NAME = "gicsScreen";
34+
private final String PREFS_NAME_FLUTTER = "FlutterSharedPreferences";
35+
3136
private GICControl defaultImageControl;
3237
private GICControl defaultButtonControl;
3338
private GICControl defaultTextControl;
3439
private GICControl defaultSwitchControl;
40+
private final String PREFS_FLUTTER_PREFIX = "flutter.";
41+
42+
//constructor purely for making compatible with flutter
43+
public ControlDefaults(Context context) {
44+
final String PREFS_NAME_LEGACY = "gicsScreen";
45+
SharedPreferences prefsLegacy = context.getApplicationContext().getSharedPreferences(PREFS_NAME_LEGACY, MODE_PRIVATE);
46+
SharedPreferences prefsFlutter = context.getApplicationContext().getSharedPreferences(PREFS_NAME_FLUTTER, MODE_PRIVATE);
47+
SharedPreferences.Editor flutterEditor = prefsFlutter.edit();
48+
SharedPreferences.Editor legacyEditor = prefsLegacy.edit();
49+
50+
Map<String, ?> keys = prefsLegacy.getAll();
51+
for (Map.Entry<String, ?> entry : keys.entrySet()) {
52+
Log.d("GICS", "cleanupLegacyDefaults: " + entry.getKey());
53+
if (containsKey(entry.getKey()) ) {
54+
Log.d("GICS", "cleanupLegacy: " + "converting");
55+
//we need to convert
56+
if (entry.getValue() instanceof String)
57+
flutterEditor.putString(PREFS_FLUTTER_PREFIX + entry.getKey(), (String) entry.getValue());
58+
else //gotta be an int
59+
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + entry.getKey(), (Integer) entry.getValue());
60+
//and remove
61+
legacyEditor.remove(entry.getKey());
62+
}
63+
}
64+
65+
//set resource defaults
66+
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_button_primary", R.drawable.button_blue);
67+
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_button_secondary", R.drawable.button_blue_dark);
68+
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_switch_primary", R.drawable.switch_off);
69+
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_switch_secondary", R.drawable.switch_on);
70+
71+
legacyEditor.apply();
72+
flutterEditor.apply();
73+
}
74+
private boolean containsKey (String key) {
75+
return key.contains("_image_defaults") ||
76+
key.contains("_button_defaults") ||
77+
key.contains("_text_defaults") ||
78+
key.contains("_switch_defaults");
79+
}
80+
3581

3682
public ControlDefaults(Context context, int screenId) {
37-
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
83+
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME_FLUTTER, MODE_PRIVATE);
3884

3985
String prefString = screenId + "_image_defaults";
4086
defaultImageControl = loadControl(context, prefs, prefString);
@@ -92,25 +138,30 @@ private GICControl loadControl(Context context, SharedPreferences prefs, String
92138
}
93139

94140
public void saveDefaults(Context context, int screenId) {
95-
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
141+
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME_FLUTTER, MODE_PRIVATE);
142+
save(context, screenId, prefs);
143+
}
144+
145+
//reusable for both saveDefaults and the new upgrade method
146+
private void save(Context context, int screenId, SharedPreferences prefs) {
96147
SharedPreferences.Editor prefsEditor = prefs.edit();
97148
ObjectMapper mapper = new ObjectMapper();
98149
String json;
99150

100151
try {
101-
String prefString = screenId + "_image_defaults";
152+
String prefString = PREFS_FLUTTER_PREFIX + screenId + "_image_defaults";
102153
json = mapper.writeValueAsString(defaultImageControl);
103154
prefsEditor.putString(prefString, json);
104155

105-
prefString = screenId + "_text_defaults";
156+
prefString = PREFS_FLUTTER_PREFIX + screenId + "_text_defaults";
106157
json = mapper.writeValueAsString(defaultTextControl);
107158
prefsEditor.putString(prefString, json);
108159

109-
prefString = screenId + "_button_defaults";
160+
prefString = PREFS_FLUTTER_PREFIX + screenId + "_button_defaults";
110161
json = mapper.writeValueAsString(defaultButtonControl);
111162
prefsEditor.putString(prefString, json);
112163

113-
prefString = screenId + "_switch_defaults";
164+
prefString = PREFS_FLUTTER_PREFIX + screenId + "_switch_defaults";
114165
json = mapper.writeValueAsString(defaultSwitchControl);
115166
prefsEditor.putString(prefString, json);
116167
} catch (JsonProcessingException e) {

gic_flutter/android/app/src/main/kotlin/ca/coffeeshopstudio/gaminginterfaceclient/views/AbstractGameActivity.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ protected StateListDrawable buildButtonDrawable(GICControl control) {
105105
Drawable primary;
106106
Drawable secondary;
107107

108+
if (control.getPrimaryImage() == null)
109+
control.setPrimaryImage("");
110+
if (control.getSecondaryImage() == null)
111+
control.setSecondaryImage("");
112+
108113
if (control.getPrimaryColor() != -1) {
109114
//color gradients
110115
//we don't support mixing color and otherwise
@@ -269,7 +274,7 @@ private void initText(TextView view, GICControl control) {
269274
}
270275

271276
protected void setFontTypeface(TextView textView, GICControl control) {
272-
if (control.getFontName().isEmpty()) {
277+
if (control.getFontName() == null || control.getFontName().isEmpty()) {
273278
textView.setTypeface(Typeface.DEFAULT);
274279
} else {
275280
if (control.getFontType() == 0) {

gic_flutter/android/app/src/main/kotlin/ca/coffeeshopstudio/gaminginterfaceclient/views/edit/EditButtonFragment.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import android.content.Intent;
88
import android.content.pm.PackageManager;
99
import android.graphics.Bitmap;
10-
import android.graphics.Color;
1110
import android.graphics.Typeface;
1211
import android.graphics.drawable.Drawable;
1312
import android.graphics.drawable.StateListDrawable;
1413
import android.net.Uri;
15-
import android.os.Build;
1614
import android.os.Bundle;
1715
import android.provider.MediaStore;
1816
import android.text.InputFilter;
@@ -32,6 +30,10 @@
3230
import android.widget.TextView;
3331
import android.widget.Toast;
3432

33+
import androidx.annotation.NonNull;
34+
import androidx.annotation.Nullable;
35+
import androidx.fragment.app.DialogFragment;
36+
3537
import com.flask.colorpicker.ColorPickerView;
3638
import com.flask.colorpicker.builder.ColorPickerClickListener;
3739
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
@@ -47,9 +49,6 @@
4749
import java.util.List;
4850
import java.util.Objects;
4951

50-
import androidx.annotation.NonNull;
51-
import androidx.annotation.Nullable;
52-
import androidx.fragment.app.DialogFragment;
5352
import ca.coffeeshopstudio.gaminginterfaceclient.R;
5453
import ca.coffeeshopstudio.gaminginterfaceclient.models.AutoItKeyMap;
5554
import ca.coffeeshopstudio.gaminginterfaceclient.models.ControlTypes;
@@ -140,6 +139,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
140139

141140
private void loadControl(GICControl control) {
142141
controlToLoad = control;
142+
if (controlToLoad.getPrimaryImage() == null)
143+
controlToLoad.setPrimaryImage("");
144+
if (controlToLoad.getSecondaryImage() == null)
145+
controlToLoad.setSecondaryImage("");
143146
}
144147

145148
private void loadView(View view) {
@@ -619,14 +622,14 @@ private StateListDrawable buildStatePreview() {
619622
if (controlToLoad.getPrimaryImageResource() != -1) {
620623
normal = getResources().getDrawable(ControlTypes.GetButtonDrawableId(controlToLoad.getPrimaryImageResource(), true));
621624
}
622-
if (!controlToLoad.getPrimaryImage().isEmpty()) {
625+
if (controlToLoad.getPrimaryImage() != null && !controlToLoad.getPrimaryImage().isEmpty()) {
623626
normal = Drawable.createFromPath(controlToLoad.getPrimaryImage());
624627
}
625628

626629
if (controlToLoad.getSecondaryImageResource() != -1) {
627630
secondary = getResources().getDrawable(ControlTypes.GetButtonDrawableId(controlToLoad.getSecondaryImageResource(), false));
628631
}
629-
if (!controlToLoad.getSecondaryImage().isEmpty()) {
632+
if (controlToLoad.getSecondaryImage() != null && !controlToLoad.getSecondaryImage().isEmpty()) {
630633
secondary = Drawable.createFromPath(controlToLoad.getSecondaryImage());
631634
}
632635

gic_flutter/android/app/src/main/kotlin/ca/coffeeshopstudio/gaminginterfaceclient/views/edit/EditToggleFragment.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import android.content.DialogInterface;
66
import android.content.Intent;
77
import android.graphics.Bitmap;
8-
import android.graphics.Color;
98
import android.graphics.Typeface;
109
import android.graphics.drawable.Drawable;
1110
import android.graphics.drawable.StateListDrawable;
1211
import android.net.Uri;
13-
import android.os.Build;
1412
import android.os.Bundle;
1513
import android.provider.MediaStore;
1614
import android.text.InputFilter;
@@ -147,6 +145,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
147145

148146
private void loadControl(GICControl control) {
149147
controlToLoad = control;
148+
if (controlToLoad.getPrimaryImage() == null)
149+
controlToLoad.setPrimaryImage("");
150+
if (controlToLoad.getSecondaryImage() == null)
151+
controlToLoad.setSecondaryImage("");
150152
}
151153

152154
@Override
@@ -565,14 +567,14 @@ private StateListDrawable buildStatePreview() {
565567
if (controlToLoad.getPrimaryImageResource() != -1) {
566568
normal = getResources().getDrawable(ControlTypes.GetSwitchDrawableId(controlToLoad.getPrimaryImageResource(), true));
567569
}
568-
if (!controlToLoad.getPrimaryImage().isEmpty()) {
570+
if (controlToLoad.getPrimaryImage() != null && !controlToLoad.getPrimaryImage().isEmpty()) {
569571
normal = Drawable.createFromPath(controlToLoad.getPrimaryImage());
570572
}
571573

572574
if (controlToLoad.getSecondaryImageResource() != -1) {
573575
secondary = getResources().getDrawable(ControlTypes.GetSwitchDrawableId(controlToLoad.getSecondaryImageResource(), false));
574576
}
575-
if (!controlToLoad.getSecondaryImage().isEmpty()) {
577+
if (controlToLoad.getSecondaryImage() != null && !controlToLoad.getSecondaryImage().isEmpty()) {
576578
secondary = Drawable.createFromPath(controlToLoad.getSecondaryImage());
577579
}
578580

gic_flutter/lib/app.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_localizations/flutter_localizations.dart';
3-
import 'package:gic_flutter/ui/launcher.dart';
43
import 'package:gic_flutter/views/intro/introView.dart';
54
import 'package:gic_flutter/service_locator.dart';
65
import 'package:gic_flutter/services/localStorageService.dart';
76

87
import 'model/intl/localizations.dart';
98
import 'theme/theme.dart';
9+
import 'ui/launcher/launcher.dart';
1010

1111
class GicApp extends StatelessWidget {
1212
GicApp ();

gic_flutter/lib/bloc/launcherBloc.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LauncherBloc {
2222
Stream<LauncherModel> get preferences => _modelFetcher.stream;
2323

2424
/// Loads the preferences from the repository, and adds to the sink
25-
void fetchAllPreferences() async {
25+
Future<void> fetchAllPreferences() async {
2626
LauncherModel itemModel = await _repository.fetch();
2727
_modelFetcher.sink.add(itemModel);
2828
}

0 commit comments

Comments
 (0)