35
APPENDIX CODE VALUES COLOR <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#000000</color> <color name="colorPrimaryDark">#56565c</color> <color name="colorAccent">#101010</color> </resources> CODE VALUES STRING <resources> <string name="app_name">FILTERING YOUTUBE ARYA</string> <string name="button_search">Search</string> <string name="content_authority">com.arya.youtubefiltering</string> </resources> CODE VALUES STYLE <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:spinnerDropDownItemStyle">@style/mySpinnerItemStyle</item> </style> <style name="form"> <item name="android:paddingLeft">8dp</item> <item name="android:paddingRight">8dp</item> <item name="android:layout_marginTop">3dp</item> <item name="android:layout_height">40dp</item> <item name="android:layout_margin">10dp</item> </style> <style name="form_edit_text" parent="form"> <item name="android:background">@drawable/bg_edit_text</item> <item name="android:lines">1</item> <item name="android:maxLines">1</item> <item name="android:singleLine">true</item> </style> <style name="form_button" parent="form"> <item name="android:background">@drawable/bg_button</item> <item name="android:paddingLeft">10dp</item> <item name="android:paddingRight">10dp</item> <item name="android:textColor">@android:color/white</item> A

CODE VALUES COLOR ·

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CODE VALUES COLOR ·

APPENDIX

CODE VALUES COLOR

<?xml version="1.0" encoding="utf-8"?> <resources>

<color name="colorPrimary">#000000</color> <color name="colorPrimaryDark">#56565c</color> <color name="colorAccent">#101010</color>

</resources>

CODE VALUES STRING

<resources> <string name="app_name">FILTERING YOUTUBE ARYA</string> <string name="button_search">Search</string> <string

name="content_authority">com.arya.youtubefiltering</string> </resources>

CODE VALUES STYLE

<resources>

<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. -->

<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item

name="android:spinnerDropDownItemStyle">@style/mySpinnerItemStyle</item> </style>

<style name="form"> <item name="android:paddingLeft">8dp</item> <item name="android:paddingRight">8dp</item> <item name="android:layout_marginTop">3dp</item> <item name="android:layout_height">40dp</item> <item name="android:layout_margin">10dp</item>

</style>

<style name="form_edit_text" parent="form"> <item name="android:background">@drawable/bg_edit_text</item> <item name="android:lines">1</item> <item name="android:maxLines">1</item> <item name="android:singleLine">true</item>

</style>

<style name="form_button" parent="form"> <item name="android:background">@drawable/bg_button</item> <item name="android:paddingLeft">10dp</item> <item name="android:paddingRight">10dp</item> <item name="android:textColor">@android:color/white</item>

A

Page 2: CODE VALUES COLOR ·

</style>

<stylename="mySpinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner"> <item name="android:textColor">#000000</item>

</style> </resources>

CODE LAYOUT SPLASH SCREEN

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout

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="match_parent" tools:context="com.arya.youtubefiltering.SplashScreen" android:background="@android:color/white">

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:id="@+id/text_splash" android:text="CHRISTIAN ARYA PRATAMA" android:textColor="@android:color/black" android:visibility="invisible"

/> </RelativeLayout>

CODE LAYOUT ACTIVITY MAIN

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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="match_parent" tools:context="com.arya.youtubefiltering.MainActivity">

<EditText

B

Page 3: CODE VALUES COLOR ·

android:layout_width="match_parent" style="@style/form_edit_text"android:id="@+id/keyword"

/>

<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/keyword" android:id="@+id/radio_group">

<RadioButton

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Music" android:id="@+id/music"/>

<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="News"android:id="@+id/news"/>

<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Sports" android:id="@+id/sports"/>

</RadioGroup>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/radio_group" android:text="Safe Search" android:id="@+id/text_safesearch" android:layout_marginLeft="30dp" android:layout_marginRight="10dp"/>

<Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/text_safesearch" android:spinnerMode="dialog" android:layout_marginLeft="30dp" android:id="@+id/switch_safesearch">

</Switch>

C

Page 4: CODE VALUES COLOR ·

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/keyword" android:layout_alignParentRight="true" android:text="Publish Year" android:id="@+id/text_tahun" android:layout_marginRight="10dp"/>

<EditText android:layout_width="130dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@id/text_tahun" android:inputType="number" android:id="@+id/editText_year">

</EditText>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editText_year" android:layout_alignParentRight="true" android:text="Order By" android:id="@+id/text_order" android:layout_marginRight="10dp"/>

