// Path: src/main/java/de/e621/rebane/activities/DMailsActivity.java
// public class DMailsActivity extends PaginatedListActivity implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener {
// 
//     final static String FORUMQUERYPAGE = "a621 SearchManager DMail Page";
// 
//     @Override
//     @SuppressLint("MissingSuperCall")
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(R.layout.content_paginated_list, savedInstanceState);
//         //setContentView(R.layout.activity_paginated_list);
//         postLayoutInflated(this.getClass());
//     }
// 
//     @Override
//     public boolean onCreateOptionsMenu(Menu menu) {
//         // Inflate the menu; this adds items to the action bar if it is present.
//         getMenuInflater().inflate(R.menu.dmails, menu);
//         this.menu = menu;
//         return true;
//     }
// 
//     @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);
//         outState.putInt(FORUMQUERYPAGE, page);
//     }
// 
//     @Override
//     void handleIntent(Intent intent) {
//         super.handleIntent(intent);
//         page = intent.getIntExtra(FORUMQUERYPAGE,1);
// 
//         if (results==null) searchPosts("", page);
//     }
// 
//     @Override void searchPosts(String escapedQuery, int page) {
//         API_URI = "dmail/inbox.xml?page="+page;
//         API_LOGIN = true;
// 
//         super.searchPosts(escapedQuery, page);
//     }
// 
//     @Override void onSearchResult(XMLNode result, String query, int page) {
//         results = new DMailListAdapter(getApplicationContext(), R.id.lblTitle, result.getChildren());
//         //results.svNumPosts = (result.attributes().contains("count") ? Integer.valueOf(result.getAttribute("count")) : 0); //this value is not provided
//         DMailsActivity.this.page = page;
// 
//         ActionBar ab = getSupportActionBar();
//         ab.setTitle(getResources().getString(R.string.title_dmail) + " | " + page);
//         //setTitle(getResources().getString(R.string.title_posts) + " " + _page + (_query.equals("")?" | *":" | "+XMLUtils.unescapeXML(_query)));
//     }
// 
// }


import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.itwookie.XMLreader.XMLNode;
import com.itwookie.XMLreader.XMLReader;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import de.e621.rebane.a621.R;
import de.e621.rebane.activities.DMailsActivity;

            urlc.setRequestMethod("GET");
            urlc.setChunkedStreamingMode(256);
            urlc.setConnectTimeout(15000);
            urlc.setReadTimeout(15000);
            urlc.setUseCaches(false);
            InputStream bis = urlc.getInputStream();
            Logger.getLogger("a621").info("Background - Connected with response code " + urlc.getResponseCode() + ": " + urlc.getResponseMessage());

            result = (new XMLReader()).parse(bis);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (result != null) {
            int cnt = 0;
            StringBuilder cont = new StringBuilder();
            for (XMLNode msg : result.getChildren()) {
                if (!msg.getType().equals("dmail")) {
                    cnt = 0;
                    break;
                }
                //Logger.getLogger("a621").info ("DMail: " + msg.toString());
                Boolean seen = Boolean.parseBoolean(msg.getFirstChildContent("has-seen").orElse(""));
                if (!seen) {
                    cnt++;
                    cont.append(msg.getFirstChildContent("title").orElse("") + " \n");
                }
            }
            if (cnt > 0) {
                NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


// Path: src/main/java/de/e621/rebane/activities/DMailsActivity.java
// public class DMailsActivity extends PaginatedListActivity implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener {
// 
//     final static String FORUMQUERYPAGE = "a621 SearchManager DMail Page";
// 
//     @Override
//     @SuppressLint("MissingSuperCall")
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(R.layout.content_paginated_list, savedInstanceState);
//         //setContentView(R.layout.activity_paginated_list);
//         postLayoutInflated(this.getClass());
//     }
// 
//     @Override
//     public boolean onCreateOptionsMenu(Menu menu) {
//         // Inflate the menu; this adds items to the action bar if it is present.
//         getMenuInflater().inflate(R.menu.dmails, menu);
//         this.menu = menu;
//         return true;
//     }
// 
//     @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);
//         outState.putInt(FORUMQUERYPAGE, page);
//     }
// 
//     @Override
//     void handleIntent(Intent intent) {
//         super.handleIntent(intent);
//         page = intent.getIntExtra(FORUMQUERYPAGE,1);
// 
//         if (results==null) searchPosts("", page);
//     }
// 
//     @Override void searchPosts(String escapedQuery, int page) {
//         API_URI = "dmail/inbox.xml?page="+page;
//         API_LOGIN = true;
// 
//         super.searchPosts(escapedQuery, page);
//     }
// 
//     @Override void onSearchResult(XMLNode result, String query, int page) {
//         results = new DMailListAdapter(getApplicationContext(), R.id.lblTitle, result.getChildren());
//         //results.svNumPosts = (result.attributes().contains("count") ? Integer.valueOf(result.getAttribute("count")) : 0); //this value is not provided
//         DMailsActivity.this.page = page;
// 
//         ActionBar ab = getSupportActionBar();
//         ab.setTitle(getResources().getString(R.string.title_dmail) + " | " + page);
//         //setTitle(getResources().getString(R.string.title_posts) + " " + _page + (_query.equals("")?" | *":" | "+XMLUtils.unescapeXML(_query)));
//     }
// 
// }


// Path: src/main/java/de/e621/rebane/service/DMailService.java
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.itwookie.XMLreader.XMLNode;
import com.itwookie.XMLreader.XMLReader;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import de.e621.rebane.a621.R;
import de.e621.rebane.activities.DMailsActivity;

            urlc.setRequestMethod("GET");
            urlc.setChunkedStreamingMode(256);
            urlc.setConnectTimeout(15000);
            urlc.setReadTimeout(15000);
            urlc.setUseCaches(false);
            InputStream bis = urlc.getInputStream();
            Logger.getLogger("a621").info("Background - Connected with response code " + urlc.getResponseCode() + ": " + urlc.getResponseMessage());

            result = (new XMLReader()).parse(bis);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (result != null) {
            int cnt = 0;
            StringBuilder cont = new StringBuilder();
            for (XMLNode msg : result.getChildren()) {
                if (!msg.getType().equals("dmail")) {
                    cnt = 0;
                    break;
                }
                //Logger.getLogger("a621").info ("DMail: " + msg.toString());
                Boolean seen = Boolean.parseBoolean(msg.getFirstChildContent("has-seen").orElse(""));
                if (!seen) {
                    cnt++;
                    cont.append(msg.getFirstChildContent("title").orElse("") + " \n");
                }
            }
            if (cnt > 0) {
                NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


                Intent dmail = new Intent(getApplicationContext(), DMailsActivity.class);
