Open source

How to make open-source projects, which people want to use

2017-04-01 Conferences, DSP2017, Open source No comments

Today at Kariera IT conference in Katowice, Poland, I presented talk explaining how to make open-source projects, which people want to use from my perspective.

Below, you can find slides from my presentation. Thank you all for the attendance, interesting questions and organizers for inviting me. I hope you learned something new.
Of course, any constructive feedback for this talk will be appreciated :).

Links

Control Spotify on Linux like a hacker

2017-03-05 DSP2017, Linux, Open source, Python 2 comments

Recently, I created a tiny script called spotify-cli, which allows you to control Spotify on Linux from terminal. It’s inspired by shpotify, which is a shell script doing similar things, but on macOS. My script is written in Python and uses dbus under the hood, which allows to communicate with bus daemon to pass messages between applications. I used pactl for controlling the system sound.

You can install spotify-cli as follows via wget:

sh -c "$(wget https://raw.githubusercontent.com/pwittchen/spotify-cli-linux/master/install.sh -O -)"

or via curl:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/pwittchen/spotify-cli-linux/master/install.sh)"

After that, you can just type spotify-cli in your terminal.
You can use spotify-cli with the following parameters:

--help, -h          shows help
--status            shows status (currently played song name and artist)
--play              plays the song
--pause             pauses the song
--playpause         plays or pauses the song (toggles a state)
--next              plays the next song
--previous, --prev  plays the previous song
--volumeup          increases sound volume
--volumedown        decreases sound volume

That’s it! Happy listening!

Source code of the project can be found at https://github.com/pwittchen/spotify-cli-linux.

ReactiveNetwork – release v. 0.5.0

2016-07-24 Android, Java, Open source No comments

I have never thought that seemingly tiny thing like monitoring network connectivity on a mobile device can be subject to development for at least about one year!

I’ve recently released a new version of my project – ReactiveNetwork library – v. 0.5.0.

Highlights of this release are as follows:

  • added support for the new network monitoring strategy with NetworkCallback available since Android Lollipop (API 21)
  • kept backward compatibility of network monitoring with pre-Lollipop devices
  • added possibility to implement custom network monitoring strategy
  • made methods responsible for creating Observables static like in original RxJava project
  • added Preconditions class verifying correctness of the input parameters
  • changed API of Observable responsible for monitoring network from Observable<ConnectivityStatus> observeNetworkConnectivity(context) to Observable<Connectivity> observeNetworkConnectivity(context)
  • replaced ConnectivityStatus enum with Connectivity class containing info about network state, type and name
  • added more unit tests

You can read detailed release notes on GitHub.

I hope, this project will make your apps more robust and you won’t be surprised by incorrect network monitoring when your users will upgrade their devices to Android N. The newest Android version is not officially released to all Android devices yet, but it’s already supported by ReactiveNetwork library.

ReactiveNetwork – new releases & roadmap

2016-06-10 Android, Java, Open source, RxJava No comments

Recent updates

I’ve recently released version 0.3.0 of ReactiveNetwork library for Android. As you can see in the release notes, it contains a lot of updates.
Highlights:

  • Deprecated methods related to monitoring WiFi Access Points and WiFi Singal level in favor of ReactiveWiFi project, which has this functionality extracted from ReactiveNetwork
  • Deprecated methods and enums related to monitoring connectivity with The Internet
  • Added Observables, which allows monitoring Internet connectivity basing on socket connection with a remote host (we can also monitor specific host with given parameters)

Roadmap for the future versions

Updates planned for 0.4.0:

  • Removing deprecated methods
  • Removing unused permissions from AndroidManifest.xml

Track progress of releasing 0.4.0 on GitHub

Updates planned for 0.5.0:

  • Updating library code with respect to the updates in Android 5 and 6 (especially ConnectivityManager) related to monitoring network connectivity mentioned in issue #62 on GitHub
  • Creating strategy interface to keep backward compatibility with Pre-Lollipop devices, so we’ll be able to monitor network in a different way depending on the given Android version

Track progress of releasing 0.5.0 on GitHub

Another future updates (not related to any version):
These updates are also important, but they’re not related to library API

  • Adding example of library usage with Retrofit (without breaking reactive stream chain)

Track progress of resolving this issue on GitHub

Final thoughts

Currently, it’s my most popular open-source project and people rely on it in production apps, so I’m trying to keep it as simple and as good as I can with respect to the recent updates of Android SDK. I’m getting really good feedback from people on GitHub and seriously considering it during the development process. If something bothers you in that project, don’t hesitate to create an Issue or new Pull Request on GitHub.

