Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

ДЗ_2_Сагадеева Светлана #22

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
*.iml
.gradle
/local.properties
Expand All @@ -11,3 +12,4 @@
/build
/captures
.externalNativeBuild
/.idea/
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

28 changes: 19 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "ru.ok.technopolis.students"
minSdkVersion 15
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -17,12 +17,22 @@ android {
}
}
}
repositories {
google()
jcenter()

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.android.support:recyclerview-v7:28.0.0'
compile 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.ok.technopolis.students">

<application
Expand All @@ -8,14 +9,18 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AdditionActivity" />
<activity android:name=".InfoActivity"/>

</application>

</manifest>
61 changes: 61 additions & 0 deletions app/src/main/java/ru/ok/technopolis/students/AdditionActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ru.ok.technopolis.students;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.RadioAccessSpecifier;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.Random;

public class AdditionActivity extends AppCompatActivity implements View.OnClickListener {
TextView secondName;
Copy link

Choose a reason for hiding this comment

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

Лучше в явном виде устанавливать видимость полей (public,private...)

TextView firstName;
ImageView photo;
RadioButton isFemale;
RadioButton isMale;
Button saver;

private String[] image_names;
Copy link

Choose a reason for hiding this comment

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

Стоит использовать camelCase

int pic_id;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setTitle("Addition");
setContentView(R.layout.student_addition);
Random random = new Random();
Intent data = getIntent();
Copy link

Choose a reason for hiding this comment

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

Зачем здесь интент?

secondName = (EditText) findViewById(R.id.student_add__et_second_name);
firstName = (EditText) findViewById(R.id.student_add__et_first_name);
image_names = getResources().getStringArray(R.array.image_names);
photo = findViewById(R.id.student_add__iv_photo);
isFemale = findViewById(R.id.student_add__rb_female);
isMale = findViewById(R.id.student_add__rb_male);
saver = findViewById(R.id.student_add__b_save);
pic_id = getResources().getIdentifier(image_names[random.nextInt(5)], "drawable", getPackageName());
photo.setImageResource(pic_id);
saver.setOnClickListener(this);
}

@Override
public void onClick(View v) {

Copy link

Choose a reason for hiding this comment

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

Лишняя строка

boolean male = isMale.isChecked();
Intent intent = new Intent();
intent.putExtra("secondName", secondName.getText().toString());
Copy link

Choose a reason for hiding this comment

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

secondName.getText() может вернуть null

Copy link
Author

Choose a reason for hiding this comment

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

ошибки ввода пользователем (попытки добавить или изменить студента, оставив его с пустой фамилией или именем) обрабатываю в InfoActivity и AdditionActivity соответственно

intent.putExtra("firstName", firstName.getText().toString());
intent.putExtra("sex", male);
intent.putExtra("photo", pic_id);
setResult(RESULT_OK, intent);
finish();
}
}
81 changes: 81 additions & 0 deletions app/src/main/java/ru/ok/technopolis/students/InfoActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ru.ok.technopolis.students;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import java.util.Random;

public class InfoActivity extends AppCompatActivity implements View.OnClickListener {
TextView secondName;
TextView firstName;
ImageView photo;
RadioButton isFemale;
RadioButton isMale;
Button saver;
Button deleter;

private String[] image_names;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setTitle("Editor");
setContentView(R.layout.student_info);
secondName = (EditText) findViewById(R.id.student_info__et_second_name);
firstName = (EditText) findViewById(R.id.student_info__et_first_name);
image_names = getResources().getStringArray(R.array.image_names);
photo = findViewById(R.id.student_info__iv_photo);
isFemale = findViewById(R.id.student_info__rb_female);
isMale = findViewById(R.id.student_info__rb_male);
saver = findViewById(R.id.student_info__b_save);
deleter = findViewById(R.id.student_info__b_delete);
Intent data = getIntent();
int pic_id = data.getIntExtra("photo", 1);
// int id = getResources().getIdentifier(image_names[pic_id], "drawable", getPackageName());
Copy link

Choose a reason for hiding this comment

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

?

photo.setImageResource(pic_id);
boolean male;
boolean female;
male = data.getBooleanExtra("male", false);
Copy link

Choose a reason for hiding this comment

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

Ключи экстра лучше определить в виде констант, что бы избежать опечаток в написании

Copy link

Choose a reason for hiding this comment

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

@gilgenbergg Все еще актуально

Copy link

Choose a reason for hiding this comment

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

Зачем тут инициализация в 2 строки? Можно сделать одной

female = !male;
Copy link

Choose a reason for hiding this comment

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

Не используется нигде

secondName.setText(data.getStringExtra("second_name"));
firstName.setText(data.getStringExtra("first_name"));
if (male)
Copy link

Choose a reason for hiding this comment

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

Лучше ставить фигурные скобы в условии if

Copy link

Choose a reason for hiding this comment

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

@gilgenbergg Все еще актуально

isMale.setChecked(true);
Copy link

Choose a reason for hiding this comment

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

можно прям поставить результат в радиобаттон isMale.setChecked(male);

else
isFemale.setChecked(true);
saver.setOnClickListener(this);
deleter.setOnClickListener(this);
}

@Override
public void onClick(View v) {
Intent intent = new Intent();
switch (v.getId()) {
case R.id.student_info__b_save:
intent.putExtra("secondName", secondName.getText().toString());
intent.putExtra("firstName", firstName.getText().toString());
intent.putExtra("button_code", 1);
intent.putExtra("index", getIntent().getIntExtra("index", -1));
intent.putExtra("photo", getIntent().getIntExtra("photo", 1));
intent.putExtra("isMale", false);
// intent.putExtra("pic_id", 1);
Copy link

Choose a reason for hiding this comment

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

?

Copy link
Author

Choose a reason for hiding this comment

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

весь закомменченный код убран

break;
case R.id.student_info__b_delete:
intent.putExtra("button_code", 2);
intent.putExtra("index", getIntent().getIntExtra("index", -1));
break;
default:
break;
}
setResult(RESULT_OK, intent);
finish();
}
}
Loading