Service state sorted by status + if new post launch stateActivity
This commit is contained in:
parent
2ec49072d3
commit
445b4b6793
|
@ -1,9 +1,12 @@
|
|||
package org.disroot.disrootapp.ui;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -11,6 +14,7 @@ import android.content.pm.PackageManager;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -48,14 +52,22 @@ import android.widget.CheckBox;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import org.disroot.disrootapp.R;
|
||||
import org.disroot.disrootapp.utils.Constants;
|
||||
import org.disroot.disrootapp.utils.HttpHandler;
|
||||
import org.disroot.disrootapp.webviews.DisWebChromeClient;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -99,7 +111,14 @@ public class MainActivity extends AppCompatActivity implements View.OnLongClickL
|
|||
|
||||
private CookieManager cookieManager;
|
||||
|
||||
|
||||
//status report
|
||||
private ProgressDialog pDialog;
|
||||
private ListView lv;
|
||||
public SharedPreferences checkDate;
|
||||
// URL to get data JSON
|
||||
static String incidenturl0 ="https://state.disroot.org/api/v1/incidents?sort=id&order=desc";
|
||||
ArrayList<HashMap<String, String>> messageList;
|
||||
ArrayList<HashMap<String, String>> getDate;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -589,6 +608,16 @@ public class MainActivity extends AppCompatActivity implements View.OnLongClickL
|
|||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
//Status report
|
||||
messageList = new ArrayList<>();
|
||||
getDate = new ArrayList<>();
|
||||
|
||||
lv = findViewById(R.id.list);
|
||||
|
||||
checkDate = getSharedPreferences("storeDate", Context.MODE_PRIVATE);
|
||||
|
||||
new MainActivity.GetList().execute();
|
||||
}
|
||||
|
||||
//Dialog windows
|
||||
|
@ -1735,4 +1764,77 @@ public class MainActivity extends AppCompatActivity implements View.OnLongClickL
|
|||
intent.setType("text/plain");
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
//status report
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
class GetList extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... arg0) {
|
||||
HttpHandler sh = new HttpHandler();
|
||||
|
||||
// Making a request to url and getting response
|
||||
String jsonStrincidents0 = sh.makeServiceCall(incidenturl0);
|
||||
|
||||
Log.e(TAG, "Response from url: " + incidenturl0);
|
||||
|
||||
if (jsonStrincidents0 != null) {//Incidaetnts page
|
||||
try {
|
||||
JSONObject jsonObj = new JSONObject(jsonStrincidents0);
|
||||
|
||||
// Getting JSON Array node
|
||||
JSONArray data = jsonObj.getJSONArray("data");
|
||||
|
||||
//Make it sotre date and show state if new date is newer than stored date
|
||||
int a=0;
|
||||
JSONObject o = data.getJSONObject(a);
|
||||
String callid = o.getString("id");
|
||||
String updated = o.getString("updated_at");
|
||||
// tmp hash map for single service
|
||||
HashMap<String, String> date = new HashMap<>();
|
||||
// adding each child node to HashMap key => value
|
||||
date.put("id", callid);
|
||||
date.put("updated", updated);
|
||||
getDate.add(date);
|
||||
String stateDate = date.put( "updated", updated );
|
||||
String dateStored= checkDate.getString( "storeDate","" );
|
||||
if (!stateDate.equals( dateStored ))
|
||||
{
|
||||
checkDate.edit().putString( "storeDate", stateDate).apply();
|
||||
Log.e(TAG, "date: " + dateStored);
|
||||
Log.e(TAG, "date2: " + stateDate);
|
||||
Intent goState = new Intent(MainActivity.this, StateMessagesActivity.class);
|
||||
MainActivity.this.startActivity(goState);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
|
||||
} catch (final JSONException e) {
|
||||
Log.e(TAG, "Json parsing error: " + e.getMessage());
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Json parsing error: " + e.getMessage(),
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}else {
|
||||
Log.e(TAG, "Couldn't get json from server.");
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Couldn't get json from server. Check LogCat for possible errors!",
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ public class StateActivity extends AppCompatActivity {
|
|||
private ListView lv;
|
||||
|
||||
// URL to get data JSON
|
||||
static String url = "https://state.disroot.org/api/v1/components";
|
||||
static String url1 = "https://state.disroot.org/api/v1/components?page=2";
|
||||
static String url = "https://state.disroot.org/api/v1/components?sort=status";
|
||||
static String url1 = "https://state.disroot.org/api/v1/components?sort=status&page=2";
|
||||
|
||||
ArrayList<HashMap<String, String>> stateList;
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ package org.disroot.disrootapp.ui;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -26,6 +28,7 @@ import org.json.JSONArray;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
@ -36,11 +39,13 @@ public class StateMessagesActivity extends AppCompatActivity {
|
|||
|
||||
private ProgressDialog pDialog;
|
||||
private ListView lv;
|
||||
//SharedPreferences checkDate;
|
||||
|
||||
// URL to get data JSON
|
||||
static String incidenturl0 ="https://state.disroot.org/api/v1/incidents?sort=id&order=desc";
|
||||
|
||||
ArrayList<HashMap<String, String>> messageList;
|
||||
ArrayList<HashMap<String, String>> getDate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -68,9 +73,12 @@ public class StateMessagesActivity extends AppCompatActivity {
|
|||
});
|
||||
|
||||
messageList = new ArrayList<>();
|
||||
getDate = new ArrayList<>();
|
||||
|
||||
lv = findViewById(R.id.list);
|
||||
|
||||
//checkDate = getSharedPreferences("storeDate", Context.MODE_PRIVATE);
|
||||
|
||||
new GetList().execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<release version="1.0.2" versioncode="12" >
|
||||
<change>State page is api based instead of webview</change>
|
||||
<change>In State page is possible to view state messages</change>
|
||||
<change>State page is ordered by status</change>
|
||||
<change>Fixed app crashing when launching Pix-art messenger</change>
|
||||
</release>
|
||||
<release version="1.0.2" versioncode="12" >
|
||||
|
|
Loading…
Reference in New Issue