Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
improved preference enums with auto-casting - more progress for #113
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Feb 13, 2018
1 parent c99fcd4 commit 3bb9c68
Show file tree
Hide file tree
Showing 33 changed files with 354 additions and 507 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/james/status/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public interface OnPreferenceChangedListener {
}

public static void showDebug(Context context, String message, int length) {
if (PreferenceData.STATUS_DEBUG.getBooleanValue(context))
if (PreferenceData.STATUS_DEBUG.getValue(context))
Toast.makeText(context, message, length).show();
else Log.d("Status", message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected Integer run() throws InterruptedException {
protected void done(@Nullable Integer result) {
ColorPickerDialog dialog = new ColorPickerDialog(AppSettingActivity.this);
dialog.setPreference(app.getIntegerPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.COLOR));
dialog.setDefaultPreference(result != null ? result : PreferenceData.STATUS_COLOR.getIntValue(AppSettingActivity.this));
dialog.setDefaultPreference(result != null ? result : (int) PreferenceData.STATUS_COLOR.getValue(AppSettingActivity.this));
dialog.setListener(new PreferenceDialog.OnPreferenceListener<Integer>() {
@Override
public void onPreference(PreferenceDialog dialog, Integer preference) {
Expand Down Expand Up @@ -112,7 +112,7 @@ protected Integer run() throws InterruptedException {

@Override
protected void done(@Nullable Integer result) {
colorView.setImageDrawable(new ColorDrawable(result != null ? result : PreferenceData.STATUS_COLOR.getIntValue(AppSettingActivity.this)));
colorView.setImageDrawable(new ColorDrawable(result != null ? result : (int) PreferenceData.STATUS_COLOR.getValue(AppSettingActivity.this)));
}
}.execute();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ protected void done(@Nullable Integer result) {

ColorPickerDialog dialog = new ColorPickerDialog(AppSettingActivity.this);
dialog.setPreference(activity.getIntegerPreference(AppSettingActivity.this, AppData.PreferenceIdentifier.COLOR));
dialog.setDefaultPreference(result != null ? result : PreferenceData.STATUS_COLOR.getIntValue(AppSettingActivity.this));
dialog.setDefaultPreference(result != null ? result : (int) PreferenceData.STATUS_COLOR.getValue(AppSettingActivity.this));
dialog.setListener(new PreferenceDialog.OnPreferenceListener<Integer>() {
@Override
public void onPreference(PreferenceDialog dialog, Integer preference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
}
});

service.setChecked(PreferenceData.STATUS_ENABLED.getBooleanValue(this) && StaticUtils.isStatusServiceRunning(this));
service.setChecked((boolean) PreferenceData.STATUS_ENABLED.getValue(this) && StaticUtils.isStatusServiceRunning(this));
service.setOnCheckedChangeListener(this);

adapter = new SimplePagerAdapter(this, getSupportFragmentManager(), viewPager, new GeneralPreferenceFragment(), new IconPreferenceFragment(), new AppPreferenceFragment(), new HelpFragment());
Expand Down Expand Up @@ -192,7 +192,7 @@ protected void onResume() {
super.onResume();

service.setOnCheckedChangeListener(null);
service.setChecked(PreferenceData.STATUS_ENABLED.getBooleanValue(this) || StaticUtils.isStatusServiceRunning(this));
service.setChecked((boolean) PreferenceData.STATUS_ENABLED.getValue(this) || StaticUtils.isStatusServiceRunning(this));
service.setOnCheckedChangeListener(this);

if (behavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/james/status/adapters/IconAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.CompoundButton;

import com.james.status.R;
import com.james.status.data.PreferenceData;
import com.james.status.data.icon.IconData;
import com.james.status.services.StatusService;
import com.james.status.utils.StaticUtils;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void onBindViewHolder(final ViewHolder holder, int position) {

itemView = holder.v;

icon.putPreference(IconData.PreferenceIdentifier.POSITION, position);
PreferenceData.ICON_POSITION.setValue(activity, position, icon.getIdentifierArgs());

holder.checkBox.setText(icon.getTitle());
holder.checkBox.setOnCheckedChangeListener(null);
Expand All @@ -63,7 +64,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
holder.checkBox.setChecked(false);
holder.checkBox.setOnCheckedChangeListener(this);
} else {
icon.putPreference(IconData.PreferenceIdentifier.VISIBILITY, isChecked);
PreferenceData.ICON_VISIBILITY.setValue(activity, isChecked, icon.getIdentifierArgs());
StaticUtils.updateStatusService(activity);

notifyItemChanged(holder.getAdapterPosition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.james.status.R;
import com.james.status.data.IconStyleData;
import com.james.status.data.PreferenceData;
import com.james.status.data.icon.IconData;
import com.james.status.dialogs.IconCreatorDialog;
import com.james.status.views.CustomImageView;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void onClick(View view) {
if (styles.size() > 0) setIconStyle(styles.get(0));
else notifyDataSetChanged();

new IconCreatorDialog(context, style, icon.getStringArrayPreference(IconData.PreferenceIdentifier.ICON_STYLE_NAMES), icon.getIconNames()).setListener(new IconCreatorDialog.OnIconStyleListener() {
new IconCreatorDialog(context, style, (String[]) PreferenceData.ICON_ICON_STYLE_NAMES.getSpecificValue(context, icon.getIdentifierArgs()), icon.getIconNames()).setListener(new IconCreatorDialog.OnIconStyleListener() {
@Override
public void onIconStyle(IconStyleData style) {
icon.addIconStyle(style);
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/james/status/data/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public int getColor(Context context) {

@ColorInt
public int getDefaultColor(Context context) {
if (PreferenceData.STATUS_COLOR_AUTO.getBooleanValue(context)) {
if (PreferenceData.STATUS_COLOR_AUTO.getValue(context)) {
Integer color = ColorUtils.getPrimaryColor(context, getComponentName());
if (color != null)
return color;
}

return PreferenceData.STATUS_COLOR.getIntValue(context);
return PreferenceData.STATUS_COLOR.getValue(context);
}

public void setTag(String key, Object value) {
Expand Down Expand Up @@ -262,13 +262,13 @@ public int getColor(Context context) {

@ColorInt
public int getDefaultColor(Context context) {
if (PreferenceData.STATUS_COLOR_AUTO.getBooleanValue(context)) {
if (PreferenceData.STATUS_COLOR_AUTO.getValue(context)) {
Integer color = ColorUtils.getPrimaryColor(context, getComponentName());
if (color != null)
return color;
}

return PreferenceData.STATUS_COLOR.getIntValue(context);
return PreferenceData.STATUS_COLOR.getValue(context);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public String getName(Context context) {
}

public boolean shouldShowHeadsUp(Context context) {
return PreferenceData.STATUS_NOTIFICATIONS_HEADS_UP.getBooleanValue(context) && (priority >= NotificationCompat.PRIORITY_HIGH || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) && isAlert;
return (boolean) PreferenceData.STATUS_NOTIFICATIONS_HEADS_UP.getValue(context) && (priority >= NotificationCompat.PRIORITY_HIGH || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) && isAlert;
}

public boolean shouldHideStatusBar() {
Expand Down
Loading

0 comments on commit 3bb9c68

Please sign in to comment.