Skip to content

Commit

Permalink
Merge pull request #88 from chrqls/dev
Browse files Browse the repository at this point in the history
[#60] Last questions can be deleted and questions can only be deleted during START_MAKE
  • Loading branch information
Charles Quelos committed Dec 17, 2013
2 parents a594af2 + eae7e02 commit 1b5184a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/smilec/smile/ui/GeneralActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public class GeneralActivity extends FragmentActivity {

private String ip;
private String hours, minutes, seconds;
private String status;

private static String status;
public static String getStatus() { return status; }

private Button btSolve, btResults;

Expand Down Expand Up @@ -563,6 +565,8 @@ public void onClick(View v) {
private void startSolvingQuestion() {
ActivityUtil.showLongToast(GeneralActivity.this, R.string.solving);

status = CurrentMessageStatus.START_SOLVE.name();

btResults.setEnabled(true);

solve = false;
Expand Down
52 changes: 36 additions & 16 deletions src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
**/
package org.smilec.smile.ui.adapter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

import org.smilec.smile.R;
import org.smilec.smile.bu.Constants;
import org.smilec.smile.bu.SmilePlugServerManager;
import org.smilec.smile.domain.CurrentMessageStatus;
import org.smilec.smile.domain.Question;
import org.smilec.smile.domain.Results;
import org.smilec.smile.ui.GeneralActivity;
Expand All @@ -30,6 +36,7 @@
import org.smilec.smile.util.ImageLoader;

import android.accounts.NetworkErrorException;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
Expand Down Expand Up @@ -105,14 +112,9 @@ public View getView(int position, View convertView, ViewGroup parent) {

ImageView ivDetails = (ImageView) convertView.findViewById(R.id.iv_details);
ivDetails.setOnClickListener(new OpenItemDetailsListener(question));
System.out.println("----> Nexus 7 | ImageView");

} else {

Button ivDetails = (Button) convertView.findViewById(R.id.iv_details);
ivDetails.setOnClickListener(new OpenItemDetailsListener(question));

System.out.println("----> VisioTab1001 | Button");
}

final RatingBar rbRatingBar = (RatingBar) convertView.findViewById(R.id.rb_ratingbar);
Expand Down Expand Up @@ -158,12 +160,16 @@ private void loadDetails(final Dialog detailsDialog, Question question) {
ImageButton btBack = (ImageButton) detailsDialog.findViewById(R.id.bt_back);
ImageButton btTrash = (ImageButton) detailsDialog.findViewById(R.id.bt_trash);

currentQuestion = question.getNumber();
// note: first question equal to '1'
currentQuestion = question.getNumber()-1;

btClose.setOnClickListener(new CloseClickListenerUtil(detailsDialog));
btBack.setOnClickListener(new CloseClickListenerUtil(detailsDialog));

// If the user click on the trash icon
// If the user click on the trash icon
if(!GeneralActivity.getStatus().equals(CurrentMessageStatus.START_MAKE.name())) {
btTrash.setVisibility(View.INVISIBLE);
}
btTrash.setOnClickListener(new Button.OnClickListener() {

@Override
Expand All @@ -186,23 +192,37 @@ public void onClick(View v) {
public void onClick(View v) {

try {
// note: first question equal to '1'
new SmilePlugServerManager().deleteQuestionInSessionByNumber(ip, context, currentQuestion-1);

new SmilePlugServerManager().deleteQuestionInSessionByNumber(ip, context, currentQuestion);
} catch (NetworkErrorException e) {
e.printStackTrace();
}

Toast.makeText(
context, "Trying to delete question #"+currentQuestion, Toast.LENGTH_LONG
).show();
Toast.makeText(context, "Deleting...", Toast.LENGTH_LONG).show();

confirmDialog.dismiss();
detailsDialog.dismiss();

// TEMP CODE
QuestionsFragment.idQuestionsDeleted.add(currentQuestion-1);
// END TEMP CODE
};
// TODO #60: Adding a question to filter the questions
QuestionsFragment.idQuestionsDeleted.add(currentQuestion);

// final String filter = new String(currentQuestion+";");
// FileOutputStream fOut = null;
//
// try {
// fOut = context.openFileOutput("filter_delete", Context.MODE_PRIVATE);
// OutputStreamWriter osw = new OutputStreamWriter(fOut);
//
// // Write the string to the file and ensure that everything is really written out and close
// osw.write(filter);
// osw.close();
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// END
};
});
}
});
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,33 +250,25 @@ public void updateFragment(final Board board) {
synchronized(mQuestionsMutex) {
questionsOld.addAll(mQuestions);



mQuestions.clear();

if (mRun) {
Collection<Question> newQuestions = null;
newQuestions = board.getQuestions();
List<Question> newQuestions = null;
newQuestions = (List<Question>) board.getQuestions();

// TEMP code #60

// TEMP #60
if(!idQuestionsDeleted.isEmpty()) {

for(int i=0; i<idQuestionsDeleted.size(); i++) {

if(!questionsOld.isEmpty()) {


questionsDeleted.add(questionsOld.get(idQuestionsDeleted.get(i)));
idQuestionsDeleted.remove(i);
if(!newQuestions.isEmpty()) {
questionsDeleted.add(newQuestions.get(idQuestionsDeleted.get(i)));
idQuestionsDeleted.remove(i);
}
}
}

for(int i=0; i<questionsDeleted.size(); i++) {

if(newQuestions.contains(questionsDeleted.get(i))) {

newQuestions.remove(questionsDeleted.get(i));
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/smilec/smile/util/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public static final InputStream executePut(String url, String json)
return executeMethod(put);
}

public static final InputStream executeDelete(String url)
throws NetworkErrorException, UnsupportedEncodingException, JSONException {
public static final InputStream executeDelete(String url) throws NetworkErrorException, UnsupportedEncodingException, JSONException {

HttpDelete delete = new HttpDelete(url);
delete.setHeader("Content-Type", SmilePlugUtil.JSON);
Expand Down

0 comments on commit 1b5184a

Please sign in to comment.