Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
day night theme setup + removing memory leaks + use vector drawables
Browse files Browse the repository at this point in the history
  • Loading branch information
Laith Nurie committed May 2, 2016
1 parent 3f27cb8 commit 9fb90ba
Show file tree
Hide file tree
Showing 54 changed files with 223 additions and 58 deletions.
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
classpath 'com.android.tools.build:gradle:2.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,6 +18,18 @@ allprojects {
}
}

subprojects {

ext {
commonCompileSdkVersion = 23
commonBuildToolsVersion = "23.0.2"
commonMinSdkVersion = 16
commonTargetSdkVersion = 23
commonSupportLibraryVersion = '23.3.0'
commonPlayServicesVersion = '8.4.0'
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
24 changes: 12 additions & 12 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
compileSdkVersion commonCompileSdkVersion
buildToolsVersion commonBuildToolsVersion

defaultConfig {
applicationId "com.laithlab.rhythm"
Expand All @@ -20,8 +20,8 @@ android {
onesignal_google_project_number: properties.getProperty('onesignal_google_project_number')]
}

minSdkVersion 16
targetSdkVersion 23
minSdkVersion commonMinSdkVersion
targetSdkVersion commonTargetSdkVersion
versionCode 5
versionName "1.0"
}
Expand Down Expand Up @@ -59,16 +59,16 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
compile "com.android.support:appcompat-v7:${commonSupportLibraryVersion}"
compile "com.android.support:palette-v7:${commonSupportLibraryVersion}"
compile "com.android.support:design:${commonSupportLibraryVersion}"
compile "com.android.support:recyclerview-v7:${commonSupportLibraryVersion}"

compile 'com.onesignal:OneSignal:2.1.1@aar'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile "com.google.android.gms:play-services-wearable:${commonPlayServicesVersion}"
compile "com.google.android.gms:play-services-gcm:${commonPlayServicesVersion}"
compile "com.google.android.gms:play-services-analytics:${commonPlayServicesVersion}"
compile "com.google.android.gms:play-services-location:${commonPlayServicesVersion}"

compile 'com.facebook.stetho:stetho:1.2.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
Expand Down
22 changes: 22 additions & 0 deletions mobile/src/main/java/com/laithlab/rhythm/RhythmApp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.laithlab.rhythm;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDelegate;
import android.util.Log;

import com.crashlytics.android.Crashlytics;
Expand All @@ -14,13 +17,20 @@
import timber.log.Timber;

public class RhythmApp extends Application {
static {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}

private SharedPreferences mSharedPreferences;
private int currentNightMode;

public RhythmApp() {
super();
}

public void onCreate() {
super.onCreate();
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

CrashlyticsCore core = new CrashlyticsCore.Builder()
.disabled(BuildConfig.DEBUG)
Expand All @@ -45,6 +55,18 @@ public void idsAvailable(String usernameID, String registrationId) {
}
}

public String getSelectedTheme() {
return mSharedPreferences.getString("theme_list", "light");
}

public int getCurrentNighMode() {
return currentNightMode;
}

public void setCurrentNightMode(int currentNightMode) {
this.currentNightMode = currentNightMode;
}

public class CrashlyticsTree extends Timber.Tree {
private static final String CRASHLYTICS_KEY_PRIORITY = "priority";
private static final String CRASHLYTICS_KEY_TAG = "tag";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.laithlab.rhythm.utils.ViewUtils;
import com.laithlab.rhythm.R;

public class ArtistActivity extends AppCompatActivity implements AlbumGridAdapter.ClickListener {
public class ArtistActivity extends RhythmActivity implements AlbumGridAdapter.ClickListener {

private static final java.lang.String ARTIST_ID_PARAM = "artistId";
private static final java.lang.String ARTIST_PARAM = "artist";
Expand Down Expand Up @@ -66,7 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
Expand All @@ -33,12 +32,11 @@

import java.util.List;

public class BrowseActivity extends AppCompatActivity implements MusicDBProgressCallBack, ArtistGridAdapter.ClickListener {
public class BrowseActivity extends RhythmActivity implements MusicDBProgressCallBack, ArtistGridAdapter.ClickListener {

private static final int REQUEST_READ_STORAGE = 1;
private DrawerLayout drawerLayout;
private RecyclerView browseGrid;
private Context context;
private View loadingContainer;

private SharedPreferences sharedPreferences;
Expand All @@ -49,16 +47,15 @@ public class BrowseActivity extends AppCompatActivity implements MusicDBProgress
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse);
context = this;
sharedPreferences = context.getSharedPreferences("com.laithlab.rhythm", Context.MODE_PRIVATE);
sharedPreferences = getSharedPreferences("com.laithlab.rhythm", Context.MODE_PRIVATE);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
}

Expand All @@ -68,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
ProgressBar loadingProgess = (ProgressBar) findViewById(R.id.loadingProgess);
loadingProgess.getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);

List<Artist> artists = MusicDataUtility.allArtists(this);
List<Artist> artists = MusicDataUtility.allArtists(getApplicationContext());
browseGrid = (RecyclerView) findViewById(R.id.browse_grid);
GridAutoFitLayoutManager gridLayoutManager = new GridAutoFitLayoutManager(this, 300);
browseGrid.setLayoutManager(gridLayoutManager);
Expand Down Expand Up @@ -148,7 +145,7 @@ private void checkStoragePermission(final MusicDBProgressCallBack callBack) {
// permission has been granted, continue as usual
new Thread(new Runnable() {
public void run() {
MusicDataUtility.updateMusicDB(context);
MusicDataUtility.updateMusicDB(getApplicationContext());
callBack.finishedDBUpdate();
}
}).start();
Expand All @@ -164,7 +161,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
loadingContainer.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
public void run() {
MusicDataUtility.updateMusicDB(context);
MusicDataUtility.updateMusicDB(getApplicationContext());
BrowseActivity.this.finishedDBUpdate();
}
}).start();
Expand All @@ -182,7 +179,7 @@ public void finishedDBUpdate() {
runOnUiThread(new Runnable() {
@Override
public void run() {
List<ArtistDTO> artists = DTOConverter.getArtistList(MusicDataUtility.allArtists(context));
List<ArtistDTO> artists = DTOConverter.getArtistList(MusicDataUtility.allArtists(getApplicationContext()));
if (artists != null && artists.size() > 0) {
if (browseGrid.getAdapter() == null) {
artistGridAdapter = new ArtistGridAdapter(artists, BrowseActivity.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import io.realm.Realm;
import io.realm.RealmList;

public class PlaylistActivity extends AppCompatActivity implements SongListAdapter.ClickListener
public class PlaylistActivity extends RhythmActivity implements SongListAdapter.ClickListener
, PlaylistCallback, PlaylistAddCallback {

public static String MUSIC_CONTENT = "musicContent";
Expand Down Expand Up @@ -68,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Bundle extras = getIntent().getExtras();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import java.util.List;

public class PlaylistGridActivity extends AppCompatActivity implements PlaylistGridAdapter.ClickListener, PlaylistAddCallback {
public class PlaylistGridActivity extends RhythmActivity implements PlaylistGridAdapter.ClickListener, PlaylistAddCallback {

private DrawerLayout drawerLayout;
private View noPlaylists;
Expand All @@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.laithlab.rhythm.activity;

import android.content.res.Configuration;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;

import com.laithlab.rhythm.RhythmApp;

public abstract class RhythmActivity extends AppCompatActivity {

@Override
protected void onResume() {
super.onResume();
updateTheme();
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (currentNightMode != ((RhythmApp) getApplication()).getCurrentNighMode()) {
((RhythmApp) getApplication()).setCurrentNightMode(currentNightMode);
recreate();
}
}

private void updateTheme() {
String theme = ((RhythmApp) getApplication()).getSelectedTheme();
int nightMode = AppCompatDelegate.MODE_NIGHT_NO;
if (theme.equals("dark")) {
nightMode = AppCompatDelegate.MODE_NIGHT_YES;
}
if (theme.equals("auto")) {
nightMode = AppCompatDelegate.MODE_NIGHT_AUTO;
}
AppCompatDelegate.setDefaultNightMode(nightMode);
getDelegate().applyDayNight();
}
}
17 changes: 17 additions & 0 deletions mobile/src/main/java/com/laithlab/rhythm/activity/RhythmPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.support.v7.app.AppCompatDelegate;

import com.laithlab.rhythm.R;
import com.laithlab.rhythm.utils.DialogHelper;
Expand All @@ -30,6 +32,21 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);

final ListPreference themePref = (ListPreference) findPreference("theme_list");
if (themePref.getEntry() != null) {
themePref.setSummary(themePref.getEntry());
}
themePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int index = themePref.findIndexOfValue(String.valueOf(newValue));
String theme = (String) themePref.getEntries()[index];
themePref.setSummary(theme);
themePref.setValue(newValue.toString());

return true;
}
});
Preference resetStats = findPreference("reset_stats");

resetStats.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ protected void onCreate(Bundle savedInstanceState) {

searchList = (RecyclerView) findViewById(R.id.search_list);

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
searchList.setLayoutManager(layoutManager);
List<SearchResult> results = MusicDataUtility.getAllSearchResults(this);
List<SearchResult> results = MusicDataUtility.getAllSearchResults(getApplicationContext());
if(results != null && results.size() > 0){
searchList.setAdapter(new SearchAdapter(results));
findViewById(R.id.no_search_results).setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

import static com.laithlab.rhythm.utils.PlayMode.*;

public class SwipePlayerActivity extends AppCompatActivity implements SongFragmentCallback, GoogleApiClient.ConnectionCallbacks,
public class SwipePlayerActivity extends RhythmActivity implements SongFragmentCallback, GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {

private DrawerLayout drawerLayout;
Expand All @@ -55,6 +55,7 @@ public class SwipePlayerActivity extends AppCompatActivity implements SongFragme
private TextView album;
private ViewPager viewPager;
private Menu menu;
private View playerBackground;

private boolean isWearConnected = false;
private boolean changedSongFromNotification = false;
Expand Down Expand Up @@ -83,11 +84,12 @@ protected void onCreate(Bundle savedInstanceState) {
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBar.setHomeAsUpIndicator(R.drawable.ic_action_menu);
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
}

tiltedView = findViewById(R.id.tilted_view);
playerBackground = findViewById(R.id.player_background);

drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.color_primary));
Expand Down Expand Up @@ -238,13 +240,17 @@ private void shuffleSongs() {
}

@Override
public void changePlayerStyle(int vibrantColor, int songPosition) {
public void changePlayerStyle(int vibrantColor, int backgroundColor, int songPosition) {
if (songPosition == viewPager.getCurrentItem()) {
if (vibrantColor == 0) {
vibrantColor = getResources().getColor(R.color.color_primary);
}
if (backgroundColor == 0) {
backgroundColor = getResources().getColor(R.color.color_primary_dark);
}
toolbar.setBackgroundColor(vibrantColor);
tiltedView.setBackgroundColor(vibrantColor);
playerBackground.setBackgroundColor(backgroundColor);
}
this.songPosition = songPosition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder = (ViewHolder) convertView.getTag();
}

holder.gridItemImage.setImageResource(R.drawable.ic_play_arrow_white);
holder.gridItemImage.setImageResource(R.drawable.ic_play_arrow_white_24dp);
byte[] imageData = MusicDataUtility.getImageData(songs.get(position).getSongLocation());
if (imageData != null) {
Bitmap bmp = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
Expand Down
Loading

0 comments on commit 9fb90ba

Please sign in to comment.