Browse Source

Fix inbox missing avatar issue

pms
oogee 5 years ago
parent
commit
d3d94e59e1
  1. 5
      app/src/main/java/gr/thmmy/mthmmy/activities/inbox/InboxActivity.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/inbox/tasks/InboxTask.java
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  4. 10
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/InboxViewModel.java

5
app/src/main/java/gr/thmmy/mthmmy/activities/inbox/InboxActivity.java

@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.inbox;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -10,7 +9,6 @@ import androidx.recyclerview.widget.RecyclerView;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.utils.ExternalAsyncTask;
import gr.thmmy.mthmmy.utils.NetworkResultCodes;
import gr.thmmy.mthmmy.viewmodel.InboxViewModel;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
@ -59,7 +57,10 @@ public class InboxActivity extends BaseActivity {
inboxViewModel.setOnInboxTaskFinishedListener((resultCode, inbox) -> {
progressBar.setVisibility(View.INVISIBLE);
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Successfully loaded inbox");
inboxAdapter.notifyDataSetChanged();
} else {
}
});
}

4
app/src/main/java/gr/thmmy/mthmmy/activities/inbox/tasks/InboxTask.java

@ -49,7 +49,9 @@ public class InboxTask extends NewParseTask<Inbox> {
Element pmContainer = pmContainerContainer.select("table[style=table-layout: fixed;]").first().child(0);
Element thumbnail = pmContainer.select("img.avatar").first();
pm.setThumbnailUrl(thumbnail.attr("src"));
// User might not have an avatar
if (thumbnail != null)
pm.setThumbnailUrl(thumbnail.attr("src"));
Element subjectAndDateContainer = pmContainer.select("td[align=left]").first();
pm.setSubject(subjectAndDateContainer.select("b").first().text());

3
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -1,6 +1,5 @@
package gr.thmmy.mthmmy.activities.profile;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
@ -19,6 +18,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
@ -39,7 +39,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import androidx.appcompat.app.AlertDialog;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.create_pm.CreatePMActivity;

10
app/src/main/java/gr/thmmy/mthmmy/viewmodel/InboxViewModel.java

@ -6,6 +6,8 @@ import java.util.ArrayList;
import gr.thmmy.mthmmy.activities.inbox.tasks.InboxTask;
import gr.thmmy.mthmmy.model.Inbox;
import gr.thmmy.mthmmy.model.PM;
import gr.thmmy.mthmmy.utils.NetworkResultCodes;
public class InboxViewModel extends ViewModel implements InboxTask.OnNetworkTaskFinishedListener<Inbox> {
private static final String INBOX_URL = "https://www.thmmy.gr/smf/index.php?action=pm";
@ -38,10 +40,12 @@ public class InboxViewModel extends ViewModel implements InboxTask.OnNetworkTask
@Override
public void onNetworkTaskFinished(int resultCode, Inbox inbox) {
this.inbox = inbox;
userExtraInfoVisibile.clear();
for (int i = 0; i < inbox.getPms().size(); i++)
userExtraInfoVisibile.add(false);
onInboxTaskFinishedListener.onNetworkTaskFinished(resultCode, inbox);
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
userExtraInfoVisibile.clear();
for (PM pm : inbox.getPms())
userExtraInfoVisibile.add(false);
}
}
public Inbox getInbox() {

Loading…
Cancel
Save