code cleanup, rearrange

bug fix
This commit is contained in:
NudeDude 2019-03-02 11:21:00 +01:00
parent 47b1fd1762
commit bebb53b601
7 changed files with 117 additions and 61 deletions

View File

@ -143,12 +143,7 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
home = new MainPage(this);
home.execute(MainPage.DATA, 1);
if (tabIndex == 0)
tlUnderline.setBackgroundColor(settings.getHighlightColor());
else if (tabIndex == 1)
trUnderline.setBackgroundColor(settings.getHighlightColor());
else
mnUnderline.setBackgroundColor(settings.getHighlightColor());
setIndicator();
Uri link = getIntent().getData();
if (link != null) {
@ -314,6 +309,46 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
animate();
tabIndex = tabhost.getCurrentTab();
invalidateOptionsMenu();
setIndicator();
}
@Override
public void onItemClick(RecyclerView parent, int position) {
switch (parent.getId()) {
case R.id.tl_list:
if (timelineAdapter != null && !timelineReload.isRefreshing()) {
Tweet tweet = timelineAdapter.getData().get(position);
if (tweet.getEmbeddedTweet() != null)
tweet = tweet.getEmbeddedTweet();
openTweet(tweet.getId(), tweet.getUser().getId(), tweet.getUser().getScreenname());
}
break;
case R.id.tr_list:
if (trendsAdapter != null && !trendReload.isRefreshing()) {
String search = trendsAdapter.getData().get(position).getName();
Intent intent = new Intent(this, SearchPage.class);
if (!search.startsWith("#"))
search = '\"' + search + '\"';
intent.putExtra("search", search);
startActivity(intent);
}
break;
case R.id.m_list:
if (mentionAdapter != null && !mentionReload.isRefreshing()) {
Tweet tweet = mentionAdapter.getData().get(position);
if (tweet.getEmbeddedTweet() != null)
tweet = tweet.getEmbeddedTweet();
openTweet(tweet.getId(), tweet.getUser().getId(), tweet.getUser().getScreenname());
}
break;
}
}
private void setIndicator() {
switch (tabIndex) {
case 0:
tlUnderline.setBackgroundColor(settings.getHighlightColor());
@ -336,35 +371,6 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
}
@Override
public void onItemClick(RecyclerView parent, int position) {
if (parent.getId() == R.id.tl_list) {
if (timelineAdapter != null && !timelineReload.isRefreshing()) {
Tweet tweet = timelineAdapter.getData().get(position);
if (tweet.getEmbeddedTweet() != null)
tweet = tweet.getEmbeddedTweet();
openTweet(tweet.getId(), tweet.getUser().getId(), tweet.getUser().getScreenname());
}
} else if (parent.getId() == R.id.tr_list) {
if (trendsAdapter != null && !trendReload.isRefreshing()) {
String search = trendsAdapter.getData().get(position).getName();
Intent intent = new Intent(this, SearchPage.class);
if (!search.startsWith("#"))
search = '\"' + search + '\"';
intent.putExtra("search", search);
startActivity(intent);
}
} else if (parent.getId() == R.id.m_list) {
if (mentionAdapter != null && !mentionReload.isRefreshing()) {
Tweet tweet = mentionAdapter.getData().get(position);
if (tweet.getEmbeddedTweet() != null)
tweet = tweet.getEmbeddedTweet();
openTweet(tweet.getId(), tweet.getUser().getId(), tweet.getUser().getScreenname());
}
}
}
private void openTweet(long tweetId, long userId, String username) {
Intent intent = new Intent(this, TweetDetail.class);
intent.putExtra("tweetID", tweetId);

View File

@ -296,6 +296,7 @@ public class TwitterEngine {
/**
* Follow Twitter user
*
* @param userID User ID
* @return Twitter User
* @throws TwitterException if Access is unavailable
@ -307,6 +308,7 @@ public class TwitterEngine {
/**
* Unfollow Twitter user
*
* @param userID User ID
* @return Twitter User
* @throws TwitterException if Access is unavailable
@ -354,6 +356,7 @@ public class TwitterEngine {
/**
* Unmute Twitter user
*
* @param UserID User ID
* @return Twitter User
* @throws TwitterException if Access is unavailable

View File

@ -66,6 +66,7 @@ public class GlobalSettings {
/**
* Get get background color
*
* @return color value
*/
public int getBackgroundColor() {
@ -74,6 +75,7 @@ public class GlobalSettings {
/**
* Set background color
*
* @param color background color value
*/
public void setBackgroundColor(int color) {
@ -85,6 +87,7 @@ public class GlobalSettings {
/**
* get font color
*
* @return font color value
*/
public int getFontColor() {
@ -93,6 +96,7 @@ public class GlobalSettings {
/**
* set font color
*
* @param color font color value
*/
public void setFontColor(int color) {
@ -104,6 +108,7 @@ public class GlobalSettings {
/**
* get highlight color
*
* @return highlight color value
*/
public int getHighlightColor() {
@ -112,6 +117,7 @@ public class GlobalSettings {
/**
* set highlight color
*
* @param color highlight color value
*/
public void setHighlightColor(int color) {
@ -123,17 +129,19 @@ public class GlobalSettings {
/**
* get message window color
*
* @return color value
*/
public int getTweetColor() {
public int getPopupColor() {
return tweet_color;
}
/**
* set message window color
*
* @param color color value
*/
public void setTweetColor(int color) {
public void setPopupColor(int color) {
tweet_color = color;
Editor edit = settings.edit();
edit.putInt("tweet_color", color);
@ -142,6 +150,7 @@ public class GlobalSettings {
/**
* image loading enabled
*
* @return true if enabled
*/
public boolean getImageLoad() {
@ -150,6 +159,7 @@ public class GlobalSettings {
/**
* enable/disable image load
*
* @param image true if enabled
*/
public void setImageLoad(boolean image) {
@ -161,6 +171,7 @@ public class GlobalSettings {
/**
* answer loading enabled
*
* @return if answer loading is enabled
*/
public boolean getAnswerLoad() {
@ -169,6 +180,7 @@ public class GlobalSettings {
/**
* enable/disable answer loading
*
* @param loadAnswer true if enabled
*/
public void setAnswerLoad(boolean loadAnswer) {
@ -180,6 +192,7 @@ public class GlobalSettings {
/**
* get World ID for trends
*
* @return World ID
*/
public int getWoeId() {
@ -188,6 +201,7 @@ public class GlobalSettings {
/**
* set World ID for trends
*
* @param id World ID
*/
public void setWoeId(long id) {
@ -199,6 +213,7 @@ public class GlobalSettings {
/**
* return position of the world id dropdown list
*
* @return position
*/
public int getWoeIdSelection() {
@ -207,6 +222,7 @@ public class GlobalSettings {
/**
* set last position of the dropdown list
*
* @param pos position of the last selection
*/
public void setWoeIdSelection(int pos) {
@ -218,6 +234,7 @@ public class GlobalSettings {
/**
* Check if custom World ID is set
*
* @return if custom world ID is set
*/
public boolean getCustomWidSet() {
@ -226,6 +243,7 @@ public class GlobalSettings {
/**
* Set custom World ID
*
* @param customWoeId true if Custom world ID is set
*/
public void setCustomWidSet(boolean customWoeId) {
@ -237,6 +255,7 @@ public class GlobalSettings {
/**
* get loading limit of tweets/users
*
* @return max numbers of tweets/users should be loaded
*/
public int getRowLimit() {
@ -245,6 +264,7 @@ public class GlobalSettings {
/**
* set limit of tweets/users
*
* @param limit max numbers of tweets/users
*/
public void setRowLimit(int limit) {
@ -256,6 +276,7 @@ public class GlobalSettings {
/**
* Check if current user is logged in
*
* @return true if current user is logged in
*/
public boolean getLogin() {
@ -264,6 +285,7 @@ public class GlobalSettings {
/**
* get Access tokens
*
* @return access tokens
*/
public String[] getKeys() {
@ -275,6 +297,7 @@ public class GlobalSettings {
/**
* get current users ID
*
* @return User ID
*/
public long getUserId() {
@ -283,6 +306,7 @@ public class GlobalSettings {
/**
* get Datetime Formatter for the current location
*
* @return Datetime Formatter
*/
public SimpleDateFormat getDateFormatter() {
@ -291,8 +315,9 @@ public class GlobalSettings {
/**
* Set Access tokens and user ID
* @param key1 1st access token
* @param key2 2nd access token
*
* @param key1 1st access token
* @param key2 2nd access token
* @param userId User ID
*/
public void setConnection(String key1, String key2, Long userId) {

View File

@ -2,6 +2,7 @@ package org.nuclearfog.twidda.window;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.app.AppCompatActivity;
@ -33,7 +34,12 @@ import org.nuclearfog.twidda.database.GlobalSettings;
* @see GlobalSettings
*/
public class AppSettings extends AppCompatActivity implements OnClickListener,
OnColorChangedListener, OnItemSelectedListener, OnCheckedChangeListener {
OnDismissListener, OnItemSelectedListener, OnCheckedChangeListener {
private static final int BACKGROUND = 0;
private static final int FONTCOLOR = 1;
private static final int HIGHLIGHT = 2;
private static final int POPUPCOLOR = 3;
private GlobalSettings settings;
private Button colorButton1, colorButton2, colorButton3, colorButton4;
@ -41,6 +47,8 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
private EditText woeIdText;
private Spinner woeId;
private View root;
private int color = 0;
private int mode = 0;
@Override
@ -60,7 +68,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
Button logout = findViewById(R.id.logout);
colorButton1 = findViewById(R.id.color_background);
colorButton2 = findViewById(R.id.color_font);
colorButton3 = findViewById(R.id.color_tweet);
colorButton3 = findViewById(R.id.color_popup);
colorButton4 = findViewById(R.id.highlight_color);
toggleImg = findViewById(R.id.toggleImg);
toggleAns = findViewById(R.id.toggleAns);
@ -89,7 +97,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
woeId.setSelection(settings.getWoeIdSelection());
colorButton1.setBackgroundColor(settings.getBackgroundColor());
colorButton2.setBackgroundColor(settings.getFontColor());
colorButton3.setBackgroundColor(settings.getTweetColor());
colorButton3.setBackgroundColor(settings.getPopupColor());
colorButton4.setBackgroundColor(settings.getHighlightColor());
if (settings.getCustomWidSet()) {
String text = Long.toString(settings.getWoeId());
@ -147,23 +155,27 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
break;
case R.id.color_background:
setColor(settings.getBackgroundColor());
mode = 0;
mode = BACKGROUND;
color = settings.getBackgroundColor();
setColor(color);
break;
case R.id.color_font:
setColor(settings.getFontColor());
mode = 1;
mode = FONTCOLOR;
color = settings.getFontColor();
setColor(color);
break;
case R.id.color_tweet:
setColor(settings.getTweetColor());
mode = 2;
case R.id.color_popup:
mode = POPUPCOLOR;
color = settings.getPopupColor();
setColor(color);
break;
case R.id.highlight_color:
setColor(settings.getHighlightColor());
mode = 3;
mode = HIGHLIGHT;
color = settings.getHighlightColor();
setColor(color);
break;
case R.id.load_dialog:
@ -189,22 +201,25 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
@Override
public void onColorChanged(int color) {
public void onDismiss(DialogInterface d) {
switch (mode) {
case 0:
case BACKGROUND:
root.setBackgroundColor(color);
settings.setBackgroundColor(color);
colorButton1.setBackgroundColor(color);
break;
case 1:
case FONTCOLOR:
settings.setFontColor(color);
colorButton2.setBackgroundColor(color);
break;
case 2:
settings.setTweetColor(color);
case POPUPCOLOR:
settings.setPopupColor(color);
colorButton3.setBackgroundColor(color);
break;
case 3:
case HIGHLIGHT:
settings.setHighlightColor(color);
colorButton4.setBackgroundColor(color);
break;
@ -240,6 +255,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
case R.id.toggleImg:
settings.setImageLoad(checked);
break;
case R.id.toggleAns:
settings.setAnswerLoad(checked);
break;
@ -251,7 +267,13 @@ public class AppSettings extends AppCompatActivity implements OnClickListener,
Dialog d = ColorPickerDialogBuilder.with(this)
.showAlphaSlider(false).initialColor(preColor)
.wheelType(ColorPickerView.WHEEL_TYPE.CIRCLE).density(20)
.setOnColorChangedListener(this).build();
.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int i) {
color = i;
}
}).build();
d.setOnDismissListener(this);
d.show();
}
}

View File

@ -50,7 +50,7 @@ public class MessagePopup extends AppCompatActivity implements View.OnClickListe
text = findViewById(R.id.dm_text);
GlobalSettings settings = GlobalSettings.getInstance(this);
root.setBackgroundColor(settings.getTweetColor());
root.setBackgroundColor(settings.getPopupColor());
receiver.append(username);
send.setOnClickListener(this);

View File

@ -69,7 +69,7 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener {
imgCount = findViewById(R.id.imgcount);
GlobalSettings settings = GlobalSettings.getInstance(this);
root.setBackgroundColor(settings.getTweetColor());
root.setBackgroundColor(settings.getPopupColor());
tweet.append(addition);
closeButton.setOnClickListener(this);

View File

@ -69,7 +69,7 @@
android:orientation="horizontal">
<Button
android:id="@+id/color_tweet"
android:id="@+id/color_popup"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="@dimen/settings_button"