package org.fossasia.phimpme.uploadhistory;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.view.IconicsImageView;

import org.fossasia.phimpme.R;
import org.fossasia.phimpme.base.ThemedActivity;
import org.fossasia.phimpme.data.local.UploadHistoryRealmModel;
import org.jetbrains.annotations.NotNull;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.realm.Realm;
import io.realm.RealmQuery;

/**
 * Created by pa1pal on 17/08/17.
 */

public class UploadHistory extends ThemedActivity {

    @BindView(R.id.upload_history_recycler_view)
    RecyclerView uploadHistoryRecyclerView;

    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @BindView(R.id.empty_icon)
    IconicsImageView emptyIcon;

    @BindView(R.id.emptyLayout)
    RelativeLayout emptyLayout;

    @BindView(R.id.empty_text)
    TextView emptyText;

    Realm realm;

    private RealmQuery<UploadHistoryRealmModel> uploadResults;
    private UploadHistoryAdapter uploadHistoryAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.upload_history_activity);
        ButterKnife.bind(this);
        setupToolbar();
        uploadHistoryAdapter = new UploadHistoryAdapter(getPrimaryColor());
        realm = Realm.getDefaultInstance();
        uploadResults = realm.where(UploadHistoryRealmModel.class);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setReverseLayout(true);
        layoutManager.setStackFromEnd(true);
        uploadHistoryRecyclerView.setLayoutManager(layoutManager);
        uploadHistoryRecyclerView.setAdapter(uploadHistoryAdapter);
        uploadHistoryAdapter.setResults(uploadResults);

        //uploadHistoryRecyclerView.addOnItemTouchListener(new RecyclerItemClickListner(this, this));
        emptyIcon.setColor(getIconColor());
        emptyText.setTextColor(getAccentColor());



    }

    public void setUpAdapter(@NotNull RealmQuery<UploadHistoryRealmModel> accountDetails) {
        this.uploadResults = accountDetails;
        uploadHistoryAdapter.setResults(uploadResults);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (uploadResults.findAll().size() == 0) {
            emptyLayout.setVisibility(View.VISIBLE);
            uploadHistoryRecyclerView.setVisibility(View.GONE);
        }
    }
    private void setupToolbar(){
        setSupportActionBar(toolbar);
        toolbar.setPopupTheme(getPopupToolbarStyle());
        toolbar.setBackgroundColor(getPrimaryColor());
        toolbar.setNavigationIcon(
                new IconicsDrawable(this)
                        .icon(CommunityMaterial.Icon.cmd_arrow_left)
                        .color(Color.WHITE)
                        .sizeDp(19));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
}

@@ -1228,24 +1228,92 @@
 emptyText;%0A%0A
+    @BindView(R.id.accounts_parent)%0A    RelativeLayout parentView;%0A%0A
     Realm re
@@ -1317,16 +1317,16 @@
  realm;%0A
-
 %0A    pri
@@ -1643,32 +1643,8 @@
 s);%0A
-        setupToolbar();%0A
     
@@ -2185,16 +2185,35 @@
 ults);%0A%0A
+        setUpUI();%0A
         
@@ -2302,24 +2302,60 @@
 is, this));%0A
+    %7D%0A%0A    private void setUpUI() %7B%0A
         empt
@@ -2436,18 +2436,100 @@
 lor());%0A
-%0A%0A
+        parentView.setBackgroundColor(getBackgroundColor());%0A        setupToolbar();
 %0A    %7D%0A%0A
@@ -2767,24 +2767,24 @@
 nResume() %7B%0A
-
         supe
@@ -2793,24 +2793,43 @@
 onResume();%0A
+        setUpUI();%0A
         if (

Fix #1494 - Image is now visible in all the themes. (#1499)