Skip to content

Commit

Permalink
[01] Added:
Browse files Browse the repository at this point in the history
    - color picker (experimental)
    - clickPendingEvent
    - Minor enhancements
    Removed:
    - multidex in gradle
  • Loading branch information
Stevan Medic committed Mar 22, 2016
1 parent 64588c8 commit b8f78c0
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 32 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ android {
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.smedic.tubtub"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
debug {
Expand Down Expand Up @@ -74,4 +73,6 @@ dependencies {
compile files('libs/google-api-services-youtube-v3-rev160-1.21.0.jar')
compile files('libs/picasso-2.5.2.jar')
compile files('libs/youtubeExtractor.jar')

compile 'com.pes.materialcolorpicker:library:1.0.+'
}
11 changes: 8 additions & 3 deletions app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public IBinder onBind(Intent intent) {
@Override
public void onCreate() {
super.onCreate();
videoItem = new YouTubeVideo();
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
videoItem = new YouTubeVideo();
initMediaSessions();
}

Expand Down Expand Up @@ -238,15 +238,20 @@ private void buildNotification(NotificationCompat.Action action) {

Intent intent = new Intent(getApplicationContext(), BackgroundAudioService.class);
intent.setAction(ACTION_STOP);
PendingIntent stopPendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);

PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
Intent clickIntent = new Intent(this, MainActivity.class);
clickIntent.setAction(Intent.ACTION_MAIN);
clickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent clickPendingIntent = PendingIntent.getActivity(this, 0, clickIntent, 0);

builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(videoItem.getTitle());
builder.setContentInfo(videoItem.getDuration());
builder.setShowWhen(false);
builder.setDeleteIntent(pendingIntent);
builder.setContentIntent(clickPendingIntent);
builder.setDeleteIntent(stopPendingIntent);
builder.setStyle(style);

//load bitmap for largeScreen
Expand Down
58 changes: 54 additions & 4 deletions app/src/main/java/com/smedic/tubtub/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.MatrixCursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
Expand All @@ -36,7 +38,10 @@
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
import com.smedic.tubtub.database.YouTubeSqlDb;
import com.smedic.tubtub.fragments.FavoritesFragment;
import com.smedic.tubtub.fragments.PlaylistsFragment;
Expand All @@ -57,6 +62,8 @@ public class MainActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;

private ColorPicker cp;

private SearchFragment searchFragment;
private RecentlyWatchedFragment recentlyPlayedFragment;

Expand Down Expand Up @@ -90,8 +97,12 @@ protected void onCreate(Bundle savedInstanceState) {

networkConf = new NetworkConf(this);

cp = new ColorPicker(MainActivity.this, 0, 0, 0);

setupTabIcons();

loadColor();

}

/**
Expand All @@ -116,6 +127,9 @@ private void handleIntent(Intent intent) {

if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);

viewPager.setCurrentItem(2, true); //switch to search fragment

if (searchFragment != null) {
searchFragment.searchQuery(query);
}
Expand Down Expand Up @@ -223,8 +237,6 @@ public boolean onSuggestionClick(int position) {
searchView.setQuery(suggestions.get(position), false);
searchView.clearFocus();

viewPager.setCurrentItem(2); //switch to search fragment

Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH);
suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position));
handleIntent(suggestionIntent);
Expand All @@ -236,7 +248,6 @@ public boolean onSuggestionClick(int position) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
viewPager.setCurrentItem(2); //switch to search fragment
return false; //if true, no new intent is started
}

Expand Down Expand Up @@ -306,15 +317,54 @@ public void onClick(DialogInterface dialog, int which) {
alertDialog.show();

return true;
} else if(id == R.id.action_clear_list) {
} else if (id == R.id.action_clear_list) {
YouTubeSqlDb.getInstance().videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED).deleteAll();
recentlyPlayedFragment.clearRecentlyPlayedList();
return true;
} else if (id == R.id.action_search) {
MenuItemCompat.expandActionView(item);
return true;
} else if (id == R.id.action_color_picker) {
/* Show color picker dialog */
cp.show();

/* On Click listener for the dialog, when the user select the color */
Button okColor = (Button) cp.findViewById(R.id.okColorButton);
okColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setColor(cp.getColor());
cp.dismiss();
}
});
}

return super.onOptionsItemSelected(item);
}

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

SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
sp.edit().putInt("COLOR", selectedColorRGB).commit();
}
/**
* Loads app theme color saved in preferences
*/
private void loadColor() {
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
int color = sp.getInt("COLOR", -1);

if (color != -1) {
setColor(color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -80,7 +79,6 @@ public void onResume() {
if (!getUserVisibleHint()) {
//do nothing for now
}
Log.d(TAG, "onResume - RecentlyWatchedFragment");
favoriteVideos.clear();
favoriteVideos.addAll(YouTubeSqlDb.getInstance().videos(YouTubeSqlDb.VIDEOS_TYPE.FAVORITE).readAll());
videoListAdapter.notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -89,7 +88,6 @@ public void onResume() {
//do nothing for now
}

Log.d(TAG, "onResume - RecentlyWatchedFragment");
recentlyPlayedVideos.clear();
recentlyPlayedVideos.addAll(YouTubeSqlDb.getInstance().videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED).readAll());
videoListAdapter.notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -104,7 +103,6 @@ public void onResume() {
}
//4th parameter is null, because playlists are not needed to this fragment

Log.d(TAG, "onResume - SearchFragment");
youTubeSearch = new YouTubeSearch(getActivity(), this);
youTubeSearch.setYouTubeVideosReceiver(this);
}
Expand Down
17 changes: 0 additions & 17 deletions app/src/main/res/layout/fragment_main.xml

This file was deleted.

6 changes: 6 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
android:orderInCategory="100"
android:title="@string/action_about"
app:showAsAction="never" />

<item
android:id="@+id/action_color_picker"
android:orderInCategory="100"
android:title="@string/action_color_picker"
app:showAsAction="never" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">TubTub</string>
<string name="action_about">About me</string>
<string name="action_color_picker">Color picker</string>
<string name="section_format">Hello World from section: %1$d</string>
<string name="recently_watched_tab">Recently watched</string>
<string name="search_tab">Search YouTube</string>
Expand Down

0 comments on commit b8f78c0

Please sign in to comment.