<Spinner android:layout_width="130dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@id/text_order" android:spinnerMode="dialog" android:layout_marginLeft="30dp" android:layout_marginTop="5dp" android:id="@+id/spinner_order">

</Spinner>

<Button android:layout_width="wrap_content" style="@style/form_button" android:text="@string/button_search" android:layout_below="@id/switch_safesearch" android:id="@+id/button_search"/>

<android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/button_search" android:id="@+id/recycle_view"> </android.support.v7.widget.RecyclerView>

D

Page 5: CODE VALUES COLOR ·

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:visibility="invisible" android:id="@+id/text_response"/>

</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>

CODE LAYOUT WATCH VIDEO

<RelativeLayout 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="match_parent" tools:context="com.arya.youtubefiltering.WatchVideo" android:layout_margin="5dp">

<TextViewandroid:layout_width="match_parent" android:layout_height="wrap_content" style="@style/TextAppearance.AppCompat.Title" android:id="@+id/detail_title" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"android:text="contoh untuk teks judul yang cukup panjang"/>

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/detail_title" android:id="@+id/detail_channel" style="@style/TextAppearance.AppCompat.Medium" android:text="Contoh channel title"/>

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/detail_channel" android:id="@+id/detail_views" style="@style/TextAppearance.AppCompat.Medium" android:text="Contoh views"/>

E

Page 6: CODE VALUES COLOR ·

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal” android:layout_below="@id/detail_views" android:id="@+id/linear">

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/detail_likes" style="@style/TextAppearance.AppCompat.Small" android:text="Contoh likes"/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TextAppearance.AppCompat.Small" android:text=" | "/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/detail_dislikes" style="@style/TextAppearance.AppCompat.Small" android:text="Contoh dislikes"/>

</LinearLayout>

<com.google.android.youtube.player.YouTubePlayerView android:id="@+id/youtube_video" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_below="@id/linear"/>

</RelativeLayout>

F

Page 7: CODE VALUES COLOR ·

CODE LAYOUT HISTORY

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayoutxmlns: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="match_parent"

tools:context="com.arya.youtubefiltering.HistoryActivity">

<android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/recycle_view_history" tools:layout_editor_absoluteY="8dp" tools:layout_editor_absoluteX="8dp">

</android.support.v7.widget.RecyclerView>

<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true" android:visibility="gone" android:layout_centerVertical="true"android:id="@+id/text_response_history"/>

</RelativeLayout>

CODE LAYOUT DROP DOWN ITEM

<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/text1"

android:textSize="14sp" android:gravity="left" android:text="Spinner Item" android:textColor="#000000" android:padding="10dp" />

G

Page 8: CODE VALUES COLOR ·

CODE LAYOUT VIDEO ITEM

<?xml version="1.0" encoding="utf-8"?> <LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical">

<android.support.v7.widget.CardView android:id="@+id/main_cv" android:layout_width="match_parent" android:layout_height="wrap_content">

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">

<RelativeLayout android:layout_width="120dp" android:layout_height="90dp" android:id="@+id/relative_image">

<ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/image_thumbnails" android:src="@drawable/sample"/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="2dp" android:id="@+id/text_duration" android:text="20:30" android:background="@android:color/black"tools:mockup_opacity="0.4" android:textColor="@android:color/white" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_margin="10dp"

/>

</RelativeLayout>

H

Page 9: CODE VALUES COLOR ·

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/relative_image"android:layout_marginLeft="3dp" android:orientation="vertical">

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/text_title" style="@style/TextAppearance.AppCompat.Title"android:text="Disini adalah contoh title"

/>

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/text_channel_title" style="@style/TextAppearance.AppCompat.Medium"android:text="Contoh channel title"/>

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/text_views" style="@style/TextAppearance.AppCompat.Medium" android:text="200.000 views"/>

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">

<TextView anroid:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text_likes" style="@style/TextAppearance.AppCompat.Medium"android:text="200.000 likes"/>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TextAppearance.AppCompat.Medium"android:text=" | "/>

<TextView

android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text_dislike" style="@style/TextAppearance.AppCompat.Medium"android:text="200.000 dislike"/>

I

Page 10: CODE VALUES COLOR ·

</LinearLayout>

</LinearLayout>

</RelativeLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

CODE SPLASH SCREEN

package com.arya.youtubefiltering;

import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.TextView;

public class SplashScreen extends AppCompatActivity{

TextView textSplash; Animation animationFadeIn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen);

textSplash = (TextView) findViewById(R.id.text_splash); animationFadeIn = AnimationUtils.loadAnimation(this,R.anim.fade_in);

