Splitted State activity in 2 +

Fixed app crashing issue when opening Pix-Art messenger
This commit is contained in:
massimiliano 2018-12-09 18:42:42 +01:00
parent bf12408e3c
commit 2ec49072d3
14 changed files with 451 additions and 83 deletions

View File

@ -46,6 +46,14 @@
android:label="@string/title_activity_about"
android:theme="@style/DisTheme" />
<activity android:name=".ui.WelcomeActivity" />
<activity
android:name=".ui.StateActivity"
android:label="@string/title_activity_state"
android:theme="@style/DisTheme" />
<activity
android:name=".ui.StateMessagesActivity"
android:label="@string/title_activity_state"
android:theme="@style/DisTheme" />
<activity
android:name="wsdfhjxc.taponium.MainActivity"
android:label="@string/title_activity_tap"
@ -56,14 +64,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.StateActivity"
android:label="@string/title_activity_state"
android:theme="@style/DisTheme" />
<activity
android:name=".ui.Tabbed_state"
android:label="@string/title_activity_tabbed_state"
android:theme="@style/DisTheme"></activity>
</application>
</manifest>

View File

@ -287,6 +287,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLongClickL
/* if((xmpp1 == null)&&(xmpp2 != null)) { */
if((xmpp1 == null)&&(xmpp2 != null)) {//if(xmpp1 == null) {
startActivity(xmpp2);
return;
}
//need to change to give user choise || check.getBoolean("checkPix",false)
if((xmpp1 != null)&&(xmpp2 != null)) {

View File

@ -2,14 +2,18 @@ package org.disroot.disrootapp.ui;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
@ -27,7 +31,9 @@ import java.util.HashMap;
public class StateActivity extends AppCompatActivity {
private String TAG = MainActivity.class.getSimpleName();
Button button;
private String TAG = StateActivity.class.getSimpleName();
private ProgressDialog pDialog;
private ListView lv;
@ -35,7 +41,6 @@ public class StateActivity extends AppCompatActivity {
// 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 incidenturl0 ="https://state.disroot.org/api/v1/incidents?sort=id&order=desc";
ArrayList<HashMap<String, String>> stateList;
@ -54,6 +59,16 @@ public class StateActivity extends AppCompatActivity {
}
});
button = findViewById(R.id.StateMessageBtn);//StateMessageBtn
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent goState = new Intent(StateActivity.this, StateMessagesActivity.class);
StateActivity.this.startActivity(goState);
}
});
stateList = new ArrayList<>();
lv = findViewById(R.id.list);
@ -61,6 +76,32 @@ public class StateActivity extends AppCompatActivity {
new GetList().execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_about, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_home) {
Intent goHome = new Intent(StateActivity.this, MainActivity.class);
StateActivity.this.startActivity(goHome);
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Async task class to get json by making HTTP call
*/
@ -84,7 +125,6 @@ public class StateActivity extends AppCompatActivity {
// Making a request to url and getting response
String jsonStr0 = sh.makeServiceCall(url);
String jsonStr1 = sh.makeServiceCall(url1);
String jsonStrincidents0 = sh.makeServiceCall(incidenturl0);
Log.e(TAG, "Response from url: " + jsonStr0);
@ -174,51 +214,6 @@ public class StateActivity extends AppCompatActivity {
}
});
}
} if (jsonStrincidents0 != null) {//Incidaetnts page
try {
JSONObject jsonObj = new JSONObject(jsonStrincidents0);
// Getting JSON Array node
JSONArray data = jsonObj.getJSONArray("data");
// looping through All data
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String id = c.getString("id");
String name = c.getString("name");
String message = c.getString("message");
String scheduled_at = c.getString("scheduled_at");
String updated_at = c.getString("updated_at");
String lastUpdated = "Last Updated: " + updated_at;
String human_status = c.getString("human_status");
// tmp hash map for single service
HashMap<String, String> service = new HashMap<>();
// adding each child node to HashMap key => value
service.put("id", id);
service.put("name", name);
service.put("message", message);
service.put("scheduled_at", scheduled_at);
service.put("updated_at", lastUpdated);
service.put("human_status", human_status);
// adding service to service list
stateList.add(service);
}
} 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() {
@ -244,9 +239,9 @@ public class StateActivity extends AppCompatActivity {
//Updating parsed JSON data into ListView
ListAdapter adapter = new SimpleAdapter(
StateActivity.this, stateList,
R.layout.list_item, new String[]{"name","message", "description", "updated_at", "scheduled_at",
"status_name", "human_status"}, new int[]{R.id.name, R.id.message,
R.id.description,R.id.updated_at, R.id.scheduled_at, R.id.status_name, R.id.human_status})
R.layout.list_item, new String[]{"name", "description", "updated_at",
"status_name"}, new int[]{R.id.name,
R.id.description,R.id.updated_at, R.id.status_name})
//Change Color based on Status
{
@ -305,22 +300,6 @@ public class StateActivity extends AppCompatActivity {
status.setText(R.string.PerformanceIssues);
status.setTextColor(Color.YELLOW);
break;
}//Human_status
TextView humanStatus = v.findViewById(R.id.human_status);
String humanStatusValue = humanStatus.getText().toString();
switch (humanStatusValue) {
case "Fixed":
case "Scheduled":
humanStatus.setTextColor(Color.GREEN);
break;
case "Investigating":
case "Watching":
humanStatus.setTextColor(Color.YELLOW);
break;
case "Identified":
humanStatus.setTextColor(Color.RED);
break;
}
return v;
}

View File

@ -0,0 +1,272 @@
package org.disroot.disrootapp.ui;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.disroot.disrootapp.R;
import org.disroot.disrootapp.utils.HttpHandler;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class StateMessagesActivity extends AppCompatActivity {
Button button;
private String TAG = StateMessagesActivity.class.getSimpleName();
private ProgressDialog pDialog;
private ListView lv;
// URL to get data JSON
static String incidenturl0 ="https://state.disroot.org/api/v1/incidents?sort=id&order=desc";
ArrayList<HashMap<String, String>> messageList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_state_messages);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
button = findViewById(R.id.StateBtn);//StateBtn
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent goState = new Intent(StateMessagesActivity.this, StateActivity.class);
StateMessagesActivity.this.startActivity(goState);
}
});
messageList = new ArrayList<>();
lv = findViewById(R.id.list);
new GetList().execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_about, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_home) {
Intent goHome = new Intent(StateMessagesActivity.this, MainActivity.class);
StateMessagesActivity.this.startActivity(goHome);
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Async task class to get json by making HTTP call
*/
@SuppressLint("StaticFieldLeak")
class GetList extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(StateMessagesActivity.this);
pDialog.setMessage("Loading…");
pDialog.setCancelable(false);
pDialog.show();
}
@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");
// looping through All data
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String id = c.getString("id");
String name = c.getString("name");
String message = c.getString("message");
String scheduled_at = c.getString("scheduled_at");
String scheduledAt = "Scheduled at: " + scheduled_at;
String updated_at = c.getString("updated_at");
String lastUpdated = "Last Updated: " + updated_at;
String human_status = c.getString("human_status");
// tmp hash map for single service
HashMap<String, String> service = new HashMap<>();
// adding each child node to HashMap key => value
service.put("id", id);
service.put("name", name);
service.put("message", message);
service.put("scheduled_at", scheduledAt);
service.put("updated_at", lastUpdated);
service.put("human_status", human_status);
// adding service to service list
messageList.add(service);
}
} 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;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
//Updating parsed JSON data into ListView
ListAdapter adapter = new SimpleAdapter(
StateMessagesActivity.this, messageList,
R.layout.list_item, new String[]{"name","message", "updated_at", "scheduled_at", "human_status"}, new int[]{R.id.name, R.id.message,
R.id.updated_at, R.id.scheduled_at, R.id.human_status})
//Change Color based on Status
{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
//Name Email
TextView nameMail = v.findViewById(R.id.name);
String nameMailValue = nameMail.getText().toString();
switch (nameMailValue) {
case "Email Service":
nameMail.setText(R.string.EmailService);
break;
default:
break;
}
//Name WebMail
TextView nameWebmail = v.findViewById(R.id.name);
String nameWebmailValue = nameWebmail.getText().toString();
switch (nameWebmailValue) {
case "WebMail Service":
nameWebmail.setText(R.string.WebmailService);
break;
default:
break;
}
//Name Cloud
TextView nameCloud = v.findViewById(R.id.name);
String nameCloudValue = nameCloud.getText().toString();
switch (nameCloudValue) {
case "WebMail Service":
nameCloud.setText(R.string.Cloud);
break;
default:
break;
}
//Make Last updated translatable
TextView updated = v.findViewById(R.id.updated_at);
String updatedValue = updated.getText().toString();
if (updatedValue.startsWith("Last Updated: ")){
updated.setText(updatedValue.replace("Last Updated: ",getText(R.string.LastUpdated)));
}
//Make Scheduled at translatable
TextView scheduled = v.findViewById(R.id.scheduled_at);
String scheduledValue = scheduled.getText().toString();
if (scheduledValue.startsWith("Scheduled at: ")){
scheduled.setText(scheduledValue.replace("Scheduled at: ",getText(R.string.ScheduledAt)));
}
//Human_status
TextView humanStatus = v.findViewById(R.id.human_status);
String humanStatusValue = humanStatus.getText().toString();
switch (humanStatusValue) {
case "Fixed":
case "Scheduled":
humanStatus.setTextColor(Color.GREEN);
break;
case "Investigating":
case "Watching":
humanStatus.setTextColor(Color.YELLOW);
break;
case "Identified":
humanStatus.setTextColor(Color.RED);
break;
}
return v;
}
};
lv.setAdapter(adapter);
}
}
}