Handle swipe events in reactive style

2016-03-11 Android, Java, Open source, RxJava No comments

Introduction

Initial Swipe Detector project was created on 24th of December 2014 on GitHub, so more than one year ago. I also wrote an article about that on my blog. I needed that to detect moment when user is swiping horizontally, to block vertical scroll on the ListView while deleting item with “swipe to delete” functionality. This gives better UX and apps from Google works in the same way. Mentioned project was just a simple proof of concept showing how can we detect whether user is swiping on the screen of mobile device and in which direction. Recently, I thought that it would be cool if we had a separate generic library to do the same thing. It would be even cooler if this library will provide RxJava Observable to handle such events in a reactive way. That’s why I’ve decided to take this project, extract generic code to library and write an Observable wrapping listener, which handles swipe events. Please, take a look at the outcome of that work.

swipe

Preparation

New library is called swipe. If we want to use it, we need to add proper dependencies to our build.gradle file:

dependencies {
  compile 'com.github.pwittchen:swipe:0.0.1'
}

Next, we need to create Swipe attribute in our Activity:

private Swipe swipe;

We also need to remember to call dispatchTouchEvent(MotionEvent) method:

We need to perform things described above both for listener and RxJava Observable.

Imperative way

If we are not familiar with RxJava, we can handle swipe events in an imperative way with listener:

Reactive way

If we want to use the power of RxJava and code our app in a reactive style, we need to add Subscription attribute.

private Subscription subscription;

Now, we can subscribe an Observable:

Please note, there’s much less code than in the case of listener.

We need to remember to unsubscribe our Observable, when it’s no longer needed:

That’s it! I hope it will help you to detect and handle swipe events in your apps.

Source code of the library is available on GitHub: https://github.com/pwittchen/swipe.

Infinite scroll for RecyclerView in Android

2016-02-28 Android, Java, Open source, UI 5 comments

Introduction

Three years ago I wrote short article about Endless ListView in Android. This solution was dedicated to ListView, wasn’t perfect and generic. Moreover, lot of people asked questions about this solution and they weren’t sure how to use it properly. I also had some problems with implementing endless scroll AKA infinite scroll in Android apps. In addition, in the newest Android SDK it’s recommended to use RecyclerView instead of ListView. For a long time I couldn’t find the right implementation of the infinite scroll AKA endless scroll for Android. A few solutions I’ve found weren’t production ready, weren’t working correctly or had too many features. I wanted to have small, easy and flexible solution to implement infinite scroll for Android, which works with RecyclerView from the newest Android API. That’s why I created new project called InfiniteScroll, which helps to implement infinite scroll on Android. Library is tested and its behavior is documented by appropriate unit tests. If you would like to see it in action, check out gif animation presenting how sample app works. Library is very tiny, but does its job.

How to use it?

First of all, we need to add library dependency to our build.gradle file:

dependencies {
  compile 'com.github.pwittchen:infinitescroll:0.0.1'
}

We also need to create necessary fields in our Activity:

public RecyclerView recyclerView;
private LinearLayoutManager layoutManager;

Next, we need to create new InfiniteScrollListener:

Then, we need to initialize RecyclerView and LinearLayoutManager in our Activity and add previously created listener to RecyclerView:

If we want to display loading progress, we should add additional view for it, show it while loading starts and hide it when loading is finished.

That’s it!

Please note: We can also implement “Load more” button with that library. Instead of loading items immediately, we can display such button when user scrolled to the end of the list.

Exemplary apps

You can see how, library can be implemented in the following places:

  • Sample app from main repository, which loads Strings into RecyclerView
  • Search Twitter app, which allows to search tweets and scroll them infinitely

Summary

I think, this time infinite scroll is implemented in the right and re-usable way. I hope, it will make your life easier while developing your apps.

Source code of the library can be found at: https://github.com/pwittchen/InfiniteScroll.

ReactiveNetwork – release of v. 0.2.0

2016-02-11 Android, Java, Open source, RxJava No comments

I’ve recently released new version of ReactiveNetwork library for Android.

