Diff of /app/src/main/java/com/codesys/forge/MyService.java [cd5981] .. [4c8954]  Maximize  Restore

Switch to unified view

a/app/src/main/java/com/codesys/forge/MyService.java b/app/src/main/java/com/codesys/forge/MyService.java
...
...
97
                .setContentIntent(pendingIntent)
97
                .setContentIntent(pendingIntent)
98
                ;
98
                ;
99
        notificationManager.notify(id, builder.build());
99
        notificationManager.notify(id, builder.build());
100
    }
100
    }
101
    protected void CheckForUpdatesAndNotify() {
101
    protected void CheckForUpdatesAndNotify() {
102
        new AsyncTask<Void, Void, String>() {
102
            String urlString = "https://forge.codesys.com/rest/forge/saml";
103
            @Override
104
            protected String doInBackground(Void... voids) {
105
                String urlString = "https://forge.codesys.com/rest/forge/saml";
106
                try {
103
            try {
107
                    URL url = new URL(urlString);
104
                URL url = new URL(urlString);
108
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
105
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
109
                    conn.setReadTimeout(10000 /* milliseconds */);
106
                conn.setReadTimeout(10000 /* milliseconds */);
110
                    conn.setConnectTimeout(15000 /* milliseconds */);
107
                conn.setConnectTimeout(15000 /* milliseconds */);
111
                    conn.setRequestMethod("GET");
108
                conn.setRequestMethod("GET");
112
                    conn.setDoInput(true);
109
                conn.setDoInput(true);
113
                    if (cookies != null)
110
                if (cookies != null)
114
                        conn.setRequestProperty("Cookie", cookies);
111
                    conn.setRequestProperty("Cookie", cookies);
115
                    conn.connect();
112
                conn.connect();
116
                    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
113
                BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
117
                    StringBuilder stringBuilder = new StringBuilder();
114
                StringBuilder stringBuilder = new StringBuilder();
118
115
119
                    String line = null;
116
                String line = null;
120
                    while ((line = reader.readLine()) != null)
117
                while ((line = reader.readLine()) != null)
121
                    {
118
                {
122
                        stringBuilder.append(line + "\n");
119
                    stringBuilder.append(line + "\n");
123
                    }
120
                }
124
                    String news = stringBuilder.toString();
121
                String news = stringBuilder.toString();
125
                    JSONObject obj = new JSONObject(news);
122
                JSONObject obj = new JSONObject(news);
126
                    for (int i=0; i < obj.getJSONArray("news").length(); i++)
123
                for (int i=0; i < obj.getJSONArray("news").length(); i++)
127
                    {
124
                {
128
                        String uri = obj.getJSONArray("news").getString(i);
125
                    String uri = obj.getJSONArray("news").getString(i);
129
                        switch(uri) {
126
                    switch(uri) {
130
                            case "/forge/community-feed/":
127
                        case "/forge/community-feed/":
131
                                CreateNotification(1);
128
                            CreateNotification(1);
132
                                break;
129
                            break;
133
                            case "/forge/news/":
130
                        case "/forge/news/":
134
                                CreateNotification(2);
131
                            CreateNotification(2);
135
                                break;
132
                            break;
136
                            case "/forge/talk/":
133
                        case "/forge/talk/":
137
                                CreateNotification(3);
134
                            CreateNotification(3);
138
                                break;
135
                            break;
139
                        }
136
                    }
140
                    }
137
                }
141
                    return news;
138
            }
142
                }
143
                catch(MalformedURLException e) {
139
            catch(MalformedURLException e) {
144
                    Log.e("get news", e.getLocalizedMessage());
140
                Log.e("get news", e.getLocalizedMessage());
145
                }
141
            }
146
                catch(IOException e) {
142
            catch(IOException e) {
147
                    Log.e("get news", e.getLocalizedMessage());
143
                Log.e("get news", e.getLocalizedMessage());
148
                }
144
            }
149
                catch(JSONException e) {
145
            catch(JSONException e) {
150
                    Log.e("get news", e.getLocalizedMessage());
146
                Log.e("get news", e.getLocalizedMessage());
151
                }
147
            }
152
                return "error";
153
            }
154
155
        }.execute();
156
157
    }
148
    }
158
    @Override
149
    @Override
159
    public void onCreate() {
150
    public void onCreate() {
160
        mContext = this;
151
        mContext = this;
161
        //Toast.makeText(mContext,"Service created",Toast.LENGTH_SHORT).show();
152
        //Toast.makeText(mContext,"Service created",Toast.LENGTH_SHORT).show();
...
...
175
    }
166
    }
176
167
177
    @Override
168
    @Override
178
    public int onStartCommand(Intent intent, int flags, int startId) {
169
    public int onStartCommand(Intent intent, int flags, int startId) {
179
        mRunning = true;
170
        mRunning = true;
180
        cookies = intent.getStringExtra("cookies");
171
        if (intent != null) {
172
            cookies = intent.getStringExtra("cookies");
173
        }
181
        return super.onStartCommand(intent, flags, startId);
174
        return super.onStartCommand(intent, flags, startId);
182
    }
175
    }
183
176
184
    @Override
177
    @Override
185
    public IBinder onBind(Intent arg0) {
178
    public IBinder onBind(Intent arg0) {