diff options
author | Bryson Steck <steck.bryson@gmail.com> | 2021-06-28 23:11:38 -0600 |
---|---|---|
committer | Bryson Steck <steck.bryson@gmail.com> | 2021-06-28 23:11:38 -0600 |
commit | 1643931494c2b9411a05fdefe8c03416fe072142 (patch) | |
tree | aa630be5609065b17b3bcaea0069c11972a49fbc /app/src/main/java/me/brysonsteck/wiimmfiwatcher/fragments/WatchCodeAdapter.java | |
parent | 3c2a356b1a57cdc3c9264a0bab6d4e6c6bb265e1 (diff) | |
parent | 3c10ea67a3dab3d221e609d8dc6bc0df145f1220 (diff) | |
download | wiimmfi-watcher-1.1.4.tar wiimmfi-watcher-1.1.4.tar.gz wiimmfi-watcher-1.1.4.tar.bz2 |
released 1.1.41.1.4
Diffstat (limited to 'app/src/main/java/me/brysonsteck/wiimmfiwatcher/fragments/WatchCodeAdapter.java')
-rw-r--r-- | app/src/main/java/me/brysonsteck/wiimmfiwatcher/fragments/WatchCodeAdapter.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/fragments/WatchCodeAdapter.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/fragments/WatchCodeAdapter.java new file mode 100644 index 0000000..400436b --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/fragments/WatchCodeAdapter.java @@ -0,0 +1,85 @@ +package me.brysonsteck.wiimmfiwatcher.fragments; + +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.content.res.Configuration; +import android.graphics.Color; +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; + +import com.google.android.material.button.MaterialButton; +import com.google.android.material.textview.MaterialTextView; + +import java.util.ArrayList; + +import me.brysonsteck.wiimmfiwatcher.R; +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; +import me.brysonsteck.wiimmfiwatcher.wiimmfi.WiimmfiActivity; + +public class WatchCodeAdapter extends RecyclerView.Adapter<WatchCodeAdapter.ViewHolder>{ + ObservableArrayList<FriendCode> entries; + Context context; + MaterialTextView errorText; + ProgressDialog progressBar; + ArrayList<String> recentCodes; + + public WatchCodeAdapter(Context context, ObservableArrayList<FriendCode> entries, + MaterialTextView errorText, ProgressDialog progressBar) { + this.context = context; + this.entries = entries; + this.errorText = errorText; + this.progressBar = progressBar; + this.recentCodes = new ArrayList<>(); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recent_friend_codes_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + String currentFC = entries.get(position).friendCode; + MaterialButton fcButton = holder.itemView.findViewById(R.id.recent_friend_code_button); + int nightModeFlags = + context.getResources().getConfiguration().uiMode & + Configuration.UI_MODE_NIGHT_MASK; + if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) { + // Night mode is active, we're using dark theme + fcButton.setBackgroundColor(Color.parseColor("#313131")); + } + fcButton.setText(currentFC); + fcButton.setOnClickListener(view -> { + progressBar.setCancelable(true); + progressBar.setMessage(holder.itemView.getResources().getString(R.string.locating_text, currentFC)); + progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER); + progressBar.setProgress(0); + progressBar.setMax(100); + progressBar.show(); + errorText.setText(""); + Intent intent = new Intent(view.getContext(), WiimmfiActivity.class); + intent.putExtra("friendCode", currentFC); + context.startActivity(intent); + }); + } + + + @Override + public int getItemCount() { + return entries.size(); + } + + class ViewHolder extends RecyclerView.ViewHolder { + public ViewHolder(@NonNull View itemView) { + super(itemView); + } + } +} |