Skip to content

Commit

Permalink
Issue 128 new screen wizard (#132)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Terence-D authored Oct 20, 2020
1 parent 9e38803 commit b5fd545
Show file tree
Hide file tree
Showing 34 changed files with 1,130 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.preference.PreferenceManager
import ca.coffeeshopstudio.gaminginterfaceclient.models.ControlDefaults
import ca.coffeeshopstudio.gaminginterfaceclient.models.screen.ScreenRepository
import ca.coffeeshopstudio.gaminginterfaceclient.utils.CryptoHelper
import ca.coffeeshopstudio.gaminginterfaceclient.views.DonateActivity
Expand Down Expand Up @@ -31,6 +32,7 @@ class MainActivity: FlutterActivity() {
const val actionGetDownloadFolder = "downloadFolder"
const val actionUpdateDarkMode = "darkmode/set"
const val actionUtilUpdateScreens = "screens/upgrade"
const val actionCheckDefaults = "defaults"
}

private lateinit var _result: MethodChannel.Result
Expand Down Expand Up @@ -105,6 +107,9 @@ class MainActivity: FlutterActivity() {
actionGetDownloadFolder -> {
result.success(Environment.getExternalStorageDirectory().absolutePath);
}
actionCheckDefaults -> {
ControlDefaults(applicationContext);
}
actionUpdateDarkMode -> {
val defaultPrefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
val editor = defaultPrefs.edit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Map;

import ca.coffeeshopstudio.gaminginterfaceclient.R;

import static android.content.Context.MODE_PRIVATE;

Expand All @@ -27,14 +31,56 @@
* limitations under the License.
*/
public class ControlDefaults {
private final String PREFS_NAME = "gicsScreen";
private final String PREFS_NAME_FLUTTER = "FlutterSharedPreferences";

private GICControl defaultImageControl;
private GICControl defaultButtonControl;
private GICControl defaultTextControl;
private GICControl defaultSwitchControl;
private final String PREFS_FLUTTER_PREFIX = "flutter.";

//constructor purely for making compatible with flutter
public ControlDefaults(Context context) {
final String PREFS_NAME_LEGACY = "gicsScreen";
SharedPreferences prefsLegacy = context.getApplicationContext().getSharedPreferences(PREFS_NAME_LEGACY, MODE_PRIVATE);
SharedPreferences prefsFlutter = context.getApplicationContext().getSharedPreferences(PREFS_NAME_FLUTTER, MODE_PRIVATE);
SharedPreferences.Editor flutterEditor = prefsFlutter.edit();
SharedPreferences.Editor legacyEditor = prefsLegacy.edit();

Map<String, ?> keys = prefsLegacy.getAll();
for (Map.Entry<String, ?> entry : keys.entrySet()) {
Log.d("GICS", "cleanupLegacyDefaults: " + entry.getKey());
if (containsKey(entry.getKey()) ) {
Log.d("GICS", "cleanupLegacy: " + "converting");
//we need to convert
if (entry.getValue() instanceof String)
flutterEditor.putString(PREFS_FLUTTER_PREFIX + entry.getKey(), (String) entry.getValue());
else //gotta be an int
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + entry.getKey(), (Integer) entry.getValue());
//and remove
legacyEditor.remove(entry.getKey());
}
}

//set resource defaults
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_button_primary", R.drawable.button_blue);
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_button_secondary", R.drawable.button_blue_dark);
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_switch_primary", R.drawable.switch_off);
flutterEditor.putInt(PREFS_FLUTTER_PREFIX + "default_switch_secondary", R.drawable.switch_on);

legacyEditor.apply();
flutterEditor.apply();
}
private boolean containsKey (String key) {
return key.contains("_image_defaults") ||
key.contains("_button_defaults") ||
key.contains("_text_defaults") ||
key.contains("_switch_defaults");
}


public ControlDefaults(Context context, int screenId) {
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME_FLUTTER, MODE_PRIVATE);

String prefString = screenId + "_image_defaults";
defaultImageControl = loadControl(context, prefs, prefString);
Expand Down Expand Up @@ -92,25 +138,30 @@ private GICControl loadControl(Context context, SharedPreferences prefs, String
}

public void saveDefaults(Context context, int screenId) {
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(PREFS_NAME_FLUTTER, MODE_PRIVATE);
save(context, screenId, prefs);
}

//reusable for both saveDefaults and the new upgrade method
private void save(Context context, int screenId, SharedPreferences prefs) {
SharedPreferences.Editor prefsEditor = prefs.edit();
ObjectMapper mapper = new ObjectMapper();
String json;

try {
String prefString = screenId + "_image_defaults";
String prefString = PREFS_FLUTTER_PREFIX + screenId + "_image_defaults";
json = mapper.writeValueAsString(defaultImageControl);
prefsEditor.putString(prefString, json);

prefString = screenId + "_text_defaults";
prefString = PREFS_FLUTTER_PREFIX + screenId + "_text_defaults";
json = mapper.writeValueAsString(defaultTextControl);
prefsEditor.putString(prefString, json);

prefString = screenId + "_button_defaults";
prefString = PREFS_FLUTTER_PREFIX + screenId + "_button_defaults";
json = mapper.writeValueAsString(defaultButtonControl);
prefsEditor.putString(prefString, json);

prefString = screenId + "_switch_defaults";
prefString = PREFS_FLUTTER_PREFIX + screenId + "_switch_defaults";
json = mapper.writeValueAsString(defaultSwitchControl);
prefsEditor.putString(prefString, json);
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ protected StateListDrawable buildButtonDrawable(GICControl control) {
Drawable primary;
Drawable secondary;

if (control.getPrimaryImage() == null)
control.setPrimaryImage("");
if (control.getSecondaryImage() == null)
control.setSecondaryImage("");

if (control.getPrimaryColor() != -1) {
//color gradients
//we don't support mixing color and otherwise
Expand Down Expand Up @@ -269,7 +274,7 @@ private void initText(TextView view, GICControl control) {
}

protected void setFontTypeface(TextView textView, GICControl control) {
if (control.getFontName().isEmpty()) {
if (control.getFontName() == null || control.getFontName().isEmpty()) {
textView.setTypeface(Typeface.DEFAULT);
} else {
if (control.getFontType() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.InputFilter;
Expand All @@ -32,6 +30,10 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerClickListener;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
Expand All @@ -47,9 +49,6 @@
import java.util.List;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import ca.coffeeshopstudio.gaminginterfaceclient.R;
import ca.coffeeshopstudio.gaminginterfaceclient.models.AutoItKeyMap;
import ca.coffeeshopstudio.gaminginterfaceclient.models.ControlTypes;
Expand Down Expand Up @@ -140,6 +139,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

private void loadControl(GICControl control) {
controlToLoad = control;
if (controlToLoad.getPrimaryImage() == null)
controlToLoad.setPrimaryImage("");
if (controlToLoad.getSecondaryImage() == null)
controlToLoad.setSecondaryImage("");
}

private void loadView(View view) {
Expand Down Expand Up @@ -619,14 +622,14 @@ private StateListDrawable buildStatePreview() {
if (controlToLoad.getPrimaryImageResource() != -1) {
normal = getResources().getDrawable(ControlTypes.GetButtonDrawableId(controlToLoad.getPrimaryImageResource(), true));
}
if (!controlToLoad.getPrimaryImage().isEmpty()) {
if (controlToLoad.getPrimaryImage() != null && !controlToLoad.getPrimaryImage().isEmpty()) {
normal = Drawable.createFromPath(controlToLoad.getPrimaryImage());
}

if (controlToLoad.getSecondaryImageResource() != -1) {
secondary = getResources().getDrawable(ControlTypes.GetButtonDrawableId(controlToLoad.getSecondaryImageResource(), false));
}
if (!controlToLoad.getSecondaryImage().isEmpty()) {
if (controlToLoad.getSecondaryImage() != null && !controlToLoad.getSecondaryImage().isEmpty()) {
secondary = Drawable.createFromPath(controlToLoad.getSecondaryImage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.InputFilter;
Expand Down Expand Up @@ -147,6 +145,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

private void loadControl(GICControl control) {
controlToLoad = control;
if (controlToLoad.getPrimaryImage() == null)
controlToLoad.setPrimaryImage("");
if (controlToLoad.getSecondaryImage() == null)
controlToLoad.setSecondaryImage("");
}

@Override
Expand Down Expand Up @@ -565,14 +567,14 @@ private StateListDrawable buildStatePreview() {
if (controlToLoad.getPrimaryImageResource() != -1) {
normal = getResources().getDrawable(ControlTypes.GetSwitchDrawableId(controlToLoad.getPrimaryImageResource(), true));
}
if (!controlToLoad.getPrimaryImage().isEmpty()) {
if (controlToLoad.getPrimaryImage() != null && !controlToLoad.getPrimaryImage().isEmpty()) {
normal = Drawable.createFromPath(controlToLoad.getPrimaryImage());
}

if (controlToLoad.getSecondaryImageResource() != -1) {
secondary = getResources().getDrawable(ControlTypes.GetSwitchDrawableId(controlToLoad.getSecondaryImageResource(), false));
}
if (!controlToLoad.getSecondaryImage().isEmpty()) {
if (controlToLoad.getSecondaryImage() != null && !controlToLoad.getSecondaryImage().isEmpty()) {
secondary = Drawable.createFromPath(controlToLoad.getSecondaryImage());
}

Expand Down
2 changes: 1 addition & 1 deletion gic_flutter/lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:gic_flutter/ui/launcher.dart';
import 'package:gic_flutter/views/intro/introView.dart';
import 'package:gic_flutter/service_locator.dart';
import 'package:gic_flutter/services/localStorageService.dart';

import 'model/intl/localizations.dart';
import 'theme/theme.dart';
import 'ui/launcher/launcher.dart';

class GicApp extends StatelessWidget {
GicApp ();
Expand Down
2 changes: 1 addition & 1 deletion gic_flutter/lib/bloc/launcherBloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LauncherBloc {
Stream<LauncherModel> get preferences => _modelFetcher.stream;

/// Loads the preferences from the repository, and adds to the sink
void fetchAllPreferences() async {
Future<void> fetchAllPreferences() async {
LauncherModel itemModel = await _repository.fetch();
_modelFetcher.sink.add(itemModel);
}
Expand Down
Loading

0 comments on commit b5fd545

Please sign in to comment.