Skip to content

Commit

Permalink
[01] Fixed bug with playlist items number and added text color picker…
Browse files Browse the repository at this point in the history
… feature
  • Loading branch information
Stevan Medic committed Mar 28, 2016
1 parent 73fafdf commit 1b11a88
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 43 deletions.
Binary file modified app/libs/library-release.aar
Binary file not shown.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
android:launchMode="singleTop">
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
Expand Down
57 changes: 37 additions & 20 deletions app/src/main/java/com/smedic/tubtub/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.CursorAdapter;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class MainActivity extends AppCompatActivity {
private ViewPager viewPager;

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

private SearchFragment searchFragment;
private RecentlyWatchedFragment recentlyPlayedFragment;
Expand Down Expand Up @@ -325,61 +327,76 @@ public void onClick(DialogInterface dialog, int which) {
return true;
} else if (id == R.id.action_color_picker) {
/* Show color picker dialog */
ColorPickerDialogBuilder.with(this)
.setTitle("Color picker")
ColorPickerDialogBuilder
.with(this)
.setTitle("Choose background and text color")
.initialColor(initialColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.setPickerCount(2)
.initialColors(initialColors)
.density(12)
.setOnColorSelectedListener(new OnColorSelectedListener() {
@Override
public void onColorSelected(int selectedColor) {
initialColor = selectedColor;
}
})
.setPositiveButton("ok", new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
setColor(selectedColor);
//changeBackgroundColor(selectedColor);
if (allColors != null) {
setColors(allColors[0], allColors[1]);
}
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.showColorEdit(true)
.build()
.show();


}

return super.onOptionsItemSelected(item);
}

/**
* Save app theme color in preferences
* Loads app theme color saved in preferences
*/
private void setColor(int selectedColorRGB) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(selectedColorRGB);

TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
tabs.setBackgroundColor(selectedColorRGB);
private void loadColor() {
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
sp.edit().putInt("COLOR", selectedColorRGB).commit();
int backgroundColor = sp.getInt("BACKGROUND_COLOR", -1);
int textColor = sp.getInt("TEXT_COLOR", -1);

if (backgroundColor != -1 && textColor != -1) {
setColors(backgroundColor, textColor);
} else {
initialColors = new int[]{
ContextCompat.getColor(this, R.color.colorPrimary),
ContextCompat.getColor(this, R.color.textColorPrimary)};
}
}

/**
* Loads app theme color saved in preferences
* Save app theme color in preferences
*/
private void loadColor() {
private void setColors(int backgroundColor, int textColor) {

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(backgroundColor);
toolbar.setTitleTextColor(textColor);
TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
tabs.setBackgroundColor(backgroundColor);
tabs.setTabTextColors(textColor, textColor);
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
int color = sp.getInt("COLOR", -1);
sp.edit().putInt("BACKGROUND_COLOR", backgroundColor).commit();
sp.edit().putInt("TEXT_COLOR", textColor).commit();

if (color != -1) {
setColor(color);
}
initialColors[0] = backgroundColor;
initialColors[1] = textColor;
}
}
22 changes: 15 additions & 7 deletions app/src/main/java/com/smedic/tubtub/YouTubeSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.Toast;

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
Expand Down Expand Up @@ -47,6 +48,7 @@

import java.io.IOException;
import java.math.BigInteger;
import java.net.UnknownHostException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -285,28 +287,35 @@ public void run() {
try {
playlistItemRequest = youtube.playlistItems().list("id,contentDetails,snippet");
playlistItemRequest.setPlaylistId(playlistId);

playlistItemRequest.setMaxResults(50l);
playlistItemRequest.setFields("items(contentDetails/videoId,snippet/title," +
"snippet/thumbnails/default/url),nextPageToken");
// Call API one or more times to retrieve all items in the list. As long as API
// response returns a nextPageToken, there are still more items to retrieve.
//do {
playlistItemRequest.setPageToken(nextToken);
//playlistItemRequest.setPageToken(nextToken);
PlaylistItemListResponse playlistItemResult = playlistItemRequest.execute();
playlistItemList.addAll(playlistItemResult.getItems());
//nextToken = playlistItemResult.getNextPageToken();
//} while (nextToken != null);

Log.d(TAG, "all items size: " + playlistItemList.size());
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == 404) {
youTubeVideosReceiver.onPlaylistNotFound(playlistId, e.getStatusCode());
return;
} else {
e.printStackTrace();
}
} catch (UnknownHostException e) {
Toast.makeText(activity.getApplicationContext(), "Check internet connection", Toast.LENGTH_SHORT).show();
e.printStackTrace();
return;
} catch (IOException e) {
e.printStackTrace();
return;
}

playlistItemRequest.setFields("items(contentDetails/videoId,snippet/title," +
"snippet/thumbnails/default/url),nextPageToken");

//videos to get duration
YouTube.Videos.List videosList = null;
try {
Expand All @@ -320,7 +329,7 @@ public void run() {
int ii = 0;
for (PlaylistItem result : playlistItemList) {
contentDetails.append(result.getContentDetails().getVideoId());
if (ii < 49)
if (ii < playlistItemList.size() - 1)
contentDetails.append(",");
ii++;
}
Expand Down Expand Up @@ -348,7 +357,6 @@ public void run() {
youTubeVideo.setId(playlistItem.getContentDetails().getVideoId());
youTubeVideo.setTitle(playlistItem.getSnippet().getTitle());
youTubeVideo.setThumbnailURL(playlistItem.getSnippet().getThumbnails().getDefault().getUrl());

//video info
if (videoItem != null) {
String isoTime = videoItem.getContentDetails().getDuration();
Expand Down
Binary file removed app/src/main/res/drawable-hdpi/ic_favorite.png
Binary file not shown.
15 changes: 1 addition & 14 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
<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>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base"></style>

Expand Down

0 comments on commit 1b11a88

Please sign in to comment.