View File

@ -26,6 +26,36 @@
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#203140">
<Button
android:id="@+id/StateBtn"
android:shadowColor="@color/bg_primary_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="24dp"
android:drawableTop="@drawable/ic_state"
android:text="@string/state_btn"
android:layout_gravity="center"
android:layout_marginHorizontal="@android:dimen/app_icon_size"
style="?android:attr/borderlessButtonStyle"
android:textColor="#ffffff"/>
<Button
android:id="@+id/StateMessageBtn"
android:shadowColor="@color/bg_primary_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="24dp"
android:drawableTop="@drawable/ic_state"
android:text="@string/state_messages_btn"
android:layout_gravity="center"
android:layout_marginHorizontal="@android:dimen/app_icon_size"
style="?android:attr/borderlessButtonStyle"
android:textColor="#ffffff"/>
</android.support.v7.widget.LinearLayoutCompat>
<ListView
android:id="@+id/list"

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".ui.StateActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/DisTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/DisTheme.PopupOverlay"
app:title="@string/app_name">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#203140">
<Button
android:id="@+id/StateBtn"
android:shadowColor="@color/bg_primary_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="24dp"
android:drawableTop="@drawable/ic_state"
android:text="@string/state_btn"
android:layout_gravity="center"
android:layout_marginHorizontal="@android:dimen/app_icon_size"
style="?android:attr/borderlessButtonStyle"
android:textColor="#ffffff"/>
<Button
android:id="@+id/StateMessageBtn"
android:shadowColor="@color/bg_primary_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="24dp"
android:drawableTop="@drawable/ic_state"
android:text="@string/state_messages_btn"
android:layout_gravity="center"
android:layout_marginHorizontal="@android:dimen/app_icon_size"
style="?android:attr/borderlessButtonStyle"
android:textColor="#ffffff"/>
</android.support.v7.widget.LinearLayoutCompat>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#203140"/>
</LinearLayout>

