Пример #1
0
        @Override
        public void onProgressUpdate(DeckTask.TaskData... values) {
          mAllCards.clear();
          ArrayList<String[]> allCards = values[0].getAllCards();
          if (allCards == null) {
            Resources res = getResources();
            StyledDialog.Builder builder = new StyledDialog.Builder(CardBrowser.this);
            builder.setTitle(res.getString(R.string.error));
            builder.setIcon(android.R.drawable.ic_dialog_alert);
            builder.setMessage(res.getString(R.string.card_browser_cardloading_error));
            builder.setPositiveButton(
                res.getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    CardBrowser.this.finish();
                  }
                });
            builder.setOnCancelListener(
                new OnCancelListener() {
                  @Override
                  public void onCancel(DialogInterface dialog) {
                    CardBrowser.this.finish();
                  }
                });
            builder.create().show();
          } else {
            for (String[] item : allCards) {
              // reshape Arabic words
              if (mPrefFixArabic) {
                item[1] = ArabicUtilities.reshapeSentence(item[1]);
                item[2] = ArabicUtilities.reshapeSentence(item[2]);
              }

              HashMap<String, String> data = new HashMap<String, String>();
              data.put("id", item[0]);
              data.put("question", item[1]);
              data.put("answer", item[2]);
              data.put("marSus", item[3]);
              data.put("tags", item[4]);
              mAllCards.add(data);
            }
            updateCardsList();
          }

          // This verification would not be necessary if
          // onConfigurationChanged it's executed correctly (which seems
          // that emulator does not do)
          if (mProgressDialog.isShowing()) {
            try {
              mProgressDialog.dismiss();
            } catch (Exception e) {
              Log.e(
                  AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
            }
          }
        }
Пример #2
0
  private void recreateTagsDialog() {
    Resources res = getResources();
    if (allTags == null) {
      String[] oldTags = AnkiDroidApp.deck().allTags_();
      Log.i(AnkiDroidApp.TAG, "all tags: " + Arrays.toString(oldTags));
      allTags = new String[oldTags.length];
      for (int i = 0; i < oldTags.length; i++) {
        allTags[i] = oldTags[i];
      }
    }
    mSelectedTags.clear();

    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    builder.setTitle(R.string.studyoptions_limit_select_tags);
    builder.setMultiChoiceItems(
        allTags,
        new boolean[0],
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            String tag = allTags[which];
            if (mSelectedTags.contains(tag)) {
              Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
              mSelectedTags.remove(tag);
            } else {
              Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
              mSelectedTags.add(tag);
            }
          }
        });
    builder.setPositiveButton(
        res.getString(R.string.select),
        new OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            updateCardsList();
          }
        });
    builder.setNegativeButton(
        res.getString(R.string.cancel),
        new OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            mSelectedTags.clear();
          }
        });
    builder.setOnCancelListener(
        new OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            mSelectedTags.clear();
          }
        });
    mTagsDialog = builder.create();
  }
Пример #3
0
        @Override
        public void onProgressUpdate(DeckTask.TaskData... values) {
          if (canceled) {
            return;
          }
          ArrayList<HashMap<String, String>> cards = values[0].getCards();
          if (cards == null) {
            Resources res = getResources();
            StyledDialog.Builder builder = new StyledDialog.Builder(CardBrowser.this);
            builder.setTitle(res.getString(R.string.error));
            builder.setIcon(android.R.drawable.ic_dialog_alert);
            builder.setMessage(res.getString(R.string.card_browser_cardloading_error));
            builder.setPositiveButton(
                res.getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    closeCardBrowser();
                  }
                });
            builder.setOnCancelListener(
                new OnCancelListener() {
                  @Override
                  public void onCancel(DialogInterface dialog) {
                    closeCardBrowser();
                  }
                });
            builder.create().show();
          } else {
            if (mPrefFixArabic) {
              for (HashMap<String, String> entry : cards) {
                entry.put("sfld", ArabicUtilities.reshapeSentence(entry.get("sfld")));
              }
            }
            try {

              int field =
                  AnkiDroidApp.getSharedPrefs(getBaseContext()).getInt("cardBrowserField", 0);

              Card tempCard =
                  mCol.getCard(
                      Long.parseLong(
                          cards.get(0).get("id"))); // Long.parseLong(mCards.get(0).get("id"))

              ArrayList<String> uniqueFields = new ArrayList<String>();

              if (field > 0 && (mFields != null)) {
                for (HashMap<String, String> entry : cards) {
                  tempCard = mCol.getCard(Long.parseLong(entry.get("id")));
                  String item = tempCard.note().getitem(mFields[field]);
                  entry.put("sfld", item);

                  if (!uniqueFields.contains(item)) {
                    uniqueFields.add(item);
                    mAllCards.add(entry);
                    mCards.add(entry);
                  }
                }
              } else {
                mAllCards.addAll(cards);
                mCards.addAll(cards);
              }

              if (mOrder == CARD_ORDER_NONE) {
                updateCardsList();
                mProgressDialog.dismiss();
              } else {
                DeckTask.launchDeckTask(
                    DeckTask.TASK_TYPE_UPDATE_CARD_BROWSER_LIST,
                    mSortCardsHandler,
                    new DeckTask.TaskData(mAllCards, new HashMapCompare()));
              }
            } catch (OutOfMemoryError e) {
              Log.e(AnkiDroidApp.TAG, "CardBrowser: mLoadCardsHandler: OutOfMemoryError: " + e);
              Themes.showThemedToast(
                  CardBrowser.this,
                  getResources().getString(R.string.error_insufficient_memory),
                  false);
              closeCardBrowser();
            }
          }
        }
