Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Oct 18, 2023
1 parent 2ecf4f3 commit 97213b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ public Account loginApp(ConnectionUpdate connection, String pin) throws Mastodon
JSONObject json = new JSONObject(body.string());
String bearer = json.getString("access_token");
Credentials credentials = getCredentials(hostname, bearer);
Account account = new MastodonAccount(credentials.getId(), hostname, bearer, connection.getOauthConsumerToken(), connection.getOauthTokenSecret());
MastodonAccount account = new MastodonAccount(credentials.getId(), hostname, bearer, connection.getOauthConsumerToken(), connection.getOauthTokenSecret());
settings.setLogin(account, false);
User user = showUser(credentials.getId());
account.setUser(user);
return account;
}
throw new MastodonException(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class MastodonAccount implements Account {
private String bearer;
private String client_id, client_secret;

private User user;

/**
* @param id user ID
* @param hostname hostname of the Mastodon isntance
Expand Down Expand Up @@ -55,7 +57,7 @@ public long getTimestamp() {
@Nullable
@Override
public User getUser() {
return null;
return user;
}


Expand Down Expand Up @@ -117,4 +119,14 @@ public boolean equals(@Nullable Object obj) {
return getUser().equals(account.getUser());
return false;
}


/**
* set user information
*
* @param user user information associated with this account
*/
public void setUser(User user) {
this.user = user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class MainActivity extends AppCompatActivity implements ActivityResultCal
private HomeAdapter adapter;
private GlobalSettings settings;
private Picasso picasso;

private UserLoader userLoader;
private Dialog loadingCircle;

private DrawerLayout drawerLayout;
Expand Down Expand Up @@ -130,7 +130,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
followerCount = header.findViewById(R.id.navigation_profile_follower);
followingCount = header.findViewById(R.id.navigation_profile_following);

UserLoader userLoader = new UserLoader(this);
userLoader = new UserLoader(this);
loadingCircle = new ProgressDialog(this, null);
settings = GlobalSettings.get(this);
picasso = PicassoBuilder.get(this);
Expand All @@ -150,11 +150,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setCurrentUser((User) data);
}
}
// load user information
if (settings.isLoggedIn() && currentUser == null) {
Param param = new Param(Param.DATABASE, settings.getLogin().getId());
userLoader.execute(param, this);
}
// set navigation view style
navigationView.post(new Runnable() {
@Override
Expand Down Expand Up @@ -189,6 +184,11 @@ else if (adapter == null) {
adapter = new HomeAdapter(this);
viewPager.setAdapter(adapter);
}
// load user information
if (settings.isLoggedIn() && currentUser == null) {
Param param = new Param(Param.DATABASE, settings.getLogin().getId());
userLoader.execute(param, this);
}
}


Expand Down Expand Up @@ -260,9 +260,10 @@ public void onActivityResult(ActivityResult result) {
case AccountActivity.RETURN_ACCOUNT_CHANGED:
setCurrentUser(null); // remove old user content
if (data != null) {
Serializable serializable = data.getSerializableExtra(AccountActivity.RETURN_ACCOUNT);
if (serializable instanceof Account) {
setCurrentUser(((Account) serializable).getUser());
Serializable serializedAccount = data.getSerializableExtra(AccountActivity.RETURN_ACCOUNT);
if (serializedAccount instanceof Account) {
Account account = (Account) serializedAccount;
setCurrentUser(account.getUser());
}
}
// reset tab pages
Expand Down Expand Up @@ -458,10 +459,8 @@ public void onClick(View v) {


@Override
public void onResult(@NonNull Result userResult) {
if (userResult.user != null) {
setCurrentUser(userResult.user);
}
public void onResult(@NonNull Result result) {
setCurrentUser(result.user);
}

/**
Expand Down

0 comments on commit 97213b0

Please sign in to comment.