News download.
This commit is contained in:
parent
1388e55ae7
commit
563d17890a
@ -8,6 +8,7 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.StrictMode;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@ -409,6 +410,8 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
Miscellaneous.logEvent("i", "ActivityMainScreen", "Activity not running. No need to update.", 5);
|
Miscellaneous.logEvent("i", "ActivityMainScreen", "Activity not running. No need to update.", 5);
|
||||||
|
|
||||||
|
activityMainScreenInstance.checkForNews();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -562,7 +565,9 @@ public class ActivityMainScreen extends ActivityGeneric
|
|||||||
|
|
||||||
void checkForNews()
|
void checkForNews()
|
||||||
{
|
{
|
||||||
String newsUrl = "https://server47.de/automation/appNews.php";
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
String newsContent = Miscellaneous.downloadURL(newsUrl, null, null);
|
|
||||||
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
News.downloadNews();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -937,6 +937,23 @@ public class Miscellaneous extends Service
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean restrictedFeaturesConfigured()
|
||||||
|
{
|
||||||
|
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.activityDetection))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static Element getXmlTree(String inputString) throws SAXException, IOException, ParserConfigurationException
|
public static Element getXmlTree(String inputString) throws SAXException, IOException, ParserConfigurationException
|
||||||
{
|
{
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
@ -13,43 +13,89 @@ public class News
|
|||||||
String headline;
|
String headline;
|
||||||
String text;
|
String text;
|
||||||
Calendar publishDate;
|
Calendar publishDate;
|
||||||
|
String applicablePlattform;
|
||||||
|
|
||||||
public static ArrayList<News> extractNewsFromString()
|
public static ArrayList<News> downloadNews()
|
||||||
{
|
{
|
||||||
String result =
|
String newsUrl = "https://server47.de/automation/appNews.php";
|
||||||
Miscellaneous.messageBox(title, text, ActivityMainScreen.getActivityMainScreenInstance());
|
String newsContent = Miscellaneous.downloadURL(newsUrl, null, null);
|
||||||
|
|
||||||
Element homeControlRootElement = Miscellaneous.getXmlTree(inventoryString);
|
ArrayList<News> returnList = new ArrayList<>();
|
||||||
if(homeControlRootElement.getAttribute("protocolVersion").equals(String.valueOf(requiredProtocolVersion)))
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
FullDataModel.getInstance().houseList = new ArrayList<HouseTemplate>();
|
Element automationRootElement = Miscellaneous.getXmlTree(newsContent);
|
||||||
// FullDataModel.getInstance().roomList = new ArrayList<RoomTemplate>();
|
|
||||||
FullDataModel.getInstance().nodeList = new ArrayList<NodeTemplate>();
|
|
||||||
// FullDataModel.getInstance().deviceList = new ArrayList<DeviceTemplate>();
|
|
||||||
FullDataModel.getInstance().commandsList = new ArrayList<CommandTemplate>();
|
|
||||||
FullDataModel.getInstance().deviceGroupList = new ArrayList<DeviceGroupTemplate>();
|
|
||||||
// FullDataModel.getInstance().sensorList = new ArrayList<SensorTemplate>();
|
|
||||||
FullDataModel.getInstance().ruleList = new ArrayList<RuleTemplate>();
|
|
||||||
FullDataModel.getInstance().userList = new ArrayList<UserTemplate>();
|
|
||||||
FullDataModel.getInstance().userDeviceList = new ArrayList<UserDeviceTemplate>();
|
|
||||||
|
|
||||||
NodeList responseElements = homeControlRootElement.getElementsByTagName("response");
|
NodeList newsEntriesElements = automationRootElement.getElementsByTagName("newsEntries");
|
||||||
Node responseElement = responseElements.item(0);
|
|
||||||
|
|
||||||
NodeList nodeElementsHouses = homeControlRootElement.getElementsByTagName("houses");
|
NodeList newsEntryElements = ((Element)newsEntriesElements.item(0)).getElementsByTagName("newsEntry");
|
||||||
for(int i = 0; i < nodeElementsHouses.getLength(); i++)
|
|
||||||
|
for (int i = 0; i < newsEntryElements.getLength(); i++)
|
||||||
{
|
{
|
||||||
if(nodeElementsHouses.item(i).getNodeType() == Node.ELEMENT_NODE && (nodeElementsHouses.item(i).getParentNode().isSameNode(homeControlRootElement) | nodeElementsHouses.item(i).getParentNode().isSameNode(responseElement)))
|
if (newsEntryElements.item(i).getNodeType() == Node.ELEMENT_NODE && (newsEntryElements.item(i).getParentNode().isSameNode(((Element)newsEntriesElements.item(0)))))
|
||||||
{
|
{
|
||||||
NodeList nodeElementsHousesInd = nodeElementsHouses.item(i).getChildNodes();
|
News newsEntry = new News();
|
||||||
for(int j = 0; j < nodeElementsHousesInd.getLength(); j++)
|
|
||||||
{
|
Element neEl = (Element)newsEntryElements.item(i);
|
||||||
Element houseElement = (Element) nodeElementsHousesInd.item(j);
|
newsEntry.setHeadline(neEl.getElementsByTagName("headline").item(0).getTextContent());
|
||||||
HouseTemplate house = HouseTemplate.fromXmlStringStatic(Diverse.xmlToString(houseElement, true, false));
|
newsEntry.setText(neEl.getElementsByTagName("text").item(0).getTextContent());
|
||||||
FullDataModel.getInstance().houseList.add(house);
|
|
||||||
}
|
String publishDateString = neEl.getElementsByTagName("publishDate").item(0).getTextContent();
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTimeInMillis(Long.parseLong(publishDateString));
|
||||||
|
newsEntry.setPublishDate(cal);
|
||||||
|
|
||||||
|
newsEntry.setText(neEl.getElementsByTagName("applicablePlattforms").item(0).getTextContent());
|
||||||
|
|
||||||
|
returnList.add(newsEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHeadline()
|
||||||
|
{
|
||||||
|
return headline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeadline(String headline)
|
||||||
|
{
|
||||||
|
this.headline = headline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText()
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text)
|
||||||
|
{
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Calendar getPublishDate()
|
||||||
|
{
|
||||||
|
return publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishDate(Calendar publishDate)
|
||||||
|
{
|
||||||
|
this.publishDate = publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApplicablePlattform()
|
||||||
|
{
|
||||||
|
return applicablePlattform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicablePlattform(String applicablePlattform)
|
||||||
|
{
|
||||||
|
this.applicablePlattform = applicablePlattform;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user