]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/QuickDicConfig.java
414ae2ddf88667f04b5ce57f9be8c20965ccf40f
[Dictionary.git] / src / com / hughes / android / dictionary / QuickDicConfig.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary;
16
17 import java.io.Serializable;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import android.os.Environment;
22
23 import com.hughes.android.dictionary.engine.Language;
24
25 public final class QuickDicConfig implements Serializable {
26   
27   private static final long serialVersionUID = 6711617368780900979L;
28   
29   // Just increment this to have them all update...
30   static final int LATEST_VERSION = 6;
31   
32   final List<DictionaryInfo> dictionaryConfigs = new ArrayList<DictionaryInfo>();
33   int currentVersion = LATEST_VERSION;
34   
35   public QuickDicConfig() {
36     addDefaultDictionaries();
37   }
38   
39   static final String BASE_URL = "http://quickdic-dictionary.googlecode.com/files/";
40
41   // TODO: read this from a resource file....
42   
43   public void addDefaultDictionaries() {
44     {
45       final DictionaryInfo config = new DictionaryInfo();
46       config.name = "German-English";
47       config.downloadUrl = String.format("%sDE-EN_chemnitz_enwiktionary.quickdic.%s.zip", BASE_URL, VERSION_SUFFIX);
48       config.localFile = String.format("%s/quickDic/DE-EN_chemnitz_enwiktionary.quickdic", Environment.getExternalStorageDirectory());
49       addOrReplace(config);
50     }
51     
52     for (final String iso : Language.isoCodeToResourceName.keySet()) {
53       if (iso.equals("EN") || iso.equals("DE")) {
54         continue;
55       }
56       final DictionaryInfo config = new DictionaryInfo();
57       config.name = String.format("English-%s", Language.isoCodeToWikiName.get(iso));
58       config.downloadUrl = String.format("%sEN-%s_enwiktionary.quickdic.%s.zip", BASE_URL, iso, VERSION_SUFFIX);
59       config.localFile = String.format("%s/quickDic/EN-%s_enwiktionary.quickdic", Environment.getExternalStorageDirectory(), iso);
60       addOrReplace(config);
61     }
62   }
63
64   private void addOrReplace(final DictionaryInfo dictionaryConfig) {
65     for (int i = 0; i < dictionaryConfigs.size(); ++i) {
66       if (dictionaryConfigs.get(i).name.equals(dictionaryConfig.name)) {
67         dictionaryConfigs.set(i, dictionaryConfig);
68         return;
69       }
70     }
71     dictionaryConfigs.add(dictionaryConfig);
72   }
73
74 }