Conversation
| finish(); | ||
| } | ||
| }); | ||
| checkStorage.isChecked(); |
There was a problem hiding this comment.
по-моему эта строчка лишняя. ты ничего не делаешь с результатом, который ты получаешь из checkStorage.isChecked();
| EditText fileName; | ||
| EditText fileText; | ||
| int position; |
| Intent intent = getIntent(); | ||
| fileName = findViewById(R.id.fileName); | ||
| fileText = findViewById(R.id.fileText); | ||
| fileName.setText(intent.getStringExtra("NAME")); | ||
| fileText.setText(intent.getStringExtra("TEXT")); | ||
| position = intent.getIntExtra("POSITION", 0); |
There was a problem hiding this comment.
Тут как бы есть небольшая недоработка. Лично я бы передавал бы в эту активити путь к файлу и уже в ней читал бы файл, сохранял и так далее. В общем делал бы все что необходимо в рамках этой активити. Ну и собственно методы по работе с файлами лучше вынести в отдельный класс. Может тут как раз подойдут просто статические методы. Надо пробовать
| import android.widget.Button; | ||
| import android.widget.EditText; | ||
|
|
||
| public class EditItem extends AppCompatActivity { |
There was a problem hiding this comment.
Не совсем удачное имя для класса.
- Не понятно что это за компонент: активити, элемент списка и что-то еще
- Лучше к таким классам приписывать слово Activtiy/
Так вот лучше что-то типаEditTextActivity
| Intent resultIntent = new Intent(); | ||
| resultIntent.putExtra("NAMESAVE", fileName.getText().toString()); | ||
| resultIntent.putExtra("TEXTSAVE", fileText.getText().toString()); | ||
| resultIntent.putExtra("POSITIONSAVE", position); | ||
| setResult(Activity.RESULT_OK, resultIntent); |
There was a problem hiding this comment.
Если использовать чтение файла в этой активити, то можно и использовать сохранение файла
| import java.io.OutputStreamWriter; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class SecondActivity extends AppCompatActivity { |
There was a problem hiding this comment.
Не совсем понимаю зачем эта активити была создана. По факту список файлов можно было отобразить в MainActivity. Из нее открывать активити для редактирования файла. По сути SecondActivity тут избыточна.
| private ArrayAdapter<File> mAdapter; | ||
| private ArrayList<File> fileArray; | ||
| private String text; | ||
| private ListView lvMain; |
There was a problem hiding this comment.
Не используй ListView. Это устаревший компонент, который уже неиспользуется в практике
| if (isCheked == false) { | ||
| try { | ||
| BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( | ||
| openFileOutput(writeFileName.getText().toString(), MODE_PRIVATE))); | ||
| bw.write(etText.getText().toString()); | ||
| Toast.makeText(MainActivity.this, "Файл \"" + | ||
| writeFileName.getText().toString() + "\" успешно сохранен во внутреннюю память", Toast.LENGTH_SHORT).show(); | ||
| fileArray.add(new File(writeFileName.getText().toString())); | ||
| bw.close(); | ||
|
|
||
| } catch (FileNotFoundException e) { | ||
| e.printStackTrace(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } else if (isCheked == true) { | ||
| File externalPath = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "MyFiles"); | ||
| externalPath.mkdir(); | ||
| File externalFile = new File(externalPath, writeFileName.getText().toString()); | ||
| try { | ||
| BufferedWriter bw = new BufferedWriter(new FileWriter(externalFile)); | ||
| bw.write(etText.getText().toString()); | ||
| Toast.makeText(MainActivity.this, "Файл \"" + | ||
| writeFileName.getText().toString() + "\" успешно сохранен во внешнюю память", Toast.LENGTH_SHORT).show(); | ||
| fileArray.add(new File(writeFileName.getText().toString())); | ||
| bw.close(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Если ты сравнишь код в блоке if и в блоке else if, то ты заметишь, что у тебя большая часть кода совпадает. Как минимум сама логика записи одна и та же. Значит этот код можно выделить в отдельный метод. Так как это работа с файлом, то этот мметод должен быть в другом классе.
|
|
||
|
|
|
|
||
|
|
|
|
||
|
|
| android:layout_marginRight="16dp" | ||
| android:text="Перейти к настройкам" /> | ||
|
|
||
| <ListView |
There was a problem hiding this comment.
еще раз напомню. вместо ListView надо использовать RecyclerView
| android:id="@+id/title" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="Создание нового файла" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:hint="Введите текст для сохранения в файл" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:id="@+id/writeFileName" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:hint="Введите имя нового файла" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_margin="16dp" | ||
| app:layout_constraintTop_toBottomOf="@+id/btnSave" | ||
| app:layout_constraintLeft_toLeftOf="parent" | ||
| android:text="Перейти к списку файлов"/> |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:text="Список Файлов:" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_height="wrap_content" | ||
| android:layout_marginLeft="16dp" | ||
| android:layout_marginRight="16dp" | ||
| android:text="Создать новый файл" /> |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_height="wrap_content" | ||
| android:layout_marginLeft="16dp" | ||
| android:layout_marginRight="16dp" | ||
| android:text="Перейти к настройкам" /> |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:gravity="center" | ||
| android:text="Настройки" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_height="wrap_content" | ||
| android:layout_margin="20dp" | ||
| android:gravity="center" | ||
| android:text="Сохранять на External Storage" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:text="Назад к списку файлов" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:text="Редактирование файла" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:hint="Введите текст для сохранения в файл" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:hint="Введите имя нового файла" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:text="Сохранить файл" |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| app:layout_constraintLeft_toLeftOf="@+id/etText" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="Создать файл"/> |
There was a problem hiding this comment.
Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" |
There was a problem hiding this comment.
fill_parent - это устаревшее значение вместо него надо использовать match_parent
| android:layout_margin="16dp" | ||
| android:gravity="center" | ||
| android:text="Настройки" | ||
| android:textColor="#000000" |
There was a problem hiding this comment.
Цвета тоже надо выносить в colors.xml
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:text="Редактирование файла" | ||
| android:textColor="#000000" |
There was a problem hiding this comment.
Цвета тоже надо выносить в colors.xml
| android:layout_margin="16dp" | ||
| app:layout_constraintTop_toTopOf="parent" | ||
| app:layout_constraintLeft_toLeftOf="parent" | ||
| android:textColor="#000000"/> |
There was a problem hiding this comment.
Цвета тоже надо выносить в colors.xml
| android:layout_height="wrap_content" | ||
| android:layout_margin="16dp" | ||
| android:text="Список Файлов:" | ||
| android:textColor="#000000" |
There was a problem hiding this comment.
Цвета тоже надо выносить в colors.xml
| android:gravity="center" | ||
| android:text="Настройки" | ||
| android:textColor="#000000" | ||
| android:textSize="30dp" |
There was a problem hiding this comment.
размер текста указывается в других поинтах - sp
| android:layout_margin="16dp" | ||
| android:text="Список Файлов:" | ||
| android:textColor="#000000" | ||
| android:textSize="40dp" /> |
There was a problem hiding this comment.
размер текста указывается в других поинтах - sp
No description provided.