added mute function
This commit is contained in:
parent
655192f17b
commit
0d4e9bab5e
|
@ -34,10 +34,11 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
public static final long ACTION_FOLLOW = 1; // Folgen/Entfolgen
|
public static final long ACTION_FOLLOW = 1; // Folgen/Entfolgen
|
||||||
public static final long GET_TWEETS = 2; // Tweets Laden
|
public static final long GET_TWEETS = 2; // Tweets Laden
|
||||||
public static final long GET_FAVS = 3; // Favoriten Laden
|
public static final long GET_FAVS = 3; // Favoriten Laden
|
||||||
public static final long ACTION_MUTE = 4;
|
public static final long ACTION_BLOCK = 4;
|
||||||
public static final long LOAD_DB = 5;
|
public static final long ACTION_MUTE = 5;
|
||||||
private static final long FAILURE = 6;
|
public static final long LOAD_DB = 6;
|
||||||
private static final long IGNORE = 7;
|
private static final long FAILURE = 7;
|
||||||
|
private static final long IGNORE = 8;
|
||||||
|
|
||||||
private String screenName, username, description, location, follower, following;
|
private String screenName, username, description, location, follower, following;
|
||||||
private String profileImage, link, dateString;
|
private String profileImage, link, dateString;
|
||||||
|
@ -54,7 +55,8 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
private boolean isFollowed = false;
|
private boolean isFollowed = false;
|
||||||
private boolean isVerified = false;
|
private boolean isVerified = false;
|
||||||
private boolean isLocked = false;
|
private boolean isLocked = false;
|
||||||
private boolean blocked = false;
|
private boolean isBlocked = false;
|
||||||
|
private boolean isMuted = false;
|
||||||
private String errMsg = "E: Profile Load, ";
|
private String errMsg = "E: Profile Load, ";
|
||||||
private int returnCode = 0;
|
private int returnCode = 0;
|
||||||
|
|
||||||
|
@ -100,12 +102,13 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
long id = 1L;
|
long id = 1L;
|
||||||
try {
|
try {
|
||||||
isHome = homeId == userId;
|
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);
|
boolean connection[] = mTwitter.getConnection(userId);
|
||||||
isFollowing = connection[0];
|
isFollowing = connection[0];
|
||||||
isFollowed = connection[1];
|
isFollowed = connection[1];
|
||||||
blocked = connection[2];
|
isBlocked = connection[2];
|
||||||
|
isMuted = connection[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
TwitterUser user;
|
TwitterUser user;
|
||||||
|
@ -168,23 +171,16 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
}
|
}
|
||||||
else if(MODE == ACTION_FOLLOW)
|
else if(MODE == ACTION_FOLLOW)
|
||||||
{
|
{
|
||||||
if(isFollowing) {
|
isFollowing = !isFollowing;
|
||||||
mTwitter.followAction(userId,false);
|
mTwitter.followAction(userId, isFollowing);
|
||||||
isFollowing = false;
|
} else if (MODE == ACTION_BLOCK) {
|
||||||
} else {
|
isBlocked = !isBlocked;
|
||||||
mTwitter.followAction(userId,true);
|
mTwitter.blockAction(userId, isBlocked);
|
||||||
isFollowing = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(MODE == ACTION_MUTE)
|
else if(MODE == ACTION_MUTE)
|
||||||
{
|
{
|
||||||
if(blocked) {
|
isMuted = !isMuted;
|
||||||
mTwitter.blockAction(userId,false);
|
mTwitter.muteAction(userId, isMuted);
|
||||||
blocked = false;
|
|
||||||
} else {
|
|
||||||
mTwitter.blockAction(userId,true);
|
|
||||||
blocked = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (TwitterException err) {
|
} catch (TwitterException err) {
|
||||||
returnCode = err.getErrorCode();
|
returnCode = err.getErrorCode();
|
||||||
|
@ -273,18 +269,22 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
textId = R.string.followed;
|
textId = R.string.followed;
|
||||||
else
|
else
|
||||||
textId = R.string.unfollowed;
|
textId = R.string.unfollowed;
|
||||||
Toast.makeText(ui.get(), textId, Toast.LENGTH_SHORT).show();
|
Toast.makeText(connect, textId, Toast.LENGTH_SHORT).show();
|
||||||
}
|
} else if (mode == ACTION_BLOCK) {
|
||||||
else if(mode == ACTION_MUTE) {
|
|
||||||
int textId;
|
int textId;
|
||||||
if(blocked)
|
if (isBlocked)
|
||||||
textId = R.string.blocked;
|
textId = R.string.blocked;
|
||||||
else
|
else
|
||||||
textId = R.string.unblocked;
|
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();
|
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 tweetsReload = connect.findViewById(R.id.hometweets);
|
||||||
SwipeRefreshLayout favoriteReload = connect.findViewById(R.id.homefavorits);
|
SwipeRefreshLayout favoriteReload = connect.findViewById(R.id.homefavorits);
|
||||||
tweetsReload.setRefreshing(false);
|
tweetsReload.setRefreshing(false);
|
||||||
|
@ -296,11 +296,12 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
Toast.makeText(connect, errMsg, Toast.LENGTH_LONG).show();
|
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);
|
Toolbar tool = connect.findViewById(R.id.profile_toolbar);
|
||||||
if(tool.getMenu().size() >= 2) {
|
if(tool.getMenu().size() >= 2) {
|
||||||
MenuItem followIcon = tool.getMenu().getItem(1);
|
MenuItem followIcon = tool.getMenu().getItem(1);
|
||||||
MenuItem blockIcon = tool.getMenu().getItem(2);
|
MenuItem blockIcon = tool.getMenu().getItem(2);
|
||||||
|
MenuItem muteIcon = tool.getMenu().getItem(3);
|
||||||
if (isFollowing) {
|
if (isFollowing) {
|
||||||
followIcon.setIcon(R.drawable.follow_enabled);
|
followIcon.setIcon(R.drawable.follow_enabled);
|
||||||
followIcon.setTitle(R.string.unfollow);
|
followIcon.setTitle(R.string.unfollow);
|
||||||
|
@ -308,15 +309,18 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||||
followIcon.setIcon(R.drawable.follow);
|
followIcon.setIcon(R.drawable.follow);
|
||||||
followIcon.setTitle(R.string.follow);
|
followIcon.setTitle(R.string.follow);
|
||||||
}
|
}
|
||||||
if (blocked) {
|
if (isBlocked) {
|
||||||
blockIcon.setIcon(R.drawable.block_enabled);
|
|
||||||
blockIcon.setTitle(R.string.unblock);
|
blockIcon.setTitle(R.string.unblock);
|
||||||
followIcon.setVisible(false);
|
followIcon.setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
blockIcon.setIcon(R.drawable.block);
|
|
||||||
blockIcon.setTitle(R.string.block);
|
blockIcon.setTitle(R.string.block);
|
||||||
followIcon.setVisible(true);
|
followIcon.setVisible(true);
|
||||||
}
|
}
|
||||||
|
if (isMuted) {
|
||||||
|
muteIcon.setTitle(R.string.unmute);
|
||||||
|
} else {
|
||||||
|
muteIcon.setTitle(R.string.mute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,10 +269,11 @@ public class TwitterEngine {
|
||||||
*/
|
*/
|
||||||
public boolean[] getConnection(long id) throws TwitterException {
|
public boolean[] getConnection(long id) throws TwitterException {
|
||||||
Relationship connect = twitter.showFriendship(twitterID, id);
|
Relationship connect = twitter.showFriendship(twitterID, id);
|
||||||
boolean connection[] = new boolean[3];
|
boolean connection[] = new boolean[4];
|
||||||
connection[0] = connect.isSourceFollowingTarget();
|
connection[0] = connect.isSourceFollowingTarget();
|
||||||
connection[1] = connect.isTargetFollowingSource();
|
connection[1] = connect.isTargetFollowingSource();
|
||||||
connection[2] = connect.isSourceBlockingTarget();
|
connection[2] = connect.isSourceBlockingTarget();
|
||||||
|
connection[3] = connect.isSourceMutingTarget();
|
||||||
return connection;
|
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
|
* get Following User List
|
||||||
*
|
*
|
||||||
|
|
|
@ -121,6 +121,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||||
if(!home) {
|
if(!home) {
|
||||||
m.findItem(R.id.profile_follow).setVisible(true);
|
m.findItem(R.id.profile_follow).setVisible(true);
|
||||||
m.findItem(R.id.profile_block).setVisible(true);
|
m.findItem(R.id.profile_block).setVisible(true);
|
||||||
|
m.findItem(R.id.profile_mute).setVisible(true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -141,6 +142,10 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.profile_block:
|
case R.id.profile_block:
|
||||||
|
mProfile.execute(userId, ProfileLoader.ACTION_BLOCK);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.profile_mute:
|
||||||
mProfile.execute(userId, ProfileLoader.ACTION_MUTE);
|
mProfile.execute(userId, ProfileLoader.ACTION_MUTE);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
<vector android:height="24dp" android:viewportHeight="20.0"
|
|
||||||
android:viewportWidth="20.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="#FFFFFF" android:pathData="M10,0.4c-5.303,0 -9.601,4.298 -9.601,9.6c0,5.303 4.298,9.601 9.601,9.601c5.301,0 9.6,-4.298 9.6,-9.601C19.6,4.698 15.301,0.4 10,0.4zM2.399,10c0,-4.197 3.402,-7.6 7.6,-7.6c1.829,0 3.506,0.647 4.817,1.723L4.122,14.817C3.046,13.505 2.399,11.829 2.399,10zM9.999,17.599c-1.828,0 -3.505,-0.646 -4.815,-1.722L15.878,5.184C16.953,6.496 17.6,8.171 17.6,10C17.6,14.197 14.196,17.599 9.999,17.599z"/>
|
|
||||||
</vector>
|
|
|
@ -1,4 +0,0 @@
|
||||||
<vector android:height="24dp" android:viewportHeight="20.0"
|
|
||||||
android:viewportWidth="20.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="#FF0000" android:pathData="M10,0.4c-5.303,0 -9.601,4.298 -9.601,9.6c0,5.303 4.298,9.601 9.601,9.601c5.301,0 9.6,-4.298 9.6,-9.601C19.6,4.698 15.301,0.4 10,0.4zM2.399,10c0,-4.197 3.402,-7.6 7.6,-7.6c1.829,0 3.506,0.647 4.817,1.723L4.122,14.817C3.046,13.505 2.399,11.829 2.399,10zM9.999,17.599c-1.828,0 -3.505,-0.646 -4.815,-1.722L15.878,5.184C16.953,6.496 17.6,8.171 17.6,10C17.6,14.197 14.196,17.599 9.999,17.599z"/>
|
|
||||||
</vector>
|
|
|
@ -16,7 +16,10 @@
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/profile_block"
|
android:id="@+id/profile_block"
|
||||||
android:icon="@drawable/block"
|
|
||||||
android:title="@string/block"
|
android:title="@string/block"
|
||||||
android:visible="false" />
|
android:visible="false" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/profile_mute"
|
||||||
|
android:title="@string/mute"
|
||||||
|
android:visible="false" />
|
||||||
</menu>
|
</menu>
|
|
@ -59,4 +59,8 @@
|
||||||
<string name="progress_kill">abbrechen</string>
|
<string name="progress_kill">abbrechen</string>
|
||||||
<string name="save">speichern</string>
|
<string name="save">speichern</string>
|
||||||
<string name="error_log">error log</string>
|
<string name="error_log">error log</string>
|
||||||
|
<string name="mute">Stummschalten</string>
|
||||||
|
<string name="unmute">Stummschaltung aufheben</string>
|
||||||
|
<string name="muted">stummgeschaltet!</string>
|
||||||
|
<string name="unmuted">Stummschaltung aufgehoben!</string>
|
||||||
</resources>
|
</resources>
|
|
@ -66,5 +66,9 @@
|
||||||
<string name="sent_from">sent from:</string>
|
<string name="sent_from">sent from:</string>
|
||||||
<string name="progress_kill">stop loading</string>
|
<string name="progress_kill">stop loading</string>
|
||||||
<string name="save">save</string>
|
<string name="save">save</string>
|
||||||
<string name="woeid">World ID</string>
|
<string name="woeid" translatable="false">World ID</string>
|
||||||
|
<string name="mute">mute</string>
|
||||||
|
<string name="unmute">un-mute</string>
|
||||||
|
<string name="muted">muted</string>
|
||||||
|
<string name="unmuted">un-muted</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue