Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Comments

Homework6#6

Open
AndreiGrek wants to merge 2 commits intomasterfrom
Homework6
Open

Homework6#6
AndreiGrek wants to merge 2 commits intomasterfrom
Homework6

Conversation

@AndreiGrek
Copy link
Owner

No description provided.

finish();
}
});
checkStorage.isChecked();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по-моему эта строчка лишняя. ты ничего не делаешь с результатом, который ты получаешь из checkStorage.isChecked();

Comment on lines +13 to +15
EditText fileName;
EditText fileText;
int position;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет модификаторов доступа

Comment on lines +21 to +26
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут как бы есть небольшая недоработка. Лично я бы передавал бы в эту активити путь к файлу и уже в ней читал бы файл, сохранял и так далее. В общем делал бы все что необходимо в рамках этой активити. Ну и собственно методы по работе с файлами лучше вынести в отдельный класс. Может тут как раз подойдут просто статические методы. Надо пробовать

import android.widget.Button;
import android.widget.EditText;

public class EditItem extends AppCompatActivity {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не совсем удачное имя для класса.

  • Не понятно что это за компонент: активити, элемент списка и что-то еще
  • Лучше к таким классам приписывать слово Activtiy/
    Так вот лучше что-то типа EditTextActivity

Comment on lines +31 to +35
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если использовать чтение файла в этой активити, то можно и использовать сохранение файла

import java.io.OutputStreamWriter;
import java.util.ArrayList;

public class SecondActivity extends AppCompatActivity {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не совсем понимаю зачем эта активити была создана. По факту список файлов можно было отобразить в MainActivity. Из нее открывать активити для редактирования файла. По сути SecondActivity тут избыточна.

private ArrayAdapter<File> mAdapter;
private ArrayList<File> fileArray;
private String text;
private ListView lvMain;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не используй ListView. Это устаревший компонент, который уже неиспользуется в практике

Comment on lines +48 to +78
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();
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если ты сравнишь код в блоке if и в блоке else if, то ты заметишь, что у тебя большая часть кода совпадает. Как минимум сама логика записи одна и та же. Значит этот код можно выделить в отдельный метод. Так как это работа с файлом, то этот мметод должен быть в другом классе.

Comment on lines +47 to +48


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишние пустые строки

Comment on lines +57 to +58


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишние пустые строки

Comment on lines +35 to +36


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишние пустые строки

android:layout_marginRight="16dp"
android:text="Перейти к настройкам" />

<ListView

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

еще раз напомню. вместо ListView надо использовать RecyclerView

android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Создание нового файла"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="Введите текст для сохранения в файл"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:id="@+id/writeFileName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Введите имя нового файла"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_margin="16dp"
app:layout_constraintTop_toBottomOf="@+id/btnSave"
app:layout_constraintLeft_toLeftOf="parent"
android:text="Перейти к списку файлов"/>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Список Файлов:"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="Создать новый файл" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="Перейти к настройкам" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center"
android:text="Настройки"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Сохранять на External Storage"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Назад к списку файлов"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Редактирование файла"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="Введите текст для сохранения в файл"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="Введите имя нового файла"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Сохранить файл"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

app:layout_constraintLeft_toLeftOf="@+id/etText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Создать файл"/>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не забывай выносить строковые ресурсы в соотвествующий файл - strings.xml

Comment on lines +3 to +4
android:layout_width="fill_parent"
android:layout_height="fill_parent"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fill_parent - это устаревшее значение вместо него надо использовать match_parent

android:layout_margin="16dp"
android:gravity="center"
android:text="Настройки"
android:textColor="#000000"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Цвета тоже надо выносить в colors.xml

android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Редактирование файла"
android:textColor="#000000"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Цвета тоже надо выносить в colors.xml

android:layout_margin="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:textColor="#000000"/>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Цвета тоже надо выносить в colors.xml

android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Список Файлов:"
android:textColor="#000000"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Цвета тоже надо выносить в colors.xml

android:gravity="center"
android:text="Настройки"
android:textColor="#000000"
android:textSize="30dp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

размер текста указывается в других поинтах - sp

android:layout_margin="16dp"
android:text="Список Файлов:"
android:textColor="#000000"
android:textSize="40dp" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

размер текста указывается в других поинтах - sp

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants