Adds significant adapter resources.

This commit is contained in:
jahorton 2019-05-30 10:01:25 +07:00
parent 5841171681
commit 916ba3fd3e
7 changed files with 81 additions and 8 deletions

View file

@ -15,13 +15,13 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import com.tavultesoft.kmea.data.Keyboard;
import com.tavultesoft.kmea.data.adapters.KeyboardsAdapter;
final class KMKeyboardPickerAdapter extends KeyboardsAdapter implements OnClickListener {
final class KMKeyboardPickerAdapter extends ArrayAdapter<Keyboard> implements OnClickListener {
private final static int KEYBOARD_LAYOUT_RESOURCE = R.layout.list_row_layout3;
private Context context;
@ -36,9 +36,9 @@ final class KMKeyboardPickerAdapter extends KeyboardsAdapter implements OnClickL
return kbdData;
}
// TODO: End goal: take in a KeyboardAdapter instead of this list; reference that as needed.
public KMKeyboardPickerAdapter(Context context, List<? extends Map<String, String>> data) {
super(context, KEYBOARD_LAYOUT_RESOURCE, mapCast(data));
this.context = context;
}
@Override

View file

@ -26,6 +26,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.tavultesoft.kmea.data.adapters.LexicalModelAdapter;
import com.tavultesoft.kmea.packages.JSONUtils;
import com.tavultesoft.kmea.packages.LexicalModelPackageProcessor;
import com.tavultesoft.kmea.packages.PackageProcessor;

View file

@ -7,11 +7,11 @@ import androidx.annotation.NonNull;
import java.util.List;
public class RepositoryDataset extends ArrayAdapter<LanguageDataset> {
public class Dataset extends ArrayAdapter<LanguageDataset> {
// Stores internal adapters for keyboard, lexical model listings
// 'Items' are language-specific datasets holding their own language-specific adapters.
public RepositoryDataset(@NonNull Context context, int resource, @NonNull List<LanguageDataset> objects) {
private Dataset(@NonNull Context context, int resource, @NonNull List<LanguageDataset> objects) {
super(context, resource, objects);
}
}

View file

@ -0,0 +1,23 @@
package com.tavultesoft.kmea.data;
import java.util.Map;
public class LexicalModel {
public final Map<String, String> map;
/* TODO: (v13 refactor)
* Drop the HashMap and instead directly represent the following as object properties:
*
* hashMap.put(KMManager.KMKey_PackageID, packageID);
* hashMap.put(KMManager.KMKey_LanguageID, languageID);
* hashMap.put(KMManager.KMKey_LexicalModelID, modelID);
* hashMap.put(KMManager.KMKey_LexicalModelName, modelName);
* hashMap.put(KMManager.KMKey_LanguageName, langName);
* hashMap.put(KMManager.KMKey_LexicalModelVersion, modelVersion);
* hashMap.put(KMManager.KMKey_CustomModel, isCustom);
*/
public LexicalModel(Map<String, String> modelData) {
this.map = modelData;
}
}

View file

@ -7,14 +7,25 @@ import androidx.annotation.NonNull;
import com.tavultesoft.kmea.data.Keyboard;
import java.util.Collections;
import java.util.List;
public class KeyboardsAdapter extends ArrayAdapter<Keyboard> {
public class KeyboardsAdapter extends ArrayAdapter<Keyboard> implements ListBacked<Keyboard> {
private final List<Keyboard> data;
public KeyboardsAdapter(@NonNull Context context, int resource, @NonNull List<Keyboard> data) {
super(context, resource, data);
// We do NOT save a reference to the data; it should always be accessed
// through ArrayAdapter methods.
// We only want to allow mutations through the adapter, but it's useful to maintain
// a List<> version of the data to assist with other adapters.
this.data = Collections.unmodifiableList(data);
}
public List<Keyboard> asList() {
return this.data;
}
// getView should be overridden by child instances.
// - repository dataset
// - local dataset
}

View file

@ -0,0 +1,31 @@
package com.tavultesoft.kmea.data.adapters;
import android.content.Context;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import com.tavultesoft.kmea.data.LexicalModel;
import java.util.Collections;
import java.util.List;
public class LexicalModelAdapter extends ArrayAdapter<LexicalModel> implements ListBacked<LexicalModel> {
private final List<LexicalModel> data;
public LexicalModelAdapter(@NonNull Context context, int resource, @NonNull List<LexicalModel> data) {
super(context, resource, data);
// We only want to allow mutations through the adapter, but it's useful to maintain
// a List<> version of the data to assist with other adapters.
this.data = Collections.unmodifiableList(data);
}
public List<LexicalModel> asList() {
return this.data;
}
// getView should be overridden by child instances.
// - repository dataset
// - local dataset
}

View file

@ -0,0 +1,7 @@
package com.tavultesoft.kmea.data.adapters;
import java.util.List;
public interface ListBacked<T> {
List<T> asList();
}