Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review Task 1 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
117 changes: 117 additions & 0 deletions src/main/java/pl/fracz/mcr/source/Line.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package pl.fracz.mcr.source;

/*
2013-10-23, fracz, first implementation
2013-10-30, fracz, added syntax highlighting
2014-02-26, fracz, added ability to add voice comment
*/

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Html;
import android.widget.LinearLayout;
import android.widget.TextView;

Choose a reason for hiding this comment

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

Dodalbym spacje pomiedzy android a pl.fracz importami

import pl.fracz.mcr.comment.AbstractComment;
import pl.fracz.mcr.comment.Comment;
import pl.fracz.mcr.comment.CommentNotAddedException;

import java.io.File;
import java.io.Serializable;
import java.util.List;

/**
* View that represents one line of code.
*/
@SuppressLint("ViewConstructor")
public class Line extends LinearLayout implements Serializable {
private static final long serialVersionUID = 3076583280108678995L;

Choose a reason for hiding this comment

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

zgodnie z konwencja const z duzych liter: SERIAL_VERSION_UID

private static final int TWO = 2;

private final int _lineNumber;

private final String _lineOfCode;

// holds the line number

Choose a reason for hiding this comment

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

useless komentarz, lepsza nazwa zmiennej wszystko załatwi

private TextView lineNumberView;

private TextView lineContent;

private SourceFile sourceFile;

private List<Comment> comments;

public Line(Context context, SourceFile sourceFile, int lineNumber,
String lineOfCode, boolean syntaxColor) {
super(context);
this.sourceFile = sourceFile;
this._lineNumber = lineNumber;
this._lineOfCode = lineOfCode;
setOrientation(LinearLayout.HORIZONTAL);

lineNumberView = new TextView(getContext());
lineNumberView.setText(String.format("%d.", lineNumber););
lineNumberView.setSingleLine();
lineNumberView.setWidth(30);
addView(lineNumberView);

TextView lineContent = new TextView(getContext());
addLineContent(syntaxColor);
Comment on lines +53 to +60

Choose a reason for hiding this comment

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

żadnej logiki w konstruktorze, wydzieliłbym to do osobnych prywatnych metod

}

public int get() {
return _lineNumber;
}

/**
* Adds a text comment.
*
* @param comment
* @throws CommentNotAddedException
*/
Comment on lines +67 to +72

Choose a reason for hiding this comment

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

Zbyteczny komentarz, nazwa i sygnatura metody wszystko tłumaczy

public void addTextComment(String comment) throws CommentNotAddedException {
Comment textComment = new Comment(AbstractComment.Type.TEXT, this);
textComment.setText(comment);
Comment on lines +74 to +75

Choose a reason for hiding this comment

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

można wydzielić do prywatnej metody createComment(String comment)

comments.add(textComment);
if (comments.size() > 0) {
lineNumberView.setBackgroundColor(Color.parseColor("#008000"));
}
Comment on lines +77 to +79

Choose a reason for hiding this comment

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

całkowicie bezużyteczne, comments.size() zawsze bedzie wieksze od 0 po dodaniu wczesniej komentarza

}

/**
* Adds a voice comment.
*
* @param recordedFile
* @throws CommentNotAddedException
*/
Comment on lines +82 to +87

Choose a reason for hiding this comment

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

tak samo jak wyzej, zbyteczny komentarz

public void createVoiceComment(File recodedFile) throws CommentNotAddedException {

Choose a reason for hiding this comment

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

metoda powinna sie nazywac addVoiceComment, natomiast w jej srodku powinna sie znalezc metoda createVoiceComment(File recordedFile) (pierwsze 2 linijki)

Comment voiceComment = new Comment(AbstractComment.Type.VOICE, this);
voiceComment.setFile(recodedFile);
comments.add(voiceComment);
if (comments.size() > 0) {
lineNumberView.setBackgroundColor(Color.parseColor("#008000"));
}
Comment on lines +92 to +94

Choose a reason for hiding this comment

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

tak jak wyzej, po dodaniu komentarza size zawsze wiekszy od 0

}

// public void addVideoComment(File videoFile) throws CommentNotAddedException {
// }
Comment on lines +97 to +98

Choose a reason for hiding this comment

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

do usunięcia, nieużywane


private void addLineContent(boolean syntaxColor){
if (!syntaxColor || !SyntaxHighlighter.canBeHighlighted(syntaxColor))
lineContent.setText(Html.fromHtml(lineOfCode));
else
lineContent.setText(SyntaxHighlighter.highlight(Html.fromHtml(lineOfCode)));
lineContent.setTypeface(Typeface.MONOSPACE);
addView(lineContent);
}
Comment on lines +100 to +107

Choose a reason for hiding this comment

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

metoda do rozdzielenia na w private metody


public List<Comment> getComments(){

Choose a reason for hiding this comment

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

gettery i settery zebrałbym w jednym miejscu, a nie rozrzucone pomiędzy innymi metodami

return this.comments;
}

public boolean hasConversation() {
sourceFile.markConversation(this);
return getComments().size() > TWO;
}
}