From 676692fffba5fc820438f3ef79f6dc1fdd432b6f Mon Sep 17 00:00:00 2001 From: jaco Date: Sun, 29 Jan 2023 19:14:54 -0300 Subject: [PATCH] feat(stars): stars added to level, WIP end level --- .../activities/MenuMetroActivity.java | 13 ++++++ .../MenuMetroRecyclerViewAdapter.java | 13 +++++- .../metrometro/model/MetroMenu.java | 6 +++ .../main/res/layout/activity_menu_metro.xml | 46 ++++++++++++++++--- app/src/main/res/layout/menu_row.xml | 15 ++++++ 5 files changed, 86 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroActivity.java b/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroActivity.java index 816f028..b4ea4b3 100644 --- a/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroActivity.java +++ b/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroActivity.java @@ -4,9 +4,13 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import android.annotation.SuppressLint; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.util.Log; import android.view.View; +import android.widget.TextView; import com.jorgecruces.metrometro.R; import com.jorgecruces.metrometro.logic.MetroReaderXML; @@ -20,12 +24,15 @@ public class MenuMetroActivity extends AppCompatActivity { ArrayList metroMenu; private Metro metro; + private TextView scoreStarView; + @SuppressLint("MissingInflatedId") @Override protected void onCreate(Bundle savedInstanceState) { metroMenu = new ArrayList<>(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu_metro); + scoreStarView = findViewById(R.id.scoreStarView); this.initializeMetroMenuData(); @@ -42,8 +49,14 @@ public void initializeMetroMenuData() { ArrayList lines = metro.getLines(); for (Line line : lines ) { MetroMenu item = new MetroMenu(line.getName(),line.getColor()); + item.setLevelStar(true); metroMenu.add(item); } + // Score Star + SharedPreferences settings = getApplicationContext().getSharedPreferences("METRO", 0); + int scoreStar = settings.getInt("score", 0); + String scoreString = Integer.toString(scoreStar); + this.scoreStarView.setText(scoreString); } public void goBackMainActivity(View view) { diff --git a/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroRecyclerViewAdapter.java b/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroRecyclerViewAdapter.java index 05e79a3..6145782 100644 --- a/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroRecyclerViewAdapter.java +++ b/app/src/main/java/com/jorgecruces/metrometro/activities/MenuMetroRecyclerViewAdapter.java @@ -3,8 +3,10 @@ import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Color; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -53,6 +55,14 @@ public void onBindViewHolder(@NonNull MenuMetroRecyclerViewAdapter.MyViewHolder intent.putExtra("LINEA", lineaName); this.context.startActivity(intent); }); + + // Star Level + SharedPreferences settings = this.context.getSharedPreferences("METRO",0); + boolean starLevel = settings.getBoolean(lineaName,false); + if (starLevel) { + holder.starView.setImageResource(R.drawable.ic_mediamodifier_design_2_); + } + } @Override @@ -63,13 +73,14 @@ public int getItemCount() { public static class MyViewHolder extends RecyclerView.ViewHolder { // On createMethod TextView lineaMetroName; - ImageView backgroundMetroMenu; + ImageView backgroundMetroMenu, starView; CardView cardView; public MyViewHolder(@NonNull View itemView) { super(itemView); lineaMetroName = itemView.findViewById(R.id.lineaName); backgroundMetroMenu = itemView.findViewById(R.id.backgroundMetroMenu); cardView = itemView.findViewById(R.id.cardViewMenu); + starView = itemView.findViewById(R.id.starView); } } } diff --git a/app/src/main/java/com/jorgecruces/metrometro/model/MetroMenu.java b/app/src/main/java/com/jorgecruces/metrometro/model/MetroMenu.java index 7798174..0a0bf71 100644 --- a/app/src/main/java/com/jorgecruces/metrometro/model/MetroMenu.java +++ b/app/src/main/java/com/jorgecruces/metrometro/model/MetroMenu.java @@ -4,6 +4,8 @@ public class MetroMenu { private String metroName; private String color; + private boolean levelStar; + public MetroMenu(String metroName, String color) { this.metroName = metroName; this.color = color; @@ -13,6 +15,10 @@ public String getMetroName() { return metroName; } + public void setLevelStar(boolean levelStar) { + this.levelStar = levelStar; + } + public String getColor() { return color; } diff --git a/app/src/main/res/layout/activity_menu_metro.xml b/app/src/main/res/layout/activity_menu_metro.xml index cbd845e..5bda588 100644 --- a/app/src/main/res/layout/activity_menu_metro.xml +++ b/app/src/main/res/layout/activity_menu_metro.xml @@ -8,8 +8,8 @@ + app:layout_constraintTop_toBottomOf="@+id/textViewAlternative2"> @@ -37,11 +37,45 @@ android:id="@+id/textViewAlternative2" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="16dp" + android:layout_marginTop="24dp" + android:layout_marginEnd="16dp" android:fontFamily="sans-serif-light" android:text="Lineas Metro" - android:textSize="34sp" + android:textSize="36sp" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.414" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/menu_row.xml b/app/src/main/res/layout/menu_row.xml index 9e96aff..d56bb6e 100644 --- a/app/src/main/res/layout/menu_row.xml +++ b/app/src/main/res/layout/menu_row.xml @@ -1,6 +1,7 @@ @@ -68,6 +69,20 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> + +