animationFadeIn.setAnimationListener(newAnimation.AnimationListener() {

@Override public void onAnimationStart(Animation animation) { }

@Override public void onAnimationEnd(Animation animation) { Intent i = new Intent(SplashScreen.this, MainActivity.class); startActivity(i);

// close this activity finish(); }

@Override

J

Page 11: CODE VALUES COLOR ·

public void onAnimationRepeat(Animation animation) { } });

new Handler().postDelayed(new Runnable() {

@Override public void run() {

// Start fade in animation textSplash.setVisibility(View.VISIBLE);textSplash.startAnimation(animationFadeIn);} }, 2000); }

}

CODE SAVE KEY

package com.arya.youtubefiltering;

public class SimpanKey {

public static final String API_URL ="https://www.googleapis.com/youtube/v3/";

public static final String API_KEY ="AIzaSyBbOzdsWyYG9E_xhtYdTNb97IpWPjdRhhU";

}

K

Page 12: CODE VALUES COLOR ·

CODE MAIN ACTIVITY

package com.arya.youtubefiltering;

import android.content.Intent; import android.net.Uri; import android.support.annotation.IdRes; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.Switch; import android.widget.TextView; import android.widget.Toast;

import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.VolleyLog; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import com.arya.youtubefiltering.adapter.VideoAdapter; importcom.arya.youtubefiltering.customlistener.EndlessRecyclerOnScrollListener; import com.arya.youtubefiltering.entity.Video;

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

import java.util.ArrayList; import java.util.HashMap; import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {

EditText mSearhEditText, yearEditText ; TextView textResponse;

L

Page 13: CODE VALUES COLOR ·

RadioGroup radioGroup; Spinner spinnerOrder; Switch switchSearch; Button mButtonSearch ; String keyword; String pageToken=""; String listIDs= ""; String category = ""; String orderBy = ""; String year = ""; String yearStart = ""; String yearEnd = ""; String safeSearch=""; String[] listOrder = new String[]{"All", "viewCount", "date"}; ArrayAdapter<String> yearAdapter; ArrayAdapter<String> orderAdapter; ArrayList<Video> listVideo = new ArrayList<Video>(); RecyclerView recyclerView; RecyclerView.LayoutManager mLayoutManager; VideoAdapter mAdapter; EndlessRecyclerOnScrollListener scrollListener;

private static HashMap<String, String> mapRegex = new HashMap<>();private static String leadZeroRegex = "(?<=[^\\d])(\\d)(?=[^\\d])"; private static String leadZero = "0$1"; @Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

mapRegex.put("PT(\\d\\d)S", "00:$1"); mapRegex.put("PT(\\d\\d)M", "$1:00"); mapRegex.put("PT(\\d\\d)H", "$1:00:00"); mapRegex.put("PT(\\d\\d)M(\\d\\d)S", "$1:$2"); mapRegex.put("PT(\\d\\d)H(\\d\\d)S", "$1:00:$2"); mapRegex.put("PT(\\d\\d)H(\\d\\d)M", "$1:$2:00"); mapRegex.put("PT(\\d\\d)H(\\d\\d)M(\\d\\d)S", "$1:$2:$3");

mSearhEditText = (EditText)findViewById(R.id.keyword); radioGroup = (RadioGroup)findViewById(R.id.radio_group); mButtonSearch = (Button)findViewById(R.id.button_search); textResponse = (TextView) findViewById(R.id.text_response); recyclerView = (RecyclerView)findViewById(R.id.recycle_view); yearEditText = (EditText) findViewById(R.id.editText_year); spinnerOrder = (Spinner)findViewById(R.id.spinner_order); switchSearch = (Switch) findViewById(R.id.switch_safesearch);

switchSearch.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {

M

Page 14: CODE VALUES COLOR ·

@Override public void onCheckedChanged(CompoundButton buttonView, booleanisChecked) {

if(isChecked){ safeSearch = "strict"; }else{

safeSearch =""; }

} });

orderAdapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.dropdown_item, listOrder); spinnerOrder.setAdapter(orderAdapter); spinnerOrder.setOnItemSelectedListener(newAdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, intposition, long id) {

if(position==0){ orderBy=""; }else{

orderBy = listOrder[position]; }

Log.d("ORDER", orderBy);

}

@Override public void onNothingSelected(AdapterView<?> parent) {

} });

