Decided to use the library to upload files. The previous version worked fine, but it was updated. When installing a new version of the library I can’t get the correct code in any way - the studio paints the code starting with mFetch.enqueue. Help to understand what is wrong? I do everything by example in the documentation.
public class BookCardActivity extends AppCompatActivity { static final String TAG = "myLogs"; private int bookId; Fetch mFetch; ProgressBar progressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_book_card); progressBar = (ProgressBar) findViewById(R.id.progressBar3); mFetch = (Fetch) new Fetch.Builder(this, "ToddlerBook") .setDownloadConcurrentLimit(4) .enableLogging(true) .build(); ImageButton imageButton = (ImageButton) findViewById(R.id.imageButtonHome); View.OnClickListener clickHome = new View.OnClickListener() { @Override public void onClick(View v) { GoHome(); } }; imageButton.setOnClickListener(clickHome); BookUriFromId(); String fileNamePath = "filesPath.json"; String covers = MyJSON.getData(this, fileNamePath); ArrayList<String> coversPaths = getFilesPathFromFile(covers); ImageView imageView = (ImageView) findViewById(R.id.imageView); int posit = bookId - 1; File imgFile = new File(coversPaths.get(posit)); Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); imageView.setImageBitmap(myBitmap); final Button buttonDownload = (Button) findViewById(R.id.button); /** * Проверим наличие файлов в папке bookfiles_1, bookfiles_2, ... */ String folderBook = "bookfiles_" + bookId; int count = 0; /** * Проверяем необходимость загрузки файлов */ File rootFile = new File(String.valueOf(getExternalFilesDir(folderBook))); File[] filesArray = rootFile.listFiles(); int numbFiles = filesArray.length; if (numbFiles == 0) { buttonDownload.setText(R.string.buttonDownload); /** * Загрузим json с url файлов книги */ Thread jsDownload = new Thread(new Runnable() { @Override public void run() { BookLoader(); } }); jsDownload.start(); // запустили поток 1 /** * Обрабатываем нажатие кнопки "Загрузить" и грузим файлы книги */ buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { 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(); List<String> sounds = book.getSoundUrl(); String[] urlsPages = pages.toArray(new String[0]); String[] urlsSounds = sounds.toArray(new String[0]); String[] urlsFiles = ArrayAndArrayNewArray(urlsPages, urlsSounds); String folderB = "bookfiles_" + bookId; String fileNameForWrite = "book_" + bookId + ".json"; final List<Request> requestList = new ArrayList<>(); File bookfolder = new File(String.valueOf(getExternalFilesDir(folderB))); ArrayList<String> pagesFiles = new ArrayList<>(); for (int i = 0; i < urlsFiles.length; i++) { String url = urlsFiles[i]; String path = String.valueOf(bookfolder); String fileName = Uri.parse(url).getLastPathSegment(); Log.d("my2", fileName); String pageFilePath = path + "/" + fileName; final Request request = new Request(url, pageFilePath); request.setPriority(Priority.HIGH); request.setNetworkType(NetworkType.ALL); requestList.add(request); // Log.d("my2", pageFilePath); pagesFiles.add(pageFilePath); } // ЗДЕСЬ ПРОБЛЕМА!!!! mFetch.enqueue(requestList, new Func<List<? extends Download>>() { @Override public void call(List<? extends Download> downloads) { //Successfully enqueued requests. } }, new Func<Error>() { @Override public void call(Error error) { // An error occurred when enqueuing requests. } }); BookFiles bookFiles = new BookFiles(); bookFiles.setBookID(bookId); ArrayList<String> pagesPath = getPagesArray(pagesFiles); ArrayList<String> soundsPath = getSoundsArray(pagesFiles); bookFiles.setPagesPath(pagesPath); bookFiles.setSoundsPath(soundsPath); Gson gson11 = new Gson(); String filesJson = gson11.toJson(bookFiles); MyJSON.saveData(getApplicationContext(), filesJson, fileNameForWrite); buttonDownload.setText(R.string.buttonRead); buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NextActivity(); } }); } }); } else { buttonDownload.setText(R.string.buttonRead); buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NextActivity(); } }); } } private void BookUriFromId() { //получаем номер ID книги, с обложки которой перешли в слайдер Intent intent = getIntent(); bookId = intent.getIntExtra("bookId", 1); Log.d(TAG, "You read book №" + bookId); } private void NextActivity() { new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(BookCardActivity.this, SliderActivity.class); intent.putExtra("bookId", bookId); // передаю в слайдер номер книги startActivity(intent); finish(); } }, 20); } private ArrayList<String> getFilesPathFromFile(String jsResult) { ArrayList<String> urisImg = new ArrayList<>(); try { JSONArray rootJson = new JSONArray(new JSONTokener(jsResult)); for (int i = 0; i < rootJson.length(); i++) { JSONObject o = rootJson.getJSONObject(i); String strTo = (String) o.get("uriString"); urisImg.add(strTo); } } catch (JSONException e) { e.printStackTrace(); } return urisImg; } private void BookLoader() { HttpURLConnection urlConnection = null; BufferedReader reader = null; String resultJsonServer = ""; String fileBook = "list_" + "book_" + bookId + ".json"; try { String jsUrl = "http://******.ru/todbook/book" + bookId + ".json"; URL url = new URL(jsUrl); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuilder buffer = new StringBuilder(); reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { buffer.append(line); } resultJsonServer = buffer.toString(); MyJSON.saveData(getApplicationContext(), resultJsonServer, fileBook); } catch (Exception e) { e.printStackTrace(); } } public static String[] ArrayAndArrayNewArray(String[] a, String[] b) { if (a == null) return b; if (b == null) return a; String[] r = new String[a.length + b.length]; System.arraycopy(a, 0, r, 0, a.length); System.arraycopy(b, 0, r, a.length, b.length); return r; } public ArrayList<String> getSoundsArray(ArrayList<String> pagesFiles) { ArrayList<String> res = new ArrayList<>(); for (int i = 0; i < pagesFiles.size(); i++) { String soun = pagesFiles.get(i); if (soun.contains("sound")) { res.add(soun); } } return res; } public ArrayList<String> getPagesArray(ArrayList<String> pagesFiles) { ArrayList<String> res = new ArrayList<>(); for (int i = 0; i < pagesFiles.size(); i++) { String soun = pagesFiles.get(i); if (!soun.contains("sound")) { res.add(soun); } } return res; } private void GoHome() { new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(BookCardActivity.this, MainActivity.class); startActivity(intent); finish(); } }, 10); } }
Студия красит тот же участок кода, it also says that it is not. - post_zeew