c.java 11.8 KB
package com.instabug.library.d;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources.Theme;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.instabug.library.IBGCustomTextPlaceHolder.Key;
import com.instabug.library.R.attr;
import com.instabug.library.R.drawable;
import com.instabug.library.R.id;
import com.instabug.library.R.layout;
import com.instabug.library.R.string;
import com.instabug.library.h;
import com.instabug.library.internal.d.a.b.b;
import com.instabug.library.model.IssueType;
import com.instabug.library.model.a.a;
import com.instabug.library.model.g.a;
import com.instabug.library.util.InstabugSDKLogger;
import com.instabug.library.util.l;
import com.instabug.library.view.CircularImageView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject;

public class c
  extends h
  implements AdapterView.OnItemClickListener, com.instabug.library.a, e, com.instabug.library.internal.d.a.d<com.instabug.library.model.c>
{
  private b a;
  private ListView b;
  private ArrayList<com.instabug.library.model.c> c = new ArrayList();
  private com.instabug.library.util.f d;
  private a e;
  private PublishSubject<Integer> f;
  private Subscription g;
  
  public static c f()
  {
    return new c();
  }
  
  private void g()
  {
    List localList = com.instabug.library.internal.d.a.f.a().b();
    InstabugSDKLogger.d(this, "Conversations loaded from cache " + localList.size());
    this.c.clear();
    this.c.addAll(localList);
    Collections.sort(this.c, Collections.reverseOrder(new com.instabug.library.model.c.a()));
    this.a.notifyDataSetChanged();
  }
  
  private void h()
  {
    this.f.onNext(Integer.valueOf(0));
  }
  
  public List<com.instabug.library.model.g> a(@NonNull List<com.instabug.library.model.g> paramList)
  {
    if (e() != null)
    {
      com.instabug.library.b.a().b(e());
      paramList = null;
    }
    return paramList;
  }
  
  protected void a() {}
  
  protected void a(Bundle paramBundle)
  {
    paramBundle.putSerializable("CONVERSATIONS", this.c);
  }
  
  public void a(final com.instabug.library.model.c paramc)
  {
    InstabugSDKLogger.d(this, "Conversation removed from cache: " + paramc);
    e().runOnUiThread(new Runnable()
    {
      public final void run()
      {
        c.a(c.this).remove(paramc);
        c.b(c.this);
      }
    });
  }
  
  public void a(com.instabug.library.model.c paramc1, final com.instabug.library.model.c paramc2)
  {
    InstabugSDKLogger.d(this, "Conversation updated in cache");
    e().runOnUiThread(new Runnable()
    {
      public final void run()
      {
        if (paramc2.b().size() > 0) {
          c.b(c.this);
        }
      }
    });
  }
  
  public void a(boolean paramBoolean)
  {
    InstabugSDKLogger.d(this, "InstabugConversationListFragment isVisible " + paramBoolean);
    if (!paramBoolean)
    {
      d.a().b(this);
      com.instabug.library.internal.d.a.e.a().b("CONVERSATIONS_MEMORY_CACHE", this);
      return;
    }
    d.a().a(this);
    com.instabug.library.internal.d.a.e.a().a("CONVERSATIONS_MEMORY_CACHE", this);
    h();
  }
  
  public void a_()
  {
    e().runOnUiThread(new Runnable()
    {
      public final void run()
      {
        InstabugSDKLogger.d(c.this, "Conversations cache was invalidated");
        c.b(c.this);
      }
    });
  }
  
  protected int b()
  {
    return R.layout.instabug_lyt_conversations;
  }
  
  protected void b(Bundle paramBundle)
  {
    this.c = ((ArrayList)paramBundle.getSerializable("CONVERSATIONS"));
  }
  
  public void b(final com.instabug.library.model.c paramc)
  {
    InstabugSDKLogger.d(this, "Conversation added to cache: " + paramc);
    e().runOnUiThread(new Runnable()
    {
      public final void run()
      {
        if (paramc.b().size() > 0)
        {
          c.a(c.this).add(paramc);
          c.b(c.this);
        }
      }
    });
  }
  
  protected String c()
  {
    return l.a(IBGCustomTextPlaceHolder.Key.CONVERSATIONS_LIST_TITLE, getString(R.string.instabug_str_conversations));
  }
  
  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    try
    {
      this.e = ((a)paramActivity);
      return;
    }
    catch (ClassCastException localClassCastException)
    {
      throw new ClassCastException(paramActivity.toString() + " must implement InstabugConversationListFragment.Callbacks");
    }
  }
  
  public void onDestroyView()
  {
    if ((this.g != null) && (!this.g.isUnsubscribed())) {
      this.g.unsubscribe();
    }
    super.onDestroyView();
  }
  
  public void onDetach()
  {
    super.onDetach();
    this.e = null;
  }
  
  public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    paramView = this.a.a(paramInt);
    com.instabug.library.internal.d.a.f.a().a(paramView.a(), paramView);
    if (this.e != null) {
      this.e.d(((com.instabug.library.model.c)paramAdapterView.getItemAtPosition(paramInt)).a());
    }
  }
  
  public void onPause()
  {
    InstabugSDKLogger.d(this, "onPause called, un-subscribing from all listeners");
    super.onPause();
    com.instabug.library.internal.d.a.e.a().b("CONVERSATIONS_MEMORY_CACHE", this);
    d.a().b(this);
  }
  
  public void onResume()
  {
    super.onResume();
    com.instabug.library.internal.d.a.e.a().a("CONVERSATIONS_MEMORY_CACHE", this);
    d.a().a(this);
  }
  
  public void onViewCreated(View paramView, @Nullable Bundle paramBundle)
  {
    super.onViewCreated(paramView, paramBundle);
    this.b = ((ListView)paramView.findViewById(R.id.instabug_lst_conversations));
    this.b.setOnItemClickListener(this);
    this.a = new b();
    this.d = new com.instabug.library.util.f(e());
    this.b.setAdapter(this.a);
    this.f = PublishSubject.create();
    this.g = this.f.debounce(300L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer()
    {
      public final void onCompleted() {}
      
      public final void onError(Throwable paramAnonymousThrowable) {}
    });
    g();
    this.b.setVisibility(0);
    getView().findViewById(R.id.instabug_disconnected).setVisibility(8);
    getView().findViewById(R.id.instabug_blank).setVisibility(8);
  }
  
  public static abstract interface a
  {
    public abstract void d(String paramString);
  }
  
  public class b
    extends BaseAdapter
  {
    public b() {}
    
    public com.instabug.library.model.c a(int paramInt)
    {
      return (com.instabug.library.model.c)c.a(c.this).get(paramInt);
    }
    
    public int getCount()
    {
      return c.a(c.this).size();
    }
    
    public long getItemId(int paramInt)
    {
      return a(paramInt).a().hashCode();
    }
    
    public View getView(int paramInt, View paramView, final ViewGroup paramViewGroup)
    {
      Object localObject1;
      label122:
      Object localObject2;
      if (paramView == null)
      {
        paramView = LayoutInflater.from(paramViewGroup.getContext()).inflate(R.layout.instabug_conversation_list_item, paramViewGroup, false);
        paramViewGroup = new c.c(c.this, paramView);
        paramView.setTag(paramViewGroup);
        localObject1 = a(paramInt);
        InstabugSDKLogger.v(this, "Binding conversation " + localObject1 + " to view");
        Collections.sort(((com.instabug.library.model.c)localObject1).b(), new g.a());
        c.c.a(paramViewGroup).setText(((com.instabug.library.model.c)localObject1).i().c());
        if (((com.instabug.library.model.c)localObject1).e() != IssueType.FEEDBACK) {
          break label284;
        }
        c.c.b(paramViewGroup).setImageResource(R.drawable.instabug_ic_feedback_dark);
        localObject2 = ((com.instabug.library.model.c)localObject1).g();
        if (localObject2 == null) {
          break label297;
        }
        localObject2 = ((String)localObject2).substring(0, ((String)localObject2).indexOf('<'));
        c.c.c(paramViewGroup).setText((CharSequence)localObject2);
        label158:
        c.c.d(paramViewGroup).setText(com.instabug.library.util.g.a(((com.instabug.library.model.c)localObject1).h()));
        if (((com.instabug.library.model.c)localObject1).c() == 0) {
          break label353;
        }
        localObject2 = new TypedValue();
        c.this.getActivity().getTheme().resolveAttribute(R.attr.instabug_color_unread_background, (TypedValue)localObject2, true);
        c.c.e(paramViewGroup).setBackgroundColor(((TypedValue)localObject2).data);
      }
      for (;;)
      {
        if (((com.instabug.library.model.c)localObject1).f() != null)
        {
          localObject1 = com.instabug.library.internal.d.a.b.a(c.this.getActivity(), ((com.instabug.library.model.c)localObject1).f(), a.a.a);
          com.instabug.library.internal.d.a.b.a(c.this.getActivity(), (com.instabug.library.model.a)localObject1, new b.b()
          {
            public final void a(com.instabug.library.model.a paramAnonymousa)
            {
              InstabugSDKLogger.d(this, "Asset Entity downloaded: " + paramAnonymousa.c().getPath());
              try
              {
                c.c.f(paramViewGroup).setImageDrawable(null);
                c.c.f(paramViewGroup).setImageBitmap(BitmapFactory.decodeStream(new FileInputStream(paramAnonymousa.c())));
                return;
              }
              catch (FileNotFoundException paramAnonymousa)
              {
                InstabugSDKLogger.e(this, "Asset Entity downloading got FileNotFoundException error", paramAnonymousa);
              }
            }
            
            public final void a(Throwable paramAnonymousThrowable)
            {
              InstabugSDKLogger.e(this, "Asset Entity downloading got error", paramAnonymousThrowable);
            }
          });
        }
        return paramView;
        paramViewGroup = (c.c)paramView.getTag();
        break;
        label284:
        c.c.b(paramViewGroup).setImageResource(R.drawable.instabug_ic_bug_dark);
        break label122;
        label297:
        localObject2 = c.c(c.this).a() + c.this.getActivity().getApplicationContext().getString(R.string.instabug_str_notification_title);
        c.c.c(paramViewGroup).setText((CharSequence)localObject2);
        break label158;
        label353:
        c.c.e(paramViewGroup).setBackgroundDrawable(null);
      }
    }
  }
  
  public class c
  {
    private final TextView b;
    private final CircularImageView c;
    private final TextView d;
    private final TextView e;
    private final ImageView f;
    private final LinearLayout g;
    
    public c(View paramView)
    {
      this.g = ((LinearLayout)paramView.findViewById(R.id.conversation_container));
      this.b = ((TextView)paramView.findViewById(R.id.instabug_txt_message_sender));
      this.c = ((CircularImageView)paramView.findViewById(R.id.instabug_img_message_sender));
      this.f = ((ImageView)paramView.findViewById(R.id.instabug_img_bug_type));
      this.d = ((TextView)paramView.findViewById(R.id.instabug_txt_message_time));
      this.e = ((TextView)paramView.findViewById(R.id.instabug_txt_message_snippet));
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/instabug/library/d/c.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */