musiQ 1.636 release - recent optimizations and bug fixes

in #utopian-io6 years ago (edited)

Second post here. I took some examples on how to submit it correctly. Here are the few updates I did on the app. Thanks to @shirou-jeff for the submissions and issues on GitHub!

Bug Fixes

-First issue was the AlbumDetails window was disappearing on rotation. After that fix I noticed it was unscrollable.

Example: https://github.com/DDihanov/musiQ/issues/3

  • What was the solution?
    So the problem turned out to be two things:

1) Config change was reloading the activity. Since there were 2 activities where the popup window was being displayed I needed to disable reload on both places.
So first I disabled the reload like this:

First I enabled android to detect screen rotation in both activities from the manifest via "android:configChanges="orientation|screenSize"

       <activity android:name=".ui.main.MainActivity"
          android:configChanges="orientation|screenSize"/>
        <activity android:name=".ui.detail.ArtistDetails"
           android:configChanges="orientation|screenSize"/>
         <activity
             android:name=".ui.login.Login"
             android:label="@string/title_activity_login" />

After that I went on in both activities and overrode the methods that handle the rotation. In this case I didn't want them to do anything. So I went on in MainActivity.class and in ArtistDetails.class and overrode this method:

//this prevents the popupwindow from closing
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
   }

Nothing complex so far.

2) Now that this was fixed, the next issue was such, that when the user was in landscape mode and the window popped up, there was no way for him to scroll to the contents. The issue here was that the artist thumbnail was outside of the scrollview. So a simple solution was just to put it inside the scrollview so it became scrollable:

<android.support.v7.widget.CardView
        android:id="@+id/album_details_card_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="@dimen/card_margin"
        android:elevation="3dp"
        card_view:cardCornerRadius="@dimen/popup_card_radius">

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/nestedScrollView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_below="@+id/album_popup_thumbnail"
                android:layout_margin="13dp">

               .............
                     //imageview is now inside the scrollview, thus making the whole thing scrollable
                    <ImageView
                        android:id="@+id/album_popup_thumbnail"
                        android:layout_width="300dp"
                        android:layout_height="300dp"
                        android:layout_below="@+id/album_popup_title"
                        android:layout_centerHorizontal="true"
                        android:background="?attr/selectableItemBackgroundBorderless"
                        android:clickable="true"
                        android:scaleType="centerCrop" />
                        ..........

Link to the full layout: https://github.com/DDihanov/musiQ/blob/master/app/src/main/res/layout/album_popup_info.xml

- Next bug/unwanted feature was the following:

https://github.com/DDihanov/musiQ/issues/1

vid: https://youtu.be/FduZSD4htH4

This turned out to be a nasty Android SDK bug on some devices. No possible explanation was given was to why it happens on some devices and not on others, but the solution was to add this line of code to the popup window class:

popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);     
 popupWindow.setBackgroundDrawable(new BitmapDrawable());

This makes it so if the window is somehow "outside" of the screen, it can still be canceled. Link to the modified file: https://github.com/DDihanov/musiQ/blob/master/app/src/main/java/com/dihanov/musiq/ui/main/AlbumDetailsPopupWindow.java

- Next bug I fixed was a nasty OutOfMemoryException that was occuring on some devices:

java.lang.OutOfMemoryError:
.............
at com.dihanov.musiq.service.scrobble.Scrobbler.scrobble (Scrobbler.java:67)
at com.dihanov.musiq.service.scrobble.Scrobbler.manageScrobble (Scrobbler.java:333)
at com.dihanov.musiq.service.scrobble.Scrobbler.setStatus (Scrobbler.java:190)
at com.dihanov.musiq.service.MediaControllerListenerService$1.onPlaybackStateChanged (MediaControllerListenerService.java:76)

Basically this had something to do with Glide's image cache. I implemented a simple fix where I told Glide to clean it's cache when the memory is low and if android thinks its time to clean memory:
I added this to the App.class:

    @Override
    public void onLowMemory() {
        Glide.get(this).clearMemory();
        super.onLowMemory();
    }

    @Override
    public void onTrimMemory(int level) {
        Glide.get(this).clearMemory();
        super.onTrimMemory(level);
    }

- Next bug/unwanted feature I fixed was related to the search bar auto-submitting queries before the user has time to finish his search. This is the issue: https://github.com/DDihanov/musiQ/issues/4

The fix was to simply increase the time before the auto-submit from 500ms to 2000ms in both AlbumResultPresenter.class and ArtistResultPresenter.class:

private static final long DELAY_IN_MILLIS = 2000;

- A small change I made was to change the datetime format, from showing the time since the last scrobble to the date of the last scrobble. This is the method I had before, which was behaving weirdly in the RecentlyScrobbledAdapter.java:

