package de.upb.fsmi.fsdroid.cards.views;

import android.content.*;
import android.database.*;
import android.util.*;
import android.widget.*;

import org.androidannotations.annotations.*;
import org.androidannotations.annotations.res.*;
import org.slf4j.*;

import de.upb.fsmi.fsdroid.*;
import de.upb.fsmi.fsdroid.sync.*;
import de.upb.fsmi.fsdroid.sync.entities.*;

@EViewGroup(R.layout.card_status)
public class StatusCardViewGroup extends RelativeLayout {

    private static final int STATUS_LOADER = 0x01;
    private final Logger LOGGER = LoggerFactory.getLogger(StatusCardViewGroup.class.getSimpleName());

    @ViewById(R.id.txtStatus)
    TextView txtStatus;

    @ViewById(R.id.txtDescriptionStatus)
    TextView txtDescriptionStatus;

    @ViewById(R.id.imgStatus)
    ImageView imgStatus;

    @StringArrayRes
    String[] stati, statiDescriptions;

    @Bean
    AccountCreator mAccountCreator;
    private Context mContext;

    public StatusCardViewGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }


    @AfterViews
    @UiThread
    void loadStatus() {
        String[] projection = {Status.COLUMN_VALUE, Status.COLUMN_ID};

        final Cursor cursor = mContext.getContentResolver().query(
                FSDroidContentProvider.STATUS_URI, projection, null, null, Status.COLUMN_LAST_UPDATE + " DESC");

        if (cursor.moveToFirst()) {
            if (BuildConfig.DEBUG) LOGGER.debug("moved to first");
            if (cursor.getColumnCount() > 0) {
                bind(cursor.getInt(0));
            }
        }
    }


    public void bind(Integer status) {
        Log.v(StatusCardViewGroup.class.getSimpleName(), "Binding status=" + status);

        final int statusInt = status.intValue();

        imgStatus.setImageLevel(statusInt);
        txtStatus.setText(stati[statusInt]);
        txtDescriptionStatus.setText(statiDescriptions[statusInt]);
    }
}

@@ -58,17 +58,23 @@
 content.
-*
+Context
 ;%0Aimport
@@ -91,17 +91,22 @@
 atabase.
-*
+Cursor
 ;%0Aimport
@@ -123,34 +123,148 @@
 til.
-*;%0Aimport android.widget.*
+AttributeSet;%0Aimport android.util.Log;%0Aimport android.widget.ImageView;%0Aimport android.widget.RelativeLayout;%0Aimport android.widget.TextView
 ;%0A%0Ai
@@ -304,17 +304,26 @@
 tations.
-*
+AfterViews
 ;%0Aimport
@@ -362,64 +362,408 @@
 ons.
-res.*;%0Aimport org.slf4j.*;%0A%0Aimport de.upb.fsmi.fsdroid.*
+Bean;%0Aimport org.androidannotations.annotations.EViewGroup;%0Aimport org.androidannotations.annotations.UiThread;%0Aimport org.androidannotations.annotations.ViewById;%0Aimport org.androidannotations.annotations.res.StringArrayRes;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport de.upb.fsmi.fsdroid.BuildConfig;%0Aimport de.upb.fsmi.fsdroid.R;%0Aimport de.upb.fsmi.fsdroid.sync.AccountCreator
 ;%0Aim
@@ -792,17 +792,38 @@
 id.sync.
-*
+FSDroidContentProvider
 ;%0Aimport
@@ -861,9 +861,14 @@
 ies.
-*
+Status
 ;%0A%0A@
@@ -1320,16 +1320,98 @@
 ArrayRes
+(R.array.stati)%0A    String%5B%5D stati;%0A    @StringArrayRes(R.array.statiDescriptions)
 %0A    Str
@@ -1419,15 +1419,8 @@
 ng%5B%5D
- stati,
  sta

Split declarations