diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java index 5ccf8898..4f4b9e5a 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java @@ -34,10 +34,11 @@ public class ProfileLoader extends AsyncTask { public static final long ACTION_FOLLOW = 1; // Folgen/Entfolgen public static final long GET_TWEETS = 2; // Tweets Laden public static final long GET_FAVS = 3; // Favoriten Laden - public static final long ACTION_MUTE = 4; - public static final long LOAD_DB = 5; - private static final long FAILURE = 6; - private static final long IGNORE = 7; + public static final long ACTION_BLOCK = 4; + public static final long ACTION_MUTE = 5; + public static final long LOAD_DB = 6; + private static final long FAILURE = 7; + private static final long IGNORE = 8; private String screenName, username, description, location, follower, following; private String profileImage, link, dateString; @@ -54,7 +55,8 @@ public class ProfileLoader extends AsyncTask { private boolean isFollowed = false; private boolean isVerified = false; private boolean isLocked = false; - private boolean blocked = false; + private boolean isBlocked = false; + private boolean isMuted = false; private String errMsg = "E: Profile Load, "; private int returnCode = 0; @@ -100,12 +102,13 @@ public class ProfileLoader extends AsyncTask { long id = 1L; try { isHome = homeId == userId; - if(!isHome && (MODE==ACTION_FOLLOW||MODE==ACTION_MUTE||MODE==GET_INFORMATION)) + if (!isHome && (MODE == ACTION_FOLLOW || MODE == ACTION_BLOCK || MODE == ACTION_MUTE || MODE == GET_INFORMATION)) { boolean connection[] = mTwitter.getConnection(userId); isFollowing = connection[0]; isFollowed = connection[1]; - blocked = connection[2]; + isBlocked = connection[2]; + isMuted = connection[3]; } TwitterUser user; @@ -168,23 +171,16 @@ public class ProfileLoader extends AsyncTask { } else if(MODE == ACTION_FOLLOW) { - if(isFollowing) { - mTwitter.followAction(userId,false); - isFollowing = false; - } else { - mTwitter.followAction(userId,true); - isFollowing = true; - } + isFollowing = !isFollowing; + mTwitter.followAction(userId, isFollowing); + } else if (MODE == ACTION_BLOCK) { + isBlocked = !isBlocked; + mTwitter.blockAction(userId, isBlocked); } else if(MODE == ACTION_MUTE) { - if(blocked) { - mTwitter.blockAction(userId,false); - blocked = false; - } else { - mTwitter.blockAction(userId,true); - blocked = true; - } + isMuted = !isMuted; + mTwitter.muteAction(userId, isMuted); } } catch (TwitterException err) { returnCode = err.getErrorCode(); @@ -273,18 +269,22 @@ public class ProfileLoader extends AsyncTask { textId = R.string.followed; else textId = R.string.unfollowed; - Toast.makeText(ui.get(), textId, Toast.LENGTH_SHORT).show(); - } - else if(mode == ACTION_MUTE) { + Toast.makeText(connect, textId, Toast.LENGTH_SHORT).show(); + } else if (mode == ACTION_BLOCK) { int textId; - if(blocked) + if (isBlocked) textId = R.string.blocked; else textId = R.string.unblocked; + Toast.makeText(connect, textId, Toast.LENGTH_SHORT).show(); + } else if (mode == ACTION_MUTE) { + int textId; + if (isMuted) + textId = R.string.muted; + else + textId = R.string.unmuted; Toast.makeText(ui.get(), textId, Toast.LENGTH_SHORT).show(); - } - else if(mode == FAILURE) - { + } else if(mode == FAILURE) { SwipeRefreshLayout tweetsReload = connect.findViewById(R.id.hometweets); SwipeRefreshLayout favoriteReload = connect.findViewById(R.id.homefavorits); tweetsReload.setRefreshing(false); @@ -296,11 +296,12 @@ public class ProfileLoader extends AsyncTask { Toast.makeText(connect, errMsg, Toast.LENGTH_LONG).show(); } } - if(!isHome && (mode==ACTION_FOLLOW||mode==ACTION_MUTE||mode==GET_INFORMATION)) { + if (!isHome && (mode == ACTION_FOLLOW || mode == ACTION_BLOCK || mode == ACTION_MUTE || mode == GET_INFORMATION)) { Toolbar tool = connect.findViewById(R.id.profile_toolbar); if(tool.getMenu().size() >= 2) { MenuItem followIcon = tool.getMenu().getItem(1); MenuItem blockIcon = tool.getMenu().getItem(2); + MenuItem muteIcon = tool.getMenu().getItem(3); if (isFollowing) { followIcon.setIcon(R.drawable.follow_enabled); followIcon.setTitle(R.string.unfollow); @@ -308,15 +309,18 @@ public class ProfileLoader extends AsyncTask { followIcon.setIcon(R.drawable.follow); followIcon.setTitle(R.string.follow); } - if (blocked) { - blockIcon.setIcon(R.drawable.block_enabled); + if (isBlocked) { blockIcon.setTitle(R.string.unblock); followIcon.setVisible(false); } else { - blockIcon.setIcon(R.drawable.block); blockIcon.setTitle(R.string.block); followIcon.setVisible(true); } + if (isMuted) { + muteIcon.setTitle(R.string.unmute); + } else { + muteIcon.setTitle(R.string.mute); + } } } } diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java b/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java index 43db2b32..f03a784d 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java @@ -269,10 +269,11 @@ public class TwitterEngine { */ public boolean[] getConnection(long id) throws TwitterException { Relationship connect = twitter.showFriendship(twitterID, id); - boolean connection[] = new boolean[3]; + boolean connection[] = new boolean[4]; connection[0] = connect.isSourceFollowingTarget(); connection[1] = connect.isTargetFollowingSource(); connection[2] = connect.isSourceBlockingTarget(); + connection[3] = connect.isSourceMutingTarget(); return connection; } @@ -306,6 +307,21 @@ public class TwitterEngine { } } + /** + * Switch muting User + * + * @param userId User ID + * @param action using action + * @throws TwitterException if Access is unavailable + */ + public void muteAction(long userId, boolean action) throws TwitterException { + if (action) { + twitter.createMute(userId); + } else { + twitter.destroyMute(userId); + } + } + /** * get Following User List * diff --git a/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java b/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java index b3c4ad37..9061b1fa 100644 --- a/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java +++ b/app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java @@ -121,6 +121,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, if(!home) { m.findItem(R.id.profile_follow).setVisible(true); m.findItem(R.id.profile_block).setVisible(true); + m.findItem(R.id.profile_mute).setVisible(true); } return true; } @@ -141,6 +142,10 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, return true; case R.id.profile_block: + mProfile.execute(userId, ProfileLoader.ACTION_BLOCK); + return true; + + case R.id.profile_mute: mProfile.execute(userId, ProfileLoader.ACTION_MUTE); return true; diff --git a/app/src/main/res/drawable/block.xml b/app/src/main/res/drawable/block.xml deleted file mode 100644 index d2dc9825..00000000 --- a/app/src/main/res/drawable/block.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/block_enabled.xml b/app/src/main/res/drawable/block_enabled.xml deleted file mode 100644 index 07a04d78..00000000 --- a/app/src/main/res/drawable/block_enabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/app/src/main/res/menu/profile.xml b/app/src/main/res/menu/profile.xml index 24ff8dde..6cdeba1c 100644 --- a/app/src/main/res/menu/profile.xml +++ b/app/src/main/res/menu/profile.xml @@ -16,7 +16,10 @@ app:showAsAction="ifRoom" /> + \ No newline at end of file diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index ffd98f4f..05dfa983 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -59,4 +59,8 @@ abbrechen speichern error log + Stummschalten + Stummschaltung aufheben + stummgeschaltet! + Stummschaltung aufgehoben! \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4789bdc..a575ffb3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,5 +66,9 @@ sent from: stop loading save - World ID + World ID + mute + un-mute + muted + un-muted \ No newline at end of file