View File

@ -145,4 +145,7 @@
<string name="PerformanceIssues">Performance Issues</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="state_messages_btn">Show State messages</string>
<string name="state_btn">Show Service State</string>
<string name="ScheduledAt">Scheduled at:</string>
</resources>

View File

@ -174,4 +174,7 @@
<string name="PerformanceIssues">Performance Issues</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="state_messages_btn">Show State messages</string>
<string name="state_btn">Show Service State</string>
<string name="ScheduledAt">Scheduled at:</string>
</resources>

View File

@ -142,6 +142,9 @@
<string name="WebmailService">Servizio WebMail</string>
<string name="Cloud">Cloud</string>
<string name="PerformanceIssues">Problemi di performanza</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="Notification">Nessun problema con i servizi</string>
<string name="Notificationissues">Alcuni sistemi stanno avendo dei problemi</string>
<string name="state_messages_btn">Mostra messaggi di stato</string>
<string name="state_btn">Mostra stato dei servizi</string>
<string name="ScheduledAt">In programma il: \</string>
</resources>

View File

@ -143,6 +143,9 @@
<string name="WebmailService">WebMail Service</string>
<string name="Cloud">Cloud</string>
<string name="PerformanceIssues">Prestatieproblemen</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="Notification">Geen problemen</string>
<string name="Notificationissues">Sommige systemen ondervinden problemen</string>
<string name="state_messages_btn">Toon statusberichten</string>
<string name="state_btn">Toon Service Status</string>
<string name="ScheduledAt">Gepland op: \</string>
</resources>

View File

@ -144,4 +144,7 @@
<string name="PerformanceIssues">Performance Issues</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="state_messages_btn">Show State messages</string>
<string name="state_btn">Show Service State</string>
<string name="ScheduledAt">Scheduled at:</string>
</resources>

View File

@ -145,4 +145,7 @@
<string name="PerformanceIssues">Performance Issues</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="state_messages_btn">Show State messages</string>
<string name="state_btn">Show Service State</string>
<string name="ScheduledAt">Scheduled at:</string>
</resources>

View File

@ -139,13 +139,13 @@
<string name="Operational">Operational</string>
<string name="MajorOutage">Major Outage</string>
<string name="EmailService">Email Service</string>
<string name="LastUpdated">"Last updated: "</string>
<string name="LastUpdated">"Last updated: \"</string>
<string name="WebmailService">WebMail Service</string>
<string name="Cloud">Cloud</string>
<string name="PerformanceIssues">Performance Issues</string>
<string name="Notification">No issues</string>
<string name="Notificationissues">Some systems are experiencing issues</string>
<string name="title_activity_main2">Main2Activity</string>
<string name="section_format">Hello World from section: %1$d</string>
<string name="title_activity_tabbed_state">tabbed_state</string>
<string name="state_messages_btn">Show State messages</string>
<string name="state_btn">Show Service State</string>
<string name="ScheduledAt">Scheduled at: \</string>
</resources>

View File

@ -2,6 +2,8 @@
<changelog>
<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>Fixed app crashing when launching Pix-art messenger</change>
</release>
<release version="1.0.2" versioncode="12" >
<change>Third partie cookies disabled</change>