Skip to content
Snippets Groups Projects
Commit 74c4e2d0 authored by Junwon Jung's avatar Junwon Jung
Browse files

initial commit

parent a78886c2
No related branches found
No related tags found
No related merge requests found
Showing
with 4966 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
FinalProject
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/FinalProject.iml" filepath="$PROJECT_DIR$/FinalProject.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
/build
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.junwon.finalproject"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:cardview-v7:25.3.1'
compile files('libs/unirest-java-1.4.9.jar')
compile 'me.grantland:autofittextview:0.2.+'
}
File added
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Jun Won\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.example.junwon.finalproject;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.example.junwon.finalproject", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.junwon.finalproject">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.example.junwon.finalproject;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import me.grantland.widget.AutofitTextView;
/**
* Created by Jun Won on 2017-11-21.
*/
public class DetailedMovieFragment extends Fragment {
View view;
TextView tagline_text;
AutofitTextView production_companies;
int movie_id;
ImageView banner_image;
ImageView main_poster;
RatingBar rating_bar;
AutofitTextView detailed_title;
AutofitTextView detailed_genre;
AutofitTextView overview;
Bitmap banner_bitmap;
Bitmap poster_bitmap;
ArrayList<String> genre_array = new ArrayList<>();
String movie_title;
ArrayList<String> production_company_array = new ArrayList<>();
String release_date;
String tagline;
String overview_string;
int vote_average;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.detailed_movie_fragment, container, false);
setHasOptionsMenu(true);
MainActivity.deleteMenu = false;
setVariables();
getActivity().setTitle("Movie information");
getMovieId();
getData();
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.detailed_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_rate:
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(getActivity());
View mView = getActivity().getLayoutInflater().inflate(R.layout.menu_ratingbar, null);
RatingBar rating_bar = (RatingBar) mView.findViewById(R.id.menu_ratingbar);
final Button rate_button = (Button) mView.findViewById(R.id.rate_button);
final Button cancel_button = (Button) mView.findViewById(R.id.cancel_button);
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
rating_bar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, final float rating, boolean fromUser) {
rate_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AsyncTask asynctask = new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
dialog.dismiss();
}
@Override
protected Object doInBackground(Object[] params) {
Map<String, Float> map = new HashMap<>();
map.put("value", 2 * rating);
String body = HttpRequest.post("https://api.themoviedb.org/3/movie/" + movie_id + "/rating", true, "api_key",
MainActivity.getApi_key(), "session_id", MainActivity.getSession_id()).form(map).body();
System.out.println(body);
Toast.makeText(getActivity(), "Successfully Rated",
Toast.LENGTH_LONG).show();
return null;
}
}.execute();
}
});
cancel_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
});
dialog.show();
return true;
case R.id.menu_delete_rate:
AsyncTask asynctask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
HttpRequest.delete("https://api.themoviedb.org/3/movie/" + movie_id + "/rating", true, "api_key",
MainActivity.getApi_key(), "session_id", MainActivity.getSession_id());
Toast.makeText(getActivity(), "Successfully Deleted",
Toast.LENGTH_LONG).show();
return null;
}
}.execute();
return true;
case R.id.menu_favorite:
new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
Toast.makeText(getActivity(), "Added to Favorite",
Toast.LENGTH_LONG).show();
}
@Override
protected Object doInBackground(Object[] params) {
Map<String, Object> map = new HashMap<>();
map.put("media_type", "movie");
map.put("media_id", movie_id);
map.put("favorite", true);
String body = HttpRequest.post("https://api.themoviedb.org/3/account/{account_id}/favorite", true, "api_key",
MainActivity.getApi_key(), "session_id", MainActivity.getSession_id()).form(map).body();
System.out.println(body);
return null;
}
}.execute();
return true;
case R.id.menu_watchlist:
new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
Toast.makeText(getActivity(), "Added to My Watchlist",
Toast.LENGTH_LONG).show();
}
@Override
protected Object doInBackground(Object[] params) {
Map<String, Object> map = new HashMap<>();
map.put("media_type", "movie");
map.put("media_id", movie_id);
map.put("watchlist", true);
String body = HttpRequest.post("https://api.themoviedb.org/3/account/{account_id}/watchlist", true, "api_key",
MainActivity.getApi_key(), "session_id", MainActivity.getSession_id()).form(map).body();
System.out.println(body);
return null;
}
}.execute();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/**
* Getting movie ID from argument
*/
private void getMovieId() {
Bundle bundle = getArguments();
movie_id = bundle.getInt("movie_id");
}
/**
* Getting data using AsyncTask
*/
private void getData() {
AsyncTask asynctask = new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
banner_image.setImageBitmap(banner_bitmap);
banner_image.setScaleType(ImageView.ScaleType.FIT_XY);
tagline_text.setText(tagline);
main_poster.setImageBitmap(poster_bitmap);
setPosterVideo(main_poster);
rating_bar.setRating(vote_average);
String year = release_date.split("-")[0];
detailed_title.setText(movie_title + " (" + year + ")");
String genre_string = "";
for (int i = 0; i < genre_array.size(); i++) {
genre_string += genre_array.get(i);
if (i != genre_array.size() - 1) {
genre_string += ", ";
}
}
detailed_genre.setText(genre_string);
String production_string = "";
for (int i = 0; i < production_company_array.size(); i++) {
production_string += production_company_array.get(i);
if (i != production_company_array.size() - 1) {
production_string += ", ";
}
}
production_companies.setText(production_string);
overview.setText(overview_string);
Bundle bundle = new Bundle();
bundle.putString("flag", "detailed_recommended");
bundle.putInt("movie_id", movie_id);
Fragment fragment = new MovieListFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().add(R.id.detailed_recommended_frame, fragment).commit();
}
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/movie/" + movie_id,
true, "api_key", MainActivity.getApi_key()).body());
String link = jsonObject.getString("backdrop_path");
String actual_link = "http://image.tmdb.org/t/p/w185" + link;
banner_bitmap = getBitmap(actual_link);
link = jsonObject.getString("poster_path");
actual_link = "http://image.tmdb.org/t/p/w185" + link;
poster_bitmap = getBitmap(actual_link);
JSONArray genre_jsonarray = jsonObject.getJSONArray("genres");
for (int i = 0; i < genre_jsonarray.length(); i++) {
JSONObject genre_jsonobject = genre_jsonarray.getJSONObject(i);
genre_array.add(genre_jsonobject.getString("name"));
}
JSONArray production_jsonarray = jsonObject.getJSONArray("production_companies");
for (int i = 0; i < production_jsonarray.length(); i++) {
JSONObject production_jsonobject = production_jsonarray.getJSONObject(i);
production_company_array.add(production_jsonobject.getString("name"));
}
tagline = jsonObject.getString("tagline");
movie_title = jsonObject.getString("title");
release_date = jsonObject.getString("release_date");
vote_average = jsonObject.getInt("vote_average");
overview_string = jsonObject.getString("overview");
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
/**
* Clicking poster will lead to youtube video
*
* @param poster the Image of poster
*/
private void setPosterVideo(ImageView poster) {
poster.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask() {
String video_link;
@Override
protected void onPostExecute(Object o) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(video_link)));
Log.d("video", "Video playing!!");
}
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/movie/"
+ movie_id + "/videos", true, "api_key", MainActivity.getApi_key()).body());
JSONArray jsonArray = jsonObject.getJSONArray("results");
JSONObject first_jsonObject = jsonArray.getJSONObject(0);
String key = first_jsonObject.getString("key");
video_link = "https://www.youtube.com/watch?v=" + key;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
});
}
/**
* get bitmap image from the link indicated
*
* @param actual_link link to get the image
* @return bitmap image
* @throws IOException exception for IO
*/
private Bitmap getBitmap(String actual_link) throws IOException {
URL urlConnection = new URL(actual_link);
HttpURLConnection connection = (HttpURLConnection) urlConnection.openConnection();
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
}
/**
* Setting up all variables in this fragment class
*/
private void setVariables() {
banner_image = (ImageView) view.findViewById(R.id.banner_image);
main_poster = (ImageView) view.findViewById(R.id.main_poster);
rating_bar = (RatingBar) view.findViewById(R.id.rating_bar);
detailed_title = (AutofitTextView) view.findViewById(R.id.detail_title);
detailed_genre = (AutofitTextView) view.findViewById(R.id.detail_genre);
overview = (AutofitTextView) view.findViewById(R.id.overview);
tagline_text = (TextView) view.findViewById(R.id.tagline);
production_companies = (AutofitTextView) view.findViewById(R.id.production_companies);
}
}
This diff is collapsed.
package com.example.junwon.finalproject;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import de.hdodenhof.circleimageview.CircleImageView;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout drawer;
private ActionBarDrawerToggle mToggle;
private NavigationView navigationView;
private Toolbar mToolbar;
private final static String api_key = "7a3ab68737e6c2d44b1c27c3d1b90f0a";
private String request_token = "d19a2da47e00634e9b751d571cd04f35ca700d90";
private final static String session_id = "e61370e64733ae8adad24c5772016227b799667c";
private static Bitmap bitmap = null;
public Map<Integer, String> genre_map = new HashMap<>();
CircleImageView header_image;
TextView header_name;
TextView header_username;
static boolean deleteMenu = false;
/**
* function that gets session id
*
* @return session id
*/
public static String getSession_id() {
return session_id;
}
/**
* function that gets api key
*
* @return api key
*/
public static String getApi_key() {
return api_key;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
navigationView = (NavigationView) findViewById(R.id.navigationView);
mToolbar = (Toolbar) findViewById(R.id.nav_action);
drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, drawer, R.string.open, R.string.close);
setSupportActionBar(mToolbar);
drawer.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setGenreMap();
setHeader();
getFragmentManager().beginTransaction().replace(R.id.main_frame, new MovieProfileFragment()).commit();
navigationView.setNavigationItemSelectedListener(this);
}
/**
* setting up all variables
*/
private void setHeader() {
View mView = getLayoutInflater().inflate(R.layout.header_container, null);
header_image = (CircleImageView) mView.findViewById(R.id.header_image);
header_name = (TextView) mView.findViewById(R.id.header_name);
header_username = (TextView) mView.findViewById(R.id.header_username);
new ProfileData();
navigationView.addHeaderView(mView);
}
/**
* change integer genre code to the string type
*/
private void setGenreMap() {
AsyncTask asynctask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/genre/movie/list",
true, "api_key", api_key).body());
JSONArray genre_array = jsonObject.getJSONArray("genres");
for (int i = 0; i < genre_array.length(); i++) {
JSONObject genre_object = genre_array.getJSONObject(i);
int id = genre_object.getInt("id");
String name = genre_object.getString("name");
genre_map.put(id, name);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* uncheck all items in the menu
*/
public void unCheckItems() {
for (int i = 0; i < navigationView.getMenu().size(); i++) {
navigationView.getMenu().getItem(i).setChecked(false);
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_profile:
getFragmentManager().beginTransaction().replace(R.id.main_frame, new MovieProfileFragment()).commit();
unCheckItems();
item.setChecked(true);
break;
case R.id.nav_watchlist:
getFragmentManager().beginTransaction().replace(R.id.main_frame, new MyWatchlistFragment()).commit();
unCheckItems();
item.setChecked(true);
break;
case R.id.nav_upcoming:
getFragmentManager().beginTransaction().replace(R.id.main_frame, new UpcomingCollectionFragment()).commit();
unCheckItems();
item.setChecked(true);
break;
case R.id.nav_rated:
getFragmentManager().beginTransaction().replace(R.id.main_frame, new RatedMovieFragment()).commit();
unCheckItems();
item.setChecked(true);
break;
case R.id.nav_recommended:
getFragmentManager().beginTransaction().replace(R.id.main_frame, new UpcomingCollectionFragment()).commit();
unCheckItems();
item.setChecked(true);
break;
case R.id.nav_search:
getFragmentManager().beginTransaction().replace(R.id.main_frame, new SearchMovieFragment()).commit();
unCheckItems();
item.setChecked(true);
break;
}
return true;
}
/**
* get bitmap image from the link indicated
*
* @param actual_link link to get the image
* @return bitmap image
* @throws IOException exception for IO
*/
private Bitmap getBitmap(String actual_link) throws IOException {
URL urlConnection = new URL(actual_link);
HttpURLConnection connection = (HttpURLConnection) urlConnection.openConnection();
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
}
/**
* private class to hold the data
*/
private class ProfileData {
String hash;
String name;
String username;
Bitmap profile_image;
/**
* constructor of its class
*/
public ProfileData() {
AsyncTask asyncTask = new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
header_image.setImageBitmap(profile_image);
header_name.setText(name);
header_username.setText(username);
}
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/account",
true, "api_key", MainActivity.getApi_key(), "session_id", MainActivity.getSession_id()).body());
JSONObject avatar_object = jsonObject.getJSONObject("avatar");
JSONObject gravatar_object = avatar_object.getJSONObject("gravatar");
hash = gravatar_object.getString("hash");
name = jsonObject.getString("name");
username = jsonObject.getString("username");
String actual_link = "https://www.gravatar.com/avatar/" + hash;
profile_image = getBitmap(actual_link);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
}
}
This diff is collapsed.
package com.example.junwon.finalproject;
import android.app.Fragment;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import static android.R.attr.format;
/**
* Created by Jun Won on 2017-11-18.
*/
public class MovieProfileFragment extends Fragment {
View view;
private ImageView profileImage;
private TextView profileName;
private TextView rated;
private TextView average;
private TextView favorite;
private ImageView rated_movie1;
private ImageView rated_movie2;
private ImageView rated_movie3;
private ImageView favorite_movie1;
private ImageView favorite_movie2;
private ImageView favorite_movie3;
private ArrayList<Bitmap> rated_movie = new ArrayList<>();
private ArrayList<Bitmap> favorite_movie = new ArrayList<>();
private int rated_num = 0;
private int sum_rated = 0;
private int favorite_num = 0;
private ArrayList<Integer> favorite_movie_id = new ArrayList<>();
private ArrayList<Integer> rated_movie_id = new ArrayList<>();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.profile_fragment, container, false);
getActivity().setTitle("Profile");
setVariables();
MainActivity.deleteMenu = true;
try {
setRatedMovies();
setFavoriteMovies();
new ProfileData();
} catch (JSONException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return view;
}
/**
* Setting up the rated Movies in the profile page
* @throws JSONException throwing JSONException
*/
private void setRatedMovies() throws JSONException {
AsyncTask asyncTask = new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
try {
rated_movie1.setImageBitmap(rated_movie.get(0));
rated_movie2.setImageBitmap(rated_movie.get(1));
rated_movie3.setImageBitmap(rated_movie.get(2));
rated.setText(String.valueOf(rated_num));
DecimalFormat df = new DecimalFormat("#.##");
float average_num = Float.valueOf(df.format((float) sum_rated / rated_num));
average.setText(String.valueOf(average_num));
setRatedMovieItemClick();
} catch (Exception e) {
}
}
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/account/{account_id}/rated/movies",
true, "api_key", MainActivity.getApi_key(), "session_id", MainActivity.getSession_id(), "sort_by", "created_at.desc").body());
JSONArray jsonArray_result = jsonObject.getJSONArray("results");
for (int i = 0; i < jsonArray_result.length(); i++) {
JSONObject json_result = jsonArray_result.getJSONObject(i);
String link = json_result.getString("poster_path");
String actual_link = "http://image.tmdb.org/t/p/w185" + link;
rated_movie_id.add(json_result.getInt("id"));
Bitmap myBitmap = getBitmap(actual_link);
rated_movie.add(myBitmap);
rated_num++;
sum_rated += json_result.getInt("rating");
}
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
/**
* The function that sets up clicking item of the rated image
*/
private void setRatedMovieItemClick() {
rated_movie1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("movie_id",rated_movie_id.get(0));
Fragment fragment = new DetailedMovieFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.main_frame,fragment).addToBackStack(null).commit();
}
});
rated_movie2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("movie_id",rated_movie_id.get(1));
Fragment fragment = new DetailedMovieFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.main_frame,fragment).addToBackStack(null).commit();
}
});
rated_movie3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("movie_id",rated_movie_id.get(2));
Fragment fragment = new DetailedMovieFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.main_frame,fragment).addToBackStack(null).commit();
}
});
}
/**
* The function that sets up clicking item of the favorite image
*/
private void setFavoriteMovieItemClick() {
favorite_movie1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("movie_id",favorite_movie_id.get(0));
Fragment fragment = new DetailedMovieFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.main_frame,fragment).addToBackStack(null).commit();
}
});
favorite_movie2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("movie_id",favorite_movie_id.get(1));
Fragment fragment = new DetailedMovieFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.main_frame,fragment).addToBackStack(null).commit();
}
});
favorite_movie3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt("movie_id",favorite_movie_id.get(2));
Fragment fragment = new DetailedMovieFragment();
fragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.main_frame,fragment).addToBackStack(null).commit();
}
});
}
/**
* get bitmap image from the link indicated
*
* @param actual_link link to get the image
* @return bitmap image
* @throws IOException exception for IO
*/
private Bitmap getBitmap(String actual_link) throws IOException {
URL urlConnection = new URL(actual_link);
HttpURLConnection connection = (HttpURLConnection) urlConnection.openConnection();
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
}
/**
* The function that setting up basic data things of favorite movies
*/
private void setFavoriteMovies() throws JSONException, ExecutionException, InterruptedException, IOException {
AsyncTask asyncTask = new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
try {
favorite_movie1.setImageBitmap(favorite_movie.get(0));
favorite_movie2.setImageBitmap(favorite_movie.get(1));
favorite_movie3.setImageBitmap(favorite_movie.get(2));
favorite.setText(String.valueOf(favorite_num));
setFavoriteMovieItemClick();
} catch (Exception e) {
}
}
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/account/{account_id}/favorite/movies",
true, "api_key", MainActivity.getApi_key(), "session_id", MainActivity.getSession_id(), "sort_by", "created_at.desc").body());
JSONArray jsonArray_result = jsonObject.getJSONArray("results");
for (int i = 0; i < jsonArray_result.length(); i++) {
JSONObject json_result = jsonArray_result.getJSONObject(i);
String link = json_result.getString("poster_path");
String actual_link = "http://image.tmdb.org/t/p/w185" + link;
favorite_movie_id.add(json_result.getInt("id"));
Bitmap bit = getBitmap(actual_link);
favorite_movie.add(bit);
favorite_num++;
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
/**
* Setting up variables in this class
*/
private void setVariables() {
profileImage = (ImageView) view.findViewById(R.id.profileImage);
rated = (TextView) view.findViewById(R.id.rated_num);
average = (TextView) view.findViewById(R.id.average_num);
favorite = (TextView) view.findViewById(R.id.favorite_num);
rated_movie1 = (ImageView) view.findViewById(R.id.rated_movie_image1);
rated_movie2 = (ImageView) view.findViewById(R.id.rated_movie_image2);
rated_movie3 = (ImageView) view.findViewById(R.id.rated_movie_image3);
favorite_movie1 = (ImageView) view.findViewById(R.id.recommended_movies_image1);
favorite_movie2 = (ImageView) view.findViewById(R.id.recommended_movies_image2);
favorite_movie3 = (ImageView) view.findViewById(R.id.recommended_movies_image3);
profileName = (TextView) view.findViewById(R.id.profileName);
}
/**
* private class to hold the data
*/
private class ProfileData {
String hash;
String name;
String username;
Bitmap profile_image;
public ProfileData() {
AsyncTask asyncTask = new AsyncTask() {
@Override
protected void onPostExecute(Object o) {
profileImage.setImageBitmap(profile_image);
profileName.setText("Name: " + name + "\nUsername: " + username); }
@Override
protected Object doInBackground(Object[] params) {
try {
JSONObject jsonObject = new JSONObject(HttpRequest.get("https://api.themoviedb.org/3/account",
true, "api_key", MainActivity.getApi_key(), "session_id", MainActivity.getSession_id()).body());
JSONObject avatar_object = jsonObject.getJSONObject("avatar");
JSONObject gravatar_object = avatar_object.getJSONObject("gravatar");
hash = gravatar_object.getString("hash");
name = jsonObject.getString("name");
username = jsonObject.getString("username");
String actual_link = "https://www.gravatar.com/avatar/" + hash;
profile_image = getBitmap(actual_link);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
}
}
package com.example.junwon.finalproject;
import android.app.Fragment;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Map;
/**
* Created by Jun Won on 2017-11-21.
*/
public class MyWatchlistFragment extends Fragment {
View view;
/**
* Watchlist fragment with putting arguments combining MovieListFragment
*
* @return returning a view of its fragment
*/
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.collection_container_fragment, container, false);
getActivity().setTitle("My Watchlist");
MainActivity.deleteMenu = true;
Fragment watchlistfragment = new MovieListFragment();
Bundle bundle = new Bundle();
bundle.putString("flag", "my_watchlist");
watchlistfragment.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.collection_container, watchlistfragment).commit();
return view;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment