From d3d94e59e1c06f0ff5c87ddf44623fc6db911794 Mon Sep 17 00:00:00 2001 From: oogee Date: Wed, 30 Oct 2019 11:55:59 +0200 Subject: [PATCH] Fix inbox missing avatar issue --- .../thmmy/mthmmy/activities/inbox/InboxActivity.java | 5 +++-- .../thmmy/mthmmy/activities/inbox/tasks/InboxTask.java | 4 +++- .../mthmmy/activities/profile/ProfileActivity.java | 3 +-- .../java/gr/thmmy/mthmmy/viewmodel/InboxViewModel.java | 10 +++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/InboxActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/InboxActivity.java index a78091bc..022a7f7c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/InboxActivity.java +++ b/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 { + } }); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/tasks/InboxTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/tasks/InboxTask.java index 29408092..5e2f20d7 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/tasks/InboxTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/inbox/tasks/InboxTask.java @@ -49,7 +49,9 @@ public class InboxTask extends NewParseTask { 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()); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java index 5da235b1..95c4fd9c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java +++ b/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; diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/InboxViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/InboxViewModel.java index f6138806..9d6cad98 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/InboxViewModel.java +++ b/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 { 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() {