1212import com .fox2code .foxcompat .app .FoxActivity ;
1313import com .fox2code .mmm .utils .io .net .Http ;
1414import com .google .android .material .bottomnavigation .BottomNavigationItemView ;
15- import com .google .android .material .button . MaterialButton ;
15+ import com .google .android .material .bottomnavigation . BottomNavigationView ;
1616import com .google .android .material .progressindicator .LinearProgressIndicator ;
1717import com .google .android .material .textview .MaterialTextView ;
1818
@@ -42,8 +42,9 @@ protected void onCreate(Bundle savedInstanceState) {
4242 // Get the progress bar and make it indeterminate for now
4343 LinearProgressIndicator progressIndicator = findViewById (R .id .update_progress );
4444 progressIndicator .setIndeterminate (true );
45- // get update_cancel button
46- MaterialButton updateCancel = findViewById (R .id .update_cancel_button );
45+ // get update_cancel item on bottom navigation
46+ BottomNavigationView bottomNavigationView = findViewById (R .id .bottom_navigation );
47+ BottomNavigationItemView updateCancel = bottomNavigationView .findViewById (R .id .update_cancel_button );
4748 // get status text view
4849 MaterialTextView statusTextView = findViewById (R .id .update_progress_text );
4950 // set status text to please wait
@@ -85,8 +86,7 @@ public void run() {
8586 } else if (action == ACTIONS .DOWNLOAD ) {
8687 try {
8788 downloadUpdate ();
88- } catch (
89- JSONException e ) {
89+ } catch (JSONException e ) {
9090 runOnUiThread (() -> {
9191 // set status text to error
9292 statusTextView .setText (R .string .error_download_update );
@@ -97,7 +97,7 @@ public void run() {
9797 }
9898 } else if (action == ACTIONS .INSTALL ) {
9999 // ensure path was passed and points to a file within our cache directory. replace .. and url encoded characters
100- String path = getIntent ().getStringExtra ("path" ).trim ().replaceAll ("\\ .\\ ." , "" ).replaceAll ("%2e%2e" , "" );
100+ String path = Objects . requireNonNull ( getIntent ().getStringExtra ("path" ) ).trim ().replaceAll ("\\ .\\ ." , "" ).replaceAll ("%2e%2e" , "" );
101101 if (path .isEmpty ()) {
102102 runOnUiThread (() -> {
103103 // set status text to error
@@ -119,8 +119,7 @@ public void run() {
119119 if (parentFile == null || !parentFile .getCanonicalPath ().startsWith (getCacheDir ().getCanonicalPath ())) {
120120 throw new SecurityException ("Path is not in cache directory: " + path );
121121 }
122- } catch (
123- IOException e ) {
122+ } catch (IOException e ) {
124123 throw new SecurityException ("Path is not in cache directory: " + path );
125124 }
126125 if (!file .exists ()) {
@@ -164,6 +163,7 @@ public void run() {
164163 updateThread .start ();
165164 }
166165
166+ @ SuppressLint ("RestrictedApi" )
167167 public void checkForUpdate () {
168168 // get status text view
169169 MaterialTextView statusTextView = findViewById (R .id .update_progress_text );
@@ -184,7 +184,9 @@ public void checkForUpdate() {
184184 statusTextView .setText (R .string .update_available );
185185 // set button text to download
186186 BottomNavigationItemView button = findViewById (R .id .action_update );
187- button .setTooltipText (R .string .download_update );
187+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
188+ button .setTooltipText (getString (R .string .download_update ));
189+ }
188190 button .setEnabled (true );
189191 });
190192 // return
@@ -211,8 +213,7 @@ public void downloadUpdate() throws JSONException {
211213 byte [] lastestJSON = new byte [0 ];
212214 try {
213215 lastestJSON = Http .doHttpGet (AppUpdateManager .RELEASES_API_URL , false );
214- } catch (
215- Exception e ) {
216+ } catch (Exception e ) {
216217 // when logging, REMOVE the json from the log
217218 Timber .e (e , "Error downloading update info" );
218219 runOnUiThread (() -> {
@@ -274,8 +275,7 @@ public void downloadUpdate() throws JSONException {
274275 // update status text
275276 statusTextView .setText (getString (R .string .downloading_update , (int ) (((float ) downloaded / (float ) total ) * 100 )));
276277 }));
277- } catch (
278- Exception e ) {
278+ } catch (Exception e ) {
279279 runOnUiThread (() -> {
280280 progressIndicator .setIndeterminate (false );
281281 progressIndicator .setProgressCompat (100 , false );
@@ -320,8 +320,7 @@ public void downloadUpdate() throws JSONException {
320320 updateFile = new File (getCacheDir (), "update.apk" );
321321 fileOutputStream = new FileOutputStream (updateFile );
322322 fileOutputStream .write (update );
323- } catch (
324- IOException e ) {
323+ } catch (IOException e ) {
325324 runOnUiThread (() -> {
326325 progressIndicator .setIndeterminate (false );
327326 progressIndicator .setProgressCompat (100 , false );
@@ -333,8 +332,7 @@ public void downloadUpdate() throws JSONException {
333332 }
334333 try {
335334 Objects .requireNonNull (fileOutputStream ).close ();
336- } catch (
337- IOException ignored ) {
335+ } catch (IOException ignored ) {
338336 }
339337 }
340338 // install the update
0 commit comments