组中m3u上的文件解析器

时间:2018-10-15 15:39:48

标签: java android

我正在从事android studio项目。 我想解析应用程序读取的文件,并按组对数据进行排序。 数据会像这样:

TEAM -- Real Madrid -- Player -- Cristiano Ronaldo -- Position -- Front Player;
TEAM -- Real Madrid -- Player -- Casillas -- Position -- GoalKeeper;
TEAM -- BARÇA -- Player -- Messi -- Position -- Delantero;

我可以解析数据,但是我不知道如何将它们分组在皇马-巴萨,以及在这些分组中的位置,例如前锋球员,守门员,防守球员等。

我的活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
    android:id="@+id/cimg"
    android:layout_width="50sp"
    android:layout_height="50sp"
    android:layout_marginStart="10sp"
    android:contentDescription="@string/browse" />

    <TextView
        android:id="@+id/item_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16sp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="12dp"
        android:lines="1"
        android:paddingStart="60sp"
        android:text="Name"
        android:textColor="#000"
        android:textSize="22sp" />
    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_below="@+id/item_name" />

</RelativeLayout>

我的列表Adpater

public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ItemHolder> implements Filterable {

private final Context mContext;
private final LayoutInflater mInflater;
private List<M3UItem> mItem = new ArrayList<>();
private TextDrawable textDrawable;
private ColorGenerator generator = ColorGenerator.MATERIAL;

public PlaylistAdapter(Context c) {
    mContext = c;
    mInflater = LayoutInflater.from(mContext);
}

@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View sView = mInflater.inflate(R.layout.item_playlist, parent, false);
    return new ItemHolder(sView);
}

@Override
public int getItemViewType(int position) {
    return 0;
}

@Override
public void onBindViewHolder(final ItemHolder holder, final int position) {
    final M3UItem item = mItem.get(position);
    if (item != null) {
        holder.update(item);
    }
}

@Override
public int getItemCount() {
     return mItem.size();
 }

void update(List<M3UItem> _list) {
    this.mItem = _list;
    notifyDataSetChanged();
}

@Override
public Filter getFilter() {
    return new Filter() { //TODO search it on github
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            mItem.clear();
            //mItem.addAll((ArrayList<M3UItem>) results.values);
            notifyDataSetChanged();
        }
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();
            if (!(constraint.length() == 0)){
                mItem.clear();
                final String filtePatt = constraint.toString().toLowerCase().trim();
                for (M3UItem itm: mItem){
                    if (itm.getItemName().toLowerCase().contains(filtePatt)){
                        Toast.makeText(mContext, "Google", Toast.LENGTH_SHORT).show();
                        mItem.add(itm);
                    }
                    mItem.add(itm);
                }
            }
            results.values = mItem;
            results.count = mItem.size();
            return results;
        }
    };
}

public class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    final PackageManager pm = mContext.getPackageManager();
    TextView name;
    ImageView cImg;

    ItemHolder(View view) {
        super(view);
        view.setOnClickListener(this);
        name = view.findViewById(R.id.item_name);
        cImg = view.findViewById(R.id.cimg);
    }

    void update(final M3UItem item) {
        try {
        name.setText(item.getItemName());
            int color = generator.getRandomColor();
            if (item.getItemIcon().isEmpty()) {
                textDrawable = TextDrawable.builder()
                        .buildRoundRect(String.valueOf(item.getItemName().charAt(0)), color, 5);
                cImg.setImageDrawable(textDrawable);
            } else {
                if (Utils.getInstance().isNetworkAvailable(mContext)) {
                    Picasso.with(mContext).load(item.getItemIcon()).into(cImg);
                } else {
                    textDrawable = TextDrawable.builder()
                            .buildRoundRect(String.valueOf(item.getItemName().charAt(0)), color, 100);
                    cImg.setImageDrawable(textDrawable);
                }
            }
        } catch (Exception ignored) {
        }
    }

    public void onClick(View v) {
        try {
            int position = getLayoutPosition();
            final M3UItem imm = mItem.get(position);
            Intent intent = new Intent(mContext, playerExo.class);
            intent.putExtra("Name", imm.getItemName());
            intent.putExtra("Url", imm.getItemUrl());
            Log.e("Google", imm.getItemUrl());
            mContext.startActivity(intent);
        } catch (Exception ignored) {}
    }
}
}

我只想对团队和职位进行分组,但是我不知道是否需要在活动中添加一个按钮并创建一个新活动。 如果您需要更多信息,可以发布更多代码。

0 个答案:

没有答案