2021-05-08 14:58:18 -06:00
|
|
|
package me.brysonsteck.wiimmfiwatcher;
|
2021-04-30 13:40:14 -06:00
|
|
|
|
2021-05-05 00:01:19 -06:00
|
|
|
import android.content.Context;
|
2021-05-04 23:31:34 -06:00
|
|
|
import android.content.Intent;
|
2021-05-04 17:59:55 -06:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.databinding.ObservableArrayList;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2021-05-04 23:31:34 -06:00
|
|
|
import com.google.android.material.button.MaterialButton;
|
2021-05-04 17:59:55 -06:00
|
|
|
|
2021-05-08 18:01:47 -06:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2021-05-08 14:58:18 -06:00
|
|
|
import me.brysonsteck.wiimmfiwatcher.model.FriendCode;
|
|
|
|
import me.brysonsteck.wiimmfiwatcher.wiimmfi.WiimmfiActivity;
|
|
|
|
|
2021-05-04 23:31:34 -06:00
|
|
|
public class WatchCodeAdapter extends RecyclerView.Adapter<WatchCodeAdapter.ViewHolder>{
|
2021-05-04 17:59:55 -06:00
|
|
|
ObservableArrayList<FriendCode> entries;
|
2021-05-05 00:01:19 -06:00
|
|
|
Context context;
|
2021-05-08 18:01:47 -06:00
|
|
|
ArrayList<String> recentCodes;
|
2021-05-04 17:59:55 -06:00
|
|
|
|
2021-05-05 00:01:19 -06:00
|
|
|
public WatchCodeAdapter(Context context, ObservableArrayList<FriendCode> entries) {
|
|
|
|
this.context = context;
|
2021-05-04 17:59:55 -06:00
|
|
|
this.entries = entries;
|
2021-05-08 18:01:47 -06:00
|
|
|
this.recentCodes = new ArrayList<>();
|
2021-05-04 17:59:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
2021-05-04 20:18:17 -06:00
|
|
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2021-05-04 17:59:55 -06:00
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recent_friend_codes_item, parent, false);
|
2021-05-04 20:18:17 -06:00
|
|
|
return new ViewHolder(view);
|
2021-05-04 17:59:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-04 20:18:17 -06:00
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
2021-05-08 18:01:47 -06:00
|
|
|
String currentFC = entries.get(position).friendCode;
|
2021-05-04 23:31:34 -06:00
|
|
|
MaterialButton fcButton = holder.itemView.findViewById(R.id.recent_friend_code_button);
|
2021-05-08 18:01:47 -06:00
|
|
|
fcButton.setText(currentFC);
|
2021-05-04 17:59:55 -06:00
|
|
|
fcButton.setOnClickListener(view -> {
|
2021-05-08 18:01:47 -06:00
|
|
|
Intent intent = new Intent(view.getContext(), WiimmfiActivity.class);
|
|
|
|
intent.putExtra("friendCode", currentFC);
|
|
|
|
context.startActivity(intent);
|
2021-05-04 17:59:55 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-08 18:01:47 -06:00
|
|
|
|
2021-05-04 17:59:55 -06:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return entries.size();
|
|
|
|
}
|
2021-05-04 20:18:17 -06:00
|
|
|
|
2021-05-04 17:59:55 -06:00
|
|
|
class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
public ViewHolder(@NonNull View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
}
|
|
|
|
}
|
2021-04-30 13:40:14 -06:00
|
|
|
}
|