Skip to content

First code review of the client part - #2

Open
ASGusev wants to merge 75 commits into
appliedfrom
master
Open

First code review of the client part#2
ASGusev wants to merge 75 commits into
appliedfrom
master

Conversation

@ASGusev

@ASGusev ASGusev commented Dec 26, 2016

Copy link
Copy Markdown
Collaborator

Я недавно узнал про runInInterfaceThread и собираюсь убрать BroadcastReceiver.

@sproshev sproshev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Посмотрел все, кроме Message, ImageStorage, SendMM. Часть Activity пропустил, т.к. еще недописано (создание наборов карт и т.п.)

android:text="Повторите новый пароль:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/changePasswordNew1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@+id/changePasswordNew1 в этом файле определен два раза, и идея (андроид студия) это подсвечивает

//TODO: get rid of BroadcastReceivers
public class MainActivity extends AppCompatActivity implements Message.LoginMessageListener,
Message.RatingMessageListener {
private static final String RATING_PREFIX = "Рейтинг: ";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

все отображаемые сообщения должны быть в ресурсах

nicknameText = (TextView)findViewById(R.id.mainNickname);
ratingText = (TextView)findViewById(R.id.mainRatingText);

ImageStorage.createImageStorage(this);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно попробовать сделать так, чтобы хранилище картинок создавалось при первом обращении к нему, т.к. приложение может так поменяться, что запуск необязательно будет с MainActivity. В общем типичный синглтон

//TODO: get rid of BroadcastReceivers
public class MainActivity extends AppCompatActivity implements Message.LoginMessageListener,
Message.RatingMessageListener {
private static final String RATING_PREFIX = "Рейтинг: ";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

все отображаемые пользователю строки должны быть в ресурсах

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

включая те, что участвуют в layout-xml-файлах

if (code != LoginActivity.SUCCESSFUL_LOGIN) {
Intent login = new Intent(this, LoginActivity.class);
startActivity(login);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

при этом пользователю лучше что-то сказать

@@ -0,0 +1,51 @@
package ru.spbau.resemblance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

вроде не используется

@@ -0,0 +1,21 @@
package ru.spbau.resemblance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

вроде не используется

@@ -0,0 +1,37 @@
package ru.spbau.resemblance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

немного не понял, он и принимает и получает сообщения? какое предназначение у этого класса?

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DeletePlayerDialog dialog = new DeletePlayerDialog();
dialog.setPlayer(position);
dialog.setActivity(this);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

конструктор?

@ASGusev ASGusev Jan 3, 2017

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Она ругается, говорит что у такого фрагмента не может быть конструкторов с параметрами, а поля надо задавать через сеттеры.

LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(PLAYERS_LIST_UPDATE_MESSAGE));
}

public static class DeletePlayerDialog extends DialogFragment {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

private

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

На private тоже ругается.

@sproshev sproshev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

пока хватит


private static void addTestSet(Context context, String nameSet, String prefCardName, int sizeSet) {
SetCardsWrapped setCards = new SetCardsWrapped();
setCards.setNameSetCards(nameSet);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

setName?

private static void addTestSet(Context context, String nameSet, String prefCardName, int sizeSet) {
SetCardsWrapped setCards = new SetCardsWrapped();
setCards.setNameSetCards(nameSet);
setCards.addSetCards();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

из названия непонятно, что делает метод, может putToDb?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

addTestSet или addSetCards?

for (int i = 1; i <= sizeSet; i++) {
int curId = context.getResources().getIdentifier(prefCardName + i, "drawable", context.getPackageName());
Resources resources = context.getResources();
ImageWrapped curImage = addImageByUri(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(curId) + '/' + resources.getResourceTypeName(curId) + '/' + resources.getResourceEntryName(curId), context);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

этот метод никуда ничего не добавляет

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Это про addImageByUri?

private static void printToLogCur(Cursor c) {
StringBuilder newLog = new StringBuilder();
for (String columnName : c.getColumnNames()) {
newLog.append(columnName + " = " + c.getString(c.getColumnIndex(columnName)) + " ; ");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

тут warning в идее

long hashImage = 0;
try {
Uri uri = Uri.parse(uriImage);
InputStream stream = new BufferedInputStream(context.getContentResolver().openInputStream(uri));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

закрыть поток?

Log.d(LOG_TAG, "Wrong image");
}
imageDB.close();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

в каких случаях используется? почему может потребоваться обновить объект и как получить ситуацию, что обновленные данные будут отличаться от текущих?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Это к setImageInfo?

setIdImage(imageDB.getWritableDatabase().insert(IMAGE_TABLE, null, cv));
imageDB.close();
return true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DB

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Это к чему?

hashSetCards = newHash;
}

private SetCardsWrapped(Cursor c) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

те же замечания, что и классу выше

return true;
}

public static void sendMessage(final byte[] message) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

на каждую запись стартует новый поток?(

@@ -0,0 +1,154 @@
package ru.spbau.resemblance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

почему бы не забить на этот модуль и начать использовать AsyncTask? надо что-то спросить у сервера, запустил таску, она выполнилась, результат отдала

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Не вся коммуникация состоит из запросов к серверу. Во время игры сервер присылает нам данные о раунде; сообщения, с запросом на выбор карты. Что делать с ними?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants