Firebase, Youtube and Riff King – Practical Wednesday Mix

      1 Comment on Firebase, Youtube and Riff King – Practical Wednesday Mix
firebase

Firebase, Youtube And... New App!

Hi, this is Practical Wednesday Mix of Firebase, Youtube, and Riff King! It's a mix of the most practical stuff about Android that I learned this week.Mix for beginners and intermediate developers. Not for nerds! Today's topics are:

  • Firebase- unrivaled and easy database
  • Youtube Share- put your app into YT share list (cool tip, few lines)
  • Youtube Thumbnail- convert URL link to image
  • Riff King- newly published app and source code

So let's start with the statement...

Firebase Is Essential

A few weeks ago I struggled with implementing login and register feature. I created few hundreds of lines of Java code using Volley library.  I had to keep data somewhere, so on the next day, I created a new database on my domain. Database worked. On the third day, I wrote PHP scripts needed to login, register and get user data. Ha, wrote! I copied 20 various versions from the Internet. Most didn't work and I didn't know PHP. I'm really patient but being stuck with 1 stupid error is really annoying. I didn't do too much besides Android so I felt like my life is unable to compile.

Fortunately, I did it. After few days of coding, I was very proud of my app. But my friend told me that he wouldn't waste time for creating a new account on a new shitty app. He would rather log in using Google (one click and done). I decided to implement logging in using Google and it took me

Not 1 week but 1 hour...

Yeah. That's the amount of time I spent on implementing more up-to-date login screen. I used SQLite. That's a fine option for huge apps but not for small projects. Now I will always consider using Firebase. Why it's so easier and faster to implement?

  • Firebase Assistant is built in Android Studio (Tools->Firebase)
  • You don't need domain (It needs only your google account)
  • It's dummy-proof (PHP and SQL knowledge is not needed)
  • It's a real-time database (shows changes immediately)
  • Easy to use (access to data everywhere in a few lines)

It's not just database. It's advanced, but easy to use, database. Those are features provided just by logging in. Some of them are really cool because allow you to control a lot of information using UI, not console. That's much cooler. 

firebase features
Firebase Features

Links I Used

Authors of tutorials listed below are definitely more experienced than me. I found the best (working) tutorials and tested them because some previous one just wasted my time. First two are needed to log in using Google and the third one is used to store other data.

You should consider using this database if you want to be up-to-date. It's really modern and even looks cleaner. I'm very happy about their UI.

Youtube Share

Do you know this share option in youtube app to share video URL?  Yeah, it shows a list of apps on your device that can handle this feature. And your app can't. I'm sorry, it's like that by default! In youtube dependent apps it's really important to implement it because you don't want your users to copy the link and open your app, and paste it manually. Wait... They will have to open your "AddLink" window too.

In "youtube-dependent" apps, it's really important to implement it because you don't want your users to insert the link manually. Wait... They will have to open your "AddLink" window too. It's NOT user-friendly. Fortunately, You can handle this option and do every operation in the background. So your user clicks share and is satisfied. You will avoid 1-star rate. ;D And it's so easy to implement!

Implementation

  1. Copy and paste inside your first activity in Android Manifest to make app visible in the share app list
    <activity
    android:name=".HomeActivity"
    android:label="@string/title_activity_home"
    android:theme="@style/AppTheme.NoActionBar">

    <data
    android:host="www.youtube.com"
    android:mimeType="text/*"/>

  2. Handle data in the same activity. Trigger this function in onCreate()
    private void youtubeShareable() {
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
    value1 = extras.getString(Intent.EXTRA_TEXT);
    if (value1 != null && !value1.equals(""))
    displaySelectedScreen(R.id.nav_upload);
    }
    }
  3. DisplaySelectedScreen() is not essential to get data. I wanted to send this value to another fragment so I created
    String value1 = "";

    at the beginning of the code, outside of methods

  4. The displaySelectedScreen method
    private void displaySelectedScreen(int id) {
    Fragment fragment = null;
    switch (id) {
    case R.id.nav_upload:
    Bundle bundle = new Bundle();
    bundle.putString("URL", value1);
    fragment = new InsertThreadFragment();
    fragment.setArguments(bundle);
    break;
    //case ...
    }
    if (fragment != null) {
    getSupportFragmentManager().beginTransaction()
    .replace(R.id.content_home, fragment).addToBackStack("stack1").commit();
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    }

    allowed me to instantly(onCreate) switch to InsertThreadFragment when a user opens app using share video option. This method won't trigger if a user opens app manually.

  5.  Receiving bundle in InsertThreadFragment is really easy. Now you can use it whenever you want. I pasted it to edit text using urlEt.setText(urlLink)
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
    urlLink = getArguments().getString("URL");
    }
youtube

 Get Youtube Thumbnail From URL

  1. GetThumbnail class
    /**
    * Created by jakub on 22.07.17.
    */
    public class GetThumbnail extends AsyncTask<String, String, Bitmap> {
    public static int YTIDLENGTH = 11;
    Bitmap icon_val;
    String thumbURL;
    ImageView singleThumb;
    public GetThumbnail(String url, ImageView singleThumbnail) {
    this.thumbURL = url;
    this.singleThumb = singleThumbnail;
    }
    @Override
    protected Bitmap doInBackground(String... params) {
    String URLLink = thumbURL;
    if (URLLink.length() > 15) {
    String ytId = URLLink.substring(URLLink.length() - 11, URLLink.length());
    if (ytId.length() >= YTIDLENGTH) {
    ytId = ytId.substring(0, YTIDLENGTH);
    try {
    URL thumbnailURL = new URL("https://img.youtube.com/vi/" + ytId + "/0.jpg");
    icon_val = BitmapFactory.decodeStream(thumbnailURL.openConnection().getInputStream());
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    return null;
    }
    @Override
    protected void onPostExecute(Bitmap bf) {
    super.onPostExecute(icon_val);
    singleThumb.setImageBitmap(icon_val);
    }
    }

    Youtube links contain 11 character ID. I cut everything except 11 last characters and used it inside special link that provides thumbnails. Everything is done in the background so the app won't crash but will load image ASAP.

  2. How to trigger this class. This type of class is Singleton. Provide URL and imageView that will contain selected thumbnail
    new GetThumbnail(stringVideoURL, imageViewForThumbnail).execute();

    I triggered it inside RecyclerView Adapter 

    //in onBindViewHolder
    new GetThumbnail(threads.get(position).getURL(), holder.singleThumbnail).execute();

    It's really easy to use and works super-fast. There are more youtube features that I will use and write about on this blog. So make sure that you subscribe me!

firebase riff king

Riff King

It's a short one... And the name speaks a lot. Maybe you won't be a rockstar but you can be a riff king. It's the newly published app for musicians. Share your youtube video, get points and become a Riff King. If you are the type of bedroom musician then it will be a great place for you. Will be. Why will be?

For now, the app is in production mode so you can track my fails and improvements. It's not like really public. You won't find it online just like that so it looks like you will be a VIP there. There is even VIP button to sign in before app hits official version. I'm not kidding! Feel free to check Riff King on Google Play. Thanks for reading!

One thought on “Firebase, Youtube and Riff King – Practical Wednesday Mix

Leave a Reply

Your email address will not be published. Required fields are marked *