app settings bug fix, restructured color button initialization
This commit is contained in:
parent
7612ea37bb
commit
9fc9360856
@ -3,7 +3,6 @@ package org.nuclearfog.twidda.activity;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnDismissListener;
|
import android.content.DialogInterface.OnDismissListener;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
@ -78,14 +77,15 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
private GlobalSettings settings;
|
private GlobalSettings settings;
|
||||||
private LocationLoader locationAsync;
|
private LocationLoader locationAsync;
|
||||||
private LocationAdapter locationAdapter;
|
private LocationAdapter locationAdapter;
|
||||||
|
private FontAdapter fontAdapter;
|
||||||
|
|
||||||
private Dialog connectDialog, databaseDialog, logoutDialog, color_dialog_selector, appInfo;
|
private Dialog connectDialog, databaseDialog, logoutDialog, color_dialog_selector, appInfo;
|
||||||
private View root, layout_key, layout_proxy, layout_auth_en, layout_auth;
|
private View root, layout_key, layout_proxy, layout_auth_en, layout_auth;
|
||||||
private EditText proxyAddr, proxyPort, proxyUser, proxyPass, api_key1, api_key2;
|
private EditText proxyAddr, proxyPort, proxyUser, proxyPass, api_key1, api_key2;
|
||||||
|
private Button background, fontColor, popupColor, highlight, cardColor, iconColor;
|
||||||
private CompoundButton enableProxy, enableAuth, hqImage, enableAPI;
|
private CompoundButton enableProxy, enableAuth, hqImage, enableAPI;
|
||||||
private Spinner locationSpinner, fontSpinner;
|
private Spinner locationSpinner;
|
||||||
private TextView list_size;
|
private TextView list_size;
|
||||||
private Button[] colorButtons;
|
|
||||||
|
|
||||||
private ColorMode mode = ColorMode.NONE;
|
private ColorMode mode = ColorMode.NONE;
|
||||||
private int color = 0;
|
private int color = 0;
|
||||||
@ -102,12 +102,18 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
CompoundButton toggleImg = findViewById(R.id.toggleImg);
|
CompoundButton toggleImg = findViewById(R.id.toggleImg);
|
||||||
CompoundButton toggleAns = findViewById(R.id.toggleAns);
|
CompoundButton toggleAns = findViewById(R.id.toggleAns);
|
||||||
SeekBar listSizeSelector = findViewById(R.id.settings_list_seek);
|
SeekBar listSizeSelector = findViewById(R.id.settings_list_seek);
|
||||||
fontSpinner = findViewById(R.id.spinner_font);
|
Spinner fontSpinner = findViewById(R.id.spinner_font);
|
||||||
enableProxy = findViewById(R.id.settings_enable_proxy);
|
enableProxy = findViewById(R.id.settings_enable_proxy);
|
||||||
enableAuth = findViewById(R.id.settings_enable_auth);
|
enableAuth = findViewById(R.id.settings_enable_auth);
|
||||||
hqImage = findViewById(R.id.settings_image_hq);
|
hqImage = findViewById(R.id.settings_image_hq);
|
||||||
enableAPI = findViewById(R.id.settings_set_custom_keys);
|
enableAPI = findViewById(R.id.settings_set_custom_keys);
|
||||||
locationSpinner = findViewById(R.id.spinner_woeid);
|
locationSpinner = findViewById(R.id.spinner_woeid);
|
||||||
|
background = findViewById(R.id.color_background);
|
||||||
|
fontColor = findViewById(R.id.color_font);
|
||||||
|
popupColor = findViewById(R.id.color_popup);
|
||||||
|
highlight = findViewById(R.id.highlight_color);
|
||||||
|
cardColor = findViewById(R.id.color_card);
|
||||||
|
iconColor = findViewById(R.id.color_icon);
|
||||||
proxyAddr = findViewById(R.id.edit_proxy_address);
|
proxyAddr = findViewById(R.id.edit_proxy_address);
|
||||||
proxyPort = findViewById(R.id.edit_proxy_port);
|
proxyPort = findViewById(R.id.edit_proxy_port);
|
||||||
proxyUser = findViewById(R.id.edit_proxyuser);
|
proxyUser = findViewById(R.id.edit_proxyuser);
|
||||||
@ -115,20 +121,12 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
api_key1 = findViewById(R.id.settings_custom_key1);
|
api_key1 = findViewById(R.id.settings_custom_key1);
|
||||||
api_key2 = findViewById(R.id.settings_custom_key2);
|
api_key2 = findViewById(R.id.settings_custom_key2);
|
||||||
list_size = findViewById(R.id.settings_list_size);
|
list_size = findViewById(R.id.settings_list_size);
|
||||||
|
|
||||||
layout_proxy = findViewById(R.id.settings_layout_proxy);
|
layout_proxy = findViewById(R.id.settings_layout_proxy);
|
||||||
layout_auth_en = findViewById(R.id.settings_layout_auth_enable);
|
layout_auth_en = findViewById(R.id.settings_layout_auth_enable);
|
||||||
layout_auth = findViewById(R.id.settings_layout_proxy_auth);
|
layout_auth = findViewById(R.id.settings_layout_proxy_auth);
|
||||||
layout_key = findViewById(R.id.settings_layout_key);
|
layout_key = findViewById(R.id.settings_layout_key);
|
||||||
|
|
||||||
root = findViewById(R.id.settings_layout);
|
root = findViewById(R.id.settings_layout);
|
||||||
|
|
||||||
TypedArray buttons = getResources().obtainTypedArray(R.array.color_button);
|
|
||||||
colorButtons = new Button[buttons.length()];
|
|
||||||
for (int index = 0; index < buttons.length(); index++)
|
|
||||||
colorButtons[index] = findViewById(buttons.getResourceId(index, 0));
|
|
||||||
buttons.recycle();
|
|
||||||
|
|
||||||
toolbar.setTitle(R.string.title_settings);
|
toolbar.setTitle(R.string.title_settings);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
@ -150,13 +148,14 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
locationAdapter = new LocationAdapter(settings);
|
locationAdapter = new LocationAdapter(settings);
|
||||||
locationAdapter.addTop(settings.getTrendLocation());
|
locationAdapter.addTop(settings.getTrendLocation());
|
||||||
locationSpinner.setAdapter(locationAdapter);
|
locationSpinner.setAdapter(locationAdapter);
|
||||||
FontAdapter fontAdapter = new FontAdapter(settings);
|
locationSpinner.setSelected(false);
|
||||||
|
fontAdapter = new FontAdapter(settings);
|
||||||
fontSpinner.setAdapter(fontAdapter);
|
fontSpinner.setAdapter(fontAdapter);
|
||||||
fontSpinner.setSelection(settings.getFontIndex());
|
fontSpinner.setSelection(settings.getFontIndex(), false);
|
||||||
|
fontSpinner.setSelected(false);
|
||||||
|
|
||||||
AppStyles.setTheme(settings, root);
|
AppStyles.setTheme(settings, root);
|
||||||
|
|
||||||
setButtonColors();
|
|
||||||
toggleImg.setChecked(settings.getImageLoad());
|
toggleImg.setChecked(settings.getImageLoad());
|
||||||
toggleAns.setChecked(settings.getAnswerLoad());
|
toggleAns.setChecked(settings.getAnswerLoad());
|
||||||
enableAPI.setChecked(settings.isCustomApiSet());
|
enableAPI.setChecked(settings.isCustomApiSet());
|
||||||
@ -172,14 +171,19 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
enableAuth.setChecked(settings.isProxyAuthSet());
|
enableAuth.setChecked(settings.isProxyAuthSet());
|
||||||
hqImage.setEnabled(settings.getImageLoad());
|
hqImage.setEnabled(settings.getImageLoad());
|
||||||
hqImage.setChecked(settings.getImageQuality());
|
hqImage.setChecked(settings.getImageQuality());
|
||||||
|
setButtonColors();
|
||||||
|
|
||||||
connectDialog = DialogBuilder.create(this, WRONG_PROXY, this);
|
connectDialog = DialogBuilder.create(this, WRONG_PROXY, this);
|
||||||
databaseDialog = DialogBuilder.create(this, DEL_DATABASE, this);
|
databaseDialog = DialogBuilder.create(this, DEL_DATABASE, this);
|
||||||
logoutDialog = DialogBuilder.create(this, APP_LOG_OUT, this);
|
logoutDialog = DialogBuilder.create(this, APP_LOG_OUT, this);
|
||||||
appInfo = DialogBuilder.createInfoDialog(this);
|
appInfo = DialogBuilder.createInfoDialog(this);
|
||||||
|
|
||||||
for (Button btn : colorButtons)
|
background.setOnClickListener(this);
|
||||||
btn.setOnClickListener(this);
|
fontColor.setOnClickListener(this);
|
||||||
|
popupColor.setOnClickListener(this);
|
||||||
|
highlight.setOnClickListener(this);
|
||||||
|
cardColor.setOnClickListener(this);
|
||||||
|
iconColor.setOnClickListener(this);
|
||||||
logout.setOnClickListener(this);
|
logout.setOnClickListener(this);
|
||||||
delButton.setOnClickListener(this);
|
delButton.setOnClickListener(this);
|
||||||
toggleImg.setOnCheckedChangeListener(this);
|
toggleImg.setOnCheckedChangeListener(this);
|
||||||
@ -189,7 +193,6 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
enableAuth.setOnCheckedChangeListener(this);
|
enableAuth.setOnCheckedChangeListener(this);
|
||||||
hqImage.setOnCheckedChangeListener(this);
|
hqImage.setOnCheckedChangeListener(this);
|
||||||
fontSpinner.setOnItemSelectedListener(this);
|
fontSpinner.setOnItemSelectedListener(this);
|
||||||
locationSpinner.setOnItemSelectedListener(this);
|
|
||||||
listSizeSelector.setOnSeekBarChangeListener(this);
|
listSizeSelector.setOnSeekBarChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,37 +285,37 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set background color
|
// set background color
|
||||||
else if (v == colorButtons[0]) {
|
else if (v.getId() == R.id.color_background) {
|
||||||
mode = ColorMode.BACKGROUND;
|
mode = ColorMode.BACKGROUND;
|
||||||
color = settings.getBackgroundColor();
|
color = settings.getBackgroundColor();
|
||||||
setColor(color, false);
|
setColor(color, false);
|
||||||
}
|
}
|
||||||
// set font color
|
// set font color
|
||||||
else if (v == colorButtons[1]) {
|
else if (v.getId() == R.id.color_font) {
|
||||||
mode = ColorMode.FONTCOLOR;
|
mode = ColorMode.FONTCOLOR;
|
||||||
color = settings.getFontColor();
|
color = settings.getFontColor();
|
||||||
setColor(color, false);
|
setColor(color, false);
|
||||||
}
|
}
|
||||||
// set popup color
|
// set popup color
|
||||||
else if (v == colorButtons[2]) {
|
else if (v.getId() == R.id.color_popup) {
|
||||||
mode = ColorMode.POPUPCOLOR;
|
mode = ColorMode.POPUPCOLOR;
|
||||||
color = settings.getPopupColor();
|
color = settings.getPopupColor();
|
||||||
setColor(color, false);
|
setColor(color, false);
|
||||||
}
|
}
|
||||||
// set highlight color
|
// set highlight color
|
||||||
else if (v == colorButtons[3]) {
|
else if (v.getId() == R.id.highlight_color) {
|
||||||
mode = ColorMode.HIGHLIGHT;
|
mode = ColorMode.HIGHLIGHT;
|
||||||
color = settings.getHighlightColor();
|
color = settings.getHighlightColor();
|
||||||
setColor(color, false);
|
setColor(color, false);
|
||||||
}
|
}
|
||||||
// set card color
|
// set card color
|
||||||
else if (v == colorButtons[4]) {
|
else if (v.getId() == R.id.color_card) {
|
||||||
mode = ColorMode.CARDCOLOR;
|
mode = ColorMode.CARDCOLOR;
|
||||||
color = settings.getCardColor();
|
color = settings.getCardColor();
|
||||||
setColor(color, true);
|
setColor(color, true);
|
||||||
}
|
}
|
||||||
// set icon color
|
// set icon color
|
||||||
else if (v == colorButtons[5]) {
|
else if (v.getId() == R.id.color_icon) {
|
||||||
mode = ColorMode.ICONCOLOR;
|
mode = ColorMode.ICONCOLOR;
|
||||||
color = settings.getIconColor();
|
color = settings.getIconColor();
|
||||||
setColor(color, false);
|
setColor(color, false);
|
||||||
@ -326,14 +329,18 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BACKGROUND:
|
case BACKGROUND:
|
||||||
settings.setBackgroundColor(color);
|
settings.setBackgroundColor(color);
|
||||||
fontSpinner.setAdapter(fontSpinner.getAdapter());
|
fontAdapter.notifyDataSetChanged();
|
||||||
if (settings.isLoggedIn()) {
|
if (settings.isLoggedIn()) {
|
||||||
locationSpinner.setAdapter(fontSpinner.getAdapter());
|
locationAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FONTCOLOR:
|
case FONTCOLOR:
|
||||||
settings.setFontColor(color);
|
settings.setFontColor(color);
|
||||||
|
fontAdapter.notifyDataSetChanged();
|
||||||
|
if (settings.isLoggedIn()) {
|
||||||
|
locationAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POPUPCOLOR:
|
case POPUPCOLOR:
|
||||||
@ -361,18 +368,17 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton c, boolean checked) {
|
public void onCheckedChanged(CompoundButton c, boolean checked) {
|
||||||
int viewId = c.getId();
|
|
||||||
// toggle image loading
|
// toggle image loading
|
||||||
if (viewId == R.id.toggleImg) {
|
if (c.getId() == R.id.toggleImg) {
|
||||||
settings.setImageLoad(checked);
|
settings.setImageLoad(checked);
|
||||||
hqImage.setEnabled(checked);
|
hqImage.setEnabled(checked);
|
||||||
}
|
}
|
||||||
// toggle automatic answer load
|
// toggle automatic answer load
|
||||||
else if (viewId == R.id.toggleAns) {
|
else if (c.getId() == R.id.toggleAns) {
|
||||||
settings.setAnswerLoad(checked);
|
settings.setAnswerLoad(checked);
|
||||||
}
|
}
|
||||||
// enable proxy settings
|
// enable proxy settings
|
||||||
else if (viewId == R.id.settings_enable_proxy) {
|
else if (c.getId() == R.id.settings_enable_proxy) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
layout_proxy.setVisibility(VISIBLE);
|
layout_proxy.setVisibility(VISIBLE);
|
||||||
layout_auth_en.setVisibility(VISIBLE);
|
layout_auth_en.setVisibility(VISIBLE);
|
||||||
@ -383,7 +389,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//enable proxy authentication
|
//enable proxy authentication
|
||||||
else if (viewId == R.id.settings_enable_auth) {
|
else if (c.getId() == R.id.settings_enable_auth) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
layout_auth.setVisibility(VISIBLE);
|
layout_auth.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
@ -391,11 +397,11 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// enable high quality images
|
// enable high quality images
|
||||||
else if (viewId == R.id.settings_image_hq) {
|
else if (c.getId() == R.id.settings_image_hq) {
|
||||||
settings.setHighQualityImage(checked);
|
settings.setHighQualityImage(checked);
|
||||||
}
|
}
|
||||||
// enable custom API setup
|
// enable custom API setup
|
||||||
else if (viewId == R.id.settings_set_custom_keys) {
|
else if (c.getId() == R.id.settings_set_custom_keys) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
layout_key.setVisibility(VISIBLE);
|
layout_key.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
@ -407,11 +413,17 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (parent.getAdapter() instanceof LocationAdapter) {
|
// Trend location spinner
|
||||||
|
if (parent.getId() == R.id.spinner_woeid) {
|
||||||
settings.setTrendLocation(locationAdapter.getItem(position));
|
settings.setTrendLocation(locationAdapter.getItem(position));
|
||||||
} else if (parent.getAdapter() instanceof FontAdapter) {
|
}
|
||||||
|
// Font type spinner
|
||||||
|
else if (parent.getId() == R.id.spinner_font) {
|
||||||
settings.setFontIndex(position);
|
settings.setFontIndex(position);
|
||||||
AppStyles.setViewFont(settings, root);
|
AppStyles.setViewFont(settings, root);
|
||||||
|
if (settings.isLoggedIn()) {
|
||||||
|
locationAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,8 +465,9 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
locationAdapter.setData(data);
|
locationAdapter.setData(data);
|
||||||
int position = locationAdapter.getPosition(settings.getTrendLocation());
|
int position = locationAdapter.getPosition(settings.getTrendLocation());
|
||||||
if (position > 0) {
|
if (position > 0) {
|
||||||
locationSpinner.setSelection(position);
|
locationSpinner.setSelection(position, false);
|
||||||
}
|
}
|
||||||
|
locationSpinner.setOnItemSelectedListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -487,6 +500,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||||||
* setup all color buttons color
|
* setup all color buttons color
|
||||||
*/
|
*/
|
||||||
private void setButtonColors() {
|
private void setButtonColors() {
|
||||||
|
Button[] colorButtons = {background, fontColor, popupColor, highlight, cardColor, iconColor};
|
||||||
int[] colors = settings.getAllColors();
|
int[] colors = settings.getAllColors();
|
||||||
for (int i = 0; i < colorButtons.length; i++) {
|
for (int i = 0; i < colorButtons.length; i++) {
|
||||||
// set button color
|
// set button color
|
||||||
|
@ -85,10 +85,10 @@ public class FontAdapter extends BaseAdapter {
|
|||||||
textItem = new TextView(parent.getContext());
|
textItem = new TextView(parent.getContext());
|
||||||
textItem.setTextSize(COMPLEX_UNIT_SP, FONT_SIZE);
|
textItem.setTextSize(COMPLEX_UNIT_SP, FONT_SIZE);
|
||||||
textItem.setPadding(TEXT_PADDING, 0, TEXT_PADDING, TEXT_PADDING_BOTTOM);
|
textItem.setPadding(TEXT_PADDING, 0, TEXT_PADDING, TEXT_PADDING_BOTTOM);
|
||||||
textItem.setTextColor(settings.getFontColor());
|
|
||||||
}
|
}
|
||||||
textItem.setText(name);
|
textItem.setText(name);
|
||||||
textItem.setTypeface(font);
|
textItem.setTypeface(font);
|
||||||
|
textItem.setTextColor(settings.getFontColor());
|
||||||
textItem.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY_MASK);
|
textItem.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY_MASK);
|
||||||
return textItem;
|
return textItem;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import android.widget.ImageButton;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.ArrayRes;
|
import androidx.annotation.ArrayRes;
|
||||||
@ -121,6 +122,9 @@ public final class AppStyles {
|
|||||||
} else if (child instanceof SeekBar) {
|
} else if (child instanceof SeekBar) {
|
||||||
SeekBar seekBar = (SeekBar) child;
|
SeekBar seekBar = (SeekBar) child;
|
||||||
setSeekBarColor(settings, seekBar);
|
setSeekBarColor(settings, seekBar);
|
||||||
|
} else if (child instanceof Spinner) {
|
||||||
|
Spinner dropdown = (Spinner) child;
|
||||||
|
setDrawableColor(dropdown.getBackground(), settings.getIconColor());
|
||||||
} else if (child instanceof TextView) {
|
} else if (child instanceof TextView) {
|
||||||
TextView tv = (TextView) child;
|
TextView tv = (TextView) child;
|
||||||
tv.setTypeface(settings.getTypeFace());
|
tv.setTypeface(settings.getTypeFace());
|
||||||
|
@ -28,13 +28,4 @@
|
|||||||
<item>@drawable/follower</item>
|
<item>@drawable/follower</item>
|
||||||
</integer-array>
|
</integer-array>
|
||||||
|
|
||||||
<integer-array name="color_button">
|
|
||||||
<item>@id/color_background</item>
|
|
||||||
<item>@id/color_font</item>
|
|
||||||
<item>@id/color_popup</item>
|
|
||||||
<item>@id/highlight_color</item>
|
|
||||||
<item>@id/color_card</item>
|
|
||||||
<item>@id/color_icon</item>
|
|
||||||
</integer-array>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user