Depending on the presence of files in the folder, the button changes its text "Read / Download". If the files are in place, immediately setText "Read" and go to another activity. If there are no files, setText "Load" and load the files. Then we change the inscription to "Read". But when pressed again, the handler re-launches the file download. Tell me, please, how to do it. Here is the code:
if(numbFiles == 0) { buttonDownload.setText(R.string.buttonDownload); /** * ΠΠ°Π³ΡΡΠ·ΠΈΠΌ json Ρ url ΡΠ°ΠΉΠ»ΠΎΠ² ΠΊΠ½ΠΈΠ³ΠΈ */ Thread jsDownload = new Thread(new Runnable() { @Override public void run() { BookLoader(); } }); jsDownload.start(); // Π·Π°ΠΏΡΡΡΠΈΠ»ΠΈ ΠΏΠΎΡΠΎΠΊ 1 try { } catch (Exception e) { e.printStackTrace(); } /** * ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅ΠΌ Π½Π°ΠΆΠ°ΡΠΈΠ΅ ΠΊΠ½ΠΎΠΏΠΊΠΈ "ΠΠ°Π³ΡΡΠ·ΠΈΡΡ" ΠΈ Π³ΡΡΠ·ΠΈΠΌ ΡΠ°ΠΉΠ»Ρ ΠΊΠ½ΠΈΠ³ΠΈ */ buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Thread mThread = new Thread(new Runnable() { @Override public void run() { String fileListB = "list_" + "book_" + bookId + ".json"; String jsReadFile = MyJSON.getData(getApplicationContext(), fileListB); Log.d(TAG, jsReadFile); Gson gson = new Gson(); Book book = gson.fromJson(jsReadFile, Book.class); List<String> pages = book.getPageUrl(); String[] urlsPages = pages.toArray(new String[0]); DownloadFilesBook(urlsPages); } }); mThread.start(); // Π·Π°ΠΏΡΡΡΠΈΠ»ΠΈ ΠΏΠΎΡΠΎΠΊ 2 buttonDownload.setText(R.string.buttonRead); } }); } else { buttonDownload.setText(R.string.buttonRead); buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NextActivity(); } });