mLayoutManager = new LinearLayoutManager(getApplicationContext(),LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); mAdapter = new VideoAdapter(getApplicationContext(), listVideo, new VideoAdapter.OnItemClickListener() { @Override public void onItemClick(Video video) { Intent intent = new Intent(MainActivity.this, WatchVideo.class); intent.putExtra("video", video); startActivity(intent); } } ); recyclerView.setAdapter(mAdapter);

N

Page 15: CODE VALUES COLOR ·

scrollListener=newEndlessRecyclerOnScrollListener((LinearLayoutManager)mLayoutManager) { @Override public void onLoadMore(int current_page) { listIDs = ""; getVideos(keyword, pageToken, category, orderBy, yearStart,yearEnd, safeSearch); } };

mButtonSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean valid = true; keyword = mSearhEditText.getText().toString(); year = yearEditText.getText().toString();

if(TextUtils.isEmpty(keyword)){ Toast.makeText(getApplicationContext(), "Anda harus mengisikanKeyword", Toast.LENGTH_SHORT).show(); valid = false; }

if(!TextUtils.isEmpty(year)){ if(Integer.parseInt(year)<2000 || Integer.parseInt(year)>2017){ Toast.makeText(getApplicationContext(), "Tahun publish harus diisiantara 2000 sampai 2017", Toast.LENGTH_SHORT).show(); valid = false; }else{ yearStart = year+"-01-01T00:00:00Z"; yearEnd = year+"-12-31T23:59:59Z"; } }else{ yearStart = ""; yearEnd = ""; }

if(valid){ listVideo.clear(); pageToken =""; listIDs = ""; scrollListener.resetState(); getVideos(keyword, pageToken, category, orderBy, yearStart,yearEnd, safeSearch); }

} });

recyclerView.addOnScrollListener(scrollListener);

O

Page 16: CODE VALUES COLOR ·

radioGroup.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes intcheckedId) { if(checkedId==R.id.music){ category = "10"; }else if(checkedId==R.id.news){ category = "25"; }else if(checkedId==R.id.sports){ category = "17"; } } });

}

private void getVideos(final String q, String token, Stringcategory, String orderBy, String yearStart, String yearEnd, StringsafeSearch) { Uri builtUri; Uri.Builder builder;

builder = Uri.parse(SimpanKey.API_URL+"search").buildUpon();

builder.appendQueryParameter("type", "video") .appendQueryParameter("part", "snippet") .appendQueryParameter("maxResults", "10") .appendQueryParameter("q", q) .appendQueryParameter("pageToken", token) .appendQueryParameter("key", SimpanKey.API_KEY);

if(!TextUtils.isEmpty(safeSearch)){ builder.appendQueryParameter("safeSearch",

safeSearch); }

if(!TextUtils.isEmpty(category)){ builder.appendQueryParameter("videoCategoryId",

category); }

if(!TextUtils.isEmpty(orderBy)){ builder.appendQueryParameter("order", orderBy); }

if(!TextUtils.isEmpty(yearStart) || !TextUtils.isEmpty(yearEnd)){ builder.appendQueryParameter("publishedAfter", yearStart)

.appendQueryParameter("publishedBefore", yearEnd); }

builtUri = builder.build();

P

Page 17: CODE VALUES COLOR ·

String url = builtUri.toString(); Log.d("URL", url); JsonObjectRequest jsonObjReq = newJsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

@Override public void onResponse(JSONObject response) { Log.d("RESPOSE", response.toString()); try { JSONObject pageInfo = response.getJSONObject("pageInfo"); int totalResults = pageInfo.getInt("totalResults");

if(totalResults==0){ textResponse.setVisibility(View.VISIBLE); textResponse.setText("Tidak ditemukan hasil dengan katakunci \""+q+"\""); }else{ textResponse.setVisibility(View.INVISIBLE);

pageToken = response.getString("nextPageToken"); JSONArray items = response.getJSONArray("items");

for (int i = 0; i < items.length(); i++) {

JSONObject eachItem = items.getJSONObject(i);

JSONObject id = eachItem.getJSONObject("id"); String videoID = id.getString("videoId"); listIDs = listIDs+","+videoID;

} Log.d("LIST ID", listIDs); getVideoStatistic(listIDs); }

} catch (JSONException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); }

} }, new Response.ErrorListener() {

@Override public void onErrorResponse(VolleyError error) { VolleyLog.d("Volley Error: " + error.getMessage()); Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();

Q

Page 18: CODE VALUES COLOR ·

} });

RequestQueue requestQueue = Volley.newRequestQueue(this);

requestQueue.add(jsonObjReq); }

