Skip to content

Commit

Permalink
Merge pull request #11 from smedic/01_Improvements
Browse files Browse the repository at this point in the history
01 improvements
  • Loading branch information
smedic authored Feb 13, 2017
2 parents 9e8df09 + 876bbde commit 3eb44dd
Show file tree
Hide file tree
Showing 39 changed files with 243 additions and 141 deletions.
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 13 additions & 27 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
apply plugin: 'com.android.application'

android {
signingConfigs {
config {
keyAlias 'TubTubKey'
keyPassword 'tubtub'
storeFile file('/home/smedic/Android/android.jks')
storePassword 'tubtub'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.smedic.tubtub"
minSdkVersion 16
targetSdkVersion 22
targetSdkVersion 25
versionCode 8
versionName "1.7"
}

buildTypes {
debug {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
def appId = android.defaultConfig.applicationId
def fileName = appId + "-" + variant.buildType.name +".apk"
def fileName = appId + "-" + variant.buildType.name + "-" + defaultConfig.versionName + ".apk"
output.outputFile = new File(file.parent, fileName)
}
}
Expand All @@ -45,24 +38,17 @@ android {
}
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}

dependencies {
provided fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile(name:'library-release', ext:'aar')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.google.android.gms:play-services-auth:9.0.0'
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/listviewanimations_lib-core-slh_3.1.0.jar')
compile files('libs/listviewanimations_lib-manipulation_3.1.0.jar')
compile files('libs/listviewanimations_lib-core_3.1.0.jar')
compile(name:'color_picker_library-release', ext:'aar')
compile 'com.android.support:appcompat-v7'
compile 'com.android.support:design:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile files('libs/google-api-client-android-1.21.0.jar')
compile files('libs/google-http-client-android-1.21.0.jar')
compile files('libs/google-api-client-1.21.0.jar')
Expand All @@ -72,7 +58,7 @@ dependencies {
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/google-api-services-youtube-v3-rev160-1.21.0.jar')
compile files('libs/picasso-2.5.2.jar')
compile files('libs/okhttp-3.2.0.jar') //used for picasso caching
compile files('libs/picasso-2.5.2.jar');
compile 'com.github.HaarigerHarald:android-youtubeExtractor:1.5.0'
compile 'pub.devrel:easypermissions:0.3.0'
}
File renamed without changes.
Binary file removed app/libs/listviewanimations_lib-core-slh_3.1.0.jar
Binary file not shown.
Binary file removed app/libs/listviewanimations_lib-core_3.1.0.jar
Binary file not shown.
Binary file not shown.
Binary file removed app/libs/nineoldandroids-2.4.0.jar
Binary file not shown.
Binary file removed app/libs/okhttp-3.2.0.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smedic.tubtub"
android:versionName="1.01">
package="com.smedic.tubtub">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand All @@ -19,6 +17,7 @@
android:theme="@style/MyMaterialTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.searchable"
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.util.Log;
import android.util.SparseArray;

import com.smedic.tubtub.model.ItemType;
import com.smedic.tubtub.model.YouTubeVideo;
import com.smedic.tubtub.utils.Config;
import com.squareup.picasso.Picasso;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class BackgroundAudioService extends Service implements MediaPlayer.OnCom
private MediaSessionCompat mSession;
private MediaControllerCompat mController;

private int mediaType = Config.YOUTUBE_MEDIA_NO_NEW_REQUEST;
private ItemType mediaType = ItemType.YOUTUBE_MEDIA_NONE;

private YouTubeVideo videoItem;

Expand Down Expand Up @@ -155,20 +156,20 @@ private void handleIntent(Intent intent) {
* @param intent
*/
private void handleMedia(Intent intent) {
int intentMediaType = intent.getIntExtra(Config.YOUTUBE_TYPE, Config.YOUTUBE_MEDIA_NO_NEW_REQUEST);
ItemType intentMediaType = (ItemType) intent.getSerializableExtra(Config.YOUTUBE_TYPE);
switch (intentMediaType) {
case Config.YOUTUBE_MEDIA_NO_NEW_REQUEST: //video is paused,so no new playback requests should be processed
case YOUTUBE_MEDIA_NONE: //video is paused,so no new playback requests should be processed
mMediaPlayer.start();
break;
case Config.YOUTUBE_MEDIA_TYPE_VIDEO:
mediaType = Config.YOUTUBE_MEDIA_TYPE_VIDEO;
case YOUTUBE_MEDIA_TYPE_VIDEO:
mediaType = ItemType.YOUTUBE_MEDIA_TYPE_VIDEO;
videoItem = (YouTubeVideo) intent.getSerializableExtra(Config.YOUTUBE_TYPE_VIDEO);
if (videoItem.getId() != null) {
playVideo();
}
break;
case Config.YOUTUBE_MEDIA_TYPE_PLAYLIST: //new playlist playback request
mediaType = Config.YOUTUBE_MEDIA_TYPE_PLAYLIST;
case YOUTUBE_MEDIA_TYPE_PLAYLIST: //new playlist playback request
mediaType = ItemType.YOUTUBE_MEDIA_TYPE_PLAYLIST;
youTubeVideos = (ArrayList<YouTubeVideo>) intent.getSerializableExtra(Config.YOUTUBE_TYPE_PLAYLIST);
int startPosition = intent.getIntExtra(Config.YOUTUBE_TYPE_PLAYLIST_VIDEO_POS, 0);
iterator = youTubeVideos.listIterator(startPosition);
Expand Down Expand Up @@ -312,6 +313,7 @@ private void buildNotification(NotificationCompat.Action action) {
* Field which handles image loading
*/
private Target target = new Target() {

@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
updateNotificationLargeIcon(bitmap);
Expand Down Expand Up @@ -358,7 +360,7 @@ private NotificationCompat.Action generateAction(int icon, String title, String
*/
private void playNext() {
//if media type is video not playlist, just loop it
if (mediaType == Config.YOUTUBE_MEDIA_TYPE_VIDEO) {
if (mediaType == ItemType.YOUTUBE_MEDIA_TYPE_VIDEO) {
seekVideo(0);
restartVideo();
return;
Expand All @@ -383,7 +385,7 @@ private void playNext() {
*/
private void playPrevious() {
//if media type is video not playlist, just loop it
if (mediaType == Config.YOUTUBE_MEDIA_TYPE_VIDEO) {
if (mediaType == ItemType.YOUTUBE_MEDIA_TYPE_VIDEO) {
restartVideo();
return;
}
Expand Down Expand Up @@ -507,7 +509,7 @@ public void onTaskRemoved(Intent rootIntent) {

@Override
public void onCompletion(MediaPlayer _mediaPlayer) {
if (mediaType == Config.YOUTUBE_MEDIA_TYPE_PLAYLIST) {
if (mediaType == ItemType.YOUTUBE_MEDIA_TYPE_PLAYLIST) {
playNext();
buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE));
} else {
Expand Down
50 changes: 49 additions & 1 deletion app/src/main/java/com/smedic/tubtub/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.smedic.tubtub;

import android.Manifest;
import android.app.SearchManager;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -24,6 +25,7 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand All @@ -37,6 +39,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

Expand All @@ -55,16 +58,21 @@
import java.util.ArrayList;
import java.util.List;

import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/**
* Activity that manages fragments and action bar
*/
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {

private static final String TAG = "SMEDIC MAIN ACTIVITY";
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;

private final int PERMISSIONS = 1;

private int initialColor = 0xffff0040;
private int initialColors[] = new int[2];

Expand Down Expand Up @@ -104,6 +112,35 @@ protected void onCreate(Bundle savedInstanceState) {
setupTabIcons();

loadColor();

requestPermissions();
/*if (ContextCompat.checkSelfPermission(this,
Manifest.permission.GET_ACCOUNTS)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.GET_ACCOUNTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
}*/
}

@AfterPermissionGranted(PERMISSIONS)
private void requestPermissions() {
String[] perms = {Manifest.permission.GET_ACCOUNTS, Manifest.permission.READ_PHONE_STATE};
if (EasyPermissions.hasPermissions(this, perms)) {
// Already have permission, do the thing
Log.d(TAG, "requestPermissions: all permissions are there");
} else {
// Do not have permissions, request them now
EasyPermissions.requestPermissions(this, getString(R.string.all_permissions_request),
PERMISSIONS, perms);
}
}

@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[], @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}

/**
Expand Down Expand Up @@ -165,6 +202,16 @@ private void setupViewPager(ViewPager viewPager) {
viewPager.setAdapter(adapter);
}

@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
Log.d(TAG, "onPermissionsGranted:");
}

@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
Log.d(TAG, "onPermissionsDenied: ");
}

/**
* Class which provides adapter for fragment pager
*/
Expand Down Expand Up @@ -195,6 +242,7 @@ public void addFragment(Fragment fragment, String title) {
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.widget.TextView;

import com.smedic.tubtub.R;
import com.smedic.tubtub.interfaces.ItemEventsListener;
import com.smedic.tubtub.model.ItemType;
import com.smedic.tubtub.model.YouTubePlaylist;
import com.squareup.picasso.Picasso;

Expand All @@ -24,6 +26,7 @@ public class PlaylistsAdapter extends ArrayAdapter<YouTubePlaylist> {

private Activity context;
private List<YouTubePlaylist> playlists;
private ItemEventsListener itemEventsListener;

public PlaylistsAdapter(Activity context, List<YouTubePlaylist> playlists) {
super(context, R.layout.video_item, playlists);
Expand All @@ -41,8 +44,9 @@ public View getView(final int position, View convertView, ViewGroup parent) {
TextView title = (TextView) convertView.findViewById(R.id.playlist_title);
TextView videosNumber = (TextView) convertView.findViewById(R.id.videos_number);
TextView privacy = (TextView) convertView.findViewById(R.id.privacy);
ImageView shareButton = (ImageView) convertView.findViewById(R.id.share_button);

YouTubePlaylist searchResult = playlists.get(position);
final YouTubePlaylist searchResult = playlists.get(position);

Picasso.with(getContext()).load(searchResult.getThumbnailURL()).into(thumbnail);
title.setText(searchResult.getTitle());
Expand All @@ -51,9 +55,23 @@ public View getView(final int position, View convertView, ViewGroup parent) {
String status = context.getString(R.string.status) + searchResult.getStatus();
privacy.setText(status);

shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (itemEventsListener != null) {
itemEventsListener.onShareClicked(ItemType.YOUTUBE_MEDIA_TYPE_PLAYLIST,
searchResult.getId());
}
}
});

return convertView;
}

public void setOnItemEventsListener(ItemEventsListener listener) {
itemEventsListener = listener;
}

@Override
public long getItemId(int i) {
return getItem(i).hashCode();
Expand Down
Loading

0 comments on commit 3eb44dd

Please sign in to comment.