Here are the fresh release notes for version 0.2.0:

  • added possibility to observe WiFi signal level with observeWifiSignalLevel(context, numLevels) and observeWifiSignalLevel(context) method
  • created WifiSignalLevel enum
  • added internet check to parameters of getConnectivityStatus(context, checkInternet) method
  • made getConnectivityStatus(context, checkInternet) method public
  • changed String variable status in ConnectivityStatus enum to description and made it public
  • changed output of the toString() method in ConnectivityStatus to keep consistency with another enum
  • made ReactiveNetwork class non-final
  • bumped Kotlin version in sample app to 1.0.0-rc-1036
  • increased immutability of code of the library
  • updated sample apps and documentation

Thanks to @llp and his Pull Request, we are able to observe WiFi signal level AKA RSSI now! It’s one of the most interesting features in the newest release.

We can do it as follows:

or we can observe an enum value instead of integer:

WifiSignalLevel enum can have the following values:

public enum WifiSignalLevel {
  NO_SIGNAL(0, "no signal"),
  POOR(1, "poor"),
  FAIR(2, "fair"),
  GOOD(3, "good"),
  EXCELLENT(4, "excellent");
  ...
}

Any feedback will be appreciated!

Happy coding!

3 questions about your Git repository

2015-12-28 Git, Linux, Open source, Python 3 comments

Introduction

Can you answer the following questions about your Git repository?

  1. Does development branch has all changes from master branch?
  2. Is your gitlog a crap?
  3. How old are your branches?

If not, but you want to know answers, you’re lucky, because I prepared 3 simple scripts for you, which can help to find it out.

Does development branch has all changes from master branch?

git-branch-comparator is a python script, which checks if development branch has all changes from master branch in Git repository.

Another, easier way to accomplish the same task suggested in comments by Mike (thanks!) is to call simply:

$ git pull
$ git branch --contains master --no-merged development

When we are working in a Git Flow and critical bug occurs on production, sometimes there is a necessity to create so called hot-fix. We can create separate branch from master branch for this hot-fix and then merge it into master branch or we can commit a change on master branch. Second option is not recommended. After that, we have to remember to merge master branch into a development branch to have our hot-fix in a development version as well and avoid merge conflicts in the future.

This python script checks, if all changes made on master branch were also merged into development branch to keep those two branches consistent. We can add it as a job into Jenkins CI server and monitor branches consistency. In addition, release jobs can depend on that job and we can avoid merge conflicts or project unstability before release.

source code & documentation: https://github.com/pwittchen/git-branch-comparator

Is your gitlog a crap?

craplog is a python script, which checks if git git log of the given project is crappy or not. Right now, script is very simple. It just checks if more than half of the commit messages are good. Commit message is considered as good, when it contains more than two words. Of course, this is not the only condition determining the quality of the commit message, but this is early beta version of the script and can be improved later.

I’ve read a discussion in one of the pull requests to Linux kernel. It made me think about quality of Git commit messages. Of course, Linux kernel is a specific project and has its own standards. Maybe not all of these standards will be valid for a simpler or less complicated projects. Nevertheless, a lot of people don’t pay attention to git commit messages. They put crappy stuff inside them like random letters and numbers or stupid expressions, which has no specific meaning, aren’t related to the project or aren’t informative enough. In my opinion, good git log is one of the factors determining good quality of the project. Sometimes, we need to browse log to find some changes or analyze project history in order to fix a bug or find important information. It’s easier to do it, when git log is good. I’ve made some of the mentioned mistakes in the past, but I try to avoid them now.

source code & documentation: https://github.com/pwittchen/craplog

How old are your branches?

git-aged-branches is a shell script showing git branches of defined repository with age of their last commit. It works on Mac OS X, Linux and can be helpful while investigating old Git branches to delete. This script does not delete anything! It’s just for informational purposes.

source code & documentation: https://github.com/pwittchen/git-aged-branches

Summary

I hope, some of you will find these tools useful and maybe they’ll solve your current problems or help to improve quality of your projects.
If you would like to know more details about mentioned projects, check instructions how to use them and their source code, visit linked repositories on GitHub.

Note: Any feedback, new issues or pull requests are appreciated!

New release of Kirai – elegant string formatting library for Java

2015-11-22 Android, Java, Open source No comments

I’ve recently released version 1.4.0 of Kirai library. Kirai means phrase in Swahili language. It’s string formatting library written in Java. It originally started as an Android library, but it evolved to pure Java library. It’s first possibilities were basic string formatting and text formatting for Android TextViews. Now, it allows to format strings for Java, Web, Android and even Unix Terminal! Have you ever wanted to have colorful and styled text in your mobile app, website or terminal app? Now you can with an elegant and fluent API! Moreover, I’ve added test coverage supported by codecov.io. It’s really nice service, which integrates with Travis CI and is free for open-source projects. It’s available for various programming languages and build systems.