private void getVideoStatistic(String videoIds) { Uri builtUri = Uri.parse(SimpanKey.API_URL+"videos")

.buildUpon()

.appendQueryParameter("part", "snippet,contentDetails,statistics") .appendQueryParameter("id", videoIds) .appendQueryParameter("key", SimpanKey.API_KEY) .build();

String url = builtUri.toString(); Log.d("URL STATISTIC", url); JsonObjectRequest jsonObjReq = newJsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

@Override public void onResponse(JSONObject response) { Log.d("RESPOSE STATISTIC", response.toString());

try { JSONArray items = response.getJSONArray("items"); for (int i = 0; i < items.length(); i++) { JSONObject eachItem = items.getJSONObject(i); String videoID = eachItem.getString("id"); JSONObject snippet = eachItem.getJSONObject("snippet"); String channelID = snippet.getString("channelId"); String channelTitle = snippet.getString("channelTitle"); String title = snippet.getString("title"); String description = snippet.getString("description"); JSONObject allThumbnails = snippet.getJSONObject("thumbnails"); JSONObject thumbnailsDefault =allThumbnails.getJSONObject("default"); String urlThumbnails = thumbnailsDefault.getString("url"); JSONObject contentDetails =eachItem.getJSONObject("contentDetails"); JSONObject statistics = eachItem.getJSONObject("statistics"); String duration = contentDetails.getString("duration"); String viewCount = statistics.getString("viewCount"); String likeCount = statistics.getString("likeCount"); String dislikeCount = statistics.getString("dislikeCount"); //format duration christianarya String d = duration.replaceAll(leadZeroRegex, leadZero); String regex = getRegex(d); String newDuration = d.replaceAll(regex, mapRegex.get(regex)); Log.d("DURATION", newDuration); Video video = new Video(); video.setVideoID(videoID);

R

Page 19: CODE VALUES COLOR ·

video.setChannelID(channelID); video.setChannelTitle(channelTitle); video.setUrlThumbnails(urlThumbnails); video.setDescription(description); video.setTitle(title); video.setDuration(newDuration); video.setViews(viewCount); video.setLikes(likeCount); video.setDislikes(dislikeCount);

listVideo.add(video); }

mAdapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Error statistic: " + e.getMessage(), Toast.LENGTH_LONG).show(); }

} }, new Response.ErrorListener() {

@Override public void onErrorResponse(VolleyError error) { VolleyLog.d("Volley Error: " + error.getMessage()); Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show(); } }); RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(jsonObjReq); } private static String getRegex(String date) { for (String r : mapRegex.keySet()) if (Pattern.matches(r, date)) return r; return null; }

@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return true; }

@Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId()==R.id.history){ Intent intent = new Intent(MainActivity.this,HistoryActivity.class); startActivity(intent); } return super.onOptionsItemSelected(item);

S

Page 20: CODE VALUES COLOR ·

} }

CODE VIDEO

package com.arya.youtubefiltering.entity;

import android.os.Parcelable;

import java.io.Serializable;

public class Video implements Serializable{ String videoID; String title; String urlThumbnails; String description; String channelTitle; String channelID; String views; String duration; String likes; String dislikes;

public Video() {

}

public String getLikes() { return likes; }

public void setLikes(String likes) { this.likes = likes; }

public String getDislikes() { return dislikes; }

public void setDislikes(String dislikes) { this.dislikes = dislikes; }

public String getViews() { return views; }

public void setViews(String views) { this.views = views; }

public String getDuration() {

T

Page 21: CODE VALUES COLOR ·

return duration; }

public void setDuration(String duration) { this.duration = duration; }

public String getVideoID() { return videoID; }

public void setVideoID(String videoID) { this.videoID = videoID; }

public String getTitle() { return title; }

public void setTitle(String title) { this.title = title; }

public String getUrlThumbnails() { return urlThumbnails; }

public void setUrlThumbnails(String thumbnails) { this.urlThumbnails = thumbnails; }

public String getDescription() { return description; }

public void setDescription(String description) { this.description = description; }

public String getChannelTitle() { return channelTitle; }

public void setChannelTitle(String channelTitle) { this.channelTitle = channelTitle; }

public String getChannelID() { return channelID; }

public void setChannelID(String channelID) { this.channelID = channelID; } }

U

Page 22: CODE VALUES COLOR ·

CODE DBHELPER

package com.arya.youtubefiltering.db;

import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

static final String DATABASE_NAME = "youtube.db";

static final int DATABASE_VERSION = 2;

