mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-02 20:26:53 +01:00
instant storing of settings
code cleanup
This commit is contained in:
parent
8982202031
commit
c527a9cb06
@ -42,6 +42,7 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
TimelineAdapter.OnItemClicked, TrendAdapter.OnItemClicked {
|
||||
|
||||
private static final int LOGIN = 1;
|
||||
private static final int SETTING = 2;
|
||||
|
||||
private SwipeRefreshLayout timelineReload, trendReload, mentionReload;
|
||||
private RecyclerView timelineList, trendList, mentionList;
|
||||
@ -52,7 +53,6 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
private View lastTab, root;
|
||||
private TabHost tabhost;
|
||||
private int tabIndex = 0;
|
||||
private boolean settingChanged = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -110,13 +110,12 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
if (!settings.getLogin()) {
|
||||
Intent i = new Intent(this, LoginPage.class);
|
||||
startActivityForResult(i, LOGIN);
|
||||
} else if (home == null || settingChanged) {
|
||||
root.setBackgroundColor(settings.getBackgroundColor());
|
||||
|
||||
} else if (home == null) {
|
||||
timelineAdapter = new TimelineAdapter(this);
|
||||
trendsAdapter = new TrendAdapter(this);
|
||||
mentionAdapter = new TimelineAdapter(this);
|
||||
|
||||
root.setBackgroundColor(settings.getBackgroundColor());
|
||||
timelineAdapter.setColor(settings.getHighlightColor(), settings.getFontColor());
|
||||
timelineAdapter.toggleImage(settings.loadImages());
|
||||
trendsAdapter.setColor(settings.getFontColor());
|
||||
@ -129,8 +128,6 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
|
||||
home = new MainPage(this);
|
||||
home.execute(MainPage.DATA, 1);
|
||||
|
||||
settingChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,6 +150,8 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
if (reqCode == LOGIN && returnCode == RESULT_CANCELED) {
|
||||
overridePendingTransition(0, 0);
|
||||
finish();
|
||||
} else if (reqCode == SETTING) {
|
||||
home = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,7 +222,6 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
long homeId = settings.getUserId();
|
||||
Intent user = new Intent(this, UserProfile.class);
|
||||
user.putExtra("userID", homeId);
|
||||
user.putExtra("username", "");
|
||||
startActivity(user);
|
||||
break;
|
||||
|
||||
@ -233,9 +231,8 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
break;
|
||||
|
||||
case R.id.action_settings:
|
||||
settingChanged = true;
|
||||
Intent settings = new Intent(this, AppSettings.class);
|
||||
startActivity(settings);
|
||||
startActivityForResult(settings, SETTING);
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
@ -281,8 +278,8 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
|
||||
@Override
|
||||
public void onItemClick(ViewGroup parent, int position) {
|
||||
if (parent.getId() == R.id.tl_list && !timelineReload.isRefreshing()) {
|
||||
if (timelineAdapter != null) {
|
||||
if (parent.getId() == R.id.tl_list) {
|
||||
if (timelineAdapter != null && !timelineReload.isRefreshing()) {
|
||||
Tweet tweet = timelineAdapter.getData().get(position);
|
||||
if (tweet.embedded != null)
|
||||
tweet = tweet.embedded;
|
||||
@ -292,8 +289,8 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
intent.putExtra("username", tweet.user.screenname);
|
||||
startActivity(intent);
|
||||
}
|
||||
} else if (parent.getId() == R.id.tr_list && !trendReload.isRefreshing()) {
|
||||
if (trendsAdapter != null) {
|
||||
} else if (parent.getId() == R.id.tr_list) {
|
||||
if (trendsAdapter != null && !trendReload.isRefreshing()) {
|
||||
String search = trendsAdapter.getData().get(position).trend;
|
||||
Intent intent = new Intent(this, SearchPage.class);
|
||||
if (!search.startsWith("#"))
|
||||
@ -301,8 +298,8 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
|
||||
intent.putExtra("search", search);
|
||||
startActivity(intent);
|
||||
}
|
||||
} else if (parent.getId() == R.id.m_list && !mentionReload.isRefreshing()) {
|
||||
if (mentionAdapter != null) {
|
||||
} else if (parent.getId() == R.id.m_list) {
|
||||
if (mentionAdapter != null && !mentionReload.isRefreshing()) {
|
||||
Tweet tweet = mentionAdapter.getData().get(position);
|
||||
if (tweet.embedded != null)
|
||||
tweet = tweet.embedded;
|
||||
|
@ -6,18 +6,16 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog.Builder;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.NumberPicker;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.flask.colorpicker.ColorPickerView;
|
||||
import com.flask.colorpicker.OnColorChangedListener;
|
||||
@ -34,19 +32,15 @@ import org.nuclearfog.twidda.viewadapter.WorldIdAdapter;
|
||||
* @see GlobalSettings
|
||||
*/
|
||||
public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
OnColorChangedListener, OnItemSelectedListener {
|
||||
OnColorChangedListener, OnItemSelectedListener,
|
||||
CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
private GlobalSettings settings;
|
||||
private CheckBox toggleImg;
|
||||
private Button colorButton1, colorButton2, colorButton3, colorButton4;
|
||||
private Spinner woeId;
|
||||
private CheckBox toggleImg;
|
||||
private EditText woeIdText;
|
||||
private Spinner woeId;
|
||||
private View root;
|
||||
private int background, tweet, font, highlight;
|
||||
private long wId;
|
||||
private int row;
|
||||
private int woeIdPos;
|
||||
private boolean customWoeId;
|
||||
private int mode = 0;
|
||||
|
||||
|
||||
@ -54,6 +48,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
protected void onCreate(Bundle savedInst) {
|
||||
super.onCreate(savedInst);
|
||||
setContentView(R.layout.page_settings);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar_setting);
|
||||
setSupportActionBar(toolbar);
|
||||
if (getSupportActionBar() != null)
|
||||
@ -77,6 +72,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
load_popup.setOnClickListener(this);
|
||||
delButton.setOnClickListener(this);
|
||||
logout.setOnClickListener(this);
|
||||
toggleImg.setOnCheckedChangeListener(this);
|
||||
colorButton1.setOnClickListener(this);
|
||||
colorButton2.setOnClickListener(this);
|
||||
colorButton3.setOnClickListener(this);
|
||||
@ -88,24 +84,16 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
background = settings.getBackgroundColor();
|
||||
font = settings.getFontColor();
|
||||
tweet = settings.getTweetColor();
|
||||
highlight = settings.getHighlightColor();
|
||||
row = settings.getRowLimit();
|
||||
wId = settings.getWoeId();
|
||||
toggleImg.setChecked(settings.loadImages());
|
||||
woeIdPos = settings.getWoeIdSelection();
|
||||
customWoeId = settings.customWoeIdset();
|
||||
woeId.setAdapter(new WorldIdAdapter(this));
|
||||
woeId.setSelection(settings.getWoeIdSelection());
|
||||
colorButton1.setBackgroundColor(settings.getBackgroundColor());
|
||||
colorButton2.setBackgroundColor(settings.getFontColor());
|
||||
colorButton3.setBackgroundColor(settings.getTweetColor());
|
||||
colorButton4.setBackgroundColor(settings.getHighlightColor());
|
||||
|
||||
woeId.setSelection(woeIdPos);
|
||||
colorButton1.setBackgroundColor(background);
|
||||
colorButton2.setBackgroundColor(font);
|
||||
colorButton3.setBackgroundColor(tweet);
|
||||
colorButton4.setBackgroundColor(highlight);
|
||||
if (customWoeId) {
|
||||
String text = Long.toString(wId);
|
||||
if (settings.customWoeIdset()) {
|
||||
String text = Long.toString(settings.getWoeId());
|
||||
woeIdText.setVisibility(View.VISIBLE);
|
||||
woeIdText.setText(text);
|
||||
}
|
||||
@ -113,36 +101,15 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu m) {
|
||||
getMenuInflater().inflate(R.menu.setting, m);
|
||||
return super.onCreateOptionsMenu(m);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.back_settings:
|
||||
finish();
|
||||
break;
|
||||
|
||||
case R.id.save_settings:
|
||||
settings.setBackgroundColor(background);
|
||||
settings.setHighlightColor(highlight);
|
||||
settings.setTweetColor(tweet);
|
||||
settings.setFontColor(font);
|
||||
settings.setImageLoad(toggleImg.isChecked());
|
||||
settings.setRowLimit(row);
|
||||
settings.setWoeIdSelection(woeIdPos);
|
||||
settings.setCustomWoeId(customWoeId);
|
||||
String woeText = woeIdText.getText().toString();
|
||||
if (customWoeId && !woeText.isEmpty())
|
||||
wId = Long.parseLong(woeText);
|
||||
settings.setWoeId(wId);
|
||||
Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
public void onBackPressed() {
|
||||
if (settings.customWoeIdset()) {
|
||||
String woeText = woeIdText.getText().toString();
|
||||
if (!woeText.isEmpty())
|
||||
settings.setWoeId(Long.parseLong(woeText));
|
||||
else
|
||||
settings.setWoeId(1);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
|
||||
@ -179,22 +146,22 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
break;
|
||||
|
||||
case R.id.color_background:
|
||||
setColor(background);
|
||||
setColor(settings.getBackgroundColor());
|
||||
mode = 0;
|
||||
break;
|
||||
|
||||
case R.id.color_font:
|
||||
setColor(font);
|
||||
setColor(settings.getFontColor());
|
||||
mode = 1;
|
||||
break;
|
||||
|
||||
case R.id.color_tweet:
|
||||
setColor(tweet);
|
||||
setColor(settings.getTweetColor());
|
||||
mode = 2;
|
||||
break;
|
||||
|
||||
case R.id.highlight_color:
|
||||
setColor(highlight);
|
||||
setColor(settings.getHighlightColor());
|
||||
mode = 3;
|
||||
break;
|
||||
|
||||
@ -203,13 +170,15 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
final NumberPicker load = new NumberPicker(this);
|
||||
load.setMaxValue(100);
|
||||
load.setMinValue(10);
|
||||
load.setValue(row);
|
||||
load.setValue(settings.getRowLimit());
|
||||
load.setWrapSelectorWheel(false);
|
||||
load_popup.setContentView(load);
|
||||
load_popup.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
row = load.getValue();
|
||||
if (settings.getRowLimit() != load.getValue()) {
|
||||
settings.setRowLimit(load.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
load_popup.show();
|
||||
@ -222,16 +191,21 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
public void onColorChanged(int color) {
|
||||
switch (mode) {
|
||||
case 0:
|
||||
background = color;
|
||||
root.setBackgroundColor(color);
|
||||
settings.setBackgroundColor(color);
|
||||
colorButton1.setBackgroundColor(color);
|
||||
break;
|
||||
case 1:
|
||||
font = color;
|
||||
settings.setFontColor(color);
|
||||
colorButton2.setBackgroundColor(color);
|
||||
break;
|
||||
case 2:
|
||||
tweet = color;
|
||||
settings.setTweetColor(color);
|
||||
colorButton3.setBackgroundColor(color);
|
||||
break;
|
||||
case 3:
|
||||
highlight = color;
|
||||
settings.setHighlightColor(color);
|
||||
colorButton4.setBackgroundColor(color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -241,39 +215,35 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position == parent.getCount() - 1) {
|
||||
woeIdText.setVisibility(View.VISIBLE);
|
||||
customWoeId = true;
|
||||
wId = 1;
|
||||
settings.setCustomWoeId(true);
|
||||
settings.setWoeId(1);
|
||||
} else {
|
||||
woeIdText.setVisibility(View.INVISIBLE);
|
||||
woeIdText.setText("");
|
||||
customWoeId = false;
|
||||
wId = id;
|
||||
settings.setCustomWoeId(false);
|
||||
settings.setWoeId(id);
|
||||
}
|
||||
woeIdPos = position;
|
||||
settings.setWoeIdSelection(position);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
woeId.setSelection(woeIdPos);
|
||||
woeId.setSelection(settings.getWoeIdSelection());
|
||||
}
|
||||
|
||||
|
||||
public void setColor(int preColor) {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton c, boolean checked) {
|
||||
settings.setImageLoad(checked);
|
||||
}
|
||||
|
||||
|
||||
private void setColor(int preColor) {
|
||||
Dialog d = ColorPickerDialogBuilder.with(this)
|
||||
.showAlphaSlider(false).initialColor(preColor)
|
||||
.wheelType(ColorPickerView.WHEEL_TYPE.CIRCLE).density(20)
|
||||
.setOnColorChangedListener(this).build();
|
||||
d.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
colorButton1.setBackgroundColor(background);
|
||||
colorButton2.setBackgroundColor(font);
|
||||
colorButton3.setBackgroundColor(tweet);
|
||||
colorButton4.setBackgroundColor(highlight);
|
||||
root.setBackgroundColor(background);
|
||||
}
|
||||
});
|
||||
d.show();
|
||||
}
|
||||
}
|
@ -56,7 +56,8 @@ public class UserProfile extends AppCompatActivity implements
|
||||
b = getIntent().getExtras();
|
||||
if (b != null) {
|
||||
userId = b.getLong("userID");
|
||||
username = b.getString("username");
|
||||
if (b.containsKey("username"))
|
||||
username = b.getString("username");
|
||||
}
|
||||
|
||||
Toolbar tool = findViewById(R.id.profile_toolbar);
|
||||
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/save_settings"
|
||||
android:icon="@drawable/save"
|
||||
android:title="@string/save"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/back_settings"
|
||||
android:checkable="false"
|
||||
android:icon="@drawable/right"
|
||||
android:title="@string/back"
|
||||
android:visible="true"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
Loading…
x
Reference in New Issue
Block a user