https://github.com/DDihanov/musiQ/blob/master/app/src/main/java/com/dihanov/musiq/ui/adapters/RecentlyScrobbledAdapter.java

         holder.scrobble.setText(track.getArtist().getName() + " - " + track.getName());
        long difference = System.currentTimeMillis() - Long.parseLong(track.getDate().getUts()) * 1000;
        long time = TimeUnit.MILLISECONDS.toHours(difference);
        if (time <= 0) {
            holder.time.setText(String.valueOf(TimeUnit.MILLISECONDS.toMinutes(difference) + " minutes ago"));
        } else if(time == 24){
            holder.time.setText(String.valueOf(TimeUnit.MILLISECONDS.toDays(difference) + " day ago"));
        } else if(time > 24){
            holder.time.setText(String.valueOf(TimeUnit.MILLISECONDS.toDays(difference) + " days ago"));
        } else {
            holder.time.setText(String.valueOf(TimeUnit.MILLISECONDS.toHours(difference) + " hours ago"));
      }

So basically last.fm saves the date scrobbled via a UNIX UTC time stamp. So what I did here was take that stamp, multiply it with 1000 to get the milliseconds value, find the difference between the current time and the time scrobbled, and display that. However for some reason that was not giving out correct results consistently, so I switched over to android's built in DateUtils to show the time of the scrobble like this:

holder.time.setText(DateUtils.formatSameDayTime(
                Long.parseLong(track.getDate().getUts()) * 1000L,
                System.currentTimeMillis(),
                DateFormat.SHORT,
                DateFormat.SHORT));

-Last bug I fixed was the genre tags in the AlbumPopupWindow not displaying at all.
It turned out to be something small. I'm using a library that creates these tags for me. And I initialize them like this:

You can find the class here: https://github.com/DDihanov/musiQ/blob/master/app/src/main/java/com/dihanov/musiq/ui/main/AlbumDetailsPopupWindow.java

     private void initTags(Album album, View rootLayout) {
         TagView firstTag = (TagView) rootLayout.findViewById(R.id.popup_first_tag);
        TagView secondTag = (TagView) rootLayout.findViewById(R.id.popup_second_tag);
        TagView thirdTag = (TagView) rootLayout.findViewById(R.id.popup_third_tag);
        TagView fourthTag = (TagView) rootLayout.findViewById(R.id.popup_fourth_tag);
        TagView fifthTag = (TagView) rootLayout.findViewById(R.id.popup_fifth_tag);

Then I insert them in an array:

TagView[] tags = new TagView[]{
                firstTag, secondTag, thirdTag, fourthTag, fifthTag
        };

I then get the tags from the Album model, that was passed on from the API call:

List<Tag> tagText = album.getTags().getTag();

After that I sort them by name length and set the TagView's text and color appropriately:

//sorted by tag name length
        Collections.sort(firstFive, new Comparator<String>() {

            @Override
            public int compare(String s, String t1) {
                return Integer.compare(t1.length(), s.length());
            }
        });

        for (int i = 0; i < tagText.size(); i++) {
            TagView currTag = tags[i];
            currTag.setText(firstFive.get(i));
            currTag.setTagColor(Color.parseColor(((Activity) view).getString(R.color.colorAccent)));
        }

New Features

-Added LeakCanary support
This is not a big change, just added the library to detect any memory leaks. Phew! There weren't any!

musiQ is an open source musical library with fully integrated last.fm scrobbling. It's built with Dagger2, Retrofit2, RxJava and many more... You can check it out at https://github.com/DDihanov/musiQ

Thanks for taking your time to read this!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

Great post! Very descriptive! Just a little note: According to the rules, we cannot take bug fixes on own projects into account, when reviewing a contribution. This rule is to prevent fraud and "prepared" projects. This is obviously not the case here, so it's fine. Just keep that in mind that in general it is of course questionable to reward people for fixing their own bugs.

Keep up the good work!

You can contact us on Discord.
[utopian-moderator]

@mkt
Thanks for the reply. Where should I post when I continue with the releases of my project? Am I allowed to post further development on my own project?

Yes, as long as the updates have some significance you can get rewarded for your work. But here's a another little side-note: We are considering to require projects to actively register for Utopian, including a review process to ensure quality on the platform. But for now, just make sure you don't violate any rules and everything's fine.

Can you update your README according to the rule "The repository must contain a readme file with usage and install instructions, as well as an appropriate open source license."

@codingdefined
But my repo does contain a README with instructions?
https://github.com/DDihanov/musiQ/blob/master/README.md

I have mentioned the cloning instructions at the very bottom.

and a license:
https://github.com/DDihanov/musiQ/blob/master/LICENSE

@codingdefined please review it again. The last post on here was with the same repository and it went through with no problem. Thanks!

Hey @j4zz I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64420.25
ETH 3150.23
USDT 1.00
SBD 3.99