Pass dictionary name instead of unstable position in list
app/src/main/java/eu/lepiller/nani/DictionaryActivity.java
54 | 54 | @Override | |
55 | 55 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
56 | 56 | Intent intent = new Intent(DictionaryActivity.this, DictionaryDownloadActivity.class); | |
57 | - | intent.putExtra("dico", position); | |
57 | + | intent.putExtra(DictionaryDownloadActivity.EXTRA_DICTIONARY, DictionaryFactory.get(position).getName()); | |
58 | 58 | startActivityForResult(intent, DICO_REQUEST); | |
59 | 59 | } | |
60 | 60 | }); | |
… | |||
129 | 129 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
130 | 130 | super.onActivityResult(requestCode, resultCode, data); | |
131 | 131 | if (requestCode == DICO_REQUEST) { | |
132 | + | DictionaryFactory.updatePackageList(); | |
132 | 133 | adapter.notifyDataSetChanged(); | |
133 | 134 | } | |
134 | 135 | } |
app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java
34 | 34 | public class DictionaryDownloadActivity extends AppCompatActivity { | |
35 | 35 | final static String TAG = "DWN"; | |
36 | 36 | final static int notificationID = 1111; | |
37 | + | final static String EXTRA_DICTIONARY = "eu.lepiller.nani.extra.DICTIONARY"; | |
37 | 38 | ||
38 | 39 | Dictionary d; | |
39 | 40 | DownloadTask currentDownloadTask = null; | |
… | |||
80 | 81 | setContentView(R.layout.activity_dictionary_download); | |
81 | 82 | Bundle extras = getIntent().getExtras(); | |
82 | 83 | ||
83 | - | // TODO: this will open the first dictionary on error, we probably want to display a proper | |
84 | - | // error instead. | |
85 | - | int position = 0; | |
84 | + | String name = null; | |
86 | 85 | if(extras != null) | |
87 | - | position = extras.getInt("dico"); | |
86 | + | name = extras.getString(EXTRA_DICTIONARY); | |
88 | 87 | ||
89 | - | d = DictionaryFactory.get(position); | |
88 | + | d = DictionaryFactory.getByName(this, name); | |
90 | 89 | ||
91 | 90 | manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); | |
92 | 91 | builder = new NotificationCompat.Builder(DictionaryDownloadActivity.this, "dico_dll") |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
179 | 179 | instance = new DictionaryFactory(context); | |
180 | 180 | } | |
181 | 181 | ||
182 | + | public static Dictionary getByName(Context context, String name) { | |
183 | + | prepare(context); | |
184 | + | ||
185 | + | for(Dictionary d: dictionaries) { | |
186 | + | if (d.getName().equals(name)) | |
187 | + | return d; | |
188 | + | } | |
189 | + | ||
190 | + | return null; | |
191 | + | } | |
192 | + | ||
182 | 193 | public static ArrayList<Result> search(String text) throws DictionaryException { | |
183 | 194 | if(instance == null) | |
184 | 195 | throw new NoDictionaryException(); |