Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Sep 16, 2018
1 parent b89ed86 commit 2ca8276
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 46 deletions.
25 changes: 14 additions & 11 deletions app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ProfileLoader extends AsyncTask<Long, Long, Long> {
private boolean isFollowed = false;
private boolean isBlocked = false;
private boolean isMuted = false;
private boolean canDm = false;

private String errMsg = "E Profile Load: ";
private int returnCode = 0;
Expand Down Expand Up @@ -124,17 +125,18 @@ protected Long doInBackground(Long... args) {
}

user = mTwitter.getUser(UID);
publishProgress(GET_USER);
database.storeUser(user);

if (!isHome) {
boolean connection[] = mTwitter.getConnection(UID);
isFollowing = connection[0];
isFollowed = connection[1];
isBlocked = connection[2];
isMuted = connection[3];
canDm = connection[4];
}

publishProgress(GET_USER);
database.storeUser(user);

if (MODE == ACTION_FOLLOW) {
isFollowing = !isFollowing;
mTwitter.followAction(UID, isFollowing);
Expand All @@ -148,7 +150,7 @@ protected Long doInBackground(Long... args) {
mTwitter.muteAction(UID, isMuted);
publishProgress(GET_USER);
} else {
boolean access = (!user.isLocked || isFollowed);
boolean access = (!user.isLocked || isFollowing);
if ((MODE == GET_TWEETS || homeTl.getItemCount() == 0) && access) {
long id = 1L;
if (homeTl.getItemCount() > 0)
Expand Down Expand Up @@ -231,13 +233,14 @@ protected void onProgressUpdate(Long... mode) {
}
if (imgEnabled) {
Picasso.get().load(user.profileImg + "_bigger").into(profile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ImagePopup(ui.get()).execute(user.profileImg);
}
});
}
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ImagePopup(ui.get()).execute(user.profileImg);
}
});

} else if (MODE == GET_TWEETS) {
SwipeRefreshLayout homeReload = ui.get().findViewById(R.id.hometweets);
homeReload.setRefreshing(false);
Expand Down Expand Up @@ -292,7 +295,7 @@ protected void onPostExecute(final Long MODE) {
favoriteReload.setRefreshing(false);
}
if (!isHome) {
ui.get().setConnection(isFollowing, isMuted, isBlocked);
ui.get().setConnection(isFollowing, isMuted, isBlocked, canDm);
ui.get().invalidateOptionsMenu();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ public TwitterUser getUser(long id) throws TwitterException {
* Efficient Access of Connection Information
*
* @param id User ID compared with Home ID
* @return array of connection states Index 0: Following, 1: Follow, 2: blocked
* @return array of connection states Index 0: Following, 1: Follow, 2: blocked 3: muted 4: canDM
* @throws TwitterException if Connection is unavailable
*/
public boolean[] getConnection(long id) throws TwitterException {
Relationship connect = twitter.showFriendship(twitterID, id);
boolean connection[] = new boolean[4];
boolean connection[] = new boolean[5];
connection[0] = connect.isSourceFollowingTarget();
connection[1] = connect.isTargetFollowingSource();
connection[2] = connect.isSourceBlockingTarget();
connection[3] = connect.isSourceMutingTarget();
connection[4] = connect.canSourceDm();
return connection;
}

Expand Down
61 changes: 34 additions & 27 deletions app/src/main/java/org/nuclearfog/twidda/window/UserProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
private RecyclerView homeList, favoriteList;
private TabHost mTab;
private View lastTab;
private boolean isFollowing, isBlocked, isMuted;
private boolean isFollowing, isBlocked, isMuted, canDm;
private boolean home;
private long userId = 0;
private int tabIndex = 0;
Expand Down Expand Up @@ -137,28 +137,34 @@ public boolean onCreateOptionsMenu(Menu m) {

@Override
public boolean onPrepareOptionsMenu(Menu m) {
MenuItem followIcon = m.findItem(R.id.profile_follow);
MenuItem blockIcon = m.findItem(R.id.profile_block);
MenuItem muteIcon = m.findItem(R.id.profile_mute);

if (isFollowing) {
followIcon.setIcon(R.drawable.follow_enabled);
followIcon.setTitle(R.string.unfollow);
} else {
followIcon.setIcon(R.drawable.follow);
followIcon.setTitle(R.string.follow);
}
if (isBlocked) {
blockIcon.setTitle(R.string.unblock);
followIcon.setVisible(false);
} else {
blockIcon.setTitle(R.string.block);
followIcon.setVisible(true);
}
if (isMuted) {
muteIcon.setTitle(R.string.unmute);
} else {
muteIcon.setTitle(R.string.mute);
if (!home) {
MenuItem followIcon = m.findItem(R.id.profile_follow);
MenuItem blockIcon = m.findItem(R.id.profile_block);
MenuItem muteIcon = m.findItem(R.id.profile_mute);
MenuItem dmIcon = m.findItem(R.id.profile_message);

if (isFollowing) {
followIcon.setIcon(R.drawable.follow_enabled);
followIcon.setTitle(R.string.unfollow);
} else {
followIcon.setIcon(R.drawable.follow);
followIcon.setTitle(R.string.follow);
}
if (isBlocked) {
blockIcon.setTitle(R.string.unblock);
followIcon.setVisible(false);
} else {
blockIcon.setTitle(R.string.block);
followIcon.setVisible(true);
}
if (isMuted) {
muteIcon.setTitle(R.string.unmute);
} else {
muteIcon.setTitle(R.string.mute);
}
if (!canDm) {
dmIcon.setVisible(false);
}
}
return super.onPrepareOptionsMenu(m);
}
Expand All @@ -169,10 +175,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (mProfile != null && mProfile.getStatus() != RUNNING) {
switch (item.getItemId()) {
case R.id.profile_tweet:
Intent intent = new Intent(this, TweetPopup.class);
Intent tweet = new Intent(this, TweetPopup.class);
if (!home)
intent.putExtra("Addition", username);
startActivity(intent);
tweet.putExtra("Addition", username);
startActivity(tweet);
break;

case R.id.profile_follow:
Expand Down Expand Up @@ -311,9 +317,10 @@ private void animate() {
}


public void setConnection(boolean isFollowing, boolean isMuted, boolean isBlocked) {
public void setConnection(boolean isFollowing, boolean isMuted, boolean isBlocked, boolean canDm) {
this.isFollowing = isFollowing;
this.isMuted = isMuted;
this.isBlocked = isBlocked;
this.canDm = canDm;
}
}
11 changes: 5 additions & 6 deletions app/src/main/res/menu/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
android:id="@+id/profile_tweet"
android:icon="@drawable/tweet"
android:title="@string/tweet"
android:visible="true"
app:showAsAction="always" />
<item
android:id="@+id/profile_follow"
android:icon="@drawable/follow"
android:title="@string/follow"
android:visible="false"
app:showAsAction="ifRoom" />
<item
android:id="@+id/profile_message"
android:icon="@drawable/message"
android:title="@string/directmessage"
app:showAsAction="ifRoom" />
<item
android:id="@+id/profile_block"
android:title="@string/block"
Expand All @@ -27,4 +21,9 @@
android:id="@+id/profile_mute"
android:title="@string/mute"
android:visible="false" />
<item
android:id="@+id/profile_message"
android:icon="@drawable/message"
android:title="@string/directmessage"
app:showAsAction="ifRoom" />
</menu>

0 comments on commit 2ca8276

Please sign in to comment.