From 9a80a3ee555b0aca975e1633c57b609a47a44354 Mon Sep 17 00:00:00 2001 From: chrqls Date: Tue, 17 Dec 2013 02:53:03 -0800 Subject: [PATCH 1/2] [#60] We can delete last question now --- .../smile/ui/adapter/QuestionListAdapter.java | 44 +++++++++++++------ .../smile/ui/fragment/QuestionsFragment.java | 20 +++------ .../java/org/smilec/smile/util/HttpUtil.java | 3 +- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java index 5e7faa9..023b42c 100644 --- a/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java +++ b/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java @@ -15,6 +15,11 @@ **/ 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; @@ -30,6 +35,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; @@ -105,14 +111,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); @@ -158,12 +159,13 @@ 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 btTrash.setOnClickListener(new Button.OnClickListener() { @Override @@ -186,8 +188,8 @@ 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(); } @@ -199,10 +201,26 @@ public void onClick(View v) { 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 + }; }); } }); diff --git a/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java b/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java index e67ffa0..4c57ca7 100644 --- a/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java +++ b/src/main/java/org/smilec/smile/ui/fragment/QuestionsFragment.java @@ -250,33 +250,25 @@ public void updateFragment(final Board board) { synchronized(mQuestionsMutex) { questionsOld.addAll(mQuestions); - - mQuestions.clear(); if (mRun) { - Collection newQuestions = null; - newQuestions = board.getQuestions(); + List newQuestions = null; + newQuestions = (List) board.getQuestions(); - // TEMP code #60 - + // TEMP #60 if(!idQuestionsDeleted.isEmpty()) { for(int i=0; i Date: Tue, 17 Dec 2013 03:39:55 -0800 Subject: [PATCH 2/2] [#60] Deleting questions only during START_MAKE --- src/main/java/org/smilec/smile/ui/GeneralActivity.java | 6 +++++- .../org/smilec/smile/ui/adapter/QuestionListAdapter.java | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/smilec/smile/ui/GeneralActivity.java b/src/main/java/org/smilec/smile/ui/GeneralActivity.java index 943bcd0..0649890 100644 --- a/src/main/java/org/smilec/smile/ui/GeneralActivity.java +++ b/src/main/java/org/smilec/smile/ui/GeneralActivity.java @@ -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; @@ -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; diff --git a/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java b/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java index 023b42c..5674388 100644 --- a/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java +++ b/src/main/java/org/smilec/smile/ui/adapter/QuestionListAdapter.java @@ -25,6 +25,7 @@ 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; @@ -166,6 +167,9 @@ private void loadDetails(final Dialog detailsDialog, Question question) { btBack.setOnClickListener(new CloseClickListenerUtil(detailsDialog)); // 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 @@ -194,9 +198,7 @@ public void onClick(View v) { 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();