// Path: src/main/java/de/e621/rebane/components/listadapter/DMailListAdapter.java
// public class DMailListAdapter extends XMLListAdapter {
// 
//     public int getLastPage(int pagesize) {
//         return 100;
//     } //can't be computed
// 
//     public DMailListAdapter(Context context, int textViewResourceId, List<XMLNode> rowDataList) {
//         super(context, textViewResourceId, rowDataList);
//         svNumPosts = Integer.MAX_VALUE; //can't be computed
//     }
// 
//     public View getView(final int position, View convertView, ViewGroup parent) {
//         DMailViewHolder holder = new DMailViewHolder(Integer.parseInt(list.get(position).getFirstChildContent("id").orElse("")));
// 
//         LayoutInflater inflator = LayoutInflater.from(parent.getContext());
//         convertView = inflator.inflate(R.layout.twolined_listentry, parent, false);
// 
//         SQLiteDB db = new SQLiteDB(getContext().getApplicationContext());
//         db.open();
//         LoginManager lm = LoginManager.getInstance(getContext().getApplicationContext(), db);
//         XMLNode tmp = list.get(position);
//         //Logger.getLogger("a621").info(tmp.toString());
// 
//         holder.populate(position, convertView, tmp, lm);
// 
//         return convertView;
//     }
// }


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.itwookie.XMLreader.XMLNode;
import java.net.HttpURLConnection;
import java.net.URL;
import de.e621.rebane.a621.R;
import de.e621.rebane.components.listadapter.DMailListAdapter;


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_mark_all_read) {
            new AsyncTask<String, Void, Void>() {
                @Override protected Void doInBackground(String... args) {
                    try {
                        HttpURLConnection urlc = (HttpURLConnection) new URL(args[0]).openConnection();
                        urlc.addRequestProperty("User-Agent", args[1]);
                        urlc.getContentLength();
                    } catch (Exception e) {
                    }
                    return null;
                }
            }.execute(database.getValue(SettingsActivity.SETTINGBASEURL) + "dmail/mark_all_read", getApplicationContext().getString(R.string.requestUserAgent));
            Toast.makeText(getApplicationContext(), getString(R.string.dmail_response_markedall), Toast.LENGTH_LONG).show();
        }

        return super.onOptionsItemSelected(item);
    }

    @Override void setPagesize() {
        pagesize = 30; //given by API
    }

    @Override
    public void onSaveInstanceState(Bundle outState){

// Path: src/main/java/de/e621/rebane/components/listadapter/DMailListAdapter.java
// public class DMailListAdapter extends XMLListAdapter {
// 
//     public int getLastPage(int pagesize) {
//         return 100;
//     } //can't be computed
// 
//     public DMailListAdapter(Context context, int textViewResourceId, List<XMLNode> rowDataList) {
//         super(context, textViewResourceId, rowDataList);
//         svNumPosts = Integer.MAX_VALUE; //can't be computed
//     }
// 
//     public View getView(final int position, View convertView, ViewGroup parent) {
//         DMailViewHolder holder = new DMailViewHolder(Integer.parseInt(list.get(position).getFirstChildContent("id").orElse("")));
// 
//         LayoutInflater inflator = LayoutInflater.from(parent.getContext());
//         convertView = inflator.inflate(R.layout.twolined_listentry, parent, false);
// 
//         SQLiteDB db = new SQLiteDB(getContext().getApplicationContext());
//         db.open();
//         LoginManager lm = LoginManager.getInstance(getContext().getApplicationContext(), db);
//         XMLNode tmp = list.get(position);
//         //Logger.getLogger("a621").info(tmp.toString());
// 
//         holder.populate(position, convertView, tmp, lm);
// 
//         return convertView;
//     }
// }


// Path: src/main/java/de/e621/rebane/activities/DMailsActivity.java
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.itwookie.XMLreader.XMLNode;
import java.net.HttpURLConnection;
import java.net.URL;
import de.e621.rebane.a621.R;
import de.e621.rebane.components.listadapter.DMailListAdapter;


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_mark_all_read) {
            new AsyncTask<String, Void, Void>() {
                @Override protected Void doInBackground(String... args) {
                    try {
                        HttpURLConnection urlc = (HttpURLConnection) new URL(args[0]).openConnection();
                        urlc.addRequestProperty("User-Agent", args[1]);
                        urlc.getContentLength();
                    } catch (Exception e) {
                    }
                    return null;
                }
            }.execute(database.getValue(SettingsActivity.SETTINGBASEURL) + "dmail/mark_all_read", getApplicationContext().getString(R.string.requestUserAgent));
            Toast.makeText(getApplicationContext(), getString(R.string.dmail_response_markedall), Toast.LENGTH_LONG).show();
        }

        return super.onOptionsItemSelected(item);
    }

    @Override void setPagesize() {
        pagesize = 30; //given by API
    }

    @Override
    public void onSaveInstanceState(Bundle outState){

        super.onSaveInstanceState(outState);
