Skip to content

Commit

Permalink
Title and thumbnail support
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperbakhandskemager committed Jul 14, 2022
1 parent 265dd88 commit 789c7e3
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 12 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.jesperh.showyoutubedislikes"
minSdk 21
targetSdk 32
versionCode 5
versionName "0.4"
versionCode 10
versionName "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -21,6 +21,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -33,6 +34,7 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.android.volley:volley:1.2.0'
implementation 'com.squareup.picasso:picasso:2.8'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 5,
"versionName": "0.4",
"versionCode": 10,
"versionName": "1.0.0",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
package com.jesperh.showyoutubedislikes;

import static android.content.ContentValues.TAG;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.squareup.picasso.Picasso;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;

public class DisplayMessageActivity extends AppCompatActivity {
Expand Down Expand Up @@ -115,6 +130,7 @@ else if (YouTubeLink.contains("youtube.com"))
}

String FINAL_URL = API_BASE_URL + API_GET_VOTES_QUERY + VIDEO_ID;
String oEmbedURL = "https://youtube.com/oembed?format=json&url=" + YouTubeLink;

// Define the text boxes
final TextView textViewDislikes = (TextView) findViewById(R.id.YTDislikes);
Expand All @@ -123,6 +139,9 @@ else if (YouTubeLink.contains("youtube.com"))
final TextView textViewVideoLink = (TextView) findViewById(R.id.YTVideoLink);
final TextView textViewRatio = (TextView) findViewById(R.id.YTRatio);

final TextView videoTitle = (TextView) findViewById(R.id.videoTitle);
final ImageView ThumbnailView = (ImageView)findViewById(R.id.thumbnail_View);

StringRequest myRequest = new StringRequest(Request.Method.GET, FINAL_URL,
response -> {
try{
Expand All @@ -140,25 +159,48 @@ else if (YouTubeLink.contains("youtube.com"))
volleyError -> ErrorDownloading()
// Toast.makeText(DisplayMessageActivity.this, volleyError.getMessage(), Toast.LENGTH_SHORT).show()
);

StringRequest oEmbedRequest = new StringRequest(Request.Method.GET, oEmbedURL,
response -> {
try{
//Create a JSON object containing information from the API.
JSONObject myJsonObject = new JSONObject(response);
// Set video title
videoTitle.setText(myJsonObject.getString("title"));

// Set video thumbnail
String thumbnailUrl = myJsonObject.getString("thumbnail_url");
Picasso.get().load(thumbnailUrl).into(ThumbnailView);
} catch (JSONException e) {
e.printStackTrace();
}
},
volleyError -> ErrorDownloading()
// Toast.makeText(DisplayMessageActivity.this, volleyError.getMessage(), Toast.LENGTH_SHORT).show()
);

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(myRequest);
requestQueue.add(oEmbedRequest);

return "";
}

public void ErrorDownloading()
{
final TextView textViewDislikes = (TextView) findViewById(R.id.YTDislikes);
final TextView textViewLikes = (TextView) findViewById(R.id.YTLikes);
final TextView textViewViews = (TextView) findViewById(R.id.YTViews);
final TextView textViewVideoLink = (TextView) findViewById(R.id.YTVideoLink);
final TextView textViewRatio = (TextView) findViewById(R.id.YTRatio);
final TextView textViewDislikes = findViewById(R.id.YTDislikes);
final TextView textViewLikes = findViewById(R.id.YTLikes);
final TextView textViewViews = findViewById(R.id.YTViews);
final TextView textViewVideoLink = findViewById(R.id.YTVideoLink);
final TextView textViewRatio = findViewById(R.id.YTRatio);
final TextView videoTitle = findViewById(R.id.videoTitle);

textViewDislikes.setText("Error Downloading!");
textViewLikes.setText("Error Downloading!");
textViewRatio.setText("Error Downloading!");
textViewViews.setText("Error Downloading!");
textViewVideoLink.setText("Error Downloading!");
textViewVideoLink.setText("Unknown Title");

}

Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/layout/activity_display_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,30 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />

<TextView
android:id="@+id/videoTitle"
android:layout_width="294dp"
android:layout_height="47dp"
android:layout_marginStart="112dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="78dp"
android:text="Title"
android:textColor="@android:color/primary_text_dark"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/YTVideoLink" />

<ImageView
android:id="@+id/thumbnail_View"
android:layout_width="411dp"
android:layout_height="166dp"
android:layout_marginTop="13dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/videoTitle"
app:srcCompat="@mipmap/rydblogo" />
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath 'com.android.tools.build:gradle:7.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#Sat Jan 01 22:38:49 CET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
distributionSha256Sum=e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637

0 comments on commit 789c7e3

Please # to comment.