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

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

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

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

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

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

Loading…
Cancel
Save