public static final String VIDEO_TABLE_NAME = "video";

public static final String VIDEO_ID = "id_video"; public static final String VIDEO_TITLE = "title"; public static final String URL_VIDEO = "url_video"; public static final String DESCRIPTION = "description"; public static final String CHANNEL_TITLE = "channel_title"; public static final String CHANNEL_ID = "channel_id"; public static final String VIEWS = "views"; public static final String DURATION = "duration"; public static final String LIKES = "likes"; public static final String DISIKES = "dislikes";

static final String CREATE_TABLE_VIDEO = " CREATE TABLE " + VIDEO_TABLE_NAME + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + VIDEO_ID+" TEXT NOT NULL, " + VIDEO_TITLE+" TEXT NOT NULL, " + URL_VIDEO+" TEXT NOT NULL, " + DESCRIPTION+" TEXT NOT NULL, " + LIKES+" TEXT NOT NULL, " + DISIKES+" TEXT NOT NULL, " + CHANNEL_ID+" TEXT NOT NULL, " + CHANNEL_TITLE+" TEXT NOT NULL, " + VIEWS+" TEXT NOT NULL, " + DURATION+" TEXT NOT NULL); ";

public DBHelper(Context context){ super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_VIDEO); }

@Override

V

Page 23: CODE VALUES COLOR ·

public void onUpgrade(SQLiteDatabase db, int oldVersion, intnewVersion) { db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_VIDEO); onCreate(db); }

public void deleteAllTable(String table_name){

SQLiteDatabase db = this.getWritableDatabase(); db.delete(table_name,null, null);

} }

CODE DBPROVIDER

package com.arya.youtubefiltering.db;

import android.content.ContentProvider; import android.content.ContentUris; import android.content.ContentValues; import android.content.UriMatcher; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.support.annotation.Nullable;

public class DBProvider extends ContentProvider {

public static final String PROVIDER_NAME ="com.arya.youtubefiltering"; public static final String URL = "content://" + PROVIDER_NAME; public static final Uri CONTENT_URI = Uri.parse(URL);

private static final String TABLE_VIDEO ="video";

private static final int VIDEO = 100;

private static final UriMatcher sURIMatcher = newUriMatcher(UriMatcher.NO_MATCH); static { sURIMatcher.addURI(PROVIDER_NAME, TABLE_VIDEO, VIDEO); }

private DBHelper dbHelper;

@Override public boolean onCreate() { dbHelper = new DBHelper(getContext());

W

Page 24: CODE VALUES COLOR ·

return true; }

@Nullable @Override public Cursor query(Uri uri, String[] projection, Stringselection, String[] selectionArgs, String sortOrder) { Cursor retCursor; switch (sURIMatcher.match(uri)) { case VIDEO: { retCursor = dbHelper.getReadableDatabase().query( DBHelper.VIDEO_TABLE_NAME, null, selection, selectionArgs, null, null, "_id DESC"); break; }

default: throw new UnsupportedOperationException("Unknownuri: " + uri); } retCursor.setNotificationUri(getContext().getContentResolver(), uri); return retCursor; }

@Nullable @Override public String getType(Uri uri) { return null; }

@Nullable @Override public Uri insert(Uri uri, ContentValues values) { SQLiteDatabase db = dbHelper.getWritableDatabase(); Uri returnUri;

switch (sURIMatcher.match(uri)){ case VIDEO: long rowID = db.insert(

DBHelper.VIDEO_TABLE_NAME, null, values); if (rowID > 0) { returnUri =ContentUris.withAppendedId(CONTENT_URI.buildUpon().appendPath(DBHelper.VIDEO_TABLE_NAME).build(), rowID); }else {

X

Page 25: CODE VALUES COLOR ·

throw new SQLException("Failed to add a recordinto " + uri); } break;

default: throw new UnsupportedOperationException("Unknownuri: " + uri); } getContext().getContentResolver().notifyChange(returnUri,null); db.close(); return returnUri; }

@Override public int delete(Uri uri, String selection, String[]selectionArgs) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int rowsDeleted;

switch (sURIMatcher.match(uri)) { case VIDEO: rowsDeleted = db.delete(DBHelper.VIDEO_TABLE_NAME,selection, selectionArgs); break; default: throw new UnsupportedOperationException("Unknownuri: " + uri); }

if (rowsDeleted != 0) { getContext().getContentResolver().notifyChange(uri,null); } return rowsDeleted; }

