Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f641f5749c | ||
|
|
a0458b963c | ||
|
|
3403907775 | ||
|
|
768bb996d9 | ||
|
|
a008d3612b | ||
|
|
6bb9330a20 | ||
|
|
ec384792fa | ||
|
|
a954034c72 | ||
|
|
832ce77f74 | ||
|
|
9ea731af06 | ||
|
|
6763e2eefd | ||
|
|
7786e594f2 | ||
|
|
a5c4ff33aa | ||
|
|
9e38572e8e | ||
|
|
015fdf713c | ||
|
|
0d67b29189 | ||
|
|
886b175084 | ||
|
|
799ad2c5b8 | ||
|
|
471bfa3c34 | ||
|
|
4fd35d8a8d | ||
|
|
0d3bf7a991 | ||
|
|
9b7360752d | ||
|
|
ae3483761c | ||
|
|
1854752d92 | ||
|
|
7b85810c29 | ||
|
|
5ff779aee4 | ||
|
|
a7c4480464 | ||
|
|
96a266c728 | ||
|
|
99e4b284bb | ||
|
|
25a810df05 | ||
|
|
66bed8c89f | ||
|
|
07e85b6f32 | ||
|
|
50c17ab504 | ||
|
|
735fc4191a | ||
|
|
1a8d471b3f | ||
|
|
3885c13007 | ||
|
|
d01cbd2d81 | ||
|
|
096d960c76 | ||
|
|
b681b0fa11 | ||
|
|
42a1e4b530 | ||
|
|
1eec320528 | ||
|
|
3efa42facb | ||
|
|
f2ba86687a | ||
|
|
92873bed80 | ||
|
|
cfaab5263e | ||
|
|
b083863b08 | ||
|
|
9e5b70fe70 | ||
|
|
5d5f1b7f1c | ||
|
|
aae820834b | ||
|
|
2635ee890d | ||
|
|
136b969add | ||
|
|
54a455ea24 | ||
|
|
9f938ef016 | ||
|
|
8a924840dd | ||
|
|
a5cfabbfd2 | ||
|
|
89487dd6ec | ||
|
|
fb8518fcb0 | ||
|
|
31e7af3097 | ||
|
|
373748cb9c | ||
|
|
1827b964ed | ||
|
|
b1e144df73 | ||
|
|
6bdc8fe3ea | ||
|
|
018287ee6b | ||
|
|
49d6925da8 | ||
|
|
0932fdd0b8 | ||
|
|
094f98b46b | ||
|
|
968d827fc2 | ||
|
|
82bd2fc466 | ||
|
|
9ca8a38360 | ||
|
|
ddef7184b8 | ||
|
|
91238440f7 | ||
|
|
9cb8bfe2f0 | ||
|
|
5f8cca15fa | ||
|
|
128c01e68d | ||
|
|
0f42047f50 | ||
|
|
2f58a3d287 | ||
|
|
b0252b1676 | ||
|
|
da424dc70b | ||
|
|
348462a10c | ||
|
|
b4cc029716 | ||
|
|
9fef73eb7a | ||
|
|
cc0f95af91 | ||
|
|
1d6e0cc64c | ||
|
|
bd838657e4 | ||
|
|
af9f3f63fe | ||
|
|
9b5ee375b9 | ||
|
|
149de17617 | ||
|
|
fc9c0e7b55 | ||
|
|
9094db9df9 | ||
|
|
1ce515ed9f | ||
|
|
ee26a8180b | ||
|
|
85a250bcf4 | ||
|
|
6bfc0c8de0 | ||
|
|
ef5ea9391d | ||
|
|
ee5435ae3d | ||
|
|
c5c711a28a | ||
|
|
0087b6263c | ||
|
|
0c8607112c | ||
|
|
073bc0bb94 | ||
|
|
002589e54d | ||
|
|
11ee74fa2e | ||
|
|
6f9a22c517 | ||
|
|
de7da597a4 | ||
|
|
2e8871d22e | ||
|
|
eb60289066 | ||
|
|
687eb76d4f | ||
|
|
57ee5e1748 | ||
|
|
8f7d88bcdd | ||
|
|
3544e31198 | ||
|
|
9ee69a56ac | ||
|
|
63b23ef902 | ||
|
|
fa88d592cb | ||
|
|
9a06bb2630 | ||
|
|
f18dbb57bd | ||
|
|
d3e56e9e0f | ||
|
|
2e5d06d9af | ||
|
|
4d21dea4cd | ||
|
|
e4603a231e | ||
|
|
316df58af6 | ||
|
|
35516af52b | ||
|
|
3bded2af7a | ||
|
|
2c788e3329 | ||
|
|
af2409a16d | ||
|
|
7e390ed56f | ||
|
|
756a816abb | ||
|
|
1e174f77f7 | ||
|
|
ae8e1ddb82 | ||
|
|
9381065cf2 | ||
|
|
98b4ee71ae | ||
|
|
1b84c6fc15 | ||
|
|
ad9fb99205 | ||
|
|
4fdbf10054 | ||
|
|
3505c379cf | ||
|
|
6322022f47 | ||
|
|
adf60f289b | ||
|
|
27ccac205b | ||
|
|
664a7d4cea | ||
|
|
49137e111b | ||
|
|
c834551c52 | ||
|
|
91d5a7be50 | ||
|
|
552c2215c3 | ||
|
|
2e9597f34d | ||
|
|
ec6f25e11b | ||
|
|
f871761e48 | ||
|
|
60bbfceb7e | ||
|
|
0ce1657c0a | ||
|
|
035aebe741 | ||
|
|
a829aa01df | ||
|
|
76315eedc3 | ||
|
|
108df0d614 | ||
|
|
449e128373 | ||
|
|
be53bc8cfa | ||
|
|
70f8c27341 | ||
|
|
f27c43bf92 | ||
|
|
5a9e73b72f | ||
|
|
f2c98815ff | ||
|
|
99abe5e86e | ||
|
|
55a8c55aba | ||
|
|
16c31df0bf | ||
|
|
10feb5d6aa | ||
|
|
f8371a4b0a | ||
|
|
f8ed7dfac4 | ||
|
|
5b0f0bef32 | ||
|
|
c207f5470a | ||
|
|
1002351f2d | ||
|
|
dd4cc41740 | ||
|
|
3f43df52e9 | ||
|
|
de8ad98f8d | ||
|
|
0fc0605a85 | ||
|
|
326e56a24c | ||
|
|
6f388520f5 | ||
|
|
c8a52eec58 | ||
|
|
e568f43dd7 | ||
|
|
22ccdd21ac | ||
|
|
6137fface2 | ||
|
|
4588941a40 | ||
|
|
b943eb2028 | ||
|
|
80e7a3e800 | ||
|
|
51f941f68e | ||
|
|
43a966e81f | ||
|
|
e455bec77b | ||
|
|
a7c4e82050 | ||
|
|
40b2a25633 | ||
|
|
34dccea36f | ||
|
|
0c3188dec0 | ||
|
|
21300cb695 | ||
|
|
5afec93cbf | ||
|
|
482c4cb1e5 | ||
|
|
40794ccc88 | ||
|
|
f27f0d39b0 | ||
|
|
5acfb36369 | ||
|
|
38573fdc85 | ||
|
|
a5ba028d55 | ||
|
|
dfa6288272 | ||
|
|
b62f6510bb | ||
|
|
5d8539282a | ||
|
|
e79315ba9f | ||
|
|
a175a98236 | ||
|
|
1f619a93db | ||
|
|
9f596c4f2c | ||
|
|
e3105027ae |
@@ -1,485 +0,0 @@
|
||||
<code_scheme name="DefaultIntelliJCodeStyleCST" version="173">
|
||||
<option name="OTHER_INDENT_OPTIONS">
|
||||
<value>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="LINE_SEPARATOR" value="
" />
|
||||
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
|
||||
<option name="RIGHT_MARGIN" value="200" />
|
||||
<option name="HTML_KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="HTML_KEEP_LINE_BREAKS_IN_TEXT" value="false" />
|
||||
<option name="HTML_INLINE_ELEMENTS" value="a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,kbd,label,q,s,samp,select,span,strike,strong,sub,sup,textarea,tt,u,var" />
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<CssCodeStyleSettings>
|
||||
<option name="HEX_COLOR_LOWER_CASE" value="true" />
|
||||
<option name="HEX_COLOR_LONG_FORMAT" value="true" />
|
||||
</CssCodeStyleSettings>
|
||||
<HTMLCodeStyleSettings>
|
||||
<option name="HTML_KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="HTML_KEEP_LINE_BREAKS_IN_TEXT" value="false" />
|
||||
<option name="HTML_INLINE_ELEMENTS" value="abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,kbd,q,s,samp,span,strike,strong,sub,sup,textarea,tt,u,var" />
|
||||
</HTMLCodeStyleSettings>
|
||||
<JavaeeCodeStyleSettings>
|
||||
<option name="ENTITY_VO_SUFFIX" value="DTO" />
|
||||
</JavaeeCodeStyleSettings>
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="hpp" fileNamingConvention="LOWERCASE" />
|
||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
<Properties>
|
||||
<option name="KEEP_BLANK_LINES" value="true" />
|
||||
</Properties>
|
||||
<TypeScriptCodeStyleSettings version="0">
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
||||
<option name="OBJECT_LITERAL_WRAP" value="1" />
|
||||
</TypeScriptCodeStyleSettings>
|
||||
<XML>
|
||||
<option name="XML_TEXT_WRAP" value="0" />
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="CFML">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="CMake">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="CSS">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="CoffeeScript">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="8" />
|
||||
<option name="TAB_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="DB2">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Derby">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="ECMA Script Level 4">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="GSP">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Gherkin">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Groovy">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="H2">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="HAML">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="HSQLDB">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="HTML">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Haml">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||
<option name="WHILE_ON_NEW_LINE" value="true" />
|
||||
<option name="CATCH_ON_NEW_LINE" value="true" />
|
||||
<option name="FINALLY_ON_NEW_LINE" value="true" />
|
||||
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
|
||||
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
|
||||
<option name="WRAP_COMMENTS" value="true" />
|
||||
<option name="ENUM_CONSTANTS_WRAP" value="1" />
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<groups>
|
||||
<group>
|
||||
<type>GETTERS_AND_SETTERS</type>
|
||||
<order>KEEP</order>
|
||||
</group>
|
||||
<group>
|
||||
<type>OVERRIDDEN_METHODS</type>
|
||||
<order>KEEP</order>
|
||||
</group>
|
||||
<group>
|
||||
<type>DEPENDENT_METHODS</type>
|
||||
<order>DEPTH_FIRST</order>
|
||||
</group>
|
||||
</groups>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD>true</FIELD>
|
||||
<FINAL>true</FINAL>
|
||||
<STATIC>true</STATIC>
|
||||
<visibility />
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD>true</FIELD>
|
||||
<STATIC>true</STATIC>
|
||||
<visibility />
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD>true</FIELD>
|
||||
<FINAL>true</FINAL>
|
||||
<visibility />
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<FIELD>true</FIELD>
|
||||
<visibility />
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<CONSTRUCTOR>true</CONSTRUCTOR>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD>true</METHOD>
|
||||
<NAME>main</NAME>
|
||||
<PUBLIC>true</PUBLIC>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<ABSTRACT>true</ABSTRACT>
|
||||
<METHOD>true</METHOD>
|
||||
<visibility />
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<ABSTRACT>false</ABSTRACT>
|
||||
<METHOD>true</METHOD>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<METHOD>true</METHOD>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<ENUM>true</ENUM>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<INTERFACE>true</INTERFACE>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<CLASS>true</CLASS>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<CLASS>true</CLASS>
|
||||
<STATIC>true</STATIC>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JSON">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JSP">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JSPX">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JavaScript">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="LESS">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="MySQL">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="ObjectiveC">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Oracle">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="PostgreSQL">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Puppet">
|
||||
<indentOptions>
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="RHTML">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="8" />
|
||||
<option name="TAB_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="SASS">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="SCSS">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="SQL">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="SQLite">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Stylus">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Sybase">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="TSQL">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="TypeScript">
|
||||
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||
<option name="CATCH_ON_NEW_LINE" value="true" />
|
||||
<option name="FINALLY_ON_NEW_LINE" value="true" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="1" />
|
||||
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
|
||||
<option name="IF_BRACE_FORCE" value="1" />
|
||||
<option name="DOWHILE_BRACE_FORCE" value="1" />
|
||||
<option name="WHILE_BRACE_FORCE" value="1" />
|
||||
<option name="FOR_BRACE_FORCE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="ruby">
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="8" />
|
||||
<option name="TAB_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
Vendored
+24
-9
@@ -3,9 +3,10 @@
|
||||
// this groovy script is executed by jenkins
|
||||
node {
|
||||
|
||||
environment {
|
||||
ANDROID_SDK_ROOT = '/var/lib/android-sdk'
|
||||
}
|
||||
// set environment variables
|
||||
env.ANDROID_SDK_ROOT = '/var/lib/android-sdk'
|
||||
env.JAVA_HOME = '/opt/openjdk-bin-21'
|
||||
env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
|
||||
|
||||
// checkout code from scm
|
||||
stage('Checkout') {
|
||||
@@ -25,7 +26,7 @@ node {
|
||||
// build the source code with gradle
|
||||
stage('Build') {
|
||||
withCredentials([string(credentialsId: 'mowesta-keystore-password', variable: 'PASSWD')]) {
|
||||
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD clean build', label: "Building project.")
|
||||
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD clean build -x test', label: "Building project.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,17 +45,31 @@ node {
|
||||
|
||||
// deploy the build output on the server
|
||||
stage ('Deploy') {
|
||||
// release = true; // uncomment to temporary enable snapshot deployments
|
||||
// release = true; // uncomment to temporary enable snapshot deployments
|
||||
|
||||
// copy android bundles to apps pro
|
||||
if (env.BRANCH_NAME == "master") {
|
||||
echo "Copying android bundles to production server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/bundle/prodRelease/*.aab wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
}
|
||||
} else {
|
||||
echo "Skip copying of android bundles for non-master branch."
|
||||
}
|
||||
|
||||
// deploy service to apps pro or apps dev
|
||||
if (env.BRANCH_NAME == "master" && release) {
|
||||
echo "Deploying to production server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear'
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
sh 'scp -i $KEYFILE service-war/build/libs/service-war-' + version + '.war wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-31-mowesta/standalone/deployments/service-war.war'
|
||||
sh 'scp -i $KEYFILE web-war/build/libs/web-war-' + version + '.war wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-31-mowesta/standalone/deployments/web-war.war'
|
||||
}
|
||||
} else if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "feat/auth") {
|
||||
} else if (env.BRANCH_NAME == "master") {
|
||||
echo "Deploying to beta server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-dev.nes.uni-due.de:/opt/wildfly-21-beta/standalone/deployments/mowesta.ear'
|
||||
sh 'scp -i $KEYFILE service-war/build/libs/service-war-' + version + '.war mowesta@apps-dev.nes.uni-due.de:/home/mowesta/wildfly/standalone/deployments/service-war.war'
|
||||
sh 'scp -i $KEYFILE web-war/build/libs/web-war-' + version + '.war mowesta@apps-dev.nes.uni-due.de:/home/mowesta/wildfly/standalone/deployments/web-war.war'
|
||||
}
|
||||
} else {
|
||||
echo "Skipping deployment for non-master branch."
|
||||
|
||||
@@ -14,3 +14,10 @@ To build the project, you will have to install [Java](http://www.oracle.com/tech
|
||||
|
||||
Pull requests and new commits to any branch are automatically built by a Jenkins service. A Gitea webhook informs the service about changes to the repository. In addition, the service will automatically scan the lbs Gitea organization for new repositories every hour. Successful builds of new commits are indicated by a green tick on the commit page. The build status of pull requests is currently not shown in Gitea. However, you can go to the [Jenkins](https://project.nes.uni-due.de/jenkins/job/LocationBasedServices/job/mowesta/) service to view the result of builds including the console output. To modify the build process, you can change the Jenkinsfile groovy script in the root of the repository, if necessary.
|
||||
|
||||
# Configuration
|
||||
|
||||
The MoWeSta backend uses a number of system properties to configure the location of input and output folders, the base url of videos and the forecast downlods. You can set them when starting wildfly by passing a ```-DpropretyName=propertyValue``` switch to the standalone.sh. The configurations are:
|
||||
|
||||
- *baseDirectory*: Defines where the input and output folders are placed. Default is working directory.
|
||||
- *limitedMode*: Defines whether to limit the forecast download to cosmo europe. Default is false.
|
||||
- *videoUrl*: Define the url to prefix the file names with. Default is https://www.mowesta.com/data/video.
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
plugins {
|
||||
id 'org.openapi.generator' version '6.0.0'
|
||||
}
|
||||
|
||||
description = "MoWeSta Android Api"
|
||||
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.24"
|
||||
jackson_version = "2.10.3"
|
||||
jackson_databind_version = "2.10.3"
|
||||
jackson_databind_nullable_version = "0.2.2"
|
||||
jakarta_annotation_version = "1.3.5"
|
||||
feign_version = "10.11"
|
||||
feign_form_version = "3.8.0"
|
||||
junit_version = "5.7.0"
|
||||
scribejava_version = "8.0.0"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
implementation "com.google.code.findbugs:jsr305:3.0.2"
|
||||
api "io.github.openfeign:feign-core:$feign_version"
|
||||
implementation "io.github.openfeign:feign-jackson:$feign_version"
|
||||
implementation "io.github.openfeign:feign-slf4j:$feign_version"
|
||||
implementation "io.github.openfeign:feign-okhttp:$feign_version"
|
||||
implementation "io.github.openfeign.form:feign-form:$feign_form_version"
|
||||
api "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
api "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
api "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
|
||||
implementation "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version"
|
||||
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
|
||||
implementation "com.github.scribejava:scribejava-core:$scribejava_version"
|
||||
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
|
||||
api "de.grundid.opendatalab:geojson-jackson:${versionGeojson}"
|
||||
}
|
||||
|
||||
sourceSets.main.java.srcDirs = ['src/main/java', 'build/swagger/src/main/java']
|
||||
|
||||
compileJava {
|
||||
dependsOn 'generateClient'
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
dependsOn 'generateClient'
|
||||
}
|
||||
|
||||
task generateClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
|
||||
dependsOn ':service-api:resolve'
|
||||
generatorName = "java"
|
||||
inputSpec = "$projectDir/../service-api/build/swagger/mowesta.json"
|
||||
outputDir = "$projectDir/build/swagger/"
|
||||
typeMappings.putAll(["Geometry":"org.geojson.Geometry"])
|
||||
generateModelTests = false
|
||||
generateModelDocumentation = false
|
||||
generateApiTests = false
|
||||
generateApiDocumentation = false
|
||||
configOptions = [
|
||||
invokerPackage: 'com.mowesta.android.feign',
|
||||
modelPackage: 'com.mowesta.android.feign.model',
|
||||
apiPackage: 'com.mowesta.android.feign.api',
|
||||
library: "feign",
|
||||
dateLibrary: "java8",
|
||||
importMappings: 'Geometry=org.geojson.Geometry',
|
||||
annotationLibrary: "none"
|
||||
]
|
||||
}
|
||||
|
||||
+74
-49
@@ -2,36 +2,46 @@ apply plugin: 'org.handte.gradle-android-eclipse'
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
|
||||
|
||||
description = "Mowesta Android App"
|
||||
description = "MoWeSta Android App"
|
||||
|
||||
|
||||
ext {
|
||||
// android app dependencies
|
||||
versionPlay = '17.0.0'
|
||||
versionAndroidXCore = '1.2.0'
|
||||
versionAndroidXCoreTest = '2.1.0'
|
||||
versionAndroidXRecycler = '1.1.0'
|
||||
versionPlay = '17.3.0'
|
||||
versionAndroidXCore = '1.3.1'
|
||||
versionAndroidXCoreTest = '2.2.0'
|
||||
versionAndroidXRecycler = '1.4.0'
|
||||
versionAndroidXPaging = '2.1.2'
|
||||
versionAndroidXCard = '1.0.0'
|
||||
versionAndroidXCoordinator = '1.1.0'
|
||||
versionAndroidXConstraint = '2.0.4'
|
||||
versionAndroidXNavigation = '2.3.2'
|
||||
versionAndroidXLifecycle = '2.2.0'
|
||||
versionAndroidXSecurity = '1.1.0-alpha03'
|
||||
versionAndroidXViewpager = '1.0.0'
|
||||
versionGoogleMaterial = '1.2.1'
|
||||
versionAndroidXSwipeRefresh = '1.1.0'
|
||||
versionExoPlayer = '2.11.5'
|
||||
versionAndroidXCoordinator = '1.3.0'
|
||||
versionAndroidXConstraint = '2.2.2'
|
||||
versionAndroidXNavigation = '2.10.1'
|
||||
versionAndroidXLifecycle = '2.10.0'
|
||||
versionAndroidXSecurity = '1.0.0'
|
||||
versionAndroidXViewpager = '1.1.0'
|
||||
versionAndroidXWork = '2.10.5'
|
||||
versionGoogleMaterial = '1.14.0'
|
||||
versionAndroidXSwipeRefresh = '1.2.0'
|
||||
versionAndroidXWebkit = '1.17.0'
|
||||
versionExoPlayer = '1.6.0'
|
||||
versionAndroidXProfileInstaller = '1.4.1'
|
||||
versionApp = '1.4.2'
|
||||
}
|
||||
|
||||
// remove project version to workaround bugs in
|
||||
// oss-license-plugin that detects local libraries
|
||||
// by checking for a version called "unspecified"
|
||||
// see DependencyTask.groovy on GitHub at
|
||||
// https://github.com/google/play-services-plugins
|
||||
project.version = "unspecified"
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation project(":android-sdk")
|
||||
|
||||
implementation "javax.xml.bind:jaxb-api:${versionJaxb}"
|
||||
implementation project(":android-api")
|
||||
|
||||
implementation "jakarta.xml.bind:jakarta.xml.bind-api:${versionJaxb}"
|
||||
implementation "androidx.appcompat:appcompat:${versionAndroidXAppcompat}"
|
||||
|
||||
implementation "androidx.work:work-runtime:${versionAndroidXWork}"
|
||||
implementation "com.google.android.material:material:${versionGoogleMaterial}"
|
||||
implementation "androidx.preference:preference:${versionAndroidXPreference}"
|
||||
implementation "androidx.cardview:cardview:${versionAndroidXCard}"
|
||||
@@ -51,10 +61,11 @@ dependencies {
|
||||
implementation "androidx.lifecycle:lifecycle-service:${versionAndroidXLifecycle}"
|
||||
implementation "androidx.lifecycle:lifecycle-process:${versionAndroidXLifecycle}"
|
||||
|
||||
implementation "androidx.webkit:webkit:${versionAndroidXWebkit}"
|
||||
|
||||
implementation "com.google.android.exoplayer:exoplayer-core:${versionExoPlayer}"
|
||||
implementation "com.google.android.exoplayer:exoplayer-ui:${versionExoPlayer}"
|
||||
|
||||
implementation "androidx.media3:media3-exoplayer:${versionExoPlayer}"
|
||||
implementation "androidx.media3:media3-exoplayer-dash:${versionExoPlayer}"
|
||||
implementation "androidx.media3:media3-ui:${versionExoPlayer}"
|
||||
|
||||
implementation "androidx.room:room-runtime:${versionAndroidXRoom}"
|
||||
annotationProcessor "androidx.room:room-compiler:${versionAndroidXRoom}"
|
||||
@@ -68,29 +79,29 @@ dependencies {
|
||||
androidTestImplementation "androidx.navigation:navigation-testing:${versionAndroidXNavigation}"
|
||||
|
||||
implementation "com.google.android.gms:play-services-oss-licenses:${versionPlay}"
|
||||
implementation "androidx.profileinstaller:profileinstaller:${versionAndroidXProfileInstaller}"
|
||||
|
||||
testImplementation "junit:junit:${versionJunit}"
|
||||
testImplementation "androidx.test:core:${versionAndroidXTest}"
|
||||
testImplementation "androidx.arch.core:core-testing:${versionAndroidXCoreTest}"
|
||||
testImplementation "org.robolectric:robolectric:${versionRobolectric}"
|
||||
|
||||
}
|
||||
|
||||
configurations {
|
||||
all {
|
||||
exclude group: 'com.google.auto.service', module: 'auto-service'
|
||||
}
|
||||
all {
|
||||
exclude group: 'com.google.auto.service', module: 'auto-service'
|
||||
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
defaultConfig {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 16
|
||||
versionName "${version}"
|
||||
minSdkVersion 24
|
||||
compileSdk 36
|
||||
targetSdkVersion 36
|
||||
versionCode 33
|
||||
versionName "${versionApp}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
resValue "string", "application_long", "MoWeSta"
|
||||
@@ -98,6 +109,11 @@ android {
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments += ["room.schemaLocation": "${projectDir}/src/main/sql/".toString()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
@@ -109,10 +125,16 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
// add signing config if key is provided via system property
|
||||
if (System.properties['android.keystore.password'] != null) signingConfig signingConfigs.release
|
||||
}
|
||||
@@ -127,8 +149,9 @@ android {
|
||||
beta {
|
||||
dimension "backend"
|
||||
applicationIdSuffix ".beta"
|
||||
resValue "string", "mowesta_url_default", "https://beta.mowesta.com/api"
|
||||
resValue "string", "application_long", "MoWeSta Beta"
|
||||
resValue "string", "mowesta_url_default", "https://www.mowesta.com/api"
|
||||
// resValue "string", "mowesta_url_default", "https://beta.mowesta.com/api"
|
||||
resValue "string", "application_long", "B-MoWeSta"
|
||||
}
|
||||
prod {
|
||||
dimension "backend"
|
||||
@@ -138,6 +161,7 @@ android {
|
||||
|
||||
buildFeatures {
|
||||
dataBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
testOptions {
|
||||
@@ -145,23 +169,18 @@ android {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
// FragmentTagUsage: replacing fragment with FragmentContainerView breaks Navigation library
|
||||
// RelativeOverlayp: occurs in video frame which is what we want
|
||||
// VectorPath: our map and logo representations are very long vectors (consider compressing)
|
||||
|
||||
lint {
|
||||
abortOnError false
|
||||
disable 'RelativeOverlap', 'FragmentTagUsage', 'VectorPath'
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
dexOptions {
|
||||
javaMaxHeapSize "512m"
|
||||
namespace 'com.mowesta.android.app'
|
||||
|
||||
packagingOptions {
|
||||
resources {
|
||||
excludes += "META-INF/*.md"
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -188,4 +207,10 @@ eclipse {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(Test).configureEach {
|
||||
failOnNoDiscoveredTests = false
|
||||
}
|
||||
|
||||
if (System.properties['android.keystore.password'] != null) {
|
||||
build.dependsOn "bundle"
|
||||
}
|
||||
|
||||
Vendored
+30
-15
@@ -1,21 +1,36 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
# Disable symbol and name obfuscation while preserving R8 code shrinking and bytecode optimization
|
||||
-dontobfuscate
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
# Preserve stack traces and line numbers for debugging
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
# Keep Jackson annotations and reflection targets
|
||||
-dontwarn com.fasterxml.jackson.**
|
||||
|
||||
-dontwarn feign.**
|
||||
|
||||
# Keep API interfaces and model classes used for serialization/reflection
|
||||
-keep class com.mowesta.android.feign.model.** { *; }
|
||||
-keep interface com.mowesta.android.feign.api.** { *; }
|
||||
-keep class org.geojson.** { *; }
|
||||
|
||||
# Keep app data classes serialized with Jackson
|
||||
-keep class com.mowesta.android.app.repository.UserCredentials { *; }
|
||||
-keep class com.mowesta.android.app.arduino.ArduinoConfig { *; }
|
||||
-keepclassmembers class * {
|
||||
@com.fasterxml.jackson.annotation.* <fields>;
|
||||
@com.fasterxml.jackson.annotation.* <methods>;
|
||||
}
|
||||
|
||||
# Suppress warnings for optional/runtime dependencies
|
||||
-dontwarn javax.validation.**
|
||||
-dontwarn javax.xml.bind.**
|
||||
-dontwarn org.bouncycastle.**
|
||||
-dontwarn org.conscrypt.**
|
||||
-dontwarn org.openjsse.**
|
||||
-dontwarn org.slf4j.**
|
||||
@@ -1,22 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.mowesta.android.app">
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<uses-sdk tools:overrideLibrary="androidx.security" />
|
||||
|
||||
|
||||
<application android:name=".MowestaApp"
|
||||
tools:targetApi="24"
|
||||
android:networkSecurityConfig="@xml/network"
|
||||
@@ -28,11 +25,10 @@
|
||||
android:supportsRtl="true"
|
||||
android:fullBackupContent="@xml/backup">
|
||||
<activity
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleTop"
|
||||
android:name=".MowestaActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true"
|
||||
android:label="@string/application_long">
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
@@ -52,16 +48,9 @@
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver android:name=".MowestaReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".widget.ForecastWidgetProvider"
|
||||
android:exported="true"
|
||||
android:label="@string/widget_forecast_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
@@ -70,6 +59,7 @@
|
||||
android:resource="@xml/widget_forecast" />
|
||||
</receiver>
|
||||
<receiver
|
||||
android:exported="true"
|
||||
android:name=".widget.MeasureWidgetProvider"
|
||||
android:label="@string/widget_measure_name">
|
||||
<intent-filter>
|
||||
@@ -78,13 +68,5 @@
|
||||
<meta-data android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_measure" />
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".widget.WidgetReceiver"
|
||||
android:exported="true"/>
|
||||
<service android:name=".MowestaService" />
|
||||
<service
|
||||
android:name=".widget.WidgetService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
android:exported="true"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
Binary file not shown.
@@ -2,7 +2,9 @@ package com.mowesta.android.app;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.android.exoplayer2.upstream.cache.Cache;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.datasource.cache.Cache;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.repository.DeviceRepository;
|
||||
import com.mowesta.android.app.repository.FavoriteRepository;
|
||||
@@ -64,6 +66,7 @@ public interface IApp {
|
||||
*
|
||||
* @return The cache to store videos.
|
||||
*/
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
Cache getMediaCache();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.net.http.HttpResponseCache;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
@@ -14,8 +17,9 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.repository.UserCredentials;
|
||||
@@ -48,9 +52,19 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
private static final int DELAY_REFRESH = 15 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* The code used to request the permissions.
|
||||
* Requests the permission to issue notifications.
|
||||
*/
|
||||
private static final int CODE_REQUEST_PERMISSIONS = 3334;
|
||||
public static final int CODE_REQUEST_POST_NOTIFICATION = 3333;
|
||||
/**
|
||||
* The code used to request the permission for localizing in the foreground.
|
||||
*/
|
||||
public static final int CODE_REQUEST_FOREGROUND_PERMISSIONS = 3334;
|
||||
|
||||
/**
|
||||
* The code used to request the permission for localizing in the background.
|
||||
*/
|
||||
private static final int CODE_REQUEST_BACKGROUND_PERMISSIONS = 3335;
|
||||
|
||||
|
||||
/**
|
||||
* The preferences.
|
||||
@@ -88,21 +102,9 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The listener that observes the activation of the mowesta sdk service
|
||||
* and checks for the permissions.
|
||||
*/
|
||||
private OnSharedPreferenceChangeListener preferenceListener = (prefs, key) -> {
|
||||
if (MowestaSettings.PRIVACY_MEASURE.equals(key)) {
|
||||
if (settings.isPrivacyMeasure()) {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(this)) requestPermissions();
|
||||
else MowestaService.startService(this);
|
||||
} else {
|
||||
MowestaService.stopService(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
public MowestaActivity() {
|
||||
super(R.layout.activity_app);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -111,29 +113,15 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
app = (IApp) getApplication();
|
||||
favoriteTask.execute(null, app.getFavoriteRepository().getDatabase());
|
||||
settings = app.getSettings();
|
||||
setContentView(R.layout.activity_app);
|
||||
installHttpCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
// got to navigation drawer when user presses notification
|
||||
setIntent(intent);
|
||||
Navigation.findNavController(this, R.id.navigation_app).navigate(R.id.action_drawer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
settings.getPreferences().registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
settings.getPreferences().unregisterOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
@@ -169,18 +157,15 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
/**
|
||||
* Method to request location permission for the app.
|
||||
*/
|
||||
public void requestPermissions() {
|
||||
public void requestPermissions(boolean skipNotification) {
|
||||
Log.d(TAG, "Requesting permissions.");
|
||||
requestPermissions(PermissionUtil.getNonGrantedBackgroundPermissions(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the permissions.
|
||||
*
|
||||
* @param permissions The permissions to request.
|
||||
*/
|
||||
public void requestPermissions(String[] permissions) {
|
||||
ActivityCompat.requestPermissions(this, permissions, CODE_REQUEST_PERMISSIONS);
|
||||
if (!skipNotification && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !PermissionUtil.hasNotificationPermission(this)) {
|
||||
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.POST_NOTIFICATIONS }, CODE_REQUEST_POST_NOTIFICATION);
|
||||
} else if (!PermissionUtil.hasPermissions(this, PermissionUtil.getForegroundPermissions(this))) {
|
||||
ActivityCompat.requestPermissions(this, PermissionUtil.getForegroundPermissions(this), CODE_REQUEST_BACKGROUND_PERMISSIONS);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_BACKGROUND_LOCATION }, CODE_REQUEST_BACKGROUND_PERMISSIONS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,8 +177,15 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
switch (requestCode) {
|
||||
case CODE_REQUEST_PERMISSIONS: {
|
||||
case CODE_REQUEST_POST_NOTIFICATION: {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(this))
|
||||
requestPermissions(true);
|
||||
break;
|
||||
}
|
||||
case CODE_REQUEST_BACKGROUND_PERMISSIONS:
|
||||
case CODE_REQUEST_FOREGROUND_PERMISSIONS: {
|
||||
boolean granted = true;
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int i = 0, s = Math.min(permissions.length, grantResults.length); i < s; i++) {
|
||||
@@ -203,10 +195,7 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
}
|
||||
Log.d(TAG, "Permission result: " + b.toString());
|
||||
if (!granted) {
|
||||
settings.setPrivacyMeasure(false);
|
||||
showMissingPermission();
|
||||
} else {
|
||||
MowestaService.startService(this);
|
||||
showMissingPermission(requestCode == CODE_REQUEST_FOREGROUND_PERMISSIONS);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -218,22 +207,59 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
/**
|
||||
* Shows a snackbar indicating a missing permission.
|
||||
*/
|
||||
public void showMissingPermission() {
|
||||
View coordinator = findViewById(R.id.layout_coordinator);
|
||||
Snackbar.make(coordinator, R.string.message_no_permission, Snackbar.LENGTH_LONG )
|
||||
.setAction(R.string.button_configure, (view) -> {
|
||||
// go to app settings
|
||||
public void showMissingPermission(boolean foreground) {
|
||||
PermissionDialogFragment pdf = PermissionDialogFragment.newInstance(foreground);
|
||||
pdf.show(getSupportFragmentManager(), "permissions");
|
||||
}
|
||||
|
||||
/**
|
||||
* A dialog fragment to explain the need for permissions.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public static class PermissionDialogFragment extends DialogFragment {
|
||||
|
||||
private static final String KEY_FOREGROUND = "foreground";
|
||||
|
||||
public static PermissionDialogFragment newInstance(boolean foreground) {
|
||||
PermissionDialogFragment f = new PermissionDialogFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean(KEY_FOREGROUND, foreground);
|
||||
f.setArguments(b);
|
||||
return f;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
MaterialAlertDialogBuilder b = new MaterialAlertDialogBuilder(getActivity());
|
||||
b.setTitle(R.string.message_permission_title);
|
||||
b.setMessage(isForeground()?R.string.message_permission_foreground:R.string.message_permission_background);
|
||||
b.setIcon(R.drawable.ic_gps_off_normal_24);
|
||||
b.setNeutralButton(R.string.button_configure, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
Uri uri = Uri.fromParts("package", getActivity().getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
View coordinator = getActivity().findViewById(R.id.layout_coordinator);
|
||||
Snackbar.make(coordinator, R.string.message_configure_failed,
|
||||
Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
return b.show();
|
||||
}
|
||||
|
||||
private boolean isForeground() {
|
||||
Bundle b = getArguments();
|
||||
return b.getBoolean(KEY_FOREGROUND, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,22 +4,25 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
|
||||
import com.google.android.exoplayer2.upstream.cache.Cache;
|
||||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
|
||||
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
import androidx.media3.database.StandaloneDatabaseProvider;
|
||||
import androidx.media3.datasource.cache.Cache;
|
||||
import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor;
|
||||
import androidx.media3.datasource.cache.SimpleCache;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.repository.DeviceRepository;
|
||||
import com.mowesta.android.app.repository.FavoriteRepository;
|
||||
import com.mowesta.android.app.repository.UserRepository;
|
||||
import com.mowesta.android.app.repository.WidgetRepository;
|
||||
import com.mowesta.android.app.widget.WidgetReceiver;
|
||||
import com.mowesta.android.app.widget.AbstractWidgetProvider;
|
||||
import com.mowesta.android.app.widget.ForecastWidgetProvider;
|
||||
import com.mowesta.android.app.widget.MeasureWidgetProvider;
|
||||
import com.mowesta.android.app.widget.PeriodicWidgetWorker;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -29,8 +32,19 @@ import java.io.File;
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@UnstableApi
|
||||
public class MowestaApp extends Application implements IApp {
|
||||
|
||||
/** The log tag. */
|
||||
public static final String TAG = "MowestaApp";
|
||||
|
||||
/**
|
||||
* The widget providers of the app.
|
||||
*/
|
||||
private AbstractWidgetProvider[] widgetProviders = {
|
||||
new ForecastWidgetProvider(),
|
||||
new MeasureWidgetProvider()
|
||||
};
|
||||
|
||||
/**
|
||||
* The user repository.
|
||||
@@ -71,9 +85,8 @@ public class MowestaApp extends Application implements IApp {
|
||||
deviceRepository = new DeviceRepository.Builder().setTrace(false).build(this);
|
||||
favoriteRepository = new FavoriteRepository(this);
|
||||
widgetRepository = new WidgetRepository(this);
|
||||
MowestaService.startService(this);
|
||||
WidgetReceiver.updateWidgets(this);
|
||||
WidgetReceiver.scheduleUpdates(this);
|
||||
PeriodicWidgetWorker.updateWidgets(this);
|
||||
PeriodicWidgetWorker.scheduleUpdates(this);
|
||||
//if(BuildConfig.DEBUG)
|
||||
// StrictMode.enableDefaults();
|
||||
}
|
||||
@@ -81,7 +94,10 @@ public class MowestaApp extends Application implements IApp {
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
WidgetReceiver.updateWidgets(this);
|
||||
Log.d(TAG, "Configuration change detected.");
|
||||
for (int i = widgetProviders.length - 1; i >= 0; i--) {
|
||||
widgetProviders[i].triggerUpdates(MowestaApp.this, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,7 +139,7 @@ public class MowestaApp extends Application implements IApp {
|
||||
if (mediaCache == null) {
|
||||
mediaCache = new SimpleCache(new File(this.getCacheDir(), "videos"),
|
||||
new LeastRecentlyUsedCacheEvictor(25 * 1000 * 1000),
|
||||
new ExoDatabaseProvider(getContext()));
|
||||
new StandaloneDatabaseProvider(getContext()));
|
||||
}
|
||||
return mediaCache;
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A broadcast receiver that starts the background service after
|
||||
* a reboot and when the package is updated.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class MowestaReceiver extends BroadcastReceiver {
|
||||
|
||||
/**
|
||||
* The log tag of the receiver.
|
||||
*/
|
||||
private static final String TAG = "MowestaBootReceiver";
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// should not happen but nobody likes crashing apps in background
|
||||
if (intent == null || context == null) return;
|
||||
Log.d(TAG, "Received an intent with action " + intent.getAction() + ".");
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
|
||||
MowestaService.startService(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import com.mowesta.android.app.util.PermissionUtil;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.sdk.SdkService;
|
||||
|
||||
/**
|
||||
* A service to perform background measurements.
|
||||
*
|
||||
* @author Marcus, Katharina, Arman
|
||||
*/
|
||||
public class MowestaService extends SdkService {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled() {
|
||||
IApp app = (IApp)getApplication();
|
||||
MowestaSettings settings = app.getSettings();
|
||||
return settings.isPrivacyMeasure() && app.getDeviceRepository().getHandle().getValue() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultApi createApiClient() {
|
||||
IApp app = (IApp)getApplication();
|
||||
String handle = app.getDeviceRepository().getHandle().getValue();
|
||||
return app.getClientFactory().createClient(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service.
|
||||
*
|
||||
* @param context A context object.
|
||||
*/
|
||||
public static void startService(Context context) {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(context)) return;
|
||||
IApp app = (IApp)context.getApplicationContext();
|
||||
MowestaSettings settings = app.getSettings();
|
||||
if (!settings.isPrivacyMeasure() || app.getDeviceRepository().getHandle().getValue() == null) return;
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, MowestaService.class);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
context.startService(intent);
|
||||
} else {
|
||||
context.startForegroundService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the running service.
|
||||
*
|
||||
* @param context A context object.
|
||||
*/
|
||||
public static void stopService(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, MowestaService.class);
|
||||
context.stopService(intent);
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,13 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.mowesta.android.sdk.SdkSettings;
|
||||
|
||||
/**
|
||||
* A utility class to manage the settings.
|
||||
*/
|
||||
public class MowestaSettings extends SdkSettings {
|
||||
public class MowestaSettings {
|
||||
|
||||
/**
|
||||
* An enumeration with the unit system used throughout
|
||||
@@ -99,14 +96,53 @@ public class MowestaSettings extends SdkSettings {
|
||||
public static final String TEMPERATURE_UNIT = "temperature_unit";
|
||||
|
||||
/**
|
||||
* Creates the settings with the context.
|
||||
* The shared preferences for the application.
|
||||
*/
|
||||
protected @NonNull SharedPreferences preferences;
|
||||
|
||||
/**
|
||||
* The application context.
|
||||
*/
|
||||
protected @NonNull Application application;
|
||||
|
||||
/**
|
||||
* Creates a new settings object to query and modify the
|
||||
* settings.
|
||||
*
|
||||
* @param application The context.
|
||||
* @param application The application.
|
||||
*/
|
||||
public MowestaSettings(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
this.preferences = PreferenceManager.getDefaultSharedPreferences(application);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the underlying shared preferences.
|
||||
*
|
||||
* @return The preferences.
|
||||
*/
|
||||
public @NonNull SharedPreferences getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the application context.
|
||||
*
|
||||
* @return The application context
|
||||
*/
|
||||
public @NonNull
|
||||
Context getContext() { return application.getApplicationContext(); }
|
||||
|
||||
/**
|
||||
* Returns the application resources.
|
||||
*
|
||||
* @return The application resources.
|
||||
*/
|
||||
public @NonNull
|
||||
Resources getResources() { return getContext().getResources(); }
|
||||
|
||||
/**
|
||||
* Determines whether the current terms are accepted.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mowesta.android.app.arduino;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -48,7 +49,7 @@ public abstract class NetworkTask {
|
||||
/**
|
||||
* A handler to register the timeout.
|
||||
*/
|
||||
protected @NonNull Handler handler = new Handler();
|
||||
protected @NonNull Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,20 +4,20 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.net.DhcpInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mowesta.android.app.task.AbstractTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public class TransferTask {
|
||||
/**
|
||||
* The handler to post the result.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates a new task.
|
||||
@@ -110,7 +110,7 @@ public class TransferTask {
|
||||
*/
|
||||
public void execute() {
|
||||
WifiManager manager = (WifiManager)application.getSystemService(Context.WIFI_SERVICE);
|
||||
AsyncTask.SERIAL_EXECUTOR.execute(() -> {
|
||||
AbstractTask.SERIAL_EXECUTOR.execute(() -> {
|
||||
try {
|
||||
// sleep for a couple of seconds, since it
|
||||
// will take some time to get an ip address
|
||||
|
||||
@@ -235,7 +235,7 @@ public class BindingAdapters {
|
||||
res = R.string.city_type_village;
|
||||
break;
|
||||
}
|
||||
if (city.isCapital()) {
|
||||
if (city.getCapital()) {
|
||||
res = R.string.city_type_capital;
|
||||
}
|
||||
}
|
||||
@@ -858,6 +858,7 @@ public class BindingAdapters {
|
||||
if (valueText != null) {
|
||||
if (text == null) {
|
||||
text = valueText;
|
||||
break; // only use first value (since it looks bad otherwise)
|
||||
} else {
|
||||
text = view.getResources().getString(R.string.format_two_lines, text, valueText);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,12 @@ public class Widget {
|
||||
@ColumnInfo(name = "si")
|
||||
private boolean si;
|
||||
|
||||
/**
|
||||
* The color of the widget text.
|
||||
*/
|
||||
@ColumnInfo(name = "color")
|
||||
private int color;
|
||||
|
||||
/**
|
||||
* Returns the widget type.
|
||||
*
|
||||
@@ -370,4 +376,22 @@ public class Widget {
|
||||
public void setSi(boolean si) {
|
||||
this.si = si;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text color.
|
||||
*
|
||||
* @return The text color.
|
||||
*/
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text color.
|
||||
*
|
||||
* @param color The text color.
|
||||
*/
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,62 @@
|
||||
package com.mowesta.android.app.database;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.room.AutoMigration;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The database to store the widget information.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@Database(entities = { Widget.class }, version = 3, exportSchema = false)
|
||||
@Database(entities = { Widget.class }, version = 4, exportSchema = true)
|
||||
|
||||
public abstract class WidgetDatabase extends RoomDatabase {
|
||||
|
||||
/**
|
||||
* Adds a non-null color column to the widget entry. This requires
|
||||
* us to copy the data, since sql lite cannot dynamically add or
|
||||
* remove constraints.
|
||||
*/
|
||||
private static final Migration MIGRATION_3_4 = new Migration(3, 4) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase database) {
|
||||
database.execSQL("DROP INDEX IF EXISTS `index_widget_type_ref`");
|
||||
database.execSQL("ALTER TABLE `widget` ADD COLUMN `color` INTEGER");
|
||||
database.execSQL("UPDATE `widget` SET `color` = ?", new Object[] { Color.rgb(255, 255, 255) } );
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS `new_widget` (`type` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `ref` INTEGER NOT NULL, `dataId` INTEGER NOT NULL, `dataTime` INTEGER NOT NULL, `dataValue` TEXT, `contentTime` INTEGER NOT NULL, `contentValue` TEXT, `celsius` INTEGER NOT NULL, `si` INTEGER NOT NULL, `color` INTEGER NOT NULL)");
|
||||
database.execSQL("INSERT INTO `new_widget` SELECT * FROM `widget`");
|
||||
database.execSQL("DROP TABLE `widget`");
|
||||
database.execSQL("ALTER TABLE `new_widget` RENAME TO `widget`");
|
||||
database.execSQL("CREATE INDEX IF NOT EXISTS `index_widget_type_ref` ON `widget` (`type`, `ref`)");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an array with all migrations.
|
||||
*
|
||||
* @return The array with migrations.
|
||||
*/
|
||||
public static Migration[] getMigrations() {
|
||||
return new Migration[] {
|
||||
MIGRATION_3_4
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the widget accessor.
|
||||
*
|
||||
* @return The widget accessor.
|
||||
*/
|
||||
public abstract WidgetAccessor getAccessor();
|
||||
|
||||
|
||||
}
|
||||
|
||||
+24
-19
@@ -5,9 +5,11 @@ import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
@@ -41,7 +43,6 @@ public abstract class AbstractDiagramFragment extends AbstractNetworkFragment {
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,25 +65,29 @@ public abstract class AbstractDiagramFragment extends AbstractNetworkFragment {
|
||||
public abstract void onRefreshDiagram();
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_unit, menu);
|
||||
}
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
getActivity().addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_unit, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_unit_system) {
|
||||
UnitSystemDialogFragment system = new UnitSystemDialogFragment();
|
||||
system.show(getChildFragmentManager(), "system");
|
||||
return true;
|
||||
} else if (itemId == R.id.action_temperature_unit) {
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_unit_system) {
|
||||
UnitSystemDialogFragment system = new UnitSystemDialogFragment();
|
||||
system.show(getChildFragmentManager(), "system");
|
||||
return true;
|
||||
} else if (itemId == R.id.action_temperature_unit) {
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+39
-43
@@ -11,6 +11,7 @@ import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
@@ -44,12 +45,6 @@ public abstract class AbstractPlaceFragment extends AbstractNetworkFragment {
|
||||
*/
|
||||
protected abstract AbstractPlaceViewModel getPlaceViewModel();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
@@ -58,45 +53,46 @@ public abstract class AbstractPlaceFragment extends AbstractNetworkFragment {
|
||||
model.getCoordinate().observe(getViewLifecycleOwner(), (v) -> getActivity().invalidateOptionsMenu());
|
||||
model.getFavorite().observe(getViewLifecycleOwner(), (v) -> getActivity().invalidateOptionsMenu());
|
||||
model.getWikipedia().observe(getViewLifecycleOwner() ,(v) -> getActivity().invalidateOptionsMenu());
|
||||
}
|
||||
getActivity().addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_place, menu);
|
||||
AbstractPlaceViewModel model = getPlaceViewModel();
|
||||
Boolean favorite = model.getFavorite().getValue();
|
||||
if (favorite == null || favorite) {
|
||||
menu.removeItem(R.id.action_favorite_add);
|
||||
}
|
||||
if (favorite == null || !favorite) {
|
||||
menu.removeItem(R.id.action_favorite_remove);
|
||||
}
|
||||
if (model.getWikipedia().getValue() == null) {
|
||||
menu.removeItem(R.id.action_wikipedia);
|
||||
}
|
||||
if (model.getCoordinate().getValue() == null) {
|
||||
menu.removeItem(R.id.action_google_maps);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_place, menu);
|
||||
AbstractPlaceViewModel model = getPlaceViewModel();
|
||||
Boolean favorite = model.getFavorite().getValue();
|
||||
if (favorite == null || favorite) {
|
||||
menu.removeItem(R.id.action_favorite_add);
|
||||
}
|
||||
if (favorite == null || !favorite) {
|
||||
menu.removeItem(R.id.action_favorite_remove);
|
||||
}
|
||||
if (model.getWikipedia().getValue() == null) {
|
||||
menu.removeItem(R.id.action_wikipedia);
|
||||
}
|
||||
if (model.getCoordinate().getValue() == null) {
|
||||
menu.removeItem(R.id.action_google_maps);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_favorite_add) {
|
||||
getPlaceViewModel().addFavorite();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_favorite_remove) {
|
||||
getPlaceViewModel().removeFavorite();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_wikipedia) {
|
||||
openWikipedia();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_google_maps) {
|
||||
openGoogleMaps();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner());
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_favorite_add) {
|
||||
getPlaceViewModel().addFavorite();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_favorite_remove) {
|
||||
getPlaceViewModel().removeFavorite();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_wikipedia) {
|
||||
openWikipedia();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_google_maps) {
|
||||
openGoogleMaps();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import androidx.media3.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.DialogAdvertiseBinding;
|
||||
import com.mowesta.android.app.model.AdvertiseViewModel;
|
||||
|
||||
public class AdvertiseDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String KEY_ADVERTISEMENT = "advertisement";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
||||
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
BottomSheetDialog d = (BottomSheetDialog) dialog;
|
||||
FrameLayout bottomSheet = (FrameLayout) d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
|
||||
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
DialogAdvertiseBinding binding = DataBindingUtil.inflate(inflater, R.layout.dialog_advertise, container, false);
|
||||
AdvertiseViewModel model = new ViewModelProvider(this).get(AdvertiseViewModel.class);
|
||||
binding.setModel(model);
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.videoView.setPlayer(model.getExoPlayer());
|
||||
binding.videoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
|
||||
model.getClose().observe(getViewLifecycleOwner(), (v) -> { if (v) this.dismiss(); } );
|
||||
model.getOpen().observe(getViewLifecycleOwner(), (v) -> {
|
||||
if (v) {
|
||||
String url = "https://www.mowesta.com/2022/05/23/fair-experiment-bei-das-fest-in-karlsruhe/";
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(url));
|
||||
try {
|
||||
startActivity(i);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Snackbar.make(getView(), R.string.message_no_browser, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
model.getOpen().setValue(Boolean.FALSE);
|
||||
}
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
|
||||
public boolean shouldShow(Context context) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time > 1658700000000l) return false;
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
long last = prefs.getLong(KEY_ADVERTISEMENT, 0);
|
||||
return (time - last > 7 * 24* 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
Context context = getActivity();
|
||||
if (context != null) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor e = prefs.edit();
|
||||
e.putLong(KEY_ADVERTISEMENT, System.currentTimeMillis());
|
||||
e.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -18,6 +19,9 @@ import com.mowesta.android.app.adapter.CityEntryPagedListAdapter;
|
||||
import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.model.CitiesViewModel;
|
||||
import com.mowesta.android.app.model.StateViewModel;
|
||||
import com.mowesta.android.app.util.TabletUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
@@ -26,6 +30,7 @@ import com.mowesta.android.app.model.StateViewModel;
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CitiesFragment extends AbstractNetworkFragment {
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
@Override
|
||||
protected AbstractNetworkViewModel getNetworkViewModel() {
|
||||
@@ -38,10 +43,27 @@ public class CitiesFragment extends AbstractNetworkFragment {
|
||||
return inflater.inflate(R.layout.fragment_cities, container, false);
|
||||
}
|
||||
|
||||
private void applyGridWidth() {
|
||||
if (!TabletUtil.isTablet(requireContext())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int width = requireContext().getResources().getInteger(R.integer.RecyclerWidth);
|
||||
TabletUtil.setGridLayout(recyclerView, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NotNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
applyGridWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler);
|
||||
recyclerView = view.findViewById(R.id.recycler);
|
||||
applyGridWidth();
|
||||
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
CityEntryPagedListAdapter adapter = new CityEntryPagedListAdapter(getViewLifecycleOwner(), (city) -> {
|
||||
if (city != null) {
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@ package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -53,7 +54,6 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ViewPager2 pager = view.findViewById(R.id.pager);
|
||||
CityViewModel model = getCityViewModel();
|
||||
pager.setAdapter(new ForecastAdapter(this));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request != null) {
|
||||
switch (request.getType()) {
|
||||
@@ -69,7 +69,8 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
}
|
||||
}
|
||||
});
|
||||
TabLayout tabs = getActivity().findViewById(R.id.tabs);
|
||||
pager.setAdapter(new ForecastAdapter(this));
|
||||
TabLayout tabs = view.findViewById(R.id.tabs);
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
switch (position) {
|
||||
case 0:
|
||||
@@ -88,6 +89,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
}).attach();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The adapter for the pager that displays the different time granularities.
|
||||
*
|
||||
@@ -130,7 +132,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public static class ForecastRecyclerFragment extends CityFragment.ChildFragment {
|
||||
|
||||
/** A handler to post updates. */
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
@@ -71,30 +72,6 @@ public class CityFragment extends AbstractPlaceFragment {
|
||||
return getView().findViewById(R.id.bottom_navigation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_customize, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_customize) {
|
||||
getChildFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(new CustomizeDialogFragment(), "customize")
|
||||
.commit();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -121,10 +98,31 @@ public class CityFragment extends AbstractPlaceFragment {
|
||||
NavController controller = Navigation.findNavController(root.findViewById(R.id.navigation_city));
|
||||
NavigationUI.setupWithNavController(binding.bottomNavigation, controller);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder(R.id.destination_drawer);
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
getActivity().addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_customize, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_customize) {
|
||||
getChildFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(new CustomizeDialogFragment(), "customize")
|
||||
.commit();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner());
|
||||
}
|
||||
}
|
||||
|
||||
+48
-35
@@ -4,6 +4,7 @@ import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -54,11 +55,6 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
private TimeUtils timeUtils = new TimeUtils(System.currentTimeMillis(), null);
|
||||
|
||||
/**
|
||||
* The view pager of the parent.
|
||||
*/
|
||||
private ViewPager2 pager;
|
||||
|
||||
/**
|
||||
* The date formatter.
|
||||
*/
|
||||
@@ -67,7 +63,7 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
/**
|
||||
* The handler to post the removal of
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* The animator for the progress bar.
|
||||
@@ -93,8 +89,6 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
dateFormatter = new DateFormatter(getContext());
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_gradient, container, false);
|
||||
// this is quite ugly, but we need to disable the view pager and collapse the toolbar
|
||||
pager = getActivity().findViewById(R.id.pager);
|
||||
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
|
||||
binding.gradientProgress1.setMax(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setMax(TIMEOUT_REMOVER);
|
||||
animator = ValueAnimator.ofInt(TIMEOUT_REMOVER, 0);
|
||||
@@ -109,34 +103,7 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
binding.gradientText.setAlpha(Math.min(1, Math.max(0, value / 1000f)));
|
||||
}
|
||||
});
|
||||
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
|
||||
@Override
|
||||
public void onSlide(float relative) {
|
||||
if (!hasData()) return;
|
||||
animator.cancel();
|
||||
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientText.setAlpha(1);
|
||||
handler.removeCallbacks(remover);
|
||||
if (!closed) {
|
||||
layout.setExpanded(false, true);
|
||||
closed = true;
|
||||
}
|
||||
pager.setUserInputEnabled(false);
|
||||
updateSelection(relative);
|
||||
updateCondition(relative);
|
||||
binding.gradientText.setVisibility(View.VISIBLE);
|
||||
updateGuide(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideEnd() {
|
||||
pager.setUserInputEnabled(true);
|
||||
closed = false;
|
||||
animator.start();
|
||||
handler.postDelayed(remover, TIMEOUT_REMOVER);
|
||||
}
|
||||
}));
|
||||
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.gradientText.setVisibility(View.GONE);
|
||||
@@ -277,7 +244,53 @@ public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
public void onPause() {
|
||||
handler.removeCallbacks(remover);
|
||||
remover.run();
|
||||
binding.gradientScroll.setOnTouchListener(null);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
|
||||
ViewPager2 pager = getActivity().findViewById(R.id.pager);
|
||||
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
|
||||
@Override
|
||||
public void onSlide(float relative) {
|
||||
if (!hasData()) return;
|
||||
animator.cancel();
|
||||
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientText.setAlpha(1);
|
||||
handler.removeCallbacks(remover);
|
||||
if (!closed) {
|
||||
if (layout != null)
|
||||
layout.setExpanded(false, true);
|
||||
closed = true;
|
||||
}
|
||||
if (pager != null)
|
||||
pager.setUserInputEnabled(false);
|
||||
updateSelection(relative);
|
||||
updateCondition(relative);
|
||||
binding.gradientText.setVisibility(View.VISIBLE);
|
||||
updateGuide(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideEnd() {
|
||||
if (pager != null)
|
||||
pager.setUserInputEnabled(true);
|
||||
closed = false;
|
||||
animator.start();
|
||||
handler.postDelayed(remover, TIMEOUT_REMOVER);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
binding.gradientTouch.setOnTouchListener(null);
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,8 +90,8 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
appController.navigate(R.id.destination_station, bundle, opts.build());
|
||||
}
|
||||
});
|
||||
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
|
||||
binding.setConditionListener(m -> {
|
||||
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
|
||||
cityController.navigate(R.id.destination_city_forecast);
|
||||
});
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
|
||||
@@ -36,6 +36,11 @@ import java.util.List;
|
||||
*/
|
||||
public class CityVideoFragment extends CityFragment.ChildFragment {
|
||||
|
||||
/**
|
||||
* The mediator to update the tabs.
|
||||
*/
|
||||
private TabLayoutMediator mediator;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -49,32 +54,40 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
|
||||
TabLayout tabs = view.findViewById(R.id.tabs);
|
||||
List<Integer> pages = new ArrayList<>();
|
||||
CityViewModel model = getCityViewModel();
|
||||
pager.setAdapter(new VideoAdpter(this, pages));
|
||||
updateMediator(tabs, pager, pages);
|
||||
Observer<List<VideoViewModel>> videoObserver = (v) -> {
|
||||
pages.clear();
|
||||
if (model.getIconGlobal().getValue().size() > 0) pages.add(0, 0);
|
||||
if (model.getIconEurope().getValue().size() > 0) pages.add(0, 1);
|
||||
if (model.getCosmoEurope().getValue().size() > 0) pages.add(0, 2);
|
||||
pager.setAdapter(new VideoAdpter(this, pages));
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
int page = pages.get(position);
|
||||
switch (page) {
|
||||
case 0:
|
||||
tab.setText(R.string.video_source_icon_global);
|
||||
break;
|
||||
case 1:
|
||||
tab.setText(R.string.video_source_icon_europe);
|
||||
break;
|
||||
default:
|
||||
tab.setText(R.string.video_source_cosmo_europe);
|
||||
break;
|
||||
}
|
||||
}).attach();
|
||||
updateMediator(tabs, pager, pages);
|
||||
};
|
||||
model.getCosmoEurope().observe(getViewLifecycleOwner(), videoObserver);
|
||||
model.getIconEurope().observe(getViewLifecycleOwner(), videoObserver);
|
||||
model.getIconGlobal().observe(getViewLifecycleOwner(), videoObserver);
|
||||
}
|
||||
|
||||
private void updateMediator(TabLayout tabs, ViewPager2 pager, List<Integer> pages) {
|
||||
if (mediator != null && mediator.isAttached()) mediator.detach();
|
||||
mediator = new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
int page = pages.get(position);
|
||||
switch (page) {
|
||||
case 0:
|
||||
tab.setText(R.string.video_source_icon_global);
|
||||
break;
|
||||
case 1:
|
||||
tab.setText(R.string.video_source_icon_europe);
|
||||
break;
|
||||
default:
|
||||
tab.setText(R.string.video_source_cosmo_europe);
|
||||
break;
|
||||
}
|
||||
});
|
||||
mediator.attach();
|
||||
}
|
||||
|
||||
/**
|
||||
* The adapter for the pager that displays the different videos.
|
||||
*
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.FragmentCollectionBinding;
|
||||
import com.mowesta.android.app.util.DisplayUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The fragment to onboard the user with data collection.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CollectionFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*/
|
||||
private MowestaSettings settings;
|
||||
|
||||
/**
|
||||
* The view binding.
|
||||
*/
|
||||
private FragmentCollectionBinding binding;
|
||||
|
||||
/**
|
||||
* Keeps track of preference and updates the state of the switch.
|
||||
*/
|
||||
private OnSharedPreferenceChangeListener preferenceListener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
binding.privacyMeasureSwitch.setChecked(settings.isPrivacyMeasure());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_collection, container, false);
|
||||
binding.buttonContinue.setOnClickListener((v) -> {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_collection_drawer);
|
||||
settings.setCollectionShown(true);
|
||||
}
|
||||
);
|
||||
binding.privacyMeasureSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
boolean current = settings.isPrivacyMeasure();
|
||||
if (current != isChecked) {
|
||||
settings.setPrivacyMeasure(isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
binding.logoFair.setOnClickListener((v) -> openBrowser(R.string.fair_url));
|
||||
binding.logoUde.setOnClickListener((v) -> openBrowser(R.string.ude_url));
|
||||
// add a funky animation
|
||||
if (savedInstanceState == null) {
|
||||
List<View> views = new ArrayList<>();
|
||||
views.add(binding.collectionNoteLocation);
|
||||
views.add(binding.collectionNoteData);
|
||||
views.add(binding.collectionNoteEnable);
|
||||
views.add(binding.privacyMeasureSwitch);
|
||||
views.add(binding.collectionNotePermission);
|
||||
views.add(binding.buttonContinue);
|
||||
AnimatorSet set = new AnimatorSet();
|
||||
ObjectAnimator first = ObjectAnimator.ofFloat(binding.logoSun, "translationY", DisplayUtils.dpToPixels(getContext(), 90), 0f);
|
||||
first.setDuration(1000);
|
||||
first.setInterpolator(new OvershootInterpolator());
|
||||
ObjectAnimator last = ObjectAnimator.ofFloat(binding.logoSun, "translationX", DisplayUtils.dpToPixels(getContext(), 90), 0f);
|
||||
last.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
last.setDuration(1000);
|
||||
set.playTogether(first, last);
|
||||
for (View view: views) {
|
||||
view.setAlpha(0);
|
||||
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
|
||||
objectAnimator.setInterpolator(new LinearInterpolator());
|
||||
objectAnimator.setDuration(100);
|
||||
set.play(objectAnimator).after(last);
|
||||
last = objectAnimator;
|
||||
}
|
||||
set.start();
|
||||
}
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the url to which the resource string is pointing in a browser.
|
||||
*
|
||||
* @param res The resource pointing to a string representing the url.
|
||||
*/
|
||||
private void openBrowser(int res) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(getResources().getString(res)));
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Snackbar.make(getView(), R.string.message_no_browser, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
settings.getPreferences().registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
binding.privacyMeasureSwitch.setChecked(settings.isPrivacyMeasure());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
settings.getPreferences().unregisterOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.DialogColorBinding;
|
||||
import com.mowesta.android.app.model.ColorViewModel;
|
||||
|
||||
/**
|
||||
* A dialog fragment to display a color picker. The fragment uses the parent's color view model
|
||||
* to communicate with the caller.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ColorDialogFragment extends DialogFragment {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
ColorViewModel model = new ViewModelProvider(getParentFragment()).get(ColorViewModel.class);
|
||||
DialogColorBinding binding = DataBindingUtil.inflate(inflater, R.layout.dialog_color, container, false);
|
||||
binding.setModel(model);
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
View view = inflater.inflate(R.layout.dialog_color, null);
|
||||
binding.colorSliderRed.setValue(model.getRed().getValue());
|
||||
binding.colorSliderGreen.setValue(model.getGreen().getValue());
|
||||
binding.colorSliderBlue.setValue(model.getBlue().getValue());
|
||||
binding.colorSliderRed.addOnChangeListener((slider, value, fromUser) -> {
|
||||
if (fromUser) model.getRed().setValue(value);
|
||||
});
|
||||
binding.colorSliderGreen.addOnChangeListener((slider, value, fromUser) -> {
|
||||
if (fromUser) model.getGreen().setValue(value);
|
||||
});
|
||||
binding.colorSliderBlue.addOnChangeListener((slider, value, fromUser) -> {
|
||||
if (fromUser) model.getBlue().setValue(value);
|
||||
});
|
||||
model.getColor().observe(getViewLifecycleOwner(), (color) -> {
|
||||
binding.colorResultText.setTextColor(color);
|
||||
binding.colorResultImage.setColorFilter(color);
|
||||
});
|
||||
binding.buttonOk.setOnClickListener((v) -> {
|
||||
model.setState(ColorViewModel.State.CONFIRMED);
|
||||
dismiss();
|
||||
});
|
||||
binding.buttonCancel.setOnClickListener((v) -> {
|
||||
model.setState(ColorViewModel.State.DISMISSED);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(@NonNull DialogInterface dialog) {
|
||||
ColorViewModel model = new ViewModelProvider(getParentFragment()).get(ColorViewModel.class);
|
||||
model.setState(ColorViewModel.State.DISMISSED);
|
||||
super.onCancel(dialog);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import android.animation.ObjectAnimator;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -176,7 +177,7 @@ public class ConnectFragment extends Fragment {
|
||||
/**
|
||||
* The handler to post events asynchronously.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -217,7 +218,7 @@ public class ConnectFragment extends Fragment {
|
||||
});
|
||||
Args args = Args.fromBundle(getArguments());
|
||||
if (args == null) {
|
||||
getActivity().onBackPressed();
|
||||
getActivity().getOnBackPressedDispatcher().onBackPressed();
|
||||
} else {
|
||||
model.init(args);
|
||||
}
|
||||
@@ -292,7 +293,7 @@ public class ConnectFragment extends Fragment {
|
||||
if (binding != null) {
|
||||
binding.connectSun.setAlpha(0f);
|
||||
TypedValue typedValue = new TypedValue();
|
||||
getActivity().getTheme().resolveAttribute(R.attr.colorControlNormal, typedValue, true);
|
||||
getActivity().getTheme().resolveAttribute(androidx.appcompat.R.attr.colorControlNormal, typedValue, true);
|
||||
int color = ContextCompat.getColor(getActivity(), typedValue.resourceId);
|
||||
ImageViewCompat.setImageTintList(binding.connectConfigure, ColorStateList.valueOf(color));
|
||||
ImageViewCompat.setImageTintList(binding.connectDevice, ColorStateList.valueOf(color));
|
||||
|
||||
@@ -83,7 +83,7 @@ public class CountryFragment extends AbstractPlaceFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DeviceFragment extends AbstractDiagramFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
IApp app = (IApp)getContext().getApplicationContext();
|
||||
app.getUserRepository().getCredentials().observe(getViewLifecycleOwner(), (c) -> model.setUserCredentials(c));
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
@@ -39,12 +40,6 @@ public class DevicesFragment extends AbstractNetworkFragment {
|
||||
return new ViewModelProvider(this).get(DevicesViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -55,6 +50,22 @@ public class DevicesFragment extends AbstractNetworkFragment {
|
||||
Bundle bundle = new Bundle();
|
||||
controller.navigate(R.id.destination_setup, bundle, opts.build());
|
||||
});
|
||||
getActivity().addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_refresh, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_refresh) {
|
||||
DevicesViewModel model = new ViewModelProvider(DevicesFragment.this).get(DevicesViewModel.class);
|
||||
model.reload();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner());
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -84,21 +95,6 @@ public class DevicesFragment extends AbstractNetworkFragment {
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> model.reload());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_refresh, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_refresh) {
|
||||
DevicesViewModel model = new ViewModelProvider(this).get(DevicesViewModel.class);
|
||||
model.reload();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.database.AbstractCursor;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -26,6 +28,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.cursoradapter.widget.CursorAdapter;
|
||||
import androidx.customview.widget.Openable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
@@ -76,44 +79,6 @@ public class DrawerFragment extends AbstractNetworkFragment {
|
||||
return new ViewModelProvider(this).get(DrawerViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
preventSplashScreen();
|
||||
handleNotificationIntent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent going back to the splash screen if opened through deep link.
|
||||
*/
|
||||
private void preventSplashScreen() {
|
||||
NavController nav = Navigation.findNavController(getActivity().findViewById(R.id.navigation_app));
|
||||
if (nav.getGraph().getId() != R.id.navigation_core) {
|
||||
nav.setGraph(R.navigation.navigation_core);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the intent was generated by the background service and
|
||||
* opens the settings screen, if this is the case
|
||||
*/
|
||||
private void handleNotificationIntent() {
|
||||
Intent intent = getActivity().getIntent();
|
||||
if (intent.hasExtra(getString(R.string.mowesta_sdk_notification_activity_extra_name))) {
|
||||
String value = intent.getStringExtra(getString(R.string.mowesta_sdk_notification_activity_extra_name));
|
||||
if (value != null && value.equals(getString(R.string.mowesta_sdk_notification_activity_extra_value))) {
|
||||
Navigation.findNavController(getView().findViewById(R.id.navigation_drawer)).navigate(R.id.destination_settings);
|
||||
getActivity().setIntent(new Intent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -121,48 +86,52 @@ public class DrawerFragment extends AbstractNetworkFragment {
|
||||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
|
||||
loadingProgressBar = view.findViewById(R.id.progress_bar);
|
||||
getActivity().addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
|
||||
menuInflater.inflate(R.menu.menu_search, menu);
|
||||
SearchView search = (SearchView)menu.findItem(R.id.action_search).getActionView();
|
||||
search.setQueryHint(getString(R.string.action_search));
|
||||
SearchView.SearchAutoComplete complete = search.findViewById(androidx.appcompat.R.id.search_src_text);
|
||||
complete.setDropDownBackgroundResource(R.color.bg_search);
|
||||
final DrawerViewModel model = new ViewModelProvider(DrawerFragment.this).get(DrawerViewModel.class);
|
||||
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
model.setTerm(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
search.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
|
||||
@Override
|
||||
public boolean onSuggestionSelect(int position) {
|
||||
showLocation(model, position);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSuggestionClick(int position) {
|
||||
showLocation(model, position);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
search.setSuggestionsAdapter(new LocationCursorAdapter(getContext(), model.getResults()));
|
||||
AppBarLayout appbar = getView().findViewById(R.id.layout_appbar);
|
||||
search.setOnSearchClickListener((v)->appbar.setExpanded(false, true));
|
||||
}
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner());
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_search, menu);
|
||||
SearchView search = (SearchView)menu.findItem(R.id.action_search).getActionView();
|
||||
search.setQueryHint(getString(R.string.action_search));
|
||||
SearchView.SearchAutoComplete complete = search.findViewById(androidx.appcompat.R.id.search_src_text);
|
||||
complete.setDropDownBackgroundResource(R.color.bg_search);
|
||||
final DrawerViewModel model = new ViewModelProvider(this).get(DrawerViewModel.class);
|
||||
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
model.setTerm(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
search.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
|
||||
@Override
|
||||
public boolean onSuggestionSelect(int position) {
|
||||
showLocation(model, position);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSuggestionClick(int position) {
|
||||
showLocation(model, position);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
search.setSuggestionsAdapter(new LocationCursorAdapter(getContext(), model.getResults()));
|
||||
AppBarLayout appbar = getView().findViewById(R.id.layout_appbar);
|
||||
search.setOnSearchClickListener((v)->appbar.setExpanded(false, true));
|
||||
}
|
||||
|
||||
private void showLocation(DrawerViewModel model, int position) {
|
||||
LocationHierarchyPage page = model.getResults().getValue();
|
||||
LocationHierarchy dest = page.getElements().get(position);
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
@@ -40,23 +41,53 @@ import java.util.List;
|
||||
*/
|
||||
public class FavoritesFragment extends Fragment {
|
||||
|
||||
private static final String TAG_ADVERTISEMENT = "ad";
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
// possibly show the ad for eiszeit
|
||||
AdvertiseDialogFragment adf = new AdvertiseDialogFragment();
|
||||
if (adf.shouldShow(getContext()) && getChildFragmentManager().findFragmentByTag(TAG_ADVERTISEMENT) == null) {
|
||||
adf.show(getChildFragmentManager(), TAG_ADVERTISEMENT);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_favorites, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_favorites, container, false);
|
||||
getActivity().addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_unit, menu);
|
||||
inflater.inflate(R.menu.menu_refresh, menu);
|
||||
// remove this item, since it would not have an effect here
|
||||
MenuItem item = menu.findItem(R.id.action_unit_system);
|
||||
if (item != null) item.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_refresh) {
|
||||
FavoritesViewModel model = new ViewModelProvider(getActivity()).get(FavoritesViewModel.class);
|
||||
model.refresh();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_temperature_unit) {
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner());
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler);
|
||||
TabletUtil.setGridLayout(recyclerView, 300);
|
||||
TabletUtil.setGridLayout(recyclerView, 350);
|
||||
SwipeRefreshLayout swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
|
||||
FavoritesViewModel model = new ViewModelProvider(getActivity()).get(FavoritesViewModel.class);
|
||||
model.getRefreshing().observe(getViewLifecycleOwner(), (refreshing) -> {
|
||||
@@ -95,8 +126,8 @@ public class FavoritesFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||
int fromPosition = viewHolder.getAdapterPosition();
|
||||
int toPosition = target.getAdapterPosition();
|
||||
int fromPosition = viewHolder.getBindingAdapterPosition();
|
||||
int toPosition = target.getBindingAdapterPosition();
|
||||
this.target = toPosition;
|
||||
recyclerView.getAdapter().notifyItemMoved(fromPosition, toPosition);
|
||||
return false;
|
||||
@@ -122,7 +153,7 @@ public class FavoritesFragment extends Fragment {
|
||||
favorites = null;
|
||||
} else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
|
||||
favorites = model.getFavorites().getValue();
|
||||
selection = viewHolder.getAdapterPosition();
|
||||
selection = viewHolder.getBindingAdapterPosition();
|
||||
target = -1;
|
||||
}
|
||||
}
|
||||
@@ -140,29 +171,6 @@ public class FavoritesFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_unit, menu);
|
||||
inflater.inflate(R.menu.menu_refresh, menu);
|
||||
// remove this item, since it would not have an effect here
|
||||
MenuItem item = menu.findItem(R.id.action_unit_system);
|
||||
if (item != null) item.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_refresh) {
|
||||
FavoritesViewModel model = new ViewModelProvider(getActivity()).get(FavoritesViewModel.class);
|
||||
model.refresh();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_temperature_unit) {
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The view holder for favorites.
|
||||
*
|
||||
|
||||
+66
-28
@@ -5,7 +5,7 @@ import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.renderscript.ScriptGroup;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -23,11 +23,12 @@ import com.mowesta.android.app.database.Widget;
|
||||
import com.mowesta.android.app.database.WidgetDatabase;
|
||||
import com.mowesta.android.app.databinding.FragmentForecastWidgetBinding;
|
||||
import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.model.ColorViewModel;
|
||||
import com.mowesta.android.app.model.ForecastWidgetViewModel;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.app.widget.AbstractWidgetProvider;
|
||||
import com.mowesta.android.app.widget.ForecastWidgetProvider;
|
||||
import com.mowesta.android.app.widget.WidgetReceiver;
|
||||
import com.mowesta.android.app.widget.WidgetService;
|
||||
import com.mowesta.android.app.widget.PeriodicWidgetWorker;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,11 @@ import com.mowesta.android.feign.model.City;
|
||||
*/
|
||||
public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "ForecastWidgetFragment";
|
||||
|
||||
/**
|
||||
* The bundle extra to store the widget id.
|
||||
*/
|
||||
@@ -83,6 +89,9 @@ public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
ForecastWidgetViewModel model = new ViewModelProvider(this).get(ForecastWidgetViewModel.class);
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.setModel(model);
|
||||
model.getColor().observe(getViewLifecycleOwner(), (color) -> {
|
||||
binding.buttonColor.setColorFilter(color);
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -90,6 +99,12 @@ public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ForecastWidgetViewModel model = new ViewModelProvider(this).get(ForecastWidgetViewModel.class);
|
||||
ColorViewModel color = new ViewModelProvider(this).get(ColorViewModel.class);
|
||||
color.getState().observe(getViewLifecycleOwner(), state -> {
|
||||
if (state == ColorViewModel.State.CONFIRMED) {
|
||||
model.getColor().setValue(color.getColor().getValue());
|
||||
}
|
||||
});
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler);
|
||||
recyclerView.setAdapter(new CityEntryListAdapter(
|
||||
getViewLifecycleOwner(),
|
||||
@@ -97,7 +112,23 @@ public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
model.getCities(),
|
||||
model.getSelection()));
|
||||
model.getFinished().observe(getViewLifecycleOwner(), (c) -> {
|
||||
if (c != null) finish(c, model.getCelsius().getValue());
|
||||
Activity activity = getActivity();
|
||||
if (c != null) {
|
||||
try {
|
||||
finish(activity, c, model.getCelsius().getValue(), model.getColor().getValue());
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to finish.", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
model.getDialog().observe(getViewLifecycleOwner(), (d) -> {
|
||||
if (d) {
|
||||
color.setColor(model.getColor().getValue());
|
||||
color.setState(ColorViewModel.State.VISIBLE);
|
||||
ColorDialogFragment cdf = new ColorDialogFragment();
|
||||
cdf.show(getChildFragmentManager(), "color");
|
||||
model.getDialog().setValue(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,37 +136,44 @@ public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
* Finishes the the configuration and stores the widget configuration in the database.
|
||||
*
|
||||
* @param city The city.
|
||||
* @param color The color.
|
||||
* @param celsius A flag to indicate whether the widget uses celsius or fahrenheit.
|
||||
*/
|
||||
public void finish(City city, boolean celsius) {
|
||||
Activity activity = getActivity();
|
||||
public void finish(Activity activity, City city, boolean celsius, int color) {
|
||||
Context app = activity.getApplicationContext();
|
||||
DatabaseTask<WidgetDatabase, Integer, Widget> task = new DatabaseTask<>((input, database)-> {
|
||||
long now = System.currentTimeMillis();
|
||||
Widget w = new Widget();
|
||||
w.setReference(input);
|
||||
w.setType(Widget.TYPE_FORECAST);
|
||||
w.setCelsius(celsius);
|
||||
w.setDataId(city.getId());
|
||||
w.setData(city);
|
||||
w.setDataTime(now);
|
||||
database.getAccessor().add(w);
|
||||
return w;
|
||||
long now = System.currentTimeMillis();
|
||||
Widget w = new Widget();
|
||||
w.setReference(input);
|
||||
w.setType(Widget.TYPE_FORECAST);
|
||||
w.setCelsius(celsius);
|
||||
w.setDataId(city.getId());
|
||||
w.setData(city);
|
||||
w.setDataTime(now);
|
||||
w.setColor(color);
|
||||
database.runInTransaction(() -> {
|
||||
Log.d(TAG, "Added widget of type " + Widget.TYPE_FORECAST + " with id " + input + ".");
|
||||
database.getAccessor().delete(Widget.TYPE_FORECAST, input);
|
||||
database.getAccessor().add(w);
|
||||
});
|
||||
return w;
|
||||
}, (input, result) -> {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.triggerUpdate(app, input);
|
||||
if (!activity.isDestroyed()) {
|
||||
activity.finish();
|
||||
try {
|
||||
if (!activity.isDestroyed()) {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.loadWidget(app, input);
|
||||
provider.triggerUpdate(app, input, true);
|
||||
PeriodicWidgetWorker.scheduleUpdates(app);
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, input);
|
||||
activity.setResult(Activity.RESULT_OK, resultValue);
|
||||
activity.finish();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.e(TAG, "Failed to update widget.", e);
|
||||
}
|
||||
});
|
||||
WidgetReceiver.scheduleUpdates(app);
|
||||
int id = getWidgetId();
|
||||
task.execute(id, ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
|
||||
activity.setResult(Activity.RESULT_OK, resultValue);
|
||||
task.execute(getWidgetId(), ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -51,16 +51,16 @@ public class LoginFragment extends Fragment {
|
||||
NavOptions.Builder b = new NavOptions.Builder().setPopUpTo(R.id.destination_favorites, false);
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_devices, null, b.build());
|
||||
break;
|
||||
case COLLECTION:
|
||||
case DRAWER:
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_collection);
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_drawer);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// this is most likely bug in the navigation library, since it cannot find the
|
||||
// node in the xml file which is technically impossible (probably a race during loading)
|
||||
NavOptions.Builder builder = new NavOptions.Builder().setPopUpTo(R.id.destination_login, true);
|
||||
builder.setEnterAnim(R.anim.slide_in_right);
|
||||
builder.setExitAnim(R.anim.slide_out_left);
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_collection, null, builder.build());
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_drawer, null, builder.build());
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+50
-17
@@ -1,9 +1,7 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -17,23 +15,22 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavDeepLinkBuilder;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaActivity;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.adapter.DeviceEntryPagedListAdapter;
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
import com.mowesta.android.app.database.WidgetDatabase;
|
||||
import com.mowesta.android.app.databinding.FragmentMeasureWidgetBinding;
|
||||
import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.model.ColorViewModel;
|
||||
import com.mowesta.android.app.model.MeasureWidgetViewModel;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.app.widget.MeasureWidgetProvider;
|
||||
import com.mowesta.android.app.widget.WidgetReceiver;
|
||||
import com.mowesta.android.app.widget.PeriodicWidgetWorker;
|
||||
import com.mowesta.android.feign.model.Device;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -46,6 +43,11 @@ import java.util.List;
|
||||
*/
|
||||
public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "MeasureWidgetFragment";
|
||||
|
||||
/**
|
||||
* The bundle extra to store the widget id.
|
||||
*/
|
||||
@@ -108,6 +110,9 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
binding.customizeTemperature.setOnItemClickListener((parent, view, position, id) -> {
|
||||
model.getCelsius().setValue(position == 0);
|
||||
});
|
||||
model.getColor().observe(getViewLifecycleOwner(), (color) -> {
|
||||
binding.buttonColor.setColorFilter(color);
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -115,6 +120,12 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
MeasureWidgetViewModel model = new ViewModelProvider(this).get(MeasureWidgetViewModel.class);
|
||||
ColorViewModel color = new ViewModelProvider(this).get(ColorViewModel.class);
|
||||
color.getState().observe(getViewLifecycleOwner(), state -> {
|
||||
if (state == ColorViewModel.State.CONFIRMED) {
|
||||
model.getColor().setValue(color.getColor().getValue());
|
||||
}
|
||||
});
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler);
|
||||
DeviceEntryPagedListAdapter adapter = new DeviceEntryPagedListAdapter(getViewLifecycleOwner(), (device) -> {
|
||||
model.getSelection().setValue(device);
|
||||
@@ -129,7 +140,14 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
recyclerView.setAdapter(adapter);
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> model.reload());
|
||||
model.getFinished().observe(getViewLifecycleOwner(), (c) -> {
|
||||
if (c != null) finish(c, model.getCelsius().getValue(), model.getSi().getValue());
|
||||
Activity activity = getActivity();
|
||||
if (c != null) {
|
||||
try {
|
||||
finish(activity, c, model.getCelsius().getValue(), model.getSi().getValue(), model.getColor().getValue());
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to finish.", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
model.getLogin().observe(getViewLifecycleOwner(), (v) -> {
|
||||
if (v) {
|
||||
@@ -137,6 +155,15 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
model.getDialog().observe(getViewLifecycleOwner(), (d) -> {
|
||||
if (d) {
|
||||
color.setColor(model.getColor().getValue());
|
||||
color.setState(ColorViewModel.State.VISIBLE);
|
||||
ColorDialogFragment cdf = new ColorDialogFragment();
|
||||
cdf.show(getChildFragmentManager(), "color");
|
||||
model.getDialog().setValue(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,12 +203,13 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
/**
|
||||
* Finishes the the configuration and stores the widget configuration in the database.
|
||||
*
|
||||
* @param activity The activity.
|
||||
* @param device The device.
|
||||
* @param celsius A flag to indicate whether the widget uses celsius or fahrenheit.
|
||||
* @param color The widget color.
|
||||
* @param si A flag to indicate which measurement unit system.
|
||||
*/
|
||||
public void finish(Device device, boolean celsius, boolean si) {
|
||||
Activity activity = getActivity();
|
||||
public void finish(Activity activity, Device device, boolean celsius, boolean si, int color) {
|
||||
Context app = activity.getApplicationContext();
|
||||
DatabaseTask<WidgetDatabase, Integer, Widget> task = new DatabaseTask<>((input, database)-> {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -189,25 +217,30 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
w.setReference(input);
|
||||
w.setType(Widget.TYPE_MEASURE);
|
||||
w.setCelsius(celsius);
|
||||
w.setColor(color);
|
||||
w.setSi(si);
|
||||
w.setDataId(device.getId());
|
||||
w.setData(device);
|
||||
w.setDataTime(now);
|
||||
database.getAccessor().add(w);
|
||||
database.runInTransaction(() -> {
|
||||
database.getAccessor().delete(Widget.TYPE_MEASURE, input);
|
||||
database.getAccessor().add(w);
|
||||
Log.d(TAG, "Added widget of type " + Widget.TYPE_MEASURE + " with id " + input + ".");
|
||||
});
|
||||
return w;
|
||||
}, (input, result) -> {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.triggerUpdate(app, input);
|
||||
if (!activity.isDestroyed()) {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.loadWidget(app, input);
|
||||
provider.triggerUpdate(app, input, true);
|
||||
PeriodicWidgetWorker.scheduleUpdates(app);
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, input);
|
||||
activity.setResult(Activity.RESULT_OK, resultValue);
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
WidgetReceiver.scheduleUpdates(app);
|
||||
int id = getWidgetId();
|
||||
task.execute(id, ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
|
||||
activity.setResult(Activity.RESULT_OK, resultValue);
|
||||
task.execute(getWidgetId(), ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,9 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.mowesta.android.app.BuildConfig;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaApp;
|
||||
import com.mowesta.android.app.MowestaService;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.repository.DeviceRepository;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.sdk.SdkRepository;
|
||||
import com.mowesta.android.sdk.task.ClearTask;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
@@ -24,8 +19,6 @@ import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
@@ -159,7 +152,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
bindReset();
|
||||
bindTerms();
|
||||
bindLicenses();
|
||||
bindSdkSettings();
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -200,8 +192,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
*/
|
||||
private void updateBuild() {
|
||||
try {
|
||||
ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(getActivity().getPackageName(), 0);
|
||||
PackageInfo pi = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
|
||||
String summary = getResources().getString(R.string.setting_about_build_summary);
|
||||
summary = summary.replace("$version$", BuildConfig.VERSION_NAME);
|
||||
summary = summary.replace("$code$", "" + BuildConfig.VERSION_CODE);
|
||||
@@ -240,7 +230,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
// there are no notification settings on older devices
|
||||
getPreferenceScreen().removePreference(category);
|
||||
} else {
|
||||
setClickListener(KEY_NOTIFICATION_APP, createNotificationSettingsListener(getActivity().getPackageName(), getString(R.string.mowesta_sdk_notification_channel_id)));
|
||||
setClickListener(KEY_NOTIFICATION_OS, createNotificationSettingsListener("android", "FOREGROUND_SERVICE"));
|
||||
}
|
||||
}
|
||||
@@ -334,7 +323,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
setClickListener(KEY_ABOUT_TERMS, new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Navigation.findNavController(getActivity(), R.id.navigation_app).navigate(R.id.destination_terms);
|
||||
Navigation.findNavController(getActivity(), R.id.navigation_app).navigate(R.id.destination_review);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -354,20 +343,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the sdk settings.
|
||||
*/
|
||||
private void bindSdkSettings() {
|
||||
setClickListener(KEY_DEVELOPMENT_CLEAR_CACHE, new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new ClearTask(SdkRepository.getInstance(getActivity().getApplication()), false, () -> {
|
||||
Toast.makeText(preference.getContext(), R.string.setting_development_clear_message, Toast.LENGTH_SHORT).show();
|
||||
}).execute();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the developmentGroup mode.
|
||||
@@ -432,35 +407,22 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
b.setTitle(R.string.setting_privacy_reset_title);
|
||||
b.setMessage(R.string.setting_privacy_reset_message);
|
||||
b.setIcon(R.drawable.ic_delete_forever_normal_24);
|
||||
b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
b.setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// stop the service and its background processing
|
||||
Log.d(TAG, "Resetting the device.");
|
||||
Activity activity = getActivity();
|
||||
MowestaService.stopService(activity);
|
||||
// reset the settings
|
||||
MowestaApp app = (MowestaApp)activity.getApplication();
|
||||
SdkRepository sdk = SdkRepository.getInstance(app);
|
||||
MowestaSettings settings = app.getSettings();
|
||||
settings.setPrivacyMeasure(false);
|
||||
settings.setCollectionShown(false);
|
||||
app.getUserRepository().clearCredentials();
|
||||
app.getDeviceRepository().clearDevice();
|
||||
new ClearTask(sdk, true, ()-> {
|
||||
new DatabaseTask<FavoriteDatabase, Void, Void>
|
||||
((input, database)-> {
|
||||
Log.d(TAG, "Clearing database.");
|
||||
database.getAccessor().clearAll();
|
||||
return null;
|
||||
},(input, result)-> {
|
||||
Log.d(TAG, "Finishing the activity.");
|
||||
activity.finish();
|
||||
}).execute(null, app.getFavoriteRepository().getDatabase());
|
||||
}).execute();
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
b.setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// nothing to be done
|
||||
|
||||
@@ -17,6 +17,7 @@ import android.view.animation.OvershootInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
@@ -66,7 +67,7 @@ public class SetupFragment extends Fragment {
|
||||
SetupViewModel.GpsStatus status = model.registerGpsReceiver();
|
||||
switch (status) {
|
||||
case PROHIBITED:
|
||||
((MowestaActivity)getActivity()).requestPermissions(PermissionUtil.getForegroundPermissions(getActivity()));
|
||||
ActivityCompat.requestPermissions(getActivity(), PermissionUtil.getForegroundPermissions(getActivity()), MowestaActivity.CODE_REQUEST_FOREGROUND_PERMISSIONS);
|
||||
break;
|
||||
case DISABLED:
|
||||
Snackbar.make(container, R.string.setup_error_gps_disabled, Snackbar.LENGTH_LONG).setAction(R.string.button_configure, (v) -> {
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -44,8 +45,6 @@ public class SplashFragment extends Fragment {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_terms);
|
||||
} else if (shouldShowLogin()) {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_login);
|
||||
} else if (shouldShowCollection()) {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_collection);
|
||||
} else {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_drawer);
|
||||
}
|
||||
@@ -54,7 +53,7 @@ public class SplashFragment extends Fragment {
|
||||
/**
|
||||
* The handler.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* The settings to check states.
|
||||
|
||||
@@ -84,7 +84,7 @@ public class StateFragment extends AbstractPlaceFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class StationFragment extends AbstractDiagramFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -23,14 +24,33 @@ import com.mowesta.android.app.databinding.FragmentStationsBinding;
|
||||
import com.mowesta.android.app.databinding.ViewStationEntryBinding;
|
||||
import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.model.StationsViewModel;
|
||||
import com.mowesta.android.app.util.TabletUtil;
|
||||
import com.mowesta.android.feign.model.WeatherStation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Shows a list of the available stations.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class StationsFragment extends AbstractNetworkFragment {
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
private void applyGridWidth() {
|
||||
if (!TabletUtil.isTablet(requireContext())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int width = requireContext().getResources().getInteger(R.integer.RecyclerWidth);
|
||||
TabletUtil.setGridLayout(recyclerView, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NotNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
applyGridWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractNetworkViewModel getNetworkViewModel() {
|
||||
@@ -50,7 +70,9 @@ public class StationsFragment extends AbstractNetworkFragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
RecyclerView recycler = view.findViewById(R.id.recycler);
|
||||
recyclerView = view.findViewById(R.id.recycler);
|
||||
applyGridWidth();
|
||||
|
||||
StationsViewModel model = new ViewModelProvider(this).get(StationsViewModel.class);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
StationEntryPagedListAdapter adapter = new StationEntryPagedListAdapter(getViewLifecycleOwner(), (station) -> {
|
||||
@@ -65,7 +87,7 @@ public class StationsFragment extends AbstractNetworkFragment {
|
||||
model.getStations().observe(getViewLifecycleOwner(), (list) -> {
|
||||
adapter.submitList(list);
|
||||
});
|
||||
recycler.setAdapter(adapter);
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +163,7 @@ public class StationsFragment extends AbstractNetworkFragment {
|
||||
* Creates a new paged list adapter that will inform
|
||||
* the listener about click events.
|
||||
*
|
||||
* @param owner The lifecycle owner.
|
||||
* @param owner The lifecycle owner.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public StationEntryPagedListAdapter(@NonNull LifecycleOwner owner, @NonNull StationsViewModel.OnStationSelectedListener listener) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
@@ -33,11 +34,14 @@ import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
import androidx.webkit.WebViewAssetLoader;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
@@ -146,7 +150,7 @@ public class TermsFragment extends Fragment {
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public static class BrowserFragment extends CityFragment.ChildFragment {
|
||||
public static class BrowserFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The web view to show the contents.
|
||||
@@ -165,7 +169,9 @@ public class TermsFragment extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
int url = getArguments().getInt("url", 0);
|
||||
webView = (WebView) view.findViewById(R.id.web_view);
|
||||
webView.getSettings().setAllowFileAccessFromFileURLs(true);
|
||||
final WebViewAssetLoader assetLoader = new WebViewAssetLoader.Builder()
|
||||
.addPathHandler("/assets/", new WebViewAssetLoader.AssetsPathHandler(view.getContext()))
|
||||
.build();
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -179,6 +185,20 @@ public class TermsFragment extends Fragment {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequiresApi(21)
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view,
|
||||
WebResourceRequest request) {
|
||||
return assetLoader.shouldInterceptRequest(request.getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // for API < 21
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
return assetLoader.shouldInterceptRequest(Uri.parse(url));
|
||||
}
|
||||
|
||||
});
|
||||
if (url != 0) {
|
||||
webView.loadUrl(getResources().getString(url));
|
||||
|
||||
@@ -6,10 +6,12 @@ import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
@@ -17,21 +19,23 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
|
||||
import androidx.media3.ui.AspectRatioFrameLayout;
|
||||
import androidx.media3.ui.PlayerView;
|
||||
import androidx.media3.datasource.DefaultHttpDataSource;
|
||||
import androidx.media3.datasource.cache.CacheDataSource;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
@@ -154,7 +158,7 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
/**
|
||||
* The handler for the timing.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* The date formatter.
|
||||
@@ -229,6 +233,7 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
model = new ViewModelProvider(this).get(ExoPlayerViewModel.class);
|
||||
@@ -269,15 +274,18 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
timeUtils = new TimeUtils(System.currentTimeMillis(), timezone);
|
||||
formatter = new DateFormatter(getContext());
|
||||
if (model.exoPlayer == null) {
|
||||
model.exoPlayer = new SimpleExoPlayer.Builder(getContext()).build();
|
||||
model.exoPlayer = new ExoPlayer.Builder(getContext()).build();
|
||||
model.scaler.setContent(video.getWidth(), video.getHeight());
|
||||
IApp app = (IApp)getActivity().getApplication();
|
||||
DataSource.Factory dataSourceFactory = new CacheDataSourceFactory
|
||||
(app.getMediaCache(), new DefaultHttpDataSourceFactory( Util.getUserAgent
|
||||
(getContext(), getContext().getPackageName()), null));
|
||||
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(Uri.parse(video.getUrl()));
|
||||
model.exoPlayer.prepare(videoSource);
|
||||
DefaultHttpDataSource.Factory hf = new DefaultHttpDataSource.Factory();
|
||||
hf.setUserAgent(Util.getUserAgent(getContext(), getContext().getPackageName()));
|
||||
CacheDataSource.Factory cdf = new CacheDataSource.Factory();
|
||||
cdf.setUpstreamDataSourceFactory(hf);
|
||||
cdf.setCache(app.getMediaCache());
|
||||
MediaSource videoSource = new ProgressiveMediaSource.Factory(cdf)
|
||||
.createMediaSource(MediaItem.fromUri(video.getUrl()));
|
||||
model.exoPlayer.setMediaSource(videoSource);
|
||||
model.exoPlayer.prepare();
|
||||
model.exoPlayer.setPlayWhenReady(true);
|
||||
model.scaleUrl = video.getScale();
|
||||
model.reload();
|
||||
@@ -311,7 +319,8 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
Window window = getActivity().getWindow();
|
||||
if (window != null) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
if (video != null) {
|
||||
handler.postDelayed(timer, 500);
|
||||
if (model.markerX != null && model.markerY != null) {
|
||||
@@ -326,7 +335,8 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
Window window = getActivity().getWindow();
|
||||
if (window != null) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
marker.removeOnLayoutChangeListener(markerListener);
|
||||
handler.removeCallbacks(timer);
|
||||
super.onPause();
|
||||
@@ -339,6 +349,7 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
* @param width The width.
|
||||
* @param height The height.
|
||||
*/
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
private void updateVideo(int width, int height) {
|
||||
model.scaler.setScreen(width, height);
|
||||
double scale = model.scaler.getScale();
|
||||
|
||||
+7
-1
@@ -1,6 +1,7 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
@@ -16,6 +17,11 @@ import com.mowesta.android.app.repository.ClientFactory;
|
||||
*/
|
||||
public abstract class AbstractNetworkViewModel extends AndroidViewModel {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "NetworkViewModel";
|
||||
|
||||
/**
|
||||
* A class to store a parameter together with a request code.
|
||||
*
|
||||
@@ -95,7 +101,7 @@ public abstract class AbstractNetworkViewModel extends AndroidViewModel {
|
||||
* Prints the internal state of the model.
|
||||
*/
|
||||
private void printState() {
|
||||
System.out.println(getClass().getSimpleName() + " " + requestCode + " " + error.getValue() + " " + requests.getValue());
|
||||
Log.d(TAG, getClass().getSimpleName() + " " + requestCode + " " + error.getValue() + " " + requests.getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
|
||||
import androidx.media3.datasource.AssetDataSource;
|
||||
import androidx.media3.datasource.DataSource;
|
||||
|
||||
public class AdvertiseViewModel extends AndroidViewModel {
|
||||
|
||||
private ExoPlayer exoPlayer;
|
||||
|
||||
private MutableLiveData<Boolean> close = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
private MutableLiveData<Boolean> open = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public AdvertiseViewModel(Application app) {
|
||||
super(app);
|
||||
ExoPlayer.Builder builder = new ExoPlayer.Builder(app);
|
||||
exoPlayer = builder.build();
|
||||
DataSource.Factory df = new DataSource.Factory() {
|
||||
@Override
|
||||
public DataSource createDataSource() {
|
||||
return new AssetDataSource(app);
|
||||
}
|
||||
};
|
||||
MediaSource videoSource = new ProgressiveMediaSource.Factory(df)
|
||||
.createMediaSource(MediaItem.fromUri("android_assets:///dasfest.mp4"));
|
||||
exoPlayer.setRepeatMode(ExoPlayer.REPEAT_MODE_ALL);
|
||||
exoPlayer.setMediaSource(videoSource);
|
||||
exoPlayer.prepare();
|
||||
exoPlayer.setPlayWhenReady(true);
|
||||
}
|
||||
|
||||
public MutableLiveData<Boolean> getClose() {
|
||||
return close;
|
||||
}
|
||||
|
||||
public MutableLiveData<Boolean> getOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
close.setValue(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public void open() {
|
||||
open.setValue(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public ExoPlayer getExoPlayer() {
|
||||
return exoPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
exoPlayer.stop();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,16 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.DataSource;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.paging.PositionalDataSource;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.CityPage;
|
||||
@@ -36,7 +32,7 @@ public class CitiesViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* A handler to run on the main thread.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates the view model.
|
||||
|
||||
@@ -11,8 +11,6 @@ import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.app.util.DateFormatter;
|
||||
import com.mowesta.android.app.util.TimeUtils;
|
||||
import com.mowesta.android.app.util.WeatherAggregate;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
/**
|
||||
* The view model for the color picker dialog.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ColorViewModel extends ViewModel {
|
||||
|
||||
/**
|
||||
* The dialog state.
|
||||
*/
|
||||
public static enum State {
|
||||
/** The dialog is hidden. */
|
||||
HIDDEN,
|
||||
/** The dialog is visible. */
|
||||
VISIBLE,
|
||||
/** The dialog is confirmed. */
|
||||
CONFIRMED,
|
||||
/** The dialog is dismissed. */
|
||||
DISMISSED
|
||||
}
|
||||
|
||||
/** The red component from 0-255 */
|
||||
private final MutableLiveData<Float> red = new MutableLiveData<>(Float.valueOf(255));
|
||||
/** The green component from 0-255 */
|
||||
private final MutableLiveData<Float> green = new MutableLiveData<>(Float.valueOf(255));
|
||||
/** The blue component from 0-255 */
|
||||
private final MutableLiveData<Float> blue = new MutableLiveData<>(Float.valueOf(255));
|
||||
/** The computed color as RGB */
|
||||
private final MutableLiveData<Integer> color = new MutableLiveData<Integer>();
|
||||
/** The dialog state. */
|
||||
private final MutableLiveData<State> state = new MutableLiveData<>(State.HIDDEN);
|
||||
|
||||
/**
|
||||
* Creates a new model.
|
||||
*/
|
||||
public ColorViewModel() {
|
||||
Observer<Float> observer = (v) -> {
|
||||
color.setValue(Color.rgb(red.getValue().intValue(), green.getValue().intValue(), blue.getValue().intValue()));
|
||||
};
|
||||
red.observeForever(observer);
|
||||
green.observeForever(observer);
|
||||
blue.observeForever(observer);
|
||||
observer.onChanged(0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns live data with the state.
|
||||
*
|
||||
* @return The live data with the state.
|
||||
*/
|
||||
public LiveData<State> getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
public LiveData<Integer> getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* The blue component 0-255.
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public MutableLiveData<Float> getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The red component 0-255.
|
||||
*
|
||||
* @return The red component.
|
||||
*/
|
||||
public MutableLiveData<Float> getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* The green component 0-255.
|
||||
*
|
||||
* @return The green component.
|
||||
*/
|
||||
public MutableLiveData<Float> getGreen() {
|
||||
return green;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color.
|
||||
*
|
||||
* @param rgb The rgb color.
|
||||
*/
|
||||
public void setColor(int rgb) {
|
||||
red.setValue(Float.valueOf((rgb >> 16) & 0xff));
|
||||
green.setValue(Float.valueOf((rgb >> 8) & 0xff));
|
||||
blue.setValue(Float.valueOf((rgb >> 0) & 0xff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dialog state.
|
||||
*
|
||||
* @param state The state.
|
||||
*/
|
||||
public void setState(State state) {
|
||||
this.state.setValue(state);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Presentation;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.DataSource;
|
||||
@@ -14,10 +12,8 @@ import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.paging.PositionalDataSource;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
@@ -25,7 +21,6 @@ import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.CityPage;
|
||||
import com.mowesta.android.feign.model.Country;
|
||||
import com.mowesta.android.feign.model.LocationReference;
|
||||
import com.mowesta.android.feign.model.State;
|
||||
|
||||
import org.geojson.Geometry;
|
||||
|
||||
@@ -61,7 +56,7 @@ public class CountryViewModel extends AbstractPlaceViewModel {
|
||||
/**
|
||||
* The handler to run on main.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* The loader for the country.
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.content.res.Resources;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
@@ -59,7 +60,7 @@ public class DeviceViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* The handler to run on main.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates a new view model.
|
||||
@@ -195,7 +196,7 @@ public class DeviceViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<DiagramEntry<Measurement>> callback) {
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(id, 0l, now, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(id, 0L, now, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()), params.requestedStartPosition, page.getTotal())); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (isCurrentRequest(requestCode)) {
|
||||
@@ -210,7 +211,7 @@ public class DeviceViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadRange(@NonNull LoadRangeParams params, @NonNull LoadRangeCallback<DiagramEntry<Measurement>> callback) {
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(id, 0l, now, params.startPosition, params.loadSize ); },
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(id, 0L, now, params.startPosition, params.loadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()))); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (id != null && credentials != null && isCurrentRequest(requestCode)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
@@ -13,11 +14,8 @@ import androidx.paging.PositionalDataSource;
|
||||
|
||||
import com.mowesta.android.app.repository.UserCredentials;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.Device;
|
||||
import com.mowesta.android.feign.model.DevicePage;
|
||||
import com.mowesta.android.feign.model.WeatherStation;
|
||||
import com.mowesta.android.feign.model.WeatherStationPage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -42,7 +40,7 @@ public class DevicesViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* The handler to debounce the updates to the search term.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates the view model.
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
@@ -15,6 +14,7 @@ import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.feign.model.LocationHierarchyPage;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class DrawerViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* A handler to debounce the search.
|
||||
*/
|
||||
final Handler handler = new Handler();
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* The task to perform the search.
|
||||
|
||||
+21
-9
@@ -1,26 +1,20 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.location.Location;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.CityPage;
|
||||
import com.mowesta.android.feign.model.LocationHierarchy;
|
||||
import com.mowesta.android.feign.model.LocationHierarchyPage;
|
||||
import com.mowesta.android.feign.model.LocationReference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -43,7 +37,7 @@ public class ForecastWidgetViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* A handler to post updates.
|
||||
*/
|
||||
private final Handler handler = new Handler();
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/** A flag to indicate whether the submit button can be pressed. */
|
||||
private final MutableLiveData<Boolean> valid = new MutableLiveData<>(Boolean.FALSE);
|
||||
@@ -63,6 +57,12 @@ public class ForecastWidgetViewModel extends AbstractNetworkViewModel {
|
||||
/** A boolean to indicate the temperature scale. */
|
||||
private final MutableLiveData<Boolean> celsius = new MutableLiveData<>(Boolean.TRUE);
|
||||
|
||||
/** The color for the widget. */
|
||||
private final MutableLiveData<Integer> color = new MutableLiveData<>(Color.rgb(255, 255, 255));
|
||||
|
||||
/** A boolean to indicate that the dialog should be opened. */
|
||||
private final MutableLiveData<Boolean> dialog = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
/** The favorites of the user that are displayed, if there is no search term. */
|
||||
private final MutableLiveData<List<City>> favorites = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
@@ -157,6 +157,14 @@ public class ForecastWidgetViewModel extends AbstractNetworkViewModel {
|
||||
return selection;
|
||||
}
|
||||
|
||||
public MutableLiveData<Integer> getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public MutableLiveData<Boolean> getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void setCelsius(boolean value) {
|
||||
this.celsius.setValue(value);
|
||||
}
|
||||
@@ -168,6 +176,10 @@ public class ForecastWidgetViewModel extends AbstractNetworkViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
public void onColor() {
|
||||
dialog.setValue(Boolean.TRUE);
|
||||
}
|
||||
|
||||
private static CityPage emptyPage() {
|
||||
CityPage result = new CityPage();
|
||||
result.setElements(Collections.emptyList());
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.BindingAdapter;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.feign.model.LocationHierarchy;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The view model for a location view.
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.mowesta.android.app.repository.UserRepository;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.app.task.RefreshTask;
|
||||
import com.mowesta.android.app.task.SyncTask;
|
||||
import com.mowesta.android.feign.ApiClient;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.Device;
|
||||
import com.mowesta.android.feign.model.DeviceHandle;
|
||||
@@ -36,7 +35,7 @@ public class LoginViewModel extends AndroidViewModel {
|
||||
/**
|
||||
* Constants to model different destinations to go to.
|
||||
*/
|
||||
public enum Destination { DEVICES, COLLECTION};
|
||||
public enum Destination { DEVICES, DRAWER};
|
||||
|
||||
|
||||
/**
|
||||
@@ -124,7 +123,7 @@ public class LoginViewModel extends AndroidViewModel {
|
||||
getUserRepository().setCredentials(input);
|
||||
syncFavorites();
|
||||
}
|
||||
destination.setValue(Destination.COLLECTION);
|
||||
destination.setValue(Destination.DRAWER);
|
||||
}, (input, status) -> {
|
||||
checking.setValue(false);
|
||||
if (status == 403) {
|
||||
|
||||
+34
-7
@@ -1,20 +1,15 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.PagedList;
|
||||
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.Device;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The view model to fingure a measure widget.
|
||||
* The view model to configure a measure widget.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@@ -39,6 +34,12 @@ public class MeasureWidgetViewModel extends DevicesViewModel {
|
||||
/** A boolean to indicate the temperature scale. */
|
||||
private final MutableLiveData<Boolean> si = new MutableLiveData<>(Boolean.TRUE);
|
||||
|
||||
/** The color for the widget. */
|
||||
private final MutableLiveData<Integer> color = new MutableLiveData<>(Color.rgb(255, 255, 255));
|
||||
|
||||
/** A boolean to indicate that the dialog should be opened. */
|
||||
private final MutableLiveData<Boolean> dialog = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
/**
|
||||
* Creates the view model.
|
||||
*
|
||||
@@ -125,4 +126,30 @@ public class MeasureWidgetViewModel extends DevicesViewModel {
|
||||
* @return The live data.
|
||||
*/
|
||||
public MutableLiveData<Boolean> getLogin() { return login; }
|
||||
|
||||
/**
|
||||
* Returns the current color.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
public MutableLiveData<Integer> getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean to signal that the color picker shall be opened.
|
||||
*
|
||||
* @return The dialog state.
|
||||
*/
|
||||
public MutableLiveData<Boolean> getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the color button is pressed.
|
||||
*/
|
||||
public void onColor() {
|
||||
dialog.setValue(Boolean.TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The view model to display a single measurement
|
||||
* in a bottom sheet dialog.
|
||||
* The view model to display a single measurement in a bottom sheet dialog.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -9,16 +8,8 @@ import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.mowesta.android.feign.model.Measurement;
|
||||
import com.mowesta.android.feign.model.WeatherReport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The view model to display a single weather report
|
||||
* in a bottom sheet dialog.
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
@@ -356,16 +355,22 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
|
||||
private Double parseValue(String value) {
|
||||
if (value == null) return null;
|
||||
value = value.trim();
|
||||
LocaleListCompat c = ConfigurationCompat.getLocales(getApplication().getResources().getConfiguration());
|
||||
for (int i = 0; i < c.size(); i++) {
|
||||
Locale l = c.get(i);
|
||||
NumberFormat f = NumberFormat.getNumberInstance(l);
|
||||
try {
|
||||
return ((Number)f.parseObject(value.trim())).doubleValue();
|
||||
return ((Number)f.parseObject(value)).doubleValue();
|
||||
} catch (ParseException e) {
|
||||
Log.d(TAG, "Failed to parse double from: " + value);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(value.replace(',', '.'));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.d(TAG, "Failed to parse double, giving up: " + value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.DataSource;
|
||||
@@ -13,17 +12,13 @@ import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.paging.PositionalDataSource;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.app.task.TaskStatus;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.CityPage;
|
||||
import com.mowesta.android.feign.model.Country;
|
||||
import com.mowesta.android.feign.model.LocationReference;
|
||||
import com.mowesta.android.feign.model.State;
|
||||
|
||||
@@ -60,7 +55,7 @@ public class StateViewModel extends AbstractPlaceViewModel {
|
||||
/**
|
||||
* A handler to run on main.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* The loader for the state.
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -61,7 +62,7 @@ public class StationViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* The handler to run on main.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates a new view model.
|
||||
@@ -200,7 +201,7 @@ public class StationViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<DiagramEntry<WeatherReport>> callback) {
|
||||
ApiTask<Long, WeatherReportPage> task = new ApiTask<>((id, client) -> { return client.getStationReports(id, 0l, now, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
ApiTask<Long, WeatherReportPage> task = new ApiTask<>((id, client) -> { return client.getStationReports(id, 0L, now, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()), params.requestedStartPosition, page.getTotal())); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (id != null && isCurrentRequest(requestCode)) {
|
||||
|
||||
@@ -1,33 +1,17 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.DataSource;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PagedList;
|
||||
import androidx.paging.PagedListAdapter;
|
||||
import androidx.paging.PositionalDataSource;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.ViewStationEntryBinding;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.CityPage;
|
||||
import com.mowesta.android.feign.model.WeatherStation;
|
||||
import com.mowesta.android.feign.model.WeatherStationPage;
|
||||
|
||||
@@ -64,7 +48,7 @@ public class StationsViewModel extends AbstractNetworkViewModel {
|
||||
/**
|
||||
* The handler to debounce the updates to the search term.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
private Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates the view model.
|
||||
@@ -166,7 +150,7 @@ public class StationsViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<WeatherStation> callback) {
|
||||
ApiTask<Void, WeatherStationPage> task = new ApiTask<>((v, client) -> { return client.getStations(term,0, params.requestedLoadSize ); },
|
||||
ApiTask<Void, WeatherStationPage> task = new ApiTask<>((v, client) -> { return client.getStations(term, 0, params.requestedLoadSize); },
|
||||
(v, page) -> { completeRequest(requestCode, () -> callback.onResult(page.getElements(), 0, page.getTotal())); },
|
||||
(v, status) -> { finishRequest(requestCode, true); });
|
||||
if (isCurrentRequest(requestCode)) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.mowesta.android.app.model;
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Application;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
@@ -16,9 +11,6 @@ import androidx.lifecycle.MutableLiveData;
|
||||
import com.mowesta.android.app.task.ImageTask;
|
||||
import com.mowesta.android.feign.model.WeatherVideo;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* The view model for weather videos.
|
||||
*
|
||||
|
||||
@@ -117,7 +117,7 @@ public class ClientFactory {
|
||||
String p = credentials.getPassword();
|
||||
String user = l == null ? "" : l;
|
||||
String pass = p == null ? "" : p;
|
||||
return "Basic " + new String(Base64.encode((user + ":" + pass).getBytes(ISO_8859_1), 0), ASCII);
|
||||
return "Basic " + new String(Base64.encode((user + ":" + pass).getBytes(ISO_8859_1), Base64.NO_WRAP), ASCII);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -196,7 +196,7 @@ public class DeviceRepository extends Repository {
|
||||
d.setId(handle.getId());
|
||||
d.setDevice(handle.getDevice());
|
||||
d.setCreationTime(handle.getCreationTime());
|
||||
d.setDeleted(handle.isDeleted());
|
||||
d.setDeleted(handle.getDeleted());
|
||||
d.setManufacturer(handle.getManufacturer());
|
||||
d.setModificationTime(handle.getModificationTime());
|
||||
d.setModel(handle.getModel());
|
||||
|
||||
@@ -8,7 +8,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.security.crypto.EncryptedFile;
|
||||
import androidx.security.crypto.MasterKey;
|
||||
import androidx.security.crypto.MasterKeys;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -281,9 +281,8 @@ public class FileStoreObserver<T> implements Observer<T> {
|
||||
* be setup.
|
||||
*/
|
||||
@NonNull EncryptedFile getEncryptedFile() throws IOException, GeneralSecurityException {
|
||||
MasterKey.Builder b = new MasterKey.Builder(context);
|
||||
b.setKeyScheme(MasterKey.KeyScheme.AES256_GCM);
|
||||
return new EncryptedFile.Builder(context, getFile(), b.build(),
|
||||
String keySpec = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
|
||||
return new EncryptedFile.Builder(getFile(), context, keySpec,
|
||||
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class WidgetRepository extends Repository {
|
||||
*/
|
||||
public WidgetRepository(IApp application) {
|
||||
super(application);
|
||||
database = Room.databaseBuilder(application.getContext(), WidgetDatabase .class, "widgets").fallbackToDestructiveMigration().build();
|
||||
database = Room.databaseBuilder(application.getContext(), WidgetDatabase .class, "widgets").addMigrations(WidgetDatabase.getMigrations()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.mowesta.android.app.task;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
/**
|
||||
* The base class for tasks. This is a drop in replacement for Android's async task,
|
||||
* which is now deprecated.
|
||||
*
|
||||
* @param <Result>
|
||||
*/
|
||||
public abstract class AbstractTask<Result> {
|
||||
|
||||
/**
|
||||
* The log tag of the task.
|
||||
*/
|
||||
private static final String TAG = "Task";
|
||||
|
||||
/**
|
||||
* The executor to execute a couple of tasks in parallel. We limit this to
|
||||
* 4 threads to avoid excessive sever loads.
|
||||
*/
|
||||
public static ExecutorService POOL_EXECUTOR = Executors.newFixedThreadPool(4);
|
||||
|
||||
/**
|
||||
* The executor used to run tasks sequentially. This is used to ensure that
|
||||
* tasks requiring a specific order will respect the scheduling order.
|
||||
*/
|
||||
public static ExecutorService SERIAL_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
|
||||
private static int counter = 0;
|
||||
|
||||
/**
|
||||
* A flag to indicate whether the execution will take place on the pooled
|
||||
* or on a serial executor.
|
||||
*/
|
||||
private final boolean pooled;
|
||||
|
||||
/**
|
||||
* The flag to determine whether the task is canceled.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* A flag to prevent the duplicate task execution.
|
||||
*/
|
||||
private boolean executed;
|
||||
|
||||
/**
|
||||
* The handler to perform execution
|
||||
*/
|
||||
protected final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates a new task executed on a serial executor.
|
||||
*/
|
||||
public AbstractTask() {
|
||||
this.pooled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new task that is running on a serial executor (false
|
||||
* or thred pool executor (true).
|
||||
*
|
||||
* @param pooled True to run the task on a thread pool, false to
|
||||
* run it on a serial executor.
|
||||
*/
|
||||
public AbstractTask(boolean pooled) {
|
||||
this.pooled = pooled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the execution will take place on a pool (true)
|
||||
* or on a serial executor (false).
|
||||
*
|
||||
* @return True for pooled execution, false for serial execution.
|
||||
*/
|
||||
public boolean isPooled() {
|
||||
return pooled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the task on the executor.
|
||||
*/
|
||||
public void execute() {
|
||||
int c;
|
||||
synchronized (this) {
|
||||
counter += 1;
|
||||
c = counter;
|
||||
if (executed) throw new RuntimeException("Cannot execute task twice.");
|
||||
executed = true;
|
||||
}
|
||||
ExecutorService target = pooled?POOL_EXECUTOR:SERIAL_EXECUTOR;
|
||||
try {
|
||||
Log.v(TAG, "Schedule " + c + " (" + pooled + ")");
|
||||
target.execute(() -> {
|
||||
try {
|
||||
Log.v(TAG, "Running " + c);
|
||||
Result r = doInBackground();
|
||||
handler.post(() -> {
|
||||
try {
|
||||
onPostExecute(r);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Unexpected exception while executing post execute.", e);
|
||||
}
|
||||
});
|
||||
Log.v(TAG, "Completed " + c);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Unexpected exception while executing in background.", e);
|
||||
}
|
||||
});
|
||||
} catch (RejectedExecutionException e) {
|
||||
Log.d(TAG, "Scheduling of task failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canceled flag on the task, if not set already and
|
||||
* notifies the monitor associated with this object.
|
||||
*/
|
||||
public void cancel() {
|
||||
synchronized (this) {
|
||||
cancelled = true;
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the task is canceled.
|
||||
*
|
||||
* @return True to cancel.
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
synchronized (this) {
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method that will be called on a background thread.
|
||||
*
|
||||
* @return The result value.
|
||||
*/
|
||||
protected abstract Result doInBackground();
|
||||
|
||||
/**
|
||||
* The method that wil be called.
|
||||
*
|
||||
* @param result The result.
|
||||
*/
|
||||
protected void onPostExecute(Result result) { }
|
||||
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.mowesta.android.app.task;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
|
||||
import feign.FeignException;
|
||||
@@ -45,7 +43,7 @@ public class ApiTask<I, O> {
|
||||
/**
|
||||
* Called when the call fails.
|
||||
*
|
||||
* @parma input The input of the call.
|
||||
* @param input The input of the call.
|
||||
* @param status The error code of the call.
|
||||
*/
|
||||
void onError(I input, int status);
|
||||
@@ -105,18 +103,15 @@ public class ApiTask<I, O> {
|
||||
*
|
||||
* @param input The input.
|
||||
* @param client the api client.
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public ApiTask<Favorite, Boolean> execute(final I input, final DefaultApi client) {
|
||||
new AsyncTask<I, Void, O>() {
|
||||
public void execute(final I input, final DefaultApi client) {
|
||||
new AbstractTask<O>(true) {
|
||||
private Exception e;
|
||||
@Override
|
||||
@SafeVarargs
|
||||
protected final O doInBackground( I... is) {
|
||||
protected final O doInBackground() {
|
||||
try {
|
||||
return call.exeucte(is[0], client);
|
||||
return call.exeucte(input, client);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Exception while executing api task.", e);
|
||||
this.e = e;
|
||||
@@ -137,8 +132,7 @@ public class ApiTask<I, O> {
|
||||
successListener.onSuccess(input, o);
|
||||
}
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, input);
|
||||
return null;
|
||||
}.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mowesta.android.app.task;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
@@ -82,14 +81,12 @@ public class DatabaseTask<D extends RoomDatabase, I, O> {
|
||||
* @param database The database.
|
||||
* @param input The input.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void execute(final I input, final D database) {
|
||||
new AsyncTask<I, Void, O>() {
|
||||
new AbstractTask<O>(false) {
|
||||
@Override
|
||||
@SafeVarargs
|
||||
protected final O doInBackground(I... is) {
|
||||
return call.exeucte(is[0], database);
|
||||
protected final O doInBackground() {
|
||||
return call.exeucte(input, database);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +94,7 @@ public class DatabaseTask<D extends RoomDatabase, I, O> {
|
||||
super.onPostExecute(o);
|
||||
resultListener.onResult(input, o);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, input);
|
||||
}.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.mowesta.android.app.task;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -54,12 +53,11 @@ public class ImageTask {
|
||||
*
|
||||
* @param url The url to download.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void execute(final @NonNull String url) {
|
||||
AsyncTask task = new AsyncTask<Void, Void, Bitmap>() {
|
||||
new AbstractTask<Bitmap>(true) {
|
||||
@Override
|
||||
protected Bitmap doInBackground(@SuppressLint("StaticFieldLeak") Void... voids) {
|
||||
protected Bitmap doInBackground() {
|
||||
try {
|
||||
InputStream in = new URL(url).openStream();
|
||||
return BitmapFactory.decodeStream(in);
|
||||
@@ -73,8 +71,7 @@ public class ImageTask {
|
||||
protected void onPostExecute(Bitmap bitmap) {
|
||||
listener.onResult(url, bitmap);
|
||||
}
|
||||
};
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[])new Void[0]);
|
||||
}.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mowesta.android.app.task;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
@@ -9,7 +8,6 @@ import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.CityPage;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -102,9 +100,9 @@ public class RefreshTask {
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void execute(DefaultApi client) {
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
new AbstractTask<Boolean>(true) {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
protected Boolean doInBackground() {
|
||||
List<Favorite> favorites = database.getAccessor().getAll();
|
||||
final List<Favorite> modified = new ArrayList<>();
|
||||
final List<Favorite> unmodified = new ArrayList<>();
|
||||
@@ -124,7 +122,8 @@ public class RefreshTask {
|
||||
result[0] = false;
|
||||
modified.notifyAll();
|
||||
}
|
||||
}).execute(f, client);
|
||||
});
|
||||
loadTask.execute(f, client);
|
||||
}
|
||||
synchronized (modified) {
|
||||
try {
|
||||
@@ -144,7 +143,7 @@ public class RefreshTask {
|
||||
super.onPostExecute(aBoolean);
|
||||
if (completionListener != null) completionListener.onCompletion(aBoolean);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mowesta.android.app.task;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
@@ -9,12 +8,10 @@ import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.LocationReference;
|
||||
import com.mowesta.android.feign.model.Settings;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A task that will synchronize the entries in the local favorite
|
||||
@@ -76,9 +73,9 @@ public class SyncTask {
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void execute(DefaultApi client) {
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
new AbstractTask<Boolean>(false) {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
protected Boolean doInBackground() {
|
||||
List<Favorite> favorites = database.getAccessor().getAll();
|
||||
try {
|
||||
List<Favorite> favs = new ArrayList<>(favorites);
|
||||
@@ -168,7 +165,7 @@ public class SyncTask {
|
||||
if (completionListener != null) completionListener.onCompletion(result);
|
||||
}
|
||||
|
||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
}.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ColoredSnackbar {
|
||||
*/
|
||||
public static Snackbar make(View view, CharSequence text, int duration) {
|
||||
Snackbar snackbar = Snackbar.make(view, text, duration);
|
||||
snackbar.getView().setBackgroundColor(getAttribute(view.getContext(), R.attr.colorAccent));
|
||||
snackbar.getView().setBackgroundColor(getAttribute(view.getContext(), androidx.appcompat.R.attr.colorAccent));
|
||||
List<View> views = new ArrayList<>();
|
||||
views.add(snackbar.getView());
|
||||
while (! views.isEmpty()) {
|
||||
|
||||
@@ -96,4 +96,18 @@ public class PermissionUtil {
|
||||
return new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION };
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the app has the post notification permission.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if the app may post notifications.
|
||||
*/
|
||||
public static boolean hasNotificationPermission(@NonNull Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
return hasPermissions(context, new String[] { Manifest.permission.POST_NOTIFICATIONS });
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
@@ -17,7 +13,7 @@ import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* A utiltiy class to comptue times when aggregating weather
|
||||
* A utility class to computes times when aggregating weather
|
||||
* conditions into weather summaries.
|
||||
*
|
||||
* @author Marcus
|
||||
@@ -44,15 +40,15 @@ public class TimeUtils {
|
||||
* @param tz The time zone.
|
||||
*/
|
||||
public TimeUtils(long now, String tz) {
|
||||
if (tz != null) {
|
||||
c.setTimeZone(TimeZone.getTimeZone(tz));
|
||||
}
|
||||
c.setTimeInMillis(now);
|
||||
update(today);
|
||||
c.add(Calendar.DAY_OF_MONTH, -1);
|
||||
update(yesterday);
|
||||
c.add(Calendar.DAY_OF_MONTH, 2);
|
||||
update(tomorrow);
|
||||
if (tz != null) {
|
||||
c.setTimeZone(TimeZone.getTimeZone(tz));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+45
-4
@@ -2,12 +2,15 @@ package com.mowesta.android.app.widget;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
import com.mowesta.android.app.database.WidgetAccessor;
|
||||
import com.mowesta.android.app.database.WidgetDatabase;
|
||||
@@ -60,7 +63,7 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||
Log.d(TAG, "Updating widget data for " + Arrays.toString(appWidgetIds));
|
||||
for (int i = 0; i < appWidgetIds.length; i++) {
|
||||
triggerUpdate(context, appWidgetIds[i]);
|
||||
triggerUpdate(context, appWidgetIds[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +71,7 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
|
||||
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
|
||||
Log.d(TAG, "Updating widget data for " + appWidgetId + " due to change.");
|
||||
triggerUpdate(context, appWidgetId);
|
||||
triggerUpdate(context, appWidgetId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,22 +131,40 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
* Triggers the widget service to perform an update.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param schedule Determines whether we also perform a background update.
|
||||
* @param id The id.
|
||||
*/
|
||||
public void triggerUpdate(Context context, int id) {
|
||||
WidgetService.scheduleUpdate(context, type, id);
|
||||
public void triggerUpdate(Context context, int id, boolean schedule) {
|
||||
if (schedule) OnetimeWidgetWorker.updateWidget(context, type, id);
|
||||
Log.d(TAG, "Start database query for widget " + id + ".");
|
||||
DatabaseTask<WidgetDatabase, Integer, Widget> task = new DatabaseTask<WidgetDatabase, Integer, Widget>((input, database)-> {
|
||||
List<Widget> widgets = database.getAccessor().get(type, input);
|
||||
if (widgets.isEmpty()) return null;
|
||||
else return widgets.get(0);
|
||||
}, (input, widget)-> {
|
||||
if (widget != null) {
|
||||
Log.d(TAG, "Finish database query for widget " + input + ".");
|
||||
updateWidget(context, widget);
|
||||
} else {
|
||||
loadWidget(context, id);
|
||||
}
|
||||
});
|
||||
task.execute(id, getWidgetDatabase(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a remote view that shows that the widget is loading.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param id The id.
|
||||
*/
|
||||
public void loadWidget(Context context, int id) {
|
||||
Log.d(TAG, "Building loading view for widget " + id + ".");
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_loading);
|
||||
appWidgetManager.updateAppWidget(id, views);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the widget dimensions for the app widget. If the options
|
||||
* cannot be retrieved, the width and height will be 0.
|
||||
@@ -153,6 +174,7 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
* @return An int array containing the width and height.
|
||||
*/
|
||||
protected int[] getWidgetDimensions(Context context, int id) {
|
||||
Log.d(TAG, "Requesting app widget manager options.");
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(context);
|
||||
Bundle options = manager.getAppWidgetOptions(id);
|
||||
if (options == null) return new int[] { 0, 0 };
|
||||
@@ -160,6 +182,10 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
int maxWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, 0);
|
||||
int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0);
|
||||
int maxHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, 0);
|
||||
Log.d(TAG, String.format("Widget %d: Width(%d-%d) Height(%d-%d)", id, minWidth, maxWidth, minHeight, maxHeight));
|
||||
if (maxWidth == 0 && maxHeight == 0) {
|
||||
return new int[] { 100, 100 };
|
||||
}
|
||||
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return new int[] { minWidth, maxHeight };
|
||||
} else {
|
||||
@@ -178,5 +204,20 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
public abstract void updateWidget(Context context, Widget widget);
|
||||
|
||||
|
||||
/**
|
||||
* Updates all widgets of the provider.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param schedule True to also schedule a background update.
|
||||
* @return True if any update has been scheduled.
|
||||
*/
|
||||
public boolean triggerUpdates(Context context, boolean schedule) {
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(context);
|
||||
int[] ids = manager.getAppWidgetIds(new ComponentName(context, getClass()));
|
||||
for (int id: ids) {
|
||||
triggerUpdate(context, id, schedule);
|
||||
}
|
||||
return ids.length > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mowesta.android.app.widget;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -41,4 +42,9 @@ public class ForecastWidgetActivity extends AppCompatActivity {
|
||||
setResult(RESULT_CANCELED, resultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.d("ForecastWidgetActivity", "onStop");
|
||||
}
|
||||
}
|
||||
|
||||
+21
-5
@@ -6,7 +6,9 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
@@ -74,6 +76,7 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
|
||||
@Override
|
||||
public void updateWidget(Context context, Widget widget) {
|
||||
Log.d(TAG, "Performing forecast widget update "+ widget.getReference() + ".");
|
||||
City city = widget.getData(City.class);
|
||||
if (city == null) {
|
||||
Log.d(TAG, "Ignoring update without for widget " + widget.getReference() + " without city.");
|
||||
@@ -92,8 +95,13 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
}
|
||||
days = a.getDays();
|
||||
}
|
||||
Log.d(TAG, "Building remote views.");
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_forecast);
|
||||
// set color
|
||||
views.setTextColor(R.id.widget_location_name, widget.getColor());
|
||||
views.setTextColor(R.id.widget_condition_text, widget.getColor());
|
||||
views.setTextColor(R.id.widget_condition_temperature, widget.getColor());
|
||||
// set city name
|
||||
views.setTextViewText(R.id.widget_location_name, BindingTransforms.getName(context, city.getNames(), false));
|
||||
// set icon
|
||||
@@ -102,7 +110,7 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
Integer icon = BindingTransforms.getIcon(weatherType, false);
|
||||
if (icon != null) {
|
||||
views.setImageViewResource(R.id.widget_condition_icon, icon);
|
||||
views.setInt(R.id.widget_condition_icon, "setColorFilter", Color.argb(255, 255, 255, 255));
|
||||
views.setInt(R.id.widget_condition_icon, "setColorFilter", widget.getColor());
|
||||
views.setImageViewResource(R.id.widget_condition_background, icon);
|
||||
views.setInt(R.id.widget_condition_background, "setColorFilter", Color.argb(255, 0, 0, 0));
|
||||
}
|
||||
@@ -113,7 +121,10 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
views.setTextViewText(R.id.widget_condition_temperature, UnitUtils.toSpanned(UnitUtils.getTemperature(context, condition.getTemperature(), unit)));
|
||||
}
|
||||
}
|
||||
float scale = context.getResources().getDisplayMetrics().scaledDensity / context.getResources().getDisplayMetrics().density;
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
float scaledDensity = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm);
|
||||
float scale = scaledDensity / dm.density;
|
||||
Log.d(TAG, "Building remote views done.");
|
||||
int[] widgetDimension = getWidgetDimensions(context, widget.getReference());
|
||||
int width = widgetDimension[0];
|
||||
int height = widgetDimension[1];
|
||||
@@ -124,7 +135,7 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
if (height > (BREAK_VERTICAL * scale) && count > 0) {
|
||||
views.addView(R.id.widget_container_days, new RemoteViews(context.getPackageName(), R.layout.widget_forecast_spacer));
|
||||
for (int i = 0; i < count; i++) {
|
||||
RemoteViews day = createDayView(context, days.get(i), unit);
|
||||
RemoteViews day = createDayView(context, days.get(i), unit, widget.getColor());
|
||||
views.addView(R.id.widget_container_days, day);
|
||||
views.addView(R.id.widget_container_days, new RemoteViews(context.getPackageName(), R.layout.widget_forecast_spacer));
|
||||
}
|
||||
@@ -150,16 +161,21 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
* @param context The context.
|
||||
* @param model The model.
|
||||
* @param unit The temperature unit.
|
||||
* @param color The color.
|
||||
* @return The view.
|
||||
*/
|
||||
private RemoteViews createDayView(Context context, SummaryViewModel model, MowestaSettings.TemperatureUnit unit) {
|
||||
private RemoteViews createDayView(Context context, SummaryViewModel model, MowestaSettings.TemperatureUnit unit, int color) {
|
||||
RemoteViews day = new RemoteViews(context.getPackageName(), R.layout.widget_forecast_day);
|
||||
// set color
|
||||
day.setTextColor(R.id.widget_day_text, color);
|
||||
day.setTextColor(R.id.widget_day_temperature, color);
|
||||
// set content
|
||||
day.setTextViewText(R.id.widget_day_text, model.getTitle().getValue());
|
||||
WeatherCondition.TypeEnum weatherType = model.getMax().getValue().getType();
|
||||
Integer icon = BindingTransforms.getIcon(weatherType, false);
|
||||
if (icon != null) {
|
||||
day.setImageViewResource(R.id.widget_day_icon, icon);
|
||||
day.setInt(R.id.widget_day_icon, "setColorFilter", Color.argb(255, 255, 255, 255));
|
||||
day.setInt(R.id.widget_day_icon, "setColorFilter", color);
|
||||
day.setImageViewResource(R.id.widget_day_background, icon);
|
||||
day.setInt(R.id.widget_day_background, "setColorFilter", Color.argb(255, 0, 0, 0));
|
||||
}
|
||||
|
||||
+24
-13
@@ -5,9 +5,12 @@ import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spanned;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.navigation.NavDeepLinkBuilder;
|
||||
@@ -59,6 +62,7 @@ public class MeasureWidgetProvider extends AbstractWidgetProvider {
|
||||
|
||||
@Override
|
||||
public void updateWidget(Context context, Widget widget) {
|
||||
Log.d(TAG, "Performing measure widget update "+ widget.getReference() + ".");
|
||||
Device device = widget.getData(Device.class);
|
||||
if (device == null) {
|
||||
Log.d(TAG, "Ignoring update without for widget " + widget.getReference() + " without device.");
|
||||
@@ -67,12 +71,18 @@ public class MeasureWidgetProvider extends AbstractWidgetProvider {
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
MowestaSettings.TemperatureUnit unit = widget.isCelsius()?MowestaSettings.TemperatureUnit.CELSIUS:MowestaSettings.TemperatureUnit.FAHRENHEIT;
|
||||
MowestaSettings.UnitSystem system = widget.isSi()?MowestaSettings.UnitSystem.STANDARD:MowestaSettings.UnitSystem.IMPERIAL;
|
||||
float scale = context.getResources().getDisplayMetrics().scaledDensity / context.getResources().getDisplayMetrics().density;
|
||||
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
float scaledDensity = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm);
|
||||
float scale = scaledDensity / dm.density;
|
||||
|
||||
int[] widgetDimension = getWidgetDimensions(context, widget.getReference());
|
||||
int width = widgetDimension[0];
|
||||
int height = widgetDimension[1];
|
||||
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_measure);
|
||||
views.setTextColor(R.id.widget_device_name, widget.getColor());
|
||||
views.setTextColor(R.id.widget_device_model, widget.getColor());
|
||||
// set device
|
||||
views.setTextViewText(R.id.widget_device_name, device.getDevice());
|
||||
views.setTextViewText(R.id.widget_device_model, device.getModel());
|
||||
@@ -81,7 +91,7 @@ public class MeasureWidgetProvider extends AbstractWidgetProvider {
|
||||
int label = BindingTransforms.getOsLabel(device.getOs());
|
||||
if (icon != 0 && label != 0) {
|
||||
views.setImageViewResource(R.id.widget_device_icon, icon);
|
||||
views.setInt(R.id.widget_device_icon, "setColorFilter", Color.argb(255, 255, 255, 255));
|
||||
views.setInt(R.id.widget_device_icon, "setColorFilter", widget.getColor());
|
||||
views.setImageViewResource(R.id.widget_device_background, icon);
|
||||
views.setInt(R.id.widget_device_background, "setColorFilter", Color.argb(255, 0, 0, 0));
|
||||
views.setContentDescription(R.id.widget_device_icon, context.getResources().getString(label));
|
||||
@@ -90,28 +100,28 @@ public class MeasureWidgetProvider extends AbstractWidgetProvider {
|
||||
Measurement measurement = widget.getContent(Measurement.class);
|
||||
if (measurement != null) {
|
||||
List<RemoteViews> items = new ArrayList<>();
|
||||
Date dateTime = new Date(measurement.getTime());
|
||||
String date = android.text.format.DateFormat.getDateFormat(context).format(dateTime);
|
||||
createItemView(items, context, R.drawable.ic_calendar_today_normal_24, R.string.widget_measure_date, UnitUtils.toSpanned(date));
|
||||
String time = android.text.format.DateFormat.getTimeFormat(context).format(dateTime);
|
||||
createItemView(items, context, R.drawable.ic_alarm_normal_24, R.string.widget_measure_time , UnitUtils.toSpanned(time));
|
||||
if (measurement.getTemperature() != null) {
|
||||
createItemView(items, context, R.drawable.ic_thermometer_normal_24, R.string.label_temperature, UnitUtils.toSpanned(UnitUtils.getTemperature(context, measurement.getTemperature(), unit)));
|
||||
createItemView(items, context, R.drawable.ic_thermometer_normal_24, R.string.label_temperature, UnitUtils.toSpanned(UnitUtils.getTemperature(context, measurement.getTemperature(), unit)), widget.getColor());
|
||||
}
|
||||
if (measurement.getPressure() != null) {
|
||||
createItemView(items, context, R.drawable.ic_barometer_normal_24, R.string.label_pressure, UnitUtils.toSpanned(UnitUtils.getPressure(context, measurement.getPressure(), system)));
|
||||
createItemView(items, context, R.drawable.ic_barometer_normal_24, R.string.label_pressure, UnitUtils.toSpanned(UnitUtils.getPressure(context, measurement.getPressure(), system)), widget.getColor());
|
||||
}
|
||||
if (measurement.getHumidity() != null) {
|
||||
createItemView(items, context, R.drawable.ic_humidity_normal_24, R.string.label_humidity, UnitUtils.toSpanned(context.getResources().getString(R.string.format_humidity, measurement.getHumidity())));
|
||||
createItemView(items, context, R.drawable.ic_humidity_normal_24, R.string.label_humidity, UnitUtils.toSpanned(context.getResources().getString(R.string.format_humidity, measurement.getHumidity())), widget.getColor());
|
||||
}
|
||||
if (device.getOs() != Device.OsEnum.IOS && device.getOs() != Device.OsEnum.ANDROID) {
|
||||
if (measurement.getData().containsKey(MeasurementType.BATTERY_VOLTAGE.name())) {
|
||||
Object[] values = MeasurementType.BATTERY_VOLTAGE.getValues(measurement.getData().get(MeasurementType.BATTERY_VOLTAGE.name()));
|
||||
if (values.length > 0 && values[0] instanceof Double) {
|
||||
createItemView(items, context, R.drawable.ic_outline_battery_unknown_normal_24, R.string.measurement_type_battery_voltage, UnitUtils.toSpanned(context.getResources().getString(R.string.format_voltage, (Double)values[0])));
|
||||
createItemView(items, context, R.drawable.ic_outline_battery_unknown_normal_24, R.string.measurement_type_battery_voltage, UnitUtils.toSpanned(context.getResources().getString(R.string.format_voltage, (Double)values[0])), widget.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
Date dateTime = new Date(measurement.getTime());
|
||||
String date = android.text.format.DateFormat.getDateFormat(context).format(dateTime);
|
||||
createItemView(items, context, R.drawable.ic_calendar_today_normal_24, R.string.widget_measure_date, UnitUtils.toSpanned(date), widget.getColor());
|
||||
String time = android.text.format.DateFormat.getTimeFormat(context).format(dateTime);
|
||||
createItemView(items, context, R.drawable.ic_alarm_normal_24, R.string.widget_measure_time , UnitUtils.toSpanned(time), widget.getColor());
|
||||
int max = Math.min(items.size(), (int)((height - (HEIGHT_DEVICE * scale)) / (HEIGHT_ITEM * scale)));
|
||||
for (int i = 0; i < max; i++) {
|
||||
views.addView(R.id.widget_container_item, items.get(i));
|
||||
@@ -132,15 +142,16 @@ public class MeasureWidgetProvider extends AbstractWidgetProvider {
|
||||
appWidgetManager.updateAppWidget(widget.getReference(), views);
|
||||
}
|
||||
|
||||
public void createItemView(List<RemoteViews> result, Context context, int icon, int description, Spanned value) {
|
||||
public void createItemView(List<RemoteViews> result, Context context, int icon, int description, Spanned value, int color) {
|
||||
if (value != null) {
|
||||
RemoteViews item = new RemoteViews(context.getPackageName(), R.layout.widget_measure_item);
|
||||
item.setImageViewResource(R.id.widget_item_icon, icon);
|
||||
item.setInt(R.id.widget_item_icon, "setColorFilter", Color.argb(255, 255, 255, 255));
|
||||
item.setInt(R.id.widget_item_icon, "setColorFilter", color);
|
||||
item.setImageViewResource(R.id.widget_item_background, icon);
|
||||
item.setInt(R.id.widget_item_background, "setColorFilter", Color.argb(255, 0, 0, 0));
|
||||
item.setContentDescription(R.id.widget_item_icon, context.getResources().getString(description));
|
||||
item.setTextViewText(R.id.widget_item_text, value);
|
||||
item.setTextColor(R.id.widget_item_text, color);
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package com.mowesta.android.app.widget;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.work.Data;
|
||||
import androidx.work.OneTimeWorkRequest;
|
||||
import androidx.work.OutOfQuotaPolicy;
|
||||
import androidx.work.WorkManager;
|
||||
import androidx.work.Worker;
|
||||
import androidx.work.WorkerParameters;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
import com.mowesta.android.app.database.WidgetAccessor;
|
||||
import com.mowesta.android.app.database.WidgetDatabase;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.Device;
|
||||
import com.mowesta.android.feign.model.Measurement;
|
||||
import com.mowesta.android.feign.model.MeasurementPage;
|
||||
import com.mowesta.android.feign.model.WeatherForecast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A worker that updates a widget. The widget reference
|
||||
* is passed as a parameter to the job.
|
||||
*/
|
||||
public class OnetimeWidgetWorker extends Worker {
|
||||
|
||||
/**
|
||||
* The worker to update the widget.
|
||||
*/
|
||||
public static final String TAG = "OnetimeWidgetWorker";
|
||||
|
||||
/**
|
||||
* The extra containing the reference.
|
||||
*/
|
||||
public static final String EXTRA_WIDGET_REFERENCE = "reference";
|
||||
|
||||
|
||||
/**
|
||||
* The extra containing the widget type.
|
||||
*/
|
||||
public static final String EXTRA_WIDGET_TYPE = "type";
|
||||
|
||||
/**
|
||||
* The delay to update the data.
|
||||
*/
|
||||
private static final int DELAY_DATA = 24 * 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* The delay to update the content.
|
||||
*/
|
||||
private static final int DELAY_CONTENT = 30 * 60 * 1000;
|
||||
|
||||
/** The widget type. */
|
||||
private int type;
|
||||
/** The widget reference. */
|
||||
private int reference;
|
||||
/** The handler. */
|
||||
private Handler handler;
|
||||
/** The app. */
|
||||
private IApp app;
|
||||
|
||||
public OnetimeWidgetWorker(
|
||||
@NonNull Context context,
|
||||
@NonNull WorkerParameters params) {
|
||||
super(context, params);
|
||||
app = (IApp)context.getApplicationContext();
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
type = params.getInputData().getInt(EXTRA_WIDGET_TYPE, Widget.TYPE_INVALID);
|
||||
reference = params.getInputData().getInt(EXTRA_WIDGET_REFERENCE, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
}
|
||||
|
||||
public static void updateWidget(Context context, int type, int reference) {
|
||||
Log.d(TAG, "Scheduling update for widget " + type + " " + reference + ".");
|
||||
try {
|
||||
WorkManager workManager = WorkManager.getInstance(context);
|
||||
OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(OnetimeWidgetWorker.class);
|
||||
builder.setInputData(OnetimeWidgetWorker.createData(type, reference));
|
||||
builder.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST);
|
||||
OneTimeWorkRequest request = builder.build();
|
||||
workManager.beginWith(request).enqueue();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to schedule update for widget " + type + " " + reference + ".", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the data for scheduling the worker.
|
||||
*
|
||||
* @param type The type.
|
||||
* @param reference The reference.
|
||||
* @return The data.
|
||||
*/
|
||||
public static Data createData(int type, int reference) {
|
||||
Data.Builder b = new Data.Builder();
|
||||
b.putInt(EXTRA_WIDGET_TYPE, type);
|
||||
b.putInt(EXTRA_WIDGET_REFERENCE, reference);
|
||||
return b.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result doWork() {
|
||||
try {
|
||||
Log.d(TAG, "Performing update for widget " + type + " " + reference + ".");
|
||||
if (type == Widget.TYPE_INVALID || reference == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
Log.d(TAG, "Received an invalid request for type " + type + " and reference " + reference + ".");
|
||||
return Result.success();
|
||||
}
|
||||
WidgetDatabase database = app.getWidgetRepository().getDatabase();
|
||||
WidgetAccessor accessor = database.getAccessor();
|
||||
List<Widget> widgets = accessor.get(type, reference);
|
||||
if (widgets.isEmpty()) {
|
||||
Log.d(TAG, "Received a request for removed widget with type " + type + " and reference " + reference + ".");
|
||||
return Result.success();
|
||||
}
|
||||
Widget widget = widgets.get(0);
|
||||
if (type == Widget.TYPE_FORECAST) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient();
|
||||
long time = System.currentTimeMillis();
|
||||
City[] city = new City[] { widget.getData(City.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (city[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
city[0] = api.getCity(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
WeatherForecast[] content = new WeatherForecast[] { widget.getContent(WeatherForecast.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
content[0] = api.getCityForecast(widget.getDataId());
|
||||
contentTime[0] = time;
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(city[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.updateWidget(app.getContext(), w);
|
||||
});
|
||||
}
|
||||
} else if (type == Widget.TYPE_MEASURE) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient(app.getUserRepository().getCredentials().getValue());
|
||||
long time = System.currentTimeMillis();
|
||||
Device[] device = new Device[] { widget.getData(Device.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (device[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
device[0] = api.getDevice(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
Measurement[] content = new Measurement[] { widget.getContent(Measurement.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
MeasurementPage page = api.getDeviceMeasurements(widget.getDataId(), 0L, time, 0, 1);
|
||||
if (page.getElements().size() > 0) {
|
||||
content[0] = page.getElements().get(0);
|
||||
contentTime[0] = time;
|
||||
}
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(device[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.updateWidget(app.getContext(), w);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Failed to perform background update.", e);
|
||||
}
|
||||
// Indicate whether the work finished successfully with the Result
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mowesta.android.app.widget;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
import androidx.work.Worker;
|
||||
import androidx.work.WorkerParameters;
|
||||
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A widget worker that is scheduled for periodic
|
||||
* execution and triggers immediate one-time updates
|
||||
* for all widgets.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class PeriodicWidgetWorker extends Worker {
|
||||
|
||||
public static final String TAG = "PeriodicWidgetWorker";
|
||||
|
||||
private static final String WORK_TAG = "widget_refresh";
|
||||
|
||||
public PeriodicWidgetWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||
super(context, workerParams);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Result doWork() {
|
||||
updateWidgets(getApplicationContext());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules periodic updates to all widgets.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void scheduleUpdates(Context context) {
|
||||
Log.d(TAG, "Scheduling periodic widget updates.");
|
||||
PeriodicWorkRequest.Builder builder = new PeriodicWorkRequest.Builder(PeriodicWidgetWorker.class, 15, TimeUnit.MINUTES);
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(WORK_TAG, ExistingPeriodicWorkPolicy.KEEP, builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all widgets one time.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void updateWidgets(Context context) {
|
||||
Log.d(TAG, "Received widget update request.");
|
||||
boolean hasWidgets = updateWidgets(context, ForecastWidgetProvider.class, Widget.TYPE_FORECAST);
|
||||
hasWidgets |= updateWidgets(context, MeasureWidgetProvider.class, Widget.TYPE_MEASURE);
|
||||
if (!hasWidgets) cancelUpdates(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all widgets of a particular provider and returns whether anything
|
||||
* has been scheduled.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param provider The widget provider class.
|
||||
* @param type The widget type.
|
||||
* @return True if any update has been scheduled.
|
||||
*/
|
||||
private static boolean updateWidgets(Context context, Class<?> provider, int type) {
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(context);
|
||||
int[] ids = manager.getAppWidgetIds(new ComponentName(context, provider));
|
||||
WorkManager workManager = WorkManager.getInstance(context);
|
||||
for (int id: ids) {
|
||||
OnetimeWidgetWorker.updateWidget(context, type, id);
|
||||
}
|
||||
return ids.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the scheduled periodic update.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void cancelUpdates(Context context) {
|
||||
WorkManager.getInstance(context).cancelUniqueWork(WORK_TAG);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package com.mowesta.android.app.widget;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
|
||||
/**
|
||||
* The receiver that will
|
||||
*/
|
||||
public class WidgetReceiver extends BroadcastReceiver {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "WidgetReceiver";
|
||||
/**
|
||||
* The request code.
|
||||
*/
|
||||
private static final int REQuEST_CODE = 2298;
|
||||
|
||||
/**
|
||||
* The initial scheduling delay.
|
||||
*/
|
||||
private static final int DELAY_START = 60000;
|
||||
|
||||
/**
|
||||
* The periodic update rate.
|
||||
*/
|
||||
private static final int DELAY_PERIOD = 15 * 60000;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
updateWidgets(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all widgets.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void updateWidgets(Context context) {
|
||||
Log.d(TAG, "Received widget update request.");
|
||||
boolean hasWidgets = updateWidgets(context, ForecastWidgetProvider.class, Widget.TYPE_FORECAST);
|
||||
hasWidgets |= updateWidgets(context, MeasureWidgetProvider.class, Widget.TYPE_MEASURE);
|
||||
if (!hasWidgets) cancelUpdates(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all widgets of a particular provider and returns whether anything
|
||||
* has been scheduled.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param provider The widget provider class.
|
||||
* @param type The widget type.
|
||||
* @return True if any update has been scheduled.
|
||||
*/
|
||||
private static boolean updateWidgets(Context context, Class<?> provider, int type) {
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(context);
|
||||
int[] ids = manager.getAppWidgetIds(new ComponentName(context, provider));
|
||||
for (int id: ids) {
|
||||
WidgetService.scheduleUpdate(context, type, id);
|
||||
}
|
||||
return ids.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules periodic widget updates.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void scheduleUpdates(Context context) {
|
||||
Log.d(TAG, "Scheduling periodic widget updates.");
|
||||
AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + DELAY_START, DELAY_PERIOD, createIntent(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a pending intent for the updates.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return The pending intent.
|
||||
*/
|
||||
private static PendingIntent createIntent(Context context) {
|
||||
Intent intent = new Intent(context, WidgetReceiver.class);
|
||||
return PendingIntent.getBroadcast(context, 2298, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the period widget updates.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public static void cancelUpdates(Context context) {
|
||||
Log.d(TAG, "Canceling periodic widget updates.");
|
||||
AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
alarm.cancel(createIntent(context));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
package com.mowesta.android.app.widget;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.JobIntentService;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
import com.mowesta.android.app.database.WidgetAccessor;
|
||||
import com.mowesta.android.app.database.WidgetDatabase;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.Device;
|
||||
import com.mowesta.android.feign.model.Measurement;
|
||||
import com.mowesta.android.feign.model.MeasurementPage;
|
||||
import com.mowesta.android.feign.model.WeatherForecast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The service that updates the forecast widgets.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class WidgetService extends JobIntentService {
|
||||
|
||||
/**
|
||||
* The extra containing the reference.
|
||||
*/
|
||||
public static final String EXTRA_WIDGET_REFERENCE = "reference";
|
||||
|
||||
/**
|
||||
* The delay to update the data.
|
||||
*/
|
||||
private static final int DELAY_DATA = 24 * 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* The delay to update the content.
|
||||
*/
|
||||
private static final int DELAY_CONTENT = 1 * 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* The extra containing the widget type.
|
||||
*/
|
||||
public static final String EXTRA_WIDGET_TYPE = "type";
|
||||
|
||||
/**
|
||||
* The id for the service.
|
||||
*/
|
||||
private static final int SERVICE_ID = 1111;
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "WidgetService";
|
||||
|
||||
/**
|
||||
* A handler to perform work on the ui thread.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
|
||||
/**
|
||||
* Schedules an update for a particular widget referenced by its type and its
|
||||
* local id.
|
||||
*
|
||||
* @param context Tthe context.
|
||||
* @param reference The widget reference.
|
||||
* @param type The widget type.
|
||||
*/
|
||||
public static void scheduleUpdate(Context context, int type, int reference) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, JobIntentService.class);
|
||||
intent.putExtra(EXTRA_WIDGET_TYPE, type);
|
||||
intent.putExtra(EXTRA_WIDGET_REFERENCE, reference);
|
||||
enqueueWork(context, WidgetService.class, SERVICE_ID, intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleWork(@NonNull Intent intent) {
|
||||
int type = intent.getIntExtra(EXTRA_WIDGET_TYPE, Widget.TYPE_INVALID);
|
||||
int reference = intent.getIntExtra(EXTRA_WIDGET_REFERENCE, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
if (type == Widget.TYPE_INVALID || reference == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
Log.d(TAG, "Received an invalid request for type " + type + " and reference " + reference + ".");
|
||||
return;
|
||||
}
|
||||
IApp app = (IApp)getApplicationContext();
|
||||
WidgetDatabase database = app.getWidgetRepository().getDatabase();
|
||||
WidgetAccessor accessor = database.getAccessor();
|
||||
List<Widget> widgets = accessor.get(type, reference);
|
||||
if (widgets.isEmpty()) {
|
||||
Log.d(TAG, "Received a request for removed widget with type " + type + " and reference " + reference + ".");
|
||||
return;
|
||||
}
|
||||
Widget widget = widgets.get(0);
|
||||
if (type == Widget.TYPE_FORECAST) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient();
|
||||
long time = System.currentTimeMillis();
|
||||
City[] city = new City[] { widget.getData(City.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (city[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
city[0] = api.getCity(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
WeatherForecast[] content = new WeatherForecast[] { widget.getContent(WeatherForecast.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
content[0] = api.getCityForecast(widget.getDataId());
|
||||
contentTime[0] = time;
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(city[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.updateWidget(getApplicationContext(), w);
|
||||
});
|
||||
}
|
||||
} else if (type == Widget.TYPE_MEASURE) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient(app.getUserRepository().getCredentials().getValue());
|
||||
long time = System.currentTimeMillis();
|
||||
Device[] device = new Device[] { widget.getData(Device.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (device[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
device[0] = api.getDevice(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
Measurement[] content = new Measurement[] { widget.getContent(Measurement.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
MeasurementPage page = api.getDeviceMeasurements(widget.getDataId(), 0l, time, 0, 1);
|
||||
if (page.getElements().size() > 0) {
|
||||
content[0] = page.getElements().get(0);
|
||||
contentTime[0] = time;
|
||||
}
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(device[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.updateWidget(getApplicationContext(), w);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:angle="0"
|
||||
android:endColor="#ff0000"
|
||||
android:centerColor="#00aa00"
|
||||
android:startColor="#0000ff"
|
||||
android:type="linear" />
|
||||
|
||||
</shape>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06c-1.13,0.12 -2.19,0.46 -3.16,0.97l1.5,1.5C10.16,5.19 11.06,5 12,5c3.87,0 7,3.13 7,7 0,0.94 -0.19,1.84 -0.52,2.65l1.5,1.5c0.5,-0.96 0.84,-2.02 0.97,-3.15L23,13v-2h-2.06zM3,4.27l2.04,2.04C3.97,7.62 3.25,9.23 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c1.77,-0.2 3.38,-0.91 4.69,-1.98L19.73,21 21,19.73 4.27,3 3,4.27zM16.27,17.54C15.09,18.45 13.61,19 12,19c-3.87,0 -7,-3.13 -7,-7 0,-1.61 0.55,-3.09 1.46,-4.27l9.81,9.81z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
|
||||
</vector>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/navigation_view"
|
||||
android:layout_width="210dp"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
app:itemTextAppearance="?attr/textAppearanceBody1"
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
tools:context=".MowestaActivity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="false"
|
||||
android:id="@+id/layout_coordinator">
|
||||
|
||||
<fragment
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/navigation_app"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout_coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@@ -10,4 +12,4 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<data>
|
||||
<variable
|
||||
name="model"
|
||||
type="com.mowesta.android.app.model.AdvertiseViewModel" />
|
||||
</data>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/header"
|
||||
android:background="@color/accent"
|
||||
tools:targetApi="21"
|
||||
android:elevation="4dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Space
|
||||
android:layout_width="@dimen/space_medium"
|
||||
android:layout_height="wrap_content"/>
|
||||
<ImageView
|
||||
android:contentDescription="@null"
|
||||
android:layout_width="48dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_height="wrap_content"
|
||||
app:tint="@color/fg_accent"
|
||||
app:srcCompat="@drawable/ic_info_normal_24"/>
|
||||
|
||||
<TextView
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="@dimen/space_medium"
|
||||
android:layout_marginEnd="@dimen/space_medium"
|
||||
android:layout_gravity="center_vertical"
|
||||
style="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:text="@string/advertise_header"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
<ImageButton
|
||||
android:contentDescription="@string/button_close"
|
||||
android:layout_width="48dp"
|
||||
app:tint="@color/fg_accent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="@{ () -> model.close() }"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
|
||||
app:srcCompat="@drawable/ic_close_normal_24" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="@{ () -> model.open() }"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp">
|
||||
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/video_view"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:use_controller="false"
|
||||
app:resize_mode="zoom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ad_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="@string/advertise_title"
|
||||
android:textAppearance="?attr/textAppearanceHeadline3"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
<TextView
|
||||
android:text="@string/advertise_more"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/accent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ad_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:text="@string/advertise_description"
|
||||
android:textAppearance="?attr/textAppearanceBody2"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user