Skip to content

Commit

Permalink
feat(stars): stars added to level, WIP end level
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrucesdeveloper committed Jan 29, 2023
1 parent ba23ed5 commit 676692f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,12 +24,15 @@ public class MenuMetroActivity extends AppCompatActivity {

ArrayList<MetroMenu> 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();

Expand All @@ -42,8 +49,14 @@ public void initializeMetroMenuData() {
ArrayList<Line> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +15,10 @@ public String getMetroName() {
return metroName;
}

public void setLevelStar(boolean levelStar) {
this.levelStar = levelStar;
}

public String getColor() {
return color;
}
Expand Down
46 changes: 40 additions & 6 deletions app/src/main/res/layout/activity_menu_metro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ImageView
android:id="@+id/imageView"
android:layout_width="64dp"
android:layout_height="55dp"
android:layout_width="63dp"
android:layout_height="58dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="42dp"
Expand All @@ -25,23 +25,57 @@
android:id="@+id/menuMetroRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewAlternative2" >
app:layout_constraintTop_toBottomOf="@+id/textViewAlternative2">

</androidx.recyclerview.widget.RecyclerView>

<TextView
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" />

<TextView
android:id="@+id/scoreStarView"
android:layout_width="35dp"
android:layout_height="49dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="27dp"
android:fontFamily="sans-serif-light"
android:text="0"
android:textAlignment="center"
android:textSize="38sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/menuMetroRecyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView3"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="63dp"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/menuMetroRecyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toEndOf="@+id/textViewAlternative2"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/btn_star_big_on" />
</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 15 additions & 0 deletions app/src/main/res/layout/menu_row.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down Expand Up @@ -68,6 +69,20 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/starView"
android:layout_width="54dp"
android:layout_height="55dp"
android:layout_marginStart="16dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/lineaName"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/btn_star" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

Expand Down

0 comments on commit 676692f

Please sign in to comment.