diff --git a/app/build.gradle b/app/build.gradle index 428bf8e..e5bd513 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { @@ -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.+' } diff --git a/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java b/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java index f43a05f..5d27e17 100644 --- a/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java +++ b/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java @@ -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(); } @@ -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 diff --git a/app/src/main/java/com/smedic/tubtub/MainActivity.java b/app/src/main/java/com/smedic/tubtub/MainActivity.java index 8c76342..1447093 100644 --- a/app/src/main/java/com/smedic/tubtub/MainActivity.java +++ b/app/src/main/java/com/smedic/tubtub/MainActivity.java @@ -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; @@ -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; @@ -57,6 +62,8 @@ public class MainActivity extends AppCompatActivity { private TabLayout tabLayout; private ViewPager viewPager; + private ColorPicker cp; + private SearchFragment searchFragment; private RecentlyWatchedFragment recentlyPlayedFragment; @@ -90,8 +97,12 @@ protected void onCreate(Bundle savedInstanceState) { networkConf = new NetworkConf(this); + cp = new ColorPicker(MainActivity.this, 0, 0, 0); + setupTabIcons(); + loadColor(); + } /** @@ -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); } @@ -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); @@ -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 } @@ -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); + } + } } diff --git a/app/src/main/java/com/smedic/tubtub/fragments/FavoritesFragment.java b/app/src/main/java/com/smedic/tubtub/fragments/FavoritesFragment.java index 9895b7f..1708404 100644 --- a/app/src/main/java/com/smedic/tubtub/fragments/FavoritesFragment.java +++ b/app/src/main/java/com/smedic/tubtub/fragments/FavoritesFragment.java @@ -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; @@ -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(); diff --git a/app/src/main/java/com/smedic/tubtub/fragments/RecentlyWatchedFragment.java b/app/src/main/java/com/smedic/tubtub/fragments/RecentlyWatchedFragment.java index 4cdb506..ac0c201 100644 --- a/app/src/main/java/com/smedic/tubtub/fragments/RecentlyWatchedFragment.java +++ b/app/src/main/java/com/smedic/tubtub/fragments/RecentlyWatchedFragment.java @@ -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; @@ -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(); diff --git a/app/src/main/java/com/smedic/tubtub/fragments/SearchFragment.java b/app/src/main/java/com/smedic/tubtub/fragments/SearchFragment.java index 3047dbe..3c60763 100644 --- a/app/src/main/java/com/smedic/tubtub/fragments/SearchFragment.java +++ b/app/src/main/java/com/smedic/tubtub/fragments/SearchFragment.java @@ -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; @@ -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); } diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml deleted file mode 100644 index 18c364f..0000000 --- a/app/src/main/res/layout/fragment_main.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 4bc710a..457b1a6 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -22,4 +22,10 @@ android:orderInCategory="100" android:title="@string/action_about" app:showAsAction="never" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b28c697..a10832a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ TubTub About me + Color picker Hello World from section: %1$d Recently watched Search YouTube