Пример #4
0
  @Override
  protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
      case DIALOG_ORDER:
        builder.setTitle(res.getString(R.string.card_browser_change_display_order_title));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
        builder.setSingleChoiceItems(
            getResources().getStringArray(R.array.card_browser_order_labels),
            mOrder,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface arg0, int which) {
                if (which != mOrder) {
                  mOrder = which;
                  AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext())
                      .edit()
                      .putInt("cardBrowserOrder", mOrder)
                      .commit();
                  if (mOrder != CARD_ORDER_NONE) {
                    DeckTask.launchDeckTask(
                        DeckTask.TASK_TYPE_UPDATE_CARD_BROWSER_LIST,
                        mSortCardsHandler,
                        new DeckTask.TaskData(mAllCards, new HashMapCompare()));
                  }
                }
              }
            });
        dialog = builder.create();
        break;

      case DIALOG_CONTEXT_MENU:
        String[] entries = new String[4];
        @SuppressWarnings("unused")
        MenuItem item;
        entries[CONTEXT_MENU_MARK] = res.getString(R.string.card_browser_mark_card);
        entries[CONTEXT_MENU_SUSPEND] = res.getString(R.string.card_browser_suspend_card);
        entries[CONTEXT_MENU_DELETE] = res.getString(R.string.card_browser_delete_card);
        entries[CONTEXT_MENU_DETAILS] = res.getString(R.string.card_browser_card_details);
        builder.setTitle("contextmenu");
        builder.setIcon(R.drawable.ic_menu_manage);
        builder.setItems(entries, mContextMenuListener);
        dialog = builder.create();
        break;

      case DIALOG_TAGS:
        allTags = mCol.getTags().all();
        builder.setTitle(R.string.studyoptions_limit_select_tags);
        builder.setMultiChoiceItems(
            allTags,
            new boolean[allTags.length],
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                String tag = allTags[which];
                if (mSelectedTags.contains(tag)) {
                  Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
                  mSelectedTags.remove(tag);
                } else {
                  Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
                  mSelectedTags.add(tag);
                }
              }
            });
        builder.setPositiveButton(
            res.getString(R.string.select),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                mSearchEditText.setText("");
                mTimerHandler.removeCallbacks(updateList);
                String tags = mSelectedTags.toString();
                mSearchEditText.setHint(
                    getResources()
                        .getString(
                            R.string.card_browser_tags_shown,
                            tags.substring(1, tags.length() - 1)));
                DeckTask.launchDeckTask(
                    DeckTask.TASK_TYPE_UPDATE_CARD_BROWSER_LIST,
                    new DeckTask.TaskListener() {
                      @Override
                      public void onPreExecute() {
                        mProgressDialog =
                            StyledProgressDialog.show(
                                CardBrowser.this,
                                "",
                                getResources().getString(R.string.card_browser_filtering_cards),
                                true);
                      }

                      @Override
                      public void onProgressUpdate(DeckTask.TaskData... values) {}

                      @Override
                      public void onPostExecute(DeckTask.TaskData result) {
                        updateList();
                        if (mProgressDialog != null && mProgressDialog.isShowing()) {
                          mProgressDialog.dismiss();
                        }
                      }
                    },
                    new DeckTask.TaskData(mAllCards),
                    new DeckTask.TaskData(mCards),
                    new DeckTask.TaskData(new Object[] {mSelectedTags}));
              }
            });
        builder.setNegativeButton(
            res.getString(R.string.cancel),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                mSelectedTags.clear();
              }
            });
        builder.setOnCancelListener(
            new OnCancelListener() {

              @Override
              public void onCancel(DialogInterface dialog) {
                mSelectedTags.clear();
              }
            });
        dialog = builder.create();
        break;
        //		case DIALOG_RELOAD_CARDS:
        //			builder.setTitle(res.getString(R.string.pref_cache_cardbrowser));
        //			builder.setMessage(res.getString(R.string.pref_cache_cardbrowser_reload));
        //			builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() {
        //
        //				@Override
        //				public void onClick(DialogInterface arg0, int arg1) {
        //					DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_CARDS,
        //							mLoadCardsHandler,
        //							new DeckTask.TaskData(mDeck, LOAD_CHUNK));
        //					}
        //
        //			});
        //			builder.setNegativeButton(res.getString(R.string.no), new OnClickListener() {
        //
        //				@Override
        //				public void onClick(DialogInterface arg0, int arg1) {
        //					mAllCards.addAll(sAllCardsCache);
        //					mCards.addAll(mAllCards);
        //					updateList();
        //				}
        //
        //			});
        //			builder.setCancelable(true);
        //			builder.setOnCancelListener(new OnCancelListener() {
        //
        //				@Override
        //				public void onCancel(DialogInterface arg0) {
        //					mAllCards.addAll(sAllCardsCache);
        //					mCards.addAll(mAllCards);
        //					updateList();
        //				}
        //
        //			});
        //			dialog = builder.create();
        //			break;
      case DIALOG_FIELD:
        builder.setTitle(res.getString(R.string.card_browser_field_title));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);

        HashMap<String, String> card = mAllCards.get(0);

        String[][] items = mCol.getCard(Long.parseLong(card.get("id"))).note().items();

        mFields = new String[items.length + 1];
        mFields[0] = "SFLD";

        for (int i = 0; i < items.length; i++) {
          mFields[i + 1] = items[i][0];
        }

        builder.setSingleChoiceItems(
            mFields,
            0,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface arg0, int which) {
                if (which != mField) {
                  mField = which;
                  AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext())
                      .edit()
                      .putInt("cardBrowserField", mField)
                      .commit();
                  getCards();
                }
              }
            });
        dialog = builder.create();
        break;
    }
    return dialog;
  }