Check library source code and samples at: https://github.com/pwittchen/kirai

You can add it to your project via Maven:

<dependency>
    <groupId>com.github.pwittchen.kirai</groupId>
    <artifactId>library</artifactId>
    <version>1.4.0</version>
</dependency>

or through Gradle:

dependencies {
  compile 'com.github.pwittchen.kirai:library:1.4.0'
}

Bunch of updates in my OSS for Android

2015-11-08 Android, Java, Kotlin, Open source No comments

Introduction

In the last days I prepared a bunch of updates in my open-source software for Android. Most of them are bug fixes and are related to increasing robustness of the projects as well as their overall quality. I also decided to play a little with Kotlin language from JetBrains, which seems to be reasonable choice for mobile applications running on Android. Nevertheless, writing an app in Kotlin requires some additional configuration and we should remember, it’s still in beta version. If you are interested in Kotlin programming for Android, take a look at Getting started with Android and Kotlin guide from official Kotlin website. You can also take a look at one of my sample apps written in Kotlin and its configuration in Gradle.

Summary of updates

ReactiveNetwork v. 0.1.3

  • fixed bug with incorrect status after going back from background inside the sample app reported in issue #31
  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • added static code analysis
  • updated code formatting
  • added sample sample app in Kotlin

Unfortunately, in Android we cannot use Java 8 yet and code should be written in Java 7. We can do some hacks like using RetroLambda or libraries implementing part of functionalities available in Java 8 like streams, but these solutions are still hacks – not the right way. In Kotlin we can use lambdas like in Java 8. In addition, we have a lot of other cool features, which allow us to write less lines of code and detect possible mistakes while writing apps. E.g. Kotlin helps us to avoid NPEs with its additional operators like !!, which tells us that NPE can occur, so we can think of eliminating this possibility. If we don’t use this operator when we should, IntelliJ IDEA or Android Studio will warn us. Below, we can see exemplary usage of ReactiveNetwork library with Kotlin. In this code snippet, we are using so called synthetic properties from Kotlin Extensions for Android. Value connectivity_status is an id of the view defined in XML layout. We can call it directly in Kotlin code and treat as object. It’s really useful and allows us to avoid calling findViewById(...) method for every view in Activity or injecting views with additional libraries like ButterKnife or KotterKnife. It means that we can get rid of a lot of boilerplate code.

ReactiveSensors

  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • added static code analysis
  • refactored sample app and removed repetitions in code

In this project I made only changes inside the documentation, improved Gradle configuration and added another sample app. There were no changes inside the library code, so there was no need to release new library version to Maven Central Repository. Moreover, I’m going to add sample app in Kotlin for this project in the nearest future.

ReactiveBeacons v. 0.3.0

  • replaced distinct() operator with distinctUntilChanged() operator in Observable observe() method in ReactiveBeacons class
  • added permissions ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION to satisfy requirements of Android 6
  • renamed void requestBluetoothAccessIfDisabled(activity) method to void requestBluetoothAccess(activity)
  • added boolean isBluetoothEnabled() method
  • added boolean isLocationEnabled(context) method
  • added void requestLocationAccess(activity) method
  • modified sample app in order to make it work on Android 6 Marshmallow
  • reduced target API from 23 to 22 in library due to problems with additional permissions and new permission model (it can be subject of improvements in the next releases)
  • added package private AccessRequester class
  • added sample app in Kotlin

WeatherIconView v. 1.1.0

  • added icons from 2.0 version of the original weather-icons project
  • updated compile sdk version
  • updated Gradle Build Tools version

Prefser v. 2.0.2

  • fixed bug reported in issue #70: get(...) method now returns a null value instead of “null” string when setting default value to null of String type
  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • changed code formatting to SquareAndroid
  • added static code analysis
  • improved code according to static code analysis suggestions

Kirai v. 1.1.0

  • removed formatter(...) method from Kirai class
  • added format(...) method accepting implementation of Formatter interface to Kirai class
  • added Syntax interface and HtmlSyntax class implementing this interface
  • added put(String key, Object value, Syntax syntax) method to Piece class
  • set HtmlSyntax as default Syntax implementation in Piece class
  • removed dependencies to Android SDK
  • updated project dependencies
  • applied Square code style
  • updated tests, sample app and code snippets in README.md
  • added gh-pages with JavaDoc

Any suggestions of further improvements are more than welcome as usual!