@Override public int update(Uri uri, ContentValues values, Stringselection, String[] selectionArgs) { SQLiteDatabase db = dbHelper.getWritableDatabase(); int rowsUpdated;

switch (sURIMatcher.match(uri)) { case VIDEO: rowsUpdated = db.update(DBHelper.VIDEO_TABLE_NAME,values, DBHelper.VIDEO_ID+" = ?", selectionArgs); break;

default: throw new UnsupportedOperationException("Unknownuri: " + uri); }

Y

Page 26: CODE VALUES COLOR ·

if (rowsUpdated != 0) { getContext().getContentResolver().notifyChange(uri,null); } return rowsUpdated; } }

CODE WATCH VIDEO

package com.arya.youtubefiltering;

import android.content.ContentValues; import android.media.MediaPlayer; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.MediaController; import android.widget.TextView; import android.widget.Toast; import android.widget.VideoView;

import com.arya.youtubefiltering.db.DBHelper; import com.arya.youtubefiltering.db.DBProvider; import com.arya.youtubefiltering.entity.Video; import com.google.android.youtube.player.YouTubeBaseActivity; importcom.google.android.youtube.player.YouTubeInitializationResult; import com.google.android.youtube.player.YouTubePlayer; import com.google.android.youtube.player.YouTubePlayerView;

import java.io.IOException;

public class WatchVideo extends YouTubeBaseActivity implementsYouTubePlayer.OnInitializedListener { TextView textTitle; TextView textChannel; TextView textViews; TextView textLikes; TextView textDislikes;

Video video;

YouTubePlayerView youTubePlayerView;

String videoID; String videoTitle; String channelTitle; String likes; String dislikes; String views;

Z

Page 27: CODE VALUES COLOR ·

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_watch_video);

textTitle = (TextView)findViewById(R.id.detail_title); textChannel = (TextView)findViewById(R.id.detail_channel); textViews = (TextView)findViewById(R.id.detail_views); textLikes = (TextView)findViewById(R.id.detail_likes); textDislikes =(TextView)findViewById(R.id.detail_dislikes);

youTubePlayerView = (YouTubePlayerView)findViewById(R.id.youtube_video);

Bundle extras = getIntent().getExtras();

video = (Video)extras.getSerializable("video");

videoID = video.getVideoID(); videoTitle = video.getTitle(); channelTitle = video.getChannelTitle(); likes = video.getLikes(); dislikes = video.getDislikes(); views = video.getViews();

textTitle.setText(videoTitle); textChannel.setText(channelTitle); textViews.setText(views+" views"); textLikes.setText(likes+" likes"); textDislikes.setText(dislikes+" dislikes");

youTubePlayerView.initialize(SimpanKey.API_KEY, this);

}

@Override public void onInitializationSuccess(YouTubePlayer.Providerprovider, YouTubePlayer youTubePlayer, boolean b) { if (!b) { youTubePlayer.cueVideo(videoID); addToDatabase(video); } }

@Override public void onInitializationFailure(YouTubePlayer.Providerprovider, YouTubeInitializationResult youTubeInitializationResult){ Toast.makeText(getApplicationContext(), "Error playingyoutube video", Toast.LENGTH_SHORT).show(); }

AA

Page 28: CODE VALUES COLOR ·

public void addToDatabase(Video video){ ContentValues contentValues = new ContentValues();

contentValues.put(DBHelper.VIDEO_ID, video.getVideoID()); contentValues.put(DBHelper.VIDEO_TITLE, video.getTitle()); contentValues.put(DBHelper.URL_VIDEO,video.getUrlThumbnails()); contentValues.put(DBHelper.CHANNEL_ID,video.getChannelID()); contentValues.put(DBHelper.CHANNEL_TITLE,video.getChannelTitle()); contentValues.put(DBHelper.VIEWS, video.getViews()); contentValues.put(DBHelper.DURATION, video.getDuration()); contentValues.put(DBHelper.LIKES, video.getLikes()); contentValues.put(DBHelper.DISIKES, video.getDislikes()); contentValues.put(DBHelper.DESCRIPTION,video.getDescription());

Uri contentURI =DBProvider.CONTENT_URI.buildUpon().appendPath(DBHelper.VIDEO_TABLE_NAME).build(); Log.d("INSERT AAAA", contentURI.toString()); Uri uri =getApplicationContext().getContentResolver().insert( contentURI, contentValues);

Log.d("INSERT", uri.toString()); } }

AB

Page 29: CODE VALUES COLOR ·

CODE HISTORY ACTIVITY

package com.arya.youtubefiltering;

