Add decimal point to stats

This commit is contained in:
Jesper 2022-01-03 13:52:19 +01:00
parent 9361d64931
commit ce5baf19e2

View File

@ -18,6 +18,8 @@ import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.DecimalFormat;
import java.util.regex.Pattern;
public class DisplayMessageActivity extends AppCompatActivity {
@ -134,10 +136,10 @@ public class DisplayMessageActivity extends AppCompatActivity {
try{
//Create a JSON object containing information from the API.
JSONObject myJsonObject = new JSONObject(response);
textViewDislikes.setText(myJsonObject.getString("dislikes") + " \uD83D\uDC4E");
textViewLikes.setText(myJsonObject.getString("likes") + " \uD83D\uDC4D");
textViewDislikes.setText(AddComma(myJsonObject.getString("dislikes")) + " \uD83D\uDC4E");
textViewLikes.setText(AddComma(myJsonObject.getString("likes")) + " \uD83D\uDC4D");
textViewRatio.setText(myJsonObject.getString("rating").substring(0, 3) + " / 5 ⭐");
textViewViews.setText(myJsonObject.getString("viewCount") + " \uD83D\uDC41");
textViewViews.setText(AddComma(myJsonObject.getString("viewCount")) + " \uD83D\uDC41");
textViewVideoLink.setText(YouTubeLink + " \uD83D\uDD17");
} catch (JSONException e) {
e.printStackTrace();
@ -151,6 +153,14 @@ public class DisplayMessageActivity extends AppCompatActivity {
return "";
}
public String AddComma(String number)
{
double parsedNumber = Double.parseDouble(number);
DecimalFormat formatter = new DecimalFormat("#,###");
number = formatter.format(parsedNumber);
return number;
}
public void ClickReturnYouTubeDislikeLink(View view)
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://returnyoutubedislike.com/"));