From d8d08593d8097928305b099a7e54672b72e79d3e Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Thu, 28 May 2020 11:02:55 +0200 Subject: [PATCH] code cleanup --- .../twidda/activity/MessagePopup.java | 4 +-- .../twidda/activity/TweetDetail.java | 2 +- .../twidda/activity/UserDetail.java | 34 +++++++++++-------- .../twidda/activity/UserProfile.java | 14 ++++---- .../twidda/fragment/ListFragment.java | 4 +-- app/src/main/res/layout/page_settings.xml | 2 +- app/src/main/res/values-de-rDE/strings.xml | 4 +-- app/src/main/res/values/strings.xml | 4 +-- 8 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/MessagePopup.java b/app/src/main/java/org/nuclearfog/twidda/activity/MessagePopup.java index 76ecea4d..b30c3430 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/MessagePopup.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/MessagePopup.java @@ -50,8 +50,8 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener, private MessageUploader messageAsync; private EditText receiver, message; private Dialog loadingCircle; - private @Nullable - String mediaPath; + @Nullable + private String mediaPath; @Override diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java b/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java index eb41f013..2d14c59d 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/TweetDetail.java @@ -86,7 +86,7 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, private long tweetID; @Override - protected void onCreate(Bundle b) { + protected void onCreate(@Nullable Bundle b) { super.onCreate(b); setContentView(R.layout.page_tweet); ViewPager pager = findViewById(R.id.tweet_pager); diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/UserDetail.java b/app/src/main/java/org/nuclearfog/twidda/activity/UserDetail.java index b918366f..1364ed64 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/UserDetail.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/UserDetail.java @@ -19,14 +19,12 @@ public class UserDetail extends AppCompatActivity { public static final String KEY_USERDETAIL_MODE = "userlist_mode"; public static final String KEY_USERDETAIL_ID = "userlist_owner_id"; - public static final int USERLIST_FRIENDS = 0; - public static final int USERLIST_FOLLOWER = 1; - public static final int USERLIST_RETWEETS = 2; - public static final int USERLSIT_FAVORITS = 3; - public static final int USERLIST_SUBSCRIBER = 4; - - private long id; - private int mode; + public static final int NONE = 0; + public static final int USERLIST_FRIENDS = 1; + public static final int USERLIST_FOLLOWER = 2; + public static final int USERLIST_RETWEETS = 3; + public static final int USERLIST_FAVORITS = 4; + public static final int USERLIST_SUBSCRBR = 5; @Override protected void onCreate(@Nullable Bundle b) { @@ -35,17 +33,16 @@ public class UserDetail extends AppCompatActivity { View root = findViewById(R.id.user_view); ViewPager pager = findViewById(R.id.user_pager); Toolbar toolbar = findViewById(R.id.user_toolbar); + setSupportActionBar(toolbar); + long id = 0; + int mode = NONE; Bundle param = getIntent().getExtras(); - if (param != null && param.containsKey(KEY_USERDETAIL_MODE) && param.containsKey(KEY_USERDETAIL_ID)) { + if (param != null) { mode = param.getInt(KEY_USERDETAIL_MODE); id = param.getLong(KEY_USERDETAIL_ID); } - GlobalSettings settings = GlobalSettings.getInstance(this); - root.setBackgroundColor(settings.getBackgroundColor()); - setSupportActionBar(toolbar); - switch (mode) { case USERLIST_FRIENDS: FragmentAdapter adapter; @@ -54,30 +51,37 @@ public class UserDetail extends AppCompatActivity { adapter = new FragmentAdapter(getSupportFragmentManager(), AdapterType.FRIENDS_PAGE, id, ""); pager.setAdapter(adapter); break; + case USERLIST_FOLLOWER: if (getSupportActionBar() != null) getSupportActionBar().setTitle(R.string.userlist_follower); adapter = new FragmentAdapter(getSupportFragmentManager(), AdapterType.FOLLOWER_PAGE, id, ""); pager.setAdapter(adapter); break; + case USERLIST_RETWEETS: if (getSupportActionBar() != null) getSupportActionBar().setTitle(R.string.userlist_retweet); adapter = new FragmentAdapter(getSupportFragmentManager(), AdapterType.RETWEETER_PAGE, id, ""); pager.setAdapter(adapter); break; - case USERLSIT_FAVORITS: + + case USERLIST_FAVORITS: if (getSupportActionBar() != null) getSupportActionBar().setTitle(R.string.userlist_favorite); adapter = new FragmentAdapter(getSupportFragmentManager(), AdapterType.FAVOR_PAGE, id, ""); pager.setAdapter(adapter); break; - case USERLIST_SUBSCRIBER: + + case USERLIST_SUBSCRBR: if (getSupportActionBar() != null) getSupportActionBar().setTitle(R.string.user_list_subscr); adapter = new FragmentAdapter(getSupportFragmentManager(), AdapterType.SUBSCRIBER_PAGE, id, ""); pager.setAdapter(adapter); } + + GlobalSettings settings = GlobalSettings.getInstance(this); + root.setBackgroundColor(settings.getBackgroundColor()); FontTool.setViewFontAndColor(settings, root); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java index ef47b353..65344e36 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java @@ -89,7 +89,6 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, @Nullable private TwitterUser user; private long userId; - private boolean isHome; private int tabIndex = 0; @@ -119,9 +118,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, settings = GlobalSettings.getInstance(this); Bundle param = getIntent().getExtras(); - if (param != null && param.containsKey(KEY_PROFILE_ID)) { + if (param != null) { userId = param.getLong(KEY_PROFILE_ID); - isHome = userId == settings.getUserId(); } setSupportActionBar(tool); @@ -200,7 +198,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, @Override public boolean onCreateOptionsMenu(Menu m) { getMenuInflater().inflate(R.menu.profile, m); - if (isHome) { + if (userId == settings.getUserId()) { MenuItem dmIcon = m.findItem(R.id.profile_message); MenuItem setting = m.findItem(R.id.profile_settings); dmIcon.setVisible(true); @@ -225,7 +223,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, followIcon.setIcon(R.drawable.follow_requested); followIcon.setTitle(R.string.follow_requested); } - if (user.isLocked() && !isHome) { + if (user.isLocked() && userId != settings.getUserId()) { MenuItem listItem = m.findItem(R.id.profile_lists); listItem.setVisible(false); } @@ -266,7 +264,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, case R.id.profile_tweet: if (user != null) { Intent tweet = new Intent(this, TweetPopup.class); - if (!isHome) + if (userId != settings.getUserId()) tweet.putExtra(KEY_TWEETPOPUP_PREFIX, user.getScreenname()); startActivity(tweet); } @@ -394,7 +392,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, switch (v.getId()) { case R.id.following: if (user != null && properties != null) { - if (!user.isLocked() || properties.isFriend() || isHome) { + if (!user.isLocked() || properties.isFriend() || userId == settings.getUserId()) { Intent following = new Intent(this, UserDetail.class); following.putExtra(KEY_USERDETAIL_ID, userId); following.putExtra(KEY_USERDETAIL_MODE, USERLIST_FRIENDS); @@ -405,7 +403,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, case R.id.follower: if (user != null && properties != null) { - if (!user.isLocked() || properties.isFriend() || isHome) { + if (!user.isLocked() || properties.isFriend() || userId == settings.getUserId()) { Intent follower = new Intent(this, UserDetail.class); follower.putExtra(KEY_USERDETAIL_ID, userId); follower.putExtra(KEY_USERDETAIL_MODE, USERLIST_FOLLOWER); diff --git a/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java b/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java index 94c5e800..cb85bb5d 100644 --- a/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java @@ -37,7 +37,7 @@ import static org.nuclearfog.twidda.activity.ListDetail.KEY_LISTDETAIL_ID; import static org.nuclearfog.twidda.activity.ListDetail.KEY_LISTDETAIL_NAME; import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_ID; import static org.nuclearfog.twidda.activity.UserDetail.KEY_USERDETAIL_MODE; -import static org.nuclearfog.twidda.activity.UserDetail.USERLIST_SUBSCRIBER; +import static org.nuclearfog.twidda.activity.UserDetail.USERLIST_SUBSCRBR; import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID; import static org.nuclearfog.twidda.backend.TwitterListLoader.Action.DELETE; import static org.nuclearfog.twidda.backend.TwitterListLoader.Action.FOLLOW; @@ -134,7 +134,7 @@ public class ListFragment extends Fragment implements OnRefreshListener, ListCli case SUBSCRIBER: Intent following = new Intent(getContext(), UserDetail.class); following.putExtra(KEY_USERDETAIL_ID, listItem.getId()); - following.putExtra(KEY_USERDETAIL_MODE, USERLIST_SUBSCRIBER); + following.putExtra(KEY_USERDETAIL_MODE, USERLIST_SUBSCRBR); startActivity(following); break; diff --git a/app/src/main/res/layout/page_settings.xml b/app/src/main/res/layout/page_settings.xml index 71094ae8..6c62ceea 100644 --- a/app/src/main/res/layout/page_settings.xml +++ b/app/src/main/res/layout/page_settings.xml @@ -234,7 +234,7 @@ android:layout_weight="1" android:background="@drawable/button" android:singleLine="true" - android:text="@string/delete_database" /> + android:text="@string/settings_clear_data" />