import android.app.Activity; import android.app.LoaderManager; import android.content.CursorLoader; import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.TextView;

import com.arya.youtubefiltering.adapter.VideoAdapter; import com.arya.youtubefiltering.db.DBHelper; import com.arya.youtubefiltering.db.DBProvider; import com.arya.youtubefiltering.entity.Video;

import java.util.ArrayList;

public class HistoryActivity extends AppCompatActivity implementsLoaderManager.LoaderCallbacks<Cursor> { TextView textResponse; ArrayList<Video> listVideo = new ArrayList<Video>(); RecyclerView recyclerView; RecyclerView.LayoutManager mLayoutManager; VideoAdapter mAdapter;

private int LOADER_VIDEO = 111;

@Override public void onResume() { super.onResume(); getLoaderManager().restartLoader(LOADER_VIDEO, null,this); }

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history);

getLoaderManager().initLoader(LOADER_VIDEO, null,this); textResponse =(TextView)findViewById(R.id.text_response_history);

AC

Page 30: CODE VALUES COLOR ·

recyclerView = (RecyclerView)findViewById(R.id.recycle_view_history);

mLayoutManager = newLinearLayoutManager(getApplicationContext(),LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); mAdapter = new VideoAdapter(getApplicationContext(),listVideo, new VideoAdapter.OnItemClickListener() { @Override public void onItemClick(Video video) { } } ); recyclerView.setAdapter(mAdapter);

}

private void setRecyclerView(Cursor cursor){ listVideo.clear(); if (cursor == null) { Log.e("cursor ", "Error"); } else if (cursor.getCount() < 1) { Log.d("DISINI 3", "TRUE"); textResponse.setVisibility(View.VISIBLE); textResponse.setText("Tidak ada history"); Log.e("FRAG cursor", "Data tidak ditemukan"); } else { textResponse.setVisibility(View.GONE); Log.d("DISINI 4", "TRUE"); while (cursor.moveToNext()) { String videoID =cursor.getString(cursor.getColumnIndex(DBHelper.VIDEO_ID)); String title =cursor.getString(cursor.getColumnIndex(DBHelper.VIDEO_TITLE));; String urlThumbnails =cursor.getString(cursor.getColumnIndex(DBHelper.URL_VIDEO));; String description =cursor.getString(cursor.getColumnIndex(DBHelper.DESCRIPTION));; String channelTitle =cursor.getString(cursor.getColumnIndex(DBHelper.CHANNEL_TITLE));; String channelID =cursor.getString(cursor.getColumnIndex(DBHelper.CHANNEL_ID));; String views =cursor.getString(cursor.getColumnIndex(DBHelper.VIEWS));; String duration =cursor.getString(cursor.getColumnIndex(DBHelper.DURATION));; String likes =cursor.getString(cursor.getColumnIndex(DBHelper.LIKES));; String dislikes =cursor.getString(cursor.getColumnIndex(DBHelper.DISIKES));;

AD

Page 31: CODE VALUES COLOR ·

//Log.d("TEST CURSOR", judul_kajian);

Video video = new Video(); video.setVideoID(videoID); video.setTitle(title); video.setUrlThumbnails(urlThumbnails); video.setDescription(description); video.setChannelTitle(channelTitle); video.setChannelID(channelID); video.setViews(views); video.setDuration(duration); video.setLikes(likes); video.setDislikes(dislikes);

listVideo.add(video); }

mAdapter.notifyDataSetChanged(); } }

@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { Log.d("LOADED CURSOR", "TRUE"); Uri uri =DBProvider.CONTENT_URI.buildUpon().appendPath(DBHelper.VIDEO_TABLE_NAME).build();

CursorLoader cursorLoader = newCursorLoader(getApplicationContext(), uri, null, null, null,null);

return cursorLoader; }

@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data){ setRecyclerView(data); }

@Override public void onLoaderReset(Loader<Cursor> loader) {

}

@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.history_menu, menu); return true; }

AE

Page 32: CODE VALUES COLOR ·

@Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId()==R.id.history_delete){ DBHelper dbHelper = newDBHelper(getApplicationContext()); dbHelper.deleteAllTable(DBHelper.VIDEO_TABLE_NAME); listVideo.clear(); mAdapter.notifyDataSetChanged(); } return super.onOptionsItemSelected(item); } }

//CHRISTIANARYA_13020052

AF

Page 33: CODE VALUES COLOR ·

PLAGSCAN

AG

Page 34: CODE VALUES COLOR ·

AH

Page 35: CODE VALUES COLOR ·

AI